From bd2185fdf21bf2f7186649ed1d85b07fa499540c Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Mon, 8 Apr 2019 09:41:39 -0400 Subject: fix delete vfmodule corrected the vnfc customization id that is passed down add junit for getRelatedResourcesInVnfc method Change-Id: I943952a260191a49c8fc1c0813b1e111448f637b Issue-ID: SO-1759 Signed-off-by: Benjamin, Max (mb388a) --- .../workflow/tasks/WorkflowAction.java | 63 ++++++++++++++++------ 1 file changed, 48 insertions(+), 15 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 867be2ec95..7562bd964e 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 @@ -372,6 +372,31 @@ public class WorkflowAction { return vnfcs; } + protected List getRelatedResourcesInVnfc(Vnfc vnfc, Class resultClass, AAIObjectType type) { + + List configurations = new ArrayList<>(); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VNFC, vnfc.getVnfcName()); + AAIResultWrapper vnfcResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri); + Optional relationshipsOp = vnfcResultsWrapper.getRelationships(); + if (!relationshipsOp.isPresent()) { + logger.debug("No relationships were found for VNFC in AAI"); + } else { + Relationships relationships = relationshipsOp.get(); + List configurationResultWrappers = this.getResultWrappersFromRelationships(relationships, type); + for(AAIResultWrapper configurationResultWrapper : configurationResultWrappers) { + Optional configurationOp = configurationResultWrapper.asBean(resultClass); + if(configurationOp.isPresent()) { + configurations.add(configurationOp.get()); + } + } + } + return configurations; + } + + protected List getResultWrappersFromRelationships(Relationships relationships, AAIObjectType type){ + return relationships.getByType(type); + } + protected boolean isConfiguration(List orchFlows) { for(OrchestrationFlow flow : orchFlows) { if(flow.getFlowName().contains("Configuration")) { @@ -384,6 +409,7 @@ public class WorkflowAction { protected List getConfigBuildingBlocks(ServiceInstancesRequest sIRequest, List orchFlows, String requestId, Resource resourceKey, String apiVersion, String resourceId, String requestAction, boolean aLaCarte, String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, DelegateExecution execution) { + List flowsToExecuteConfigs = new ArrayList<>(); List result = new ArrayList<>(orchFlows); result = orchFlows.stream().filter(item -> item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList()); @@ -392,22 +418,29 @@ public class WorkflowAction { String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(); String vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId(); - List configurations = getRelatedResourcesInVfModule(vnfId, vfModuleId, org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION); - - for(org.onap.aai.domain.yang.Configuration configuration : configurations) { - workflowResourceIds.setConfigurationId(configuration.getConfigurationId()); - for(OrchestrationFlow orchFlow : result) { - resourceKey.setVfModuleCustomizationId(vfModuleCustomizationUUID); - resourceKey.setCvnfModuleCustomizationId(configuration.getModelCustomizationId()); - resourceKey.setVnfCustomizationId(vnfCustomizationUUID); - ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId, - requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true); - String vnfcName = getVnfcNameForConfiguration(configuration); - if(vnfcName == null || vnfcName.isEmpty()) { - buildAndThrowException(execution, "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")); + + 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, 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(execution, multipleRelationshipsError, new Exception(multipleRelationshipsError)); + } + for(org.onap.aai.domain.yang.Configuration configuration : configurations) { + workflowResourceIds.setConfigurationId(configuration.getConfigurationId()); + for(OrchestrationFlow orchFlow : result) { + resourceKey.setVfModuleCustomizationId(vfModuleCustomizationUUID); + resourceKey.setCvnfModuleCustomizationId(vnfc.getModelCustomizationId()); + resourceKey.setVnfCustomizationId(vnfCustomizationUUID); + ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, resourceId, + requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, null, true); + String vnfcName = getVnfcNameForConfiguration(configuration); + if(vnfcName == null || vnfcName.isEmpty()) { + buildAndThrowException(execution, "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")); + } + ebb.getConfigurationResourceKeys().setVnfcName(vnfcName); + flowsToExecuteConfigs.add(ebb); } - ebb.getConfigurationResourceKeys().setVnfcName(vnfcName); - flowsToExecuteConfigs.add(ebb); } } return flowsToExecuteConfigs; -- cgit 1.2.3-korg