asdctool code quality improvements 34/73234/3
authorSonsino, Ofir (os0695) <os0695@intl.att.com>
Wed, 21 Nov 2018 09:22:09 +0000 (11:22 +0200)
committerTal Gitelman <tal.gitelman@att.com>
Thu, 22 Nov 2018 14:49:07 +0000 (14:49 +0000)
Change-Id: I443c9bb288d123d10bcc2f1f58f540206fb947fc
Issue-ID: SDC-1950
Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
asdctool/src/main/java/org/openecomp/sdc/asdctool/App.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/Utils.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/DataMigration.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ProductLogic.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/RestUtils.java

index 7d11040..f7aaa1e 100644 (file)
@@ -23,7 +23,6 @@ package org.openecomp.sdc.asdctool;
 import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
-import org.openecomp.sdc.asdctool.main.ArtifactUUIDFixMenu;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index ff0f847..5c7d78e 100644 (file)
@@ -92,7 +92,7 @@ public class Utils {
                                        }
                                }
 
-                               if (false == leftValue.equals(rightValue)) {
+                               if (!leftValue.equals(rightValue)) {
                                        log.trace("The value of key {} is differnet between properties. {} vs {}",key,leftValue,rightValue);
                                        return false;
                                }
@@ -105,7 +105,7 @@ public class Utils {
 
        public static void setProperties(Element element, Map<String, Object> properties) {
 
-               if (properties != null && false == properties.isEmpty()) {
+               if (properties != null && !properties.isEmpty()) {
 
                        Object[] propertyKeyValues = new Object[properties.size() * 2];
                        int i = 0;
index c935265..8c70435 100644 (file)
@@ -63,7 +63,13 @@ import java.util.stream.Collectors;
 
 @org.springframework.stereotype.Component("artifactUuidFix")
 public class ArtifactUuidFix {
+       
+       private static final String MIGRATION1707_ARTIFACT_UUID_FIX = "Migration1707ArtifactUuidFix  fix group:  group name {} correct artifactId {} artifactUUID {} ";
+
+    private static final String FAILED_TO_FETCH_VF_RESOURCES = "Failed to fetch vf resources ";
 
+    private static final String UTF8 = "utf-8";
+       
        @Autowired
        private TitanDao titanDao;
 
@@ -102,7 +108,7 @@ public class ArtifactUuidFix {
                }
                if ("service_vf".equals(runMode) || "fix".equals(runMode)) {
                        log.info("Mode {}. Find problem VFs", runMode);
-                       if (fetchVf(serviceList, vfLst, time) == false) {
+                       if (!fetchVf(serviceList, vfLst, time)) {
                                log.info("Mode {}. Find problem VFs finished with failure", runMode);
                                return false;
                        }
@@ -110,7 +116,7 @@ public class ArtifactUuidFix {
                }
                if ("fix".equals(runMode) || "fix_only_services".equals(runMode)) {
                        log.info("Mode {}. Start fix", runMode);
-                       if (fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca) == false) {
+                       if (!fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca)) {
                                log.info("Mode {}. Fix finished with failure", runMode);
                                return false;
                        }
@@ -123,7 +129,7 @@ public class ArtifactUuidFix {
        private boolean fetchFaultVf(String fixComponent, List<Resource> vfLst, long time) {
                log.info("Find fault VF ");
                String fileName = "fault_" + time + ".csv";
-               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
                        writer.write("vf name, vf id, state, version\n");
 
                        Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
@@ -180,7 +186,7 @@ public class ArtifactUuidFix {
                        }
 
                } catch (Exception e) {
-                       log.info("Failed to fetch vf resources ", e);
+                       log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
                        return false;
                } finally {
                        titanDao.commit();
@@ -195,7 +201,7 @@ public class ArtifactUuidFix {
                        return true;
                }
                String fileName = "problemVf_" + time + ".csv";
-               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
                        writer.write("vf name, vf id, state, version, example service name\n");
                        Set<String> vfIds = new HashSet<>();
                        for (Service service : serviceList) {
@@ -239,7 +245,7 @@ public class ArtifactUuidFix {
        private boolean fetchServices(String fixServices, List<Service> serviceList, long time) {
                log.info("Find problem Services {}", fixServices);
                String fileName = "problemService_" + time + ".csv";
-               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
                        writer.write("service name, service id, state, version\n");
 
                        Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
@@ -571,7 +577,7 @@ public class ArtifactUuidFix {
 
                long time = System.currentTimeMillis();
                String fileName = "FailedGenerateTosca" + "_" + time + ".csv";
-               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
                        writer.write("componentType, name, version, UID, UUID, invariantUUID, state\n");
                        List<Component> failedList = new ArrayList<>();
 
@@ -899,7 +905,7 @@ public class ArtifactUuidFix {
                                }
                                if (isAddToGroup) {
                                        log.debug(
-                                                       "Migration1707ArtifactUuidFix  fix group:  group name {} correct artifactId {} artifactUUID {} ",
+                                                       MIGRATION1707_ARTIFACT_UUID_FIX,
                                                        group.getName(), correctArtifactId, correctArtifactUUID);
                                        group.getArtifacts().add(correctArtifactId);
                                        if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
@@ -908,7 +914,7 @@ public class ArtifactUuidFix {
                                }
                        } else {
                                log.debug(
-                                               "Migration1707ArtifactUuidFix  fix group:  group name {} correct artifactId {} artifactUUID {} ",
+                                               MIGRATION1707_ARTIFACT_UUID_FIX,
                                                group.getName(), correctArtifactId, correctArtifactUUID);                               
                                Set<String> tmpSet = new HashSet<>(group.getGroupInstanceArtifacts());
                                tmpSet.add(correctArtifactId);
@@ -987,7 +993,7 @@ public class ArtifactUuidFix {
                        }
                        if (isAddToGroup) {
                                log.debug(
-                                               "Migration1707ArtifactUuidFix  fix group:  group name {} correct artifactId {} artifactUUID {} ",
+                                               MIGRATION1707_ARTIFACT_UUID_FIX,
                                                group.getName(), correctArtifactId, correctArtifactUUID);
                                group.getArtifacts().add(correctArtifactId);
                                if (correctArtifactUUID != null && !correctArtifactUUID.isEmpty()) {
@@ -1106,7 +1112,7 @@ public class ArtifactUuidFix {
                        });
 
                } catch (Exception e) {
-                       log.info("Failed to fetch vf resources ", e);
+                       log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
 
                } finally {
                        titanDao.commit();
@@ -1120,7 +1126,7 @@ public class ArtifactUuidFix {
                boolean result = true;
                long time = System.currentTimeMillis();
                String fileName = name + "_" + time + ".csv";
-               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+               try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF8))) {
                        writer.write("name, UUID, invariantUUID, state, version\n");
                        for (Map.Entry<String, List<Component>> entry : vertices.entrySet()) {
                                List<Component> compList = entry.getValue();
@@ -1165,7 +1171,7 @@ public class ArtifactUuidFix {
                        }
 
                } catch (Exception e) {
-                       log.info("Failed to fetch vf resources ", e);
+                       log.info(FAILED_TO_FETCH_VF_RESOURCES, e);
                        return false;
                } finally {
                        titanDao.commit();
index fddcab1..4842163 100644 (file)
@@ -131,11 +131,8 @@ public class DataMigration {
                                }
                        }
                }
-               if (importToCassandra && !importToCassndra(files)) {
-                       return false;
-               }
 
-               return true;
+               return !importToCassandra || importToCassndra(files);
        }
 
        private boolean initEsClient() {
index 2804a72..d43b3b8 100644 (file)
@@ -57,7 +57,23 @@ import java.util.Map.Entry;
 
 public class GraphMLConverter {
 
-       private static Logger log = Logger.getLogger(GraphMLConverter.class.getName());
+       private static final String FROM_VERTEX = "fromVertex={}";
+
+    private static final String STORAGE_BACKEND = "storage.backend";
+
+    private static final String INMEMORY = "inmemory";
+
+    private static final String CLOSE_FILE_OUTPUT_STREAM_FAILED = "close FileOutputStream failed - {}";
+
+    private static final String EXPORT_GRAPH = "exportGraph.";
+
+    private static final String DOT_JSON = ".json";
+
+    private static final String EXPORTED_FILE = "Exported file=";
+
+    private static final String NODE_LABEL = "nodeLabel";
+
+    private static Logger log = Logger.getLogger(GraphMLConverter.class.getName());
 
        private Gson gson = new Gson();
 
@@ -71,10 +87,10 @@ public class GraphMLConverter {
 
                        List<ImmutablePair<String, String>> propertiesCriteriaToDelete = new ArrayList<>();
                        ImmutablePair<String, String> immutablePair1 = new ImmutablePair<>("healthcheckis", "GOOD");
-                       ImmutablePair<String, String> immutablePair2 = new ImmutablePair<>("nodeLabel", "user");
-                       ImmutablePair<String, String> immutablePair3 = new ImmutablePair<>("nodeLabel",
+                       ImmutablePair<String, String> immutablePair2 = new ImmutablePair<>(NODE_LABEL, "user");
+                       ImmutablePair<String, String> immutablePair3 = new ImmutablePair<>(NODE_LABEL,
                                        "resourceCategory");
-                       ImmutablePair<String, String> immutablePair4 = new ImmutablePair<>("nodeLabel",
+                       ImmutablePair<String, String> immutablePair4 = new ImmutablePair<>(NODE_LABEL,
                                        "serviceCategory");
 
                        propertiesCriteriaToDelete.add(immutablePair1);
@@ -109,7 +125,7 @@ public class GraphMLConverter {
                                return false;
                        }
 
-                       System.out.println("Exported file=" + result);
+                       System.out.println(EXPORTED_FILE + result);
                } catch (Exception e) {
                        log.info("export graph failed -{}" , e);
                        return false;
@@ -133,7 +149,7 @@ public class GraphMLConverter {
 
                        result = exportGraphMl(graph, outputDirectory);
 
-                       System.out.println("Exported file=" + result);
+                       System.out.println(EXPORTED_FILE + result);
                } catch (Exception e) {
                        log.info("export exportGraphMl failed - {}" , e);
                        return null;
@@ -160,7 +176,7 @@ public class GraphMLConverter {
                                return false;
                        }
 
-                       System.out.println("Exported file=" + result);
+                       System.out.println(EXPORTED_FILE + result);
                } catch (Exception e) {
                        log.info("find Error In Json Graph failed - {}" , e);
                        return false;
@@ -183,7 +199,7 @@ public class GraphMLConverter {
 
                String result = null;
 
-               String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".json";
+               String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + DOT_JSON;
 
                OutputStream out = null;
                try {
@@ -208,7 +224,7 @@ public class GraphMLConverter {
                                        out.close();
                                }
                        } catch (IOException e) {
-                               log.info("close FileOutputStream failed - {}" , e);
+                               log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
                        }
                }
                return result;
@@ -217,7 +233,7 @@ public class GraphMLConverter {
 
        public String exportGraphMl(TitanGraph graph, String outputDirectory) {
                String result = null;
-               String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml";
+               String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + ".graphml";
                try {
                        try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(outputFile))) {
                                graph.io(IoCore.graphml()).writer().normalize(true).create().writeGraph(os, graph);
@@ -288,7 +304,7 @@ public class GraphMLConverter {
                                        is.close();
                                }
                        } catch (IOException e) {
-                               log.info("close FileOutputStream failed - {}" , e);
+                               log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
                        }
                }
 
@@ -303,7 +319,7 @@ public class GraphMLConverter {
 
                String result = null;
 
-               String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".json";
+               String outputFile = outputDirectory + File.separator + EXPORT_GRAPH + System.currentTimeMillis() + DOT_JSON;
 
                OutputStream out = null;
                try {
@@ -327,7 +343,7 @@ public class GraphMLConverter {
                                                vertexTo = edge.inVertex();
 
                                                BaseConfiguration conf = new BaseConfiguration();
-                                               conf.setProperty("storage.backend", "inmemory");
+                                               conf.setProperty(STORAGE_BACKEND, INMEMORY);
                                                TitanGraph openGraph = Utils.openGraph(conf);
 
                                                TitanVertex addVertexFrom = openGraph.addVertex();
@@ -339,7 +355,7 @@ public class GraphMLConverter {
                                                Edge addEdge = addVertexFrom.addEdge(edge.label(), addVertexTo);
                                                Utils.setProperties(addEdge, Utils.getProperties(edge));
 
-                                               log.info("fromVertex={}", Utils.getProperties(vertexFrom));
+                                               log.info(FROM_VERTEX, Utils.getProperties(vertexFrom));
                                                log.info("toVertex={}", Utils.getProperties(vertexTo));
                                                log.info("edge={} {} ",edge.label(),Utils.getProperties(edge));
 
@@ -351,7 +367,7 @@ public class GraphMLConverter {
                                        } catch (Exception e) {
                                                log.info("run Edge Scan failed - {}" , e);
 
-                                               log.error("fromVertex={}", Utils.getProperties(vertexFrom));
+                                               log.error(FROM_VERTEX, Utils.getProperties(vertexFrom));
                                                log.error("toVertex={}", Utils.getProperties(vertexTo));
                                                log.error("edge={} {} ",edge.label(),Utils.getProperties(edge));
 
@@ -377,13 +393,13 @@ public class GraphMLConverter {
                                                if (!iterator2.hasNext()) {
 
                                                        BaseConfiguration conf = new BaseConfiguration();
-                                                       conf.setProperty("storage.backend", "inmemory");
+                                                       conf.setProperty(STORAGE_BACKEND, INMEMORY);
                                                        TitanGraph openGraph = Utils.openGraph(conf);
 
                                                        TitanVertex addVertexFrom = openGraph.addVertex();
                                                        Utils.setProperties(addVertexFrom, Utils.getProperties(vertex));
 
-                                                       log.info("fromVertex={}", Utils.getProperties(addVertexFrom));
+                                                       log.info(FROM_VERTEX, Utils.getProperties(addVertexFrom));
 
                                                        GraphSONWriter create = GraphSONWriter.build().create();
                                                        create.writeGraph(out, openGraph);
@@ -415,7 +431,7 @@ public class GraphMLConverter {
                        ;
 
                        BaseConfiguration conf = new BaseConfiguration();
-                       conf.setProperty("storage.backend", "inmemory");
+                       conf.setProperty(STORAGE_BACKEND, INMEMORY);
                        for (NodeTypeEnum nodeTypeEnum : NodeTypeEnum.values()) {
                                removeNodesByLabel(graph, nodeTypeEnum.getName());
                        }
@@ -435,7 +451,7 @@ public class GraphMLConverter {
                                        out.close();
                                }
                        } catch (IOException e) {
-                               log.info("close FileOutputStream failed - {}" , e);
+                               log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
                        }
                }
                return result;
@@ -457,7 +473,7 @@ public class GraphMLConverter {
                List<Map<String, Object>> users = new ArrayList<>();
                String result = null;
 
-               String outputFile = outputDirectory + File.separator + "users." + System.currentTimeMillis() + ".json";
+               String outputFile = outputDirectory + File.separator + "users." + System.currentTimeMillis() + DOT_JSON;
 
                FileWriter fileWriter = null;
                try {
@@ -494,7 +510,7 @@ public class GraphMLConverter {
                                        fileWriter.close();
                                }
                        } catch (IOException e) {
-                               log.info("close FileOutputStream failed - {}" , e);
+                               log.info(CLOSE_FILE_OUTPUT_STREAM_FAILED , e);
                        }
                }
                return result;
@@ -534,7 +550,7 @@ public class GraphMLConverter {
                                return false;
                        }
 
-                       System.out.println("Exported file=" + result);
+                       System.out.println(EXPORTED_FILE + result);
                } catch (Exception e) {
                        log.info("export Users failed - {}" , e);
                        return false;
index e533c31..2aed83c 100644 (file)
@@ -65,7 +65,7 @@ public class GraphMLDataAnalyzer {
                // Parse ML file
                SAXBuilder builder = new SAXBuilder();
                File xmlFile = new File(mlFileLocation);
-               Document document = (Document) builder.build(xmlFile);
+               Document document = builder.build(xmlFile);
                
                // XLS data file name
                String outputFile = mlFileLocation.replace(".graphml", ".xls");
index 40fd6fb..de23c69 100644 (file)
@@ -88,10 +88,8 @@ public class ProductLogic {
 
        private TitanGraph openGraph(String titanFileLocation) {
 
-               TitanGraph graph = TitanFactory.open(titanFileLocation);
-
-               return graph;
-
+               return TitanFactory.open(titanFileLocation);
+               
        }
 
 }
index a886367..6a35da1 100644 (file)
@@ -32,7 +32,7 @@ import java.util.Properties;
  */
 public class RestUtils {
 
-       final static String DELETE_PRODUCT = "http://%s:%s/sdc2/rest/v1/catalog/products/%s";
+    static final String DELETE_PRODUCT = "http://%s:%s/sdc2/rest/v1/catalog/products/%s";
 
        private static Logger log = Logger.getLogger(RestUtils.class.getName());