Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add job subcommand to CLI #17931

Merged
merged 15 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/cancel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"strconv"

"github.com/palantir/stacktrace"
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var Cancel = &CancelCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "cancel",
JavaClassName: cmd.JobShellJavaClass,
},
}

type CancelCommand struct {
*env.BaseJavaCommand
jobId int
}

func (c *CancelCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *CancelCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Cancel.CommandName,
Short: "Cancels a job asynchronously.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
command.Flags().IntVar(&c.jobId, "id", 0, "Determine a job ID to cancel")
command.MarkFlagRequired("id")
return command
}

func (c *CancelCommand) Run(args []string) error {
if c.jobId <= 0 {
return stacktrace.NewError("Flag --id should be a positive integer")
}
javaArgs := []string{"cancel", strconv.Itoa(c.jobId)}
return c.Base().Run(javaArgs)
}
61 changes: 61 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/cmd_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"strconv"

"github.com/palantir/stacktrace"
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var CmdStatus = &CmdStatusCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "cmdStatus",
JavaClassName: cmd.JobShellJavaClass,
},
}

type CmdStatusCommand struct {
*env.BaseJavaCommand
jobControlId int
}

func (c *CmdStatusCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *CmdStatusCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: CmdStatus.CommandName,
Short: "Get the status information for a distributed command.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
command.Flags().IntVar(&c.jobControlId, "id", 0,
"Determine the job control ID to get the status information")
command.MarkFlagRequired("id")
return command
}

func (c *CmdStatusCommand) Run(args []string) error {
if c.jobControlId <= 0 {
return stacktrace.NewError("Flag --id should be a positive integer")
}
javaArgs := []string{"getCmdStatus", strconv.Itoa(c.jobControlId)}
return c.Base().Run(javaArgs)
}
28 changes: 28 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import "alluxio.org/cli/env"

var Service = &env.Service{
Name: "job",
Description: "Command line tool for interacting with the job service.",
Commands: []env.Command{
Cancel,
CmdStatus,
JobStatus,
Leader,
List,
Load,
Submit,
},
}
68 changes: 68 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/job_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"strconv"

"github.com/palantir/stacktrace"
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var JobStatus = &JobStatusCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "jobStatus",
JavaClassName: cmd.JobShellJavaClass,
},
}

type JobStatusCommand struct {
*env.BaseJavaCommand
jobId int
everyTask bool
}

func (c *JobStatusCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *JobStatusCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: JobStatus.CommandName,
Short: "Displays the status info for the specific job.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
command.Flags().IntVar(&c.jobId, "id", 0,
"Determine the job ID to get status info")
command.Flags().BoolVarP(&c.everyTask, "every-task", "v", false,
"Determine display the status of every task")
command.MarkFlagRequired("id")
return command
}

func (c *JobStatusCommand) Run(args []string) error {
if c.jobId <= 0 {
return stacktrace.NewError("Flag --id should be a positive integer")
}
javaArgs := []string{"stat"}
if c.everyTask {
javaArgs = append(javaArgs, "-v")
}
javaArgs = append(javaArgs, strconv.Itoa(c.jobId))
return c.Base().Run(javaArgs)
}
51 changes: 51 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/leader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var Leader = &LeaderCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "leader",
JavaClassName: cmd.JobShellJavaClass,
},
}

type LeaderCommand struct {
*env.BaseJavaCommand
}

func (c *LeaderCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *LeaderCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Leader.CommandName,
Short: "Prints the hostname of the job master service leader.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
return command
}

func (c *LeaderCommand) Run(args []string) error {
javaArgs := []string{"leader"}
return c.Base().Run(javaArgs)
}
52 changes: 52 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var List = &ListCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "list",
JavaClassName: cmd.JobShellJavaClass,
},
}

type ListCommand struct {
*env.BaseJavaCommand
}

func (c *ListCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *ListCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: List.CommandName,
Short: "Prints the IDs of the most recent jobs, running and finished, " +
"in the history up to the capacity set in alluxio.job.master.job.capacity",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
return command
}

func (c *ListCommand) Run(args []string) error {
javaArgs := []string{"ls"}
return c.Base().Run(javaArgs)
}
54 changes: 54 additions & 0 deletions cli/src/alluxio.org/cli/cmd/job/load.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
* (the "License"). You may not use this work except in compliance with the License, which is
* available at www.apache.org/licenses/LICENSE-2.0
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied, as more fully set forth in the License.
*
* See the NOTICE file distributed with this work for information regarding copyright ownership.
*/

package job

import (
"github.com/spf13/cobra"

"alluxio.org/cli/cmd"
"alluxio.org/cli/env"
)

var Load = &LoadCommand{
BaseJavaCommand: &env.BaseJavaCommand{
CommandName: "load",
JavaClassName: cmd.FileSystemShellJavaClass,
},
}

type LoadCommand struct {
*env.BaseJavaCommand
path string
}

func (c *LoadCommand) Base() *env.BaseJavaCommand {
return c.BaseJavaCommand
}

func (c *LoadCommand) ToCommand() *cobra.Command {
command := c.Base().InitRunJavaClassCmd(&cobra.Command{
Use: Load.CommandName,
Short: "Submit load job to Alluxio master, update job options if already exists",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Run(args)
},
})
command.Flags().StringVar(&c.path, "path", "", "Determine the path of the load job to submit")
command.MarkFlagRequired("path")
return command
}

func (c *LoadCommand) Run(args []string) error {
javaArgs := []string{"load", c.path, "--submit"}
return c.Base().Run(javaArgs)
}
Loading
Loading