From 96f00e4e4e82f80958aa6f368e9b3ee9476d2885 Mon Sep 17 00:00:00 2001 From: "Sindhuri.A" Date: Mon, 19 Nov 2018 16:01:50 +0530 Subject: Refactor Code asdctool classes Code refactor : asdctool classes Issue-ID: SDC-1880 Change-Id: I9a3bfb20441f7c5df25c6a61b77abcb8268a0d62 Signed-off-by: Sindhuri.A --- .../sdc/asdctool/impl/ArtifactUuidFix.java | 44 +++++++++++----------- .../sdc/asdctool/impl/GraphMLConverter.java | 27 +++++-------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java index 9b45d93bc5..c935265ccc 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/ArtifactUuidFix.java @@ -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 hasProps = new HashMap<>(); + Map hasProps = new EnumMap<>(GraphPropertyEnum.class); hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF.name()); - Map hasNotProps = new HashMap<>(); + Map 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 hasProps = new HashMap<>(); + Map 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 hasNotProps = new HashMap<>(); + Map 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 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> nodeToFix, Map> vfToFix, Map> serviceToFix) { - Map hasProps = new HashMap<>(); + Map 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 compList = new ArrayList(); + List compList = new ArrayList<>(); result.put(ivariantUuid, compList); } List compList = result.get(ivariantUuid); @@ -1149,8 +1150,8 @@ public class ArtifactUuidFix { Either 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"); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java index bcb6a0a283..2804a728f0 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLConverter.java @@ -70,11 +70,11 @@ public class GraphMLConverter { graph = openGraph(titanFileLocation); List> propertiesCriteriaToDelete = new ArrayList<>(); - ImmutablePair immutablePair1 = new ImmutablePair("healthcheckis", "GOOD"); - ImmutablePair immutablePair2 = new ImmutablePair("nodeLabel", "user"); - ImmutablePair immutablePair3 = new ImmutablePair("nodeLabel", + ImmutablePair immutablePair1 = new ImmutablePair<>("healthcheckis", "GOOD"); + ImmutablePair immutablePair2 = new ImmutablePair<>("nodeLabel", "user"); + ImmutablePair immutablePair3 = new ImmutablePair<>("nodeLabel", "resourceCategory"); - ImmutablePair immutablePair4 = new ImmutablePair("nodeLabel", + ImmutablePair 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 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 getProperties(Element element) { - Map result = new HashMap(); + Map result = new HashMap<>(); ; - if (element.keys() != null && element.keys().size() > 0) { + if (element.keys() != null && !element.keys().isEmpty()) { Map propertyMap = ElementHelper.propertyMap(element, element.keys().toArray(new String[element.keys().size()])); -- cgit 1.2.3-korg