aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src')
-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.java55
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java75
-rw-r--r--framework/src/main/resources/open-cli.properties2
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/ProcessRunnerTest.java2
-rw-r--r--framework/src/test/resources/open-cli.properties49
8 files changed, 148 insertions, 42 deletions
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..d09dfa50 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 {
@@ -199,7 +214,7 @@ public class OnapCommandExecutionStore {
String storePath = getBasePath() + File.separator + executionId + SEPARATOR + product +
SEPARATOR + service +
SEPARATOR + cmd +
- (profile != null ? (SEPARATOR + profile) : "" );
+ SEPARATOR + (profile != null ? profile : "" );
try {
File dir = new File(storePath);
@@ -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"));
@@ -302,14 +319,30 @@ public class OnapCommandExecutionStore {
try {
List <String> dirs = new ArrayList<>();
- if (SEARCH_MODE.equals(SearchMode.file)) {
- for (File f: new File(getBasePath()).listFiles())
- dirs.add(f.getAbsolutePath());
+ if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.file)) {
+ for (File f: new File(getBasePath()).listFiles()) {
+ if(search.containsKey("execution-id")) {
+ if (f.getName().startsWith(search.get("execution-id")))
+ dirs.add(f.getAbsolutePath());
+
+ continue;
+ }
+
+ if(search.containsKey("request-id")) {
+ if (f.getName().startsWith(search.get("request-id")))
+ dirs.add(f.getAbsolutePath());
+
+ continue;
+ }
+
+ else
+ dirs.add(f.getAbsolutePath());
+ }
} else {
//find results -type d -newermt '2019-02-11 10:00:00' ! -newermt '2019-02-11 15:10:00' -name "*__*__profile-list*"
//find 'results' -type d -newermt '2019-02-11T10:00:00.000' ! -newermt '2019-02-11T15:10:00.000' -name "*__*__profile*"
- String searchString = "find '" + new File(getBasePath()).getAbsolutePath() + "' -type d ";
+ String searchString = "find " + new File(getBasePath()).getAbsolutePath() + " -type d ";
String startTime = search.get("startTime");
if (startTime != null) {
@@ -321,7 +354,7 @@ public class OnapCommandExecutionStore {
searchString += " ! -newermt " + endTime ;
}
- searchString += " -name '";
+ searchString += " -name \"";
if(search.containsKey("execution-id")) {
searchString += search.get("execution-id");
@@ -333,7 +366,7 @@ public class OnapCommandExecutionStore {
for (String term: Arrays.asList(new String []{"product", "service", "command", "profile"})) {
searchString += "__";
- if (search.get(term) != null) {
+ if (search.get(term) != null && !search.get(term).isEmpty()) {
searchString += search.get(term);
} else {
searchString += "*";
@@ -342,16 +375,18 @@ public class OnapCommandExecutionStore {
if (!searchString.endsWith("*"))
searchString += "*";
- searchString += "'";
+ searchString += "\"";
ProcessRunner pr = new ProcessRunner(new String [] {searchString}, null, ".");
+ pr.setTimeout(10000);
pr.overrideToUnix();
pr.run();
if (pr.getExitCode() != 0) {
throw new OnapCommandExecutionFailed("System failed to search the executions with error " + pr.getError());
}
- dirs = Arrays.asList(pr.getOutput().split("\\r?\\n"));
+ if (!pr.getOutput().trim().isEmpty())
+ dirs = Arrays.asList(pr.getOutput().split("\\r?\\n"));
}
for (String dir: dirs) {
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 d36a0d6c..ff9d5520 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,12 +17,12 @@
package org.onap.cli.fw.utils;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
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;
@@ -41,8 +41,8 @@ public class ProcessRunner {
private String cwd = System.getProperty("user.home");
private String []env = null;
private int exitCode = -1;
- private String output;
- private String error;
+ private String output = "";
+ private String error = "";
private long timeout = 0;
private OutputStream stdout;
private OutputStream stderr;
@@ -92,12 +92,6 @@ public class ProcessRunner {
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 {
@@ -107,47 +101,70 @@ public class ProcessRunner {
p = Runtime.getRuntime().exec(cmds, this.env, null);
}
- final Process p1 = p;
- new Thread(new Runnable() {
+ boolean readOutput = false;
+ if (this.getStdout() == null) {
+ this.setStdout(new ByteArrayOutputStream());
+ readOutput = true;
+ }
+
+ boolean readError = false;
+ if (this.getStderr() == null) {
+ this.setStderr(new ByteArrayOutputStream());
+ readError = true;
+ }
+
+ final OutputStream stdout = this.getStdout();
+ final OutputStream stderr = this.getStderr();
+
+ final InputStream stdoutP = p.getInputStream();
+ final InputStream stderrP = p.getErrorStream();
+
+ Thread outThread = new Thread(new Runnable() {
public void run() {
try {
- if (stdout != null) {
- IOUtils.copy(p1.getInputStream(), stdout);
- }
- else IOUtils.copy(p1.getInputStream(), writerOutput);
+ IOUtils.copy(stdoutP, stdout);
} catch (IOException e) {
}
}
- }).start();
+ });
- new Thread(new Runnable() {
+ Thread errThread = new Thread(new Runnable() {
public void run() {
try {
- if (stderr != null) {
- IOUtils.copy(p1.getErrorStream(), stderr);
- }
- else IOUtils.copy(p1.getErrorStream(), writerError);
+ IOUtils.copy(stderrP, stderr);
} catch (IOException e) {
}
}
- }).start();
+ });
+
+ outThread.start();
+ errThread.start();
boolean completed = p.waitFor(this.getTimeout(), TimeUnit.MILLISECONDS);
+ outThread.join();
+ errThread.join();
+
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);
+ if (readOutput)
+ this.output = new String(((ByteArrayOutputStream)this.getStdout()).toByteArray(), "UTF-8");
+
+ if (readError)
+ this.error = new String(((ByteArrayOutputStream)this.getStderr()).toByteArray(), "UTF-8");;
+
p.destroy();
+ 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);
+
if (!completed) {
throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
- } else {
-
}
}
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/framework/src/test/java/org/onap/cli/fw/utils/ProcessRunnerTest.java b/framework/src/test/java/org/onap/cli/fw/utils/ProcessRunnerTest.java
index 2e5b2ab9..6d7ebbf9 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/ProcessRunnerTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/ProcessRunnerTest.java
@@ -39,7 +39,7 @@ public class ProcessRunnerTest {
public void testStreamToString() throws IOException {
InputStream stubInputStream = IOUtils.toInputStream("Test stream", "UTF-8");
String out = processRunner.streamToString(stubInputStream);
- Assert.assertEquals("Test stream\n", out);
+ Assert.assertEquals("Test stream", out.trim());
}
}
diff --git a/framework/src/test/resources/open-cli.properties b/framework/src/test/resources/open-cli.properties
new file mode 100644
index 00000000..bd8a6acf
--- /dev/null
+++ b/framework/src/test/resources/open-cli.properties
@@ -0,0 +1,49 @@
+# Copyright 2018 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.
+
+cli.product_name=open-cli
+cli.version=3.0.0
+cli.discover_always=false
+cli.data.dir=./data
+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
+
+cli.schema.base.info.sections=product,service,type,author,ignore,state
+cli.schema.base.info.sections.mandatory=product,service
+
+cli.schema.base.parameters.sections=name,description,type,short_option,long_option, is_optional,default_value,is_secured,is_include,is_default_param
+cli.schema.base.parameters.sections.mandatory=name,description,type
+
+cli.schema.base.results.sections=name,description,scope,type,is_secured, default_value
+cli.schema.base.results.sections.mandatory=name, description, type, scope
+
+cli.schema.boolean_values=true,false
+cli.schema.command.type=cmd,auth,catalog
+
+# moco properties
+cli.sample.gen.enable=false
+cli.sample.gen.target=./open-cli-sample
+
+# mrkanag Move this to db, once exteranl command registration is supported in place of discovery
+cli.schema.profile.available=http,snmp,cmd
+
+#other properties to load (it should be hanled when plugins are made as externally register-able
+#when command plugin management support is enabled in oclip
+cli.schema.profile.confs= \ No newline at end of file