forked from apache/ratis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RATIS-1860. Add ratis-shell cmd to generate a new raft-meta.conf. (ap…
…ache#901) * Add ratis-shell cmd to generate a new raft-meta.conf. * Remove index option. * Style fix. * Use GroupCommand as the parent of RaftMetaConfCommand. * Modified by review comments. * Update cli.md * Use LocalCommand as the parent of RaftMetaConfCommand. * ReConstruct some abstract command. * Modified by review comments. * Use println instead of printf. * Checkstyle error fix(delete some unuse import). --------- Co-authored-by: idellzheng <[email protected]>
- Loading branch information
Showing
10 changed files
with
276 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.ratis.shell.cli.sh.command; | ||
|
||
import org.apache.ratis.shell.cli.Command; | ||
|
||
import java.io.PrintStream; | ||
import java.net.InetSocketAddress; | ||
|
||
/** | ||
* The base class for all the ratis shell {@link Command} classes. | ||
*/ | ||
public abstract class AbstractCommand implements Command { | ||
|
||
private final PrintStream printStream; | ||
|
||
protected AbstractCommand(Context context) { | ||
printStream = context.getPrintStream(); | ||
} | ||
|
||
public static InetSocketAddress parseInetSocketAddress(String address) { | ||
try { | ||
final String[] hostPortPair = address.split(":"); | ||
if (hostPortPair.length < 2) { | ||
throw new IllegalArgumentException("Unexpected address format <HOST:PORT>."); | ||
} | ||
return new InetSocketAddress(hostPortPair[0], Integer.parseInt(hostPortPair[1])); | ||
} catch (Exception e) { | ||
throw new IllegalArgumentException("Failed to parse the server address parameter \"" + address + "\".", e); | ||
} | ||
} | ||
|
||
protected PrintStream getPrintStream() { | ||
return printStream; | ||
} | ||
|
||
protected void printf(String format, Object... args) { | ||
printStream.printf(format, args); | ||
} | ||
|
||
protected void println(Object message) { | ||
printStream.println(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/LocalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.ratis.shell.cli.sh.command; | ||
|
||
import org.apache.ratis.shell.cli.Command; | ||
import org.apache.ratis.shell.cli.sh.local.RaftMetaConfCommand; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Command for local operation, which no need to connect to ratis server | ||
*/ | ||
public class LocalCommand extends AbstractParentCommand { | ||
|
||
private static final List<Function<Context, Command>> SUB_COMMAND_CONSTRUCTORS | ||
= Collections.unmodifiableList(Arrays.asList(RaftMetaConfCommand::new)); | ||
|
||
/** | ||
* @param context command context | ||
*/ | ||
public LocalCommand(Context context) { | ||
super(context, SUB_COMMAND_CONSTRUCTORS); | ||
} | ||
|
||
@Override | ||
public String getCommandName() { | ||
return "local"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return description(); | ||
} | ||
|
||
/** | ||
* @return command's description | ||
*/ | ||
public static String description() { | ||
return "Command for local operation, which no need to connect to ratis server; " | ||
+ "see the sub-commands for the details."; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
467043d
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.