Skip to content

Commit

Permalink
Merge pull request #666 from jiangkaihua/master
Browse files Browse the repository at this point in the history
Add command vjobs, vqueues and unit tests.
  • Loading branch information
volcano-sh-bot authored Jan 15, 2020
2 parents c3b48ac + 56bcd26 commit 3c1f009
Show file tree
Hide file tree
Showing 17 changed files with 1,398 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ command-lines:
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vcancel ./cmd/cli/vcancel
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vresume ./cmd/cli/vresume
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vsuspend ./cmd/cli/vsuspend
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vjobs ./cmd/cli/vjobs
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vqueues ./cmd/cli/vqueues
2 changes: 1 addition & 1 deletion cmd/cli/util/util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Volcano Authors.
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
10 changes: 5 additions & 5 deletions cmd/cli/vcancel/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Volcano Authors.
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/klog"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/job"
"volcano.sh/volcano/pkg/cli/vcancel"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
Expand All @@ -45,14 +45,14 @@ func main() {
Short: "cancel a job",
Long: `cancel a running, pending, or aborted job with specified name in default or specified namespace`,
Run: func(cmd *cobra.Command, args []string) {
util.CheckError(cmd, job.DeleteJob())
util.CheckError(cmd, vcancel.CancelJob())
},
}

jobCancelCmd := &rootCmd
job.InitDeleteFlags(jobCancelCmd)
vcancel.InitCancelFlags(jobCancelCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %v\n", err)
fmt.Printf("Failed to execute vcancel: %v\n", err)
os.Exit(-2)
}
}
58 changes: 58 additions & 0 deletions cmd/cli/vjobs/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2019 The Volcano Authors.
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 main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vjobs"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vjobs",
Short: "view job information",
Long: `view information of a job with specified name or jobs from the same namespace`,
Run: func(cmd *cobra.Command, args []string) {
util.CheckError(cmd, vjobs.ViewJob())
},
}

jobViewCmd := &rootCmd
vjobs.InitViewFlags(jobViewCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vjobs: %v\n", err)
os.Exit(-2)
}
}
58 changes: 58 additions & 0 deletions cmd/cli/vqueues/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2019 The Volcano Authors.
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 main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vqueues"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vqueues",
Short: "view queue information",
Long: `view information of a queue with specified name or queues from the same namespace`,
Run: func(cmd *cobra.Command, args []string) {
util.CheckError(cmd, vqueues.GetQueue())
},
}

jobGetCmd := &rootCmd
vqueues.InitGetFlags(jobGetCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vqueues: %v\n", err)
os.Exit(-2)
}
}
10 changes: 5 additions & 5 deletions cmd/cli/vresume/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Volcano Authors.
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/klog"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/job"
"volcano.sh/volcano/pkg/cli/vresume"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
Expand All @@ -45,14 +45,14 @@ func main() {
Short: "resume a job",
Long: `resume an aborted job with specified name in default or specified namespace`,
Run: func(cmd *cobra.Command, args []string) {
util.CheckError(cmd, job.ResumeJob())
util.CheckError(cmd, vresume.ResumeJob())
},
}

jobResumeCmd := &rootCmd
job.InitResumeFlags(jobResumeCmd)
vresume.InitResumeFlags(jobResumeCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %v\n", err)
fmt.Printf("Failed to execute vresume: %v\n", err)
os.Exit(-2)
}
}
10 changes: 5 additions & 5 deletions cmd/cli/vsuspend/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Volcano Authors.
Copyright 2019 The Volcano Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,7 @@ import (
"k8s.io/klog"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/job"
"volcano.sh/volcano/pkg/cli/vsuspend"
)

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
Expand All @@ -45,14 +45,14 @@ func main() {
Short: "suspend a job",
Long: `suspend a running or pending job with specified name in default or specified namespace`,
Run: func(cmd *cobra.Command, args []string) {
util.CheckError(cmd, job.SuspendJob())
util.CheckError(cmd, vsuspend.SuspendJob())
},
}

jobSuspendCmd := &rootCmd
job.InitSuspendFlags(jobSuspendCmd)
vsuspend.InitSuspendFlags(jobSuspendCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %v\n", err)
fmt.Printf("Failed to execute vsuspend: %v\n", err)
os.Exit(-2)
}
}
Loading

0 comments on commit 3c1f009

Please sign in to comment.