diff --git a/cmd/fetch.go b/cmd/fetch.go index 0f778d2..c56cede 100644 --- a/cmd/fetch.go +++ b/cmd/fetch.go @@ -62,6 +62,23 @@ func init() { help(cmd, s) }) + /* Fetch mesos leader */ + mesosCmd.Flags().String("zkPath", "/mesos", "Zookeeper node path where mesos leader election happens") + + fetchCmd.AddCommand(mesosCmd) + + // Hijack help function to hide unnecessary global flags + mesosCmd.SetHelpFunc(func(cmd *cobra.Command, s []string) { + if cmd.HasInheritedFlags() { + cmd.InheritedFlags().VisitAll(func(f *pflag.Flag) { + if f.Name != "logLevel" { + f.Hidden = true + } + }) + } + help(cmd, s) + }) + // Fetch jobs fetchJobsCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") fetchCmd.AddCommand(fetchJobsCmd) @@ -106,6 +123,17 @@ Pass Zookeeper nodes separated by a space as an argument to this command.`, Run: fetchLeader, } +var mesosCmd = &cobra.Command{ + Use: "mesos [zkNode0, zkNode1, ...zkNodeN]", + 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 + PreRun: setConfig, + Short: "Fetch current Mesos-master leader given Zookeeper nodes. ", + 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.`, + Run: fetchMesos, +} + var fetchJobsCmd = &cobra.Command{ Use: "jobs", Short: "Fetch a list of task Aurora running under a role.", @@ -218,6 +246,21 @@ func fetchLeader(cmd *cobra.Command, args []string) { fmt.Println(url) } +func fetchMesos(cmd *cobra.Command, args []string) { + if len(args) < 1 { + args = append(args, "localhost") + } + log.Infof("Fetching Mesos-master leader from %v \n", args) + + url, err := realis.MesosFromZKOpts(realis.ZKEndpoints(args...), realis.ZKPath(cmd.Flag("zkPath").Value.String())) + + if err != nil { + log.Fatalf("error: %+v\n", err) + } + + fmt.Println(url) +} + // TODO: Expand this to be able to filter by job name and environment. func fetchJobs(cmd *cobra.Command, args []string) { log.Infof("Fetching tasks under role: %s \n", *role) diff --git a/cmd/root.go b/cmd/root.go index 3b5889d..c15b064 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -47,7 +47,7 @@ var filename string var message = new(string) var updateID string var monitor bool -var timeout time.Duration // seconds +var timeout time.Duration var log = logrus.New() const australisVer = "v1.0.1" diff --git a/go.mod b/go.mod index a4ef81b..470ef98 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/aurora-scheduler/australis require ( - github.com/aurora-scheduler/gorealis/v2 v2.22.1 + github.com/aurora-scheduler/gorealis/v2 v2.22.2 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.6.0 github.com/spf13/cobra v1.0.0