-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 decommission capability and removenode cmd #18530
Changes from all commits
ad1a709
0514fd8
b305f18
c361a00
c81ca8d
802d02b
409814e
976ec25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* 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 process | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"alluxio.org/cli/cmd/names" | ||
"alluxio.org/cli/env" | ||
) | ||
|
||
var RemoveWorker = &RemoveWorkerCommand{ | ||
BaseJavaCommand: &env.BaseJavaCommand{ | ||
CommandName: "remove-worker", | ||
JavaClassName: names.FileSystemAdminShellJavaClass, | ||
Parameters: []string{"nodes", "remove"}, | ||
}, | ||
} | ||
|
||
type RemoveWorkerCommand struct { | ||
*env.BaseJavaCommand | ||
workerId string | ||
} | ||
|
||
func (c *RemoveWorkerCommand) Base() *env.BaseJavaCommand { | ||
return c.BaseJavaCommand | ||
} | ||
|
||
func (c *RemoveWorkerCommand) ToCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remove-worker", | ||
Short: "Remove a worker from ETCD membership", | ||
Long: `Remove given worker from the cluster, so that clients and other workers will not consider the removed worker for services. | ||
The worker must have been stopped before it can be safely removed from the cluster.`, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return c.Run(args) | ||
}, | ||
} | ||
const name = "name" | ||
cmd.Flags().StringVarP(&c.workerId, name, "n", "", "Worker id") | ||
cmd.MarkFlagRequired(name) | ||
return cmd | ||
} | ||
|
||
func (c *RemoveWorkerCommand) Run(_ []string) error { | ||
return c.Base().Run([]string{"-n", c.workerId}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
package alluxio.wire; | ||
|
||
import alluxio.exception.status.InvalidArgumentException; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
|
@@ -112,6 +114,38 @@ public int hashCode() { | |
return hashCode; | ||
} | ||
|
||
/** | ||
* Construct from a workerid representation from registration. | ||
* | ||
* @param workerIdentityStr | ||
* @return WorkerIdentity object | ||
* @throws InvalidArgumentException | ||
*/ | ||
public static WorkerIdentity fromString(String workerIdentityStr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this method close to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done and done |
||
throws InvalidArgumentException { | ||
String prefix = "worker-"; | ||
String errStr = "Unrecognized worker identity string"; | ||
if (!workerIdentityStr.startsWith(prefix)) { | ||
throw new InvalidArgumentException(errStr + ": " + workerIdentityStr); | ||
} | ||
String idStr = workerIdentityStr.substring(prefix.length()); | ||
try { | ||
return ParserV1.INSTANCE.fromUUID(idStr); | ||
} catch (java.lang.IllegalArgumentException ex) { | ||
// DO NOTHING | ||
} | ||
try { | ||
return ParserV0.INSTANCE.fromLong(Long.parseLong(idStr)); | ||
} catch (NumberFormatException ex) { | ||
throw new InvalidArgumentException(errStr + ": " + workerIdentityStr); | ||
} | ||
} | ||
|
||
/** | ||
* [NOTE] paired with fromString. | ||
* if modified, change fromString as well | ||
* @return String representation of WorkerIdentity | ||
*/ | ||
@Override | ||
public String toString() { | ||
return String.format("worker-%s", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also make changes to nodes.go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes Rico is making the change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added now with the running format: |
||
* 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 alluxio.cli.fsadmin.nodes; | ||
|
||
import alluxio.cli.fsadmin.command.AbstractFsAdminCommand; | ||
import alluxio.cli.fsadmin.command.Context; | ||
import alluxio.conf.AlluxioConfiguration; | ||
import alluxio.membership.MembershipManager; | ||
import alluxio.wire.WorkerIdentity; | ||
import alluxio.wire.WorkerInfo; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Remove a non-running worker from the membership. | ||
*/ | ||
public class RemoveWorkerCommand extends AbstractFsAdminCommand { | ||
public static final String WORKERNAME_OPTION_NAME = "n"; | ||
public static final String HELP_OPTION_NAME = "h"; | ||
|
||
private static final Option WORKERNAME_OPTION = | ||
Option.builder(WORKERNAME_OPTION_NAME) | ||
.required(true) | ||
.hasArg(true) | ||
.desc("ID of the worker to remove") | ||
.build(); | ||
|
||
private static final Option HELP_OPTION = | ||
Option.builder(HELP_OPTION_NAME) | ||
.required(false) | ||
.hasArg(false) | ||
.desc("print help information.") | ||
.build(); | ||
|
||
private final AlluxioConfiguration mAlluxioConf; | ||
|
||
/** | ||
* @param context | ||
* @param alluxioConf | ||
*/ | ||
public RemoveWorkerCommand(Context context, AlluxioConfiguration alluxioConf) { | ||
super(context); | ||
mAlluxioConf = alluxioConf; | ||
} | ||
|
||
@Override | ||
public String getCommandName() { | ||
return "remove"; | ||
} | ||
|
||
@Override | ||
public Options getOptions() { | ||
return new Options().addOption(WORKERNAME_OPTION) | ||
.addOption(HELP_OPTION); | ||
} | ||
|
||
@Override | ||
public String getUsage() { | ||
return getCommandName() + " -n <WorkerId> | -h"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Remove given worker from the cluster, so that clients and " | ||
+ "other workers will not consider the removed worker for services. " | ||
+ "The worker must have been stopped before it can be safely removed " | ||
+ "from the cluster."; | ||
} | ||
|
||
@Override | ||
public int run(CommandLine cl) throws IOException { | ||
if (cl.hasOption(HELP_OPTION_NAME) | ||
|| !cl.hasOption(WORKERNAME_OPTION_NAME)) { | ||
System.out.println(getUsage()); | ||
System.out.println(getDescription()); | ||
return 0; | ||
} | ||
MembershipManager membershipManager = | ||
MembershipManager.Factory.create(mAlluxioConf); | ||
String workerId = cl.getOptionValue(WORKERNAME_OPTION_NAME).trim(); | ||
membershipManager.decommission( | ||
new WorkerInfo().setIdentity(WorkerIdentity.fromString(workerId))); | ||
mPrintStream.println(String.format( | ||
"Successfully removed worker: %s", workerId)); | ||
return 0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing license header in new file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done