Skip to content

Commit

Permalink
Add job subcommand to CLI
Browse files Browse the repository at this point in the history
Add job commands to golang CLI as part of #17522

`bin/alluxio-bash job cancel id` -> `bin/alluxio job cancel --id`
`bin/alluxio-bash job leader` -> `bin/alluxio job leader`
`bin/alluxio-bash job ls` -> `bin/alluxio job list`
`bin/alluxio-bash job getCmdStatus jobControlId` -> `bin/alluxio job cmdStatus --id`
`bin/alluxio-bash job stat [-v] id` -> `bin/alluxio job jobStatus [-v] --id`
`bin/alluxio-bash fs distributedCp src dst` -> `bin/alluxio job submit --type cp --src --dst`
`bin/alluxio-bash fs distributedMv src dst` -> `bin/alluxio job submit --type mv --src --dst`
`bin/alluxio-bash fs load path --submit` -> `bin/alluxio job load --path`

			pr-link: #17931
			change-id: cid-aa5d06b53adbc5ad0a35177ca51217fcb1b35ef4
  • Loading branch information
twalluxio committed Aug 8, 2023
1 parent 8a8b338 commit cf82f12
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 0 deletions.
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

0 comments on commit cf82f12

Please sign in to comment.