aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorKanagaraj M <mkr1481@gmail.com>2019-08-02 14:10:30 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2019-08-05 19:49:23 +0530
commitb100c49fbd130e4fe58ce82f1e5f765f13917703 (patch)
treecb5d5d0c42ea17939b98b76229cc341c6f2332d9 /main
parentf24ae00ec10cdcbab41429841926051ba08c88ec (diff)
Update framework
Issue-ID: CLI-169 Change-Id: Ice38da575d2e349bb875149afd894e348bc20253 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'main')
-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
2 files changed, 103 insertions, 46 deletions
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 {