From 70dac125e796d52b874f4e7f3839f9cf042e0f98 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Thu, 29 Aug 2019 15:41:53 +0530 Subject: Minor issues fix Issue-ID: CLI-166 Change-Id: I97bd303b4e636bfc53e24732c7c6e4062037909b Signed-off-by: Kanagaraj Manickam k00365106 --- .../onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java | 32 ++++++++++++++++++++-- .../http/error/OnapCommandFailedMocoGenerate.java | 3 +- .../cli/fw/http/utils/OnapCommandHttpUtils.java | 2 +- 3 files changed, 33 insertions(+), 4 deletions(-) (limited to 'profiles') 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; } -- cgit 1.2.3-korg f='#n12'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75