diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
9 files changed, 674 insertions, 35 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index 4d5494d18c..8a6c4c2796 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -5,13 +5,14 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (c) 2019 Samsung + * Modifications Copyright (c) 2019 Bell Canada. * ================================================================================ * 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. @@ -22,39 +23,23 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; -import java.util.List; -import java.util.Map; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; -import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; -import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.*; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.orchestration.AAICollectionResources; -import org.onap.so.client.orchestration.AAIConfigurationResources; -import org.onap.so.client.orchestration.AAINetworkResources; -import org.onap.so.client.orchestration.AAIPnfResources; -import org.onap.so.client.orchestration.AAIServiceInstanceResources; -import org.onap.so.client.orchestration.AAIVfModuleResources; -import org.onap.so.client.orchestration.AAIVnfResources; -import org.onap.so.client.orchestration.AAIVolumeGroupResources; +import org.onap.so.client.orchestration.*; import org.onap.so.db.catalog.beans.OrchestrationStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; @Component public class AAIUpdateTasks { @@ -340,7 +325,6 @@ public class AAIUpdateTasks { * BPMN access method to update status of VfModule to Created in AAI * * @param execution - * */ public void updateOrchestrationStatusCreatedVfModule(BuildingBlockExecution execution) { try { @@ -357,7 +341,6 @@ public class AAIUpdateTasks { * BPMN access method to update aaiDeactivateVfModuleRollback to true for deactivating the VfModule * * @param execution - * @throws buildAndThrowWorkflowException */ public void updateOrchestrationStatusDeactivateVfModule(BuildingBlockExecution execution) { execution.setVariable("aaiDeactivateVfModuleRollback", false); @@ -794,7 +777,6 @@ public class AAIUpdateTasks { logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfigureVnf", ex); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } - } /** @@ -806,11 +788,55 @@ public class AAIUpdateTasks { try { GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); aaiVnfResources.updateOrchestrationStatusVnf(vnf, OrchestrationStatus.CONFIGURED); - } catch (Exception ex) { logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfiguredVnf", ex); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } + } + /** + * BPMN access method to update status of VNF/VF-Module based on SO scope and action. + * + * @param execution - BuildingBlockExecution + * @param scope - SO scope (vnf/vfModule) + * @param action - action (configAssign/configDeploy/configUndeploy etc..) + */ + public void updateOrchestrationStatusForCds(BuildingBlockExecution execution, String scope, String action) { + try { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + OrchestrationStatus status = getOrchestrationStatus(action); + switch (scope) { + case "vnf": + aaiVnfResources.updateOrchestrationStatusVnf(vnf, status); + break; + case "vfModule": + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, status); + break; + default: + throw new IllegalArgumentException( + "Invalid scope to update orchestration status for CDS : " + action); + } + } catch (Exception ex) { + logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusForCds", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + private OrchestrationStatus getOrchestrationStatus(String action) { + /** + * At this state, OrcherstationStatus enum associated with configAssign and configDeploy. I am not sure which is + * the correct approach. 1. Are we going to map each specific action to OrchestrationStauts ? 2. We will have + * only one generic status for all actions ? + */ + + switch (action) { + case "configAssign": + return OrchestrationStatus.ASSIGNED; + case "configDeploy": + return OrchestrationStatus.CONFIGURED; + default: + throw new IllegalArgumentException("Invalid action to set Orchestration status: " + action); + } } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java index 6b0cbc0396..0f65b4b3d4 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDE.java @@ -31,11 +31,14 @@ import org.springframework.stereotype.Component; * This implementation of {@ref ControllerRunnable} is used for Self service, i.e, blueprint based Controller. */ @Component -public class CdsControllerDE extends AbstractCDSProcessingBBUtils implements ControllerRunnable<DelegateExecution> { +public class CdsControllerDE implements ControllerRunnable<DelegateExecution> { @Autowired(required = false) private List<ControllerPreparable<DelegateExecution>> prepareList; + @Autowired + private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils; + @Override public Boolean understand(ControllerContext<DelegateExecution> context) { return context.getControllerActor().equalsIgnoreCase("cds"); @@ -55,7 +58,7 @@ public class CdsControllerDE extends AbstractCDSProcessingBBUtils implements Con @Override public void run(ControllerContext<DelegateExecution> context) { DelegateExecution execution = context.getExecution(); - constructExecutionServiceInputObject(execution); - sendRequestToCDSClient(execution); + abstractCDSProcessingBBUtils.constructExecutionServiceInputObject(execution); + abstractCDSProcessingBBUtils.sendRequestToCDSClient(execution); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java new file mode 100644 index 0000000000..86d56005f6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecution.java @@ -0,0 +1,109 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 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.flowspecific.tasks; + +import java.util.Optional; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.BBNameSelectionReference; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ControllerExecution { + private static final Logger logger = LoggerFactory.getLogger(ControllerExecution.class); + private static final String CONTROLLER_ACTOR = "controllerActor"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String SCOPE = "scope"; + private static final String ACTION = "action"; + private static final String BBNAME = "bbName"; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CatalogDbClient catalogDbClient; + @Autowired + private ExtractPojosForBB extractPojosForBB; + + /** + * Setting Controller Actor, Scope and Action Variables in BuildingBlockExecution object + * + * @param execution - BuildingBlockExecution object + */ + public void setControllerActorScopeAction(BuildingBlockExecution execution) { + try { + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + String modleUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid(); + VnfResourceCustomization vnfResourceCustomization = + catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(modleUuid); + + // Fetching Controller Actor at VNF level if null then Controller Actor is set as "APPC" + String controllerActor = Optional.ofNullable(vnfResourceCustomization.getControllerActor()).orElse("APPC"); + ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); + BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); + String scope = Optional.ofNullable(buildingBlock.getBpmnScope()).orElseThrow( + () -> new NullPointerException("BPMN Scope is NULL in the orchestration_flow_reference table ")); + String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow( + () -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table ")); + execution.setVariable(SCOPE, scope); + execution.setVariable(ACTION, action); + execution.setVariable(CONTROLLER_ACTOR, controllerActor); + logger.debug("Executing Controller Execution for ControllerActor: {}, Scope: {} , Action: {}", + controllerActor, scope, action); + + } catch (Exception ex) { + logger.error("An exception occurred while fetching Controller Actor,Scope and Action ", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + /** + * Selecting bbName from BBNameSelectionReference and setting the value in a variable of BuildingBlockExecution + * + * @param execution - BuildingBlockExecution object + */ + public void selectBB(BuildingBlockExecution execution) { + try { + + String controllerActor = execution.getVariable(CONTROLLER_ACTOR); + String action = Optional.of((String) execution.getVariable(ACTION)).get(); + String scope = Optional.of((String) execution.getVariable(SCOPE)).get(); + BBNameSelectionReference bbNameSelectionReference = + catalogDbClient.getBBNameSelectionReference(controllerActor, scope, action); + String bbName = bbNameSelectionReference.getBbName(); + execution.setVariable(BBNAME, bbName); + logger.debug(" Executing {} BPMN", bbName); + } catch (Exception ex) { + logger.error("An exception occurred while getting bbname from catalogdb ", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + + } + + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java new file mode 100644 index 0000000000..f568026aa5 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBB.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.flowspecific.tasks; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.AbstractCDSProcessingBBUtils; +import org.onap.so.client.cds.GeneratePayloadForCds; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * For Vnf/Vf-Module/Service BuildingBlockExecution is being used. + * + * @param - BuildingBlockExecution + */ +@Component +public class GenericCDSProcessingBB implements ControllerRunnable<BuildingBlockExecution> { + private static final Logger logger = LoggerFactory.getLogger(GenericCDSProcessingBB.class); + private static final String EXECUTION_OBJECT = "executionObject"; + public static final String CDS_ACTOR = "cds"; + public static final String VNF_SCOPE = "vnf"; + public static final String VF_MODULE_SCOPE = "vf-module"; + + @Autowired + private ExceptionBuilder exceptionBuilder; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private AbstractCDSProcessingBBUtils cdsDispather; + + @Autowired + private GeneratePayloadForCds generatePayloadForCds; + + @Override + public Boolean understand(ControllerContext<BuildingBlockExecution> context) { + String scope = context.getControllerScope(); + return CDS_ACTOR.equalsIgnoreCase(context.getControllerActor()) + && (VNF_SCOPE.equalsIgnoreCase(scope) || VF_MODULE_SCOPE.equalsIgnoreCase(scope)); + } + + @Override + public Boolean ready(ControllerContext<BuildingBlockExecution> context) { + return true; + } + + @Override + public void prepare(ControllerContext<BuildingBlockExecution> context) { + BuildingBlockExecution buildingBlockExecution = context.getExecution(); + try { + AbstractCDSPropertiesBean abstractCDSPropertiesBean = + generatePayloadForCds.buildCdsPropertiesBean(buildingBlockExecution); + buildingBlockExecution.setVariable(EXECUTION_OBJECT, abstractCDSPropertiesBean); + } catch (Exception ex) { + logger.error("An exception occurred when creating payload for CDS request", ex); + exceptionBuilder.buildAndThrowWorkflowException(buildingBlockExecution, 7000, ex); + } + } + + @Override + public void run(ControllerContext<BuildingBlockExecution> context) { + BuildingBlockExecution obj = context.getExecution(); + cdsDispather.constructExecutionServiceInputObject(obj); + cdsDispather.sendRequestToCDSClient(obj); + } +} 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 80c6f0b969..9ee0104a5f 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 @@ -94,6 +94,7 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.util.CollectionUtils; @Component public class WorkflowAction { @@ -410,15 +411,17 @@ public class WorkflowAction { } } - if (flowsToExecute == null || flowsToExecute.isEmpty()) { + if (CollectionUtils.isEmpty(flowsToExecute)) { throw new IllegalStateException("Macro did not come up with a valid execution path."); } + List<String> flowNames = new ArrayList<>(); logger.info("List of BuildingBlocks to execute:"); - for (ExecuteBuildingBlock ebb : flowsToExecute) { + + flowsToExecute.forEach(ebb -> { logger.info(ebb.getBuildingBlock().getBpmnFlowName()); flowNames.add(ebb.getBuildingBlock().getBpmnFlowName()); - } + }); if (!isResume) { bbInputSetupUtils.persistFlowExecutionPath(requestId, flowsToExecute); @@ -431,7 +434,12 @@ public class WorkflowAction { execution.setVariable("isRollbackComplete", false); } catch (Exception ex) { - buildAndThrowException(execution, "Exception while setting execution list. ", ex); + if (!(execution.hasVariable("WorkflowException") + || execution.hasVariable("WorkflowExceptionExceptionMessage"))) { + buildAndThrowException(execution, "Exception while setting execution list. ", ex); + } else { + throw ex; + } } } @@ -537,7 +545,7 @@ public class WorkflowAction { if (configurations.size() > 1) { String multipleRelationshipsError = "Multiple relationships exist from VNFC " + vnfc.getVnfcName() + " to Configurations"; - buildAndThrowException(dataObj.getExecution(), multipleRelationshipsError, + buildAndThrowException(dataObj.getExecution(), "Exception in getConfigBuildingBlock: ", new Exception(multipleRelationshipsError)); } for (org.onap.aai.domain.yang.Configuration configuration : configurations) { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java index 79bce8a1f4..142cb53ed8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/decisionpoint/impl/camunda/controller/cds/CdsControllerDETest.java @@ -26,8 +26,10 @@ import org.camunda.bpm.engine.delegate.DelegateExecution; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; import org.onap.so.bpmn.infrastructure.decisionpoint.api.controller.ControllerPreparable; +import org.onap.so.client.cds.AbstractCDSProcessingBBUtils; import org.onap.so.client.exception.ExceptionBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; @@ -35,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class}) +@ContextConfiguration(classes = {CdsControllerDE.class, ExceptionBuilder.class, AbstractCDSProcessingBBUtils.class}) public class CdsControllerDETest { @Autowired @@ -47,6 +49,9 @@ public class CdsControllerDETest { @MockBean private ControllerPreparable<DelegateExecution> preparable; + @Mock + private AbstractCDSProcessingBBUtils abstractCDSProcessingBBUtils; + @Before public void setUp() { when(controllerContext.getControllerActor()).thenReturn("cds"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java new file mode 100644 index 0000000000..72a987c395 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ControllerExecutionTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 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.flowspecific.tasks; + + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.db.catalog.beans.BBNameSelectionReference; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; + + +public class ControllerExecutionTest extends BaseTaskTest { + + @InjectMocks + private ControllerExecution controllerExecution = new ControllerExecution(); + + private static final String TEST_SCOPE = "vfModule"; + private static final String TEST_BBNAME = "ConfigurationScaleOut"; + private static final String TEST_ACTION = "configScaleOut"; + private static final String TEST_CONTROLLER_ACTOR = "APPC"; + + private BuildingBlock buildingBlock = new BuildingBlock(); + VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization(); + private ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock(); + private GenericVnf genericVnf; + private ServiceInstance serviceInstance; + private RequestContext requestContext; + private String msoRequestId; + + + @Before + public void before() throws BBObjectNotFoundException { + + genericVnf = setGenericVnf(); + serviceInstance = setServiceInstance(); + msoRequestId = UUID.randomUUID().toString(); + requestContext = setRequestContext(); + requestContext.setMsoRequestId(msoRequestId); + gBBInput.setRequestContext(requestContext); + buildingBlock.setBpmnAction(TEST_ACTION); + buildingBlock.setBpmnScope(TEST_SCOPE); + executeBuildingBlock.setBuildingBlock(buildingBlock); + execution.setVariable("buildingBlock", executeBuildingBlock); + + doThrow(new BpmnError("BPMN Error")).when(exceptionUtil) + .buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); + + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.GENERIC_VNF_ID))) + .thenReturn(genericVnf); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.SERVICE_INSTANCE_ID))) + .thenReturn(serviceInstance); + + + } + + @Test + public void testSetControllerActorScopeAction() throws Exception { + + + doReturn(vnfResourceCustomization).when(catalogDbClient).getVnfResourceCustomizationByModelCustomizationUUID( + genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid()); + controllerExecution.setControllerActorScopeAction(execution); + assertEquals(TEST_SCOPE, execution.getVariable("scope")); + assertEquals(TEST_ACTION, execution.getVariable("action")); + assertEquals(TEST_CONTROLLER_ACTOR, execution.getVariable("controllerActor")); + + } + + + @Test + public void testSelectBB() throws Exception { + // given + BBNameSelectionReference bbNameSelectionReference = new BBNameSelectionReference(); + bbNameSelectionReference.setBbName(TEST_BBNAME); + bbNameSelectionReference.setAction(TEST_ACTION); + bbNameSelectionReference.setControllerActor(TEST_CONTROLLER_ACTOR); + bbNameSelectionReference.setScope(TEST_SCOPE); + doReturn(bbNameSelectionReference).when(catalogDbClient).getBBNameSelectionReference(TEST_CONTROLLER_ACTOR, + TEST_SCOPE, TEST_ACTION); + execution.setVariable("controllerActor", TEST_CONTROLLER_ACTOR); + execution.setVariable("scope", TEST_SCOPE); + execution.setVariable("action", TEST_ACTION); + + // when + controllerExecution.selectBB(execution); + // verify + assertEquals(TEST_BBNAME, execution.getVariable("bbName")); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java new file mode 100644 index 0000000000..24bbc78afb --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/GenericCDSProcessingBBTest.java @@ -0,0 +1,197 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada. + * ================================================================================ + * 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.flowspecific.tasks; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext; +import org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerRunnable; +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.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.*; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Resources; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; +import org.springframework.beans.factory.annotation.Autowired; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.*; + +public class GenericCDSProcessingBBTest extends BaseTaskTest { + + private static final String VNF_SCOPE = "vnf"; + private static final String TEST_VNF_MODEL_CUSTOMIZATION_UUID = "23ce9ac4-e5dd-11e9-81b4-2a2ae2dbcce4"; + private static final String DEPLOY_ACTION_FOR_CDS = "configDeploy"; + private static final String GENERAL_BLOCK_EXECUTION_MAP_KEY = "gBBInput"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String TEST_MSO_REQUEST_ID = "ff874603-4222-11e7-9252-005056850d2e"; + private static final String EXECUTION_OBJECT = "executionObject"; + private static final String BLUEPRINT_NAME = "test"; + private static final String BLUEPRINT_VERSION = "1.0.0"; + + @InjectMocks + private GenericCDSProcessingBB controllerRunnable; + + @Mock + private AbstractCDSProcessingBBUtils cdsDispather; + + @Mock + private GeneratePayloadForCds generatePayloadForCds; + + private BuildingBlockExecution buildingBlockExecution; + + private ExecuteBuildingBlock executeBuildingBlock; + + @Before + public void setUp() { + buildingBlockExecution = createBuildingBlockExecution(); + executeBuildingBlock = new ExecuteBuildingBlock(); + } + + @Test + public void testExecutionObjectCreationForVnf() throws Exception { + // given + ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>(); + controllerContext.setExecution(buildingBlockExecution); + controllerContext.setControllerActor("CDS"); + controllerContext.setControllerScope("vnf"); + setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION_FOR_CDS); + AbstractCDSPropertiesBean cdsBean = prepareCDSBean(); + + doReturn(cdsBean).when(generatePayloadForCds).buildCdsPropertiesBean(buildingBlockExecution); + doNothing().when(cdsDispather).constructExecutionServiceInputObject(buildingBlockExecution); + doNothing().when(cdsDispather).sendRequestToCDSClient(buildingBlockExecution); + + // when + Boolean isUnderstandable = controllerRunnable.understand(controllerContext); + Boolean isReady = controllerRunnable.ready(controllerContext); + controllerRunnable.prepare(controllerContext); + controllerRunnable.run(controllerContext); + + // verify + assertEquals(isUnderstandable, true); + assertEquals(isReady, true); + AbstractCDSPropertiesBean executionObject = buildingBlockExecution.getVariable(EXECUTION_OBJECT); + assertNotNull(executionObject); + assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class); + assertEquals(BLUEPRINT_NAME, executionObject.getBlueprintName()); + assertEquals(BLUEPRINT_VERSION, executionObject.getBlueprintVersion()); + assertEquals(TEST_MSO_REQUEST_ID, executionObject.getRequestId()); + assertNotNull(executionObject.getRequestObject()); + } + + private AbstractCDSPropertiesBean prepareCDSBean() { + AbstractCDSPropertiesBean cdsBean = new AbstractCDSPropertiesBean(); + cdsBean.setBlueprintName(BLUEPRINT_NAME); + cdsBean.setBlueprintVersion(BLUEPRINT_VERSION); + cdsBean.setRequestId(TEST_MSO_REQUEST_ID); + cdsBean.setRequestObject("requestObject"); + + return cdsBean; + } + + private GeneralBuildingBlock createGeneralBuildingBlock() { + GeneralBuildingBlock generalBuildingBlock = new GeneralBuildingBlock(); + RequestContext requestContext = new RequestContext(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setUserParams(createRequestParameters()); + requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId(TEST_MSO_REQUEST_ID); + generalBuildingBlock.setRequestContext(requestContext); + return generalBuildingBlock; + } + + private List<Map<String, Object>> createRequestParameters() { + List<Map<String, Object>> userParams = new ArrayList<>(); + Map<String, Object> userParamMap = new HashMap<>(); + userParamMap.put("service", getUserParams()); + userParams.add(userParamMap); + return userParams; + } + + private Service getUserParams() { + Service service = new Service(); + Resources resources = new Resources(); + resources.setVnfs(createVnfList()); + service.setResources(resources); + return service; + } + + private List<Vnfs> createVnfList() { + List<Map<String, String>> instanceParamsListSearchedVnf = new ArrayList<>(); + Map<String, String> instanceParam = new HashMap<>(); + instanceParam.put("sec_group", "sec_group"); + instanceParam.put("net_id", "acl-cloud-region"); + instanceParamsListSearchedVnf.add(instanceParam); + Vnfs searchedVnf = createVnf(instanceParamsListSearchedVnf); + List<Vnfs> vnfList = new ArrayList<>(); + vnfList.add(searchedVnf); + return vnfList; + } + + private Vnfs createVnf(List<Map<String, String>> instanceParamsList) { + Vnfs vnf = new Vnfs(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelCustomizationId(TEST_VNF_MODEL_CUSTOMIZATION_UUID); + vnf.setModelInfo(modelInfo); + vnf.setInstanceParams(instanceParamsList); + return vnf; + } + + private BuildingBlockExecution createBuildingBlockExecution() { + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable(GENERAL_BLOCK_EXECUTION_MAP_KEY, createGeneralBuildingBlock()); + return new DelegateExecutionImpl(execution); + } + + private void setScopeAndAction(String scope, String action) { + BuildingBlock buildingBlock = new BuildingBlock(); + buildingBlock.setBpmnScope(scope); + buildingBlock.setBpmnAction(action); + executeBuildingBlock.setBuildingBlock(buildingBlock); + buildingBlockExecution.setVariable(BUILDING_BLOCK, executeBuildingBlock); + } +} 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 8e47c34cb0..4fdd97d95a 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 @@ -41,6 +41,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; @@ -228,6 +229,77 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void selectExecutionListExceptionAlreadyBuiltTest() throws Exception { + DelegateExecution delegateExecution = new DelegateExecutionFake(); + String gAction = "deleteInstance"; + String resource = "VfModule"; + delegateExecution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + delegateExecution.setVariable("requestAction", gAction); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json"))); + delegateExecution.setVariable("bpmnRequest", bpmnRequest); + delegateExecution.setVariable("aLaCarte", true); + delegateExecution.setVariable("apiVersion", "7"); + delegateExecution.setVariable("requestUri", + "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", + "UnassignVfModuleBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, + true, "my-custom-cloud-owner")).thenReturn(northBoundRequest); + + doAnswer(invocation -> { + DelegateExecutionFake execution = invocation.getArgument(0); + execution.setVariable("WorkflowException", "exception"); + execution.setVariable("WorkflowExceptionErrorMessage", "errorMessage"); + throw new BpmnError("WorkflowException"); + }).when(exceptionUtil).buildAndThrowWorkflowException(delegateExecution, 7000, + "Exception in getConfigBuildingBlock: Multiple relationships exist from VNFC testVnfcName to Configurations"); + + + org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf(); + vnf.setVnfId("vnf0"); + vnf.setModelCustomizationId("modelCustomizationId"); + when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf); + + org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule(); + vfModule.setModelCustomizationId("modelCustomizationId"); + when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule); + + List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>(); + org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc(); + vnfc.setModelInvariantId("modelInvariantId"); + vnfc.setVnfcName("testVnfcName"); + vnfcs.add(vnfc); + doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any()); + + List<org.onap.aai.domain.yang.Configuration> configurations = + new ArrayList<org.onap.aai.domain.yang.Configuration>(); + org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); + configuration.setConfigurationId("configurationId"); + configuration.setModelCustomizationId("modelCustimizationId"); + configuration.setConfigurationName("testConfigurationName"); + configurations.add(configuration); + org.onap.aai.domain.yang.Configuration configuration1 = new org.onap.aai.domain.yang.Configuration(); + configuration1.setConfigurationId("configurationId"); + configuration1.setModelCustomizationId("modelCustimizationId"); + configuration1.setConfigurationName("testConfigurationName"); + configurations.add(configuration1); + doReturn(configurations).when(SPY_workflowAction).getRelatedResourcesInVnfc(any(), any(), any()); + + doReturn("testName").when(SPY_workflowAction).getVnfcNameForConfiguration(any()); + + thrown.expect(BpmnError.class); + SPY_workflowAction.selectExecutionList(delegateExecution); + assertEquals( + "Exception in getConfigBuildingBlock: Multiple relationships exist from VNFC testVnfcName to Configurations", + delegateExecution.getVariable("WorkflowException")); + } + + @Test public void selectExecutionListDuplicateNameExceptionTest() throws Exception { String gAction = "createInstance"; execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); |