Incorporated PR review changes

This commit is contained in:
ananaysingh 2022-08-18 22:07:15 +05:30
parent a2e5b86c3b
commit c001093379
2 changed files with 21 additions and 9 deletions

View file

@ -43,7 +43,7 @@ func init() {
killTasksCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment") killTasksCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
killTasksCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") killTasksCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
killTasksCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name") killTasksCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name")
killTasksCmd.Flags().StringVarP(instance, "instance", "i", "", "Instance Number") killTasksCmd.Flags().StringVarP(instances, "instances", "i", "", "Instances")
killTasksCmd.Flags().BoolVarP(&monitor, "monitor", "m", true, "monitor the result after sending the command") killTasksCmd.Flags().BoolVarP(&monitor, "monitor", "m", true, "monitor the result after sending the command")
killTasksCmd.MarkFlagRequired("environment") killTasksCmd.MarkFlagRequired("environment")
killTasksCmd.MarkFlagRequired("role") killTasksCmd.MarkFlagRequired("role")
@ -62,6 +62,18 @@ var killJobCmd = &cobra.Command{
Run: killJob, Run: killJob,
} }
/*
* The killTasks command allows the user to kill a specific task of a job.
* The command also allows the user to kill multiple tasks of the same job. To do so the user needs to pass a list of instance numbers as comma separated values.
* Pass the instance number of the job to be killed after the --instances or -i flag
* Please note that all the instances passed must belong to the same job.
*
* example : australis kill tasks -e "environment" -r "role" -n "job_name" -i "1"
* The above example kills instance number 1.
*
* example 2 : australis kill tasks -e "environment" -r "role" -n "job_name" -i "1, 5, 9"
* The above example kills tasks 1, 5 and 9, which are part of the same job
*/
var killTasksCmd = &cobra.Command{ var killTasksCmd = &cobra.Command{
Use: "tasks", Use: "tasks",
Short: "Kill Aurora Tasks", Short: "Kill Aurora Tasks",
@ -87,7 +99,7 @@ func killJob(cmd *cobra.Command, args []string) {
} }
func killTasks(cmd *cobra.Command, args []string) { func killTasks(cmd *cobra.Command, args []string) {
log.Infof("Killing task [Env:%s Role:%s Name:%s Instance:%s]\n", *env, *role, *name, *instance) log.Infof("Killing task [Env:%s Role:%s Name:%s Instance:%s]\n", *env, *role, *name, *instances)
//Set jobKey for the tasks to be killed. //Set jobKey for the tasks to be killed.
task := realis.NewTask(). task := realis.NewTask().
@ -96,8 +108,8 @@ func killTasks(cmd *cobra.Command, args []string) {
Name(*name) Name(*name)
//Check that instance number is passed //Check that instance number is passed
if instance == nil { if instances == nil {
log.Fatalln("Instance number not found. Please pass a valid instance number. If you want to pass multiple instances, please pass them as space separated integer values") log.Fatalln("Instance number not found. Please pass a valid instance number. If you want to pass multiple instances, please pass them as comma separated integer values")
} }
/* /*
@ -107,10 +119,11 @@ func killTasks(cmd *cobra.Command, args []string) {
var intErr error var intErr error
var instanceNumber int var instanceNumber int
splitString := strings.Split(*instance, " ") splitString := strings.Split(*instances, ",")
instanceList := make([]int32, len(splitString)) instanceList := make([]int32, len(splitString))
for i := range instanceList { for i := range instanceList {
splitString[i] = strings.TrimSpace(splitString[i])
instanceNumber, intErr = strconv.Atoi(splitString[i]) instanceNumber, intErr = strconv.Atoi(splitString[i])
if intErr != nil { if intErr != nil {
log.Fatalln("Instance passed should be a number. Error: " + intErr.Error()) log.Fatalln("Instance passed should be a number. Error: " + intErr.Error())
@ -121,11 +134,10 @@ func killTasks(cmd *cobra.Command, args []string) {
} }
//Call the killtasks function, passing the instanceList as the list of instances to be killed. //Call the killtasks function, passing the instanceList as the list of instances to be killed.
_, err := client.KillInstances(task.JobKey(), instanceList...) if _, err := client.KillInstances(task.JobKey(), instanceList...); err != nil {
if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
if monitor { if monitor {
if ok, err := client.MonitorInstances(task.JobKey(), 0, 5, 50); !ok || err != nil { if ok, err := client.MonitorInstances(task.JobKey(), 0, 5, 50); !ok || err != nil {
log.Fatalln("Unable to kill the given task") log.Fatalln("Unable to kill the given task")

View file

@ -51,7 +51,7 @@ var monitor bool
var timeout time.Duration var timeout time.Duration
var log = logrus.New() var log = logrus.New()
var taskStatus = new(string) var taskStatus = new(string)
var instance = new(string) var instances = new(string)
const australisVer = "v1.0.4" const australisVer = "v1.0.4"