Refactor Code asdctool classes 10/73010/2
authorSindhuri.A <arcot.sindhuri@huawei.com>
Mon, 19 Nov 2018 10:31:50 +0000 (16:01 +0530)
committerSindhu A <arcot.sindhuri@huawei.com>
Mon, 19 Nov 2018 10:37:28 +0000 (10:37 +0000)
Code refactor : asdctool classes

Issue-ID: SDC-1880

Change-Id: I9a3bfb20441f7c5df25c6a61b77abcb8268a0d62
Signed-off-by: Sindhuri.A <arcot.sindhuri@huawei.com>
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java

index 9b45d93..c935265 100644 (file)
@@ -58,6 +58,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.EnumMap;
 import java.util.stream.Collectors;
 
 @org.springframework.stereotype.Component("artifactUuidFix")
@@ -90,16 +91,16 @@ public class ArtifactUuidFix {
 
                doFixTosca(nodeToFixTosca, vfToFixTosca, serviceToFixTosca);
 
-               if (fixComponent.equals("vf_only")) {
-                       if (fetchFaultVf(fixComponent, vfLst, time) == false) {
+               if ("vf_only".equals(fixComponent)) {
+                       if (!fetchFaultVf(fixComponent, vfLst, time)) {
                                return false;
                        }
                } else {
-                       if (fetchServices(fixComponent, serviceList, time) == false) {
+                       if (!fetchServices(fixComponent, serviceList, time)) {
                                return false;
                        }
                }
-               if (runMode.equals("service_vf") || runMode.equals("fix")) {
+               if ("service_vf".equals(runMode) || "fix".equals(runMode)) {
                        log.info("Mode {}. Find problem VFs", runMode);
                        if (fetchVf(serviceList, vfLst, time) == false) {
                                log.info("Mode {}. Find problem VFs finished with failure", runMode);
@@ -107,7 +108,7 @@ public class ArtifactUuidFix {
                        }
                        log.info("Mode {}. Find problem VFs finished with success", runMode);
                }
-               if (runMode.equals("fix") || runMode.equals("fix_only_services")) {
+               if ("fix".equals(runMode) || "fix_only_services".equals(runMode)) {
                        log.info("Mode {}. Start fix", runMode);
                        if (fix(vfLst, serviceList, nodeToFixTosca, vfToFixTosca, serviceToFixTosca) == false) {
                                log.info("Mode {}. Fix finished with failure", runMode);
@@ -125,11 +126,11 @@ public class ArtifactUuidFix {
                try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
                        writer.write("vf name, vf id, state, version\n");
 
-                       Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+                       Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
                        hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
                        hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name());
 
-                       Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
+                       Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
                        hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
                        log.info("Try to fetch resources with properties {} and not {}", hasProps, hasNotProps);
 
@@ -241,14 +242,14 @@ public class ArtifactUuidFix {
                try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
                        writer.write("service name, service id, state, version\n");
 
-                       Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+                       Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
                        hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
-                       if (fixServices.equals("distributed_only")) {
+                       if ("distributed_only".equals(fixServices)) {
                                hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());                     
                                hasProps.put(GraphPropertyEnum.DISTRIBUTION_STATUS, DistributionStatusEnum.DISTRIBUTED.name());
                        }
 
-                       Map<GraphPropertyEnum, Object> hasNotProps = new HashMap<>();
+                       Map<GraphPropertyEnum, Object> hasNotProps = new EnumMap<>(GraphPropertyEnum.class);
                        hasNotProps.put(GraphPropertyEnum.IS_DELETED, true);
                        log.info("Try to fetch services with properties {} and not {}", hasProps, hasNotProps);
 
@@ -378,7 +379,7 @@ public class ArtifactUuidFix {
                        log.info(" artifacts.size() < artifactsUuid.size() group {} in resource {} ", gr.getName(), resourceName);
                        return true;
                }
-               if (artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty())) {
+               if (!artifacts.isEmpty() && (artifactsUuid == null || artifactsUuid.isEmpty())) {
                        log.info(
                                        " artifacts.size() > 0 && (artifactsUuid == null || artifactsUuid.isEmpty() group {} in resource {} ",
                                        gr.getName(), resourceName);
@@ -511,7 +512,7 @@ public class ArtifactUuidFix {
                }
                for (String artifactUUID : artifactsUuid) {
                        String label = findArtifactLabelFromArtifactId(artifactUUID);
-                       if (label != null && !label.isEmpty() && !label.equals("")) {
+                       if (label != null && !label.isEmpty() && !"".equals(label)) {
                                return true;
                        }
                }
@@ -817,15 +818,15 @@ public class ArtifactUuidFix {
 
                        Optional<ArtifactDefinition> optionalVfModuleArtifact = artifactsMap.values().stream()
                                        .filter(p -> p.getArtifactType().equals(ArtifactTypeEnum.VF_MODULES_METADATA.name())).findAny();
-                       ArtifactDefinition vfModuleAertifact = null;
+                       ArtifactDefinition vfModuleArtifact;
                        if(!optionalVfModuleArtifact.isPresent()){
-                               vfModuleAertifact = createVfModuleArtifact(instance, service);
-                               artifactsMap.put(vfModuleAertifact.getArtifactLabel(), vfModuleAertifact);
+                               vfModuleArtifact = createVfModuleArtifact(instance, service);
+                               artifactsMap.put(vfModuleArtifact.getArtifactLabel(), vfModuleArtifact);
                        }
                        else {
-                               vfModuleAertifact = optionalVfModuleArtifact.get();                             
+                               vfModuleArtifact = optionalVfModuleArtifact.get();
                        }
-                       fillVfModuleInstHeatEnvPayload(service, instance, groupsList, vfModuleAertifact);
+                       fillVfModuleInstHeatEnvPayload(service, instance, groupsList, vfModuleArtifact);
                }
        }
 
@@ -1043,7 +1044,7 @@ public class ArtifactUuidFix {
        public boolean doFixTosca(Map<String, List<Component>> nodeToFix, Map<String, List<Component>> vfToFix,
                        Map<String, List<Component>> serviceToFix) {
 
-               Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+               Map<GraphPropertyEnum, Object> hasProps = new EnumMap<>(GraphPropertyEnum.class);
                hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
                hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
 
@@ -1084,7 +1085,7 @@ public class ArtifactUuidFix {
                        componentsList.forEach(vertex -> {
                                String ivariantUuid = (String) vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
                                if (!result.containsKey(ivariantUuid)) {
-                                       List<Component> compList = new ArrayList<Component>();
+                                       List<Component> compList = new ArrayList<>();
                                        result.put(ivariantUuid, compList);
                                }
                                List<Component> compList = result.get(ivariantUuid);
@@ -1149,8 +1150,8 @@ public class ArtifactUuidFix {
                                                Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
                                                                .getToscaElement(c.getUniqueId(), filter);
                                                if (toscaElement.isRight()) {
-                                                       System.out.println("getVerticesToValidate: failed to find element" + c.getUniqueId()
-                                                                       + " staus is" + toscaElement.right().value());
+                                                       log.debug("getVerticesToValidate: failed to find element" + c.getUniqueId()
+                                                                       + " status is" + toscaElement.right().value());
                                                } else {
                                                        compListfull.add(toscaElement.left().value());
                                                }
@@ -1258,7 +1259,6 @@ public class ArtifactUuidFix {
           private ArtifactDefinition createVfModuleArtifact(ComponentInstance currVF, Service service) {
 
                ArtifactDefinition vfModuleArtifactDefinition = new ArtifactDefinition();
-               String newCheckSum = null;
 
                vfModuleArtifactDefinition.setDescription("Auto-generated VF Modules information artifact");
                vfModuleArtifactDefinition.setArtifactDisplayName("Vf Modules Metadata");
index bcb6a0a..2804a72 100644 (file)
@@ -70,11 +70,11 @@ public class GraphMLConverter {
                        graph = openGraph(titanFileLocation);
 
                        List<ImmutablePair<String, String>> propertiesCriteriaToDelete = new ArrayList<>();
-                       ImmutablePair<String, String> immutablePair1 = new ImmutablePair<String, String>("healthcheckis", "GOOD");
-                       ImmutablePair<String, String> immutablePair2 = new ImmutablePair<String, String>("nodeLabel", "user");
-                       ImmutablePair<String, String> immutablePair3 = new ImmutablePair<String, String>("nodeLabel",
+                       ImmutablePair<String, String> immutablePair1 = new ImmutablePair<>("healthcheckis", "GOOD");
+                       ImmutablePair<String, String> immutablePair2 = new ImmutablePair<>("nodeLabel", "user");
+                       ImmutablePair<String, String> immutablePair3 = new ImmutablePair<>("nodeLabel",
                                        "resourceCategory");
-                       ImmutablePair<String, String> immutablePair4 = new ImmutablePair<String, String>("nodeLabel",
+                       ImmutablePair<String, String> immutablePair4 = new ImmutablePair<>("nodeLabel",
                                        "serviceCategory");
 
                        propertiesCriteriaToDelete.add(immutablePair1);
@@ -82,16 +82,13 @@ public class GraphMLConverter {
                        propertiesCriteriaToDelete.add(immutablePair3);
                        propertiesCriteriaToDelete.add(immutablePair4);
 
-                       boolean result = importJsonGraph(graph, inputFile, propertiesCriteriaToDelete);
-
-                       return result;
+                       return importJsonGraph(graph, inputFile, propertiesCriteriaToDelete);
 
                } catch (Exception e) {
                        log.info("import graph failed - {} " , e);
                        return false;
                } finally {
                        if (graph != null) {
-                               // graph.shutdown();
                                graph.close();
                        }
                }
@@ -118,7 +115,6 @@ public class GraphMLConverter {
                        return false;
                } finally {
                        if (graph != null) {
-                               // graph.shutdown();
                                graph.close();
                        }
                }
@@ -179,9 +175,7 @@ public class GraphMLConverter {
 
        public TitanGraph openGraph(String titanFileLocation) {
 
-               TitanGraph graph = TitanFactory.open(titanFileLocation);
-
-               return graph;
+               return TitanFactory.open(titanFileLocation);
 
        }
 
@@ -269,7 +263,7 @@ public class GraphMLConverter {
                                }
                        }
                        File file = new File(graphJsonFile);
-                       if (false == file.isFile()) {
+                       if (!file.isFile()) {
                                System.out.println("File " + graphJsonFile + " cannot be found.");
                                return result;
                        }
@@ -287,7 +281,6 @@ public class GraphMLConverter {
                } catch (Exception e) {
                        System.out.println("Failed to import graph " + e.getMessage());
                        log.info("Failed to import graph - {}" , e);
-                       // graph.rollback();
                        graph.tx().rollback();
                } finally {
                        try {
@@ -381,7 +374,7 @@ public class GraphMLConverter {
 
                                                vertex = iteratorVertex.next();
                                                Iterator<Edge> iterator2 = vertex.edges(Direction.BOTH);
-                                               if (false == iterator2.hasNext()) {
+                                               if (!iterator2.hasNext()) {
 
                                                        BaseConfiguration conf = new BaseConfiguration();
                                                        conf.setProperty("storage.backend", "inmemory");
@@ -510,10 +503,10 @@ public class GraphMLConverter {
 
        public Map<String, Object> getProperties(Element element) {
 
-               Map<String, Object> result = new HashMap<String, Object>();
+               Map<String, Object> result = new HashMap<>();
                ;
 
-               if (element.keys() != null && element.keys().size() > 0) {
+               if (element.keys() != null && !element.keys().isEmpty()) {
                        Map<String, Property> propertyMap = ElementHelper.propertyMap(element,
                                        element.keys().toArray(new String[element.keys().size()]));