Address review comments
This commit is contained in:
parent
cf5c8a5ade
commit
1c65607208
1 changed files with 25 additions and 19 deletions
44
cmd/fetch.go
44
cmd/fetch.go
|
@ -30,6 +30,10 @@ const (
|
||||||
localAgentStateURL = "http://127.0.0.1:5051/state"
|
localAgentStateURL = "http://127.0.0.1:5051/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type mesosAgentState struct {
|
||||||
|
MasterHostname string `json:"master_hostname,omitempty""`
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(fetchCmd)
|
rootCmd.AddCommand(fetchCmd)
|
||||||
|
|
||||||
|
@ -68,8 +72,8 @@ func init() {
|
||||||
help(cmd, s)
|
help(cmd, s)
|
||||||
})
|
})
|
||||||
|
|
||||||
/* Fetch mesos leader */
|
mesosLeaderCmd.Flags().String("zkPath", "/mesos", "Zookeeper node path where mesos leader election happens")
|
||||||
mesosCmd.Flags().String("zkPath", "/mesos", "Zookeeper node path where mesos leader election happens")
|
mesosCmd.AddCommand(mesosLeaderCmd)
|
||||||
|
|
||||||
fetchCmd.AddCommand(mesosCmd)
|
fetchCmd.AddCommand(mesosCmd)
|
||||||
|
|
||||||
|
@ -130,14 +134,20 @@ Pass Zookeeper nodes separated by a space as an argument to this command.`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var mesosCmd = &cobra.Command{
|
var mesosCmd = &cobra.Command{
|
||||||
Use: "mesos leader [zkNode0, zkNode1, ...zkNodeN]",
|
Use: "mesos",
|
||||||
|
PreRun: setConfig,
|
||||||
|
Short: "Fetch information from Mesos.",
|
||||||
|
}
|
||||||
|
|
||||||
|
var mesosLeaderCmd = &cobra.Command{
|
||||||
|
Use: "leader [zkNode0, zkNode1, ...zkNodeN]",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {}, // We don't need a realis client for this cmd
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {}, // We don't need a realis client for this cmd
|
||||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {}, // We don't need a realis client for this cmd
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {}, // We don't need a realis client for this cmd
|
||||||
PreRun: setConfig,
|
PreRun: setConfig,
|
||||||
Short: "Fetch current Mesos-master leader given Zookeeper nodes. ",
|
Short: "Fetch current Mesos-master leader given Zookeeper nodes.",
|
||||||
Long: `Gets the current leading Mesos-master instance using information from Zookeeper path.
|
Long: `Gets the current leading Mesos-master instance using information from Zookeeper path.
|
||||||
Pass Zookeeper nodes separated by a space as an argument to this command. If no nodes are provided,
|
Pass Zookeeper nodes separated by a space as an argument to this command. If no nodes are provided,
|
||||||
it fetches leader from local Mesos-agent instance`,
|
it fetches leader from local Mesos agent or Zookeeper`,
|
||||||
Run: fetchMesosLeader,
|
Run: fetchMesosLeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,13 +266,14 @@ func fetchLeader(cmd *cobra.Command, args []string) {
|
||||||
func fetchMesosLeader(cmd *cobra.Command, args []string) {
|
func fetchMesosLeader(cmd *cobra.Command, args []string) {
|
||||||
var url string
|
var url string
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
url = fetchMesosLeaderFromAgent(localAgentStateURL)
|
url, err := fetchMesosLeaderFromAgent(localAgentStateURL)
|
||||||
if url == "" {
|
if err != nil || url == "" {
|
||||||
log.Warn("unable to fetch Mesos leader from local Mesos agent, please try again with zk nodes")
|
log.Debugf("unable to fetch Mesos leader from local Mesos agent: %v", err)
|
||||||
|
args = append(args, "localhost")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(url)
|
fmt.Println(url)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
log.Infof("Fetching Mesos-master leader from %v \n", args)
|
log.Infof("Fetching Mesos-master leader from %v \n", args)
|
||||||
|
|
||||||
|
@ -275,7 +286,7 @@ func fetchMesosLeader(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println(url)
|
fmt.Println(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchMesosLeaderFromAgent(url string) (mesosLeaderHostName string) {
|
func fetchMesosLeaderFromAgent(url string) (mesosLeaderHostName string, err error) {
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -285,18 +296,13 @@ func fetchMesosLeaderFromAgent(url string) (mesosLeaderHostName string) {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
var res interface{}
|
state := &mesosAgentState{}
|
||||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
err = json.NewDecoder(resp.Body).Decode(state)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hostname, ok := res.(map[string]interface{})["master_hostname"]
|
mesosLeaderHostName = state.MasterHostname
|
||||||
if !ok {
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
mesosLeaderHostName, _ = hostname.(string)
|
|
||||||
|
|
||||||
return mesosLeaderHostName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Expand this to be able to filter by job name and environment.
|
// TODO: Expand this to be able to filter by job name and environment.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue