From 1497aca2bb8370b0759a71b5f414e3efb574835d Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Thu, 6 Feb 2020 18:48:44 -0800 Subject: [PATCH 1/5] Bumping up the version. --- CHANGELOG | 2 +- debian/changelog | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bc0e6e1..94bee08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -0.0.10 (unreleased) +0.1.0 (unreleased) 0.0.9 diff --git a/debian/changelog b/debian/changelog index fe0d744..405a1bf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -australis (0.0.10) unstable; urgency=medium +australis (0.1.0) unstable; urgency=medium * Unreleased From e0d400e85cdba4f9962e34e6bf025e69e6e07bd5 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Thu, 6 Feb 2020 18:49:21 -0800 Subject: [PATCH 2/5] Adding flags to take in JSON from the command line. --- cmd/create.go | 2 +- cmd/kill.go | 2 +- cmd/monitor.go | 2 +- cmd/pulse.go | 2 +- cmd/resume.go | 2 +- cmd/root.go | 5 +++-- cmd/start.go | 44 ++++++++++++++++++++++++++++++++++---------- cmd/stop.go | 4 ++-- go.mod | 2 +- 9 files changed, 45 insertions(+), 20 deletions(-) diff --git a/cmd/create.go b/cmd/create.go index 54033bd..d78d724 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -189,7 +189,7 @@ func createJob(cmd *cobra.Command, args []string) { log.Fatal("unable to create Aurora job: ", err) } - if ok, monitorErr := client.InstancesMonitor(auroraJob.JobKey(), + if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(), auroraJob.GetInstanceCount(), 5, 50); !ok || monitorErr != nil { diff --git a/cmd/kill.go b/cmd/kill.go index 5fb4086..fc79c0d 100644 --- a/cmd/kill.go +++ b/cmd/kill.go @@ -58,7 +58,7 @@ func killJob(cmd *cobra.Command, args []string) { log.Fatalln(err) } - if ok, err := client.InstancesMonitor(job.JobKey(), 0, 5, 50); !ok || err != nil { + if ok, err := client.MonitorInstances(job.JobKey(), 0, 5, 50); !ok || err != nil { log.Fatalln("Unable to kill all instances of job") } } diff --git a/cmd/monitor.go b/cmd/monitor.go index 55a1863..d1c0016 100644 --- a/cmd/monitor.go +++ b/cmd/monitor.go @@ -61,7 +61,7 @@ func monitorHost(cmd *cobra.Command, args []string) { } log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval) - hostResult, err := client.HostMaintenanceMonitor(args, maintenanceModes, monitorHostCmd.monitorInterval, monitorHostCmd.monitorTimeout) + hostResult, err := client.MonitorHostMaintenance(args, maintenanceModes, monitorHostCmd.monitorInterval, monitorHostCmd.monitorTimeout) maintenanceMonitorPrint(hostResult, maintenanceModes) diff --git a/cmd/pulse.go b/cmd/pulse.go index 7a3c2f9..38db2b7 100644 --- a/cmd/pulse.go +++ b/cmd/pulse.go @@ -36,7 +36,7 @@ var pulseJobUpdateCmd = &cobra.Command{ func pulseJobUpdate(cmd *cobra.Command, args []string) { _, err := client.PulseJobUpdate( - &aurora.JobUpdateKey{ + aurora.JobUpdateKey{ Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name}, ID: updateID, }) diff --git a/cmd/resume.go b/cmd/resume.go index 9c597c7..2b43497 100644 --- a/cmd/resume.go +++ b/cmd/resume.go @@ -37,7 +37,7 @@ var resumeJobUpdateCmd = &cobra.Command{ func resumeJobUpdate(cmd *cobra.Command, args []string) { err := client.ResumeJobUpdate( - &aurora.JobUpdateKey{ + aurora.JobUpdateKey{ Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name}, ID: updateID, }, diff --git a/cmd/root.go b/cmd/root.go index 25e19c9..84dbb02 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -36,6 +36,8 @@ var caCertsPath string var clientKey, clientCert string var configFile string var toJson bool +var fromJson bool +var fromJsonFile string var logLevel string var duration time.Duration var percent float64 @@ -43,10 +45,9 @@ var count int64 var filename string var message = new(string) var updateID string -var statusList = make([]string, 0, 0) var log = logrus.New() -const australisVer = "v0.0.10" +const australisVer = "v0.1.0" var forceDrainTimeout time.Duration diff --git a/cmd/start.go b/cmd/start.go index f32ddb7..20fb0a4 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -15,6 +15,7 @@ package cmd import ( + "errors" "time" "github.com/paypal/gorealis/v2/gen-go/apache/aurora" @@ -23,6 +24,8 @@ import ( const countFlag = "count" const percentageFlag = "percentage" +const jsonFlag = "json" +const jsonFileFlag = "json-file" func init() { rootCmd.AddCommand(startCmd) @@ -34,6 +37,8 @@ func init() { // Maintenance specific flags startDrainCmd.cmd.Flags().DurationVar(&startDrainCmd.monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.") startDrainCmd.cmd.Flags().DurationVar(&startDrainCmd.monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.") + startDrainCmd.cmd.Flags().StringVar(&fromJsonFile, jsonFileFlag, "", "JSON file to read list of agents from.") + startDrainCmd.cmd.Flags().BoolVar(&fromJson, jsonFlag, false, "Read JSON list of agents from the STDIN.") /* SLA Aware commands */ startCmd.AddCommand(startSLADrainCmd.cmd) @@ -46,6 +51,8 @@ func init() { startSLADrainCmd.cmd.Flags().DurationVar(&forceDrainTimeout, "sla-limit", time.Minute*60, "Time limit after which SLA-Aware drain sheds SLA Awareness.") startSLADrainCmd.cmd.Flags().DurationVar(&startSLADrainCmd.monitorInterval, "interval", time.Second*10, "Interval at which to poll scheduler.") startSLADrainCmd.cmd.Flags().DurationVar(&startSLADrainCmd.monitorTimeout, "timeout", time.Minute*20, "Time after which the monitor will stop polling and throw an error.") + startSLADrainCmd.cmd.Flags().StringVar(&fromJsonFile, jsonFileFlag, "", "JSON file to read list of agents from.") + startSLADrainCmd.cmd.Flags().BoolVar(&fromJson, jsonFlag, false, "Read JSON list of agents from the STDIN.") startCmd.AddCommand(startMaintenanceCmd.cmd) startMaintenanceCmd.cmd.Run = maintenance @@ -53,6 +60,8 @@ func init() { // SLA Maintenance specific flags startMaintenanceCmd.cmd.Flags().DurationVar(&startMaintenanceCmd.monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.") startMaintenanceCmd.cmd.Flags().DurationVar(&startMaintenanceCmd.monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.") + startMaintenanceCmd.cmd.Flags().StringVar(&fromJsonFile, jsonFileFlag, "", "JSON file to read list of agents from.") + startMaintenanceCmd.cmd.Flags().BoolVar(&fromJson, jsonFlag, false, "Read JSON list of agents from the STDIN.") } var startCmd = &cobra.Command{ @@ -62,19 +71,19 @@ var startCmd = &cobra.Command{ var startDrainCmd = monitorCmdConfig{ cmd: &cobra.Command{ - Use: "drain [space separated host list]", + Use: "drain [space separated host list or use JSON flags]", Short: "Place a list of space separated Mesos Agents into draining mode.", Long: `Adds a Mesos Agent to Aurora's Drain list. Agents in this list are not allowed to schedule new tasks and any tasks already running on this Agent are killed and rescheduled in an Agent that is not in maintenance mode. Command expects a space separated list of hosts to place into maintenance mode.`, - Args: cobra.MinimumNArgs(1), + Args: argsValidateJSONFlags, }, } var startSLADrainCmd = monitorCmdConfig{ cmd: &cobra.Command{ - Use: "sla-drain [space separated host list]", + Use: "sla-drain [space separated host list or use JSON flags]", Short: "Place a list of space separated Mesos Agents into maintenance mode using SLA aware strategies.", Long: `Adds a Mesos Agent to Aurora's Drain list. Agents in this list are not allowed to schedule new tasks and any tasks already running on this Agent @@ -84,21 +93,36 @@ If the --count argument is passed, tasks will be drained using the count SLA pol when a Job does not have a defined SLA policy. If the --percentage argument is passed, tasks will be drained using the percentage SLA policy as a fallback when a Job does not have a defined SLA policy.`, - Args: cobra.MinimumNArgs(1), + Args: argsValidateJSONFlags, }, } var startMaintenanceCmd = monitorCmdConfig{ cmd: &cobra.Command{ - Use: "maintenance [space separated host list]", + Use: "maintenance [space separated host list or use JSON flags]", Short: "Place a list of space separated Mesos Agents into maintenance mode.", Long: `Places Mesos Agent into Maintenance mode. Agents in this list are de-prioritized for scheduling a task. Command expects a space separated list of hosts to place into maintenance mode.`, - Args: cobra.MinimumNArgs(1), + Args: argsValidateJSONFlags, }, } +func argsValidateJSONFlags(cmd *cobra.Command, args []string) error { + if cmd.Flags().Changed(jsonFlag) && cmd.Flags().Changed(jsonFileFlag) { + return errors.New("only json file or json stdin must be set") + } + // These two flags are mutually exclusive + if cmd.Flags().Changed(jsonFlag) != cmd.Flags().Changed(jsonFileFlag) { + return nil + } + + if len(args) < 1 { + return errors.New("at least one host must be specified") + } + return nil +} + func drain(cmd *cobra.Command, args []string) { log.Infoln("Setting hosts to DRAINING") log.Infoln(args) @@ -111,7 +135,7 @@ func drain(cmd *cobra.Command, args []string) { log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval) // Monitor change to DRAINING and DRAINED mode - hostResult, err := client.HostMaintenanceMonitor( + hostResult, err := client.MonitorHostMaintenance( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}, startDrainCmd.monitorInterval, @@ -135,7 +159,7 @@ func slaDrainHosts(policy *aurora.SlaPolicy, interval, timeout time.Duration, ho log.Infof("Monitoring for %v at %v intervals", timeout, interval) // Monitor change to DRAINING and DRAINED mode - hostResult, err := client.HostMaintenanceMonitor( + hostResult, err := client.MonitorHostMaintenance( hosts, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}, interval, @@ -178,7 +202,7 @@ func maintenance(cmd *cobra.Command, args []string) { log.Infoln(args) result, err := client.StartMaintenance(args...) if err != nil { - log.Fatalf("error: %+v\n", err) + log.Fatalf("error: %+v", err) } log.Debugln(result) @@ -186,7 +210,7 @@ func maintenance(cmd *cobra.Command, args []string) { log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval) // Monitor change to DRAINING and DRAINED mode - hostResult, err := client.HostMaintenanceMonitor( + hostResult, err := client.MonitorHostMaintenance( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED}, startMaintenanceCmd.monitorInterval, diff --git a/cmd/stop.go b/cmd/stop.go index 0ff6cee..c170e1e 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -66,13 +66,13 @@ func endMaintenance(cmd *cobra.Command, args []string) { log.Println(args) result, err := client.EndMaintenance(args...) if err != nil { - log.Fatalf("error: %+v\n", err) + log.Fatalf("error: %+v", err) } log.Debugln(result) // Monitor change to NONE mode - hostResult, err := client.HostMaintenanceMonitor( + hostResult, err := client.MonitorHostMaintenance( args, []aurora.MaintenanceMode{aurora.MaintenanceMode_NONE}, stopMaintenanceConfig.monitorInterval, diff --git a/go.mod b/go.mod index bcc57ae..8e10a03 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/BurntSushi/toml v0.3.1 // indirect github.com/cpuguy83/go-md2man v1.0.10 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect - github.com/paypal/gorealis/v2 v2.0.1 + github.com/paypal/gorealis/v2 v2.21.0 github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e github.com/sirupsen/logrus v1.2.0 github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123 From b37462d00625a4c54a1791f6df5fe9d0feab5f95 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Thu, 6 Feb 2020 18:50:58 -0800 Subject: [PATCH 3/5] go.sum no longer strictly necessary since go1.13 --- go.sum | 62 ---------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 go.sum diff --git a/go.sum b/go.sum deleted file mode 100644 index f93d82c..0000000 --- a/go.sum +++ /dev/null @@ -1,62 +0,0 @@ -git.apache.org/thrift.git v0.12.0 h1:692K1/SsOcQvkvMRMdt60FCq2AvKpuQNM6sIeH3mN4s= -git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= -github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= -github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= -github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= -github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/paypal/gorealis/v2 v2.0.1 h1:7V9jjoeRWeVWaTm9Fgc08gWq1/k/sebVDe2WeFWAVGA= -github.com/paypal/gorealis/v2 v2.0.1/go.mod h1:mJz1e40v9vHyw8dDvzGvblHcCtFuJ+eo7yPjFYnowhE= -github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= -github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e h1:+RHxT/gm0O3UF7nLJbdNzAmULvCFt4XfXHWzh3XI/zs= -github.com/pkg/errors v0.0.0-20171216070316-e881fd58d78e/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= -github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/samuel/go-zookeeper v0.0.0-20171117190445-471cd4e61d7a h1:EYL2xz/Zdo0hyqdZMXR4lmT2O11jDLTPCEqIe/FR6W4= -github.com/samuel/go-zookeeper v0.0.0-20171117190445-471cd4e61d7a/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= -github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= -github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123 h1:q6iuSBmQzLC/v8wFROjMxVDNFXeev53yQKUtkoLhS10= -github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= -github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/viper v1.3.1 h1:5+8j8FTpnFV4nEImW/ofkzEt8VoOiLXxdYIDsB73T38= -github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0= -golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a h1:1n5lsVfiQW3yfsRGu98756EH1YthsFqr/5mxHduZW2A= -golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 05557a65c8727142d14e7eade6e25c3d5be6ae67 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Fri, 7 Feb 2020 18:36:33 -0800 Subject: [PATCH 4/5] Adding support for reading JSON list of hosts to drain from STDIN or from a file. --- cmd/start.go | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 20fb0a4..a9dddf1 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -15,7 +15,10 @@ package cmd import ( + "encoding/json" "errors" + "io/ioutil" + "os" "time" "github.com/paypal/gorealis/v2/gen-go/apache/aurora" @@ -123,10 +126,36 @@ func argsValidateJSONFlags(cmd *cobra.Command, args []string) error { return nil } +func hostList(cmd *cobra.Command, args []string) []string { + var hosts []string + if cmd.Flags().Changed(jsonFlag) { + err := json.NewDecoder(os.Stdin).Decode(&hosts) + if err != nil { + log.Fatal(err) + } + } else if cmd.Flags().Changed(jsonFileFlag) { + data, err := ioutil.ReadFile(fromJsonFile) + if err != nil { + log.Fatal(err) + } + + err = json.Unmarshal(data, &hosts) + if err != nil { + log.Fatal(err) + } + } else { + hosts = args + } + + return hosts +} + func drain(cmd *cobra.Command, args []string) { + hosts := hostList(cmd, args) + log.Infoln("Setting hosts to DRAINING") - log.Infoln(args) - result, err := client.DrainHosts(args...) + log.Infoln(hosts) + result, err := client.DrainHosts(hosts...) if err != nil { log.Fatalf("error: %+v", err) } @@ -136,7 +165,7 @@ func drain(cmd *cobra.Command, args []string) { log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval) // Monitor change to DRAINING and DRAINED mode hostResult, err := client.MonitorHostMaintenance( - args, + hosts, []aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED}, startDrainCmd.monitorInterval, startDrainCmd.monitorTimeout) @@ -149,7 +178,6 @@ func drain(cmd *cobra.Command, args []string) { } func slaDrainHosts(policy *aurora.SlaPolicy, interval, timeout time.Duration, hosts ...string) { - result, err := client.SLADrainHosts(policy, int64(forceDrainTimeout.Seconds()), hosts...) if err != nil { log.Fatalf("error: %+v\n", err) @@ -172,6 +200,8 @@ func slaDrainHosts(policy *aurora.SlaPolicy, interval, timeout time.Duration, ho } } func slaDrain(cmd *cobra.Command, args []string) { + hosts := hostList(cmd, args) + // This check makes sure only a single flag is set. // If they're both set or both not set, the statement will evaluate to true. if cmd.Flags().Changed(percentageFlag) == cmd.Flags().Changed(countFlag) { @@ -194,13 +224,15 @@ func slaDrain(cmd *cobra.Command, args []string) { } log.Infoln("Hosts affected: ", args) - slaDrainHosts(policy, startDrainCmd.monitorInterval, startDrainCmd.monitorTimeout, args...) + slaDrainHosts(policy, startDrainCmd.monitorInterval, startDrainCmd.monitorTimeout, hosts...) } func maintenance(cmd *cobra.Command, args []string) { + hosts := hostList(cmd, args) + log.Infoln("Setting hosts to Maintenance mode") - log.Infoln(args) - result, err := client.StartMaintenance(args...) + log.Infoln(hosts) + result, err := client.StartMaintenance(hosts...) if err != nil { log.Fatalf("error: %+v", err) } @@ -211,7 +243,7 @@ func maintenance(cmd *cobra.Command, args []string) { // Monitor change to DRAINING and DRAINED mode hostResult, err := client.MonitorHostMaintenance( - args, + hosts, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED}, startMaintenanceCmd.monitorInterval, startMaintenanceCmd.monitorTimeout) From d3b8d05a6a17eee71847c7308c3f83ed0460ebcb Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Fri, 7 Feb 2020 18:40:02 -0800 Subject: [PATCH 5/5] Adding changes to changelogs --- CHANGELOG | 2 ++ debian/changelog | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 94bee08..72753ac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ 0.1.0 (unreleased) +* Adding support for drain sub-command to take in JSON list from stdin or from a specified file. +* Added flags `json-file` and `json` to drain, maintenance, and sla-drain. 0.0.9 diff --git a/debian/changelog b/debian/changelog index 405a1bf..33fbbb7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ australis (0.1.0) unstable; urgency=medium - * Unreleased + * Adding support for drain sub-command to take in JSON list from stdin or from a specified file. + * Added flags json-file and json to drain, maintenance, and sla-drain. -- Renan DelValle Wed, 29 Jan 2020 15:10:00 -0700