aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandProfileNotFound.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandWarning.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java24
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java145
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java4
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java2
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java2
8 files changed, 100 insertions, 89 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProfileNotFound.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProfileNotFound.java
index efc7b36c..56a58590 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProfileNotFound.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandProfileNotFound.java
@@ -26,7 +26,6 @@ public class OnapCommandProfileNotFound extends OnapCommandException {
private static final String ERROR_CODE = "0xc002";
- private static final String ERROR_MSG = "Profile does not exist";
/**
* Profile does not exist.
*/
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 ccd2cee5..619451e5 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
@@ -24,15 +24,15 @@ public abstract class OnapCommandWarning extends OnapCommandException {
private static final long serialVersionUID = -1833571383961748520L;
- public OnapCommandWarning(String errorCode, String errorMessage, long httpStatusCode) {
+ protected OnapCommandWarning(String errorCode, String errorMessage, long httpStatusCode) {
super(errorCode, errorMessage, httpStatusCode);
}
- public OnapCommandWarning(String errorCode, String errorMessage) {
+ protected OnapCommandWarning(String errorCode, String errorMessage) {
super(errorCode, errorMessage);
}
- public OnapCommandWarning(String errorCode, String errorMessage, Throwable err) {
+ protected OnapCommandWarning(String errorCode, String errorMessage, Throwable err) {
super(errorCode, errorMessage, err);
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
index fa9bcf02..cba7134d 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/OnapCommandResult.java
@@ -120,8 +120,8 @@ public class OnapCommandResult {
public Map<String, OnapCommandResultAttribute> getRecordsMap() {
Map<String, OnapCommandResultAttribute> recordMap = new HashMap<>();
- for (OnapCommandResultAttribute record : this.getRecords()) {
- recordMap.put(record.getName(), record);
+ for (OnapCommandResultAttribute data : this.getRecords()) {
+ recordMap.put(data.getName(), data);
}
return recordMap;
@@ -194,8 +194,8 @@ public class OnapCommandResult {
if (!this.getRecords().isEmpty()) {
if (this.getPrintDirection().equals(OnapCommandPrintDirection.LANDSCAPE)) {
- for (OnapCommandResultAttribute record : this.getScopedRecords()) {
- print.addColumn(record.getName(), record.getValues());
+ for (OnapCommandResultAttribute data : this.getScopedRecords()) {
+ print.addColumn(data.getName(), data.getValues());
}
} else {
// Add property column
@@ -207,12 +207,12 @@ public class OnapCommandResult {
val.setName(OnapCommandConstants.PORTRAINT_COLUMN_NAME_VALUE);
val.setScope(OnapCommandResultAttributeScope.SHORT);
- for (OnapCommandResultAttribute record : this.getScopedRecords()) {
- prp.getValues().add(record.getName());
- if (record.getValues().size() == 1) {
- val.getValues().add(record.getValues().get(0));
+ for (OnapCommandResultAttribute data : this.getScopedRecords()) {
+ prp.getValues().add(data.getName());
+ if (data.getValues().size() == 1) {
+ val.getValues().add(data.getValues().get(0));
} else {
- val.getValues().add(record.getValues().toString());
+ val.getValues().add(data.getValues().toString());
}
}
@@ -254,11 +254,11 @@ public class OnapCommandResult {
private List<OnapCommandResultAttribute> getScopedRecords() {
List<OnapCommandResultAttribute> recordList = new ArrayList<>();
- for (OnapCommandResultAttribute record : this.getRecords()) {
- if (record.getScope().ordinal() > this.getScope().ordinal()) {
+ for (OnapCommandResultAttribute data : this.getRecords()) {
+ if (data.getScope().ordinal() > this.getScope().ordinal()) {
continue;
}
- recordList.add(record);
+ recordList.add(data);
}
return recordList;
diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java
index 7e0d40ee..d8f29800 100644
--- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java
+++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaMerger.java
@@ -77,9 +77,10 @@ public class OnapCommandSchemaMerger {
public static void mergeYamlMap(Map<String, Object> mergedResult, Map<String, Object> yamlContents) {
if (yamlContents == null) return;
- for (String key : yamlContents.keySet()) {
+ for (Map.Entry<String,Object> entry : yamlContents.entrySet()) {
- Object yamlValue = yamlContents.get(key);
+ String key = entry.getKey();
+ Object yamlValue = entry.getValue();
if (yamlValue == null) {
mergedResult.put(key, yamlValue);
continue;
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 e72327fe..91f45f02 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
@@ -55,6 +55,8 @@ public class OnapCommandExecutionStore {
private static final String FAILED = "failed";
private static final String EXECUTIONID = "execution-id";
private static final String REQUESTID = "request-id";
+ private static final String OS_NAME = "os.name";
+ private static final String WINDOWS = "windows";
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
@@ -338,78 +340,89 @@ public class OnapCommandExecutionStore {
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<>();
- try {
- List <String> dirs = new ArrayList<>();
- if (System.getProperty("os.name").toLowerCase().startsWith("windows") || searchMode.equals(SearchMode.FILE)) {
- for (File f: new File(getBasePath()).listFiles()) {
- if(search.containsKey(EXECUTIONID)) {
- if (f.getName().startsWith(search.get(EXECUTIONID)))
- dirs.add(f.getAbsolutePath());
+ public List <String> listExecutionsWindows(Map<String, String> search, List <String> dirs){
+ for (File f: new File(getBasePath()).listFiles()) {
+ if(search.containsKey(EXECUTIONID)) {
+ if (f.getName().startsWith(search.get(EXECUTIONID)))
+ dirs.add(f.getAbsolutePath());
+
+ continue;
+ }
+
+ if(search.containsKey(REQUESTID)) {
+ if (f.getName().startsWith(search.get(REQUESTID)))
+ dirs.add(f.getAbsolutePath());
+
+ }
+
+ else
+ dirs.add(f.getAbsolutePath());
+ }
+ return dirs;
+ }
+
+ public List <String> searchAndListExecutions(Map<String, String> search, List <String> dirs) throws OnapCommandExecutionFailed, IOException, InterruptedException {
+ StringBuilder searchString = new StringBuilder("find " + new File(getBasePath()).getAbsolutePath() + " -type d ");
+
+ String startTime = search.get("startTime");
+ if (startTime != null) {
+ searchString.append(" -newermt " + startTime);
+ }
+
+ String endTime = search.get("endTime");
+ if (endTime != null) {
+ searchString.append(" ! -newermt " + endTime);
+ }
+
+ searchString.append(" -name \"");
- continue;
- }
+ if(search.containsKey(EXECUTIONID)) {
+ searchString.append(search.get(EXECUTIONID));
+ } else if(search.containsKey(REQUESTID)) {
+ searchString.append(search.get(REQUESTID) + "*");
+ } else {
+ searchString.append("*");
+ }
- if(search.containsKey(REQUESTID)) {
- if (f.getName().startsWith(search.get(REQUESTID)))
- dirs.add(f.getAbsolutePath());
+ for (String term: Arrays.asList("product", "service", "command", "profile")) {
+ searchString.append("__");
+ if (search.get(term) != null && !search.get(term).isEmpty()) {
+ searchString.append(search.get(term));
+ } else {
+ searchString.append("*");
+ }
+ }
+ if (!searchString.toString().endsWith("*"))
+ searchString.append("*");
+
+ searchString.append("\"");
+
+ ProcessRunner pr = new ProcessRunner(new String [] {searchString.toString()}, 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());
+ }
- }
+ if (!pr.getOutput().trim().isEmpty())
+ dirs = Arrays.asList(pr.getOutput().split("\\r?\\n"));
- else
- dirs.add(f.getAbsolutePath());
- }
+ return dirs;
+ }
+
+ public List<OnapCommandExecutionStore.Execution> listExecutions(Map<String, String> search) throws OnapCommandExecutionFailed {
+ List <OnapCommandExecutionStore.Execution> list = new ArrayList<>();
+
+ try {
+ List <String> dirs = new ArrayList<>();
+ if (System.getProperty(OS_NAME).toLowerCase().startsWith(WINDOWS) || searchMode.equals(SearchMode.FILE)) {
+ dirs = listExecutionsWindows(search, dirs);
} 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*"
-
- StringBuilder searchString = new StringBuilder("find " + new File(getBasePath()).getAbsolutePath() + " -type d ");
-
- String startTime = search.get("startTime");
- if (startTime != null) {
- searchString.append(" -newermt " + startTime);
- }
-
- String endTime = search.get("endTime");
- if (endTime != null) {
- searchString.append(" ! -newermt " + endTime);
- }
-
- searchString.append(" -name \"");
-
- if(search.containsKey(EXECUTIONID)) {
- searchString.append(search.get(EXECUTIONID));
- } else if(search.containsKey(REQUESTID)) {
- searchString.append(search.get(REQUESTID) + "*");
- } else {
- searchString.append("*");
- }
-
- for (String term: Arrays.asList("product", "service", "command", "profile")) {
- searchString.append("__");
- if (search.get(term) != null && !search.get(term).isEmpty()) {
- searchString.append(search.get(term));
- } else {
- searchString.append("*");
- }
- }
- if (!searchString.toString().endsWith("*"))
- searchString.append("*");
-
- searchString.append("\"");
-
- ProcessRunner pr = new ProcessRunner(new String [] {searchString.toString()}, 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());
- }
-
- if (!pr.getOutput().trim().isEmpty())
- dirs = Arrays.asList(pr.getOutput().split("\\r?\\n"));
+ dirs = searchAndListExecutions(search, dirs);
}
for (String dir: dirs) {
@@ -470,7 +483,7 @@ public class OnapCommandExecutionStore {
public String showExecutionOut(String executionId) throws OnapCommandExecutionNotFound {
try {
- return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stdout"));
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + STDOUT));
} catch (IOException e) {
return "";
}
@@ -478,7 +491,7 @@ public class OnapCommandExecutionStore {
public String showExecutionErr(String executionId) throws OnapCommandExecutionNotFound {
try {
- return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "stderr"));
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + STDERR));
} catch (IOException e) {
return "";
}
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 b2bbfd47..c970e3ab 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
@@ -338,7 +338,7 @@ public class OnapCommandDiscoveryUtils {
if (!schema.getVersion().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) {
String schemaURI = schema.getSchemaURI();
- OnapCommandUtils.log.info("Unsupported Schema version found {} " + schemaURI);
+ OnapCommandUtils.log.info("Unsupported Schema version found {} ", schemaURI);
}
else{
@@ -556,7 +556,7 @@ public class OnapCommandDiscoveryUtils {
* @throws OnapCommandInvalidSchema
* exception
*/
- public static Map<String, ?> loadYaml(Resource resource, boolean ignoreInvalidSchema) throws OnapCommandInvalidSchema, IOException {
+ public static Map<String, ?> loadYaml(Resource resource, boolean ignoreInvalidSchema) throws OnapCommandInvalidSchema, IOException {//NOSONAR
Map<String, ?> values = null;
try {
values = loadYaml(resource.getInputStream());
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 53e90661..123521bf 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
@@ -168,8 +168,6 @@ public class OnapCliArgsParser {
"it should be in the form of <key>=<value>");
}
- //Make sure to read values from file, in case file path is given.
- //map.put(argArr[0], readTextStringFromUrl(argArr[1], paramMap.get(paramName).getName()));
map.put(argArr[0], argArr[1]);
paramMap.get(paramName).setValue(map);
i++;
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 3bbdcf6f..95ffb9f2 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
@@ -256,7 +256,7 @@ public class OpenCommandShellCmd extends OnapCommand {
outputValue = pr.getError();
} else {
- //remove ${tmp: and closing }
+ //remove $(tmp: and closing )
String tmpName = this.output.substring(7, this.output.length()-1);
String tmpFile = tmpFiles.get("tmp:" + tmpName);
if (tmpFile != null) {