Browse Source

client: add httpClusterClient.Sync

Brian Waldon 11 years ago
parent
commit
5ed5d018be
1 changed files with 23 additions and 1 deletions
  1. 23 1
      client/cluster.go

+ 23 - 1
client/cluster.go

@@ -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
+}