From c5edcaa48b0cf0431beb2fd5a3a467417e654d19 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Wed, 26 Dec 2018 17:27:23 -0800 Subject: [PATCH] Refactored to update to gorealis v2. --- CHANGELOG | 4 ++++ cmd/fetch.go | 8 ++++---- cmd/kill.go | 12 ++---------- cmd/root.go | 12 +++++------- cmd/set.go | 8 +------- cmd/start.go | 24 ++++++++++++------------ cmd/stop.go | 18 +++++------------- debian/changelog | 6 ++++++ 8 files changed, 39 insertions(+), 53 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 08929c2..64a21a5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +0.0.7 + +* Initial migration to gorealis v2 + 0.0.6 * Added auto-completion to the deb file. diff --git a/cmd/fetch.go b/cmd/fetch.go index 1b9b9fb..b1c69e6 100644 --- a/cmd/fetch.go +++ b/cmd/fetch.go @@ -119,7 +119,7 @@ func fetchTasks(cmd *cobra.Command, args []string) { func fetchStatus(cmd *cobra.Command, args []string) { log.Infof("Fetching maintenance status for %v \n", args) - _, result, err := client.MaintenanceStatus(args...) + result, err := client.MaintenanceStatus(args...) if err != nil { log.Fatalf("error: %+v\n", err) } @@ -127,7 +127,7 @@ func fetchStatus(cmd *cobra.Command, args []string) { if toJson { fmt.Println(toJSON(result.Statuses)) } else { - for k := range result.Statuses { + for _, k := range result.GetStatuses() { fmt.Printf("Result: %s:%s\n", k.Host, k.Mode) } } @@ -162,7 +162,7 @@ func fetchJobs(cmd *cobra.Command, args []string) { *role = "" } - _, result, err := client.GetJobs(*role) + result, err := client.GetJobs(*role) if err != nil { log.Fatalf("error: %+v\n", err) @@ -171,7 +171,7 @@ func fetchJobs(cmd *cobra.Command, args []string) { if toJson { var configSlice []*aurora.JobConfiguration - for config := range result.GetConfigs() { + for _, config := range result.GetConfigs() { configSlice = append(configSlice, config) } diff --git a/cmd/kill.go b/cmd/kill.go index 6a16d84..0b20b00 100644 --- a/cmd/kill.go +++ b/cmd/kill.go @@ -1,8 +1,6 @@ package cmd import ( - "fmt" - "github.com/paypal/gorealis" "github.com/spf13/cobra" @@ -53,20 +51,14 @@ func killJob(cmd *cobra.Command, args []string) { Environment(*env). Role(*role). Name(*name) - resp, err := client.KillJob(job.JobKey()) + err := client.KillJob(job.JobKey()) if err != nil { log.Fatalln(err) } - if ok, err := monitor.Instances(job.JobKey(), 0, 5, 50); !ok || err != nil { + if ok, err := client.InstancesMonitor(job.JobKey(), 0, 5, 50); !ok || err != nil { log.Fatalln("Unable to kill all instances of job") } - - if toJson { - fmt.Println(toJSON(resp.GetResult_())) - } else { - fmt.Println(resp.GetResult_()) - } } func killEntireCluster(cmd *cobra.Command, args []string) { diff --git a/cmd/root.go b/cmd/root.go index 3733419..10e6eb4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,8 +15,7 @@ var username, password, zkAddr, schedAddr string var env, role, name = new(string), new(string), new(string) var ram, disk int64 var cpu float64 -var client realis.Realis -var monitor *realis.Monitor +var client *realis.Client var skipCertVerification bool var caCertsPath string var clientKey, clientCert string @@ -28,7 +27,7 @@ var percent float64 var count int64 var filename string -const australisVer = "v0.0.6" +const australisVer = "v0.0.7" var monitorInterval, monitorTimeout time.Duration @@ -119,7 +118,7 @@ func connect(cmd *cobra.Command, args []string) { realisOptions := []realis.ClientOption{realis.BasicAuth(username, password), realis.ThriftJSON(), - realis.TimeoutMS(20000), + realis.Timeout(20 * time.Second), realis.BackOff(realis.Backoff{ Steps: 2, Duration: 10 * time.Second, @@ -141,16 +140,15 @@ func connect(cmd *cobra.Command, args []string) { // Client certificate configuration if available if clientKey != "" || clientCert != "" || caCertsPath != "" { realisOptions = append(realisOptions, - realis.Certspath(caCertsPath), + realis.CertsPath(caCertsPath), realis.ClientCerts(clientKey, clientCert), realis.InsecureSkipVerify(skipCertVerification)) } // Connect to Aurora Scheduler and create a client object - client, err = realis.NewRealisClient(realisOptions...) + client, err = realis.NewClient(realisOptions...) if err != nil { log.Fatal(err) } - monitor = &realis.Monitor{Client: client} } diff --git a/cmd/set.go b/cmd/set.go index b2a46c4..07d397f 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -72,15 +72,9 @@ func setQuota(cmd *cobra.Command, args []string) { log.Println("Setting Quota resources for role.") log.Println(args) - resp, err := client.SetQuota(*role, &cpu, &ram, &disk) + err := client.SetQuota(*role, &cpu, &ram, &disk) if err != nil { log.Fatal(err) } - - if toJson{ - fmt.Println(toJSON(resp.GetResult_())) - } else { - fmt.Println(resp.GetResult_()) - } } diff --git a/cmd/start.go b/cmd/start.go index 8cd6fac..a48a3d1 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -102,7 +102,7 @@ expects a space separated list of hosts to place into maintenance mode.`, func drain(cmd *cobra.Command, args []string) { log.Infoln("Setting hosts to DRAINING") log.Infoln(args) - _, result, err := client.DrainHosts(args...) + result, err := client.DrainHosts(args...) if err != nil { log.Fatalf("error: %+v\n", err) } @@ -110,16 +110,16 @@ func drain(cmd *cobra.Command, args []string) { log.Debugln(result) // Monitor change to DRAINING and DRAINED mode - hostResult, err := monitor.HostMaintenance( + hostResult, err := client.HostMaintenanceMonitor( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}, - int(monitorInterval.Seconds()), - int(monitorTimeout.Seconds())) + monitorInterval, + monitorTimeout) maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}) if err != nil { - log.Fatalln("error: %+v", err) + log.Fatalln(err) } } @@ -133,11 +133,11 @@ func slaDrain(policy *aurora.SlaPolicy, hosts ...string) { log.Debugln(result) // Monitor change to DRAINING and DRAINED mode - hostResult, err := monitor.HostMaintenance( + hostResult, err := client.HostMaintenanceMonitor( hosts, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}, - int(monitorInterval.Seconds()), - int(monitorTimeout.Seconds())) + monitorInterval, + monitorTimeout) maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}) @@ -167,7 +167,7 @@ func SLAPercentageDrain(cmd *cobra.Command, args []string) { func maintenance(cmd *cobra.Command, args []string) { log.Infoln("Setting hosts to Maintenance mode") log.Infoln(args) - _, result, err := client.StartMaintenance(args...) + result, err := client.StartMaintenance(args...) if err != nil { log.Fatalf("error: %+v\n", err) } @@ -175,11 +175,11 @@ func maintenance(cmd *cobra.Command, args []string) { log.Debugln(result) // Monitor change to DRAINING and DRAINED mode - hostResult, err := monitor.HostMaintenance( + hostResult, err := client.HostMaintenanceMonitor( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED}, - int(monitorInterval.Seconds()), - int(monitorTimeout.Seconds())) + monitorInterval, + monitorTimeout) maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED}) diff --git a/cmd/stop.go b/cmd/stop.go index bcb6624..f66783d 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -1,7 +1,6 @@ package cmd import ( - "fmt" "github.com/paypal/gorealis/gen-go/apache/aurora" "github.com/spf13/cobra" "time" @@ -48,7 +47,7 @@ var stopUpdateCmd = &cobra.Command{ func endMaintenance(cmd *cobra.Command, args []string) { log.Println("Setting hosts to NONE maintenance status.") log.Println(args) - _, result, err := client.EndMaintenance(args...) + result, err := client.EndMaintenance(args...) if err != nil { log.Fatalf("error: %+v\n", err) } @@ -56,12 +55,11 @@ func endMaintenance(cmd *cobra.Command, args []string) { log.Debugln(result) // Monitor change to NONE mode - hostResult, err := monitor.HostMaintenance( + hostResult, err := client.HostMaintenanceMonitor( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_NONE}, - int(monitorInterval.Seconds()), - int(monitorTimeout.Seconds())) - + monitorInterval, + monitorTimeout) maintenanceMonitorPrint(hostResult,[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE}) @@ -78,7 +76,7 @@ func stopUpdate(cmd *cobra.Command, args []string) { log.Infof("Stopping (aborting) update [%s/%s/%s] %s\n", *env, *role, *name, args[0]) - resp, err := client.AbortJobUpdate(aurora.JobUpdateKey{ + err := client.AbortJobUpdate(aurora.JobUpdateKey{ Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name}, ID: args[0], }, @@ -87,10 +85,4 @@ func stopUpdate(cmd *cobra.Command, args []string) { if err != nil { log.Fatalln(err) } - - if toJson{ - fmt.Println(toJSON(resp.GetResult_())) - } else { - fmt.Println(resp.GetResult_()) - } } diff --git a/debian/changelog b/debian/changelog index 4cf42eb..d7c9287 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +australis (0.0.7) unstable; urgency=medium + + * Upgraded australis to gorealis v2. + + -- Renan DelValle Wed, 26 Dec 2018 15:10:00 -0700 + australis (0.0.6) unstable; urgency=medium * Added auto-completion to the deb file.