diff --git a/clusters.go b/clusters.go index c5bf325..d3747e1 100644 --- a/clusters.go +++ b/clusters.go @@ -28,6 +28,7 @@ type Cluster struct { ZK string `json:"zk"` ZKPort int `json:"zk_port"` SchedZKPath string `json:"scheduler_zk_path"` + MesosZKPath string `json:"scheduler_zk_path"` SchedURI string `json:"scheduler_uri"` ProxyURL string `json:"proxy_url"` AuthMechanism string `json:"auth_mechanism"` @@ -61,17 +62,7 @@ func GetDefaultClusterFromZKUrl(zkURL string) *Cluster { AuthMechanism: "UNAUTHENTICATED", ZK: zkURL, SchedZKPath: "/aurora/scheduler", - AgentRunDir: "latest", - AgentRoot: "/var/lib/mesos", - } -} - -func GetDefaultMesosClusterFromZKUrl(zkURL string) *Cluster { - return &Cluster{ - Name: "defaultCluster", - AuthMechanism: "UNAUTHENTICATED", - ZK: zkURL, - SchedZKPath: "/mesos", + MesosZKPath: "/mesos", AgentRunDir: "latest", AgentRoot: "/var/lib/mesos", } diff --git a/realis_e2e_test.go b/realis_e2e_test.go index a3439b3..1f544d8 100644 --- a/realis_e2e_test.go +++ b/realis_e2e_test.go @@ -196,7 +196,7 @@ func TestMasterFromZK(t *testing.T) { } func TestMesosMasterFromZK(t *testing.T) { - cluster := realis.GetDefaultMesosClusterFromZKUrl("192.168.33.2:2181") + cluster := realis.GetDefaultClusterFromZKUrl("192.168.33.2:2181") masterNodesMap, err := realis.MesosMasterNodesFromZK(*cluster) assert.NoError(t, err) diff --git a/zk.go b/zk.go index 44aa5e2..b1c4ad4 100644 --- a/zk.go +++ b/zk.go @@ -335,7 +335,7 @@ func MasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { // Get all the master nodes through all the children in the given path serviceInst := new(ServiceInstance) - var host []string + var hosts []string for _, child := range children { childPath := config.path + "/" + child data, _, err := c.Get(childPath) @@ -367,10 +367,10 @@ func MasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { } } else { // data is not in a json format - host = append(host, string(data)) + hosts = append(hosts, string(data)) } } - result["masterNodes"] = host + result["masterNodes"] = hosts // Master nodes data might not be available yet, try to fetch again. if len(result["masterNodes"]) == 0 { @@ -389,7 +389,7 @@ func MasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { // Retrieves current Mesos Aurora master nodes from ZK. func MesosMasterNodesFromZK(cluster Cluster) (map[string][]string, error) { - return MesosMasterNodesFromZKOpts(ZKEndpoints(strings.Split(cluster.ZK, ",")...), ZKPath(cluster.SchedZKPath)) + return MesosMasterNodesFromZKOpts(ZKEndpoints(strings.Split(cluster.ZK, ",")...), ZKPath(cluster.MesosZKPath)) } // Retrieves current mesos master nodes/leader from ZK with a custom configuration. @@ -436,7 +436,7 @@ func MesosMasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { // Get all the master nodes through all the children in the given path minScore := math.MaxInt64 var mesosInstance MesosInstance - var host []string + var hosts []string for _, child := range children { // Only the master nodes will start with json.info_ if strings.HasPrefix(child, "json.info_") { @@ -468,7 +468,7 @@ func MesosMasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { } // Combine all master nodes into comma-separated // Return hostname instead of ip to be consistent with aurora master nodes - host = append(host, mesosInstance.Address.Hostname) + hosts = append(hosts, mesosInstance.Address.Hostname) // get the leader from the child with the smallest score. if score < minScore { minScore = score @@ -476,7 +476,7 @@ func MesosMasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) { } } } - result["masterNodes"] = host + result["masterNodes"] = hosts // Master nodes data might not be available yet, try to fetch again. if len(result["masterNodes"]) == 0 { return false, NewTemporaryError(errors.New("no mesos master nodes found"))