aboutsummaryrefslogtreecommitdiffstats
path: root/appc-directed-graph/dg-loader/provider
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-02-21 14:54:51 +0100
committerPatrick Brady <pb071s@att.com>2018-02-22 17:47:47 +0000
commit446bae37c2f6dabe842cb2b6585a17bcec327a17 (patch)
treec17c7920103092d46755e8cc3c72009606d51373 /appc-directed-graph/dg-loader/provider
parent4dba18de7f337c8e9b4e67a55b7c1f44ef21f034 (diff)
DGXMLActivate sonar fixes
Change-Id: I7d09a91d66d491b5942214d1df36c188c4e9cda6 Issue-ID: APPC-654 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
Diffstat (limited to 'appc-directed-graph/dg-loader/provider')
-rw-r--r--appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java117
1 files changed, 62 insertions, 55 deletions
diff --git a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java
index 6d2cfda4d..77415478a 100644
--- a/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java
+++ b/appc-directed-graph/dg-loader/provider/src/main/java/org/onap/sdnc/dg/loader/DGXMLActivate.java
@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory;
@@ -36,16 +37,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
public class DGXMLActivate {
- private final static Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
+ private static final Logger logger = LoggerFactory.getLogger(DGXMLLoadNActivate.class);
+ private static final String STRING_ENCODING = "utf-8";
private final SvcLogicStore store;
- public static String STRING_ENCODING = "utf-8";
- public DGXMLActivate(String propfile) throws Exception {
+ public DGXMLActivate(String propfile) throws DGXMLException, SvcLogicException {
if (StringUtils.isBlank(propfile)) {
- throw new Exception(propfile + " Profile file is not defined");
+ throw new DGXMLException(propfile + " Profile file is not defined");
}
this.store = SvcLogicStoreFactory.getSvcLogicStore(propfile);
}
@@ -54,87 +54,94 @@ public class DGXMLActivate {
this.store = store;
}
-
- public void activateDg(String activateFilePath) throws Exception {
+ public void activateDg(String activateFilePath) {
logger.info(
- "******************** Activating DG into Database *****************************");
+ "******************** Activating DG into Database *****************************");
try {
- List<String> errors = new ArrayList<String>();
+ List<String> errors = new ArrayList<>();
if (this.store != null) {
File activateFile = new File(activateFilePath);
if (activateFile.isFile()) {
List<String> fileLines = FileUtils.readLines(activateFile, STRING_ENCODING);
- if (fileLines != null) {
- for (String line : fileLines) {
- if (line != null && !line.trim().startsWith("#")) {
- String lineArray[] = line.trim().split(":");
- try {
- if (lineArray != null && lineArray.length >= 4) {
- String module = lineArray[0];
- String rpc = lineArray[1];
- String version = lineArray[2];
- String mode = lineArray[3];
- if (StringUtils.isNotBlank(module)
- && StringUtils.isNotBlank(rpc)
- && StringUtils.isNotBlank(version)
- && StringUtils.isNotBlank(mode)) {
- logger.info("Activating DG :" + line);
- SvcLogicGraph graph =
- this.store.fetch(module, rpc, version, mode);
- if (graph != null) {
- logger.info(
- "Found Graph :" + line + " Activating ...");
- this.store.activate(graph);
- } else {
- throw new Exception(
- "Failed to fetch from Database");
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- errors.add(
- "Failed to Activate " + line + ", " + e.getMessage());
- }
- }
- }
- }
+ tryActivateDG(errors, fileLines);
} else {
- throw new Exception(activateFile + " is not a valid Activate file Path");
+ throw new DGXMLException(activateFile + " is not a valid Activate file Path");
}
} else {
- throw new Exception("Failed to initialise SvcLogicStore");
+ throw new DGXMLException("Failed to initialise SvcLogicStore");
}
- if (errors.size() > 0) {
- throw new Exception(errors.toString());
+ if (errors.isEmpty()) {
+ throw new DGXMLException(errors.toString());
}
} catch (Exception e) {
- logger.error(e.getMessage());
+ logger.error("Failed to activate DG", e);
}
}
+ private void tryActivateDG(List<String> errors, List<String> fileLines) {
+ if (fileLines != null) {
+ for (String line : fileLines) {
+ if (line != null && !line.trim().startsWith("#")) {
+ String[] lineArray = line.trim().split(":");
+ doActivateDG(errors, line, lineArray);
+ }
+ }
+ }
+ }
+
+ private void doActivateDG(List<String> errors, String line, String[] lineArray) {
+ try {
+ if (lineArray.length >= 4) {
+ String module = lineArray[0];
+ String rpc = lineArray[1];
+ String version = lineArray[2];
+ String mode = lineArray[3];
+ if (StringUtils.isNotBlank(module)
+ && StringUtils.isNotBlank(rpc)
+ && StringUtils.isNotBlank(version)
+ && StringUtils.isNotBlank(mode)) {
+ logger.info("Activating DG :" + line);
+ SvcLogicGraph graph =
+ this.store.fetch(module, rpc, version, mode);
+ tryActivateStore(line, graph);
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Failed to Activate " + line, e);
+ errors.add("Failed to Activate " + line + ", " + e.getMessage());
+ }
+ }
+
+ private void tryActivateStore(String line, SvcLogicGraph graph) throws SvcLogicException, DGXMLException {
+ if (graph != null) {
+ logger.info(
+ "Found Graph :" + line + " Activating ...");
+ this.store.activate(graph);
+ } else {
+ throw new DGXMLException("Failed to fetch from Database");
+ }
+ }
public static void main(String[] args) {
try {
- String activateFile = null;
- String propertyPath = null;
+ String activateFile;
+ String propertyPath;
if (args != null && args.length >= 2) {
activateFile = args[0];
propertyPath = args[1];
} else {
- throw new Exception(
- "Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
+ throw new DGXMLException(
+ "Sufficient inputs for DGXMLActivate are missing <activatefile> <dbPropertyfile>");
}
DGXMLActivate dgXmlActivate = new DGXMLActivate(propertyPath);
dgXmlActivate.activateDg(activateFile);
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("Arguments missing", e);
} finally {
System.exit(1);
}
}
-
}