From f91d16b1e729c139f281919015e6566705582bc4 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Fri, 24 Jul 2020 14:10:11 -0400 Subject: Execute building block uses wrong config id Fixed issue where execute building block has the wrong config id Add and updated unit test and made improvements to WorkflowAction Removed method that is no longer used by wfa Fixed compilatoon error for build failure, exception being thrown Need to check if list is empty and return null if it is Issue-ID: SO-3098 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I0cf811a1070237bcb463f2f3949f56eebbe41b6b --- .../workflow/tasks/WorkflowAction.java | 81 +++++++++------------- .../workflow/tasks/WorkflowActionBBTasks.java | 7 +- 2 files changed, 35 insertions(+), 53 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src/main/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 1a49e3af7f..6f11882281 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 @@ -37,6 +37,7 @@ import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.apache.commons.lang3.SerializationUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; import org.onap.aai.domain.yang.GenericVnf; @@ -460,9 +461,8 @@ public class WorkflowAction { return vnfcs; } - protected List getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectType type) { - - List configurations = new ArrayList<>(); + protected T getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectType type) throws Exception { + T configuration = null; AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfc.getVnfcName()); AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); Optional relationshipsOp = vnfcResultsWrapper.getRelationships(); @@ -472,12 +472,19 @@ public class WorkflowAction { Relationships relationships = relationshipsOp.get(); List configurationResultWrappers = this.getResultWrappersFromRelationships(relationships, type); - for (AAIResultWrapper configurationResultWrapper : configurationResultWrappers) { - Optional configurationOp = configurationResultWrapper.asBean(resultClass); - configurationOp.ifPresent(configurations::add); + if (configurationResultWrappers.size() > 1) { + String multipleRelationshipsError = + "Multiple relationships exist from VNFC " + vnfc.getVnfcName() + " to Configurations"; + throw new Exception(multipleRelationshipsError); + } + if (!configurationResultWrappers.isEmpty()) { + Optional configurationOp = configurationResultWrappers.get(0).asBean(resultClass); + if (configurationOp.isPresent()) { + configuration = configurationOp.get(); + } } } - return configurations; + return configuration; } protected List getResultWrappersFromRelationships(Relationships relationships, @@ -519,33 +526,26 @@ public class WorkflowAction { List vnfcs = getRelatedResourcesInVfModule(vnfId, vfModuleId, org.onap.aai.domain.yang.Vnfc.class, AAIObjectType.VNFC); for (org.onap.aai.domain.yang.Vnfc vnfc : vnfcs) { - List configurations = getRelatedResourcesInVnfc(vnfc, + WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds()); + org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION); - if (configurations.size() > 1) { - String multipleRelationshipsError = - "Multiple relationships exist from VNFC " + vnfc.getVnfcName() + " to Configurations"; - buildAndThrowException(dataObj.getExecution(), "Exception in getConfigBuildingBlock: ", - new Exception(multipleRelationshipsError)); - } - for (org.onap.aai.domain.yang.Configuration configuration : configurations) { - dataObj.getWorkflowResourceIds().setConfigurationId(configuration.getConfigurationId()); - for (OrchestrationFlow orchFlow : result) { - dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); - dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId()); - dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID); - String vnfcName = getVnfcNameForConfiguration(configuration); - if (vnfcName == null || vnfcName.isEmpty()) { - buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " - + ": VnfcName does not exist or is null while there is a configuration for the vfModule", - new Exception("Vnfc and Configuration do not match")); - } - ExecuteBuildingBlock ebb = - buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), dataObj.getResourceKey(), - dataObj.getApiVersion(), dataObj.getResourceId(), dataObj.getRequestAction(), - dataObj.isaLaCarte(), dataObj.getVnfType(), dataObj.getWorkflowResourceIds(), - dataObj.getRequestDetails(), false, null, vnfcName, true, null); - flowsToExecuteConfigs.add(ebb); + workflowIdsCopy.setConfigurationId(configuration.getConfigurationId()); + for (OrchestrationFlow orchFlow : result) { + dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID); + dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId()); + dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID); + String vnfcName = vnfc.getVnfcName(); + if (vnfcName == null || vnfcName.isEmpty()) { + buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " + + ": VnfcName does not exist or is null while there is a configuration for the vfModule", + new Exception("Vnfc and Configuration do not match")); } + ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), + dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(), + dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, + dataObj.getRequestDetails(), false, null, vnfcName, true, null); + flowsToExecuteConfigs.add(ebb); + } } return flowsToExecuteConfigs; @@ -613,23 +613,6 @@ public class WorkflowAction { return orchFlows; } - protected String getVnfcNameForConfiguration(org.onap.aai.domain.yang.Configuration configuration) { - AAIResultWrapper wrapper = new AAIResultWrapper(configuration); - Optional relationshipsOp = wrapper.getRelationships(); - if (!relationshipsOp.isPresent()) { - logger.debug("No relationships were found for Configuration in AAI"); - return null; - } - Relationships relationships = relationshipsOp.get(); - List vnfcResultWrappers = relationships.getByType(AAIObjectType.VNFC); - if (vnfcResultWrappers.size() != 1) { - logger.debug("Too many vnfcs or no vnfc found that are related to configuration"); - } - Optional vnfcOp = vnfcResultWrappers.get(0).asBean(Vnfc.class); - return vnfcOp.map(Vnfc::getVnfcName).orElse(null); - - } - protected List sortVfModulesByBaseFirst(List vfModuleResources) { int count = 0; for (Resource resource : vfModuleResources) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index 155011ece0..7420df144a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -459,11 +459,10 @@ public class WorkflowActionBBTasks { } } - protected String getConfigurationId(Vnfc vnfc) { - List configurations = + protected String getConfigurationId(Vnfc vnfc) throws Exception { + Configuration configuration = workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, AAIObjectType.CONFIGURATION); - if (!configurations.isEmpty()) { - Configuration configuration = configurations.get(0); + if (configuration != null) { return configuration.getConfigurationId(); } else { return UUID.randomUUID().toString(); -- cgit 1.2.3-korg