From 464775cb4d3e2eb14b25ebba627cae1b81de62ac Mon Sep 17 00:00:00 2001 From: "r.bogacki" Date: Tue, 4 Jun 2019 13:02:46 +0200 Subject: Improvements in ToscaResourceInstaller Improvements in ToscaResourceInstaller according to the Sonar analyses. -Removed unnecessary imports. -Removed unnecessary exceptions. -Improvements for an array size checking. -Refactored diamond operators for a simplicity. Issue-ID: SO-1984 Signed-off-by: Robert Bogacki Change-Id: I498933adadbb2d6f5dc956b0056c728f141e3869 --- .../installer/heat/ToscaResourceInstaller.java | 41 ++++++++++------------ 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 1daf81940b..f3f46e39d7 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -39,7 +39,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import com.google.common.base.Strings; -import org.hibernate.StaleObjectStateException; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.LockAcquisitionException; import org.onap.sdc.api.notification.IArtifactInfo; @@ -295,6 +294,7 @@ public class ToscaResourceInstaller { status = vfResourceStructure.isDeployedSuccessfully(); } catch (RuntimeException e) { status = false; + logger.debug("Exception :", e); } try { Service existingService = @@ -432,7 +432,6 @@ public class ToscaResourceInstaller { for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { Metadata metadata = nodeTemplate.getMetaData(); - String serviceType = toscaResourceStruct.getCatalogService().getServiceType(); String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper() .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY); processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, @@ -499,7 +498,7 @@ public class ToscaResourceInstaller { List getRequirementList(List resultList, List nodeTemplates, ISdcCsarHelper iSdcCsarHelper) { - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.addAll(nodeTemplates); for (NodeTemplate nodeTemplate : nodeTemplates) { @@ -530,12 +529,12 @@ public class ToscaResourceInstaller { // This method retrieve resource sequence from csar file void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) { - List resouceSequence = new ArrayList(); - List resultList = new ArrayList(); + List resouceSequence = new ArrayList<>(); + List resultList = new ArrayList<>(); ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); List nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates(); - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.addAll(nodeTemplates); for (NodeTemplate nodeTemplate : nodeTemplates) { @@ -724,9 +723,8 @@ public class ToscaResourceInstaller { List configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); - List serviceProxyList = new ArrayList(); - List configurationResourceList = - new ArrayList(); + List serviceProxyList = new ArrayList<>(); + List configurationResourceList = new ArrayList<>(); ServiceProxyResourceCustomization serviceProxy = null; @@ -979,8 +977,8 @@ public class ToscaResourceInstaller { VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service); - Set existingCvnfcSet = new HashSet(); - Set existingVnfcSet = new HashSet(); + Set existingCvnfcSet = new HashSet<>(); + Set existingVnfcSet = new HashSet<>(); for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { @@ -1112,7 +1110,7 @@ public class ToscaResourceInstaller { } } - if (tempGroupList.size() != 0 && tempGroupList.size() < groupList.size()) { + if (!tempGroupList.isEmpty() && tempGroupList.size() < groupList.size()) { getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper); } } @@ -1649,7 +1647,7 @@ public class ToscaResourceInstaller { List networkInstanceGroupList = new ArrayList<>(); List collectionResourceInstanceGroupCustomizationList = - new ArrayList(); + new ArrayList<>(); for (Group group : groupList) { @@ -1935,10 +1933,9 @@ public class ToscaResourceInstaller { // * Extract VFC's and CVFC's then add them to VFModule // ****************************************************************************************************************** - Set cvnfcConfigurationCustomizations = - new HashSet(); - Set cvnfcCustomizations = new HashSet(); - Set vnfcCustomizations = new HashSet(); + Set cvnfcConfigurationCustomizations = new HashSet<>(); + Set cvnfcCustomizations = new HashSet<>(); + Set vnfcCustomizations = new HashSet<>(); // Only set the CVNFC if this vfModule group is a member of it. List groupMembers = @@ -2254,14 +2251,14 @@ public class ToscaResourceInstaller { if (matchingObject.isPresent()) { List heatFilesList = new ArrayList<>(); - List volumeHeatChildTemplates = new ArrayList(); - List heatChildTemplates = new ArrayList(); + List volumeHeatChildTemplates = new ArrayList<>(); + List heatChildTemplates = new ArrayList<>(); HeatTemplate parentHeatTemplate = new HeatTemplate(); String parentArtifactType = null; Set artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts()); for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - List childNestedHeatTemplates = new ArrayList(); + List childNestedHeatTemplates = new ArrayList<>(); if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) { checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact, @@ -2578,7 +2575,7 @@ public class ToscaResourceInstaller { if (object == null) { return null; - } else if (object.equals("NULL")) { + } else if ("NULL".equals(object)) { return null; } else if (object instanceof Integer) { return object.toString(); @@ -2650,7 +2647,7 @@ public class ToscaResourceInstaller { // existing customization available in db. private void addVnfCustomization(Service service, VnfResourceCustomization vnfResourceCustomization) { List services = serviceRepo.findByModelUUID(service.getModelUUID()); - if (services.size() > 0) { + if (!services.isEmpty()) { // service exist in db Service existingService = services.get(0); List vnfCustomizations = existingService.getVnfCustomizations(); -- cgit 1.2.3-korg