Adding command to fetch leader given zookeeper endpoints.
This commit is contained in:
parent
0a93854a52
commit
becb32c7ff
1 changed files with 36 additions and 3 deletions
39
cmd/fetch.go
39
cmd/fetch.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/paypal/gorealis"
|
||||||
"github.com/paypal/gorealis/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/gen-go/apache/aurora"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -12,10 +13,15 @@ func init() {
|
||||||
rootCmd.AddCommand(fetchCmd)
|
rootCmd.AddCommand(fetchCmd)
|
||||||
|
|
||||||
// Sub-commands
|
// Sub-commands
|
||||||
|
|
||||||
|
// Fetch Task Config
|
||||||
fetchCmd.AddCommand(taskConfigCmd)
|
fetchCmd.AddCommand(taskConfigCmd)
|
||||||
taskConfigCmd.Flags().StringVarP(&env, "environment", "e", "", "Aurora Environment")
|
taskConfigCmd.Flags().StringVarP(&env, "environment", "e", "", "Aurora Environment")
|
||||||
taskConfigCmd.Flags().StringVarP(&role, "role", "r", "", "Aurora Role")
|
taskConfigCmd.Flags().StringVarP(&role, "role", "r", "", "Aurora Role")
|
||||||
taskConfigCmd.Flags().StringVarP(&name, "name", "n", "", "Aurora Name")
|
taskConfigCmd.Flags().StringVarP(&name, "name", "n", "", "Aurora Name")
|
||||||
|
|
||||||
|
// Fetch Leader
|
||||||
|
fetchCmd.AddCommand(leaderCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fetchCmd = &cobra.Command{
|
var fetchCmd = &cobra.Command{
|
||||||
|
@ -24,10 +30,19 @@ var fetchCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
var taskConfigCmd = &cobra.Command{
|
var taskConfigCmd = &cobra.Command{
|
||||||
Use: "config" ,
|
Use: "config",
|
||||||
Short: "Fetch a list of task configurations from Aurora.",
|
Short: "Fetch a list of task configurations from Aurora.",
|
||||||
Long: `To be written.`,
|
Long: `To be written.`,
|
||||||
Run: fetchTasks,
|
Run: fetchTasks,
|
||||||
|
}
|
||||||
|
|
||||||
|
var leaderCmd = &cobra.Command{
|
||||||
|
Use: "leader",
|
||||||
|
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
|
||||||
|
Short: "Fetch current Aurora leader given Zookeeper nodes. Pass Zookeeper nodes separated by a space as an argument to this command.",
|
||||||
|
Long: `To be written.`,
|
||||||
|
Run: fetchLeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchTasks(cmd *cobra.Command, args []string) {
|
func fetchTasks(cmd *cobra.Command, args []string) {
|
||||||
|
@ -46,3 +61,21 @@ func fetchTasks(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println(t)
|
fmt.Println(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fetchLeader(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Printf("Fetching leader from %v \n", args)
|
||||||
|
|
||||||
|
if len(args) < 1 {
|
||||||
|
fmt.Println("At least one Zookeper node address must be passed in.")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
url, err := realis.LeaderFromZKOpts(realis.ZKEndpoints(args...), realis.ZKPath("/aurora/scheduler"))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error: %+v\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(url)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue