Compare commits
No commits in common. "main" and "1.0.0" have entirely different histories.
|
@ -1,58 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nacos-ctl-bootstrap</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-interaction</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-command</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>${maven-assembly-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>
|
||||
com.alibaba.nacos.ctl.bootstrap.ClientMain
|
||||
</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -1,72 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.bootstrap;
|
||||
|
||||
import com.alibaba.nacos.ctl.bootstrap.command.NacosBootstrapCommand;
|
||||
import com.alibaba.nacos.ctl.command.NacosCommand;
|
||||
import com.alibaba.nacos.ctl.command.NacosCtl;
|
||||
import com.alibaba.nacos.ctl.command.spi.NacosCommandLoader;
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import com.alibaba.nacos.ctl.bootstrap.utils.StringUtils;
|
||||
import jline.console.UserInterruptException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
/**
|
||||
* 黑窗命令行客户端
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class ClientMain {
|
||||
|
||||
public static void main(String[] args) throws HandlerException {
|
||||
|
||||
System.out.println("NacosCtl Loading...");
|
||||
InputGetter.init();
|
||||
System.out.println("NacosCtl Load finished.\n");
|
||||
|
||||
System.out.println("Loading Nacos client sdk...");
|
||||
LogicHandler.init();
|
||||
System.out.println("Loading Nacos client sdk finished.\n");
|
||||
|
||||
System.out.println("Loading Extension commands...");
|
||||
NacosCommandLoader.getInstance().loadCommands();
|
||||
System.out.println("Loading Extension commands finish\n");
|
||||
|
||||
new CommandLine(new NacosBootstrapCommand()).execute(args);
|
||||
|
||||
loopExecute(InputGetter.getInstance());
|
||||
}
|
||||
|
||||
private static void loopExecute(InputGetter in) {
|
||||
|
||||
String[] args;
|
||||
CommandLine commandLine = new CommandLine(new NacosCtl());
|
||||
for (NacosCommand each : NacosCommandLoader.getInstance().getLoadedCommands()) {
|
||||
commandLine.getCommandSpec().addSubcommand(each.getCommandName(), new CommandLine(each));
|
||||
}
|
||||
|
||||
// 循环执行命令
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
String line = in.nextLine();
|
||||
args = StringUtils.parseInput(line);
|
||||
// 忽略无效输入
|
||||
if (args.length < 1 || args[0].length() < 1) {
|
||||
continue;
|
||||
}
|
||||
// 给Picocli执行命令
|
||||
|
||||
int ret = commandLine.execute(args);
|
||||
// 特殊的流程控制,通过返回值来判断,-1是退出,-2是清屏
|
||||
if (ret == -1) {
|
||||
break;
|
||||
}
|
||||
if (ret == -2) {
|
||||
in.clear();
|
||||
}
|
||||
} catch (UserInterruptException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="ERROR">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</root>
|
||||
</configuration>
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nacos-ctl-command</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-interaction</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
<artifactId>picocli</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.vandermeer</groupId>
|
||||
<artifactId>asciitable</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,29 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.command;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_CLEAR;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_CLEAR;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_CLEAR;
|
||||
|
||||
/**
|
||||
* clear the terminal, it only works with jline input
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_CLEAR, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_CLEAR, description = DESCRIPTION_CLEAR)
|
||||
public class NacosClear implements Callable<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
return -2;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.command;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
/**
|
||||
* Nacos command.
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public abstract class NacosCommand implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
/**
|
||||
* Get command name.
|
||||
*
|
||||
* @return command name
|
||||
*/
|
||||
public abstract String getCommandName();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.command;
|
||||
|
||||
import com.alibaba.nacos.ctl.command.config.NacosConfig;
|
||||
import com.alibaba.nacos.ctl.command.instance.NacosInstance;
|
||||
import com.alibaba.nacos.ctl.command.namespace.NacosNamespace;
|
||||
import com.alibaba.nacos.ctl.command.service.NacosService;
|
||||
import com.alibaba.nacos.ctl.command.switches.NacosSwitch;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.APP_NAME;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.CLI_DESCRIPTION;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.COMMAND_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.FOOTER;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.MIXIN_STANDARD_HELP_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.VERSION_NAME;
|
||||
|
||||
/**
|
||||
* the main command, based on picocli
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Command(name = APP_NAME, mixinStandardHelpOptions = MIXIN_STANDARD_HELP_OPTIONS, version = VERSION_NAME, description = CLI_DESCRIPTION, commandListHeading = COMMAND_LIST_HEADING, footer = FOOTER, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosQuit.class, NacosClear.class, NacosConfig.class, NacosNamespace.class,
|
||||
NacosInstance.class, NacosSwitch.class, NacosService.class,
|
||||
NacosUse.class,
|
||||
// NacosWatch.class,
|
||||
})
|
||||
public class NacosCtl extends NacosCommand {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return APP_NAME;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.command;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_QUIT;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_QUIT;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_QUIT_ALIAS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_QUIT;
|
||||
|
||||
/**
|
||||
* quit from cli
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_QUIT, aliases = NAME_QUIT_ALIAS, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_QUIT, description = DESCRIPTION_QUIT)
|
||||
public class NacosQuit implements Callable<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
try {
|
||||
LogicHandler.shutdown();
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
System.out.println("bye!");
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.command.spi;
|
||||
|
||||
import com.alibaba.nacos.ctl.command.NacosCommand;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Nacos command loader.
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public class NacosCommandLoader {
|
||||
|
||||
private static final NacosCommandLoader INSTANCE = new NacosCommandLoader();
|
||||
|
||||
private static final Map<String, NacosCommand> COMMANDS = new ConcurrentHashMap<>();
|
||||
|
||||
private static final String IGNORE_INVALID_COMMANDS = "Ignore invalid command(%s) without CommandLine.Command annotation.";
|
||||
|
||||
private static final String LOADED_COMMANDS = "Load command(%s) finished.";
|
||||
|
||||
private NacosCommandLoader() {
|
||||
}
|
||||
|
||||
public static NacosCommandLoader getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void loadCommands() {
|
||||
for (NacosCommand each : ServiceLoader.load(NacosCommand.class)) {
|
||||
if (notContainCommandAnnotation(each.getClass())) {
|
||||
System.out.println(String.format(IGNORE_INVALID_COMMANDS, each.getCommandName()));
|
||||
continue;
|
||||
}
|
||||
System.out.println(String.format(LOADED_COMMANDS, each.getCommandName()));
|
||||
COMMANDS.putIfAbsent(each.getCommandName(), each);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean notContainCommandAnnotation(Class<? extends NacosCommand> clazz) {
|
||||
return clazz.getAnnotationsByType(CommandLine.Command.class).length == 0;
|
||||
}
|
||||
|
||||
public Collection<NacosCommand> getLoadedCommands() {
|
||||
return COMMANDS.values();
|
||||
}
|
||||
}
|
28
core/pom.xml
28
core/pom.xml
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nacos-ctl-core</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,63 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.core.utils;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import com.alibaba.nacos.client.config.impl.SpasAdapter;
|
||||
import com.alibaba.nacos.client.naming.utils.SignUtil;
|
||||
import com.alibaba.nacos.common.constant.HttpHeaderConsts;
|
||||
import com.alibaba.nacos.common.http.param.Header;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.common.utils.UuidUtils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Auth utils
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public class AuthUtils {
|
||||
|
||||
public static Header buildConfigSpas(Map<String, String> paramValues, String accessKey, String secretKey) {
|
||||
Header header = Header.newInstance();
|
||||
header.getHeader().remove(HttpHeaderConsts.CONTENT_TYPE);
|
||||
if (StringUtils.isNotEmpty(accessKey) && StringUtils.isNotEmpty(secretKey)) {
|
||||
header.addParam("Spas-AccessKey", accessKey);
|
||||
Map<String, String> signHeaders = SpasAdapter.getSignHeaders(paramValues, secretKey);
|
||||
if (signHeaders != null) {
|
||||
header.addAll(signHeaders);
|
||||
}
|
||||
}
|
||||
String ts = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
header.addParam(Constants.CLIENT_REQUEST_TS_HEADER, ts);
|
||||
header.addParam("exConfigInfo", "true");
|
||||
header.addParam(HttpHeaderConsts.REQUEST_ID, UuidUtils.generateUuid());
|
||||
return header;
|
||||
}
|
||||
|
||||
public static void injectNamingSpas(Map<String, String> paramValues, String accessKey, String secretKey) {
|
||||
if (StringUtils.isNotBlank(accessKey) && StringUtils.isNotBlank(secretKey)) {
|
||||
try {
|
||||
String signData = getSignData(paramValues.get("serviceName"));
|
||||
String signature = SignUtil.sign(signData, secretKey);
|
||||
paramValues.put("signature", signature);
|
||||
paramValues.put("data", signData);
|
||||
paramValues.put("ak", accessKey);
|
||||
} catch (Exception e) {
|
||||
System.out.println("inject ak/sk failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSignData(String serviceName) {
|
||||
return StringUtils.isNotEmpty(serviceName) ? System.currentTimeMillis() + "@@" + serviceName
|
||||
: String.valueOf(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public static void injectIdentity(Header header, String identityKey, String identityValue) {
|
||||
if (StringUtils.isNotBlank(identityKey) && StringUtils.isNotBlank(identityValue)) {
|
||||
header.addParam(identityKey, identityValue);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<assembly>
|
||||
<id>release</id>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<formats>
|
||||
<format>dir</format>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<includes>
|
||||
<include>conf/**</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<includes>
|
||||
<include>bin/*</include>
|
||||
</includes>
|
||||
<fileMode>0755</fileMode>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<!--打好的jar包名称和放置目录-->
|
||||
<source>../bootstrap/target/nacos-ctl-bootstrap-${project.version}-jar-with-dependencies.jar</source>
|
||||
<outputDirectory>target/</outputDirectory>
|
||||
<destName>nacosctl.jar</destName>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
|
@ -1,80 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cygwin=false
|
||||
darwin=false
|
||||
os400=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true;;
|
||||
Darwin*) darwin=true;;
|
||||
OS400*) os400=true;;
|
||||
esac
|
||||
error_exit ()
|
||||
{
|
||||
echo "ERROR: $1 !!"
|
||||
exit 1
|
||||
}
|
||||
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
|
||||
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
|
||||
[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/opt/taobao/java
|
||||
[ ! -e "$JAVA_HOME/bin/java" ] && unset JAVA_HOME
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if $darwin; then
|
||||
|
||||
if [ -x '/usr/libexec/java_home' ] ; then
|
||||
export JAVA_HOME=`/usr/libexec/java_home`
|
||||
|
||||
elif [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home" ]; then
|
||||
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home"
|
||||
fi
|
||||
else
|
||||
JAVA_PATH=`dirname $(readlink -f $(which javac))`
|
||||
if [ "x$JAVA_PATH" != "x" ]; then
|
||||
export JAVA_HOME=`dirname $JAVA_PATH 2>/dev/null`
|
||||
fi
|
||||
fi
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better!"
|
||||
fi
|
||||
fi
|
||||
|
||||
export SERVER="nacosctl"
|
||||
|
||||
export JAVA_HOME
|
||||
export JAVA="$JAVA_HOME/bin/java"
|
||||
export BASE_DIR=`cd $(dirname $0)/..; pwd`
|
||||
export CONFIG_DIR=${BASE_DIR}/conf/
|
||||
|
||||
#===========================================================================================
|
||||
# JVM Configuration
|
||||
#===========================================================================================
|
||||
|
||||
JAVA_OPT="${JAVA_OPT} -Xms512m -Xmx512m -Xmn256m"
|
||||
|
||||
JAVA_MAJOR_VERSION=$($JAVA -version 2>&1 | sed -E -n 's/.* version "([0-9]*).*$/\1/p')
|
||||
if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then
|
||||
JAVA_OPT_EXT_FIX=""
|
||||
else
|
||||
JAVA_OPT_EXT_FIX="-Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
|
||||
fi
|
||||
|
||||
JAVA_OPT="${JAVA_OPT} -Dconfig.dir=${CONFIG_DIR}"
|
||||
JAVA_OPT="${JAVA_OPT} -jar ${BASE_DIR}/target/${SERVER}.jar"
|
||||
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
|
||||
|
||||
if [ ! -d "${BASE_DIR}/logs" ]; then
|
||||
mkdir ${BASE_DIR}/logs
|
||||
fi
|
||||
|
||||
echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT} $@"
|
||||
|
||||
# check the start.out log output file
|
||||
if [ ! -f "${BASE_DIR}/logs/start.out" ]; then
|
||||
touch "${BASE_DIR}/logs/start.out"
|
||||
fi
|
||||
|
||||
if [[ "$JAVA_OPT_EXT_FIX" == "" ]]; then
|
||||
"$JAVA" ${JAVA_OPT} "$@"
|
||||
else
|
||||
"$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} "$@"
|
||||
fi
|
|
@ -1,7 +0,0 @@
|
|||
#username = nacos
|
||||
#password = nacos
|
||||
#confirmEnabled = true
|
||||
#accessKey =
|
||||
#secretKey =
|
||||
#host = localhost
|
||||
#port = 8848
|
|
@ -1,47 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>distrobution</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-bootstrap</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>nacos-ctl</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>assembly/release.xml</descriptor>
|
||||
</descriptors>
|
||||
<tarLongFileMode>posix</tarLongFileMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -1,26 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nacos-ctl-interaction</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,25 +0,0 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||
|
||||
import jline.console.completer.Completer;
|
||||
|
||||
/**
|
||||
* Nacos completer builder
|
||||
*
|
||||
* @author xiweng.yy
|
||||
*/
|
||||
public interface NacosCompleterBuilder {
|
||||
|
||||
/**
|
||||
* Get completer name.
|
||||
*
|
||||
* @return completer name
|
||||
*/
|
||||
String getCompleterName();
|
||||
|
||||
/**
|
||||
* Build target completer.
|
||||
*
|
||||
* @return completer
|
||||
*/
|
||||
Completer build();
|
||||
}
|
238
pom.xml
238
pom.xml
|
@ -1,196 +1,100 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacosctl</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>${revision}</version>
|
||||
<modules>
|
||||
<module>distrobution</module>
|
||||
<module>core</module>
|
||||
<module>interaction</module>
|
||||
<module>command</module>
|
||||
<module>bootstrap</module>
|
||||
</modules>
|
||||
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<revision>1.0.1</revision>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<nacos.client.version>1.4.4</nacos.client.version>
|
||||
<picocli.version>4.6.3</picocli.version>
|
||||
<asciitable.version>0.3.2</asciitable.version>
|
||||
<jline.version>2.14.6</jline.version>
|
||||
<httpcomponents.version>4.5.14</httpcomponents.version>
|
||||
<gson.version>2.8.9</gson.version>
|
||||
<slf4j.version>1.7.36</slf4j.version>
|
||||
<logback.version>1.2.11</logback.version>
|
||||
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<mockito.version>4.0.0</mockito.version>
|
||||
|
||||
<maven-resources-plugin.version>3.3.0</maven-resources-plugin.version>
|
||||
<maven-assembly-plugin.version>3.4.2</maven-assembly-plugin.version>
|
||||
<maven-flatten-version>1.1.0</maven-flatten-version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-interaction</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-command</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-ctl-bootstrap</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
<artifactId>picocli</artifactId>
|
||||
<version>${picocli.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos.client.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.vandermeer</groupId>
|
||||
<artifactId>asciitable</artifactId>
|
||||
<version>${asciitable.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
<version>${jline.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpcomponents.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.picocli</groupId>
|
||||
<artifactId>picocli</artifactId>
|
||||
<version>4.6.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>1.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>de.vandermeer</groupId>
|
||||
<artifactId>asciitable</artifactId>
|
||||
<version>0.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jline</groupId>
|
||||
<artifactId>jline</artifactId>
|
||||
<version>2.14.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.1.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>${maven-assembly-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>${maven-resources-plugin.version}</version>
|
||||
<configuration>
|
||||
<!-- We are not suppose to setup the customer resources here -->
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${maven-flatten-version}</version>
|
||||
<configuration>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
<pomElements>
|
||||
<dependencies>expand</dependencies>
|
||||
</pomElements>
|
||||
</configuration>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>
|
||||
com.alibaba.nacos.cli.ClientMain
|
||||
</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.alibaba.nacos.cli;
|
||||
|
||||
import com.alibaba.nacos.cli.commands.NacosCtl;
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import com.alibaba.nacos.cli.utils.StringUtils;
|
||||
import picocli.CommandLine;
|
||||
|
||||
/**
|
||||
* 黑窗命令行客户端
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class ClientMain {
|
||||
|
||||
public static void main(String[] args) throws HandlerException {
|
||||
|
||||
System.out.println("NacosCtl Loading...\n");
|
||||
InputGetter.init();
|
||||
|
||||
System.out.println("Loading Nacos client sdk...\n");
|
||||
LogicHandler.init();
|
||||
|
||||
new CommandLine(new NacosCtl()).execute(args);
|
||||
|
||||
loopExecute(InputGetter.getInstance());
|
||||
}
|
||||
|
||||
private static void loopExecute(InputGetter in) {
|
||||
|
||||
String[] args;
|
||||
|
||||
// 循环执行命令
|
||||
while (true) {
|
||||
|
||||
String line = in.nextLine();
|
||||
args = StringUtils.parseInput(line);
|
||||
// 忽略无效输入
|
||||
if (args.length < 1 || args[0].length() < 1) {
|
||||
continue;
|
||||
}
|
||||
// 给Picocli执行命令
|
||||
int ret = new CommandLine(new NacosCtl()).execute(args);
|
||||
// 特殊的流程控制,通过返回值来判断,-1是退出,-2是清屏
|
||||
if (ret == -1) {
|
||||
break;
|
||||
}
|
||||
if (ret == -2) {
|
||||
in.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.alibaba.nacos.cli.commands;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_CLEAR;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_CLEAR;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_CLEAR;
|
||||
|
||||
/**
|
||||
* clear the terminal, it only works with jline input
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_CLEAR, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_CLEAR, description = DESCRIPTION_CLEAR)
|
||||
public class NacosClear implements Callable<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer call() throws Exception {
|
||||
return -2;
|
||||
}
|
||||
}
|
|
@ -1,75 +1,77 @@
|
|||
package com.alibaba.nacos.ctl.bootstrap.command;
|
||||
|
||||
import com.alibaba.nacos.ctl.command.NacosClear;
|
||||
import com.alibaba.nacos.ctl.command.NacosQuit;
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.config.ConfigLoader;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.APP_NAME;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.CLI_DESCRIPTION;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.COMMAND_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.FOOTER;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.GREETING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.MIXIN_STANDARD_HELP_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.VERSION_NAME;
|
||||
|
||||
/**
|
||||
* the main command, based on picocli
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Command(name = APP_NAME, mixinStandardHelpOptions = MIXIN_STANDARD_HELP_OPTIONS, version = VERSION_NAME, description = CLI_DESCRIPTION, commandListHeading = COMMAND_LIST_HEADING, footer = FOOTER, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosQuit.class, NacosClear.class})
|
||||
public class NacosBootstrapCommand implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-e",
|
||||
"--endpoint"}, paramLabel = "<endpoint ip>", description = "The Nacos-Server host Ip.")
|
||||
private String host;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--port"}, paramLabel = "<port>", description = "The port of Nacos-Server.")
|
||||
private Integer port;
|
||||
|
||||
@CommandLine.Option(names = {"-u",
|
||||
"--username"}, paramLabel = "<username>", description = "Nacos authentication username.")
|
||||
private String username;
|
||||
|
||||
@CommandLine.Option(names = {"-pswd",
|
||||
"--password"}, paramLabel = "<password>", description = "Nacos password username.")
|
||||
private String password;
|
||||
|
||||
@CommandLine.Option(names = {"-ak", "--accessKey"}, paramLabel = "<accessKey>", description = "Nacos access key.")
|
||||
private String accessKey;
|
||||
|
||||
@CommandLine.Option(names = {"-sk", "--secretKey"}, paramLabel = "<secretKey>", description = "Nacos secret key.")
|
||||
private String secretKey;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(GREETING);
|
||||
Map<String, String> confs = new HashMap<>();
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
if (f.isAnnotationPresent(CommandLine.Option.class)) {
|
||||
try {
|
||||
Object o = f.get(this);
|
||||
if (o != null) {
|
||||
confs.put(f.getName(), o.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//todo
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!confs.isEmpty()) {
|
||||
ConfigLoader.preload(confs);
|
||||
GlobalConfig.getInstance().refresh();
|
||||
LogicHandler.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands;
|
||||
|
||||
import com.alibaba.nacos.cli.commands.config.NacosConfig;
|
||||
import com.alibaba.nacos.cli.commands.instance.NacosInstance;
|
||||
import com.alibaba.nacos.cli.commands.namespace.NacosNamespace;
|
||||
import com.alibaba.nacos.cli.commands.service.NacosService;
|
||||
import com.alibaba.nacos.cli.commands.switches.NacosSwitch;
|
||||
import com.alibaba.nacos.cli.config.ConfigLoader;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.Command;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.APP_NAME;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.CLI_DESCRIPTION;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.COMMAND_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.FOOTER;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.GREETING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.MIXIN_STANDARD_HELP_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.VERSION_NAME;
|
||||
|
||||
/**
|
||||
* the main command, based on picocli
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Command(name = APP_NAME, mixinStandardHelpOptions = MIXIN_STANDARD_HELP_OPTIONS, version = VERSION_NAME, description = CLI_DESCRIPTION, commandListHeading = COMMAND_LIST_HEADING, footer = FOOTER, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosQuit.class, NacosClear.class, NacosConfig.class, NacosNamespace.class,
|
||||
NacosInstance.class, NacosSwitch.class, NacosService.class,
|
||||
// NacosMetrics.class,
|
||||
NacosUse.class,
|
||||
// NacosWatch.class,
|
||||
})
|
||||
public class NacosCtl implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-e",
|
||||
"--endpoint"}, paramLabel = "<endpoint ip>", description = "The Nacos-Server host Ip.")
|
||||
private String host;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--port"}, paramLabel = "<port>", description = "The port of Nacos-Server.")
|
||||
private Integer port;
|
||||
|
||||
@CommandLine.Option(names = {"-u",
|
||||
"--username"}, paramLabel = "<username>", description = "Nacos authentication username.")
|
||||
private String username;
|
||||
|
||||
@CommandLine.Option(names = {"-pswd",
|
||||
"--password"}, paramLabel = "<password>", description = "Nacos password username.")
|
||||
private String password;
|
||||
|
||||
@CommandLine.Option(names = {"-ak", "--accessKey"}, paramLabel = "<accessKey>", description = "Nacos access key.")
|
||||
private String accessKey;
|
||||
|
||||
@CommandLine.Option(names = {"-sk", "--secretKey"}, paramLabel = "<secretKey>", description = "Nacos secret key.")
|
||||
private String secretKey;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println(GREETING);
|
||||
Map<String, String> confs = new HashMap<>();
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
if (f.isAnnotationPresent(CommandLine.Option.class)) {
|
||||
try {
|
||||
Object o = f.get(this);
|
||||
if (o != null) {
|
||||
confs.put(f.getName(), o.toString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//todo
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigLoader.preload(confs);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
package com.alibaba.nacos.cli.commands;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_METRICS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_METRICS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_METRICS;
|
||||
|
||||
/**
|
||||
* get metrics data from nacos prometheus http port
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_METRICS, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_METRICS, description = DESCRIPTION_METRICS, subcommands = {
|
||||
CommandLine.HelpCommand.class})
|
||||
@Deprecated
|
||||
public class NacosMetrics implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<module>", description = "The module name of the metrics")
|
||||
public Module module;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Stream<String> metrics = LogicHandler.getMetrics();
|
||||
metrics.map(this::mapModule).filter(Objects::nonNull).sorted().forEachOrdered(System.out::println);
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private enum Module {
|
||||
/**
|
||||
* nacos 客户端模块参数
|
||||
*/
|
||||
CLIENT,
|
||||
/**
|
||||
* nacos server的参数
|
||||
*/
|
||||
NACOS,
|
||||
/**
|
||||
* jvm和gc相关信息
|
||||
*/
|
||||
JVM,
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
EXCEPTION
|
||||
}
|
||||
|
||||
/**
|
||||
* translate metrics name to chinese.
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public String mapModule(String s) {
|
||||
|
||||
String backup = s;
|
||||
|
||||
Map<String, String> map = enumMap.get(module);
|
||||
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||
if (s.startsWith(e.getKey())) {
|
||||
s = s.replace(e.getKey(), e.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (backup.equals(s)) {
|
||||
return null;
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, String> clientMap;
|
||||
|
||||
private static Map<String, String> exceptionMap;
|
||||
|
||||
private static Map<String, String> nacosMap;
|
||||
|
||||
private static Map<String, String> jvmMap;
|
||||
|
||||
private static Map<Module, Map<String, String>> enumMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
jvmMap = new HashMap<>();
|
||||
jvmMap.put("system_cpu_usage", "CPU使用率");
|
||||
jvmMap.put("system_load_average_1m", "CPU负载");
|
||||
jvmMap.put("jvm_memory_used_bytes", "内存使用字节");
|
||||
jvmMap.put("jvm_memory_max_bytes", "内存最大字节");
|
||||
jvmMap.put("jvm_gc_pause_seconds_count", "GC次数");
|
||||
jvmMap.put("jvm_gc_pause_seconds_sum", "GC耗时");
|
||||
jvmMap.put("jvm_threads_daemon", "线程数");
|
||||
|
||||
clientMap = new HashMap<>();
|
||||
clientMap.put("nacos_monitor{name='subServiceCount'}", "订阅的服务数");
|
||||
clientMap.put("nacos_monitor{name='pubServiceCount'}", "发布的服务数");
|
||||
clientMap.put("nacos_monitor{name='configListenSize'}", "监听的配置数");
|
||||
clientMap.put("nacos_client_request_seconds_count", "请求次数");
|
||||
clientMap.put("nacos_client_request_seconds_sum", "请求总耗时");
|
||||
|
||||
nacosMap = new HashMap<>();
|
||||
nacosMap.put("http_server_requests_seconds_count", "http请求次数");
|
||||
nacosMap.put("http_server_requests_seconds_sum", "http请求总耗时");
|
||||
nacosMap.put("nacos_timer_seconds_sum", "Nacos config水平通知耗时");
|
||||
nacosMap.put("nacos_timer_seconds_count", "Nacos config水平通知次数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"longPolling\",}", "Nacos config长连接数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"configCount\",}", "Nacos config配置个数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"dumpTask\",}", "Nacos config配置落盘任务堆积数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"notifyTask\",}", "Nacos config配置水平通知任务堆积数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"getConfig\",}", "Nacos config读配置统计数");
|
||||
nacosMap.put("nacos_monitor{module=\"config\",name=\"publish\",}", "Nacos config写配置统计数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"ipCount\",}", "Nacos naming ip个数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"domCount\",}", "Nacos naming域名个数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"failedPush\",}", "Nacos naming推送失败数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"avgPushCost\",}", "Nacos naming平均推送耗时");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"leaderStatus\",}", "Nacos naming角色状态");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"maxPushCost\",}", "Nacos naming最大推送耗时");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"mysqlhealthCheck\",}", "Nacos naming mysql健康检查次数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"httpHealthCheck\",}", "Nacos naming http健康检查次数");
|
||||
nacosMap.put("nacos_monitor{module=\"naming\",name=\"tcpHealthCheck\",}", "Nacos naming tcp健康检查次数");
|
||||
|
||||
exceptionMap = new HashMap<>();
|
||||
exceptionMap.put("nacos_exception_total{name='db'}", "数据库异常");
|
||||
exceptionMap.put("nacos_exception_total{name='configNotify'}", "Nacos config水平通知失败");
|
||||
exceptionMap.put("nacos_exception_total{name='unhealth'}", "Nacos config server之间健康检查异常");
|
||||
exceptionMap.put("nacos_exception_total{name='disk'}", "Nacos naming写磁盘异常");
|
||||
exceptionMap.put("nacos_exception_total{name='leaderSendBeatFailed'}", "Nacos naming leader发送心跳异常");
|
||||
exceptionMap.put("nacos_exception_total{name='illegalArgument'}", "请求参数不合法");
|
||||
exceptionMap.put("nacos_exception_total{name='nacos'}", "Nacos请求响应内部错误异常");
|
||||
|
||||
enumMap.put(Module.NACOS, nacosMap);
|
||||
enumMap.put(Module.JVM, jvmMap);
|
||||
enumMap.put(Module.EXCEPTION, exceptionMap);
|
||||
enumMap.put(Module.CLIENT, clientMap);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package com.alibaba.nacos.cli.commands;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_QUIT;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_QUIT;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_QUIT;
|
||||
|
||||
/**
|
||||
* quit from cli
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_QUIT, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_QUIT, description = DESCRIPTION_QUIT)
|
||||
public class NacosQuit implements Callable<Integer> {
|
||||
|
||||
|
||||
@Override
|
||||
public Integer call() {
|
||||
try {
|
||||
LogicHandler.shutdown();
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
System.out.println("bye!");
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -1,38 +1,38 @@
|
|||
package com.alibaba.nacos.ctl.command;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_USE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_USE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_USE;
|
||||
|
||||
/**
|
||||
* switch to different namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_USE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_USE, description = DESCRIPTION_USE)
|
||||
public class NacosUse implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<namespace>", description = "Specify a namespace you want to use.")
|
||||
String namespace;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.useNamespace(namespace);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_USE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_USE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_USE;
|
||||
|
||||
/**
|
||||
* switch to different namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_USE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_USE, description = DESCRIPTION_USE)
|
||||
public class NacosUse implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<namespace>", description = "Specify a namespace you want to use.")
|
||||
String namespace;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.useNamespace(namespace);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,34 +1,34 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_CONFIG;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_CONFIG;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_CONFIG;
|
||||
|
||||
/**
|
||||
* config subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_CONFIG, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_CONFIG, description = DESCRIPTION_CONFIG, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosConfigAdd.class, NacosConfigDelete.class, NacosConfigGet.class,
|
||||
// ConfigImport.class,
|
||||
// ConfigExport.class,
|
||||
NacosConfigList.class})
|
||||
public class NacosConfig implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_CONFIG;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_CONFIG;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_CONFIG;
|
||||
|
||||
/**
|
||||
* config subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_CONFIG, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_CONFIG, description = DESCRIPTION_CONFIG, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosConfigAdd.class, NacosConfigDelete.class, NacosConfigGet.class,
|
||||
// ConfigImport.class,
|
||||
// ConfigExport.class,
|
||||
NacosConfigList.class})
|
||||
public class NacosConfig implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,68 +1,65 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "publish configurations", description = "It publishes configurations in Nacos.")
|
||||
public class NacosConfigAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<content or file path>", description = "Configuration content or file path.")
|
||||
String content;
|
||||
|
||||
@CommandLine.Option(names = {"-f", "--file"}, description = "If it is a config content from file?")
|
||||
boolean isFile = false;
|
||||
|
||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||
String type;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (isFile) {
|
||||
try {
|
||||
byte[] bytes = Files.readAllBytes(Paths.get(new File(content).getPath()));
|
||||
content = new String(bytes);
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to read file");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (LogicHandler.postConfig(group, dataId, content, type)) {
|
||||
System.out.println("done");
|
||||
return;
|
||||
}
|
||||
System.out.printf("publish config group:%s, dataid:%s failed%n", group, dataId);
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "publish configurations", description = "It publishes configurations in Nacos.")
|
||||
public class NacosConfigAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<content or file path>", description = "Configuration content or file path.")
|
||||
String content;
|
||||
|
||||
@CommandLine.Option(names = {"-f", "--file"}, description = "If it is a config content from file?")
|
||||
boolean isFile = false;
|
||||
|
||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||
String type;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (isFile) {
|
||||
try {
|
||||
byte[] bytes = Files.readAllBytes(Paths.get(new File(content).getPath()));
|
||||
content = new String(bytes);
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to read file");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.postConfig(group, dataId, content, type);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,45 +1,45 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete configurations", description = "It deletes configurations in Nacos.")
|
||||
public class NacosConfigDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteConfig(group, dataId);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete configurations", description = "It deletes configurations in Nacos.")
|
||||
public class NacosConfigDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteConfig(group, dataId);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +1,61 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.google.common.io.Files;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_EXPORT;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a config from nacos server and export it as a file
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Deprecated
|
||||
@CommandLine.Command(name = NAME_EXPORT, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "export configurations", description = "Get a config from nacos server and export it as a file.")
|
||||
public class NacosConfigExport implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||
File file;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Files.touch(file);
|
||||
} catch (IOException e) {
|
||||
System.out.println("directory not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
byte[] bytes = LogicHandler.getConfig(group, dataId).getBytes();
|
||||
fos.write(bytes);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to write file");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.google.common.io.Files;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_EXPORT;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a config from nacos server and export it as a file
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Deprecated
|
||||
@CommandLine.Command(name = NAME_EXPORT, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "export configurations", description = "Get a config from nacos server and export it as a file.")
|
||||
public class NacosConfigExport implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||
File file;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Files.touch(file);
|
||||
} catch (IOException e) {
|
||||
System.out.println("directory not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
byte[] bytes = LogicHandler.getConfig(group, dataId).getBytes();
|
||||
fos.write(bytes);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to write file");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,67 +1,67 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.google.common.io.Files;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get configurations", description = "This API is used to get configurations in Nacos.")
|
||||
public class NacosConfigGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Option(names = {"-f",
|
||||
"--file"}, paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||
File file;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String content = LogicHandler.getConfig(group, dataId);
|
||||
if (file == null) {
|
||||
System.out.println(content);
|
||||
} else {
|
||||
|
||||
try {
|
||||
Files.touch(file);
|
||||
} catch (IOException e) {
|
||||
System.out.println("directory not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Files.write(content.getBytes(), file);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to write file");
|
||||
}
|
||||
}
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.google.common.io.Files;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get configurations", description = "This API is used to get configurations in Nacos.")
|
||||
public class NacosConfigGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Option(names = {"-f",
|
||||
"--file"}, paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||
File file;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String content = LogicHandler.getConfig(group, dataId);
|
||||
if (file == null) {
|
||||
System.out.println(content);
|
||||
} else {
|
||||
|
||||
try {
|
||||
Files.touch(file);
|
||||
} catch (IOException e) {
|
||||
System.out.println("directory not exist!");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Files.write(content.getBytes(), file);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to write file");
|
||||
}
|
||||
}
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_IMPORT;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* create a config by uploading a local file
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Deprecated
|
||||
@CommandLine.Command(name = NAME_IMPORT, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "import configurations", description = "Create a config by uploading a local file.")
|
||||
public class NacosConfigImport implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna import.")
|
||||
File file;
|
||||
|
||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||
String type;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
int length = fis.available();
|
||||
byte[] bytes = new byte[length];
|
||||
fis.read(bytes);
|
||||
String content = new String(bytes);
|
||||
LogicHandler.postConfig(group, dataId, content, type);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to read file");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_IMPORT;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* create a config by uploading a local file
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@Deprecated
|
||||
@CommandLine.Command(name = NAME_IMPORT, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "import configurations", description = "Create a config by uploading a local file.")
|
||||
public class NacosConfigImport implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna import.")
|
||||
File file;
|
||||
|
||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||
String type;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
int length = fis.available();
|
||||
byte[] bytes = new byte[length];
|
||||
fis.read(bytes);
|
||||
String content = new String(bytes);
|
||||
LogicHandler.postConfig(group, dataId, content, type);
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("file not exists!");
|
||||
} catch (IOException e) {
|
||||
System.out.println("failed to read file");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +1,60 @@
|
|||
package com.alibaba.nacos.ctl.command.config;
|
||||
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* list config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list configurations", description = "List configurations from server.")
|
||||
public class NacosConfigList implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<group>", description = "Configuration group.")
|
||||
String group = "";
|
||||
|
||||
@CommandLine.Option(names = {"-d", "--dataId"}, paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId = "";
|
||||
|
||||
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||
Integer pageNo = 1;
|
||||
|
||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||
Integer pageSize = 20;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String search = "accurate";
|
||||
try {
|
||||
if (StringUtils.isEmpty(group)) {
|
||||
group = "**";
|
||||
search = "blur";
|
||||
}
|
||||
if (StringUtils.isEmpty(dataId)) {
|
||||
dataId = "**";
|
||||
search = "blur";
|
||||
}
|
||||
List<ConfigVO> list = LogicHandler.listConfigs(dataId, group, pageNo, pageSize, search);
|
||||
int counter = 1;
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.getContext().setWidth(60);
|
||||
at.addRule();
|
||||
at.addRow("<Config>", "Data Id", "Group Id");
|
||||
at.addRule();
|
||||
for (ConfigVO bean : list) {
|
||||
at.addRow(counter++, bean.getDataId(), bean.getGroupName());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render());
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* list config
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list configurations", description = "List configurations from server.")
|
||||
public class NacosConfigList implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<group>", description = "Configuration group.")
|
||||
String group = "";
|
||||
|
||||
@CommandLine.Option(names = {"-d", "--dataId"}, paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId = "";
|
||||
|
||||
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||
Integer pageNo = 1;
|
||||
|
||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||
Integer pageSize = 20;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
List<ConfigVO> list = LogicHandler.listConfigs(dataId, group, pageNo, pageSize);
|
||||
int counter = 1;
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.getContext().setWidth(60);
|
||||
at.addRule();
|
||||
at.addRow("<Config>", "Data Id", "Group Id");
|
||||
at.addRule();
|
||||
for (ConfigVO bean : list) {
|
||||
at.addRow(counter++, bean.getDataId(), bean.getGroupName());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render());
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,32 +1,33 @@
|
|||
package com.alibaba.nacos.ctl.command.instance;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_INSTANCE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_INSTANCE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_INSTANCE;
|
||||
|
||||
/**
|
||||
* instance subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_INSTANCE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_INSTANCE, description = DESCRIPTION_INSTANCE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosInstanceAdd.class, NacosInstanceDelete.class, NacosInstanceUpdate.class,
|
||||
NacosInstanceGet.class})
|
||||
public class NacosInstance implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.instance;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_INSTANCE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_INSTANCE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_INSTANCE;
|
||||
|
||||
/**
|
||||
* instance subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_INSTANCE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_INSTANCE, description = DESCRIPTION_INSTANCE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosInstanceAdd.class, NacosInstanceDelete.class, NacosInstanceUpdate.class,
|
||||
NacosInstanceGet.class})
|
||||
public class NacosInstance implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,66 +1,66 @@
|
|||
package com.alibaba.nacos.ctl.command.instance;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add an instance.", description = "Register an instance to service.")
|
||||
public class NacosInstanceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||
Double weight;
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Not Enable.")
|
||||
boolean enabled = true;
|
||||
|
||||
@CommandLine.Option(names = {"-h",
|
||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||
boolean health = true;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||
String metadata;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p",
|
||||
"--ephemeral"}, paramLabel = "<boolean>", description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.addInstance(ip, port, weight, enabled, health, metadata, clusterName, serviceName, groupName,
|
||||
ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.instance;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add an instance.", description = "Register an instance to service.")
|
||||
public class NacosInstanceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||
Double weight;
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Not Enable.")
|
||||
boolean enabled = true;
|
||||
|
||||
@CommandLine.Option(names = {"-h",
|
||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||
boolean health = true;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||
String metadata;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p",
|
||||
"--ephemeral"}, paramLabel = "<boolean>", description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.addInstance(ip, port, weight, enabled, health, metadata, clusterName, serviceName, groupName,
|
||||
ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +1,56 @@
|
|||
package com.alibaba.nacos.ctl.command.instance;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "deregister instance", description = "Delete instance from service.")
|
||||
public class NacosInstanceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteInstance(ip, port, clusterName, serviceName, groupName, ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.instance;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "deregister instance", description = "Delete instance from service.")
|
||||
public class NacosInstanceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteInstance(ip, port, clusterName, serviceName, groupName, ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,58 +1,58 @@
|
|||
package com.alibaba.nacos.ctl.command.instance;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get instances
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get instances", description = "Get instances from server.")
|
||||
public class NacosInstanceGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s", "--subscribed"}, description = "Subscribed.")
|
||||
boolean subscribed = false;
|
||||
|
||||
@CommandLine.Option(names = {"-h",
|
||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||
boolean health = true;
|
||||
|
||||
|
||||
@CommandLine.Option(names = {"-c",
|
||||
"--cluster"}, paramLabel = "<clusterName>", description = "Cluster name. use -c multi times to set multi value")
|
||||
List<String> clusters;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<Instance> instances = LogicHandler.getInstances(serviceName, groupName, clusters, health, subscribed);
|
||||
System.out.println("Instances:");
|
||||
for (Instance in : instances) {
|
||||
System.out.println(in);
|
||||
}
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.instance;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get instances
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get instances", description = "Get instances from server.")
|
||||
public class NacosInstanceGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s", "--subscribed"}, description = "Subscribed.")
|
||||
boolean subscribed = false;
|
||||
|
||||
@CommandLine.Option(names = {"-h",
|
||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||
boolean health = true;
|
||||
|
||||
|
||||
@CommandLine.Option(names = {"-c",
|
||||
"--cluster"}, paramLabel = "<clusterName>", description = "Cluster name. use -c multi times to set multi value")
|
||||
List<String> clusters;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<Instance> instances = LogicHandler.getInstances(serviceName, groupName, clusters, health, subscribed);
|
||||
System.out.println("Instances:");
|
||||
for (Instance in : instances) {
|
||||
System.out.println(in);
|
||||
}
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,60 +1,60 @@
|
|||
package com.alibaba.nacos.ctl.command.instance;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "modify instance", description = "Modify an instance of service.")
|
||||
public class NacosInstanceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||
Double weight;
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Enabled or not.")
|
||||
boolean enabled = true;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||
String metadata;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateInstance(ip, port, weight, enabled, metadata, clusterName, serviceName, groupName,
|
||||
ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.instance;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update an instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "modify instance", description = "Modify an instance of service.")
|
||||
public class NacosInstanceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||
String ip;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||
Integer port;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||
Double weight;
|
||||
|
||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Enabled or not.")
|
||||
boolean enabled = true;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||
String metadata;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
String clusterName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||
boolean ephemeral = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateInstance(ip, port, weight, enabled, metadata, clusterName, serviceName, groupName,
|
||||
ephemeral);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
package com.alibaba.nacos.ctl.command.namespace;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_NAMESPACE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_NAMESPACE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_NAMESPACE;
|
||||
|
||||
/**
|
||||
* namespace subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_NAMESPACE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_NAMESPACE, description = DESCRIPTION_NAMESPACE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosNamespaceAdd.class, NacosNamespaceList.class, NacosNamespaceDelete.class,
|
||||
NacosNamespaceUpdate.class,})
|
||||
public class NacosNamespace implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.namespace;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_NAMESPACE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_NAMESPACE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_NAMESPACE;
|
||||
|
||||
/**
|
||||
* namespace subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_NAMESPACE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_NAMESPACE, description = DESCRIPTION_NAMESPACE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosNamespaceAdd.class, NacosNamespaceList.class, NacosNamespaceDelete.class,
|
||||
NacosNamespaceUpdate.class,})
|
||||
public class NacosNamespace implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,43 +1,43 @@
|
|||
package com.alibaba.nacos.ctl.command.namespace;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* create a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "create namespace", description = "This API is used to create a namespace in Nacos.")
|
||||
public class NacosNamespaceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||
String name;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--description"}, paramLabel = "<description>", description = "Description of the namespace.")
|
||||
String description;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.addNamespace(name, id, description);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.namespace;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* create a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "create namespace", description = "This API is used to create a namespace in Nacos.")
|
||||
public class NacosNamespaceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||
String name;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--description"}, paramLabel = "<description>", description = "Description of the namespace.")
|
||||
String description;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.addNamespace(name, id, description);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +1,42 @@
|
|||
package com.alibaba.nacos.ctl.command.namespace;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete namespace", description = "This API is used to remove a namespace in Nacos.")
|
||||
public class NacosNamespaceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteNamespace(id);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.namespace;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete namespace", description = "This API is used to remove a namespace in Nacos.")
|
||||
public class NacosNamespaceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteNamespace(id);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,44 @@
|
|||
package com.alibaba.nacos.ctl.command.namespace;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the list of all the namespaces from the server.
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all namespaces", description = "This API is used to get all namespaces.")
|
||||
public class NacosNamespaceList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<NamespaceVO> list = LogicHandler.listNamespaces();
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.addRule();
|
||||
at.addRow("Namespace Name", "Namespace Id");
|
||||
at.addRule();
|
||||
for (NamespaceVO bean : list) {
|
||||
at.addRow(bean.getName(), bean.getId());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render(80));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.namespace;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the list of all the namespaces from the server.
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all namespaces", description = "This API is used to get all namespaces.")
|
||||
public class NacosNamespaceList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
List<NamespaceVO> list = LogicHandler.listNamespaces();
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.addRule();
|
||||
at.addRow("Namespace Name", "Namespace Id");
|
||||
at.addRule();
|
||||
for (NamespaceVO bean : list) {
|
||||
at.addRow(bean.getName(), bean.getId());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render(80));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,41 +1,41 @@
|
|||
package com.alibaba.nacos.ctl.command.namespace;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "update a namespace", description = "This API is used to modify a namespace.")
|
||||
public class NacosNamespaceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||
String name;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<description>", description = "Description you gonna update.")
|
||||
String description;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateNamespace(name, id, description);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.namespace;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update a namespace
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "update a namespace", description = "This API is used to modify a namespace.")
|
||||
public class NacosNamespaceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||
String name;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||
String id;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<description>", description = "Description you gonna update.")
|
||||
String description;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateNamespace(name, id, description);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SERVICE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SERVICE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SERVICE;
|
||||
|
||||
/**
|
||||
* service subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SERVICE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SERVICE, description = DESCRIPTION_SERVICE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosServiceAdd.class, NacosServiceGet.class, NacosServiceDelete.class,
|
||||
NacosServiceUpdate.class, NacosServiceList.class})
|
||||
public class NacosService implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SERVICE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SERVICE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SERVICE;
|
||||
|
||||
/**
|
||||
* service subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SERVICE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SERVICE, description = DESCRIPTION_SERVICE, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosServiceAdd.class, NacosServiceGet.class, NacosServiceDelete.class,
|
||||
NacosServiceUpdate.class, NacosServiceList.class})
|
||||
public class NacosService implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a service", description = "This API is used to create a new empty service.")
|
||||
public class NacosServiceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s",
|
||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||
String selector;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-t",
|
||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||
float threshold;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||
String metadata;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.addService(groupName, serviceName, threshold, metadata, selector));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a service", description = "This API is used to create a new empty service.")
|
||||
public class NacosServiceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s",
|
||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||
String selector;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-t",
|
||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||
float threshold;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||
String metadata;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.addService(groupName, serviceName, threshold, metadata, selector));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,44 +1,44 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete service", description = "This API is used to remove a service.")
|
||||
public class NacosServiceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteService(groupName, serviceName);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* delete a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_DELETE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "delete service", description = "This API is used to remove a service.")
|
||||
public class NacosServiceDelete implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LogicHandler.deleteService(groupName, serviceName);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,37 +1,37 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get service", description = "This API is used to get a service info.")
|
||||
public class NacosServiceGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.out.println(LogicHandler.getService(groupName, serviceName));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get service", description = "This API is used to get a service info.")
|
||||
public class NacosServiceGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
System.out.println(LogicHandler.getService(groupName, serviceName));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +1,59 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* list some services intro
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list service intro", description = "Get a quick look of current services on the nacos-server. If you want to get detail about certain service, please use 'service get' command.")
|
||||
public class NacosServiceList implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-s", "--serviceName"}, paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||
Integer pageNo = 1;
|
||||
|
||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||
Integer pageSize = 20;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
List<ServiceVO> list = LogicHandler.listServices(serviceName, groupName, pageNo, pageSize);
|
||||
int counter = 1;
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.getContext().setWidth(100);
|
||||
at.addRule();
|
||||
at.addRow("<Service>", "Service Name", "Group Name", "Healthy Instance Count");
|
||||
at.addRule();
|
||||
for (ServiceVO bean : list) {
|
||||
at.addRow(counter++, bean.getName(), bean.getGroup(), bean.getHealthCount());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render());
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import de.vandermeer.asciitable.AsciiTable;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* list some services intro
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list service intro", description = "Get a quick look of current services on the nacos-server. If you want to get detail about certain service, please use 'service get' command.")
|
||||
public class NacosServiceList implements Runnable {
|
||||
|
||||
@CommandLine.Option(names = {"-s", "--serviceName"}, paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||
Integer pageNo = 1;
|
||||
|
||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||
Integer pageSize = 20;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
List<ServiceVO> list = LogicHandler.listServices(serviceName, groupName, pageNo, pageSize);
|
||||
int counter = 1;
|
||||
AsciiTable at = new AsciiTable();
|
||||
at.getContext().setWidth(100);
|
||||
at.addRule();
|
||||
at.addRow("<Service>", "Service Name", "Group Name", "Healthy Instance Count");
|
||||
at.addRule();
|
||||
for (ServiceVO bean : list) {
|
||||
at.addRow(counter++, bean.getName(), bean.getGroup(), bean.getHealthCount());
|
||||
}
|
||||
at.addRule();
|
||||
System.out.println(at.render());
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +1,49 @@
|
|||
package com.alibaba.nacos.ctl.command.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "update a service", description = "This API is used to modify a service info.")
|
||||
public class NacosServiceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s",
|
||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||
String selector;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-t",
|
||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||
float threshold;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||
String metadata;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateService(groupName, serviceName, threshold, metadata, selector);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* update a service
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_UPDATE, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "update a service", description = "This API is used to modify a service info.")
|
||||
public class NacosServiceUpdate implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Option(names = {"-s",
|
||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||
String selector;
|
||||
|
||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-t",
|
||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||
float threshold;
|
||||
|
||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||
String metadata;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LogicHandler.updateService(groupName, serviceName, threshold, metadata, selector);
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,32 +1,32 @@
|
|||
package com.alibaba.nacos.ctl.command.switches;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SWITCH;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SWITCH;
|
||||
|
||||
/**
|
||||
* switch subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SWITCH, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SWITCH, description = DESCRIPTION_SWITCH, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosSwitchGet.class, NacosSwitchSet.class, NacosSwitchAdd.class,
|
||||
NacosSwitchRemove.class})
|
||||
public class NacosSwitch implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.switches;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SWITCH;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SWITCH;
|
||||
|
||||
/**
|
||||
* switch subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SWITCH, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SWITCH, description = DESCRIPTION_SWITCH, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosSwitchGet.class, NacosSwitchSet.class, NacosSwitchAdd.class,
|
||||
NacosSwitchRemove.class})
|
||||
public class NacosSwitch implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,46 +1,46 @@
|
|||
package com.alibaba.nacos.ctl.command.switches;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* for some switches in the type of map and list, add an element
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add an element to a switch", description = "For some switches in the type of map and list, add an element.")
|
||||
public class NacosSwitchAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||
String key;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||
String value;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
LogicHandler.updateSwitchMap(entry, key, value, debug, "add");
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.switches;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* for some switches in the type of map and list, add an element
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add an element to a switch", description = "For some switches in the type of map and list, add an element.")
|
||||
public class NacosSwitchAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||
String key;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||
String value;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
LogicHandler.updateSwitchMap(entry, key, value, debug, "add");
|
||||
System.out.println("done");
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +1,46 @@
|
|||
package com.alibaba.nacos.ctl.command.switches;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the value of a switch
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get switch value", description = "Get the value of a switch")
|
||||
public class NacosSwitchGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Switch name, input 'all' to get all switches.")
|
||||
String grep = "";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Map<String, String> switchMap = LogicHandler.getSwitches();
|
||||
|
||||
if ("all".equals(grep)) {
|
||||
grep = "";
|
||||
}
|
||||
switchMap.forEach((k, v) -> {
|
||||
if (k.contains(grep)) {
|
||||
System.out.println(k + ":" + v);
|
||||
}
|
||||
});
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.switches;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the value of a switch
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_GET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "get switch value", description = "Get the value of a switch")
|
||||
public class NacosSwitchGet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Switch name, input 'all' to get all switches.")
|
||||
String grep = "";
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
Map<String, String> switchMap = LogicHandler.getSwitches();
|
||||
|
||||
if ("all".equals(grep)) {
|
||||
grep = "";
|
||||
}
|
||||
switchMap.forEach((k, v) -> {
|
||||
if (k.contains(grep)) {
|
||||
System.out.println(k + ":" + v);
|
||||
}
|
||||
});
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +1,46 @@
|
|||
package com.alibaba.nacos.ctl.command.switches;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* for some switches in the type of map and list, remove an element
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove an element to a switch", description = "For some switches in the type of map and list, remove an element.")
|
||||
public class NacosSwitchRemove implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||
String key;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.updateSwitchMap(entry, key, null, debug, "remove"));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.switches;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.InputGetter;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* for some switches in the type of map and list, remove an element
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove an element to a switch", description = "For some switches in the type of map and list, remove an element.")
|
||||
public class NacosSwitchRemove implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||
String key;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (InputGetter.cancelConfirm()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.updateSwitchMap(entry, key, null, debug, "remove"));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,42 +1,42 @@
|
|||
package com.alibaba.nacos.ctl.command.switches;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SET;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* set the value of the switch
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "set the switch value", description = "Set the switch value.(For some switch in the type of map and list, please use add/remove)")
|
||||
public class NacosSwitchSet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||
String value;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.updateSwitch(entry, value, debug));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.switches;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SET;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* set the value of the switch
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_SET, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "set the switch value", description = "Set the switch value.(For some switch in the type of map and list, please use add/remove)")
|
||||
public class NacosSwitchSet implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||
String entry;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||
String value;
|
||||
|
||||
@CommandLine.Option(names = {"-d",
|
||||
"--debug"}, paramLabel = "<debug>", description = "Input \"-d\" to use debug mode, if affect the local server, true means yes, false means no, default true")
|
||||
boolean debug = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
System.out.println(LogicHandler.updateSwitch(entry, value, debug));
|
||||
} catch (HandlerException e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
package com.alibaba.nacos.ctl.command.watch;
|
||||
|
||||
import com.alibaba.nacos.ctl.command.watch.config.NacosWatchConfig;
|
||||
import com.alibaba.nacos.ctl.command.watch.service.NacosWatchInstance;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* watch subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "watch", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "watch service/config.", description = "Set a listener to watch service/config changes.", subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchConfig.class, NacosWatchInstance.class})
|
||||
public class NacosWatch implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch;
|
||||
|
||||
import com.alibaba.nacos.cli.commands.watch.config.NacosWatchConfig;
|
||||
import com.alibaba.nacos.cli.commands.watch.service.NacosWatchInstance;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* watch subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "watch", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "watch service/config.", description = "Set a listener to watch service/config changes.", subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchConfig.class, NacosWatchInstance.class})
|
||||
public class NacosWatch implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,30 +1,30 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.config;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* watch config subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "config", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "watch config", description = "watch config", subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchConfigAdd.class, NacosWatchConfigList.class,
|
||||
NacosWatchConfigRemove.class})
|
||||
@Deprecated
|
||||
public class NacosWatchConfig implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.config;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* watch config subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "config", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "watch config", description = "watch config", subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchConfigAdd.class, NacosWatchConfigList.class,
|
||||
NacosWatchConfigRemove.class})
|
||||
@Deprecated
|
||||
public class NacosWatchConfig implements Runnable {
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,35 +1,35 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add config listener
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a watcher", description = "Add a watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.watchConfig(dataId, group));
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add config listener
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a watcher", description = "Add a watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||
String group;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||
String dataId;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.watchConfig(dataId, group));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,33 +1,33 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the watcher list
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all watchers", description = "List all watchers")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<String> list = LogicHandler.listConfigWatches();
|
||||
list.forEach(l -> {
|
||||
System.out.println(l);
|
||||
});
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the watcher list
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all watchers", description = "List all watchers")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<String> list = LogicHandler.listConfigWatches();
|
||||
list.forEach(l -> {
|
||||
System.out.println(l);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,30 +1,30 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* remove a watcher
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove watcher", description = "Remove a config watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigRemove implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<id>", description = "Listener Id. (Press `Tab` to list Ids)")
|
||||
String id;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.unwatchConfig(id));
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.config;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* remove a watcher
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove watcher", description = "Remove a config watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchConfigRemove implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<id>", description = "Listener Id. (Press `Tab` to list Ids)")
|
||||
String id;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.unwatchConfig(id));
|
||||
}
|
||||
}
|
|
@ -1,33 +1,33 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.service;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SWITCH;
|
||||
|
||||
/**
|
||||
* watch instance subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "instance", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SWITCH, description = DESCRIPTION_SWITCH, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchInstanceAdd.class, NacosWatchInstanceList.class,
|
||||
NacosWatchInstanceRemove.class})
|
||||
@Deprecated
|
||||
public class NacosWatchInstance implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.service;
|
||||
|
||||
import picocli.CommandLine;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SWITCH;
|
||||
|
||||
/**
|
||||
* watch instance subcommand
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "instance", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = USAGE_SWITCH, description = DESCRIPTION_SWITCH, subcommands = {
|
||||
CommandLine.HelpCommand.class, NacosWatchInstanceAdd.class, NacosWatchInstanceList.class,
|
||||
NacosWatchInstanceRemove.class})
|
||||
@Deprecated
|
||||
public class NacosWatchInstance implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Spec
|
||||
CommandLine.Model.CommandSpec spec;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
spec.commandLine().usage(System.err);
|
||||
}
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a listener to instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a watcher", description = "Add a watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
List<String> clusters;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.watchService(serviceName, groupName, clusters));
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* add a listener to instance
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_ADD, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "add a watcher", description = "Add a watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceAdd implements Runnable {
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
List<String> clusters;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.watchService(serviceName, groupName, clusters));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the watcher list
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all watchers", description = "List all watchers")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<String> list = LogicHandler.listServiceWatches();
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* get the watcher list
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = NAME_LIST, sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "list all watchers", description = "List all watchers")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceList implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
List<String> list = LogicHandler.listServiceWatches();
|
||||
list.forEach(System.out::println);
|
||||
}
|
||||
}
|
|
@ -1,40 +1,40 @@
|
|||
package com.alibaba.nacos.ctl.command.watch.service;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* remove a watcher
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove watcher", description = "Remove an instance watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceRemove implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
List<String> clusters;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.unwatchService(serviceName, groupName, clusters));
|
||||
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.commands.watch.service;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
||||
|
||||
/**
|
||||
* remove a watcher
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
@CommandLine.Command(name = "remove", sortOptions = SORT_OPTIONS, headerHeading = HEADER_HEADING, synopsisHeading = SYNOPSIS_HEADING, descriptionHeading = DESCRIPTION_HEADING, parameterListHeading = PARAMETER_LIST_HEADING, optionListHeading = OPTION_LIST_HEADING, header = "remove watcher", description = "Remove an instance watcher.")
|
||||
@Deprecated
|
||||
public class NacosWatchInstanceRemove implements Runnable {
|
||||
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||
String serviceName;
|
||||
|
||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||
String groupName;
|
||||
|
||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||
List<String> clusters;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
System.out.println(LogicHandler.unwatchService(serviceName, groupName, clusters));
|
||||
|
||||
}
|
||||
}
|
|
@ -1,19 +1,17 @@
|
|||
package com.alibaba.nacos.ctl.core.config;
|
||||
package com.alibaba.nacos.cli.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -30,19 +28,11 @@ public class ConfigLoader {
|
|||
|
||||
private static void readFile() {
|
||||
try {
|
||||
Path configFilePath = Paths.get(System.getProperty("config.dir"), CONF_PATH);
|
||||
if (!Files.exists(configFilePath)) {
|
||||
System.out.println(
|
||||
String.format("[WARN] Can't find %s file in dir %s, skip load properties from file.", CONF_PATH,
|
||||
System.getProperty("config.dir")));
|
||||
return;
|
||||
}
|
||||
InputStream inputStream = Files.newInputStream(configFilePath, StandardOpenOption.READ);
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
Map<String, String> propertiesMap = properties.entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
|
||||
tinyDb.putAll(propertiesMap);
|
||||
List<String> lines = Files.readAllLines(Paths.get(CONF_PATH), StandardCharsets.UTF_8);
|
||||
Map<String, String> confs = lines.stream().peek(s -> s.trim()).filter(s -> !s.startsWith("#"))
|
||||
.filter(s -> s.contains("=")).map(s -> s.split("=")).filter(sa -> sa.length == 2)
|
||||
.collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim()));
|
||||
tinyDb.putAll(confs);
|
||||
} catch (Exception e) {
|
||||
//...不存在就不加载
|
||||
}
|
||||
|
@ -70,7 +60,7 @@ public class ConfigLoader {
|
|||
public static boolean fill(Object o) {
|
||||
boolean flag = true;
|
||||
for (Field f : o.getClass().getDeclaredFields()) {
|
||||
if (f.isAnnotationPresent(FromProperties.class)) {
|
||||
if (f.isAnnotationPresent(FromPropertie.class)) {
|
||||
String name = f.getName();
|
||||
String value = tinyDb.get(name);
|
||||
if (value != null) {
|
||||
|
@ -91,19 +81,13 @@ public class ConfigLoader {
|
|||
return flag;
|
||||
}
|
||||
|
||||
public static Properties toProperties() {
|
||||
Properties result = new Properties();
|
||||
result.putAll(tinyDb);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author lehr
|
||||
*/
|
||||
@Documented
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FromProperties {
|
||||
public @interface FromPropertie {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.alibaba.nacos.ctl.core.config;
|
||||
package com.alibaba.nacos.cli.config;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.config.ConfigLoader.FromProperties;
|
||||
import com.alibaba.nacos.cli.config.ConfigLoader.FromPropertie;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
|
@ -22,25 +22,25 @@ public class GlobalConfig {
|
|||
private String namespaceId = "";
|
||||
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private boolean confirmEnabled = true;
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private String host = "localhost";
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private Integer port = 8848;
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private String username = "nacos";
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private String password = "nacos";
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private String accessKey = "accessKey";
|
||||
|
||||
@FromProperties
|
||||
@FromPropertie
|
||||
private String secretKey = "secretKey";
|
||||
|
||||
|
||||
|
@ -57,13 +57,9 @@ public class GlobalConfig {
|
|||
}
|
||||
|
||||
private GlobalConfig() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
boolean fillAll = ConfigLoader.fill(this);
|
||||
if (fillAll) {
|
||||
System.out.println("Successfully load all configuration.\n");
|
||||
System.out.println("Successfully load all configuration from file.\n");
|
||||
}
|
||||
System.out.println(this);
|
||||
}
|
|
@ -1,15 +1,15 @@
|
|||
package com.alibaba.nacos.ctl.core;
|
||||
package com.alibaba.nacos.cli.core;
|
||||
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.core.service.openapi.OpenApiService;
|
||||
import com.alibaba.nacos.ctl.core.service.sdk.SdkConfigService;
|
||||
import com.alibaba.nacos.ctl.core.service.sdk.SdkNamingService;
|
||||
import com.alibaba.nacos.ctl.core.utils.SwitchUtils;
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.service.openapi.OpenApiService;
|
||||
import com.alibaba.nacos.cli.core.service.sdk.SdkConfigService;
|
||||
import com.alibaba.nacos.cli.core.service.sdk.SdkNamingService;
|
||||
import com.alibaba.nacos.cli.utils.SwitchUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -39,20 +39,6 @@ public class LogicHandler {
|
|||
sdkNamingService = new SdkNamingService();
|
||||
}
|
||||
|
||||
public static void refresh() {
|
||||
try {
|
||||
sdkConfigService.shutdown();
|
||||
sdkNamingService.shutdown();
|
||||
config = GlobalConfig.getInstance();
|
||||
openApiService = new OpenApiService();
|
||||
sdkConfigService = new SdkConfigService();
|
||||
sdkNamingService = new SdkNamingService();
|
||||
} catch (Exception e) {
|
||||
System.out.println("refresh Logic Handler failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换当前的默认Namespace ,读取到新到Namespace和Id后,需要:
|
||||
*
|
||||
|
@ -87,14 +73,13 @@ public class LogicHandler {
|
|||
return sdkConfigService.getConfig(dataId, group);
|
||||
}
|
||||
|
||||
public static boolean postConfig(String group, String dataId, String content, String type) throws HandlerException {
|
||||
return sdkConfigService.publishConfig(dataId, group, content, type);
|
||||
public static void postConfig(String group, String dataId, String content, String type) throws HandlerException {
|
||||
sdkConfigService.publishConfig(dataId, group, content, type);
|
||||
}
|
||||
|
||||
public static List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize,
|
||||
String search)
|
||||
public static List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize)
|
||||
throws HandlerException {
|
||||
return openApiService.listConfigs(dataId, group, pageNo, pageSize, search);
|
||||
return openApiService.listConfigs(dataId, group, pageNo, pageSize);
|
||||
}
|
||||
|
||||
public static void deleteConfig(String group, String dataId) throws HandlerException {
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.bean;
|
||||
package com.alibaba.nacos.cli.core.bean;
|
||||
|
||||
/**
|
||||
* @author lehr
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.bean;
|
||||
package com.alibaba.nacos.cli.core.bean;
|
||||
|
||||
/**
|
||||
* @author lehr
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.bean;
|
||||
package com.alibaba.nacos.cli.core.bean;
|
||||
|
||||
/**
|
||||
* @author lehr
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.exception;
|
||||
package com.alibaba.nacos.cli.core.exception;
|
||||
|
||||
/**
|
||||
* @author lehr
|
|
@ -1,12 +1,11 @@
|
|||
package com.alibaba.nacos.ctl.core.service.openapi;
|
||||
package com.alibaba.nacos.cli.core.service.openapi;
|
||||
|
||||
import com.alibaba.nacos.api.utils.StringUtils;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider;
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
@ -18,10 +17,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.DELETE;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.GET;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.POST;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.DELETE;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.GET;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.POST;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||
|
||||
/**
|
||||
* @author lehr Access the server by nacos http open-api
|
||||
|
@ -59,7 +58,7 @@ public class OpenApiService {
|
|||
return httpProvider.nacosRequest(PUT, SWITCH_URL, params);
|
||||
}
|
||||
|
||||
public List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize, String search)
|
||||
public List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize)
|
||||
throws HandlerException {
|
||||
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
|
@ -67,10 +66,9 @@ public class OpenApiService {
|
|||
params.put("group", group);
|
||||
params.put("pageNo", pageNo);
|
||||
params.put("pageSize", pageSize);
|
||||
params.put("search", search);
|
||||
if (!StringUtils.isEmpty(config.getNamespaceId())) {
|
||||
params.put("tenant", config.getNamespaceId());
|
||||
}
|
||||
params.put("search", "accurate");
|
||||
params.put("search", "accurate");
|
||||
params.put("tenant", config.getNamespaceId());
|
||||
String ret = httpProvider.nacosRequest(GET, CONF_URL, params);
|
||||
|
||||
JsonObject data = new JsonParser().parse(ret).getAsJsonObject();
|
|
@ -1,11 +1,8 @@
|
|||
package com.alibaba.nacos.ctl.core.service.openapi.network;
|
||||
package com.alibaba.nacos.cli.core.service.openapi.network;
|
||||
|
||||
import com.alibaba.nacos.common.http.param.Header;
|
||||
import com.alibaba.nacos.ctl.core.config.ConfigLoader;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.core.service.openapi.network.bean.HttpDelete;
|
||||
import com.alibaba.nacos.ctl.core.utils.AuthUtils;
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.service.openapi.network.bean.HttpDelete;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.apache.http.NameValuePair;
|
||||
|
@ -27,12 +24,11 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.DELETE;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.GET;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.POST;
|
||||
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.DELETE;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.GET;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.POST;
|
||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||
import static org.apache.http.client.config.RequestConfig.custom;
|
||||
|
||||
/**
|
||||
|
@ -44,10 +40,6 @@ public class HttpProvider {
|
|||
|
||||
private String authStr = "";
|
||||
|
||||
private String serverIdentityKey;
|
||||
|
||||
private String serverIdentityValue;
|
||||
|
||||
public HttpProvider() {
|
||||
String username = config.getUsername();
|
||||
String password = config.getPassword();
|
||||
|
@ -56,9 +48,6 @@ public class HttpProvider {
|
|||
} catch (HandlerException e) {
|
||||
System.out.println("nacos login failed:" + e.getMessage());
|
||||
}
|
||||
Properties properties = ConfigLoader.toProperties();
|
||||
serverIdentityKey = properties.getProperty("serverIdentityKey", "");
|
||||
serverIdentityValue = properties.getProperty("serverIdentityValue", "");
|
||||
}
|
||||
|
||||
private static final String LOGIN_FAILED = "unknown user!";
|
||||
|
@ -129,26 +118,18 @@ public class HttpProvider {
|
|||
// 拼接完整url
|
||||
String url = getNacosUrl() + "/v1" + path;
|
||||
List<NameValuePair> params = new ArrayList<>();
|
||||
String accessKey = GlobalConfig.getInstance().getAccessKey();
|
||||
String secretKey = GlobalConfig.getInstance().getSecretKey();
|
||||
Map<String, String> tempStringParameters = new HashMap<>();
|
||||
if (parameterMap != null) {
|
||||
parameterMap.forEach((key, value) -> tempStringParameters.put(key, String.valueOf(value)));
|
||||
parameterMap.entrySet().forEach(e -> {
|
||||
if (e.getValue() != null) {
|
||||
params.add(new BasicNameValuePair(e.getKey(), String.valueOf(e.getValue())));
|
||||
}
|
||||
});
|
||||
}
|
||||
Header header = AuthUtils.buildConfigSpas(tempStringParameters, accessKey, secretKey);
|
||||
AuthUtils.injectNamingSpas(tempStringParameters, accessKey, secretKey);
|
||||
AuthUtils.injectIdentity(header, serverIdentityKey, serverIdentityValue);
|
||||
tempStringParameters.forEach((key, value) -> {
|
||||
if (value != null) {
|
||||
params.add(new BasicNameValuePair(key, value));
|
||||
}
|
||||
});
|
||||
|
||||
// 根据请求类型不同,构造请求,拼接参数,发送请求
|
||||
|
||||
try {
|
||||
HttpRequestBase req = generateRequest(method, url, params);
|
||||
header.getHeader().forEach(req::addHeader);
|
||||
String ret = sendRequest(req);
|
||||
if (ret != null && ret.contains(FORBIDDEN)) {
|
||||
throw new HandlerException("403 Forbidden! Please check your permission.");
|
||||
|
@ -177,7 +158,7 @@ public class HttpProvider {
|
|||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
return httpPost;
|
||||
} else if (DELETE.equals(method)) {
|
||||
com.alibaba.nacos.ctl.core.service.openapi.network.bean.HttpDelete httpDelete = new HttpDelete(
|
||||
com.alibaba.nacos.cli.core.service.openapi.network.bean.HttpDelete httpDelete = new HttpDelete(
|
||||
url + "?accessToken=" + authStr);
|
||||
httpDelete.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.service.openapi.network.bean;
|
||||
package com.alibaba.nacos.cli.core.service.openapi.network.bean;
|
||||
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package com.alibaba.nacos.ctl.core.service.sdk;
|
||||
package com.alibaba.nacos.cli.core.service.sdk;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.core.service.sdk.watcher.ConfigWatcher;
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.service.sdk.watcher.ConfigWatcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
|
@ -1,12 +1,12 @@
|
|||
package com.alibaba.nacos.ctl.core.service.sdk;
|
||||
package com.alibaba.nacos.cli.core.service.sdk;
|
||||
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.core.service.sdk.watcher.InstanceWatcher;
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.service.sdk.watcher.InstanceWatcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.service.sdk.watcher;
|
||||
package com.alibaba.nacos.cli.core.service.sdk.watcher;
|
||||
|
||||
import com.alibaba.nacos.api.config.listener.Listener;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.core.service.sdk.watcher;
|
||||
package com.alibaba.nacos.cli.core.service.sdk.watcher;
|
||||
|
||||
import com.alibaba.nacos.api.naming.listener.AbstractEventListener;
|
||||
import com.alibaba.nacos.api.naming.listener.Event;
|
|
@ -1,93 +1,92 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.ctl.intraction.input.completer.NacosCtlCompleter;
|
||||
import jline.console.ConsoleReader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* JLine实现的输入行
|
||||
*
|
||||
* <p>有可能会出现创建出错的情况,那样的话只能用默认的Scanner来
|
||||
*
|
||||
* <p>整个的补全逻辑都在completer包下,自己写了一整套补全逻辑
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class InputGetter {
|
||||
|
||||
private static InputGetter instance = new InputGetter();
|
||||
|
||||
public static InputGetter getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ConsoleReader console;
|
||||
|
||||
private GlobalConfig config = GlobalConfig.getInstance();
|
||||
|
||||
public static void init() throws HandlerException {
|
||||
try {
|
||||
instance.console = new ConsoleReader();
|
||||
instance.console.setHandleUserInterrupt(true);
|
||||
instance.console.addCompleter(new NacosCtlCompleter());
|
||||
} catch (IOException e) {
|
||||
throw new HandlerException("Failed to load JLine", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于删除等请求,需要让用户再确认下
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean cancelConfirm() {
|
||||
|
||||
if (!GlobalConfig.getInstance().isConfirmEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
String s = instance.console.readLine("confirm operation? (y/n) ").trim();
|
||||
boolean cancel = !("yes".equals(s) || "y".equals(s));
|
||||
if (cancel) {
|
||||
System.out.println("operation canceled!");
|
||||
}
|
||||
return cancel;
|
||||
} catch (IOException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public String nextLine() {
|
||||
|
||||
try {
|
||||
return console.readLine(getPrompt());
|
||||
} catch (IOException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
try {
|
||||
console.clearScreen();
|
||||
} catch (IOException e) {
|
||||
System.out.println("fail to clear screen");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给客户端提供prompt文字(每次刷新一次信息)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPrompt() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("[NacosCtl:").append(config.getHostAddress()).append("(").append(config.getNamespaceName())
|
||||
.append(")]>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.input;
|
||||
|
||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.input.completer.NacosCtlCompleter;
|
||||
import jline.console.ConsoleReader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* JLine实现的输入行
|
||||
*
|
||||
* <p>有可能会出现创建出错的情况,那样的话只能用默认的Scanner来
|
||||
*
|
||||
* <p>整个的补全逻辑都在completer包下,自己写了一整套补全逻辑
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class InputGetter {
|
||||
|
||||
private static InputGetter instance = new InputGetter();
|
||||
|
||||
public static InputGetter getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private ConsoleReader console;
|
||||
|
||||
private GlobalConfig config = GlobalConfig.getInstance();
|
||||
|
||||
public static void init() throws HandlerException {
|
||||
try {
|
||||
instance.console = new ConsoleReader();
|
||||
instance.console.addCompleter(new NacosCtlCompleter());
|
||||
} catch (IOException e) {
|
||||
throw new HandlerException("Failed to load JLine", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于删除等请求,需要让用户再确认下
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static boolean cancelConfirm() {
|
||||
|
||||
if (!GlobalConfig.getInstance().isConfirmEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
String s = instance.console.readLine("confirm operation? (y/n) ").trim();
|
||||
boolean cancel = !("yes".equals(s) || "y".equals(s));
|
||||
if (cancel) {
|
||||
System.out.println("operation canceled!");
|
||||
}
|
||||
return cancel;
|
||||
} catch (IOException e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public String nextLine() {
|
||||
|
||||
try {
|
||||
return console.readLine(getPrompt());
|
||||
} catch (IOException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
try {
|
||||
console.clearScreen();
|
||||
} catch (IOException e) {
|
||||
System.out.println("fail to clear screen");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给客户端提供prompt文字(每次刷新一次信息)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPrompt() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("[NacosCtl:").append(config.getHostAddress()).append("(").append(config.getNamespaceName())
|
||||
.append(")]>");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||
package com.alibaba.nacos.cli.input.completer;
|
||||
|
||||
import jline.console.completer.ArgumentCompleter;
|
||||
import jline.console.completer.Completer;
|
||||
|
@ -13,10 +13,7 @@ import java.lang.annotation.Target;
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* 提供各种命令用到的completer group
|
||||
|
@ -25,8 +22,6 @@ import java.util.ServiceLoader;
|
|||
*/
|
||||
public class CompleterFactory {
|
||||
|
||||
private static final String LOADED_COMPLETER = "LOAD completer(%s) finished.";
|
||||
|
||||
/**
|
||||
* @author lehr
|
||||
*/
|
||||
|
@ -35,7 +30,6 @@ public class CompleterFactory {
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
private @interface Enabled {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static List<Completer> loadAll() throws InvocationTargetException, IllegalAccessException {
|
||||
|
@ -51,15 +45,6 @@ public class CompleterFactory {
|
|||
return completers;
|
||||
}
|
||||
|
||||
public static Collection<? extends Completer> loadExtensionCompleter() {
|
||||
List<Completer> result = new LinkedList<>();
|
||||
for (NacosCompleterBuilder each : ServiceLoader.load(NacosCompleterBuilder.class)) {
|
||||
result.add(each.build());
|
||||
System.out.println(String.format(LOADED_COMPLETER, each.getCompleterName()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对于不提供后续补全的几个基本指令,简单提供String补全组
|
||||
*
|
|
@ -1,75 +1,74 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
import jline.internal.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* NacosCtl全局指令自动补全器
|
||||
*
|
||||
* <p>整个程序的各种子指令的补全逻辑都在这里拼接
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class NacosCtlCompleter implements Completer {
|
||||
|
||||
private List<Completer> completers;
|
||||
|
||||
public NacosCtlCompleter() throws HandlerException {
|
||||
try {
|
||||
completers = CompleterFactory.loadAll();
|
||||
completers.addAll(CompleterFactory.loadExtensionCompleter());
|
||||
} catch (Exception e) {
|
||||
throw new HandlerException("failed to load completer groups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
|
||||
Preconditions.checkNotNull(candidates);
|
||||
List<Completion> completions = new ArrayList(this.completers.size());
|
||||
int max = -1;
|
||||
Iterator var6 = this.completers.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
Completer completer = (Completer) var6.next();
|
||||
Completion completion = new Completion(candidates);
|
||||
completion.complete(completer, buffer, cursor);
|
||||
max = Math.max(max, completion.cursor);
|
||||
completions.add(completion);
|
||||
}
|
||||
|
||||
var6 = completions.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
Completion completion = (Completion) var6.next();
|
||||
if (completion.cursor == max) {
|
||||
candidates.addAll(completion.candidates);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
private class Completion {
|
||||
|
||||
public final List<CharSequence> candidates;
|
||||
|
||||
public int cursor;
|
||||
|
||||
public Completion(List<CharSequence> candidates) {
|
||||
Preconditions.checkNotNull(candidates);
|
||||
this.candidates = new LinkedList(candidates);
|
||||
}
|
||||
|
||||
public void complete(Completer completer, String buffer, int cursor) {
|
||||
Preconditions.checkNotNull(completer);
|
||||
this.cursor = completer.complete(buffer, cursor, this.candidates);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.input.completer;
|
||||
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
import jline.internal.Preconditions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* NacosCtl全局指令自动补全器
|
||||
*
|
||||
* <p>整个程序的各种子指令的补全逻辑都在这里拼接
|
||||
*
|
||||
* @author lehr
|
||||
*/
|
||||
public class NacosCtlCompleter implements Completer {
|
||||
|
||||
private List<Completer> completers;
|
||||
|
||||
public NacosCtlCompleter() throws HandlerException {
|
||||
try {
|
||||
completers = CompleterFactory.loadAll();
|
||||
} catch (Exception e) {
|
||||
throw new HandlerException("failed to load completer groups", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
|
||||
Preconditions.checkNotNull(candidates);
|
||||
List<Completion> completions = new ArrayList(this.completers.size());
|
||||
int max = -1;
|
||||
Iterator var6 = this.completers.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
Completer completer = (Completer) var6.next();
|
||||
Completion completion = new Completion(candidates);
|
||||
completion.complete(completer, buffer, cursor);
|
||||
max = Math.max(max, completion.cursor);
|
||||
completions.add(completion);
|
||||
}
|
||||
|
||||
var6 = completions.iterator();
|
||||
|
||||
while (var6.hasNext()) {
|
||||
Completion completion = (Completion) var6.next();
|
||||
if (completion.cursor == max) {
|
||||
candidates.addAll(completion.candidates);
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
private class Completion {
|
||||
|
||||
public final List<CharSequence> candidates;
|
||||
|
||||
public int cursor;
|
||||
|
||||
public Completion(List<CharSequence> candidates) {
|
||||
Preconditions.checkNotNull(candidates);
|
||||
this.candidates = new LinkedList(candidates);
|
||||
}
|
||||
|
||||
public void complete(Completer completer, String buffer, int cursor) {
|
||||
Preconditions.checkNotNull(completer);
|
||||
this.cursor = completer.complete(buffer, cursor, this.candidates);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +1,50 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Use命令自动补全可用的namespace
|
||||
*/
|
||||
class NacosSwitchSetCompleter implements Completer {
|
||||
|
||||
private SortedSet<String> strings = new TreeSet<String>();
|
||||
|
||||
|
||||
@Override
|
||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||
|
||||
// 找服务器刷新可访问的数据类型
|
||||
if (strings.isEmpty()) {
|
||||
Map<String, String> switches = null;
|
||||
try {
|
||||
switches = LogicHandler.getSwitches();
|
||||
} catch (HandlerException e) {
|
||||
switches = Collections.emptyMap();
|
||||
}
|
||||
strings.addAll(switches.keySet());
|
||||
strings.add("all");
|
||||
}
|
||||
|
||||
// 如果目前没有输入,则列出所有选项
|
||||
if (buffer == null) {
|
||||
candidates.addAll(strings);
|
||||
} else {
|
||||
// 进行前缀匹配,把match的加入进去
|
||||
for (String match : strings.tailSet(buffer)) {
|
||||
if (!match.startsWith(buffer)) {
|
||||
break;
|
||||
}
|
||||
candidates.add(match);
|
||||
}
|
||||
}
|
||||
return candidates.isEmpty() ? -1 : 0;
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.input.completer;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Use命令自动补全可用的namespace
|
||||
*/
|
||||
class NacosSwitchSetCompleter implements Completer {
|
||||
|
||||
private SortedSet<String> strings = new TreeSet<String>();
|
||||
|
||||
|
||||
@Override
|
||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||
|
||||
// 找服务器刷新可访问的数据类型
|
||||
if (strings.isEmpty()) {
|
||||
Map<String, String> switches = null;
|
||||
try {
|
||||
switches = LogicHandler.getSwitches();
|
||||
} catch (HandlerException e) {
|
||||
switches = Collections.emptyMap();
|
||||
}
|
||||
strings.addAll(switches.keySet());
|
||||
strings.add("all");
|
||||
}
|
||||
|
||||
// 如果目前没有输入,则列出所有选项
|
||||
if (buffer == null) {
|
||||
candidates.addAll(strings);
|
||||
} else {
|
||||
// 进行前缀匹配,把match的加入进去
|
||||
for (String match : strings.tailSet(buffer)) {
|
||||
if (!match.startsWith(buffer)) {
|
||||
break;
|
||||
}
|
||||
candidates.add(match);
|
||||
}
|
||||
}
|
||||
return candidates.isEmpty() ? -1 : 0;
|
||||
}
|
||||
}
|
|
@ -1,50 +1,50 @@
|
|||
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Use命令自动补全可用的namespace
|
||||
*/
|
||||
class NacosUseCompleter implements Completer {
|
||||
|
||||
private SortedSet<String> strings = new TreeSet<String>();
|
||||
|
||||
|
||||
@Override
|
||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||
|
||||
// 找服务器刷新可访问的数据类型
|
||||
strings.clear();
|
||||
List<NamespaceVO> namespaces = null;
|
||||
try {
|
||||
namespaces = LogicHandler.listNamespaces();
|
||||
} catch (HandlerException e) {
|
||||
namespaces = Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
strings.addAll(namespaces.stream().map(NamespaceVO::toString).collect(Collectors.toList()));
|
||||
|
||||
// 如果目前没有输入,则列出所有选项
|
||||
if (buffer == null) {
|
||||
candidates.addAll(strings);
|
||||
} else {
|
||||
// 进行前缀匹配,把match的加入进去
|
||||
for (String match : strings.tailSet(buffer)) {
|
||||
if (!match.startsWith(buffer)) {
|
||||
break;
|
||||
}
|
||||
candidates.add(match);
|
||||
}
|
||||
}
|
||||
return candidates.isEmpty() ? -1 : 0;
|
||||
}
|
||||
}
|
||||
package com.alibaba.nacos.cli.input.completer;
|
||||
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
import jline.console.completer.Completer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Use命令自动补全可用的namespace
|
||||
*/
|
||||
class NacosUseCompleter implements Completer {
|
||||
|
||||
private SortedSet<String> strings = new TreeSet<String>();
|
||||
|
||||
|
||||
@Override
|
||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||
|
||||
// 找服务器刷新可访问的数据类型
|
||||
strings.clear();
|
||||
List<NamespaceVO> namespaces = null;
|
||||
try {
|
||||
namespaces = LogicHandler.listNamespaces();
|
||||
} catch (HandlerException e) {
|
||||
namespaces = Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
strings.addAll(namespaces.stream().map(NamespaceVO::toString).collect(Collectors.toList()));
|
||||
|
||||
// 如果目前没有输入,则列出所有选项
|
||||
if (buffer == null) {
|
||||
candidates.addAll(strings);
|
||||
} else {
|
||||
// 进行前缀匹配,把match的加入进去
|
||||
for (String match : strings.tailSet(buffer)) {
|
||||
if (!match.startsWith(buffer)) {
|
||||
break;
|
||||
}
|
||||
candidates.add(match);
|
||||
}
|
||||
}
|
||||
return candidates.isEmpty() ? -1 : 0;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.command.utils;
|
||||
package com.alibaba.nacos.cli.utils;
|
||||
|
||||
/**
|
||||
* @author lehr 用来统一记录各种指令的提示信息的,方便编辑和浏览所以写一起了
|
||||
|
@ -10,7 +10,7 @@ public class HintUtils {
|
|||
*/
|
||||
public static final String APP_NAME = "nacosctl";
|
||||
|
||||
public static final String VERSION_NAME = "v1.0.1";
|
||||
public static final String VERSION_NAME = "v1.0.0-Beta";
|
||||
|
||||
public static final String CLI_DESCRIPTION = "NacosCtl is a fast, scalable, helpful client that can let you connect to nacos-server easily.";
|
||||
|
||||
|
@ -51,8 +51,6 @@ public class HintUtils {
|
|||
|
||||
public static final String NAME_QUIT = "quit";
|
||||
|
||||
public static final String NAME_QUIT_ALIAS = "stop";
|
||||
|
||||
public static final String USAGE_QUIT = "Quit from the Cli";
|
||||
|
||||
public static final String DESCRIPTION_QUIT = "Quit from the cli, and close the connection with current server.";
|
|
@ -1,4 +1,4 @@
|
|||
package com.alibaba.nacos.ctl.bootstrap.utils;
|
||||
package com.alibaba.nacos.cli.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
|
@ -1,7 +1,7 @@
|
|||
package com.alibaba.nacos.ctl.core.utils;
|
||||
package com.alibaba.nacos.cli.utils;
|
||||
|
||||
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -0,0 +1,10 @@
|
|||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
<root level="ERROR">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
Loading…
Reference in New Issue