Adding fetch task status. Changed how logrus is used to be able to be passed down to gorealis.
This commit is contained in:
parent
2abd691a1c
commit
4551231644
10 changed files with 72 additions and 29 deletions
|
@ -2,8 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
70
cmd/fetch.go
70
cmd/fetch.go
|
@ -2,13 +2,11 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/pflag"
|
|
||||||
|
|
||||||
"github.com/paypal/gorealis/v2"
|
"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"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -17,11 +15,21 @@ func init() {
|
||||||
// Sub-commands
|
// Sub-commands
|
||||||
|
|
||||||
// Fetch Task Config
|
// Fetch Task Config
|
||||||
fetchCmd.AddCommand(taskConfigCmd)
|
fetchCmd.AddCommand(fetchTaskCmd)
|
||||||
|
|
||||||
|
// Fetch Task Config
|
||||||
|
fetchTaskCmd.AddCommand(taskConfigCmd)
|
||||||
taskConfigCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
|
taskConfigCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
|
||||||
taskConfigCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
taskConfigCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
||||||
taskConfigCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
taskConfigCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
|
||||||
|
|
||||||
|
// Fetch Task Status
|
||||||
|
fetchTaskCmd.AddCommand(taskStatusCmd)
|
||||||
|
taskStatusCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
|
||||||
|
taskStatusCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
|
||||||
|
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")
|
||||||
|
|
||||||
|
@ -53,11 +61,24 @@ var fetchCmd = &cobra.Command{
|
||||||
Short: "Fetch information from Aurora",
|
Short: "Fetch information from Aurora",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fetchTaskCmd = &cobra.Command{
|
||||||
|
Use: "task",
|
||||||
|
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.",
|
||||||
Long: `To be written.`,
|
Long: `To be written.`,
|
||||||
Run: fetchTasks,
|
Run: fetchTasksConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
var taskStatusCmd = &cobra.Command{
|
||||||
|
Use: "status",
|
||||||
|
Short: "Fetch task status for a Job key.",
|
||||||
|
Long: `To be written.`,
|
||||||
|
Run: fetchTasksStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
var leaderCmd = &cobra.Command{
|
var leaderCmd = &cobra.Command{
|
||||||
|
@ -83,11 +104,11 @@ var fetchStatusCmd = &cobra.Command{
|
||||||
Use: "status",
|
Use: "status",
|
||||||
Short: "Fetch the maintenance status of a node from Aurora",
|
Short: "Fetch the maintenance status of a node from Aurora",
|
||||||
Long: `This command will print the actual status of the mesos agent nodes in Aurora server`,
|
Long: `This command will print the actual status of the mesos agent nodes in Aurora server`,
|
||||||
Run: fetchStatus,
|
Run: fetchHostStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchTasks(cmd *cobra.Command, args []string) {
|
func fetchTasksConfig(cmd *cobra.Command, args []string) {
|
||||||
fmt.Printf("Fetching job configuration for [%s/%s/%s] \n", env, role, name)
|
log.Infof("Fetching job configuration for [%s/%s/%s] \n", *env, *role, *name)
|
||||||
|
|
||||||
// Task Query takes nil for values it shouldn't need to match against.
|
// Task Query takes nil for values it shouldn't need to match against.
|
||||||
// This allows us to potentially more expensive calls for specific environments, roles, or job names.
|
// This allows us to potentially more expensive calls for specific environments, roles, or job names.
|
||||||
|
@ -117,7 +138,38 @@ func fetchTasks(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchStatus(cmd *cobra.Command, args []string) {
|
func fetchTasksStatus(cmd *cobra.Command, args []string) {
|
||||||
|
log.Infof("Fetching task status for [%s/%s/%s] \n", *env, *role, *name)
|
||||||
|
|
||||||
|
// Task Query takes nil for values it shouldn't need to match against.
|
||||||
|
// This allows us to potentially more expensive calls for specific environments, roles, or job names.
|
||||||
|
if *env == "" {
|
||||||
|
env = nil
|
||||||
|
}
|
||||||
|
if *role == "" {
|
||||||
|
role = nil
|
||||||
|
}
|
||||||
|
if *role == "" {
|
||||||
|
role = nil
|
||||||
|
}
|
||||||
|
//TODO: Add filtering down by status
|
||||||
|
taskQuery := &aurora.TaskQuery{Environment: env, Role: role, JobName: name}
|
||||||
|
|
||||||
|
tasks, err := client.GetTaskStatus(taskQuery)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("error: %+v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if toJson {
|
||||||
|
fmt.Println(toJSON(tasks))
|
||||||
|
} else {
|
||||||
|
for _, t := range tasks {
|
||||||
|
fmt.Println(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchHostStatus(cmd *cobra.Command, args []string) {
|
||||||
log.Infof("Fetching maintenance status for %v \n", args)
|
log.Infof("Fetching maintenance status for %v \n", args)
|
||||||
result, err := client.MaintenanceStatus(args...)
|
result, err := client.MaintenanceStatus(args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -3,8 +3,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"github.com/paypal/gorealis/v2"
|
"github.com/paypal/gorealis/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"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"
|
||||||
|
|
10
cmd/root.go
10
cmd/root.go
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/paypal/gorealis/v2"
|
"github.com/paypal/gorealis/v2"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var username, password, zkAddr, schedAddr string
|
var username, password, zkAddr, schedAddr string
|
||||||
|
@ -28,8 +28,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 log = logrus.New()
|
||||||
|
|
||||||
const australisVer = "v0.0.7"
|
const australisVer = "v0.0.8"
|
||||||
|
|
||||||
var monitorInterval, monitorTimeout time.Duration
|
var monitorInterval, monitorTimeout time.Duration
|
||||||
|
|
||||||
|
@ -68,7 +69,7 @@ func Execute() {
|
||||||
|
|
||||||
// TODO(rdelvalle): Move more from connect into this function
|
// TODO(rdelvalle): Move more from connect into this function
|
||||||
func setConfig(cmd *cobra.Command, args []string) {
|
func setConfig(cmd *cobra.Command, args []string) {
|
||||||
lvl, err := log.ParseLevel(logLevel)
|
lvl, err := logrus.ParseLevel(logLevel)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Log level %v is not valid\n", logLevel)
|
log.Fatalf("Log level %v is not valid\n", logLevel)
|
||||||
|
@ -126,7 +127,8 @@ func connect(cmd *cobra.Command, args []string) {
|
||||||
Duration: 10 * time.Second,
|
Duration: 10 * time.Second,
|
||||||
Factor: 2.0,
|
Factor: 2.0,
|
||||||
Jitter: 0.1,
|
Jitter: 0.1,
|
||||||
})}
|
}),
|
||||||
|
realis.SetLogger(log)}
|
||||||
|
|
||||||
// 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] != "" {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
|
@ -4,8 +4,6 @@ import (
|
||||||
"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"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toJSON(v interface{}) string {
|
func toJSON(v interface{}) string {
|
||||||
|
@ -25,7 +25,7 @@ func getLoggingLevels() string {
|
||||||
|
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
for _, level := range log.AllLevels {
|
for _, level := range logrus.AllLevels {
|
||||||
buffer.WriteString(level.String())
|
buffer.WriteString(level.String())
|
||||||
buffer.WriteString(" ")
|
buffer.WriteString(" ")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue