client: add httpClusterClient.Sync

release-2.0
Brian Waldon 2014-10-31 11:04:22 -07:00
parent f6e8b677cf
commit 5ed5d018be
1 changed files with 23 additions and 1 deletions

View File

@ -23,8 +23,9 @@ import (
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
func NewHTTPClient(tr *http.Transport, eps []string) (*httpClusterClient, error) {
func NewHTTPClient(tr CancelableTransport, eps []string) (*httpClusterClient, error) {
c := httpClusterClient{
transport: tr,
endpoints: make([]httpActionDo, len(eps)),
}
@ -44,6 +45,7 @@ func NewHTTPClient(tr *http.Transport, eps []string) (*httpClusterClient, error)
}
type httpClusterClient struct {
transport CancelableTransport
endpoints []httpActionDo
}
@ -51,3 +53,23 @@ func (c *httpClusterClient) do(ctx context.Context, act httpAction) (*http.Respo
//TODO(bcwaldon): introduce retry logic so all endpoints are attempted
return c.endpoints[0].do(ctx, act)
}
func (c *httpClusterClient) Sync() error {
mAPI := NewMembersAPI(c, DefaultRequestTimeout)
ms, err := mAPI.List()
if err != nil {
return err
}
eps := make([]string, 0)
for _, m := range ms {
eps = append(eps, m.ClientURLs...)
}
nc, err := NewHTTPClient(c.transport, eps)
if err != nil {
return err
}
*c = *nc
return nil
}