aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam <mkr1481@gmail.com>2019-08-29 15:41:53 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2019-08-29 15:41:53 +0530
commit70dac125e796d52b874f4e7f3839f9cf042e0f98 (patch)
tree9382129179acf1a0b0e82c5051a0f287f000c0e1
parent02b61c5a78448d2c01ce15adecb6df99f1b6b8c8 (diff)
Minor issues fix
Issue-ID: CLI-166 Change-Id: I97bd303b4e636bfc53e24732c7c6e4062037909b Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r--deployment/zip/src/main/release/conf/open-cli.properties3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidSample.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java20
-rw-r--r--framework/src/main/resources/open-cli.properties2
-rw-r--r--grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java11
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java43
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java32
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java3
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java2
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java2
12 files changed, 99 insertions, 26 deletions
diff --git a/deployment/zip/src/main/release/conf/open-cli.properties b/deployment/zip/src/main/release/conf/open-cli.properties
index eff85b8a..76048e69 100644
--- a/deployment/zip/src/main/release/conf/open-cli.properties
+++ b/deployment/zip/src/main/release/conf/open-cli.properties
@@ -20,6 +20,7 @@ cli.artifact.dir=$s{env:OPEN_CLI_HOME}/data/artifacts
cli.tmp.dir=$s{env:OPEN_CLI_HOME}/data/tmp
#timeout in seconds
cli.grpc.client.timeout=60
+cli.execution.search.mode=find
#schema validation
cli.schema.base.sections=open_cli_schema_version,name,description,parameters,results,info
@@ -38,7 +39,7 @@ cli.schema.boolean_values=true,false
cli.schema.command.type=cmd,auth,catalog
# moco properties
-cli.sample.gen.enable=false
+cli.sample.gen.enable=true
cli.sample.gen.target=$s{env:OPEN_CLI_HOME}/open-cli-sample
# mrkanag Move this to db, once exteranl command registration is supported in place of discovery
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
index 53018025..51a18627 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
@@ -43,6 +43,7 @@ public class OnapCommandConstants {
public static final String OPEN_CLI_DATA_DIR = "cli.data.dir";
public static final String OPEN_CLI_ARTIFACT_DIR = "cli.artifact.dir";
public static final String OPEN_CLI_GRPC_CLIENT_TIMEOUT = "cli.grpc.client.timeout";
+ public static final String OPEN_CLI_EXECUTION_SEARCH_MODE = "cli.execution.search.mode";
//schema
public static final String OPEN_CLI_SCHEMA_VERSION = "open_cli_schema_version";
public static final String OPEN_CLI_SCHEMA_VERSION_VALUE_1_0 = "1.0";
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidSample.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidSample.java
index 32e5cf65..9f702209 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidSample.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidSample.java
@@ -20,7 +20,7 @@ package org.onap.cli.fw.error;
* Command sample is invalid.
*
*/
-public class OnapCommandInvalidSample extends OnapCommandException {
+public class OnapCommandInvalidSample extends OnapCommandWarning {
private static final long serialVersionUID = -3387652326582792835L;
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java
index 3b49f464..ccd2cee5 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java
@@ -31,4 +31,8 @@ public abstract class OnapCommandWarning extends OnapCommandException {
public OnapCommandWarning(String errorCode, String errorMessage) {
super(errorCode, errorMessage);
}
+
+ public OnapCommandWarning(String errorCode, String errorMessage, Throwable err) {
+ super(errorCode, errorMessage, err);
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
index d09e4304..d032a99c 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
@@ -48,12 +48,21 @@ public class OnapCommandExecutionStore {
private enum SearchMode {
find,
file //for developer mode
+
+
}
+
private static SearchMode SEARCH_MODE = SearchMode.file;
+ static {
+ String mode = OnapCommandConfig.getPropertyValue(OnapCommandConstants.OPEN_CLI_EXECUTION_SEARCH_MODE);
+ if (mode.equalsIgnoreCase(SearchMode.find.name()))
+ SEARCH_MODE = SearchMode.find;
+ }
public static class ExecutionStoreContext {
private String requestId;
private String executionId;
+ private String profile;
private String storePath;
public String getExecutionId() {
return executionId;
@@ -76,6 +85,12 @@ public class OnapCommandExecutionStore {
this.requestId = requestId;
return this;
}
+ public String getProfile() {
+ return profile;
+ }
+ public void setProfile(String profile) {
+ this.profile = profile;
+ }
}
public static class Execution {
@@ -219,8 +234,10 @@ public class OnapCommandExecutionStore {
if (input != null)
FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "input"), input);
- if (profile != null)
+ if (profile != null) {
+ context.setProfile(profile);
FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "profile"), profile);
+ }
FileUtils.touch(new File(context.getStorePath() + File.separator + "stdout"));
FileUtils.touch(new File(context.getStorePath() + File.separator + "stderr"));
@@ -371,6 +388,7 @@ public class OnapCommandExecutionStore {
if (new File(executionStorePath + File.separator + "executionId").exists())
exectuion.setId(FileUtils.readFileToString(new File(executionStorePath + File.separator + "executionId")));
exectuion.setProduct(FileUtils.readFileToString(new File(executionStorePath + File.separator + "product")));
+ exectuion.setProfile(FileUtils.readFileToString(new File(executionStorePath + File.separator + "profile")));
exectuion.setService(FileUtils.readFileToString(new File(executionStorePath + File.separator + "service")));
exectuion.setCommand(FileUtils.readFileToString(new File(executionStorePath + File.separator + "command")));
if (new File(executionStorePath + File.separator + "profile").exists())
diff --git a/framework/src/main/resources/open-cli.properties b/framework/src/main/resources/open-cli.properties
index 259fd227..bd8a6acf 100644
--- a/framework/src/main/resources/open-cli.properties
+++ b/framework/src/main/resources/open-cli.properties
@@ -20,7 +20,7 @@ cli.artifact.dir=./data/artifacts
cli.tmp.dir=./data/tmp
#timeout in seconds
cli.grpc.client.timeout=60
-
+cli.execution.search.mode=file
#schema validation
cli.schema.base.sections=open_cli_schema_version,name,description,parameters,results,info
cli.schema.base.sections.mandatory=open_cli_schema_version
diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
index f34df89f..9f325067 100644
--- a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
+++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
@@ -162,18 +162,18 @@ public class OpenInterfaceGrpcServer {
new ArrayList<String>());
//fill from profile
+ Map<String, String> cache= OnapCommandRegistrar.getRegistrar().getParamCache(product);
for (OnapCommandParameter param: cmd.getParameters()) {
- Map<String, String> cache= OnapCommandRegistrar.getRegistrar().getParamCache(product);
if (cache.containsKey(
cmd.getInfo().getService() + ":" + cmd.getName() + ":" + param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(
+ param.setValue(cache.get(
cmd.getInfo().getService() + ":" + cmd.getName() + ":" + param.getLongOption()));
} else if (cache.containsKey(
cmd.getInfo().getService() + ":" + param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(
+ param.setValue(cache.get(
cmd.getInfo().getService() + ":" + param.getLongOption()));
- } else if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(param.getLongOption()));
+ } else if (cache.containsKey(param.getLongOption())) {
+ param.setValue(cache.get(param.getLongOption()));
}
}
}
@@ -261,7 +261,6 @@ public class OpenInterfaceGrpcServer {
} catch (OnapCommandException e) {
logger.info(e.getMessage());
-
Builder reply = Output.newBuilder();
reply.putAttrs(OnapCommandConstants.RESULTS, "{}");
reply.setSuccess(false);
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 0c7082f8..268b23cf 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -161,6 +161,10 @@ public class OnapCli {
System.out.println(msg);
}
+ protected void printerr(String msg) {
+ System.err.println(msg);
+ }
+
private void print(Throwable throwable) {
String error = throwable.getMessage() != null ? throwable.getMessage() : "";
this.print(error);
@@ -349,7 +353,7 @@ public class OnapCli {
} else {
resultAtt.getValues().add(OnapCommandConstants.VERIFY_RESULT_FAIL);
}
- this.print(testResult.getDebugInfo());
+ this.printerr(testResult.getDebugInfo());
this.print("\n***************Expected Output: \n" + expectedOutput);
this.print("\n***************Actual Output: \n" + actualOutput);
}
@@ -509,20 +513,28 @@ public class OnapCli {
}
//refer params from profile
- if (this.profile != null)
+ if (this.profile != null) {
+
+ Map<String, String> paramCache = new HashMap<>();
+ if (this.product == null)
+ paramCache = OnapCommandRegistrar.getRegistrar().getParamCache();
+ else
+ paramCache = OnapCommandRegistrar.getRegistrar().getParamCache(this.product);
+
for (OnapCommandParameter param: cmd.getParameters()) {
- if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(
+ if (paramCache.containsKey(
cmd.getInfo().getService() + ":" + cmd.getName() + ":" + param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(
+ param.setValue(paramCache.get(
cmd.getInfo().getService() + ":" + cmd.getName() + ":" + param.getLongOption()));
- } else if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(
+ } else if (paramCache.containsKey(
cmd.getInfo().getService() + ":" + param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(
+ param.setValue(paramCache.get(
cmd.getInfo().getService() + ":" + param.getLongOption()));
- } else if (OnapCommandRegistrar.getRegistrar().getParamCache().containsKey(param.getLongOption())) {
- param.setValue(OnapCommandRegistrar.getRegistrar().getParamCache().get(param.getLongOption()));
+ } else if (paramCache.containsKey(param.getLongOption())) {
+ param.setValue(paramCache.get(param.getLongOption()));
}
}
+ }
//load the parameters value from the map read from param-file
if (!this.argsParamFile.isEmpty()) {
@@ -558,8 +570,17 @@ public class OnapCli {
this.exitFailure();
}
} catch (OnapCommandWarning w) {
+ if (cmd.getExecutionContext() != null) {
+ OnapCommandExecutionStore.getStore().storeExectutionEnd(
+ cmd.getExecutionContext(),
+ w.getMessage(),
+ null,
+ cmd.getResult().getDebugInfo(),
+ cmd.getResult().isPassed());
+ }
+
this.print(w);
- this.print(cmd.getResult().getDebugInfo());
+ this.printerr(cmd.getResult().getDebugInfo());
this.exitSuccessfully();
} catch (Exception e) {
if (executionStoreContext != null) {
@@ -572,7 +593,7 @@ public class OnapCli {
}
this.print(e);
- this.print(cmd.getResult().getDebugInfo());
+ this.printerr(cmd.getResult().getDebugInfo());
this.exitFailure();
}
}
@@ -580,7 +601,7 @@ public class OnapCli {
public void handleTracking(OnapCommand cmd) throws OnapCommandException {
if (cmd.getResult().isDebug())
- this.print(cmd.getResult().getDebugInfo());
+ this.printerr(cmd.getResult().getDebugInfo());
String printOut = cmd.getResult().print();
this.print(printOut);
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
index 40ccf5c4..bc864529 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.commons.io.FileUtils;
import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants;
import org.onap.cli.fw.cmd.error.OnapCommandCmdFailure;
@@ -175,11 +176,13 @@ public class OpenCommandShellCmd extends OnapCommand {
//add oclip specific environment variables
if (this.getExecutionContext() != null) {
envs.add("OPEN_CLI_REQUEST_ID=" + this.getExecutionContext().getRequestId());
+ if (this.getExecutionContext().getProfile() != null) {
+ envs.add("OPEN_CLI_PROFILE=" + this.getExecutionContext().getProfile());
+ }
if (OnapCommandRegistrar.getRegistrar().getHost() != null) {
envs.add("OPEN_CLI_RPC_HOST=" + OnapCommandRegistrar.getRegistrar().getHost());
envs.add("OPEN_CLI_RPC_PORT=" + OnapCommandRegistrar.getRegistrar().getPort());
}
- //mrkanag set the profile OPEN_CLI_PROFILE
}
for (String env: this.getEnvs().keySet()) {
@@ -315,7 +318,32 @@ public class OpenCommandShellCmd extends OnapCommand {
int idxE = line.indexOf("}", idxS);
String tmpName = line.substring(idxS + 7, idxE);
tmpName = tmpName.trim();
- result.put("tmp:" + tmpName, this.getOutputAttributeFilePath(tmpName, true));
+ String tmpTkns[] = tmpName.split(":");
+ String tmpFileName;
+ String paramName;
+ if (tmpTkns.length == 2) {
+ tmpFileName = tmpTkns[0];
+ paramName = tmpTkns[1];
+ } else {
+ tmpFileName = tmpTkns[0];
+ paramName = null;
+ }
+
+ String tmpFilePath = this.getOutputAttributeFilePath(tmpFileName, true);
+ if (paramName != null) {
+ //Write the value of input params into file before passing to command
+ try {
+ FileUtils.touch(new File(tmpFilePath));
+ FileUtils.writeStringToFile(new File(tmpFilePath),
+ this.getParametersMap().get(paramName).getValue().toString());
+ } catch (IOException e) {
+ // NO SONAR
+ }
+ }
+
+ result.put("tmp:" + tmpFileName, tmpFilePath); //used in output parsing
+ result.put("tmp:" + tmpName, tmpFilePath); //used in line replacement
+
currentIdx = idxE + 1;
}
return result;
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java b/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
index 12a645c4..9d6274ac 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
@@ -17,12 +17,13 @@
package org.onap.cli.fw.http.error;
import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandWarning;
/**
* Invalid data for generating moco json .
*
*/
-public class OnapCommandFailedMocoGenerate extends OnapCommandException {
+public class OnapCommandFailedMocoGenerate extends OnapCommandWarning {
private static final long serialVersionUID = -5386652726982792831L;
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
index 5cab0a68..d1f88df4 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
@@ -171,7 +171,7 @@ public class OnapCommandHttpUtils {
/**
* In case of empty response body [] or {}
**/
- if (resultHttp.getBody().length() <= 2) {
+ if (resultHttp.getBody() != null && resultHttp.getBody().length() <= 2) {
return result;
}
diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
index d7999bea..e49e4d41 100644
--- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
@@ -38,7 +38,7 @@ public class MockResponse {
}
public void setJson(String json) throws IOException {
- if (!json.isEmpty()) {
+ if (json != null && !json.isEmpty()) {
try {
ObjectMapper objectMapper = new ObjectMapper();
this.json = objectMapper.readTree(json);