summaryrefslogtreecommitdiffstats
path: root/asdctool/src/main/java/org
diff options
context:
space:
mode:
authorParshad Patel <pars.patel@samsung.com>2018-09-12 20:26:38 +0900
committerMichael Lando <ml636r@att.com>2018-09-18 15:47:14 +0000
commit48a9fdbd8da734f8e5bfb3cd38295ee315dd7fd2 (patch)
tree09694f310c3c180c6f948c392117d3cb95bc3b48 /asdctool/src/main/java/org
parente0199375f17d89314de0fe812329dc99d8e7abf9 (diff)
Fix use try-with-resources issues in asdctool
Fix sonar issues in ArtifactValidatorExecuter.java,ExportImportTitanServlet.java Issue-ID: SDC-1672 Change-Id: I39a6376ea61de135bfb824e121adff37b631fdf2 Signed-off-by: Parshad Patel <pars.patel@samsung.com>
Diffstat (limited to 'asdctool/src/main/java/org')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java18
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java35
2 files changed, 18 insertions, 35 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
index 089e9729d4..34696b33eb 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
@@ -44,7 +44,7 @@ public class ArtifactValidatorExecuter{
Map<String, List<Component>> result = new HashMap<>();
Either<List<GraphVertex>, TitanOperationStatus> resultsEither = titanDao.getByCriteria(type, hasProps);
if (resultsEither.isRight()) {
- System.out.println("getVerticesToValidate failed "+ resultsEither.right().value());
+ log.error("getVerticesToValidate failed "+ resultsEither.right().value());
return result;
}
System.out.println("getVerticesToValidate: "+resultsEither.left().value().size()+" vertices to scan");
@@ -62,7 +62,7 @@ public class ArtifactValidatorExecuter{
Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
if (toscaElement.isRight()) {
- System.out.println("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
+ log.error("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
}else{
compList.add(toscaElement.left().value());
}
@@ -76,9 +76,7 @@ public class ArtifactValidatorExecuter{
boolean result = true;
long time = System.currentTimeMillis();
String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_"+ time + ".csv";
- Writer writer = null;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"));
+ try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
writer.write("name, UUID, invariantUUID, state, version\n");
Collection<List<Component>> collection = vertices.values();
for(List<Component> compList: collection ){
@@ -100,15 +98,10 @@ public class ArtifactValidatorExecuter{
}
} catch (Exception e) {
- log.info("Failed to fetch vf resources ", e);
+ log.error("Failed to fetch vf resources ", e);
return false;
} finally {
titanDao.commit();
- try {
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- /* ignore */}
}
return result;
}
@@ -124,8 +117,7 @@ public class ArtifactValidatorExecuter{
writer.write(sb.toString());
}
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ log.error("Failed to write module result to file ", e);
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
index c1f9335d59..31b1b1f07a 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/servlets/ExportImportTitanServlet.java
@@ -70,39 +70,30 @@ public class ExportImportTitanServlet {
conf.setProperty("storage.machine-id-appendix", System.currentTimeMillis() % 1000);
- TitanGraph openGraph = Utils.openGraph(conf);
- if (openGraph == null) {
- Response buildErrorResponse = Utils.buildOkResponse(500, "failed to open graph", null);
- return buildErrorResponse;
+ try(TitanGraph openGraph = Utils.openGraph(conf)){
+
+ if (openGraph == null) {
+ Response buildErrorResponse = Utils.buildOkResponse(500, "failed to open graph", null);
+ return buildErrorResponse;
+ }
+
+ // Open Titan Graph
+
+ Response buildOkResponse = Utils.buildOkResponse(200, "ok man", null);
+
+ return buildOkResponse;
}
-
- // Open Titan Graph
-
- Response buildOkResponse = Utils.buildOkResponse(200, "ok man", null);
-
- return buildOkResponse;
}
private Properties convertFileToProperties(File titanPropertiesFile) {
Properties properties = new Properties();
- FileReader fileReader = null;
- try {
- fileReader = new FileReader(titanPropertiesFile);
+ try (FileReader fileReader = new FileReader(titanPropertiesFile)){
properties.load(fileReader);
-
} catch (Exception e) {
log.error("Failed to convert file to properties", e);
return null;
- } finally {
- if (fileReader != null) {
- try {
- fileReader.close();
- } catch (IOException e) {
- log.error("Failed to close file", e);
- }
- }
}
return properties;