Adding flags to take in JSON from the command line.
This commit is contained in:
parent
1497aca2bb
commit
e0d400e85c
9 changed files with 45 additions and 20 deletions
|
@ -189,7 +189,7 @@ func createJob(cmd *cobra.Command, args []string) {
|
||||||
log.Fatal("unable to create Aurora job: ", err)
|
log.Fatal("unable to create Aurora job: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok, monitorErr := client.InstancesMonitor(auroraJob.JobKey(),
|
if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(),
|
||||||
auroraJob.GetInstanceCount(),
|
auroraJob.GetInstanceCount(),
|
||||||
5,
|
5,
|
||||||
50); !ok || monitorErr != nil {
|
50); !ok || monitorErr != nil {
|
||||||
|
|
|
@ -58,7 +58,7 @@ func killJob(cmd *cobra.Command, args []string) {
|
||||||
log.Fatalln(err)
|
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")
|
log.Fatalln("Unable to kill all instances of job")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func monitorHost(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval)
|
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)
|
maintenanceMonitorPrint(hostResult, maintenanceModes)
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ var pulseJobUpdateCmd = &cobra.Command{
|
||||||
|
|
||||||
func pulseJobUpdate(cmd *cobra.Command, args []string) {
|
func pulseJobUpdate(cmd *cobra.Command, args []string) {
|
||||||
_, err := client.PulseJobUpdate(
|
_, err := client.PulseJobUpdate(
|
||||||
&aurora.JobUpdateKey{
|
aurora.JobUpdateKey{
|
||||||
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
||||||
ID: updateID,
|
ID: updateID,
|
||||||
})
|
})
|
||||||
|
|
|
@ -37,7 +37,7 @@ var resumeJobUpdateCmd = &cobra.Command{
|
||||||
|
|
||||||
func resumeJobUpdate(cmd *cobra.Command, args []string) {
|
func resumeJobUpdate(cmd *cobra.Command, args []string) {
|
||||||
err := client.ResumeJobUpdate(
|
err := client.ResumeJobUpdate(
|
||||||
&aurora.JobUpdateKey{
|
aurora.JobUpdateKey{
|
||||||
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
||||||
ID: updateID,
|
ID: updateID,
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,6 +36,8 @@ var caCertsPath string
|
||||||
var clientKey, clientCert string
|
var clientKey, clientCert string
|
||||||
var configFile string
|
var configFile string
|
||||||
var toJson bool
|
var toJson bool
|
||||||
|
var fromJson bool
|
||||||
|
var fromJsonFile string
|
||||||
var logLevel string
|
var logLevel string
|
||||||
var duration time.Duration
|
var duration time.Duration
|
||||||
var percent float64
|
var percent float64
|
||||||
|
@ -43,10 +45,9 @@ var count int64
|
||||||
var filename string
|
var filename string
|
||||||
var message = new(string)
|
var message = new(string)
|
||||||
var updateID string
|
var updateID string
|
||||||
var statusList = make([]string, 0, 0)
|
|
||||||
var log = logrus.New()
|
var log = logrus.New()
|
||||||
|
|
||||||
const australisVer = "v0.0.10"
|
const australisVer = "v0.1.0"
|
||||||
|
|
||||||
var forceDrainTimeout time.Duration
|
var forceDrainTimeout time.Duration
|
||||||
|
|
||||||
|
|
44
cmd/start.go
44
cmd/start.go
|
@ -15,6 +15,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
|
@ -23,6 +24,8 @@ import (
|
||||||
|
|
||||||
const countFlag = "count"
|
const countFlag = "count"
|
||||||
const percentageFlag = "percentage"
|
const percentageFlag = "percentage"
|
||||||
|
const jsonFlag = "json"
|
||||||
|
const jsonFileFlag = "json-file"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(startCmd)
|
rootCmd.AddCommand(startCmd)
|
||||||
|
@ -34,6 +37,8 @@ func init() {
|
||||||
// Maintenance specific flags
|
// Maintenance specific flags
|
||||||
startDrainCmd.cmd.Flags().DurationVar(&startDrainCmd.monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
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().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 */
|
/* SLA Aware commands */
|
||||||
startCmd.AddCommand(startSLADrainCmd.cmd)
|
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(&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.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().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)
|
startCmd.AddCommand(startMaintenanceCmd.cmd)
|
||||||
startMaintenanceCmd.cmd.Run = maintenance
|
startMaintenanceCmd.cmd.Run = maintenance
|
||||||
|
@ -53,6 +60,8 @@ func init() {
|
||||||
// SLA Maintenance specific flags
|
// 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.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().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{
|
var startCmd = &cobra.Command{
|
||||||
|
@ -62,19 +71,19 @@ var startCmd = &cobra.Command{
|
||||||
|
|
||||||
var startDrainCmd = monitorCmdConfig{
|
var startDrainCmd = monitorCmdConfig{
|
||||||
cmd: &cobra.Command{
|
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.",
|
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
|
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 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
|
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.`,
|
expects a space separated list of hosts to place into maintenance mode.`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: argsValidateJSONFlags,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var startSLADrainCmd = monitorCmdConfig{
|
var startSLADrainCmd = monitorCmdConfig{
|
||||||
cmd: &cobra.Command{
|
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.",
|
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
|
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 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.
|
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
|
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.`,
|
when a Job does not have a defined SLA policy.`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: argsValidateJSONFlags,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var startMaintenanceCmd = monitorCmdConfig{
|
var startMaintenanceCmd = monitorCmdConfig{
|
||||||
cmd: &cobra.Command{
|
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.",
|
Short: "Place a list of space separated Mesos Agents into maintenance mode.",
|
||||||
Long: `Places Mesos Agent into Maintenance mode. Agents in this list
|
Long: `Places Mesos Agent into Maintenance mode. Agents in this list
|
||||||
are de-prioritized for scheduling a task. Command
|
are de-prioritized for scheduling a task. Command
|
||||||
expects a space separated list of hosts to place into maintenance mode.`,
|
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) {
|
func drain(cmd *cobra.Command, args []string) {
|
||||||
log.Infoln("Setting hosts to DRAINING")
|
log.Infoln("Setting hosts to DRAINING")
|
||||||
log.Infoln(args)
|
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)
|
log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval)
|
||||||
// Monitor change to DRAINING and DRAINED mode
|
// Monitor change to DRAINING and DRAINED mode
|
||||||
hostResult, err := client.HostMaintenanceMonitor(
|
hostResult, err := client.MonitorHostMaintenance(
|
||||||
args,
|
args,
|
||||||
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED},
|
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED},
|
||||||
startDrainCmd.monitorInterval,
|
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)
|
log.Infof("Monitoring for %v at %v intervals", timeout, interval)
|
||||||
// Monitor change to DRAINING and DRAINED mode
|
// Monitor change to DRAINING and DRAINED mode
|
||||||
hostResult, err := client.HostMaintenanceMonitor(
|
hostResult, err := client.MonitorHostMaintenance(
|
||||||
hosts,
|
hosts,
|
||||||
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED},
|
[]aurora.MaintenanceMode{aurora.MaintenanceMode_DRAINED},
|
||||||
interval,
|
interval,
|
||||||
|
@ -178,7 +202,7 @@ func maintenance(cmd *cobra.Command, args []string) {
|
||||||
log.Infoln(args)
|
log.Infoln(args)
|
||||||
result, err := client.StartMaintenance(args...)
|
result, err := client.StartMaintenance(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %+v\n", err)
|
log.Fatalf("error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugln(result)
|
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)
|
log.Infof("Monitoring for %v at %v intervals", monitorHostCmd.monitorTimeout, monitorHostCmd.monitorInterval)
|
||||||
|
|
||||||
// Monitor change to DRAINING and DRAINED mode
|
// Monitor change to DRAINING and DRAINED mode
|
||||||
hostResult, err := client.HostMaintenanceMonitor(
|
hostResult, err := client.MonitorHostMaintenance(
|
||||||
args,
|
args,
|
||||||
[]aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED},
|
[]aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED},
|
||||||
startMaintenanceCmd.monitorInterval,
|
startMaintenanceCmd.monitorInterval,
|
||||||
|
|
|
@ -66,13 +66,13 @@ func endMaintenance(cmd *cobra.Command, args []string) {
|
||||||
log.Println(args)
|
log.Println(args)
|
||||||
result, err := client.EndMaintenance(args...)
|
result, err := client.EndMaintenance(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %+v\n", err)
|
log.Fatalf("error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugln(result)
|
log.Debugln(result)
|
||||||
|
|
||||||
// Monitor change to NONE mode
|
// Monitor change to NONE mode
|
||||||
hostResult, err := client.HostMaintenanceMonitor(
|
hostResult, err := client.MonitorHostMaintenance(
|
||||||
args,
|
args,
|
||||||
[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE},
|
[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE},
|
||||||
stopMaintenanceConfig.monitorInterval,
|
stopMaintenanceConfig.monitorInterval,
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -4,7 +4,7 @@ require (
|
||||||
github.com/BurntSushi/toml v0.3.1 // indirect
|
github.com/BurntSushi/toml v0.3.1 // indirect
|
||||||
github.com/cpuguy83/go-md2man v1.0.10 // indirect
|
github.com/cpuguy83/go-md2man v1.0.10 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // 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/pkg/errors v0.0.0-20171216070316-e881fd58d78e
|
||||||
github.com/sirupsen/logrus v1.2.0
|
github.com/sirupsen/logrus v1.2.0
|
||||||
github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123
|
github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue