Compare commits
23 Commits
Author | SHA1 | Date |
---|---|---|
|
d2b632c3f1 | |
|
841a7d65a0 | |
|
2418167265 | |
|
4794b51e9b | |
|
2cb3c94916 | |
|
ec89a99cf1 | |
|
986f9add3d | |
|
27aafcb849 | |
|
236e1d14b2 | |
|
36701fe69b | |
|
2bf2cb06f1 | |
|
e04a15aa75 | |
|
59b5560888 | |
|
2ac4c7c6f3 | |
|
1cd1ea971d | |
|
fadb12f238 | |
|
5a3462d10c | |
|
95942a8a7b | |
|
561fcb11e6 | |
|
f0b3fcf595 | |
|
c32dce9403 | |
|
c137c44011 | |
|
185ef09ad1 |
|
@ -0,0 +1,58 @@
|
||||||
|
<?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>
|
|
@ -0,0 +1,72 @@
|
||||||
|
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,77 +1,75 @@
|
||||||
package com.alibaba.nacos.cli.commands;
|
package com.alibaba.nacos.ctl.bootstrap.command;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.commands.config.NacosConfig;
|
import com.alibaba.nacos.ctl.command.NacosClear;
|
||||||
import com.alibaba.nacos.cli.commands.instance.NacosInstance;
|
import com.alibaba.nacos.ctl.command.NacosQuit;
|
||||||
import com.alibaba.nacos.cli.commands.namespace.NacosNamespace;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.commands.service.NacosService;
|
import com.alibaba.nacos.ctl.core.config.ConfigLoader;
|
||||||
import com.alibaba.nacos.cli.commands.switches.NacosSwitch;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.config.ConfigLoader;
|
import picocli.CommandLine;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine.Command;
|
||||||
import picocli.CommandLine.Command;
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Field;
|
import java.util.HashMap;
|
||||||
import java.util.HashMap;
|
import java.util.Map;
|
||||||
import java.util.Map;
|
|
||||||
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.APP_NAME;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.APP_NAME;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.CLI_DESCRIPTION;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.CLI_DESCRIPTION;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.COMMAND_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.COMMAND_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.FOOTER;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.FOOTER;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.GREETING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.GREETING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.MIXIN_STANDARD_HELP_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.MIXIN_STANDARD_HELP_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.VERSION_NAME;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.VERSION_NAME;
|
|
||||||
|
/**
|
||||||
/**
|
* the main command, based on picocli
|
||||||
* the main command, based on picocli
|
*
|
||||||
*
|
* @author lehr
|
||||||
* @author lehr
|
*/
|
||||||
*/
|
@Command(name = APP_NAME, mixinStandardHelpOptions = MIXIN_STANDARD_HELP_OPTIONS, version = VERSION_NAME, description = CLI_DESCRIPTION, commandListHeading = COMMAND_LIST_HEADING, footer = FOOTER, subcommands = {
|
||||||
@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})
|
||||||
CommandLine.HelpCommand.class, NacosQuit.class, NacosClear.class, NacosConfig.class, NacosNamespace.class,
|
public class NacosBootstrapCommand implements Runnable {
|
||||||
NacosInstance.class, NacosSwitch.class, NacosService.class,
|
|
||||||
// NacosMetrics.class,
|
@CommandLine.Option(names = {"-e",
|
||||||
NacosUse.class,
|
"--endpoint"}, paramLabel = "<endpoint ip>", description = "The Nacos-Server host Ip.")
|
||||||
// NacosWatch.class,
|
private String host;
|
||||||
})
|
|
||||||
public class NacosCtl implements Runnable {
|
@CommandLine.Option(names = {"-p", "--port"}, paramLabel = "<port>", description = "The port of Nacos-Server.")
|
||||||
|
private Integer port;
|
||||||
@CommandLine.Option(names = {"-e",
|
|
||||||
"--endpoint"}, paramLabel = "<endpoint ip>", description = "The Nacos-Server host Ip.")
|
@CommandLine.Option(names = {"-u",
|
||||||
private String host;
|
"--username"}, paramLabel = "<username>", description = "Nacos authentication username.")
|
||||||
|
private String username;
|
||||||
@CommandLine.Option(names = {"-p", "--port"}, paramLabel = "<port>", description = "The port of Nacos-Server.")
|
|
||||||
private Integer port;
|
@CommandLine.Option(names = {"-pswd",
|
||||||
|
"--password"}, paramLabel = "<password>", description = "Nacos password username.")
|
||||||
@CommandLine.Option(names = {"-u",
|
private String password;
|
||||||
"--username"}, paramLabel = "<username>", description = "Nacos authentication username.")
|
|
||||||
private String username;
|
@CommandLine.Option(names = {"-ak", "--accessKey"}, paramLabel = "<accessKey>", description = "Nacos access key.")
|
||||||
|
private String accessKey;
|
||||||
@CommandLine.Option(names = {"-pswd",
|
|
||||||
"--password"}, paramLabel = "<password>", description = "Nacos password username.")
|
@CommandLine.Option(names = {"-sk", "--secretKey"}, paramLabel = "<secretKey>", description = "Nacos secret key.")
|
||||||
private String password;
|
private String secretKey;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-ak", "--accessKey"}, paramLabel = "<accessKey>", description = "Nacos access key.")
|
@Override
|
||||||
private String accessKey;
|
public void run() {
|
||||||
|
System.out.println(GREETING);
|
||||||
@CommandLine.Option(names = {"-sk", "--secretKey"}, paramLabel = "<secretKey>", description = "Nacos secret key.")
|
Map<String, String> confs = new HashMap<>();
|
||||||
private String secretKey;
|
for (Field f : this.getClass().getDeclaredFields()) {
|
||||||
|
if (f.isAnnotationPresent(CommandLine.Option.class)) {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
Object o = f.get(this);
|
||||||
System.out.println(GREETING);
|
if (o != null) {
|
||||||
Map<String, String> confs = new HashMap<>();
|
confs.put(f.getName(), o.toString());
|
||||||
for (Field f : this.getClass().getDeclaredFields()) {
|
}
|
||||||
if (f.isAnnotationPresent(CommandLine.Option.class)) {
|
} catch (Exception e) {
|
||||||
try {
|
//todo
|
||||||
Object o = f.get(this);
|
}
|
||||||
if (o != null) {
|
}
|
||||||
confs.put(f.getName(), o.toString());
|
}
|
||||||
}
|
if (!confs.isEmpty()) {
|
||||||
} catch (Exception e) {
|
ConfigLoader.preload(confs);
|
||||||
//todo
|
GlobalConfig.getInstance().refresh();
|
||||||
}
|
LogicHandler.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConfigLoader.preload(confs);
|
}
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.utils;
|
package com.alibaba.nacos.ctl.bootstrap.utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -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>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?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>
|
|
@ -0,0 +1,29 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +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 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,38 +1,38 @@
|
||||||
package com.alibaba.nacos.cli.commands;
|
package com.alibaba.nacos.ctl.command;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_USE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_USE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_USE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_USE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_USE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_USE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* switch to different namespace
|
* switch to different namespace
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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)
|
@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 {
|
public class NacosUse implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<namespace>", description = "Specify a namespace you want to use.")
|
@CommandLine.Parameters(paramLabel = "<namespace>", description = "Specify a namespace you want to use.")
|
||||||
String namespace;
|
String namespace;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.useNamespace(namespace);
|
LogicHandler.useNamespace(namespace);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,34 +1,34 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_CONFIG;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_CONFIG;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_CONFIG;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_CONFIG;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_CONFIG;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* config subcommand
|
* config subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosConfigAdd.class, NacosConfigDelete.class, NacosConfigGet.class,
|
||||||
// ConfigImport.class,
|
// ConfigImport.class,
|
||||||
// ConfigExport.class,
|
// ConfigExport.class,
|
||||||
NacosConfigList.class})
|
NacosConfigList.class})
|
||||||
public class NacosConfig implements Runnable {
|
public class NacosConfig implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,65 +1,68 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a config
|
* add a config
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosConfigAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<content or file path>", description = "Configuration content or file path.")
|
@CommandLine.Parameters(paramLabel = "<content or file path>", description = "Configuration content or file path.")
|
||||||
String content;
|
String content;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-f", "--file"}, description = "If it is a config content from file?")
|
@CommandLine.Option(names = {"-f", "--file"}, description = "If it is a config content from file?")
|
||||||
boolean isFile = false;
|
boolean isFile = false;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Files.readAllBytes(Paths.get(new File(content).getPath()));
|
byte[] bytes = Files.readAllBytes(Paths.get(new File(content).getPath()));
|
||||||
content = new String(bytes);
|
content = new String(bytes);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("failed to read file");
|
System.out.println("failed to read file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.postConfig(group, dataId, content, type);
|
if (LogicHandler.postConfig(group, dataId, content, type)) {
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
return;
|
||||||
System.out.println(e.getMessage());
|
}
|
||||||
}
|
System.out.printf("publish config group:%s, dataid:%s failed%n", group, dataId);
|
||||||
|
} catch (HandlerException e) {
|
||||||
}
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,45 +1,45 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.InputGetter;
|
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a config
|
* delete a config
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosConfigDelete implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (InputGetter.cancelConfirm()) {
|
if (InputGetter.cancelConfirm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.deleteConfig(group, dataId);
|
LogicHandler.deleteConfig(group, dataId);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,61 +1,61 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_EXPORT;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_EXPORT;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a config from nacos server and export it as a file
|
* get a config from nacos server and export it as a file
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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.")
|
@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 {
|
public class NacosConfigExport implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna export.")
|
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.touch(file);
|
Files.touch(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("directory not exist!");
|
System.out.println("directory not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||||
byte[] bytes = LogicHandler.getConfig(group, dataId).getBytes();
|
byte[] bytes = LogicHandler.getConfig(group, dataId).getBytes();
|
||||||
fos.write(bytes);
|
fos.write(bytes);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("file not exists!");
|
System.out.println("file not exists!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("failed to write file");
|
System.out.println("failed to write file");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,67 +1,67 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a config
|
* get a config
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosConfigGet implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-f",
|
@CommandLine.Option(names = {"-f",
|
||||||
"--file"}, paramLabel = "<file>", description = "The config file path you wanna export.")
|
"--file"}, paramLabel = "<file>", description = "The config file path you wanna export.")
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
String content = LogicHandler.getConfig(group, dataId);
|
String content = LogicHandler.getConfig(group, dataId);
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
System.out.println(content);
|
System.out.println(content);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.touch(file);
|
Files.touch(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("directory not exist!");
|
System.out.println("directory not exist!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Files.write(content.getBytes(), file);
|
Files.write(content.getBytes(), file);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("file not exists!");
|
System.out.println("file not exists!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("failed to write file");
|
System.out.println("failed to write file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,58 +1,58 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_IMPORT;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_IMPORT;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a config by uploading a local file
|
* create a config by uploading a local file
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@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.")
|
@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 {
|
public class NacosConfigImport implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna import.")
|
@CommandLine.Parameters(paramLabel = "<file>", description = "The config file path you wanna import.")
|
||||||
File file;
|
File file;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
@CommandLine.Option(names = {"-t", "--type"}, paramLabel = "<type>", description = "Configuration type.")
|
||||||
String type;
|
String type;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try (FileInputStream fis = new FileInputStream(file)) {
|
try (FileInputStream fis = new FileInputStream(file)) {
|
||||||
int length = fis.available();
|
int length = fis.available();
|
||||||
byte[] bytes = new byte[length];
|
byte[] bytes = new byte[length];
|
||||||
fis.read(bytes);
|
fis.read(bytes);
|
||||||
String content = new String(bytes);
|
String content = new String(bytes);
|
||||||
LogicHandler.postConfig(group, dataId, content, type);
|
LogicHandler.postConfig(group, dataId, content, type);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("file not exists!");
|
System.out.println("file not exists!");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("failed to read file");
|
System.out.println("failed to read file");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,60 +1,69 @@
|
||||||
package com.alibaba.nacos.cli.commands.config;
|
package com.alibaba.nacos.ctl.command.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.api.utils.StringUtils;
|
||||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||||
import de.vandermeer.asciitable.AsciiTable;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import de.vandermeer.asciitable.AsciiTable;
|
||||||
|
import picocli.CommandLine;
|
||||||
import java.util.List;
|
|
||||||
|
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.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_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
|
/**
|
||||||
*
|
* list config
|
||||||
* @author lehr
|
*
|
||||||
*/
|
* @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.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 = {"-g", "--group"}, paramLabel = "<group>", description = "Configuration group.")
|
||||||
|
String group = "";
|
||||||
@CommandLine.Option(names = {"-d", "--dataId"}, paramLabel = "<dataId>", description = "Configuration ID.")
|
|
||||||
String dataId = "";
|
@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 = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||||
|
Integer pageNo = 1;
|
||||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
|
||||||
Integer pageSize = 20;
|
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||||
|
Integer pageSize = 20;
|
||||||
@Override
|
|
||||||
public void run() {
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
String search = "accurate";
|
||||||
List<ConfigVO> list = LogicHandler.listConfigs(dataId, group, pageNo, pageSize);
|
try {
|
||||||
int counter = 1;
|
if (StringUtils.isEmpty(group)) {
|
||||||
AsciiTable at = new AsciiTable();
|
group = "**";
|
||||||
at.getContext().setWidth(60);
|
search = "blur";
|
||||||
at.addRule();
|
}
|
||||||
at.addRow("<Config>", "Data Id", "Group Id");
|
if (StringUtils.isEmpty(dataId)) {
|
||||||
at.addRule();
|
dataId = "**";
|
||||||
for (ConfigVO bean : list) {
|
search = "blur";
|
||||||
at.addRow(counter++, bean.getDataId(), bean.getGroupName());
|
}
|
||||||
}
|
List<ConfigVO> list = LogicHandler.listConfigs(dataId, group, pageNo, pageSize, search);
|
||||||
at.addRule();
|
int counter = 1;
|
||||||
System.out.println(at.render());
|
AsciiTable at = new AsciiTable();
|
||||||
} catch (HandlerException e) {
|
at.getContext().setWidth(60);
|
||||||
System.out.println(e.getMessage());
|
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,33 +1,32 @@
|
||||||
package com.alibaba.nacos.cli.commands.instance;
|
package com.alibaba.nacos.ctl.command.instance;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_INSTANCE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_INSTANCE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_INSTANCE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_INSTANCE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_INSTANCE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_INSTANCE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* instance subcommand
|
* instance subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosInstanceAdd.class, NacosInstanceDelete.class, NacosInstanceUpdate.class,
|
||||||
NacosInstanceGet.class})
|
NacosInstanceGet.class})
|
||||||
public class NacosInstance implements Runnable {
|
public class NacosInstance implements Runnable {
|
||||||
|
|
||||||
|
@CommandLine.Spec
|
||||||
@CommandLine.Spec
|
CommandLine.Model.CommandSpec spec;
|
||||||
CommandLine.Model.CommandSpec spec;
|
|
||||||
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
spec.commandLine().usage(System.err);
|
||||||
spec.commandLine().usage(System.err);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
|
@ -1,66 +1,66 @@
|
||||||
package com.alibaba.nacos.cli.commands.instance;
|
package com.alibaba.nacos.ctl.command.instance;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add an instance
|
* add an instance
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosInstanceAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||||
String ip;
|
String ip;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||||
Integer port;
|
Integer port;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||||
Double weight;
|
Double weight;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Not Enable.")
|
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Not Enable.")
|
||||||
boolean enabled = true;
|
boolean enabled = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-h",
|
@CommandLine.Option(names = {"-h",
|
||||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||||
boolean health = true;
|
boolean health = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||||
String metadata;
|
String metadata;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||||
String clusterName;
|
String clusterName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-p",
|
@CommandLine.Option(names = {"-p",
|
||||||
"--ephemeral"}, paramLabel = "<boolean>", description = "If instance is ephemeral.")
|
"--ephemeral"}, paramLabel = "<boolean>", description = "If instance is ephemeral.")
|
||||||
boolean ephemeral = true;
|
boolean ephemeral = true;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.addInstance(ip, port, weight, enabled, health, metadata, clusterName, serviceName, groupName,
|
LogicHandler.addInstance(ip, port, weight, enabled, health, metadata, clusterName, serviceName, groupName,
|
||||||
ephemeral);
|
ephemeral);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,56 +1,56 @@
|
||||||
package com.alibaba.nacos.cli.commands.instance;
|
package com.alibaba.nacos.ctl.command.instance;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.InputGetter;
|
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete an instance
|
* delete an instance
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosInstanceDelete implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||||
String ip;
|
String ip;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||||
Integer port;
|
Integer port;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||||
String clusterName;
|
String clusterName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||||
boolean ephemeral = true;
|
boolean ephemeral = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (InputGetter.cancelConfirm()) {
|
if (InputGetter.cancelConfirm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.deleteInstance(ip, port, clusterName, serviceName, groupName, ephemeral);
|
LogicHandler.deleteInstance(ip, port, clusterName, serviceName, groupName, ephemeral);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,58 +1,58 @@
|
||||||
package com.alibaba.nacos.cli.commands.instance;
|
package com.alibaba.nacos.ctl.command.instance;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get instances
|
* get instances
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosInstanceGet implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-s", "--subscribed"}, description = "Subscribed.")
|
@CommandLine.Option(names = {"-s", "--subscribed"}, description = "Subscribed.")
|
||||||
boolean subscribed = false;
|
boolean subscribed = false;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-h",
|
@CommandLine.Option(names = {"-h",
|
||||||
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
"--health"}, description = "Healthy or not. Default value is 'true', adding '-h' means 'false'.")
|
||||||
boolean health = true;
|
boolean health = true;
|
||||||
|
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c",
|
@CommandLine.Option(names = {"-c",
|
||||||
"--cluster"}, paramLabel = "<clusterName>", description = "Cluster name. use -c multi times to set multi value")
|
"--cluster"}, paramLabel = "<clusterName>", description = "Cluster name. use -c multi times to set multi value")
|
||||||
List<String> clusters;
|
List<String> clusters;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
List<Instance> instances = LogicHandler.getInstances(serviceName, groupName, clusters, health, subscribed);
|
List<Instance> instances = LogicHandler.getInstances(serviceName, groupName, clusters, health, subscribed);
|
||||||
System.out.println("Instances:");
|
System.out.println("Instances:");
|
||||||
for (Instance in : instances) {
|
for (Instance in : instances) {
|
||||||
System.out.println(in);
|
System.out.println(in);
|
||||||
}
|
}
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,60 +1,60 @@
|
||||||
package com.alibaba.nacos.cli.commands.instance;
|
package com.alibaba.nacos.ctl.command.instance;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update an instance
|
* update an instance
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosInstanceUpdate implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
@CommandLine.Parameters(paramLabel = "<ip>", description = "IP of instance.")
|
||||||
String ip;
|
String ip;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
@CommandLine.Parameters(paramLabel = "<port>", description = "Port of instance.")
|
||||||
Integer port;
|
Integer port;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
@CommandLine.Option(names = {"-w", "--weight"}, paramLabel = "<weight>", description = "Weight")
|
||||||
Double weight;
|
Double weight;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Enabled or not.")
|
@CommandLine.Option(names = {"-e", "--enabled"}, description = "Enabled or not.")
|
||||||
boolean enabled = true;
|
boolean enabled = true;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Extended information.")
|
||||||
String metadata;
|
String metadata;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||||
String clusterName;
|
String clusterName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--group"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
@CommandLine.Option(names = {"-p", "--ephemeral"}, description = "If instance is ephemeral.")
|
||||||
boolean ephemeral = true;
|
boolean ephemeral = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.updateInstance(ip, port, weight, enabled, metadata, clusterName, serviceName, groupName,
|
LogicHandler.updateInstance(ip, port, weight, enabled, metadata, clusterName, serviceName, groupName,
|
||||||
ephemeral);
|
ephemeral);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,32 +1,32 @@
|
||||||
package com.alibaba.nacos.cli.commands.namespace;
|
package com.alibaba.nacos.ctl.command.namespace;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_NAMESPACE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_NAMESPACE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_NAMESPACE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_NAMESPACE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_NAMESPACE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_NAMESPACE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* namespace subcommand
|
* namespace subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosNamespaceAdd.class, NacosNamespaceList.class, NacosNamespaceDelete.class,
|
||||||
NacosNamespaceUpdate.class,})
|
NacosNamespaceUpdate.class,})
|
||||||
public class NacosNamespace implements Runnable {
|
public class NacosNamespace implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,43 +1,43 @@
|
||||||
package com.alibaba.nacos.cli.commands.namespace;
|
package com.alibaba.nacos.ctl.command.namespace;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a namespace
|
* create a namespace
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosNamespaceAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-d",
|
@CommandLine.Option(names = {"-d",
|
||||||
"--description"}, paramLabel = "<description>", description = "Description of the namespace.")
|
"--description"}, paramLabel = "<description>", description = "Description of the namespace.")
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.addNamespace(name, id, description);
|
LogicHandler.addNamespace(name, id, description);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
package com.alibaba.nacos.cli.commands.namespace;
|
package com.alibaba.nacos.ctl.command.namespace;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.InputGetter;
|
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a namespace
|
* delete a namespace
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosNamespaceDelete implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (InputGetter.cancelConfirm()) {
|
if (InputGetter.cancelConfirm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.deleteNamespace(id);
|
LogicHandler.deleteNamespace(id);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,44 +1,44 @@
|
||||||
package com.alibaba.nacos.cli.commands.namespace;
|
package com.alibaba.nacos.ctl.command.namespace;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import de.vandermeer.asciitable.AsciiTable;
|
import de.vandermeer.asciitable.AsciiTable;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the list of all the namespaces from the server.
|
* get the list of all the namespaces from the server.
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosNamespaceList implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
List<NamespaceVO> list = LogicHandler.listNamespaces();
|
List<NamespaceVO> list = LogicHandler.listNamespaces();
|
||||||
AsciiTable at = new AsciiTable();
|
AsciiTable at = new AsciiTable();
|
||||||
at.addRule();
|
at.addRule();
|
||||||
at.addRow("Namespace Name", "Namespace Id");
|
at.addRow("Namespace Name", "Namespace Id");
|
||||||
at.addRule();
|
at.addRule();
|
||||||
for (NamespaceVO bean : list) {
|
for (NamespaceVO bean : list) {
|
||||||
at.addRow(bean.getName(), bean.getId());
|
at.addRow(bean.getName(), bean.getId());
|
||||||
}
|
}
|
||||||
at.addRule();
|
at.addRule();
|
||||||
System.out.println(at.render(80));
|
System.out.println(at.render(80));
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,41 +1,41 @@
|
||||||
package com.alibaba.nacos.cli.commands.namespace;
|
package com.alibaba.nacos.ctl.command.namespace;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update a namespace
|
* update a namespace
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosNamespaceUpdate implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
@CommandLine.Parameters(paramLabel = "<name>", description = "Namespace show name.")
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
@CommandLine.Parameters(paramLabel = "<Id>", description = "Namespace Id.")
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<description>", description = "Description you gonna update.")
|
@CommandLine.Parameters(paramLabel = "<description>", description = "Description you gonna update.")
|
||||||
String description;
|
String description;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.updateNamespace(name, id, description);
|
LogicHandler.updateNamespace(name, id, description);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,32 +1,32 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SERVICE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SERVICE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SERVICE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SERVICE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SERVICE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SERVICE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* service subcommand
|
* service subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosServiceAdd.class, NacosServiceGet.class, NacosServiceDelete.class,
|
||||||
NacosServiceUpdate.class, NacosServiceList.class})
|
NacosServiceUpdate.class, NacosServiceList.class})
|
||||||
public class NacosService implements Runnable {
|
public class NacosService implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,49 +1,49 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a service
|
* add a service
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosServiceAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-s",
|
@CommandLine.Option(names = {"-s",
|
||||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||||
String selector;
|
String selector;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t",
|
@CommandLine.Option(names = {"-t",
|
||||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||||
float threshold;
|
float threshold;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||||
String metadata;
|
String metadata;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println(LogicHandler.addService(groupName, serviceName, threshold, metadata, selector));
|
System.out.println(LogicHandler.addService(groupName, serviceName, threshold, metadata, selector));
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,44 +1,44 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.InputGetter;
|
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_DELETE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_DELETE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a service
|
* delete a service
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosServiceDelete implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (InputGetter.cancelConfirm()) {
|
if (InputGetter.cancelConfirm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.deleteService(groupName, serviceName);
|
LogicHandler.deleteService(groupName, serviceName);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,37 +1,37 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a service
|
* get a service
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosServiceGet implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
System.out.println(LogicHandler.getService(groupName, serviceName));
|
System.out.println(LogicHandler.getService(groupName, serviceName));
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,59 +1,59 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import de.vandermeer.asciitable.AsciiTable;
|
import de.vandermeer.asciitable.AsciiTable;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list some services intro
|
* list some services intro
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosServiceList implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-s", "--serviceName"}, paramLabel = "<serviceName>", description = "Service name.")
|
@CommandLine.Option(names = {"-s", "--serviceName"}, paramLabel = "<serviceName>", description = "Service name.")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
@CommandLine.Option(names = {"-n", "--pageNo"}, paramLabel = "<pageNo>", description = "Page number.")
|
||||||
Integer pageNo = 1;
|
Integer pageNo = 1;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
@CommandLine.Option(names = {"-i", "--pageSize"}, paramLabel = "<pageSize>", description = "Page size.")
|
||||||
Integer pageSize = 20;
|
Integer pageSize = 20;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<ServiceVO> list = LogicHandler.listServices(serviceName, groupName, pageNo, pageSize);
|
List<ServiceVO> list = LogicHandler.listServices(serviceName, groupName, pageNo, pageSize);
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
AsciiTable at = new AsciiTable();
|
AsciiTable at = new AsciiTable();
|
||||||
at.getContext().setWidth(100);
|
at.getContext().setWidth(100);
|
||||||
at.addRule();
|
at.addRule();
|
||||||
at.addRow("<Service>", "Service Name", "Group Name", "Healthy Instance Count");
|
at.addRow("<Service>", "Service Name", "Group Name", "Healthy Instance Count");
|
||||||
at.addRule();
|
at.addRule();
|
||||||
for (ServiceVO bean : list) {
|
for (ServiceVO bean : list) {
|
||||||
at.addRow(counter++, bean.getName(), bean.getGroup(), bean.getHealthCount());
|
at.addRow(counter++, bean.getName(), bean.getGroup(), bean.getHealthCount());
|
||||||
}
|
}
|
||||||
at.addRule();
|
at.addRule();
|
||||||
System.out.println(at.render());
|
System.out.println(at.render());
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,49 +1,49 @@
|
||||||
package com.alibaba.nacos.cli.commands.service;
|
package com.alibaba.nacos.ctl.command.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_UPDATE;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_UPDATE;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update a service
|
* update a service
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosServiceUpdate implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
@CommandLine.Parameters(paramLabel = "<serviceName>", description = "Service name.")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-s",
|
@CommandLine.Option(names = {"-s",
|
||||||
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
"--selector"}, paramLabel = "<selector>", description = "Visit strategy, please input JSON string.")
|
||||||
String selector;
|
String selector;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
@CommandLine.Option(names = {"-g", "--groupName"}, paramLabel = "<groupName>", description = "Group name.")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-t",
|
@CommandLine.Option(names = {"-t",
|
||||||
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
"--threshold"}, paramLabel = "<threshold>", description = "Set value from 0 to 1, default 0.")
|
||||||
float threshold;
|
float threshold;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
@CommandLine.Option(names = {"-m", "--metadata"}, paramLabel = "<metadata>", description = "Metadata of service.")
|
||||||
String metadata;
|
String metadata;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
LogicHandler.updateService(groupName, serviceName, threshold, metadata, selector);
|
LogicHandler.updateService(groupName, serviceName, threshold, metadata, selector);
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,32 +1,32 @@
|
||||||
package com.alibaba.nacos.cli.commands.switches;
|
package com.alibaba.nacos.ctl.command.switches;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SWITCH;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SWITCH;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SWITCH;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SWITCH;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SWITCH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* switch subcommand
|
* switch subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosSwitchGet.class, NacosSwitchSet.class, NacosSwitchAdd.class,
|
||||||
NacosSwitchRemove.class})
|
NacosSwitchRemove.class})
|
||||||
public class NacosSwitch implements Runnable {
|
public class NacosSwitch implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,46 +1,46 @@
|
||||||
package com.alibaba.nacos.cli.commands.switches;
|
package com.alibaba.nacos.ctl.command.switches;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for some switches in the type of map and list, add an element
|
* for some switches in the type of map and list, add an element
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosSwitchAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||||
String entry;
|
String entry;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||||
String key;
|
String key;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-d",
|
@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")
|
"--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;
|
boolean debug = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LogicHandler.updateSwitchMap(entry, key, value, debug, "add");
|
LogicHandler.updateSwitchMap(entry, key, value, debug, "add");
|
||||||
System.out.println("done");
|
System.out.println("done");
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,46 +1,46 @@
|
||||||
package com.alibaba.nacos.cli.commands.switches;
|
package com.alibaba.nacos.ctl.command.switches;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_GET;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_GET;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the value of a switch
|
* get the value of a switch
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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")
|
@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 {
|
public class NacosSwitchGet implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<name>", description = "Switch name, input 'all' to get all switches.")
|
@CommandLine.Parameters(paramLabel = "<name>", description = "Switch name, input 'all' to get all switches.")
|
||||||
String grep = "";
|
String grep = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, String> switchMap = LogicHandler.getSwitches();
|
Map<String, String> switchMap = LogicHandler.getSwitches();
|
||||||
|
|
||||||
if ("all".equals(grep)) {
|
if ("all".equals(grep)) {
|
||||||
grep = "";
|
grep = "";
|
||||||
}
|
}
|
||||||
switchMap.forEach((k, v) -> {
|
switchMap.forEach((k, v) -> {
|
||||||
if (k.contains(grep)) {
|
if (k.contains(grep)) {
|
||||||
System.out.println(k + ":" + v);
|
System.out.println(k + ":" + v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,46 +1,46 @@
|
||||||
package com.alibaba.nacos.cli.commands.switches;
|
package com.alibaba.nacos.ctl.command.switches;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.InputGetter;
|
import com.alibaba.nacos.ctl.intraction.input.InputGetter;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* for some switches in the type of map and list, remove an element
|
* for some switches in the type of map and list, remove an element
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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 {
|
public class NacosSwitchRemove implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||||
String entry;
|
String entry;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
@CommandLine.Parameters(paramLabel = "<key>", description = "Switch value")
|
||||||
String key;
|
String key;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-d",
|
@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")
|
"--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;
|
boolean debug = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (InputGetter.cancelConfirm()) {
|
if (InputGetter.cancelConfirm()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println(LogicHandler.updateSwitchMap(entry, key, null, debug, "remove"));
|
System.out.println(LogicHandler.updateSwitchMap(entry, key, null, debug, "remove"));
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
package com.alibaba.nacos.cli.commands.switches;
|
package com.alibaba.nacos.ctl.command.switches;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_SET;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_SET;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the value of the switch
|
* set the value of the switch
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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)")
|
@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 {
|
public class NacosSwitchSet implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
@CommandLine.Parameters(paramLabel = "<entry>", description = "Switch name")
|
||||||
String entry;
|
String entry;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
@CommandLine.Parameters(paramLabel = "<value>", description = "Switch value")
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-d",
|
@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")
|
"--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;
|
boolean debug = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
System.out.println(LogicHandler.updateSwitch(entry, value, debug));
|
System.out.println(LogicHandler.updateSwitch(entry, value, debug));
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.utils;
|
package com.alibaba.nacos.ctl.command.utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr 用来统一记录各种指令的提示信息的,方便编辑和浏览所以写一起了
|
* @author lehr 用来统一记录各种指令的提示信息的,方便编辑和浏览所以写一起了
|
||||||
|
@ -10,7 +10,7 @@ public class HintUtils {
|
||||||
*/
|
*/
|
||||||
public static final String APP_NAME = "nacosctl";
|
public static final String APP_NAME = "nacosctl";
|
||||||
|
|
||||||
public static final String VERSION_NAME = "v1.0.0-Beta";
|
public static final String VERSION_NAME = "v1.0.1";
|
||||||
|
|
||||||
public static final String CLI_DESCRIPTION = "NacosCtl is a fast, scalable, helpful client that can let you connect to nacos-server easily.";
|
public static final String CLI_DESCRIPTION = "NacosCtl is a fast, scalable, helpful client that can let you connect to nacos-server easily.";
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ public class HintUtils {
|
||||||
|
|
||||||
public static final String NAME_QUIT = "quit";
|
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 USAGE_QUIT = "Quit from the Cli";
|
||||||
|
|
||||||
public static final String DESCRIPTION_QUIT = "Quit from the cli, and close the connection with current server.";
|
public static final String DESCRIPTION_QUIT = "Quit from the cli, and close the connection with current server.";
|
|
@ -1,31 +1,31 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch;
|
package com.alibaba.nacos.ctl.command.watch;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.commands.watch.config.NacosWatchConfig;
|
import com.alibaba.nacos.ctl.command.watch.config.NacosWatchConfig;
|
||||||
import com.alibaba.nacos.cli.commands.watch.service.NacosWatchInstance;
|
import com.alibaba.nacos.ctl.command.watch.service.NacosWatchInstance;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* watch subcommand
|
* watch subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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})
|
CommandLine.HelpCommand.class, NacosWatchConfig.class, NacosWatchInstance.class})
|
||||||
public class NacosWatch implements Runnable {
|
public class NacosWatch implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,30 +1,30 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.config;
|
package com.alibaba.nacos.ctl.command.watch.config;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* watch config subcommand
|
* watch config subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosWatchConfigAdd.class, NacosWatchConfigList.class,
|
||||||
NacosWatchConfigRemove.class})
|
NacosWatchConfigRemove.class})
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class NacosWatchConfig implements Runnable {
|
public class NacosWatchConfig implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,35 +1,35 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.config;
|
package com.alibaba.nacos.ctl.command.watch.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add config listener
|
* add config listener
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchConfigAdd implements Runnable {
|
public class NacosWatchConfigAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
@CommandLine.Parameters(paramLabel = "<group>", description = "Configuration group.")
|
||||||
String group;
|
String group;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
@CommandLine.Parameters(paramLabel = "<dataId>", description = "Configuration ID.")
|
||||||
String dataId;
|
String dataId;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
System.out.println(LogicHandler.watchConfig(dataId, group));
|
System.out.println(LogicHandler.watchConfig(dataId, group));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.config;
|
package com.alibaba.nacos.ctl.command.watch.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the watcher list
|
* get the watcher list
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchConfigList implements Runnable {
|
public class NacosWatchConfigList implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
List<String> list = LogicHandler.listConfigWatches();
|
List<String> list = LogicHandler.listConfigWatches();
|
||||||
list.forEach(l -> {
|
list.forEach(l -> {
|
||||||
System.out.println(l);
|
System.out.println(l);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,30 +1,30 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.config;
|
package com.alibaba.nacos.ctl.command.watch.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove a watcher
|
* remove a watcher
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchConfigRemove implements Runnable {
|
public class NacosWatchConfigRemove implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<id>", description = "Listener Id. (Press `Tab` to list Ids)")
|
@CommandLine.Parameters(paramLabel = "<id>", description = "Listener Id. (Press `Tab` to list Ids)")
|
||||||
String id;
|
String id;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
System.out.println(LogicHandler.unwatchConfig(id));
|
System.out.println(LogicHandler.unwatchConfig(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.service;
|
package com.alibaba.nacos.ctl.command.watch.service;
|
||||||
|
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_SWITCH;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_SWITCH;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.USAGE_SWITCH;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.USAGE_SWITCH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* watch instance subcommand
|
* watch instance subcommand
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.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,
|
CommandLine.HelpCommand.class, NacosWatchInstanceAdd.class, NacosWatchInstanceList.class,
|
||||||
NacosWatchInstanceRemove.class})
|
NacosWatchInstanceRemove.class})
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class NacosWatchInstance implements Runnable {
|
public class NacosWatchInstance implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
@CommandLine.Spec
|
@CommandLine.Spec
|
||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
spec.commandLine().usage(System.err);
|
spec.commandLine().usage(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,40 +1,40 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.service;
|
package com.alibaba.nacos.ctl.command.watch.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_ADD;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_ADD;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a listener to instance
|
* add a listener to instance
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchInstanceAdd implements Runnable {
|
public class NacosWatchInstanceAdd implements Runnable {
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||||
List<String> clusters;
|
List<String> clusters;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
System.out.println(LogicHandler.watchService(serviceName, groupName, clusters));
|
System.out.println(LogicHandler.watchService(serviceName, groupName, clusters));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,31 +1,31 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.service;
|
package com.alibaba.nacos.ctl.command.watch.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.NAME_LIST;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.NAME_LIST;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the watcher list
|
* get the watcher list
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchInstanceList implements Runnable {
|
public class NacosWatchInstanceList implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
List<String> list = LogicHandler.listServiceWatches();
|
List<String> list = LogicHandler.listServiceWatches();
|
||||||
list.forEach(System.out::println);
|
list.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,40 +1,40 @@
|
||||||
package com.alibaba.nacos.cli.commands.watch.service;
|
package com.alibaba.nacos.ctl.command.watch.service;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.DESCRIPTION_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.DESCRIPTION_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.HEADER_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.HEADER_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.OPTION_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.OPTION_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.PARAMETER_LIST_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.PARAMETER_LIST_HEADING;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SORT_OPTIONS;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SORT_OPTIONS;
|
||||||
import static com.alibaba.nacos.cli.utils.HintUtils.SYNOPSIS_HEADING;
|
import static com.alibaba.nacos.ctl.command.utils.HintUtils.SYNOPSIS_HEADING;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove a watcher
|
* remove a watcher
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @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.")
|
@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
|
@Deprecated
|
||||||
public class NacosWatchInstanceRemove implements Runnable {
|
public class NacosWatchInstanceRemove implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
@CommandLine.Parameters(paramLabel = "<service name>", description = "Instance service name")
|
||||||
String serviceName;
|
String serviceName;
|
||||||
|
|
||||||
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
@CommandLine.Parameters(paramLabel = "<group name>", description = "Instance group name")
|
||||||
String groupName;
|
String groupName;
|
||||||
|
|
||||||
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
@CommandLine.Option(names = {"-c", "--cluster"}, paramLabel = "<clusterName>", description = "Cluster name.")
|
||||||
List<String> clusters;
|
List<String> clusters;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
System.out.println(LogicHandler.unwatchService(serviceName, groupName, clusters));
|
System.out.println(LogicHandler.unwatchService(serviceName, groupName, clusters));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?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,15 +1,15 @@
|
||||||
package com.alibaba.nacos.cli.core;
|
package com.alibaba.nacos.ctl.core;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.core.service.openapi.OpenApiService;
|
import com.alibaba.nacos.ctl.core.service.openapi.OpenApiService;
|
||||||
import com.alibaba.nacos.cli.core.service.sdk.SdkConfigService;
|
import com.alibaba.nacos.ctl.core.service.sdk.SdkConfigService;
|
||||||
import com.alibaba.nacos.cli.core.service.sdk.SdkNamingService;
|
import com.alibaba.nacos.ctl.core.service.sdk.SdkNamingService;
|
||||||
import com.alibaba.nacos.cli.utils.SwitchUtils;
|
import com.alibaba.nacos.ctl.core.utils.SwitchUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -39,6 +39,20 @@ public class LogicHandler {
|
||||||
sdkNamingService = new SdkNamingService();
|
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后,需要:
|
* 切换当前的默认Namespace ,读取到新到Namespace和Id后,需要:
|
||||||
*
|
*
|
||||||
|
@ -73,13 +87,14 @@ public class LogicHandler {
|
||||||
return sdkConfigService.getConfig(dataId, group);
|
return sdkConfigService.getConfig(dataId, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void postConfig(String group, String dataId, String content, String type) throws HandlerException {
|
public static boolean postConfig(String group, String dataId, String content, String type) throws HandlerException {
|
||||||
sdkConfigService.publishConfig(dataId, group, content, type);
|
return sdkConfigService.publishConfig(dataId, group, content, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize)
|
public static List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize,
|
||||||
|
String search)
|
||||||
throws HandlerException {
|
throws HandlerException {
|
||||||
return openApiService.listConfigs(dataId, group, pageNo, pageSize);
|
return openApiService.listConfigs(dataId, group, pageNo, pageSize, search);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteConfig(String group, String dataId) throws HandlerException {
|
public static void deleteConfig(String group, String dataId) throws HandlerException {
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.bean;
|
package com.alibaba.nacos.ctl.core.bean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.bean;
|
package com.alibaba.nacos.ctl.core.bean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.bean;
|
package com.alibaba.nacos.ctl.core.bean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
|
@ -1,17 +1,19 @@
|
||||||
package com.alibaba.nacos.cli.config;
|
package com.alibaba.nacos.ctl.core.config;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -28,11 +30,19 @@ public class ConfigLoader {
|
||||||
|
|
||||||
private static void readFile() {
|
private static void readFile() {
|
||||||
try {
|
try {
|
||||||
List<String> lines = Files.readAllLines(Paths.get(CONF_PATH), StandardCharsets.UTF_8);
|
Path configFilePath = Paths.get(System.getProperty("config.dir"), CONF_PATH);
|
||||||
Map<String, String> confs = lines.stream().peek(s -> s.trim()).filter(s -> !s.startsWith("#"))
|
if (!Files.exists(configFilePath)) {
|
||||||
.filter(s -> s.contains("=")).map(s -> s.split("=")).filter(sa -> sa.length == 2)
|
System.out.println(
|
||||||
.collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim()));
|
String.format("[WARN] Can't find %s file in dir %s, skip load properties from file.", CONF_PATH,
|
||||||
tinyDb.putAll(confs);
|
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);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//...不存在就不加载
|
//...不存在就不加载
|
||||||
}
|
}
|
||||||
|
@ -60,7 +70,7 @@ public class ConfigLoader {
|
||||||
public static boolean fill(Object o) {
|
public static boolean fill(Object o) {
|
||||||
boolean flag = true;
|
boolean flag = true;
|
||||||
for (Field f : o.getClass().getDeclaredFields()) {
|
for (Field f : o.getClass().getDeclaredFields()) {
|
||||||
if (f.isAnnotationPresent(FromPropertie.class)) {
|
if (f.isAnnotationPresent(FromProperties.class)) {
|
||||||
String name = f.getName();
|
String name = f.getName();
|
||||||
String value = tinyDb.get(name);
|
String value = tinyDb.get(name);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
@ -81,13 +91,19 @@ public class ConfigLoader {
|
||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Properties toProperties() {
|
||||||
|
Properties result = new Properties();
|
||||||
|
result.putAll(tinyDb);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
@Target({ElementType.FIELD})
|
@Target({ElementType.FIELD})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface FromPropertie {
|
public @interface FromProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alibaba.nacos.cli.config;
|
package com.alibaba.nacos.ctl.core.config;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.config.ConfigLoader.FromPropertie;
|
import com.alibaba.nacos.ctl.core.config.ConfigLoader.FromProperties;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -22,25 +22,25 @@ public class GlobalConfig {
|
||||||
private String namespaceId = "";
|
private String namespaceId = "";
|
||||||
|
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private boolean confirmEnabled = true;
|
private boolean confirmEnabled = true;
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private String host = "localhost";
|
private String host = "localhost";
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private Integer port = 8848;
|
private Integer port = 8848;
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private String username = "nacos";
|
private String username = "nacos";
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private String password = "nacos";
|
private String password = "nacos";
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private String accessKey = "accessKey";
|
private String accessKey = "accessKey";
|
||||||
|
|
||||||
@FromPropertie
|
@FromProperties
|
||||||
private String secretKey = "secretKey";
|
private String secretKey = "secretKey";
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,9 +57,13 @@ public class GlobalConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
private GlobalConfig() {
|
private GlobalConfig() {
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
boolean fillAll = ConfigLoader.fill(this);
|
boolean fillAll = ConfigLoader.fill(this);
|
||||||
if (fillAll) {
|
if (fillAll) {
|
||||||
System.out.println("Successfully load all configuration from file.\n");
|
System.out.println("Successfully load all configuration.\n");
|
||||||
}
|
}
|
||||||
System.out.println(this);
|
System.out.println(this);
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.exception;
|
package com.alibaba.nacos.ctl.core.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
|
@ -1,11 +1,12 @@
|
||||||
package com.alibaba.nacos.cli.core.service.openapi;
|
package com.alibaba.nacos.ctl.core.service.openapi;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.api.utils.StringUtils;
|
||||||
import com.alibaba.nacos.cli.core.bean.ConfigVO;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
import com.alibaba.nacos.ctl.core.bean.ConfigVO;
|
||||||
import com.alibaba.nacos.cli.core.bean.ServiceVO;
|
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.bean.ServiceVO;
|
||||||
import com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
|
import com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
|
@ -17,10 +18,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.DELETE;
|
import static com.alibaba.nacos.ctl.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.ctl.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.ctl.core.service.openapi.network.HttpProvider.Method.POST;
|
||||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.PUT;
|
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr Access the server by nacos http open-api
|
* @author lehr Access the server by nacos http open-api
|
||||||
|
@ -58,7 +59,7 @@ public class OpenApiService {
|
||||||
return httpProvider.nacosRequest(PUT, SWITCH_URL, params);
|
return httpProvider.nacosRequest(PUT, SWITCH_URL, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize)
|
public List<ConfigVO> listConfigs(String dataId, String group, Integer pageNo, Integer pageSize, String search)
|
||||||
throws HandlerException {
|
throws HandlerException {
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
@ -66,9 +67,10 @@ public class OpenApiService {
|
||||||
params.put("group", group);
|
params.put("group", group);
|
||||||
params.put("pageNo", pageNo);
|
params.put("pageNo", pageNo);
|
||||||
params.put("pageSize", pageSize);
|
params.put("pageSize", pageSize);
|
||||||
params.put("search", "accurate");
|
params.put("search", search);
|
||||||
params.put("search", "accurate");
|
if (!StringUtils.isEmpty(config.getNamespaceId())) {
|
||||||
params.put("tenant", config.getNamespaceId());
|
params.put("tenant", config.getNamespaceId());
|
||||||
|
}
|
||||||
String ret = httpProvider.nacosRequest(GET, CONF_URL, params);
|
String ret = httpProvider.nacosRequest(GET, CONF_URL, params);
|
||||||
|
|
||||||
JsonObject data = new JsonParser().parse(ret).getAsJsonObject();
|
JsonObject data = new JsonParser().parse(ret).getAsJsonObject();
|
|
@ -1,8 +1,11 @@
|
||||||
package com.alibaba.nacos.cli.core.service.openapi.network;
|
package com.alibaba.nacos.ctl.core.service.openapi.network;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.common.http.param.Header;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.config.ConfigLoader;
|
||||||
import com.alibaba.nacos.cli.core.service.openapi.network.bean.HttpDelete;
|
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.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import org.apache.http.NameValuePair;
|
import org.apache.http.NameValuePair;
|
||||||
|
@ -24,11 +27,12 @@ import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.DELETE;
|
import static com.alibaba.nacos.ctl.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.ctl.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.ctl.core.service.openapi.network.HttpProvider.Method.POST;
|
||||||
import static com.alibaba.nacos.cli.core.service.openapi.network.HttpProvider.Method.PUT;
|
import static com.alibaba.nacos.ctl.core.service.openapi.network.HttpProvider.Method.PUT;
|
||||||
import static org.apache.http.client.config.RequestConfig.custom;
|
import static org.apache.http.client.config.RequestConfig.custom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,6 +44,10 @@ public class HttpProvider {
|
||||||
|
|
||||||
private String authStr = "";
|
private String authStr = "";
|
||||||
|
|
||||||
|
private String serverIdentityKey;
|
||||||
|
|
||||||
|
private String serverIdentityValue;
|
||||||
|
|
||||||
public HttpProvider() {
|
public HttpProvider() {
|
||||||
String username = config.getUsername();
|
String username = config.getUsername();
|
||||||
String password = config.getPassword();
|
String password = config.getPassword();
|
||||||
|
@ -48,6 +56,9 @@ public class HttpProvider {
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
System.out.println("nacos login failed:" + e.getMessage());
|
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!";
|
private static final String LOGIN_FAILED = "unknown user!";
|
||||||
|
@ -118,18 +129,26 @@ public class HttpProvider {
|
||||||
// 拼接完整url
|
// 拼接完整url
|
||||||
String url = getNacosUrl() + "/v1" + path;
|
String url = getNacosUrl() + "/v1" + path;
|
||||||
List<NameValuePair> params = new ArrayList<>();
|
List<NameValuePair> params = new ArrayList<>();
|
||||||
|
String accessKey = GlobalConfig.getInstance().getAccessKey();
|
||||||
|
String secretKey = GlobalConfig.getInstance().getSecretKey();
|
||||||
|
Map<String, String> tempStringParameters = new HashMap<>();
|
||||||
if (parameterMap != null) {
|
if (parameterMap != null) {
|
||||||
parameterMap.entrySet().forEach(e -> {
|
parameterMap.forEach((key, value) -> tempStringParameters.put(key, String.valueOf(value)));
|
||||||
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 {
|
try {
|
||||||
HttpRequestBase req = generateRequest(method, url, params);
|
HttpRequestBase req = generateRequest(method, url, params);
|
||||||
|
header.getHeader().forEach(req::addHeader);
|
||||||
String ret = sendRequest(req);
|
String ret = sendRequest(req);
|
||||||
if (ret != null && ret.contains(FORBIDDEN)) {
|
if (ret != null && ret.contains(FORBIDDEN)) {
|
||||||
throw new HandlerException("403 Forbidden! Please check your permission.");
|
throw new HandlerException("403 Forbidden! Please check your permission.");
|
||||||
|
@ -158,7 +177,7 @@ public class HttpProvider {
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||||
return httpPost;
|
return httpPost;
|
||||||
} else if (DELETE.equals(method)) {
|
} else if (DELETE.equals(method)) {
|
||||||
com.alibaba.nacos.cli.core.service.openapi.network.bean.HttpDelete httpDelete = new HttpDelete(
|
com.alibaba.nacos.ctl.core.service.openapi.network.bean.HttpDelete httpDelete = new HttpDelete(
|
||||||
url + "?accessToken=" + authStr);
|
url + "?accessToken=" + authStr);
|
||||||
httpDelete.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
httpDelete.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.service.openapi.network.bean;
|
package com.alibaba.nacos.ctl.core.service.openapi.network.bean;
|
||||||
|
|
||||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package com.alibaba.nacos.cli.core.service.sdk;
|
package com.alibaba.nacos.ctl.core.service.sdk;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
import com.alibaba.nacos.api.NacosFactory;
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.core.service.sdk.watcher.ConfigWatcher;
|
import com.alibaba.nacos.ctl.core.service.sdk.watcher.ConfigWatcher;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
|
@ -1,12 +1,12 @@
|
||||||
package com.alibaba.nacos.cli.core.service.sdk;
|
package com.alibaba.nacos.ctl.core.service.sdk;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
import com.alibaba.nacos.api.NacosFactory;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.core.service.sdk.watcher.InstanceWatcher;
|
import com.alibaba.nacos.ctl.core.service.sdk.watcher.InstanceWatcher;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.service.sdk.watcher;
|
package com.alibaba.nacos.ctl.core.service.sdk.watcher;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.config.listener.Listener;
|
import com.alibaba.nacos.api.config.listener.Listener;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.core.service.sdk.watcher;
|
package com.alibaba.nacos.ctl.core.service.sdk.watcher;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.listener.AbstractEventListener;
|
import com.alibaba.nacos.api.naming.listener.AbstractEventListener;
|
||||||
import com.alibaba.nacos.api.naming.listener.Event;
|
import com.alibaba.nacos.api.naming.listener.Event;
|
|
@ -0,0 +1,63 @@
|
||||||
|
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,7 +1,7 @@
|
||||||
package com.alibaba.nacos.cli.utils;
|
package com.alibaba.nacos.ctl.core.utils;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?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>
|
|
@ -0,0 +1,80 @@
|
||||||
|
#!/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
|
|
@ -0,0 +1,7 @@
|
||||||
|
#username = nacos
|
||||||
|
#password = nacos
|
||||||
|
#confirmEnabled = true
|
||||||
|
#accessKey =
|
||||||
|
#secretKey =
|
||||||
|
#host = localhost
|
||||||
|
#port = 8848
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?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>
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?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,92 +1,93 @@
|
||||||
package com.alibaba.nacos.cli.input;
|
package com.alibaba.nacos.ctl.intraction.input;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.config.GlobalConfig;
|
import com.alibaba.nacos.ctl.core.config.GlobalConfig;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import com.alibaba.nacos.cli.input.completer.NacosCtlCompleter;
|
import com.alibaba.nacos.ctl.intraction.input.completer.NacosCtlCompleter;
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JLine实现的输入行
|
* JLine实现的输入行
|
||||||
*
|
*
|
||||||
* <p>有可能会出现创建出错的情况,那样的话只能用默认的Scanner来
|
* <p>有可能会出现创建出错的情况,那样的话只能用默认的Scanner来
|
||||||
*
|
*
|
||||||
* <p>整个的补全逻辑都在completer包下,自己写了一整套补全逻辑
|
* <p>整个的补全逻辑都在completer包下,自己写了一整套补全逻辑
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
public class InputGetter {
|
public class InputGetter {
|
||||||
|
|
||||||
private static InputGetter instance = new InputGetter();
|
private static InputGetter instance = new InputGetter();
|
||||||
|
|
||||||
public static InputGetter getInstance() {
|
public static InputGetter getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConsoleReader console;
|
private ConsoleReader console;
|
||||||
|
|
||||||
private GlobalConfig config = GlobalConfig.getInstance();
|
private GlobalConfig config = GlobalConfig.getInstance();
|
||||||
|
|
||||||
public static void init() throws HandlerException {
|
public static void init() throws HandlerException {
|
||||||
try {
|
try {
|
||||||
instance.console = new ConsoleReader();
|
instance.console = new ConsoleReader();
|
||||||
instance.console.addCompleter(new NacosCtlCompleter());
|
instance.console.setHandleUserInterrupt(true);
|
||||||
} catch (IOException e) {
|
instance.console.addCompleter(new NacosCtlCompleter());
|
||||||
throw new HandlerException("Failed to load JLine", e);
|
} catch (IOException e) {
|
||||||
}
|
throw new HandlerException("Failed to load JLine", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 对于删除等请求,需要让用户再确认下
|
/**
|
||||||
*
|
* 对于删除等请求,需要让用户再确认下
|
||||||
* @return
|
*
|
||||||
*/
|
* @return
|
||||||
public static boolean cancelConfirm() {
|
*/
|
||||||
|
public static boolean cancelConfirm() {
|
||||||
if (!GlobalConfig.getInstance().isConfirmEnabled()) {
|
|
||||||
return false;
|
if (!GlobalConfig.getInstance().isConfirmEnabled()) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
try {
|
|
||||||
String s = instance.console.readLine("confirm operation? (y/n) ").trim();
|
try {
|
||||||
boolean cancel = !("yes".equals(s) || "y".equals(s));
|
String s = instance.console.readLine("confirm operation? (y/n) ").trim();
|
||||||
if (cancel) {
|
boolean cancel = !("yes".equals(s) || "y".equals(s));
|
||||||
System.out.println("operation canceled!");
|
if (cancel) {
|
||||||
}
|
System.out.println("operation canceled!");
|
||||||
return cancel;
|
}
|
||||||
} catch (IOException e) {
|
return cancel;
|
||||||
return true;
|
} catch (IOException e) {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public String nextLine() {
|
|
||||||
|
public String nextLine() {
|
||||||
try {
|
|
||||||
return console.readLine(getPrompt());
|
try {
|
||||||
} catch (IOException e) {
|
return console.readLine(getPrompt());
|
||||||
return "";
|
} catch (IOException e) {
|
||||||
}
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
|
||||||
try {
|
public void clear() {
|
||||||
console.clearScreen();
|
try {
|
||||||
} catch (IOException e) {
|
console.clearScreen();
|
||||||
System.out.println("fail to clear screen");
|
} catch (IOException e) {
|
||||||
}
|
System.out.println("fail to clear screen");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 给客户端提供prompt文字(每次刷新一次信息)
|
/**
|
||||||
*
|
* 给客户端提供prompt文字(每次刷新一次信息)
|
||||||
* @return
|
*
|
||||||
*/
|
* @return
|
||||||
public String getPrompt() {
|
*/
|
||||||
StringBuffer sb = new StringBuffer();
|
public String getPrompt() {
|
||||||
sb.append("[NacosCtl:").append(config.getHostAddress()).append("(").append(config.getNamespaceName())
|
StringBuffer sb = new StringBuffer();
|
||||||
.append(")]>");
|
sb.append("[NacosCtl:").append(config.getHostAddress()).append("(").append(config.getNamespaceName())
|
||||||
return sb.toString();
|
.append(")]>");
|
||||||
}
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alibaba.nacos.cli.input.completer;
|
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||||
|
|
||||||
import jline.console.completer.ArgumentCompleter;
|
import jline.console.completer.ArgumentCompleter;
|
||||||
import jline.console.completer.Completer;
|
import jline.console.completer.Completer;
|
||||||
|
@ -13,7 +13,10 @@ import java.lang.annotation.Target;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提供各种命令用到的completer group
|
* 提供各种命令用到的completer group
|
||||||
|
@ -22,6 +25,8 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class CompleterFactory {
|
public class CompleterFactory {
|
||||||
|
|
||||||
|
private static final String LOADED_COMPLETER = "LOAD completer(%s) finished.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +35,7 @@ public class CompleterFactory {
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
private @interface Enabled {
|
private @interface Enabled {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Completer> loadAll() throws InvocationTargetException, IllegalAccessException {
|
public static List<Completer> loadAll() throws InvocationTargetException, IllegalAccessException {
|
||||||
|
@ -45,6 +51,15 @@ public class CompleterFactory {
|
||||||
return completers;
|
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补全组
|
* 对于不提供后续补全的几个基本指令,简单提供String补全组
|
||||||
*
|
*
|
|
@ -0,0 +1,25 @@
|
||||||
|
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();
|
||||||
|
}
|
|
@ -1,74 +1,75 @@
|
||||||
package com.alibaba.nacos.cli.input.completer;
|
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import jline.console.completer.Completer;
|
import jline.console.completer.Completer;
|
||||||
import jline.internal.Preconditions;
|
import jline.internal.Preconditions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NacosCtl全局指令自动补全器
|
* NacosCtl全局指令自动补全器
|
||||||
*
|
*
|
||||||
* <p>整个程序的各种子指令的补全逻辑都在这里拼接
|
* <p>整个程序的各种子指令的补全逻辑都在这里拼接
|
||||||
*
|
*
|
||||||
* @author lehr
|
* @author lehr
|
||||||
*/
|
*/
|
||||||
public class NacosCtlCompleter implements Completer {
|
public class NacosCtlCompleter implements Completer {
|
||||||
|
|
||||||
private List<Completer> completers;
|
private List<Completer> completers;
|
||||||
|
|
||||||
public NacosCtlCompleter() throws HandlerException {
|
public NacosCtlCompleter() throws HandlerException {
|
||||||
try {
|
try {
|
||||||
completers = CompleterFactory.loadAll();
|
completers = CompleterFactory.loadAll();
|
||||||
} catch (Exception e) {
|
completers.addAll(CompleterFactory.loadExtensionCompleter());
|
||||||
throw new HandlerException("failed to load completer groups", e);
|
} catch (Exception e) {
|
||||||
}
|
throw new HandlerException("failed to load completer groups", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
|
@Override
|
||||||
Preconditions.checkNotNull(candidates);
|
public int complete(String buffer, int cursor, List<CharSequence> candidates) {
|
||||||
List<Completion> completions = new ArrayList(this.completers.size());
|
Preconditions.checkNotNull(candidates);
|
||||||
int max = -1;
|
List<Completion> completions = new ArrayList(this.completers.size());
|
||||||
Iterator var6 = this.completers.iterator();
|
int max = -1;
|
||||||
|
Iterator var6 = this.completers.iterator();
|
||||||
while (var6.hasNext()) {
|
|
||||||
Completer completer = (Completer) var6.next();
|
while (var6.hasNext()) {
|
||||||
Completion completion = new Completion(candidates);
|
Completer completer = (Completer) var6.next();
|
||||||
completion.complete(completer, buffer, cursor);
|
Completion completion = new Completion(candidates);
|
||||||
max = Math.max(max, completion.cursor);
|
completion.complete(completer, buffer, cursor);
|
||||||
completions.add(completion);
|
max = Math.max(max, completion.cursor);
|
||||||
}
|
completions.add(completion);
|
||||||
|
}
|
||||||
var6 = completions.iterator();
|
|
||||||
|
var6 = completions.iterator();
|
||||||
while (var6.hasNext()) {
|
|
||||||
Completion completion = (Completion) var6.next();
|
while (var6.hasNext()) {
|
||||||
if (completion.cursor == max) {
|
Completion completion = (Completion) var6.next();
|
||||||
candidates.addAll(completion.candidates);
|
if (completion.cursor == max) {
|
||||||
}
|
candidates.addAll(completion.candidates);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return max;
|
|
||||||
}
|
return max;
|
||||||
|
}
|
||||||
private class Completion {
|
|
||||||
|
private class Completion {
|
||||||
public final List<CharSequence> candidates;
|
|
||||||
|
public final List<CharSequence> candidates;
|
||||||
public int cursor;
|
|
||||||
|
public int cursor;
|
||||||
public Completion(List<CharSequence> candidates) {
|
|
||||||
Preconditions.checkNotNull(candidates);
|
public Completion(List<CharSequence> candidates) {
|
||||||
this.candidates = new LinkedList(candidates);
|
Preconditions.checkNotNull(candidates);
|
||||||
}
|
this.candidates = new LinkedList(candidates);
|
||||||
|
}
|
||||||
public void complete(Completer completer, String buffer, int cursor) {
|
|
||||||
Preconditions.checkNotNull(completer);
|
public void complete(Completer completer, String buffer, int cursor) {
|
||||||
this.cursor = completer.complete(buffer, cursor, this.candidates);
|
Preconditions.checkNotNull(completer);
|
||||||
}
|
this.cursor = completer.complete(buffer, cursor, this.candidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
|
@ -1,50 +1,50 @@
|
||||||
package com.alibaba.nacos.cli.input.completer;
|
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import jline.console.completer.Completer;
|
import jline.console.completer.Completer;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use命令自动补全可用的namespace
|
* Use命令自动补全可用的namespace
|
||||||
*/
|
*/
|
||||||
class NacosSwitchSetCompleter implements Completer {
|
class NacosSwitchSetCompleter implements Completer {
|
||||||
|
|
||||||
private SortedSet<String> strings = new TreeSet<String>();
|
private SortedSet<String> strings = new TreeSet<String>();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||||
|
|
||||||
// 找服务器刷新可访问的数据类型
|
// 找服务器刷新可访问的数据类型
|
||||||
if (strings.isEmpty()) {
|
if (strings.isEmpty()) {
|
||||||
Map<String, String> switches = null;
|
Map<String, String> switches = null;
|
||||||
try {
|
try {
|
||||||
switches = LogicHandler.getSwitches();
|
switches = LogicHandler.getSwitches();
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
switches = Collections.emptyMap();
|
switches = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
strings.addAll(switches.keySet());
|
strings.addAll(switches.keySet());
|
||||||
strings.add("all");
|
strings.add("all");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果目前没有输入,则列出所有选项
|
// 如果目前没有输入,则列出所有选项
|
||||||
if (buffer == null) {
|
if (buffer == null) {
|
||||||
candidates.addAll(strings);
|
candidates.addAll(strings);
|
||||||
} else {
|
} else {
|
||||||
// 进行前缀匹配,把match的加入进去
|
// 进行前缀匹配,把match的加入进去
|
||||||
for (String match : strings.tailSet(buffer)) {
|
for (String match : strings.tailSet(buffer)) {
|
||||||
if (!match.startsWith(buffer)) {
|
if (!match.startsWith(buffer)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
candidates.add(match);
|
candidates.add(match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return candidates.isEmpty() ? -1 : 0;
|
return candidates.isEmpty() ? -1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,50 +1,50 @@
|
||||||
package com.alibaba.nacos.cli.input.completer;
|
package com.alibaba.nacos.ctl.intraction.input.completer;
|
||||||
|
|
||||||
import com.alibaba.nacos.cli.core.LogicHandler;
|
import com.alibaba.nacos.ctl.core.LogicHandler;
|
||||||
import com.alibaba.nacos.cli.core.bean.NamespaceVO;
|
import com.alibaba.nacos.ctl.core.bean.NamespaceVO;
|
||||||
import com.alibaba.nacos.cli.core.exception.HandlerException;
|
import com.alibaba.nacos.ctl.core.exception.HandlerException;
|
||||||
import jline.console.completer.Completer;
|
import jline.console.completer.Completer;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use命令自动补全可用的namespace
|
* Use命令自动补全可用的namespace
|
||||||
*/
|
*/
|
||||||
class NacosUseCompleter implements Completer {
|
class NacosUseCompleter implements Completer {
|
||||||
|
|
||||||
private SortedSet<String> strings = new TreeSet<String>();
|
private SortedSet<String> strings = new TreeSet<String>();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
public int complete(final String buffer, final int cursor, final List<CharSequence> candidates) {
|
||||||
|
|
||||||
// 找服务器刷新可访问的数据类型
|
// 找服务器刷新可访问的数据类型
|
||||||
strings.clear();
|
strings.clear();
|
||||||
List<NamespaceVO> namespaces = null;
|
List<NamespaceVO> namespaces = null;
|
||||||
try {
|
try {
|
||||||
namespaces = LogicHandler.listNamespaces();
|
namespaces = LogicHandler.listNamespaces();
|
||||||
} catch (HandlerException e) {
|
} catch (HandlerException e) {
|
||||||
namespaces = Collections.EMPTY_LIST;
|
namespaces = Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
strings.addAll(namespaces.stream().map(NamespaceVO::toString).collect(Collectors.toList()));
|
strings.addAll(namespaces.stream().map(NamespaceVO::toString).collect(Collectors.toList()));
|
||||||
|
|
||||||
// 如果目前没有输入,则列出所有选项
|
// 如果目前没有输入,则列出所有选项
|
||||||
if (buffer == null) {
|
if (buffer == null) {
|
||||||
candidates.addAll(strings);
|
candidates.addAll(strings);
|
||||||
} else {
|
} else {
|
||||||
// 进行前缀匹配,把match的加入进去
|
// 进行前缀匹配,把match的加入进去
|
||||||
for (String match : strings.tailSet(buffer)) {
|
for (String match : strings.tailSet(buffer)) {
|
||||||
if (!match.startsWith(buffer)) {
|
if (!match.startsWith(buffer)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
candidates.add(match);
|
candidates.add(match);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return candidates.isEmpty() ? -1 : 0;
|
return candidates.isEmpty() ? -1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
238
pom.xml
238
pom.xml
|
@ -1,100 +1,196 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.alibaba.nacos</groupId>
|
<groupId>com.alibaba.nacos</groupId>
|
||||||
<artifactId>nacosctl</artifactId>
|
<artifactId>nacosctl</artifactId>
|
||||||
<version>1.0.0</version>
|
<packaging>pom</packaging>
|
||||||
|
<version>${revision}</version>
|
||||||
|
<modules>
|
||||||
|
<module>distrobution</module>
|
||||||
|
<module>core</module>
|
||||||
|
<module>interaction</module>
|
||||||
|
<module>command</module>
|
||||||
|
<module>bootstrap</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<revision>1.0.1</revision>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<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>
|
</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>
|
<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>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.22</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.1.7</version>
|
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<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>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<version>${maven-resources-plugin.version}</version>
|
||||||
<version>2.2-beta-5</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>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<id>flatten</id>
|
||||||
|
<phase>process-resources</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>single</goal>
|
<goal>flatten</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>flatten.clean</id>
|
||||||
|
<phase>clean</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>clean</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>
|
|
||||||
com.alibaba.nacos.cli.ClientMain
|
|
||||||
</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
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,152 +0,0 @@
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
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,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>
|
|
Loading…
Reference in New Issue