aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main/java/org
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 /framework/src/main/java/org
parentf24ae00ec10cdcbab41429841926051ba08c88ec (diff)
Update framework
Issue-ID: CLI-169 Change-Id: Ice38da575d2e349bb875149afd894e348bc20253 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'framework/src/main/java/org')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java14
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java34
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java34
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java7
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java7
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java137
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java71
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java73
17 files changed, 380 insertions, 52 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
index b814ba82..d73df4fb 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommand.java
@@ -39,6 +39,7 @@ import org.onap.cli.fw.schema.OnapCommandSchemaLoader;
import org.onap.cli.fw.schema.OnapCommandSchemaMerger;
import org.onap.cli.fw.store.OnapCommandArtifactStore;
import org.onap.cli.fw.store.OnapCommandArtifactStore.Artifact;
+import org.onap.cli.fw.store.OnapCommandExecutionStore.ExecutionStoreContext;
import org.onap.cli.fw.utils.OnapCommandHelperUtils;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.slf4j.Logger;
@@ -73,6 +74,8 @@ public abstract class OnapCommand {
private boolean isRpc = false;
+ private ExecutionStoreContext executionStoreContext;
+
public boolean isRpc() {
return isRpc;
}
@@ -234,6 +237,7 @@ public abstract class OnapCommand {
protected void postRun() throws OnapCommandException {
log.debug(this.getName() + " POST-RUN");
}
+
/**
* Oclip command execute with given parameters on service. Before calling this method, its mandatory to set all
* parameters value.
@@ -314,6 +318,8 @@ public abstract class OnapCommand {
log.info("OUTPUT: " + this.cmdResult.getRecords());
postRun();
+
+
return this.cmdResult;
}
@@ -343,4 +349,12 @@ public abstract class OnapCommand {
return OnapCommandHelperUtils.help(this);
}
// (mrkanag) Add toString for all command, parameter, result, etc objects in JSON format
+
+ public void setExecutionContext(ExecutionStoreContext executionStoreContext) {
+ this.executionStoreContext = executionStoreContext;
+ }
+
+ public ExecutionStoreContext getExecutionContext() {
+ return this.executionStoreContext;
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java
index 34ccc760..e874a14e 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapCommandType.java
@@ -27,8 +27,7 @@ public enum OnapCommandType {
AUTH,
CATALOG,
- CMD,
- SYSTEM;
+ CMD;
/**
* Get parameter type.
@@ -46,8 +45,6 @@ public enum OnapCommandType {
return CATALOG;
} else if (CMD.name().equalsIgnoreCase(name)) {
return CMD;
- } else if (SYSTEM.name().equalsIgnoreCase(name)) {
- return SYSTEM;
} else {
throw new OnapCommandInvalidCommandType(name);
}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java
new file mode 100644
index 00000000..e6be04aa
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowDebugCommand.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2019 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.cmd.execution;
+
+import org.onap.cli.fw.cmd.OnapCommand;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
+
+@OnapCommandSchema(schema = "execution-show-debug.yaml")
+public class OnapCommandExceutionShowDebugCommand extends OnapCommand {
+
+ @Override
+ protected void run() throws OnapCommandException {
+ String executionId = getParametersMap().get("execution-id").getValue().toString();
+ this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionDebug(executionId));
+ }
+
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java
new file mode 100644
index 00000000..bd3ff9ec
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowErrCommand.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2019 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.cmd.execution;
+
+import org.onap.cli.fw.cmd.OnapCommand;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
+
+@OnapCommandSchema(schema = "execution-show-err.yaml")
+public class OnapCommandExceutionShowErrCommand extends OnapCommand {
+
+ @Override
+ protected void run() throws OnapCommandException {
+ String executionId = getParametersMap().get("execution-id").getValue().toString();
+ this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionErr(executionId));
+ }
+
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java
new file mode 100644
index 00000000..878ceb13
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowOutCommand.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2019 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw.cmd.execution;
+
+import org.onap.cli.fw.cmd.OnapCommand;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.schema.OnapCommandSchema;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
+
+@OnapCommandSchema(schema = "execution-show-out.yaml")
+public class OnapCommandExceutionShowOutCommand extends OnapCommand {
+
+ @Override
+ protected void run() throws OnapCommandException {
+ String executionId = getParametersMap().get("execution-id").getValue().toString();
+ this.getResult().setOutput(OnapCommandExecutionStore.getStore().showExecutionOut(executionId));
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
index 010cdc19..fa4f60b9 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
@@ -73,6 +73,7 @@ public class OnapServiceListCommand extends OnapCommand {
}
for (String service : rslt.getOrDefault(product, new HashSet<String>())) {
+ this.getResult().getRecordsMap().get("product").getValues().add(product);
this.getResult().getRecordsMap().get("service").getValues().add(service);
this.getResult().getRecordsMap().get("description").getValues().add(
serviceDescs.containsKey(service) ? serviceDescs.get(service) : "");
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java
index ef22e4af..5046f44a 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommand.java
@@ -47,6 +47,7 @@ public class OnapSchemaListCommand extends OnapCommand {
if (service.length() > 0 && !service.equalsIgnoreCase(schema.getService())) {
continue;
}
+ this.getResult().getRecordsMap().get("product").getValues().add(schema.getProduct());
this.getResult().getRecordsMap().get("command").getValues().add(schema.getCmdName());
this.getResult().getRecordsMap().get("schema").getValues().add(schema.getSchemaName());
this.getResult().getRecordsMap().get("service").getValues().add(schema.getService());
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java
index c59521e0..b395177f 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfig.java
@@ -22,6 +22,8 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
+import org.onap.cli.fw.utils.OnapCommandUtils;
+
/**
* Oclip command constants.
*
@@ -38,7 +40,8 @@ public final class OnapCommandConfig {
}
static {
- loadProperties(prps, OnapCommandConstants.CONF);
+ addProperties(OnapCommandConstants.CONF);
+
for (String prpFile: getCommaSeparatedList(OnapCommandConstants.OPEN_CLI_PLUGIN_PRPS)) {
addProperties(prpFile);
}
@@ -57,7 +60,7 @@ public final class OnapCommandConfig {
loadProperties(ps, fileName);
for (Entry<Object, Object> entry: ps.entrySet()) {
- prps.put(entry.getKey(), entry.getValue());
+ prps.put(entry.getKey(), OnapCommandUtils.replaceLineForSpecialValues(entry.getValue().toString()));
}
}
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 56183399..53018025 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
@@ -36,14 +36,13 @@ public class OnapCommandConstants {
public static final String RESULT_PARAMS_LIST = "cli.schema.base.results.sections";
public static final String RESULT_PARAMS_MANDATORY_LIST = "cli.schema.base.results.sections.mandatory";
public static final String BOOLEAN_VALUE = "cli.schema.boolean_values";
-
public static final String COMMAND_TYPE_VALUES = "cli.schema.command.type";
public static final String SCHEMA_TYPES_SUPPORTED = "cli.schema.profile.available";
public static final String OPEN_CLI_PRODUCT_NAME = "cli.product_name";
public static final String OPEN_CLI_PLUGIN_PRPS = "cli.schema.profile.confs";
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";
//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";
@@ -151,6 +150,7 @@ public class OnapCommandConstants {
public static final String SPL_ENTRY_UUID = "uuid";
public static final String SPL_ENTRY_ENV = "env:";
public static final String SPL_ENTRY_FILE = "file:";
+ public static final String SPL_ENTRY_MD5 = "md5:";
public static final String VERSION_INFO = "version.info";
public static final String VERSION_INFO_PLACE_HOLDER_VERSION = "__VERSION__";
diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
index 618c321c..3b13c9f8 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameter.java
@@ -288,7 +288,12 @@ public class OnapCommandParameter {
public void setValue(Object value) throws OnapCommandInvalidParameterValue {
this.rawValue = value;
- if (OnapCommandParameterType.URL.equals(parameterType) && !value.toString().isEmpty() && !value.toString().startsWith("http")
+ if (OnapCommandParameterType.URL.equals(parameterType) &&
+ !value.toString().isEmpty() &&
+ !value.toString().startsWith("http") &&
+ !value.toString().startsWith("ftp") &&
+ !value.toString().startsWith("mqtt") &&
+ !value.toString().startsWith("tcp")
&& !value.toString().startsWith("/")) {
value = "/" + value;
} else if (OnapCommandParameterType.ARRAY.equals(parameterType)) {
diff --git a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java
index 391383d4..b6860b3c 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/OnapCommandParameterType.java
@@ -23,7 +23,7 @@ import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
*
*/
public enum OnapCommandParameterType {
- STRING, JSON, YAML, TEXT, URL, UUID,
+ STRING, BYTE, JSON, YAML, TEXT, URL, UUID,
DIGIT,
BOOL,
ARRAY,
@@ -42,6 +42,8 @@ public enum OnapCommandParameterType {
public static OnapCommandParameterType get(String name) throws OnapCommandInvalidParameterType {
if (JSON.name().equalsIgnoreCase(name)) {
return JSON;
+ } else if (BYTE.name().equalsIgnoreCase(name)) {
+ return BYTE;
} else if (YAML.name().equalsIgnoreCase(name)) {
return YAML;
} else if (STRING.name().equalsIgnoreCase(name)) {
diff --git a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
index d7937527..fdacbd1e 100644
--- a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
@@ -431,8 +431,8 @@ public class OnapCommandRegistrar {
}
}
- public List<Map<String, ?>> getTestSuite(String cmd) throws OnapCommandException {
- return OnapCommandDiscoveryUtils.createTestSuite(cmd, enabledProductVersion);
+ public List<Map<String, ?>> getTestSuite(String cmd, String product) throws OnapCommandException {
+ return OnapCommandDiscoveryUtils.createTestSuite(cmd, product);
}
public String getHost() {
diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
index fe191f5b..7d2cec92 100644
--- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
+++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
@@ -344,7 +344,7 @@ public class OnapCommandSchemaLoader {
case IS_OPTIONAL:
if (validate && !OnapCommandUtils.validateBoolean(String.valueOf(parameter.get(key2)))) {
exceptionList.add(OnapCommandUtils.invalidBooleanValueMessage(parameter.get(NAME),
- IS_SECURED, parameter.get(key2)));
+ IS_OPTIONAL, parameter.get(key2)));
}
if (BOOLEAN_TRUE.equalsIgnoreCase(String.valueOf(parameter.get(key2)))) {
@@ -510,6 +510,7 @@ public class OnapCommandSchemaLoader {
break;
}
}
+
return exceptionList;
}
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 4fc2508a..d09e4304 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
@@ -19,7 +19,6 @@ package org.onap.cli.fw.store;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -29,7 +28,6 @@ import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
import org.onap.cli.fw.conf.OnapCommandConfig;
import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandExecutionFailed;
@@ -54,7 +52,7 @@ public class OnapCommandExecutionStore {
private static SearchMode SEARCH_MODE = SearchMode.file;
public static class ExecutionStoreContext {
-
+ private String requestId;
private String executionId;
private String storePath;
public String getExecutionId() {
@@ -71,6 +69,13 @@ public class OnapCommandExecutionStore {
this.storePath = storePath;
return this;
}
+ public String getRequestId() {
+ return requestId;
+ }
+ public ExecutionStoreContext setRequestId(String requestId) {
+ this.requestId = requestId;
+ return this;
+ }
}
public static class Execution {
@@ -185,63 +190,113 @@ public class OnapCommandExecutionStore {
public ExecutionStoreContext storeExectutionStart(
String requestId, String product, String service, String cmd, String profile, String input) {
+ ExecutionStoreContext context = new ExecutionStoreContext();
+ context.setRequestId(requestId);
+
String executionId = requestId + "-" + System.currentTimeMillis();
+ context.setExecutionId(executionId);
String storePath = getBasePath() + File.separator + executionId + SEPARATOR + product +
SEPARATOR + service +
SEPARATOR + cmd +
(profile != null ? (SEPARATOR + profile) : "" );
+
try {
File dir = new File(storePath);
FileUtils.forceMkdir(dir);
+ context.setStorePath(dir.getAbsolutePath());
if (product != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "product"), product);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "product"), product);
if (service != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "service"), service);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "service"), service);
if (cmd != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "command"), cmd);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "command"), cmd);
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "requestId"), requestId);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "requestId"), requestId);
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "executionId"), executionId);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "executionId"), executionId);
if (input != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "input"), input);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "input"), input);
if (profile != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "profile"), profile);
- FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "in-progress"));
+ 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"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + "debug"));
+
+ FileUtils.touch(new File(context.getStorePath() + File.separator + "in-progress"));
} catch (IOException e) {
log.error("Failed to store the execution start details " + storePath);
}
- return new ExecutionStoreContext().setExecutionId(executionId).setStorePath(storePath);
+ return context;
}
public void storeExectutionEnd(
- ExecutionStoreContext execContext,
- String output, String error, boolean passed) {
+ ExecutionStoreContext context,
+ String output, String error, String debug, boolean passed) {
try {
- File dir = new File(execContext.getStorePath());
- FileUtils.forceMkdir(dir);
-
if (output != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "output"), output);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
if (error != null)
- FileUtils.writeStringToFile(new File(dir.getAbsolutePath() + File.separator + "error"), error);
-
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error);
+ if (debug != null)
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
if (passed)
- FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "completed"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + "completed"));
else
- FileUtils.touch(new File(dir.getAbsolutePath() + File.separator + "failed"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + "failed"));
+
+ new File(context.getStorePath() + File.separator + "in-progress").delete();
+ } catch (IOException e) {
+ log.error("Failed to store the execution end details " + context.storePath);
+ }
+ }
+
+ public void storeExectutionProgress(
+ ExecutionStoreContext context,
+ String output, String error, String debug) {
+
+ try {
+ if (output != null)
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
+ if (error != null)
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error);
+ if (debug != null)
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
+ } catch (IOException e) {
+ log.error("Failed to store the execution end details " + context.storePath);
+ }
+ }
+
+ public void storeExectutionDebug(
+ ExecutionStoreContext context,
+ String debug) {
- new File(dir.getAbsolutePath() + File.separator + "in-progress").delete();
+ try {
+ if (debug != null) {
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
+ }
} catch (IOException e) {
- log.error("Failed to store the execution end details " + execContext.storePath);
+ log.error("Failed to store the execution debug details " + context.storePath);
}
}
+ public void storeExectutionOutput(
+ ExecutionStoreContext context,
+ String output) {
+
+ try {
+ if (output != null) {
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
+ }
+ } catch (IOException e) {
+ log.error("Failed to store the execution output details " + context.storePath);
+ }
+ }
public List<OnapCommandExecutionStore.Execution> listExecutions(Map<String, String> search) throws OnapCommandExecutionFailed {
List <OnapCommandExecutionStore.Execution> list = new ArrayList<>();
@@ -342,7 +397,8 @@ public class OnapCommandExecutionStore {
return exectuion;
}
- public Execution getExecution(String executionId) throws OnapCommandExecutionNotFound, OnapCommandExecutionFailed {
+
+ private File getExecutionDir(String executionId) throws OnapCommandExecutionNotFound {
File []f = new File(getBasePath()).listFiles(new FilenameFilter() {
@Override
@@ -356,10 +412,37 @@ public class OnapCommandExecutionStore {
throw new OnapCommandExecutionNotFound(executionId);
}
+ return f[0];
+ }
+
+ public String showExecutionOut(String executionId) throws OnapCommandExecutionNotFound {
+ try {
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stdout"));
+ } catch (IOException e) {
+ return "";
+ }
+ }
+
+ public String showExecutionErr(String executionId) throws OnapCommandExecutionNotFound {
+ try {
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stderr"));
+ } catch (IOException e) {
+ return "";
+ }
+ }
+
+ public String showExecutionDebug(String executionId) throws OnapCommandExecutionNotFound {
+ try {
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "debug"));
+ } catch (IOException e) {
+ return "";
+ }
+ }
+ public Execution getExecution(String executionId) throws OnapCommandExecutionNotFound, OnapCommandExecutionFailed {
try {
- return this.makeExecution(f[0].getAbsolutePath());
+ return this.makeExecution(this.getExecutionDir(executionId).getAbsolutePath());
} catch (IOException e) {
throw new OnapCommandExecutionFailed(e, "Failed to retrieve the execution");
}
}
-}
+} \ No newline at end of file
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index 7c1f18f6..a94087ec 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -508,7 +508,6 @@ public class OnapCommandDiscoveryUtils {
Map<String, String> sample = samples.get(sampleId);
List<String> inputArgs = new ArrayList();
- inputArgs.add(cmd);
if (sample.get(OnapCommandConstants.VERIFY_INPUT) != null) {
inputArgs.addAll(Arrays.asList(sample.get(OnapCommandConstants.VERIFY_INPUT).trim().split(" ")));
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index e279fa0b..96f864e0 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -31,6 +31,8 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.conf.OnapCommandConfig;
@@ -185,6 +187,49 @@ public class OnapCommandUtils {
* @return
*/
public static String replaceLineForSpecialValues(String lineSpl) {
+ return replaceLineForSpecialValues(lineSpl, new HashMap<String, String>());
+ }
+
+ /**
+ *
+ * @param lineSpl
+ * @param values Value for the given entry already known by the caller.
+ * @return
+ */
+ public static String replaceLineFromResults(String line, Map <String, String> values) {
+ String resultLine = "";
+
+ if (!line.contains("$r{")) {
+ return line;
+ }
+
+ int currentIdx = 0;
+ while (currentIdx < line.length()) {
+ int idxS = line.indexOf("$r{", currentIdx);
+ if (idxS == -1) {
+ resultLine += line.substring(currentIdx);
+ break;
+ }
+ int idxE = line.indexOf("}", idxS);
+ String attr = line.substring(idxS + 3, idxE);
+ attr = attr.trim();
+
+ String value = "";
+
+ if (values.get(attr) != null) {
+ value = values.get(attr);
+ } else {
+ value = attr;
+ }
+
+ resultLine += line.substring(currentIdx, idxS) + value;
+ currentIdx = idxE + 1;
+ }
+
+ return resultLine;
+ }
+
+ public static String replaceLineForSpecialValues(String lineSpl, Map <String, String> values) {
String resultSpl = "";
if (!lineSpl.contains("$s{")) {
@@ -232,8 +277,20 @@ public class OnapCommandUtils {
//exist.
value = "";
}
+ } else if (splEntry.startsWith(OnapCommandConstants.SPL_ENTRY_MD5)) {
+ //start to read after md5:entryname
+ String entryName = splEntry.substring(4);
+ String content = values.get(entryName);
+ if (content != null)
+ value = OnapCommandUtils.md5(content);
+ else
+ value = splEntry;
} else {
- value = splEntry;
+ if (values.get(splEntry) != null) {
+ value = values.get(splEntry);
+ } else {
+ value = splEntry;
+ }
}
}
@@ -271,7 +328,11 @@ public class OnapCommandUtils {
|| OnapCommandParameterType.JSON.equals(param.getParameterType())
|| OnapCommandParameterType.YAML.equals(param.getParameterType())) {
// ignore the front and back double quotes in json body
- result += line.substring(currentIdx, idxS - 1) + params.get(paramName).getValue().toString();
+ String va_ = params.get(paramName).getValue().toString();
+ if (idxS > 0)
+ result += line.substring(currentIdx, idxS - 1) + va_;
+ else
+ result += va_;
currentIdx = idxE + 2;
} else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) {
try {
@@ -366,6 +427,12 @@ public class OnapCommandUtils {
}
}
+ public static String md5(String content) {
+ String md5 = DigestUtils.md5Hex(content);
+
+ byte[] encodeBase64 = Base64.encodeBase64(md5.getBytes());
+ return new String(encodeBase64);
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
index eb335837..db7245c7 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
@@ -17,18 +17,18 @@
package org.onap.cli.fw.utils;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
-import org.onap.cli.fw.cmd.OnapCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,8 +43,9 @@ public class ProcessRunner {
private int exitCode = -1;
private String output;
private String error;
- private Map<String, Object> results;
-
+ private long timeout = 0;
+ private OutputStream stdout;
+ private OutputStream stderr;
public ProcessRunner(String []cmd, String []env, String cwd) {
this.cmd = cmd;
@@ -55,6 +56,14 @@ public class ProcessRunner {
this.env = env;
}
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public long getTimeout() {
+ return this.timeout;
+ }
+
public void overrideToUnix() {
this.shell = UNIX_SHELL;
}
@@ -82,9 +91,13 @@ public class ProcessRunner {
@SuppressWarnings("unchecked")
public void run() throws InterruptedException, IOException {
Process p = null;
+
final StringWriter writerOutput = new StringWriter();
final StringWriter writerError = new StringWriter();
+ final OutputStream stdout = this.getStdout();
+ final OutputStream stderr = this.getStderr();
+
if (this.cmd.length == 1) {
p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, null);
} else {
@@ -98,7 +111,10 @@ public class ProcessRunner {
new Thread(new Runnable() {
public void run() {
try {
- IOUtils.copy(p1.getInputStream(), writerOutput);
+ if (stdout != null) {
+ IOUtils.copy(p1.getInputStream(), stdout);
+ }
+ else IOUtils.copy(p1.getInputStream(), writerOutput);
} catch (IOException e) {
}
}
@@ -107,21 +123,32 @@ public class ProcessRunner {
new Thread(new Runnable() {
public void run() {
try {
- IOUtils.copy(p1.getErrorStream(), writerError);
+ if (stderr != null) {
+ IOUtils.copy(p1.getErrorStream(), stderr);
+ }
+ else IOUtils.copy(p1.getErrorStream(), writerError);
} catch (IOException e) {
}
}
}).start();
- //mrkanag: handle the case if the given cmd does not exist
- p.waitFor(1, TimeUnit.MINUTES);
- this.exitCode = p.exitValue();
+ boolean completed = p.waitFor(this.getTimeout(), TimeUnit.MILLISECONDS);
+ if (completed) {
+ this.exitCode = p.exitValue();
+ }
+
this.output = writerOutput.toString();
this.error = writerError.toString();
log.debug("CMD: " + Arrays.asList(this.cmd).toString() + "\nWORKING_DIR: " + this.cwd + "\nENV: " +
((this.env == null) ? this.env : Arrays.asList(this.env).toString()) +
"\nOUTPUT: " + this.output + "\nERROR: " + this.error + "\nEXIT_CODE: " + this.exitCode);
p.destroy();
+
+ if (!completed) {
+ throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
+ } else {
+
+ }
}
public String streamToString(InputStream stream) throws IOException {
@@ -152,4 +179,32 @@ public class ProcessRunner {
public String getError() {
return this.error;
}
+
+ public OutputStream getStdout() {
+ return stdout;
+ }
+
+ public void setStdout(OutputStream stdout) {
+ this.stdout = stdout;
+ }
+
+ public OutputStream getStderr() {
+ return stderr;
+ }
+
+ public void setStderr(OutputStream stderr) {
+ this.stderr = stderr;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("COMMAND: " + this.shell + " " + Arrays.asList(this.cmd));
+ sb.append("\nCWD: " + new File(this.cwd).getAbsolutePath());
+ sb.append("\nTIMEOUT: " + this.timeout);
+ sb.append("\nEXIT-CODE: " + this.getExitCode());
+ sb.append("\nENVIRONMENTS: " + Arrays.asList(this.env));
+
+ return sb.toString();
+ }
} \ No newline at end of file