From 18d11cb6cbd15196d077d5b27af0d7fdfca42730 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 4 Feb 2021 17:26:37 +0100 Subject: [PATCH] sonar fix - improving logging - throwing more specific excpetions - using "Optional" improvement Issue-ID: SO-3428 Signed-off-by: Lukasz Muszkieta Change-Id: I873ad4b557265778e7dc0321a1e39439cfa77155 --- .../workflow/tasks/WorkflowAction.java | 30 ++++++++-------------- .../VnfcMultipleRelationshipException.java | 28 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/excpetion/VnfcMultipleRelationshipException.java diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 4be497c469..f5955d6c7d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -46,10 +46,10 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException; import org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; -import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; @@ -490,7 +490,7 @@ public class WorkflowAction { AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId)); AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); Optional relationshipsOp = vfModuleResultsWrapper.getRelationships(); - if (!relationshipsOp.isPresent()) { + if (relationshipsOp.isEmpty()) { logger.debug("No relationships were found for vfModule in AAI"); } else { Relationships relationships = relationshipsOp.get(); @@ -503,21 +503,20 @@ public class WorkflowAction { return vnfcs; } - protected T getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectName name) throws Exception { + protected T getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectName name) + throws VnfcMultipleRelationshipException { T configuration = null; AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfc.getVnfcName())); AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); Optional relationshipsOp = vnfcResultsWrapper.getRelationships(); - if (!relationshipsOp.isPresent()) { + if (relationshipsOp.isEmpty()) { logger.debug("No relationships were found for VNFC in AAI"); } else { Relationships relationships = relationshipsOp.get(); List configurationResultWrappers = this.getResultWrappersFromRelationships(relationships, name); if (configurationResultWrappers.size() > 1) { - String multipleRelationshipsError = - "Multiple relationships exist from VNFC " + vnfc.getVnfcName() + " to Configurations"; - throw new Exception(multipleRelationshipsError); + throw new VnfcMultipleRelationshipException(vnfc.getVnfcName()); } if (!configurationResultWrappers.isEmpty()) { Optional configurationOp = configurationResultWrappers.get(0).asBean(resultClass); @@ -544,7 +543,7 @@ public class WorkflowAction { } protected List getConfigBuildingBlocks(ConfigBuildingBlocksDataObject dataObj) - throws Exception { + throws AAIEntityNotFoundException, VnfcMultipleRelationshipException { List flowsToExecuteConfigs = new ArrayList<>(); List result = dataObj.getOrchFlows().stream() @@ -658,7 +657,7 @@ public class WorkflowAction { if (volumeGroupFromVfModule.isPresent()) { String volumeGroupId = volumeGroupFromVfModule.get().getVolumeGroupId(); volumeGroupName = volumeGroupFromVfModule.get().getVolumeGroupName(); - logger.debug("Volume group id of the existing volume group is: " + volumeGroupId); + logger.debug("Volume group id of the existing volume group is: {}", volumeGroupId); volumeGroupExisted = true; dataObj.getWorkflowResourceIds().setVolumeGroupId(volumeGroupId); dataObj.getReplaceInformation().setOldVolumeGroupName(volumeGroupName); @@ -675,7 +674,7 @@ public class WorkflowAction { String newVolumeGroupId = UUID.randomUUID().toString(); dataObj.getWorkflowResourceIds().setVolumeGroupId(newVolumeGroupId); dataObj.getReplaceInformation().setOldVolumeGroupName(volumeGroupName); - logger.debug("newVolumeGroupId: " + newVolumeGroupId); + logger.debug("newVolumeGroupId: {}", newVolumeGroupId); } } @@ -702,7 +701,7 @@ public class WorkflowAction { private void updateResourceIdsFromAAITraversal(List flowsToExecute, List resourceList, List> aaiResourceIds, String serviceInstanceId) { for (Pair pair : aaiResourceIds) { - logger.debug(pair.getValue0() + ", " + pair.getValue1()); + logger.debug("{}, {}", pair.getValue0(), pair.getValue1()); } Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) @@ -1324,15 +1323,6 @@ public class WorkflowAction { return sortedOrchFlows; } - private ConfigurationResourceKeys getConfigurationResourceKeys(Resource resource, String vnfcName) { - ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys(); - Optional.ofNullable(vnfcName).ifPresent(configurationResourceKeys::setVnfcName); - configurationResourceKeys.setCvnfcCustomizationUUID(resource.getCvnfModuleCustomizationId()); - configurationResourceKeys.setVfModuleCustomizationUUID(resource.getVfModuleCustomizationId()); - configurationResourceKeys.setVnfResourceCustomizationUUID(resource.getVnfCustomizationId()); - return configurationResourceKeys; - } - protected List queryNorthBoundRequestCatalogDb(DelegateExecution execution, String requestAction, WorkflowType resourceName, boolean aLaCarte, String cloudOwner) { return this.queryNorthBoundRequestCatalogDb(execution, requestAction, resourceName, aLaCarte, cloudOwner, ""); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/excpetion/VnfcMultipleRelationshipException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/excpetion/VnfcMultipleRelationshipException.java new file mode 100644 index 0000000000..8ef00655f2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/excpetion/VnfcMultipleRelationshipException.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (c) 2021 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion; + +public class VnfcMultipleRelationshipException extends Exception { + + public VnfcMultipleRelationshipException(String vnfcName) { + super("Multiple relationships exist from VNFC " + vnfcName + " to Configurations"); + } +} -- 2.16.6