diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2020-01-29 14:44:42 +0100 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2020-01-30 14:12:00 +0100 |
commit | c0600706c4de333ff51a477a1211abef8b09834f (patch) | |
tree | 97b591d4a97434891385a6f71dfa41f3cd41538d | |
parent | 76a37d03413fd1798e50274c57566c0ed3d752e4 (diff) |
Create ActivatePnfBB
Issue-ID: SO-2607
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: I1115defe4ddf417a7ea94f659cf2bea119029ebb
5 files changed, 140 insertions, 14 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ActivatePnfBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ActivatePnfBB.bpmn new file mode 100644 index 0000000000..02675c6127 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/ActivatePnfBB.bpmn @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1a52v2f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.5.0"> + <bpmn:collaboration id="Collaboration_0go8wi3"> + <bpmn:participant id="Participant_1dwc5st" name="SO Activate PNF" processRef="ActivatePnfBB" /> + <bpmn:participant id="Participant_0gycee4" name="AAI" /> + <bpmn:messageFlow id="MessageFlow_0xh6bkn" sourceRef="UpdatePnfOrchestrationStatusToActive" targetRef="Participant_0gycee4" /> + </bpmn:collaboration> + <bpmn:process id="ActivatePnfBB" name="ActivatePnfBB" isExecutable="true"> + <bpmn:sequenceFlow id="SequenceFlow_0l6rtzy" sourceRef="UpdatePnfOrchestrationStatusToActive" targetRef="PnfActive" /> + <bpmn:sequenceFlow id="SequenceFlow_1fu9o4x" sourceRef="AssignPnf_StartEvent" targetRef="UpdatePnfOrchestrationStatusToActive" /> + <bpmn:endEvent id="PnfActive" name="Pnf Active"> + <bpmn:incoming>SequenceFlow_0l6rtzy</bpmn:incoming> + </bpmn:endEvent> + <bpmn:serviceTask id="UpdatePnfOrchestrationStatusToActive" name="Update Pnf Orchestration Status to Active" camunda:expression="${AAIUpdateTasks.updateOrchestrationStatusActivePnf(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}"> + <bpmn:incoming>SequenceFlow_1fu9o4x</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0l6rtzy</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:startEvent id="AssignPnf_StartEvent"> + <bpmn:outgoing>SequenceFlow_1fu9o4x</bpmn:outgoing> + </bpmn:startEvent> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_0go8wi3"> + <bpmndi:BPMNShape id="Participant_1dwc5st_di" bpmnElement="Participant_1dwc5st" isHorizontal="true"> + <dc:Bounds x="160" y="80" width="646" height="391" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Participant_0gycee4_di" bpmnElement="Participant_0gycee4" isHorizontal="true"> + <dc:Bounds x="260" y="567" width="502" height="60" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_1ix8822_di" bpmnElement="UpdatePnfOrchestrationStatusToActive"> + <dc:Bounds x="461" y="247" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="StartEvent_1g3euow_di" bpmnElement="AssignPnf_StartEvent"> + <dc:Bounds x="219" y="269" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="MessageFlow_0xh6bkn_di" bpmnElement="MessageFlow_0xh6bkn"> + <di:waypoint x="511" y="327" /> + <di:waypoint x="511" y="567" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="EndEvent_1wfgsdz_di" bpmnElement="PnfActive"> + <dc:Bounds x="722" y="269" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="717" y="312" width="50" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0l6rtzy_di" bpmnElement="SequenceFlow_0l6rtzy"> + <di:waypoint x="561" y="287" /> + <di:waypoint x="722" y="287" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1fu9o4x_di" bpmnElement="SequenceFlow_1fu9o4x"> + <di:waypoint x="255" y="287" /> + <di:waypoint x="461" y="287" /> + </bpmndi:BPMNEdge> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> 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 86645391b4..f1fbe545ce 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 @@ -32,6 +32,7 @@ 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; @@ -44,6 +45,7 @@ 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; @@ -78,6 +80,8 @@ public class AAIUpdateTasks { private AAICollectionResources aaiCollectionResources; @Autowired private AAIConfigurationResources aaiConfigurationResources; + @Autowired + private AAIPnfResources aaiPnfResources; /** * BPMN access method to update the status of Service to Assigned in AAI @@ -114,6 +118,22 @@ public class AAIUpdateTasks { } } + + /** + * BPMN access method to update status of Pnf to Active in AAI + * + * @param execution + */ + public void updateOrchestrationStatusActivePnf(BuildingBlockExecution execution) { + try { + Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + } catch (Exception ex) { + logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusActivePnf", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + /** * BPMN access method to update status of Vnf to Assigned in AAI * diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index 9dd44c43e9..1dde814584 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -49,4 +49,14 @@ public class AAIPnfResources { injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf))) .connect(pnfURI, serviceInstanceURI); } + + public void updateOrchestrationStatusPnf(Pnf pnf, OrchestrationStatus orchestrationStatus) { + AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName()); + + Pnf pnfCopy = pnf.shallowCopyId(); + + pnf.setOrchestrationStatus(orchestrationStatus); + pnfCopy.setOrchestrationStatus(orchestrationStatus); + injectionHelper.getAaiClient().update(pnfURI, aaiObjectMapper.mapPnf(pnfCopy)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index c337f7f1b5..ae6dde6521 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -20,21 +20,7 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.util.HashMap; import org.camunda.bpm.engine.delegate.BpmnError; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; @@ -48,6 +34,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; 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; @@ -56,6 +43,18 @@ import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import java.util.HashMap; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class AAIUpdateTasksTest extends BaseTaskTest { @@ -140,6 +139,27 @@ public class AAIUpdateTasksTest extends BaseTaskTest { aaiUpdateTasks.updateOrchestrationStatusActiveService(execution); } + + @Test + public void updateOrchestrationStatusActivePnfTest() throws Exception { + Pnf pnf = preparePnfAndExtractForPnf(); + doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution); + + verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception { + Pnf pnf = preparePnfAndExtractForPnf(); + doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, + OrchestrationStatus.ACTIVE); + + expectedException.expect(BpmnError.class); + aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution); + } + @Test public void updateOrchestrationStatusAssignedVnfTest() throws Exception { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); @@ -743,4 +763,10 @@ public class AAIUpdateTasksTest extends BaseTaskTest { aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution); } + + private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException { + Pnf pnf = buildPnf(); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf); + return pnf; + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java index a929f256ac..6d5e6db083 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java @@ -22,6 +22,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; @@ -83,4 +84,17 @@ public class AAIPnfResourcesTest extends TestDataSetup { verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); } + @Test + public void updateOrchestrationStatusPnfShouldSetStatusAndUpdatePnfInAAI() { + org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf(); + doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf); + + aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + + assertEquals(OrchestrationStatus.ACTIVE, pnf.getOrchestrationStatus()); + verify(aaiObjectMapperMock, times(1)) + .mapPnf(argThat(arg -> OrchestrationStatus.ACTIVE.equals(arg.getOrchestrationStatus()))); + verify(aaiResourcesClientMock, times(1)).update(any(AAIResourceUri.class), eq(pnfYang)); + } + } |