aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/main')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java24
-rw-r--r--framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java1
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java9
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java15
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java5
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java38
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java3
8 files changed, 73 insertions, 24 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java b/framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java
index aed9224a..26b3b00d 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/dummy/OnapCommandDummy.java
@@ -29,7 +29,7 @@ public class OnapCommandDummy extends OnapCommand {
@Override
protected void run() throws OnapCommandException {
-
+ // Dummy Method
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java
new file mode 100644
index 00000000..6e073681
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandTimeOutException.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2020 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.error;
+
+public class OnapCommandTimeOutException extends RuntimeException {
+ private static final long serialVersionUID = -4280521008892487435L;
+
+ public OnapCommandTimeOutException(String message) {
+ super(message);
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
index 09050c6c..8092c0fa 100644
--- a/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
+++ b/framework/src/main/java/org/onap/cli/fw/output/print/OnapCommandPrint.java
@@ -270,7 +270,6 @@ public class OnapCommandPrint {
try {
return new JsonParser().parse(array.toJSONString()).toString();
} catch (Exception e) { // NOSONAR
- // TODO Auto-generated catch block
return array.toJSONString();
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index 58797152..32ececfa 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -52,7 +52,7 @@ public class OnapCommandArtifactStore {
private static Logger log = LoggerFactory.getLogger(OnapCommandArtifactStore.class);
private static Gson gson = new GsonBuilder().serializeNulls().create();
- private static boolean storeReady = false;
+ private static boolean storeReady = false; //NOSONAR
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
@@ -230,7 +230,7 @@ public class OnapCommandArtifactStore {
searchPattern += ".json";
- final String SP = searchPattern;
+ final String SP = searchPattern; //NOSONAR
for (File file: new File(getBasePath()).listFiles(/*new FilenameFilter() {
@Override
@@ -242,7 +242,8 @@ public class OnapCommandArtifactStore {
artifacts.add(gson.fromJson(jsonReader, Artifact.class));
} catch (Exception e) { // NOSONAR
//It is expected that this never occurs
- log.error("While seraching Failed to retrieve the artifact at {}", file.getAbsolutePath());
+ String fileAbsPath = file.getAbsolutePath();
+ log.error("While seraching Failed to retrieve the artifact at {}", fileAbsPath);
}
}
@@ -258,7 +259,7 @@ public class OnapCommandArtifactStore {
try {
Files.delete(Paths.get(storePath));
} catch (IOException e) {
- log.error("Failed to delete the artifact " + aFile.getAbsolutePath());
+ log.error("Failed to delete the artifact {}", aFile.getAbsolutePath());
}
}
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 839d1427..d8fdfab9 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
@@ -282,16 +282,21 @@ public class OnapCommandExecutionStore {
else
FileUtils.touch(new File(context.getStorePath() + File.separator + FAILED));
Path path= Paths.get(context.getStorePath() + File.separator + IN_PROGRESS);
- try {
- Files.delete(path);
- } catch (IOException e) {
- log.error("Failed to delete "+ context.getStorePath() + File.separator + IN_PROGRESS);
- }
+ deleteFile(context, path);
} catch (IOException e) {
log.error("Failed to store the execution end details {}", context.storePath);
}
}
+ private void deleteFile(ExecutionStoreContext context, Path path){
+ try {
+ Files.delete(path);
+ } catch (IOException e) {
+ String contextPath = context.getStorePath() + File.separator + IN_PROGRESS;
+ log.error("Failed to delete {}", contextPath);
+ }
+ }
+
public void storeExectutionProgress(
ExecutionStoreContext context,
String output, String error, String debug) {
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
index 732ad002..5cbdf86b 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
@@ -206,8 +206,9 @@ public class OnapCommandProfileStore {
try {
Files.delete(Paths.get(dataDir + File.separator + profile + DATA_PATH_PROFILE_JSON));
} catch (IOException e) {
- log.error("Failed to delete profile {}"+file.getAbsolutePath());
- }
+ String fileAbsPath = file.getAbsolutePath();
+ log.error("Failed to delete profile {}", fileAbsPath);
+ }
}
public List<String> getProfiles() {
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 614eb2a9..4cb95290 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
@@ -290,12 +290,7 @@ public class OnapCommandDiscoveryUtils {
Map<String, ?> deafultResourceMap;
for (Resource resource : deafultRres) {
- try {
- deafultResourceMap = loadYaml(resource);
- } catch (OnapCommandException e) {
- OnapCommandUtils.log.error("Ignores invalid schema " + resource.getURI().toString(), e);
- continue;
- }
+ deafultResourceMap = loadYaml(resource, true);
if (deafultResourceMap != null && deafultResourceMap.size() > 0) {
//default_input_parameters_http.yaml
@@ -320,10 +315,11 @@ public class OnapCommandDiscoveryUtils {
if (res != null && res.length > 0) {
for (Resource resource : res) {
Map<String, ?> resourceMap;
- try {
+ try { //NOSONAR
resourceMap = loadYaml(resource);
} catch (OnapCommandException e) {
- OnapCommandUtils.log.error("Ignores invalid schema " + resource.getURI().toString(), e);
+ String resourceURI = resource.getURI().toString();
+ OnapCommandUtils.log.error("Ignores invalid schema {} {}", resourceURI, e);
continue;
}
@@ -334,13 +330,15 @@ public class OnapCommandDiscoveryUtils {
Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
if (obj == null) {
- OnapCommandUtils.log.info("Invalid Schema yaml {}" + schema.getSchemaURI());
+ String schemaURI = schema.getSchemaURI();
+ OnapCommandUtils.log.info("Invalid Schema yaml {}", schemaURI);
}
else{
schema.setVersion(obj.toString());
if (!schema.getVersion().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) {
- OnapCommandUtils.log.info("Unsupported Schema version found {} " + schema.getSchemaURI());
+ String schemaURI = schema.getSchemaURI();
+ OnapCommandUtils.log.info("Unsupported Schema version found {} " + schemaURI);
}
else{
@@ -551,6 +549,26 @@ public class OnapCommandDiscoveryUtils {
/**
* Get schema map.
*
+ * @param resource
+ * resource obj
+ * ignoreInvalidSchema boolean
+ * @return map
+ * @throws OnapCommandInvalidSchema
+ * exception
+ */
+ public static Map<String, ?> loadYaml(Resource resource, boolean ignoreInvalidSchema) throws OnapCommandInvalidSchema, IOException {
+ Map<String, ?> values = null;
+ try {
+ values = loadYaml(resource.getInputStream());
+ } catch (OnapCommandException | IOException e) {
+ OnapCommandUtils.log.error("Ignores invalid schema {} {}", resource.getURI(), e);
+ }
+ return values;
+ }
+
+ /**
+ * Get schema map.
+ *
* @param filePath
* @return map
* @throws OnapCommandInvalidSchema
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 62f5c9a3..cc4d5eed 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
@@ -32,6 +32,7 @@ import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
+import org.onap.cli.fw.error.OnapCommandTimeOutException;
public class ProcessRunner {
private static Logger log = LoggerFactory.getLogger(ProcessRunner.class);
@@ -163,7 +164,7 @@ public class ProcessRunner {
Arrays.asList(this.cmd), this.cwd, ((this.env == null) ? this.env : Arrays.asList(this.env)), this.output, this.error, this.exitCode);
if (!completed) {
- throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
+ throw new OnapCommandTimeOutException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
}
}