Adding fetch task status. Changed how logrus is used to be able to be passed down to gorealis.

This commit is contained in:
Renan DelValle 2019-03-19 15:27:20 -07:00
parent 2abd691a1c
commit 4551231644
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
10 changed files with 72 additions and 29 deletions

View file

@ -2,8 +2,6 @@ package cmd
import (
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
func init() {

View file

@ -2,13 +2,11 @@ package cmd
import (
"fmt"
"github.com/spf13/pflag"
"github.com/paypal/gorealis/v2"
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
)
func init() {
@ -17,11 +15,21 @@ func init() {
// Sub-commands
// 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(role, "role", "r", "", "Aurora Role")
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 */
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",
}
var fetchTaskCmd = &cobra.Command{
Use: "task",
Short: "Task information from Aurora",
}
var taskConfigCmd = &cobra.Command{
Use: "config",
Short: "Fetch a list of task configurations from Aurora.",
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{
@ -83,11 +104,11 @@ var fetchStatusCmd = &cobra.Command{
Use: "status",
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`,
Run: fetchStatus,
Run: fetchHostStatus,
}
func fetchTasks(cmd *cobra.Command, args []string) {
fmt.Printf("Fetching job configuration for [%s/%s/%s] \n", env, role, name)
func fetchTasksConfig(cmd *cobra.Command, args []string) {
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.
// 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)
result, err := client.MaintenanceStatus(args...)
if err != nil {

View file

@ -5,8 +5,6 @@ import (
"strconv"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
func init() {

View file

@ -3,8 +3,6 @@ package cmd
import (
"github.com/paypal/gorealis/v2"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
)
func init() {

View file

@ -2,7 +2,6 @@ package cmd
import (
"fmt"
"log"
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"

View file

@ -8,7 +8,7 @@ import (
"github.com/paypal/gorealis/v2"
"github.com/spf13/cobra"
log "github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
)
var username, password, zkAddr, schedAddr string
@ -28,8 +28,9 @@ var count int64
var filename string
var message = new(string)
var updateID string
var log = logrus.New()
const australisVer = "v0.0.7"
const australisVer = "v0.0.8"
var monitorInterval, monitorTimeout time.Duration
@ -68,7 +69,7 @@ func Execute() {
// TODO(rdelvalle): Move more from connect into this function
func setConfig(cmd *cobra.Command, args []string) {
lvl, err := log.ParseLevel(logLevel)
lvl, err := logrus.ParseLevel(logLevel)
if err != nil {
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,
Factor: 2.0,
Jitter: 0.1,
})}
}),
realis.SetLogger(log)}
// Prefer zookeeper if both ways of connecting are provided
if len(zkAddrSlice) > 0 && zkAddrSlice[0] != "" {

View file

@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strconv"
"strings"

View file

@ -4,8 +4,6 @@ import (
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
"time"
log "github.com/sirupsen/logrus"
)
func init() {

View file

@ -1,11 +1,10 @@
package cmd
import (
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
"time"
log "github.com/sirupsen/logrus"
"github.com/paypal/gorealis/v2/gen-go/apache/aurora"
"github.com/spf13/cobra"
)
func init() {

View file

@ -4,9 +4,9 @@ import (
"bytes"
"encoding/json"
"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 {
@ -25,7 +25,7 @@ func getLoggingLevels() string {
var buffer bytes.Buffer
for _, level := range log.AllLevels {
for _, level := range logrus.AllLevels {
buffer.WriteString(level.String())
buffer.WriteString(" ")
}