Skip to content

Commit

Permalink
Add process subcommands for multiple nodes
Browse files Browse the repository at this point in the history
Add `process` commands with multiple nodes to golang CLI as part of #17522

`bin/alluxio-start.sh masters` -> `bin/cli.sh process start masters`
`bin/alluxio-start.sh job_masters` -> `bin/cli.sh process start job_masters`
`bin/alluxio-start.sh workers` -> `bin/cli.sh process start workers`
`bin/alluxio-start.sh job_workers` -> `bin/cli.sh process start job_workers`
`bin/alluxio-start.sh proxies` -> `bin/cli.sh process start proxies`
`bin/alluxio-start.sh all` -> `bin/cli.sh process start all`
`bin/alluxio-start.sh local` -> `bin/cli.sh process start local`

`bin/alluxio-stop.sh masters` -> `bin/cli.sh process stop masters`
`bin/alluxio-stop.sh job_masters` -> `bin/cli.sh process stop job_masters`
`bin/alluxio-stop.sh workers` -> `bin/cli.sh process stop workers`
`bin/alluxio-stop.sh job_workers` -> `bin/cli.sh process stop job_workers`
`bin/alluxio-stop.sh proxies` -> `bin/cli.sh process stop proxies`
`bin/alluxio-stop.sh all` -> `bin/cli.sh process stop all`
`bin/alluxio-stop.sh local` -> `bin/cli.sh process stop local`

For command `process start/stop` on multiple nodes, using crypto's `ssh` package to create an SSH session, connect to masters, workers or all nodes, then send according subcommand on single nodes to these nodes.
			pr-link: #17887
			change-id: cid-0a660de35945738c065dae2f008a61d48f6b3be9
  • Loading branch information
twalluxio committed Aug 8, 2023
1 parent 116d74d commit 8a8b338
Show file tree
Hide file tree
Showing 14 changed files with 745 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/src/alluxio.org/cli/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func checkAndSetJava(envVar *viper.Viper) error {
// check if java is available via `PATH` using `which`
whichJavaPath, err := exec.Command("which", "java").Output()
if err == nil {
envVar.Set(ConfJava.EnvVar, string(whichJavaPath))
envVar.Set(ConfJava.EnvVar, strings.TrimSpace(string(whichJavaPath)))
return nil
}
// cannot find java
Expand Down
4 changes: 3 additions & 1 deletion cli/src/alluxio.org/cli/env/process_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import (
)

type StartProcessCommand struct {
Name string
AsyncStart bool
SkipKillOnStart bool
}

func (c *StartProcessCommand) ToCommand() *cobra.Command {
c.Name = "start"
cmd := &cobra.Command{
Use: "start",
Use: c.Name,
Short: "Starts a process",
}
cmd.PersistentFlags().BoolVarP(&c.SkipKillOnStart, "skip-kill-prev", "N", false, "Avoid killing previous running processes when starting")
Expand Down
4 changes: 3 additions & 1 deletion cli/src/alluxio.org/cli/env/process_stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ package env
import "github.com/spf13/cobra"

type StopProcessCommand struct {
Name string
SoftKill bool
}

func (c *StopProcessCommand) ToCommand() *cobra.Command {
c.Name = "stop"
cmd := &cobra.Command{
Use: "stop",
Use: c.Name,
Short: "Stops a process",
}
cmd.PersistentFlags().BoolVarP(&c.SoftKill, "soft", "s", false, "Soft kill only, don't forcibly kill the process")
Expand Down
7 changes: 7 additions & 0 deletions cli/src/alluxio.org/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ import (

func main() {
for _, p := range []env.Process{
processes.All,
processes.JobMaster,
processes.JobMasters,
processes.JobWorker,
processes.JobWorkers,
processes.Local,
processes.Master,
processes.Masters,
processes.Proxy,
processes.Proxies,
processes.Worker,
processes.Workers,
} {
env.RegisterProcess(p)
}
Expand Down
76 changes: 76 additions & 0 deletions cli/src/alluxio.org/cli/processes/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 processes

import (
"github.com/palantir/stacktrace"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"alluxio.org/cli/env"
)

var All = &AllProcess{
BaseProcess: &env.BaseProcess{
Name: "all",
},
Processes: []env.Process{
Masters,
JobMasters,
Workers,
JobWorkers,
Proxies,
},
}

type AllProcess struct {
*env.BaseProcess
Processes []env.Process
}

func (p *AllProcess) SetEnvVars(envVar *viper.Viper) {
return
}

func (p *AllProcess) Base() *env.BaseProcess {
return p.BaseProcess
}

func (p *AllProcess) StartCmd(cmd *cobra.Command) *cobra.Command {
cmd.Use = p.Name
return cmd
}

func (p *AllProcess) StopCmd(cmd *cobra.Command) *cobra.Command {
cmd.Use = p.Name
return cmd
}

func (p *AllProcess) Start(cmd *env.StartProcessCommand) error {
for i := 0; i < len(p.Processes); i++ {
subProcess := p.Processes[i]
if err := subProcess.Start(cmd); err != nil {
return stacktrace.Propagate(err, "Error starting subprocesses for %s", p.Processes[i])
}
}
return nil
}

func (p *AllProcess) Stop(cmd *env.StopProcessCommand) error {
for i := len(p.Processes) - 1; i >= 0; i-- {
subProcess := p.Processes[i]
if err := subProcess.Stop(cmd); err != nil {
return stacktrace.Propagate(err, "Error stopping subprocesses for %s", p.Processes[i])
}
}
return nil
}
Loading

0 comments on commit 8a8b338

Please sign in to comment.