Address code review comment
This commit is contained in:
parent
6ce516663a
commit
1b46f867b6
3 changed files with 10 additions and 19 deletions
13
clusters.go
13
clusters.go
|
@ -28,6 +28,7 @@ type Cluster struct {
|
||||||
ZK string `json:"zk"`
|
ZK string `json:"zk"`
|
||||||
ZKPort int `json:"zk_port"`
|
ZKPort int `json:"zk_port"`
|
||||||
SchedZKPath string `json:"scheduler_zk_path"`
|
SchedZKPath string `json:"scheduler_zk_path"`
|
||||||
|
MesosZKPath string `json:"scheduler_zk_path"`
|
||||||
SchedURI string `json:"scheduler_uri"`
|
SchedURI string `json:"scheduler_uri"`
|
||||||
ProxyURL string `json:"proxy_url"`
|
ProxyURL string `json:"proxy_url"`
|
||||||
AuthMechanism string `json:"auth_mechanism"`
|
AuthMechanism string `json:"auth_mechanism"`
|
||||||
|
@ -61,17 +62,7 @@ func GetDefaultClusterFromZKUrl(zkURL string) *Cluster {
|
||||||
AuthMechanism: "UNAUTHENTICATED",
|
AuthMechanism: "UNAUTHENTICATED",
|
||||||
ZK: zkURL,
|
ZK: zkURL,
|
||||||
SchedZKPath: "/aurora/scheduler",
|
SchedZKPath: "/aurora/scheduler",
|
||||||
AgentRunDir: "latest",
|
MesosZKPath: "/mesos",
|
||||||
AgentRoot: "/var/lib/mesos",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDefaultMesosClusterFromZKUrl(zkURL string) *Cluster {
|
|
||||||
return &Cluster{
|
|
||||||
Name: "defaultCluster",
|
|
||||||
AuthMechanism: "UNAUTHENTICATED",
|
|
||||||
ZK: zkURL,
|
|
||||||
SchedZKPath: "/mesos",
|
|
||||||
AgentRunDir: "latest",
|
AgentRunDir: "latest",
|
||||||
AgentRoot: "/var/lib/mesos",
|
AgentRoot: "/var/lib/mesos",
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,7 +196,7 @@ func TestMasterFromZK(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMesosMasterFromZK(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)
|
masterNodesMap, err := realis.MesosMasterNodesFromZK(*cluster)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
14
zk.go
14
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
|
// Get all the master nodes through all the children in the given path
|
||||||
serviceInst := new(ServiceInstance)
|
serviceInst := new(ServiceInstance)
|
||||||
var host []string
|
var hosts []string
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
childPath := config.path + "/" + child
|
childPath := config.path + "/" + child
|
||||||
data, _, err := c.Get(childPath)
|
data, _, err := c.Get(childPath)
|
||||||
|
@ -367,10 +367,10 @@ func MasterNodesFromZKOpts(options ...ZKOpt) (map[string][]string, error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// data is not in a json format
|
// 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.
|
// Master nodes data might not be available yet, try to fetch again.
|
||||||
if len(result["masterNodes"]) == 0 {
|
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.
|
// Retrieves current Mesos Aurora master nodes from ZK.
|
||||||
func MesosMasterNodesFromZK(cluster Cluster) (map[string][]string, error) {
|
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.
|
// 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
|
// Get all the master nodes through all the children in the given path
|
||||||
minScore := math.MaxInt64
|
minScore := math.MaxInt64
|
||||||
var mesosInstance MesosInstance
|
var mesosInstance MesosInstance
|
||||||
var host []string
|
var hosts []string
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
// Only the master nodes will start with json.info_
|
// Only the master nodes will start with json.info_
|
||||||
if strings.HasPrefix(child, "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
|
// Combine all master nodes into comma-separated
|
||||||
// Return hostname instead of ip to be consistent with aurora master nodes
|
// 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.
|
// get the leader from the child with the smallest score.
|
||||||
if score < minScore {
|
if score < minScore {
|
||||||
minScore = score
|
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.
|
// Master nodes data might not be available yet, try to fetch again.
|
||||||
if len(result["masterNodes"]) == 0 {
|
if len(result["masterNodes"]) == 0 {
|
||||||
return false, NewTemporaryError(errors.New("no mesos master nodes found"))
|
return false, NewTemporaryError(errors.New("no mesos master nodes found"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue