goimports style fixes.
This commit is contained in:
parent
4551231644
commit
616d4bc57e
9 changed files with 125 additions and 131 deletions
12
cmd/fetch.go
12
cmd/fetch.go
|
@ -3,7 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2"
|
realis "github.com/paypal/gorealis/v2"
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
@ -29,7 +29,6 @@ func init() {
|
||||||
taskStatusCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
taskStatusCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
||||||
taskStatusCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
taskStatusCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
||||||
|
|
||||||
|
|
||||||
/* Fetch Leader */
|
/* Fetch Leader */
|
||||||
leaderCmd.Flags().String("zkPath", "/aurora/scheduler", "Zookeeper node path where leader election happens")
|
leaderCmd.Flags().String("zkPath", "/aurora/scheduler", "Zookeeper node path where leader election happens")
|
||||||
|
|
||||||
|
@ -37,9 +36,9 @@ func init() {
|
||||||
|
|
||||||
// Hijack help function to hide unnecessary global flags
|
// Hijack help function to hide unnecessary global flags
|
||||||
help := leaderCmd.HelpFunc()
|
help := leaderCmd.HelpFunc()
|
||||||
leaderCmd.SetHelpFunc(func(cmd *cobra.Command, s []string){
|
leaderCmd.SetHelpFunc(func(cmd *cobra.Command, s []string) {
|
||||||
if cmd.HasInheritedFlags(){
|
if cmd.HasInheritedFlags() {
|
||||||
cmd.InheritedFlags().VisitAll(func(f *pflag.Flag){
|
cmd.InheritedFlags().VisitAll(func(f *pflag.Flag) {
|
||||||
if f.Name != "logLevel" {
|
if f.Name != "logLevel" {
|
||||||
f.Hidden = true
|
f.Hidden = true
|
||||||
}
|
}
|
||||||
|
@ -66,7 +65,6 @@ var fetchTaskCmd = &cobra.Command{
|
||||||
Short: "Task information from Aurora",
|
Short: "Task information from Aurora",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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.",
|
||||||
|
@ -86,7 +84,7 @@ var leaderCmd = &cobra.Command{
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {}, //We don't need a realis client for this cmd
|
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
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {}, //We don't need a realis client for this cmd
|
||||||
PreRun: setConfig,
|
PreRun: setConfig,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
Short: "Fetch current Aurora leader given Zookeeper nodes. ",
|
Short: "Fetch current Aurora leader given Zookeeper nodes. ",
|
||||||
Long: `Gets the current leading aurora scheduler instance using information from Zookeeper path.
|
Long: `Gets the current leading aurora scheduler instance using information from Zookeeper path.
|
||||||
Pass Zookeeper nodes separated by a space as an argument to this command.`,
|
Pass Zookeeper nodes separated by a space as an argument to this command.`,
|
||||||
|
|
20
cmd/force.go
20
cmd/force.go
|
@ -12,7 +12,7 @@ func init() {
|
||||||
|
|
||||||
// Sub-commands
|
// Sub-commands
|
||||||
forceCmd.AddCommand(forceSnapshotCmd)
|
forceCmd.AddCommand(forceSnapshotCmd)
|
||||||
forceCmd.AddCommand(forceBackupCmd)
|
forceCmd.AddCommand(forceBackupCmd)
|
||||||
|
|
||||||
// Recon sub-commands
|
// Recon sub-commands
|
||||||
forceCmd.AddCommand(reconCmd)
|
forceCmd.AddCommand(reconCmd)
|
||||||
|
@ -30,7 +30,7 @@ var forceSnapshotCmd = &cobra.Command{
|
||||||
Short: "Force the leading scheduler to perform a Snapshot.",
|
Short: "Force the leading scheduler to perform a Snapshot.",
|
||||||
Long: `Takes a Snapshot of the in memory state of the Apache Aurora cluster and
|
Long: `Takes a Snapshot of the in memory state of the Apache Aurora cluster and
|
||||||
writes it to the Mesos replicated log. This should NOT be confused with a backup.`,
|
writes it to the Mesos replicated log. This should NOT be confused with a backup.`,
|
||||||
Run: snapshot,
|
Run: snapshot,
|
||||||
}
|
}
|
||||||
|
|
||||||
func snapshot(cmd *cobra.Command, args []string) {
|
func snapshot(cmd *cobra.Command, args []string) {
|
||||||
|
@ -48,7 +48,7 @@ var forceBackupCmd = &cobra.Command{
|
||||||
Short: "Force the leading scheduler to perform a Backup.",
|
Short: "Force the leading scheduler to perform a Backup.",
|
||||||
Long: `Force the Aurora Scheduler to write a backup of the latest snapshot to the filesystem
|
Long: `Force the Aurora Scheduler to write a backup of the latest snapshot to the filesystem
|
||||||
of the leading scheduler.`,
|
of the leading scheduler.`,
|
||||||
Run: backup,
|
Run: backup,
|
||||||
}
|
}
|
||||||
|
|
||||||
func backup(cmd *cobra.Command, args []string) {
|
func backup(cmd *cobra.Command, args []string) {
|
||||||
|
@ -95,16 +95,16 @@ func explicitRecon(cmd *cobra.Command, args []string) {
|
||||||
case 1:
|
case 1:
|
||||||
log.Infof("Using %v as batch size for explicit recon.\n", args[0])
|
log.Infof("Using %v as batch size for explicit recon.\n", args[0])
|
||||||
|
|
||||||
// Get batch size from args and convert it to the right format
|
// Get batch size from args and convert it to the right format
|
||||||
batchInt, err := strconv.Atoi(args[0])
|
batchInt, err := strconv.Atoi(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error: %+v\n", err)
|
log.Fatalf("error: %+v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
batchInt32 := int32(batchInt)
|
batchInt32 := int32(batchInt)
|
||||||
batchSize = &batchInt32
|
batchSize = &batchInt32
|
||||||
default:
|
default:
|
||||||
log.Fatalln("Provide 0 arguments to use default batch size or one argument to use a custom batch size.")
|
log.Fatalln("Provide 0 arguments to use default batch size or one argument to use a custom batch size.")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.ForceExplicitTaskReconciliation(batchSize)
|
err := client.ForceExplicitTaskReconciliation(batchSize)
|
||||||
|
@ -120,7 +120,7 @@ var forceImplicitReconCmd = &cobra.Command{
|
||||||
Short: "Force the leading scheduler to perform an implicit recon.",
|
Short: "Force the leading scheduler to perform an implicit recon.",
|
||||||
Long: `Forces leading scheduler to ask Mesos Master for a list of the latest state for
|
Long: `Forces leading scheduler to ask Mesos Master for a list of the latest state for
|
||||||
all currently known non-terminal tasks being run by Aurora.`,
|
all currently known non-terminal tasks being run by Aurora.`,
|
||||||
Run: implicitRecon,
|
Run: implicitRecon,
|
||||||
}
|
}
|
||||||
|
|
||||||
func implicitRecon(cmd *cobra.Command, args []string) {
|
func implicitRecon(cmd *cobra.Command, args []string) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/paypal/gorealis/v2"
|
realis "github.com/paypal/gorealis/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,52 +1,51 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(rollbackCmd)
|
rootCmd.AddCommand(rollbackCmd)
|
||||||
|
|
||||||
rollbackCmd.AddCommand(rollbackUpdateCmd)
|
rollbackCmd.AddCommand(rollbackUpdateCmd)
|
||||||
rollbackUpdateCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
|
rollbackUpdateCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
|
||||||
rollbackUpdateCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
rollbackUpdateCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
||||||
rollbackUpdateCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
rollbackUpdateCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
||||||
rollbackUpdateCmd.Flags().StringVar(&updateID, "id", "", "Update ID")
|
rollbackUpdateCmd.Flags().StringVar(&updateID, "id", "", "Update ID")
|
||||||
rollbackUpdateCmd.Flags().StringVar(message, "message", "", "Message to store alongside resume event")
|
rollbackUpdateCmd.Flags().StringVar(message, "message", "", "Message to store alongside resume event")
|
||||||
rollbackUpdateCmd.MarkFlagRequired("environment")
|
rollbackUpdateCmd.MarkFlagRequired("environment")
|
||||||
rollbackUpdateCmd.MarkFlagRequired("role")
|
rollbackUpdateCmd.MarkFlagRequired("role")
|
||||||
rollbackUpdateCmd.MarkFlagRequired("name")
|
rollbackUpdateCmd.MarkFlagRequired("name")
|
||||||
rollbackUpdateCmd.MarkFlagRequired("id")
|
rollbackUpdateCmd.MarkFlagRequired("id")
|
||||||
}
|
}
|
||||||
|
|
||||||
var rollbackCmd = &cobra.Command{
|
var rollbackCmd = &cobra.Command{
|
||||||
Use: "rollback",
|
Use: "rollback",
|
||||||
Short: "rollback an operation such as an Update",
|
Short: "rollback an operation such as an Update",
|
||||||
}
|
}
|
||||||
|
|
||||||
var rollbackUpdateCmd = &cobra.Command{
|
var rollbackUpdateCmd = &cobra.Command{
|
||||||
Use: "update",
|
Use: "update",
|
||||||
Short: "rollback an update that is currently paused",
|
Short: "rollback an update that is currently paused",
|
||||||
Run: rollbackUpdate,
|
Run: rollbackUpdate,
|
||||||
}
|
}
|
||||||
|
|
||||||
func rollbackUpdate(cmd *cobra.Command, args []string) {
|
func rollbackUpdate(cmd *cobra.Command, args []string) {
|
||||||
var updateMessage string
|
var updateMessage string
|
||||||
if message != nil {
|
if message != nil {
|
||||||
updateMessage = *message
|
updateMessage = *message
|
||||||
}
|
}
|
||||||
err := client.RollbackJobUpdate(aurora.JobUpdateKey{
|
err := client.RollbackJobUpdate(aurora.JobUpdateKey{
|
||||||
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
Job: &aurora.JobKey{Environment: *env, Role: *role, Name: *name},
|
||||||
ID: updateID,
|
ID: updateID,
|
||||||
}, updateMessage)
|
}, updateMessage)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Rollback update for update ID %v sent successfully\n", updateID)
|
fmt.Printf("Rollback update for update ID %v sent successfully\n", updateID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
72
cmd/root.go
72
cmd/root.go
|
@ -1,11 +1,12 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/viper"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
realis "github.com/paypal/gorealis/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -46,9 +47,9 @@ func init() {
|
||||||
rootCmd.PersistentFlags().StringVarP(&clientCert, "clientCert", "c", "", "Client certificate to use to connect to Aurora.")
|
rootCmd.PersistentFlags().StringVarP(&clientCert, "clientCert", "c", "", "Client certificate to use to connect to Aurora.")
|
||||||
rootCmd.PersistentFlags().StringVarP(&caCertsPath, "caCertsPath", "a", "", "Path where CA certificates can be found.")
|
rootCmd.PersistentFlags().StringVarP(&caCertsPath, "caCertsPath", "a", "", "Path where CA certificates can be found.")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&skipCertVerification, "skipCertVerification", "i", false, "Skip CA certificate hostname verification.")
|
rootCmd.PersistentFlags().BoolVarP(&skipCertVerification, "skipCertVerification", "i", false, "Skip CA certificate hostname verification.")
|
||||||
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/aurora/australis.yml", "Config file to use.")
|
rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/aurora/australis.yml", "Config file to use.")
|
||||||
rootCmd.PersistentFlags().BoolVar(&toJson, "toJSON", false, "Print output in JSON format.")
|
rootCmd.PersistentFlags().BoolVar(&toJson, "toJSON", false, "Print output in JSON format.")
|
||||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "logLevel", "l", "info", "Set logging level [" + getLoggingLevels() + "].")
|
rootCmd.PersistentFlags().StringVarP(&logLevel, "logLevel", "l", "info", "Set logging level ["+getLoggingLevels()+"].")
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
|
@ -79,45 +80,44 @@ func setConfig(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(cmd *cobra.Command, args []string) {
|
func connect(cmd *cobra.Command, args []string) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
setConfig(cmd, args)
|
||||||
|
|
||||||
setConfig(cmd, args)
|
zkAddrSlice := strings.Split(zkAddr, ",")
|
||||||
|
|
||||||
zkAddrSlice := strings.Split(zkAddr, ",")
|
viper.SetConfigFile(configFile)
|
||||||
|
err = viper.ReadInConfig()
|
||||||
|
if err == nil {
|
||||||
|
// Best effort load configuration. Will only set config values when flags have not set them already.
|
||||||
|
if viper.IsSet("zk") && len(zkAddrSlice) == 1 && zkAddrSlice[0] == "" {
|
||||||
|
zkAddrSlice = viper.GetStringSlice("zk")
|
||||||
|
}
|
||||||
|
|
||||||
viper.SetConfigFile(configFile)
|
if viper.IsSet("username") && username == "" {
|
||||||
err = viper.ReadInConfig()
|
username = viper.GetString("username")
|
||||||
if err == nil {
|
}
|
||||||
// Best effort load configuration. Will only set config values when flags have not set them already.
|
|
||||||
if viper.IsSet("zk") && len(zkAddrSlice) == 1 && zkAddrSlice[0] == "" {
|
|
||||||
zkAddrSlice = viper.GetStringSlice("zk")
|
|
||||||
}
|
|
||||||
|
|
||||||
if viper.IsSet("username") && username == "" {
|
if viper.IsSet("password") && password == "" {
|
||||||
username = viper.GetString("username")
|
password = viper.GetString("password")
|
||||||
}
|
}
|
||||||
|
|
||||||
if viper.IsSet("password") && password == "" {
|
if viper.IsSet("clientKey") && clientKey == "" {
|
||||||
password = viper.GetString("password")
|
clientKey = viper.GetString("clientKey")
|
||||||
}
|
}
|
||||||
|
|
||||||
if viper.IsSet("clientKey") && clientKey == "" {
|
if viper.IsSet("clientCert") && clientCert == "" {
|
||||||
clientKey = viper.GetString("clientKey")
|
clientCert = viper.GetString("clientCert")
|
||||||
}
|
}
|
||||||
|
|
||||||
if viper.IsSet("clientCert") && clientCert == "" {
|
if viper.IsSet("caCertsPath") && caCertsPath == "" {
|
||||||
clientCert = viper.GetString("clientCert")
|
caCertsPath = viper.GetString("caCertsPath")
|
||||||
}
|
}
|
||||||
|
|
||||||
if viper.IsSet("caCertsPath") && caCertsPath == "" {
|
if viper.IsSet("skipCertVerification") && !skipCertVerification {
|
||||||
caCertsPath = viper.GetString("caCertsPath")
|
skipCertVerification = viper.GetBool("skipCertVerification")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if viper.IsSet("skipCertVerification") && !skipCertVerification {
|
|
||||||
skipCertVerification = viper.GetBool("skipCertVerification")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
realisOptions := []realis.ClientOption{realis.BasicAuth(username, password),
|
realisOptions := []realis.ClientOption{realis.BasicAuth(username, password),
|
||||||
realis.ThriftJSON(),
|
realis.ThriftJSON(),
|
||||||
|
@ -133,7 +133,7 @@ func connect(cmd *cobra.Command, args []string) {
|
||||||
// Prefer zookeeper if both ways of connecting are provided
|
// Prefer zookeeper if both ways of connecting are provided
|
||||||
if len(zkAddrSlice) > 0 && zkAddrSlice[0] != "" {
|
if len(zkAddrSlice) > 0 && zkAddrSlice[0] != "" {
|
||||||
// Configure Zookeeper to connect
|
// Configure Zookeeper to connect
|
||||||
zkOptions := []realis.ZKOpt{ realis.ZKEndpoints(zkAddrSlice...), realis.ZKPath("/aurora/scheduler")}
|
zkOptions := []realis.ZKOpt{realis.ZKEndpoints(zkAddrSlice...), realis.ZKPath("/aurora/scheduler")}
|
||||||
realisOptions = append(realisOptions, realis.ZookeeperOptions(zkOptions...))
|
realisOptions = append(realisOptions, realis.ZookeeperOptions(zkOptions...))
|
||||||
} else if schedAddr != "" {
|
} else if schedAddr != "" {
|
||||||
realisOptions = append(realisOptions, realis.SchedulerUrl(schedAddr))
|
realisOptions = append(realisOptions, realis.SchedulerUrl(schedAddr))
|
||||||
|
|
|
@ -2,10 +2,11 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -32,7 +33,7 @@ var setQuotaCmd = &cobra.Command{
|
||||||
|
|
||||||
*role = args[0]
|
*role = args[0]
|
||||||
|
|
||||||
for i:=1; i < len(args); i++ {
|
for i := 1; i < len(args); i++ {
|
||||||
resourcePair := strings.Split(args[i], ":")
|
resourcePair := strings.Split(args[i], ":")
|
||||||
|
|
||||||
if len(resourcePair) != 2 {
|
if len(resourcePair) != 2 {
|
||||||
|
@ -53,7 +54,7 @@ var setQuotaCmd = &cobra.Command{
|
||||||
return errors.Wrap(err, "unable to convert RAM value provided to a integer number")
|
return errors.Wrap(err, "unable to convert RAM value provided to a integer number")
|
||||||
}
|
}
|
||||||
|
|
||||||
case "disk":
|
case "disk":
|
||||||
disk, err = strconv.ParseInt(resourcePair[1], 10, 64)
|
disk, err = strconv.ParseInt(resourcePair[1], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "unable to convert DISK value provided to a integer number")
|
return errors.Wrap(err, "unable to convert DISK value provided to a integer number")
|
||||||
|
|
32
cmd/start.go
32
cmd/start.go
|
@ -1,47 +1,46 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(startCmd)
|
rootCmd.AddCommand(startCmd)
|
||||||
|
|
||||||
|
|
||||||
// Sub-commands
|
// Sub-commands
|
||||||
startCmd.AddCommand(startDrainCmd)
|
startCmd.AddCommand(startDrainCmd)
|
||||||
|
|
||||||
// Maintenance specific flags
|
// Maintenance specific flags
|
||||||
startDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
|
startDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||||
startDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 10, "Time after which the monitor will stop polling and throw an error.")
|
startDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*10, "Time after which the monitor will stop polling and throw an error.")
|
||||||
|
|
||||||
startCmd.AddCommand(startSLADrainCmd)
|
startCmd.AddCommand(startSLADrainCmd)
|
||||||
|
|
||||||
|
|
||||||
/* SLA Aware commands */
|
/* SLA Aware commands */
|
||||||
startSLADrainCmd.AddCommand(startSLACountDrainCmd)
|
startSLADrainCmd.AddCommand(startSLACountDrainCmd)
|
||||||
|
|
||||||
// SLA Maintenance specific flags
|
// SLA Maintenance specific flags
|
||||||
startSLACountDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
|
startSLACountDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||||
startSLACountDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 20, "Time after which the monitor will stop polling and throw an error.")
|
startSLACountDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*20, "Time after which the monitor will stop polling and throw an error.")
|
||||||
startSLACountDrainCmd.Flags().Int64Var(&count, "count", 5, "Instances count that should be running to meet SLA.")
|
startSLACountDrainCmd.Flags().Int64Var(&count, "count", 5, "Instances count that should be running to meet SLA.")
|
||||||
startSLACountDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute * 10, "Window of time from which we derive the SLA.")
|
startSLACountDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute*10, "Window of time from which we derive the SLA.")
|
||||||
|
|
||||||
startSLADrainCmd.AddCommand(startSLAPercentageDrainCmd)
|
startSLADrainCmd.AddCommand(startSLAPercentageDrainCmd)
|
||||||
|
|
||||||
// SLA Maintenance specific flags
|
// SLA Maintenance specific flags
|
||||||
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
|
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||||
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 1, "Time after which the monitor will stop polling and throw an error.")
|
startSLAPercentageDrainCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*1, "Time after which the monitor will stop polling and throw an error.")
|
||||||
startSLAPercentageDrainCmd.Flags().Float64Var(&percent, "percent", 75.0, "Percentage of instances that should be running to meet SLA.")
|
startSLAPercentageDrainCmd.Flags().Float64Var(&percent, "percent", 75.0, "Percentage of instances that should be running to meet SLA.")
|
||||||
startSLAPercentageDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute * 10, "Window of time from which we derive the SLA.")
|
startSLAPercentageDrainCmd.Flags().DurationVar(&duration, "duration", time.Minute*10, "Window of time from which we derive the SLA.")
|
||||||
|
|
||||||
startCmd.AddCommand(startMaintenanceCmd)
|
startCmd.AddCommand(startMaintenanceCmd)
|
||||||
|
|
||||||
// SLA Maintenance specific flags
|
// SLA Maintenance specific flags
|
||||||
startMaintenanceCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
|
startMaintenanceCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||||
startMaintenanceCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 10, "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{
|
var startCmd = &cobra.Command{
|
||||||
|
@ -150,7 +149,7 @@ func SLACountDrain(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
slaDrain(&aurora.SlaPolicy{
|
slaDrain(&aurora.SlaPolicy{
|
||||||
CountSlaPolicy: &aurora.CountSlaPolicy{Count: count, DurationSecs: int64(duration.Seconds())}},
|
CountSlaPolicy: &aurora.CountSlaPolicy{Count: count, DurationSecs: int64(duration.Seconds())}},
|
||||||
args...)
|
args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SLAPercentageDrain(cmd *cobra.Command, args []string) {
|
func SLAPercentageDrain(cmd *cobra.Command, args []string) {
|
||||||
|
@ -159,7 +158,7 @@ func SLAPercentageDrain(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
slaDrain(&aurora.SlaPolicy{
|
slaDrain(&aurora.SlaPolicy{
|
||||||
PercentageSlaPolicy: &aurora.PercentageSlaPolicy{Percentage: percent, DurationSecs: int64(duration.Seconds())}},
|
PercentageSlaPolicy: &aurora.PercentageSlaPolicy{Percentage: percent, DurationSecs: int64(duration.Seconds())}},
|
||||||
args...)
|
args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func maintenance(cmd *cobra.Command, args []string) {
|
func maintenance(cmd *cobra.Command, args []string) {
|
||||||
|
@ -179,7 +178,6 @@ func maintenance(cmd *cobra.Command, args []string) {
|
||||||
monitorInterval,
|
monitorInterval,
|
||||||
monitorTimeout)
|
monitorTimeout)
|
||||||
|
|
||||||
|
|
||||||
maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED})
|
maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_SCHEDULED})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,8 +12,8 @@ func init() {
|
||||||
|
|
||||||
// Stop subcommands
|
// Stop subcommands
|
||||||
stopCmd.AddCommand(stopMaintCmd)
|
stopCmd.AddCommand(stopMaintCmd)
|
||||||
stopMaintCmd.Flags().DurationVar(&monitorInterval,"interval", time.Second * 5, "Interval at which to poll scheduler.")
|
stopMaintCmd.Flags().DurationVar(&monitorInterval, "interval", time.Second*5, "Interval at which to poll scheduler.")
|
||||||
stopMaintCmd.Flags().DurationVar(&monitorTimeout,"timeout", time.Minute * 1, "Time after which the monitor will stop polling and throw an error.")
|
stopMaintCmd.Flags().DurationVar(&monitorTimeout, "timeout", time.Minute*1, "Time after which the monitor will stop polling and throw an error.")
|
||||||
|
|
||||||
// Stop update
|
// Stop update
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func endMaintenance(cmd *cobra.Command, args []string) {
|
||||||
monitorInterval,
|
monitorInterval,
|
||||||
monitorTimeout)
|
monitorTimeout)
|
||||||
|
|
||||||
maintenanceMonitorPrint(hostResult,[]aurora.MaintenanceMode{aurora.MaintenanceMode_NONE})
|
maintenanceMonitorPrint(hostResult, []aurora.MaintenanceMode{aurora.MaintenanceMode_NONE})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("error: %+v", err)
|
log.Fatalln("error: %+v", err)
|
||||||
|
|
40
cmd/util.go
40
cmd/util.go
|
@ -1,9 +1,9 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -11,38 +11,36 @@ import (
|
||||||
|
|
||||||
func toJSON(v interface{}) string {
|
func toJSON(v interface{}) string {
|
||||||
|
|
||||||
output, err := json.Marshal(v)
|
output, err := json.Marshal(v)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Unable to serialize Aurora response: %+v", v)
|
log.Fatalln("Unable to serialize Aurora response: %+v", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(output)
|
return string(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func getLoggingLevels() string {
|
func getLoggingLevels() string {
|
||||||
|
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
for _, level := range logrus.AllLevels {
|
for _, level := range logrus.AllLevels {
|
||||||
buffer.WriteString(level.String())
|
buffer.WriteString(level.String())
|
||||||
buffer.WriteString(" ")
|
buffer.WriteString(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.Truncate(buffer.Len()-1)
|
buffer.Truncate(buffer.Len() - 1)
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode) {
|
func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.MaintenanceMode) {
|
||||||
if len(hostResult) > 0 {
|
if len(hostResult) > 0 {
|
||||||
// Create anonymous struct for JSON formatting
|
// Create anonymous struct for JSON formatting
|
||||||
output := struct{
|
output := struct {
|
||||||
DesiredStates []string `json:desired_states`
|
DesiredStates []string `json:desired_states`
|
||||||
Transitioned []string `json:transitioned`
|
Transitioned []string `json:transitioned`
|
||||||
NonTransitioned []string `json:non-transitioned`
|
NonTransitioned []string `json:non-transitioned`
|
||||||
}{
|
}{
|
||||||
make([]string, 0),
|
make([]string, 0),
|
||||||
|
@ -50,7 +48,7 @@ func maintenanceMonitorPrint(hostResult map[string]bool, desiredStates []aurora.
|
||||||
make([]string, 0),
|
make([]string, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _,state := range desiredStates {
|
for _, state := range desiredStates {
|
||||||
output.DesiredStates = append(output.DesiredStates, state.String())
|
output.DesiredStates = append(output.DesiredStates, state.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue