gorealis v2 refactor (#5)

* Changing default timeout for start maintenance.

* Upgrading dependencies to gorealis v2 and thrift  0.12.0

* Refactored to update to gorealis v2.
This commit is contained in:
Renan DelValle 2018-12-27 11:31:51 -08:00 committed by GitHub
parent ad4dd9606e
commit 6ab5c9334d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1335 changed files with 137431 additions and 61530 deletions

View file

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

View file

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

View file

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

View file

@ -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_())
}
}

View file

@ -43,7 +43,7 @@ func init() {
// SLA Maintenance specific flags
startMaintenanceCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
startMaintenanceCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 1, "Time after which the monitor will stop polling and throw an error.")
startMaintenanceCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 10, "Time after which the monitor will stop polling and throw an error.")
}
var startCmd = &cobra.Command{
@ -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})

View file

@ -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_())
}
}