aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/pom.xml20
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java93
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java56
-rw-r--r--main/src/main/resources/oclip-readme.txt35
4 files changed, 126 insertions, 78 deletions
diff --git a/main/pom.xml b/main/pom.xml
index 3fb4288f..9a5465c2 100644
--- a/main/pom.xml
+++ b/main/pom.xml
@@ -24,7 +24,7 @@
<parent>
<groupId>org.onap.cli</groupId>
<artifactId>cli</artifactId>
- <version>3.0.0</version>
+ <version>4.0.0-SNAPSHOT</version>
</parent>
<artifactId>cli-main</artifactId>
@@ -37,12 +37,6 @@
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.onap.cli</groupId>
<artifactId>cli-framework</artifactId>
<version>${project.parent.version}</version>
@@ -52,12 +46,24 @@
<artifactId>jline</artifactId>
<version>2.6</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.19</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jmockit</groupId>
+ <artifactId>jmockit-coverage</artifactId>
+ <version>1.19</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java
index 582be3c8..75bf5d18 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -43,6 +43,7 @@ import org.onap.cli.fw.registrar.OnapCommandRegistrar;
import org.onap.cli.fw.store.OnapCommandExecutionStore;
import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext;
import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
+import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.main.conf.OnapCliConstants;
import org.onap.cli.main.interactive.StringCompleter;
import org.onap.cli.main.utils.OnapCliArgsParser;
@@ -162,8 +163,9 @@ public class OnapCli {
}
private void print(Throwable throwable) {
- this.print(throwable.getMessage() != null ? throwable.getMessage() : "");
- log.error(throwable.getMessage(), throwable);
+ String error = throwable.getMessage() != null ? throwable.getMessage() : "";
+ this.print(error);
+ log.error(error, throwable);
}
private String getShortOption(String opt) {
@@ -282,7 +284,9 @@ public class OnapCli {
.filter(e -> e.getName().equals(OnapCommandConstants.VERIFY_CONTEXT_PARAM))
.findFirst();
- List<Map<String, ?>> testSuite = OnapCommandRegistrar.getRegistrar().getTestSuite(cmd.getName());
+ List<Map<String, ?>> testSuite = OnapCommandRegistrar.getRegistrar().getTestSuite(
+ cmd.getName(),
+ cmd.getInfo().getProduct());
OnapCommandResult testSuiteResult = new OnapCommandResult();
testSuiteResult.setType(OnapCommandResultType.TABLE);
@@ -306,11 +310,10 @@ public class OnapCli {
sampleFileAtt.getValues().add((String) sampleTest.get(OnapCommandConstants.VERIFY_SAMPLE_FILE_ID));
sampleIdAtt.getValues().add((String) sampleTest.get(OnapCommandConstants.VERIFY_SAMPLE_ID));
- cmd = OnapCommandRegistrar.getRegistrar().get(this.cmdName);
+ cmd = OnapCommandRegistrar.getRegistrar().get(cmd.getName(),
+ cmd.getInfo().getProduct());
List<String> arguments = (List<String>) sampleTest.get(OnapCommandConstants.VERIFY_INPUT);
- if (arguments.size() > 0 && arguments.get(0).equals(this.cmdName)) {
- arguments.remove(0);
- }
+
OnapCliArgsParser.populateParams(cmd.getParameters(), arguments);
this.print("\n***************Test Command: \n" + sampleTest.get(OnapCommandConstants.VERIFY_INPUT).toString());
@@ -530,38 +533,31 @@ public class OnapCli {
OnapCliArgsParser.populateParams(cmd.getParameters(), this.args);
//start the execution
- if (this.requestId != null) {
- String input = cmd.getArgsJson(true);
- executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart(
- this.requestId,
- cmd.getInfo().getProduct(),
- cmd.getInfo().getService(),
- this.cmdName,
- this.profile,
- input);
+ if (this.requestId != null && !this.requestId.isEmpty()) {
+ if (!(this.product.equalsIgnoreCase("open-cli") &&
+ this.cmdName.equalsIgnoreCase("execution-list"))) {
+ String input = cmd.getArgsJson(true);
+ executionStoreContext = OnapCommandExecutionStore.getStore().storeExectutionStart(
+ this.requestId,
+ cmd.getInfo().getProduct(),
+ cmd.getInfo().getService(),
+ this.cmdName,
+ this.profile,
+ input);
+ }
}
+ cmd.setExecutionContext(executionStoreContext);
OnapCommandResult result = cmd.execute();
- String printOut = result.print();
- if (this.requestId != null) {
- OnapCommandExecutionStore.getStore().storeExectutionEnd(
- executionStoreContext,
- printOut,
- null, result.isPassed());
- }
-
- this.print(result.getDebugInfo());
- this.print(printOut);
+ this.handleTracking(cmd);
if (result.isPassed()) {
this.exitSuccessfully();
generateSmapleYaml(cmd);
+ } else {
+ this.exitFailure();
}
-
- else this.exitFailure();
-
-
} catch (OnapCommandWarning w) {
this.print(w);
this.print(cmd.getResult().getDebugInfo());
@@ -572,6 +568,7 @@ public class OnapCli {
executionStoreContext,
null,
e.getMessage(),
+ cmd.getResult().getDebugInfo(),
false);
}
@@ -582,21 +579,35 @@ public class OnapCli {
}
}
+ public void handleTracking(OnapCommand cmd) throws OnapCommandException {
+ if (cmd.getResult().isDebug())
+ this.print(cmd.getResult().getDebugInfo());
+
+ String printOut = cmd.getResult().print();
+ this.print(printOut);
+
+ if (cmd.getExecutionContext() != null) {
+ OnapCommandExecutionStore.getStore().storeExectutionEnd(
+ cmd.getExecutionContext(),
+ printOut,
+ null,
+ cmd.getResult().getDebugInfo(),
+ cmd.getResult().isPassed());
+ }
+ }
/**
* When user invokes cli with RPC arguments...
*/
public void handleRpc() {
- if (!this.args.isEmpty()) {
+ if (this.rpcHost != null && this.rpcPort != null && this.product != null) {
try {
- if (this.rpcHost != null && this.rpcPort != null && this.product != null) {
- OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-rpc", "open-cli");
- cmd.getParametersMap().get(OnapCommandConstants.RPC_HOST).setValue(this.rpcHost);
- cmd.getParametersMap().get(OnapCommandConstants.RPC_PORT).setValue(this.rpcPort);
- cmd.getParametersMap().get(OnapCommandConstants.RPC_PRODUCT).setValue(this.product);
- cmd.getParametersMap().get(OnapCommandConstants.RPC_CMD).setValue(this.cmdName);
+ OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("schema-rpc", "open-cli");
+ cmd.getParametersMap().get(OnapCommandConstants.RPC_HOST).setValue(this.rpcHost);
+ cmd.getParametersMap().get(OnapCommandConstants.RPC_PORT).setValue(this.rpcPort);
+ cmd.getParametersMap().get(OnapCommandConstants.RPC_PRODUCT).setValue(this.product);
+ cmd.getParametersMap().get(OnapCommandConstants.RPC_CMD).setValue(this.cmdName);
- this.handleRpcCommand(cmd);
- }
+ this.handleRpcCommand(cmd);
} catch (Exception e) {
this.print(e);
this.exitFailure();
@@ -730,8 +741,8 @@ public class OnapCli {
private void generateSmapleYaml(OnapCommand cmd) throws OnapCommandException {
if (Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_ENABLED)) && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) {
try {
- SampleYamlGenerator.generateSampleYaml(args, cmd.getResult().print(),
- OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(),
+ SampleYamlGenerator.generateSampleYaml(cmd.getName(), args, cmd.getResult().print(),
+ cmd.getInfo().getProduct(),
OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_TARGET_FOLDER) + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml",
cmd.getResult().isDebug());
} catch (IOException error) {
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
index a1bde717..a07c08f2 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
@@ -32,6 +33,7 @@ import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.OnapCommandParameterType;
import org.onap.cli.main.error.OnapCliArgumentValueMissing;
import org.onap.cli.main.error.OnapCliInvalidArgument;
+import org.yaml.snakeyaml.Yaml;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -116,12 +118,25 @@ public class OnapCliArgsParser {
i++;
continue;
- } if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) {
+ } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.TEXT)) {
paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1),
paramMap.get(paramName).getName()));
i++;
continue;
+ } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.YAML)) {
+ String value = readYamlStringFromUrl(args.get(i + 1),
+ paramMap.get(paramName).getName());
+ paramMap.get(paramName).setValue(value);
+ i++;
+ continue;
+
+ } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BYTE)) {
+ paramMap.get(paramName).setValue(readBytesFromUrl(args.get(i + 1),
+ paramMap.get(paramName).getName()));
+ i++;
+ continue;
+
} else if (paramMap.get(paramName).getParameterType()
.equals(OnapCommandParameterType.ARRAY)) {
Object value = paramMap.get(paramName).getValue();
@@ -177,7 +192,7 @@ public class OnapCliArgsParser {
params.addAll(paramMap.values());
}
- private static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
+ public static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
ObjectMapper mapper = new ObjectMapper();
try {
File file = new File(input);
@@ -194,7 +209,7 @@ public class OnapCliArgsParser {
}
}
- private static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
+ public static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
try {
File file = new File(input);
if (file.isFile()) {
@@ -208,7 +223,38 @@ public class OnapCliArgsParser {
}
}
- private static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument {
+ public static String readYamlStringFromUrl(String input, String argName) throws OnapCliInvalidArgument {
+ try {
+ File file = new File(input);
+ if (file.isFile()) {
+ String value = FileUtils.readFileToString(file);
+ new Yaml().load(value);
+ return value;
+ } else {
+ return input;
+ }
+
+ } catch (IOException e) {
+ throw new OnapCliInvalidArgument(argName, e);
+ }
+ }
+
+ public static String readBytesFromUrl(String input, String argName) throws OnapCliInvalidArgument {
+ try {
+ File file = new File(input);
+ if (file.isFile()) {
+ byte[] encodeBase64 = Base64.encodeBase64(FileUtils.readFileToByteArray(file));
+ return new String(encodeBase64);
+ } else {
+ byte[] encodeBase64 = Base64.encodeBase64(input.getBytes());
+ return new String(encodeBase64);
+ }
+ } catch (IOException e) {
+ throw new OnapCliInvalidArgument(argName, e);
+ }
+ }
+
+ public static List<String> convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument {
TypeReference<List<String>> mapType = new TypeReference<List<String>>() {
};
try {
@@ -218,7 +264,7 @@ public class OnapCliArgsParser {
}
}
- private static Map<String, String> convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument {
+ public static Map<String, String> convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument {
TypeReference<Map<String, String>> mapType = new TypeReference<Map<String, String>>() {
};
try {
diff --git a/main/src/main/resources/oclip-readme.txt b/main/src/main/resources/oclip-readme.txt
index bea04b79..6c929ec7 100644
--- a/main/src/main/resources/oclip-readme.txt
+++ b/main/src/main/resources/oclip-readme.txt
@@ -1,25 +1,10 @@
-Open Command-line interface Platform(OCLIP)
-===========================================
-
- _____ _____ _ _____
-| _ | / __ \| | |_ _|
-| | | |_ __ ___ _ __ | / \/| | | |
-| | | | '_ \ / _ \ '_ \ | | | | | |
-\ \_/ / |_) | __/ | | | | \__/\| |_____| |_
- \___/| .__/ \___|_| |_| \____/\_____/\___/
- | |
- |_|
-
-Provides unified commands to operate any cloud enabled software
-products from Linux/Web console. Configure the following environment
-variables, before using it:
-
-1. OPEN_CLI_HOST_URL - Catalog service URL or a service URL
-2. OPEN_CLI_HOST_USERNAME - Service user name
-3. OPEN_CLI_HOST_PASSWORD - Service password
-
-To know the CLI version, type oclip [-v|--version]
-To know the CLI usage, type oclip [-h|--help]
-To know the usage of sub commands, type oclip <command> [-h|--help]
-
-To know more, please refer the wiki https://wiki.onap.org
+ ___ ___ ___ _ __ ___ _ __
+ / _ \ / __/ _ \| '_ ` _ \| '_ \
+| (_) | (_| (_) | | | | | | |_) |
+ \___/ \___\___/|_| |_| |_| .__/
+ | |
+ |_|
+
+Open Command Platform (OCOMP) facilitates to model any cloud-enabled or monolithic software
+product's functionality as command using Open Command Specification (OCS) and provides
+Web and command line Shell to access and operate these commands.