diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
5 files changed, 332 insertions, 205 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java index 6c6bd61041..aa1108cbb9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversal.java @@ -58,6 +58,7 @@ public class UserParamsServiceTraversal { private final CatalogDbClient catalogDbClient; private final ExceptionBuilder exceptionBuilder; + private boolean foundVfModuleOrVG; UserParamsServiceTraversal(CatalogDbClient catalogDbClient, ExceptionBuilder exceptionBuilder) { this.catalogDbClient = catalogDbClient; @@ -68,103 +69,13 @@ public class UserParamsServiceTraversal { List<Map<String, Object>> userParams, String serviceModelVersionId, String requestAction) throws IOException { List<Resource> resourceList = new ArrayList<>(); - boolean foundVfModuleOrVG = false; - String vnfCustomizationUUID = ""; - String vfModuleCustomizationUUID = ""; if (userParams != null) { for (Map<String, Object> params : userParams) { if (params.containsKey(USER_PARAM_SERVICE)) { ObjectMapper obj = new ObjectMapper(); String input = obj.writeValueAsString(params.get(USER_PARAM_SERVICE)); Service validate = obj.readValue(input, Service.class); - resourceList.add( - new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); - if (validate.getResources().getVnfs() != null) { - for (Vnfs vnf : validate.getResources().getVnfs()) { - resourceList.add(new Resource(WorkflowType.VNF, - vnf.getModelInfo().getModelCustomizationId(), false)); - if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { - vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); - } - if (vnf.getVfModules() != null) { - for (VfModules vfModule : vnf.getVfModules()) { - VfModuleCustomization vfModuleCustomization = - catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID( - vfModule.getModelInfo().getModelCustomizationUuid()); - if (vfModuleCustomization != null) { - - if (vfModuleCustomization.getVfModule() != null - && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null - && vfModuleCustomization.getVolumeHeatEnv() != null) { - resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, - vfModuleCustomization.getModelCustomizationUUID(), false)); - foundVfModuleOrVG = true; - } - - if ((vfModuleCustomization.getVfModule() != null) - && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null - && vfModuleCustomization.getHeatEnvironment() != null)) - || (vfModuleCustomization.getVfModule() != null - && vfModuleCustomization.getVfModule().getModelName() != null - && vfModuleCustomization.getVfModule().getModelName() - .contains("helm"))) { - foundVfModuleOrVG = true; - Resource resource = new Resource(WorkflowType.VFMODULE, - vfModuleCustomization.getModelCustomizationUUID(), false); - resource.setBaseVfModule( - vfModuleCustomization.getVfModule().getIsBase() != null - && vfModuleCustomization.getVfModule().getIsBase()); - resourceList.add(resource); - if (vfModule.getModelInfo() != null - && vfModule.getModelInfo().getModelCustomizationUuid() != null) { - vfModuleCustomizationUUID = - vfModule.getModelInfo().getModelCustomizationUuid(); - } - if (!vnfCustomizationUUID.isEmpty() - && !vfModuleCustomizationUUID.isEmpty()) { - List<CvnfcConfigurationCustomization> configs = - traverseCatalogDbForConfiguration( - validate.getModelInfo().getModelVersionId(), - vnfCustomizationUUID, vfModuleCustomizationUUID); - for (CvnfcConfigurationCustomization config : configs) { - Resource configResource = new Resource(WorkflowType.CONFIGURATION, - config.getConfigurationResource().getModelUUID(), false); - resource.setVnfCustomizationId( - vnf.getModelInfo().getModelCustomizationId()); - resource.setVfModuleCustomizationId( - vfModule.getModelInfo().getModelCustomizationId()); - resourceList.add(configResource); - } - } - } - if (!foundVfModuleOrVG) { - buildAndThrowException(execution, - "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); - } - } - } - } - } - } - if (validate.getResources().getPnfs() != null) { - for (Pnfs pnf : validate.getResources().getPnfs()) { - resourceList.add(new Resource(WorkflowType.PNF, - pnf.getModelInfo().getModelCustomizationId(), false)); - } - } - if (validate.getResources().getNetworks() != null) { - for (Networks network : validate.getResources().getNetworks()) { - resourceList.add(new Resource(WorkflowType.NETWORK, - network.getModelInfo().getModelCustomizationId(), false)); - } - if (requestAction.equals(CREATE_INSTANCE)) { - String networkColCustId = - queryCatalogDbForNetworkCollection(execution, serviceModelVersionId); - if (networkColCustId != null) { - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); - } - } - } + setResourceList(execution, serviceModelVersionId, requestAction, resourceList, validate); break; } } @@ -172,6 +83,140 @@ public class UserParamsServiceTraversal { return resourceList; } + private void setResourceList(DelegateExecution execution, String serviceModelVersionId, String requestAction, + List<Resource> resourceList, Service validate) { + resourceList.add(new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false)); + if (validate.getResources().getVnfs() != null) { + setResourceListForVnfs(execution, resourceList, validate); + } + if (validate.getResources().getPnfs() != null) { + setResourceListForPnfs(resourceList, validate); + } + if (validate.getResources().getNetworks() != null) { + setResourceListForNetworks(execution, serviceModelVersionId, requestAction, resourceList, validate); + } + } + + private void setResourceListForVnfs(DelegateExecution execution, List<Resource> resourceList, Service validate) { + foundVfModuleOrVG = false; + for (Vnfs vnf : validate.getResources().getVnfs()) { + resourceList.add(new Resource(WorkflowType.VNF, vnf.getModelInfo().getModelCustomizationId(), false)); + setResourceListForVfModules(execution, resourceList, validate, vnf); + } + } + + private void setResourceListForVfModules(DelegateExecution execution, List<Resource> resourceList, Service validate, + Vnfs vnf) { + if (vnf.getVfModules() != null) { + for (VfModules vfModule : vnf.getVfModules()) { + VfModuleCustomization vfModuleCustomization = + catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID( + vfModule.getModelInfo().getModelCustomizationUuid()); + if (vfModuleCustomization != null) { + setVolumeGroupWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); + setVfModuleAndConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, + vfModuleCustomization); + if (!foundVfModuleOrVG) { + buildAndThrowException(execution, + "Could not determine if vfModule was a vfModule or volume group. Heat template and Heat env are null"); + } + } + } + } + } + + private void setVolumeGroupWorkFlowTypeToResourceList(List<Resource> resourceList, + VfModuleCustomization vfModuleCustomization) { + if (vfModuleCustomization.getVfModule() != null + && vfModuleCustomization.getVfModule().getVolumeHeatTemplate() != null + && vfModuleCustomization.getVolumeHeatEnv() != null) { + foundVfModuleOrVG = true; + resourceList.add( + new Resource(WorkflowType.VOLUMEGROUP, vfModuleCustomization.getModelCustomizationUUID(), false)); + } + } + + private void setVfModuleAndConfigurationWorkFlowTypeToResourceList(List<Resource> resourceList, Service validate, + Vnfs vnf, VfModules vfModule, VfModuleCustomization vfModuleCustomization) { + if ((vfModuleCustomization.getVfModule() != null) + && ((vfModuleCustomization.getVfModule().getModuleHeatTemplate() != null + && vfModuleCustomization.getHeatEnvironment() != null)) + || (vfModuleCustomization.getVfModule() != null + && vfModuleCustomization.getVfModule().getModelName() != null + && vfModuleCustomization.getVfModule().getModelName().contains("helm"))) { + foundVfModuleOrVG = true; + Resource resource = setVfModuleWorkFlowTypeToResourceList(resourceList, vfModuleCustomization); + setConfigurationWorkFlowTypeToResourceList(resourceList, validate, vnf, vfModule, resource); + } + } + + private Resource setVfModuleWorkFlowTypeToResourceList(List<Resource> resourceList, + VfModuleCustomization vfModuleCustomization) { + Resource resource = + new Resource(WorkflowType.VFMODULE, vfModuleCustomization.getModelCustomizationUUID(), false); + resource.setBaseVfModule(vfModuleCustomization.getVfModule().getIsBase() != null + && vfModuleCustomization.getVfModule().getIsBase()); + resourceList.add(resource); + return resource; + } + + private void setConfigurationWorkFlowTypeToResourceList(List<Resource> resourceList, Service validate, Vnfs vnf, + VfModules vfModule, Resource resource) { + String vfModuleCustomizationUUID = getVfModuleCustomizationUUID(vfModule); + String vnfCustomizationUUID = getVnfCustomizationUUID(vnf); + if (!vnfCustomizationUUID.isEmpty() && !vfModuleCustomizationUUID.isEmpty()) { + List<CvnfcConfigurationCustomization> configs = traverseCatalogDbForConfiguration( + validate.getModelInfo().getModelVersionId(), vnfCustomizationUUID, vfModuleCustomizationUUID); + for (CvnfcConfigurationCustomization config : configs) { + Resource configResource = new Resource(WorkflowType.CONFIGURATION, + config.getConfigurationResource().getModelUUID(), false); + resource.setVnfCustomizationId(vnf.getModelInfo().getModelCustomizationId()); + resource.setVfModuleCustomizationId(vfModule.getModelInfo().getModelCustomizationId()); + resourceList.add(configResource); + } + } + } + + private String getVfModuleCustomizationUUID(VfModules vfModule) { + String vfModuleCustomizationUUID; + if (vfModule.getModelInfo() != null && vfModule.getModelInfo().getModelCustomizationUuid() != null) { + vfModuleCustomizationUUID = vfModule.getModelInfo().getModelCustomizationUuid(); + } else { + vfModuleCustomizationUUID = ""; + } + return vfModuleCustomizationUUID; + } + + private String getVnfCustomizationUUID(Vnfs vnf) { + String vnfCustomizationUUID; + if (vnf.getModelInfo() != null && vnf.getModelInfo().getModelCustomizationUuid() != null) { + vnfCustomizationUUID = vnf.getModelInfo().getModelCustomizationUuid(); + } else { + vnfCustomizationUUID = ""; + } + return vnfCustomizationUUID; + } + + private void setResourceListForPnfs(List<Resource> resourceList, Service validate) { + for (Pnfs pnf : validate.getResources().getPnfs()) { + resourceList.add(new Resource(WorkflowType.PNF, pnf.getModelInfo().getModelCustomizationId(), false)); + } + } + + private void setResourceListForNetworks(DelegateExecution execution, String serviceModelVersionId, + String requestAction, List<Resource> resourceList, Service validate) { + for (Networks network : validate.getResources().getNetworks()) { + resourceList + .add(new Resource(WorkflowType.NETWORK, network.getModelInfo().getModelCustomizationId(), false)); + } + if (requestAction.equals(CREATE_INSTANCE)) { + String networkColCustId = queryCatalogDbForNetworkCollection(execution, serviceModelVersionId); + if (networkColCustId != null) { + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, networkColCustId, false)); + } + } + } + private List<CvnfcConfigurationCustomization> traverseCatalogDbForConfiguration(String serviceModelUUID, String vnfCustomizationUUID, String vfModuleCustomizationUUID) { 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 d1da38f2d9..ee4e56bc18 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,6 +46,7 @@ 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.ebb.loader.VnfEBBLoader; 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; @@ -143,6 +144,8 @@ public class WorkflowAction { private AaiResourceIdValidator aaiResourceIdValidator; @Autowired private ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; + @Autowired + private VnfEBBLoader vnfEBBLoader; public void setBbInputSetupUtils(BBInputSetupUtils bbInputSetupUtils) { this.bbInputSetupUtils = bbInputSetupUtils; @@ -340,10 +343,10 @@ public class WorkflowAction { resourceList.add(new Resource(WorkflowType.SERVICE, "", false)); } else if (resourceType == WorkflowType.VNF && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) || ("recreateInstance".equalsIgnoreCase(requestAction)))) { - traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); } else if (resourceType == WorkflowType.VNF && "updateInstance".equalsIgnoreCase(requestAction)) { - customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), + vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds); } else { buildAndThrowException(execution, "Current Macro Request is not supported"); @@ -404,8 +407,6 @@ public class WorkflowAction { return containsService; } - - private List<ExecuteBuildingBlock> loadExecuteBuildingBlocks(DelegateExecution execution, String requestId, String errorMessage) { List<ExecuteBuildingBlock> flowsToExecute; @@ -1092,116 +1093,7 @@ public class WorkflowAction { } } - private void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, - String vnfId, List<Pair<WorkflowType, String>> aaiResourceIds) { - try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.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; - } - } - } - } catch (Exception ex) { - logger.error("Exception in traverseAAIVnf", ex); - buildAndThrowException(execution, - "Could not find existing Vnf or related Instances to execute the request on."); - } - } - - private void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, - String vnfId, List<Pair<WorkflowType, String>> aaiResourceIds) { - try { - ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); - org.onap.so.bpmn.servicedecomposition.bbobjects.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; - } - } - } - } catch (Exception ex) { - logger.error("Exception in customTraverseAAIVnf", ex); - buildAndThrowException(execution, - "Could not find existing Vnf or related Instances to execute the request on."); - } - - } - private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, - List<Resource> resourceList, List<Pair<WorkflowType, String>> aaiResourceIds) { - try { - org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); - AAIResultWrapper vfModuleWrapper = new AAIResultWrapper( - new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule)); - Optional<Relationships> relationshipsOp; - relationshipsOp = vfModuleWrapper.getRelationships(); - if (relationshipsOp.isPresent()) { - relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get()); - if (relationshipsOp.isPresent()) { - Optional<Configuration> 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)); - } - } - } - } catch (Exception ex) { - logger.error("Exception in findConfigurationsInsideVfModule", ex); - buildAndThrowException(execution, "Failed to find Configuration object from the vfModule."); - } - } protected WorkflowResourceIds populateResourceIdsFromApiHandler(DelegateExecution execution) { return WorkflowResourceIdsUtils.getWorkflowResourceIdsFromExecution(execution); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java index 5e16097304..9128e9e3e1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -35,7 +35,7 @@ public final class WorkflowActionConstants { static final String USER_PARAM_SERVICE = "service"; static final String CREATE_INSTANCE = "createInstance"; static final String FABRIC_CONFIGURATION = "FabricConfiguration"; - static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; + public static final String WORKFLOW_ACTION_ERROR_MESSAGE = "WorkflowActionErrorMessage"; static final String SERVICE = "Service"; static final String CONTROLLER = "Controller"; static final String NETWORKCOLLECTION = "NetworkCollection"; 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 new file mode 100644 index 0000000000..7db93e7979 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2021 Nokia + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Modifications Copyright (c) 2021 Nokia + * ================================================================================ + * Modifications Copyright (c) 2020 Tech Mahindra + * ================================================================================ + * 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.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; +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.VfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Optional; +import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE; + +@Component +public class VnfEBBLoader { + + private static final Logger logger = LoggerFactory.getLogger(VnfEBBLoader.class); + + private final BBInputSetupUtils bbInputSetupUtils; + private final BBInputSetup bbInputSetup; + private final WorkflowActionExtractResourcesAAI workflowActionUtils; + private final ExceptionBuilder exceptionBuilder; + + VnfEBBLoader(BBInputSetupUtils bbInputSetupUtils, BBInputSetup bbInputSetup, + WorkflowActionExtractResourcesAAI workflowActionUtils, ExceptionBuilder exceptionBuilder) { + this.bbInputSetupUtils = bbInputSetupUtils; + this.bbInputSetup = bbInputSetup; + this.workflowActionUtils = workflowActionUtils; + this.exceptionBuilder = exceptionBuilder; + } + + + public void traverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, String vnfId, + List<Pair<WorkflowType, String>> aaiResourceIds) { + try { + ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + org.onap.so.bpmn.servicedecomposition.bbobjects.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; + } + } + } + } catch (Exception ex) { + logger.error("Exception in traverseAAIVnf", ex); + buildAndThrowException(execution, + "Could not find existing Vnf or related Instances to execute the request on."); + } + } + + public void customTraverseAAIVnf(DelegateExecution execution, List<Resource> resourceList, String serviceId, + String vnfId, List<Pair<WorkflowType, String>> aaiResourceIds) { + try { + ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(serviceId); + org.onap.so.bpmn.servicedecomposition.bbobjects.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; + } + } + } + } catch (Exception ex) { + logger.error("Exception in customTraverseAAIVnf", ex); + buildAndThrowException(execution, + "Could not find existing Vnf or related Instances to execute the request on."); + } + + } + + private void findConfigurationsInsideVfModule(DelegateExecution execution, String vnfId, String vfModuleId, + List<Resource> resourceList, List<Pair<WorkflowType, String>> aaiResourceIds) { + try { + org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId); + AAIResultWrapper vfModuleWrapper = new AAIResultWrapper( + new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule)); + Optional<Relationships> relationshipsOp; + relationshipsOp = vfModuleWrapper.getRelationships(); + if (relationshipsOp.isPresent()) { + relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get()); + if (relationshipsOp.isPresent()) { + Optional<Configuration> 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)); + } + } + } + } catch (Exception ex) { + logger.error("Exception in findConfigurationsInsideVfModule", ex); + buildAndThrowException(execution, "Failed to find Configuration object from the vfModule."); + } + } + + private void buildAndThrowException(DelegateExecution execution, String msg) { + logger.error(msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index d0cd4b0b46..26e0d2f8c9 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -78,6 +78,7 @@ 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.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; @@ -136,6 +137,10 @@ public class WorkflowActionTest extends BaseTaskTest { @Spy protected ExecuteBuildingBlockBuilder executeBuildingBlockBuilder; + @InjectMocks + @Spy + protected VnfEBBLoader vnfEBBLoaderSpy; + @Rule public ExpectedException thrown = ExpectedException.none(); |