From cc8e9493ec5628704419238359b68057a0b1002f Mon Sep 17 00:00:00 2001 From: ananaysingh <54039499+ananaysingh@users.noreply.github.com> Date: Wed, 10 Aug 2022 20:47:39 +0530 Subject: [PATCH 1/4] Kill task go file --- cmd/killTask.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 cmd/killTask.go diff --git a/cmd/killTask.go b/cmd/killTask.go new file mode 100644 index 0000000..e691eee --- /dev/null +++ b/cmd/killTask.go @@ -0,0 +1,65 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package cmd + +import ( + realis "github.com/aurora-scheduler/gorealis/v2" + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(killTask) + + /* Sub-Commands */ + + // Kill Job + killTask.AddCommand(killTaskCmd) + + killTaskCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment") + killTaskCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") + killTaskCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name") + killTaskCmd.Flags().BoolVarP(&monitor, "monitor", "m", true, "monitor the result after sending the command") + killTaskCmd.MarkFlagRequired("environment") + killTaskCmd.MarkFlagRequired("role") + killTaskCmd.MarkFlagRequired("name") +} + +var killTask = &cobra.Command{ + Use: "killTask", + Short: "Kill an Aurora Task", +} + +var killTaskCmd = &cobra.Command{ + Use: "task", + Short: "Kill an Aurora Task", + Run: killTask, +} + +func killTask(cmd *cobra.Command, args []string) { + log.Infof("Killing task [Env:%s Role:%s Name:%s]\n", *env, *role, *name) + + task := realis.NewTask(). + Environment(*env). + Role(*role). + Name(*name) + err := client.KillTask(task.JobKey()) + if err != nil { + log.Fatalln(err) + } + if monitor { + if ok, err := client.MonitorInstances(task.JobKey(), 0, 5, 50); !ok || err != nil { + log.Fatalln("Unable to kill the given task") + } + } +} From 7c6af7de6854cc53ad1068dd282ddf0a6d8e69c7 Mon Sep 17 00:00:00 2001 From: ananaysingh <54039499+ananaysingh@users.noreply.github.com> Date: Wed, 10 Aug 2022 20:59:14 +0530 Subject: [PATCH 2/4] Updated CI to include manual workflow trigger --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b22bd7..ca3b6ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ on: pull_request: branches: - main + workflow_dispatch: jobs: build: From db2d4e9e171f3766dff3be9c9f6efa4848575aa6 Mon Sep 17 00:00:00 2001 From: ananaysingh <54039499+ananaysingh@users.noreply.github.com> Date: Fri, 12 Aug 2022 22:52:03 +0530 Subject: [PATCH 3/4] KillTask V2 --- cmd/killTask.go | 17 +++++++++++++---- cmd/root.go | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/killTask.go b/cmd/killTask.go index e691eee..7b772cd 100644 --- a/cmd/killTask.go +++ b/cmd/killTask.go @@ -14,6 +14,8 @@ package cmd import ( + "strconv" + realis "github.com/aurora-scheduler/gorealis/v2" "github.com/spf13/cobra" ) @@ -29,10 +31,12 @@ func init() { killTaskCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment") killTaskCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") killTaskCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name") + killTaskCmd.Flags().StringVarP(instance, "instance", "i", "", "Instance number") killTaskCmd.Flags().BoolVarP(&monitor, "monitor", "m", true, "monitor the result after sending the command") killTaskCmd.MarkFlagRequired("environment") killTaskCmd.MarkFlagRequired("role") killTaskCmd.MarkFlagRequired("name") + killTaskCmd.MarkFlagRequired("instance") } var killTask = &cobra.Command{ @@ -43,17 +47,22 @@ var killTask = &cobra.Command{ var killTaskCmd = &cobra.Command{ Use: "task", Short: "Kill an Aurora Task", - Run: killTask, + Run: killTaskFunc, } -func killTask(cmd *cobra.Command, args []string) { - log.Infof("Killing task [Env:%s Role:%s Name:%s]\n", *env, *role, *name) +func killTaskFunc(cmd *cobra.Command, args []string) { + log.Infof("Killing task [Env:%s Role:%s Name:%s Instance:%s]\n", *env, *role, *name, *instance) + //Set jobKey for the task to be killed. task := realis.NewTask(). Environment(*env). Role(*role). Name(*name) - err := client.KillTask(task.JobKey()) + + //Convert instance from string type to int32 type, and call the killtasks function + instanceNumber, _ := strconv.Atoi(*instance) + _, err := client.KillInstances(task.JobKey(), (int32)(instanceNumber)) + if err != nil { log.Fatalln(err) } diff --git a/cmd/root.go b/cmd/root.go index d2d0d71..2d151ee 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,7 +28,7 @@ import ( ) var username, password, zkAddr, schedAddr string -var env, role, name = new(string), new(string), new(string) +var env, role, name, instance = new(string), new(string), new(string), new(string) var dedicated string var ram, disk, gpu, port int64 var cpu float64 From fe5c246b1b6fc4b0b747779e61bba5d89a7f7fba Mon Sep 17 00:00:00 2001 From: ananaysingh <54039499+ananaysingh@users.noreply.github.com> Date: Tue, 16 Aug 2022 22:12:51 +0530 Subject: [PATCH 4/4] Reverted ci.yml --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca3b6ad..5b22bd7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,6 @@ on: pull_request: branches: - main - workflow_dispatch: jobs: build: