Add default fetch from local mesos agent
Signed-off-by: Abdul Qadeer <quadeer.leo@gmail.com>
This commit is contained in:
parent
0adb137278
commit
cf5c8a5ade
1 changed files with 43 additions and 5 deletions
48
cmd/fetch.go
48
cmd/fetch.go
|
@ -15,7 +15,9 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/aurora-scheduler/australis/internal"
|
"github.com/aurora-scheduler/australis/internal"
|
||||||
realis "github.com/aurora-scheduler/gorealis/v2"
|
realis "github.com/aurora-scheduler/gorealis/v2"
|
||||||
|
@ -24,6 +26,10 @@ import (
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
localAgentStateURL = "http://127.0.0.1:5051/state"
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(fetchCmd)
|
rootCmd.AddCommand(fetchCmd)
|
||||||
|
|
||||||
|
@ -124,14 +130,15 @@ Pass Zookeeper nodes separated by a space as an argument to this command.`,
|
||||||
}
|
}
|
||||||
|
|
||||||
var mesosCmd = &cobra.Command{
|
var mesosCmd = &cobra.Command{
|
||||||
Use: "mesos [zkNode0, zkNode1, ...zkNodeN]",
|
Use: "mesos 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.`,
|
Pass Zookeeper nodes separated by a space as an argument to this command. If no nodes are provided,
|
||||||
Run: fetchMesos,
|
it fetches leader from local Mesos-agent instance`,
|
||||||
|
Run: fetchMesosLeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
var fetchJobsCmd = &cobra.Command{
|
var fetchJobsCmd = &cobra.Command{
|
||||||
|
@ -246,9 +253,16 @@ func fetchLeader(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println(url)
|
fmt.Println(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchMesos(cmd *cobra.Command, args []string) {
|
func fetchMesosLeader(cmd *cobra.Command, args []string) {
|
||||||
|
var url string
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
args = append(args, "localhost")
|
url = fetchMesosLeaderFromAgent(localAgentStateURL)
|
||||||
|
if url == "" {
|
||||||
|
log.Warn("unable to fetch Mesos leader from local Mesos agent, please try again with zk nodes")
|
||||||
|
} else {
|
||||||
|
fmt.Println(url)
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Infof("Fetching Mesos-master leader from %v \n", args)
|
log.Infof("Fetching Mesos-master leader from %v \n", args)
|
||||||
|
|
||||||
|
@ -261,6 +275,30 @@ func fetchMesos(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println(url)
|
fmt.Println(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchMesosLeaderFromAgent(url string) (mesosLeaderHostName string) {
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var res interface{}
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hostname, ok := res.(map[string]interface{})["master_hostname"]
|
||||||
|
if !ok {
|
||||||
|
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.
|
||||||
func fetchJobs(cmd *cobra.Command, args []string) {
|
func fetchJobs(cmd *cobra.Command, args []string) {
|
||||||
log.Infof("Fetching tasks under role: %s \n", *role)
|
log.Infof("Fetching tasks under role: %s \n", *role)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue