Fetch mesos leader through zookeeper (#19)

Adds support for fetching current Mesos leader through Zookeeper
This commit is contained in:
lenhattan86 2020-11-17 12:39:51 -08:00 committed by GitHub
parent be6c458f23
commit 2f05111192
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View file

@ -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)

View file

@ -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"

2
go.mod
View file

@ -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