From 066ab1ed4c58040fa8059a80d020c7dec5f89a19 Mon Sep 17 00:00:00 2001 From: pwielebs Date: Tue, 16 Mar 2021 14:33:46 +0100 Subject: SO refactor II - refactor VnfEBBLoader.java Issue-ID: SO-3581 Signed-off-by: pwielebs Change-Id: I1567a025e18ac4bf1f77ae4b2d7a499dfca0a4cc --- .../workflow/tasks/ebb/loader/VnfEBBLoader.java | 142 +++++++++++---------- 1 file changed, 74 insertions(+), 68 deletions(-) (limited to 'bpmn/so-bpmn-tasks') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java index 7db93e7979..210d5195e5 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java @@ -28,7 +28,6 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.javatuples.Pair; -import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; @@ -36,7 +35,10 @@ import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.exception.ExceptionBuilder; @@ -69,35 +71,12 @@ public class VnfEBBLoader { public void traverseAAIVnf(DelegateExecution execution, List resourceList, String serviceId, String vnfId, List> aaiResourceIds) { try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = - bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = + bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + ServiceInstance serviceInstanceMSO = bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); if (serviceInstanceMSO.getVnfs() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { - if (vnf.getVnfId().equals(vnfId)) { - aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); - resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false)); - if (vnf.getVfModules() != null) { - for (VfModule vfModule : vnf.getVfModules()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); - resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false)); - findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), - resourceList, aaiResourceIds); - } - } - if (vnf.getVolumeGroups() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf - .getVolumeGroups()) { - aaiResourceIds - .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); - resourceList.add( - new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); - } - } - break; - } - } + findVnfWithGivenId(serviceInstanceMSO, vnfId, aaiResourceIds, resourceList, execution); } } catch (Exception ex) { logger.error("Exception in traverseAAIVnf", ex); @@ -109,39 +88,13 @@ public class VnfEBBLoader { public void customTraverseAAIVnf(DelegateExecution execution, List resourceList, String serviceId, String vnfId, List> aaiResourceIds) { try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = - bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); + org.onap.aai.domain.yang.ServiceInstance serviceInstanceAAI = + bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + ServiceInstance serviceInstanceMSO = bbInputSetup.getExistingServiceInstance(serviceInstanceAAI); resourceList.add(new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false)); if (serviceInstanceMSO.getVnfs() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf : serviceInstanceMSO.getVnfs()) { - if (vnf.getVnfId().equals(vnfId)) { - aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); - - String vnfCustomizationUUID = - bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(); - resourceList.add(new Resource(WorkflowType.VNF, vnfCustomizationUUID, false)); - - if (vnf.getVfModules() != null) { - for (VfModule vfModule : vnf.getVfModules()) { - aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); - resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false)); - findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), - resourceList, aaiResourceIds); - } - } - if (vnf.getVolumeGroups() != null) { - for (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup : vnf - .getVolumeGroups()) { - aaiResourceIds - .add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); - resourceList.add( - new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); - } - } - break; - } - } + findVnfWithGivenIdAndAddCustomizationUUID(serviceInstanceMSO, vnfId, aaiResourceIds, resourceList, + execution); } } catch (Exception ex) { logger.error("Exception in customTraverseAAIVnf", ex); @@ -151,6 +104,33 @@ public class VnfEBBLoader { } + private void findVnfWithGivenId(ServiceInstance serviceInstanceMSO, String vnfId, + List> aaiResourceIds, List resourceList, DelegateExecution execution) { + for (GenericVnf vnf : serviceInstanceMSO.getVnfs()) { + if (vnf.getVnfId().equals(vnfId)) { + aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); + resourceList.add(new Resource(WorkflowType.VNF, vnf.getVnfId(), false)); + processVfModules(vnf, aaiResourceIds, resourceList, execution); + processVolumeGroups(vnf, aaiResourceIds, resourceList); + break; + } + } + } + + private void findVnfWithGivenIdAndAddCustomizationUUID(ServiceInstance serviceInstanceMSO, String vnfId, + List> aaiResourceIds, List resourceList, DelegateExecution execution) { + for (GenericVnf vnf : serviceInstanceMSO.getVnfs()) { + if (vnf.getVnfId().equals(vnfId)) { + aaiResourceIds.add(new Pair<>(WorkflowType.VNF, vnf.getVnfId())); + resourceList.add(new Resource(WorkflowType.VNF, + bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(), false)); + processVfModules(vnf, aaiResourceIds, resourceList, execution); + processVolumeGroups(vnf, aaiResourceIds, resourceList); + break; + } + } + } + private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, List resourceList, List> aaiResourceIds) { try { @@ -161,15 +141,7 @@ public class VnfEBBLoader { relationshipsOp = vfModuleWrapper.getRelationships(); if (relationshipsOp.isPresent()) { relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get()); - if (relationshipsOp.isPresent()) { - Optional config = - workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get()); - if (config.isPresent()) { - aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.get().getConfigurationId())); - resourceList.add( - new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false)); - } - } + addConfigToResources(relationshipsOp, resourceList, aaiResourceIds); } } catch (Exception ex) { logger.error("Exception in findConfigurationsInsideVfModule", ex); @@ -177,6 +149,40 @@ public class VnfEBBLoader { } } + private void processVfModules(GenericVnf vnf, List> aaiResourceIds, + List resourceList, DelegateExecution execution) { + if (vnf.getVfModules() != null) { + for (VfModule vfModule : vnf.getVfModules()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VFMODULE, vfModule.getVfModuleId())); + resourceList.add(new Resource(WorkflowType.VFMODULE, vfModule.getVfModuleId(), false)); + findConfigurationsInsideVfModule(execution, vnf.getVnfId(), vfModule.getVfModuleId(), resourceList, + aaiResourceIds); + } + } + } + + private void processVolumeGroups(GenericVnf vnf, List> aaiResourceIds, + List resourceList) { + if (vnf.getVolumeGroups() != null) { + for (VolumeGroup volumeGroup : vnf.getVolumeGroups()) { + aaiResourceIds.add(new Pair<>(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId())); + resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, volumeGroup.getVolumeGroupId(), false)); + } + } + } + + private void addConfigToResources(Optional relationshipsOp, List resourceList, + List> aaiResourceIds) { + if (relationshipsOp.isPresent()) { + Optional config = + workflowActionUtils.extractRelationshipsConfiguration(relationshipsOp.get()); + if (config.isPresent()) { + aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.get().getConfigurationId())); + resourceList.add(new Resource(WorkflowType.CONFIGURATION, config.get().getConfigurationId(), false)); + } + } + } + private void buildAndThrowException(DelegateExecution execution, String msg) { logger.error(msg); execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); -- cgit 1.2.3-korg