2017-12-02 15:08:43 -08:00
|
|
|
package cmd
|
|
|
|
|
2017-12-03 12:41:23 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/paypal/gorealis"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2017-12-02 15:08:43 -08:00
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
2017-12-03 12:41:23 -08:00
|
|
|
Use: "australis",
|
|
|
|
Short: "australis is a client for Apache Aurora",
|
|
|
|
Long: `A light-weight command line client for use with Apache Aurora built using gorealis.`,
|
|
|
|
PersistentPreRun: connect,
|
|
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
// Make all children close the client by default upon terminating
|
|
|
|
client.Close()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-01-23 17:51:42 -08:00
|
|
|
var username, password, zkAddr, schedAddr string
|
2018-09-16 21:26:31 -07:00
|
|
|
var env, role, name = new(string), new(string), new(string)
|
2017-12-03 12:41:23 -08:00
|
|
|
var client realis.Realis
|
|
|
|
var monitor *realis.Monitor
|
2018-04-26 15:15:42 -07:00
|
|
|
var insecureSkipVerify bool
|
|
|
|
var caCertsPath string
|
|
|
|
var clientKey, clientCert string
|
2017-12-03 12:41:23 -08:00
|
|
|
|
2018-05-30 18:15:16 -07:00
|
|
|
var monitorInterval, monitorTimeout int
|
|
|
|
|
2017-12-03 12:41:23 -08:00
|
|
|
func init() {
|
2018-01-23 17:51:42 -08:00
|
|
|
rootCmd.PersistentFlags().StringVarP(&zkAddr, "zookeeper", "z", "", "Zookeeper node(s) where Aurora stores information.")
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&username, "username", "u", "", "Username to use for API authentication")
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&password, "password", "p", "", "Password to use for API authentication")
|
|
|
|
rootCmd.PersistentFlags().StringVarP(&schedAddr, "scheduler_addr", "s", "", "Aurora Scheduler's address.")
|
2018-04-26 15:15:42 -07:00
|
|
|
rootCmd.PersistentFlags().StringVarP(&clientKey, "clientKey", "k", "", "Client key 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", "", "CA certificates path to use.")
|
2018-04-29 18:55:59 -04:00
|
|
|
rootCmd.PersistentFlags().BoolVarP(&insecureSkipVerify, "insecureSkipVerify", "i", false, "Skip verification.")
|
2017-12-02 15:53:29 -08:00
|
|
|
}
|
2017-12-02 15:08:43 -08:00
|
|
|
|
2017-12-02 15:53:29 -08:00
|
|
|
func Execute() {
|
2017-12-02 15:08:43 -08:00
|
|
|
rootCmd.Execute()
|
2017-12-02 15:53:29 -08:00
|
|
|
}
|
2017-12-03 12:41:23 -08:00
|
|
|
|
|
|
|
func connect(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2018-01-23 17:51:42 -08:00
|
|
|
realisOptions := []realis.ClientOption{realis.BasicAuth(username, password),
|
2017-12-03 12:41:23 -08:00
|
|
|
realis.ThriftJSON(),
|
|
|
|
realis.TimeoutMS(20000),
|
2018-03-13 16:57:58 -07:00
|
|
|
realis.BackOff(realis.Backoff{
|
2017-12-03 12:41:23 -08:00
|
|
|
Steps: 2,
|
|
|
|
Duration: 10 * time.Second,
|
|
|
|
Factor: 2.0,
|
|
|
|
Jitter: 0.1,
|
2018-01-23 17:51:42 -08:00
|
|
|
})}
|
|
|
|
|
|
|
|
// Prefer zookeeper if both ways of connecting are provided
|
|
|
|
if zkAddr != "" {
|
2018-04-26 15:15:42 -07:00
|
|
|
// Configure Zookeeper to connect
|
|
|
|
zkOptions := []realis.ZKOpt{ realis.ZKEndpoints(zkAddr), realis.ZKPath("/aurora/scheduler")}
|
|
|
|
realisOptions = append(realisOptions, realis.ZookeeperOptions(zkOptions...))
|
2018-01-23 17:51:42 -08:00
|
|
|
} else if schedAddr != "" {
|
|
|
|
realisOptions = append(realisOptions, realis.SchedulerUrl(schedAddr))
|
|
|
|
} else {
|
|
|
|
fmt.Println("Zookeeper address or Scheduler URL must be provided.")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2018-10-19 12:29:17 -07:00
|
|
|
// Client certificate configuration if available
|
|
|
|
if clientKey != "" || clientCert != "" || caCertsPath != "" {
|
|
|
|
realisOptions = append(realisOptions,
|
|
|
|
realis.Certspath(caCertsPath),
|
|
|
|
realis.ClientCerts(clientKey, clientCert),
|
|
|
|
realis.InsecureSkipVerify(insecureSkipVerify))
|
|
|
|
}
|
|
|
|
|
2018-01-23 17:51:42 -08:00
|
|
|
// Connect to Aurora Scheduler and create a client object
|
|
|
|
client, err = realis.NewRealisClient(realisOptions...)
|
2017-12-03 12:41:23 -08:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
monitor = &realis.Monitor{Client: client}
|
|
|
|
|
|
|
|
}
|