From 49bb3328fe6d538606ce75506314be1e91e1a7e7 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 1 Mar 2019 12:53:12 -0500 Subject: use async activity call in UpdateNetwork BB remove references to AIC in comments use async activity call in UpdateNetwork BB Change-Id: I46472571078ac335bc85c865fdd82964b68c0d75 Issue-ID: SO-1583 Signed-off-by: Benjamin, Max (mb388a) --- .../subprocess/BuildingBlock/UpdateNetworkBB.bpmn | 115 ++++++++++++++------- .../bpmn/subprocess/UpdateNetworkBBTest.java | 2 +- .../infrastructure/aai/tasks/AAIUpdateTasks.java | 31 +++++- .../network/tasks/NetworkAdapterUpdateTasks.java | 25 +++-- .../aai/tasks/AAIUpdateTasksTest.java | 24 +++++ .../tasks/NetworkAdapterUpdateTasksTest.java | 39 ++----- 6 files changed, 159 insertions(+), 77 deletions(-) diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateNetworkBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateNetworkBB.bpmn index 1cfb9a3860..b93ecf8066 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateNetworkBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/UpdateNetworkBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_074w2et @@ -38,24 +38,39 @@ - - SequenceFlow_196cgux + + SequenceFlow_0qrtpcy - - - SequenceFlow_196cgux - SequenceFlow_0hsvgje - - - - SequenceFlow_0hsvgje - SequenceFlow_0fhfitm + + SequenceFlow_001ursg + SequenceFlow_06ei0em - SequenceFlow_0fhfitm + SequenceFlow_06ei0em - + + + + + + + SequenceFlow_07hq1eg + SequenceFlow_183ph5i + + + SequenceFlow_183ph5i + SequenceFlow_001ursg + + + SequenceFlow_0qrtpcy + SequenceFlow_07hq1eg + + + + + + @@ -140,43 +155,65 @@ - - + + - + - - - + + + + + - + - - - - - - + + + + + + + + + + + + + + - + - - - - - + + + - + - - - - + + + + + + + + + + + + + + + + + + - + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/UpdateNetworkBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/UpdateNetworkBBTest.java index 98e049f440..5ba38a70e0 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/UpdateNetworkBBTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/UpdateNetworkBBTest.java @@ -38,7 +38,7 @@ public class UpdateNetworkBBTest extends BaseBPMNTest { assertThat(processInstance).isStarted().hasPassedInOrder( "UpdateNetworkBB_Start", "SDNCChangeAssignNetwork", "QueryVpnBindingAAI", "QueryNetworkPolicyAAI", "QueryNetworkTableRefAAI", - "UpdateNetworkAdapter", "UpdateNetworkAAI", "UpdateNetworkBB_End"); + "Create_Network_ServiceTask", "CallActivity_NetworkAdapterRestV1", "ServiceTask_ProcessResponse", "Update_Network_AAI_ServiceTask", "UpdateNetworkBB_End"); assertThat(processInstance).isEnded(); } 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 37e1a93044..34598ef00a 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 @@ -26,6 +26,7 @@ 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; @@ -338,7 +339,7 @@ public class AAIUpdateTasks { } /** - * BPMN access method to update L3Network after it was created in AIC + * BPMN access method to update L3Network after it was created in cloud * @param execution * @throws Exception */ @@ -379,6 +380,34 @@ public class AAIUpdateTasks { } } + /** + * BPMN access method to update L3Network after it was updated in cloud + * @param execution + * @throws Exception + */ + public void updateNetworkUpdated(BuildingBlockExecution execution) throws Exception { + L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); + L3Network copiedl3network = l3network.shallowCopyId(); + UpdateNetworkResponse response = execution.getVariable("updateNetworkResponse"); + try { + copiedl3network.setNeutronNetworkId(response.getNeutronNetworkId()); + aaiNetworkResources.updateNetwork(copiedl3network); + + Map subnetMap = response.getSubnetMap(); + List subnets = l3network.getSubnets(); + if (subnets != null && subnetMap != null){ + for (Subnet subnet: subnets){ + Subnet copiedSubnet = subnet.shallowCopyId(); + copiedSubnet.setNeutronSubnetId(subnetMap.get(copiedSubnet.getSubnetId())); + copiedSubnet.setOrchestrationStatus(OrchestrationStatus.CREATED); + aaiNetworkResources.updateSubnet(copiedl3network, copiedSubnet); + } + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + public void updateObjectNetwork(BuildingBlockExecution execution) { try { L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java index ee7f3697ae..61687081d9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasks.java @@ -22,8 +22,7 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; -import java.util.Optional; - +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; @@ -31,6 +30,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; 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.adapter.network.mapper.NetworkAdapterObjectMapper; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.NetworkAdapterResources; import org.slf4j.Logger; @@ -45,7 +45,7 @@ public class NetworkAdapterUpdateTasks { @Autowired private ExtractPojosForBB extractPojosForBB; @Autowired - private NetworkAdapterResources networkAdapterResources; + private NetworkAdapterObjectMapper networkAdapterObjectMapper; @Autowired private ExceptionBuilder exceptionUtil; @@ -54,14 +54,23 @@ public class NetworkAdapterUpdateTasks { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); - Optional oUpdateNetworkResponse = networkAdapterResources.updateNetwork(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, gBBInput.getUserInput(), gBBInput.getCustomer()); - if(oUpdateNetworkResponse.isPresent()) { - UpdateNetworkResponse updateNetworkResponse = oUpdateNetworkResponse.get(); - execution.setVariable("NetworkAdapterUpdateNetworkResponse", updateNetworkResponse); - } + UpdateNetworkRequest updateNetworkRequest = networkAdapterObjectMapper.createNetworkUpdateRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, gBBInput.getUserInput(), gBBInput.getCustomer()); + execution.setVariable("networkAdapterRequest", updateNetworkRequest); + } catch(Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + + public void processResponseFromOpenstack(BuildingBlockExecution execution) { + try { + UpdateNetworkResponse updateNetworkResponse = execution.getVariable("updateNetworkResponse"); + if(updateNetworkResponse == null) { + throw new Exception("No response was sent back from NetworkAdapterRestV1 subflow."); + } + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } } 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 73d7257632..a8a249f386 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 @@ -43,6 +43,7 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; @@ -456,6 +457,29 @@ public class AAIUpdateTasksTest extends BaseTaskTest{ String neutronSubnetId = createNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue(); assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId()); } + + @Test + public void updateNetworkUpdatedTest() throws Exception { + UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse(); + updateNetworkResponse.setNeutronNetworkId("testNeutronNetworkId"); + HashMap subnetMap = new HashMap<>(); + subnetMap.put("testSubnetId", "testNeutronSubnetId"); + updateNetworkResponse.setSubnetMap(subnetMap); + + network.getSubnets().add(subnet); + + execution.setVariable("updateNetworkResponse", updateNetworkResponse); + + doNothing().when(aaiNetworkResources).updateNetwork(network); + doNothing().when(aaiNetworkResources).updateSubnet(network, subnet); + + aaiUpdateTasks.updateNetworkUpdated(execution); + verify(aaiNetworkResources, times(1)).updateNetwork(network); + verify(aaiNetworkResources, times(1)).updateSubnet(network, subnet); + + String neutronSubnetId = updateNetworkResponse.getSubnetMap().entrySet().iterator().next().getValue(); + assertEquals(neutronSubnetId, network.getSubnets().get(0).getNeutronSubnetId()); + } @Test public void updateOrchestrationStatusNetworkTest() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java index 9f2f2fbdcc..478c512b0a 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterUpdateTasksTest.java @@ -24,6 +24,7 @@ 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.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.times; @@ -39,6 +40,8 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.UpdateNetworkRequest; import org.onap.so.adapters.nwrest.UpdateNetworkResponse; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; @@ -83,35 +86,15 @@ public class NetworkAdapterUpdateTasksTest extends BaseTaskTest{ @Test public void updateNetworkTest() throws Exception { - UpdateNetworkResponse updateNetworkResponse = new UpdateNetworkResponse(); - updateNetworkResponse.setMessageId("messageId"); - updateNetworkResponse.setNetworkId("networkId"); - Optional oUpdateNetworkResponse = Optional.of(updateNetworkResponse); - - doReturn(oUpdateNetworkResponse).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); - - networkAdapterUpdateTasks.updateNetwork(execution); - - verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); - assertEquals(updateNetworkResponse, execution.getVariable("NetworkAdapterUpdateNetworkResponse")); - } - - @Test - public void updateNetworkNoResponseTest() throws Exception { - doReturn(Optional.empty()).when(networkAdapterResources).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); - + String cloudRegionPo = "cloudRegionPo"; + UpdateNetworkRequest updateNetworkRequest = new UpdateNetworkRequest(); + execution.setVariable("cloudRegionPo", cloudRegionPo); + + doReturn(updateNetworkRequest).when(networkAdapterObjectMapper).createNetworkUpdateRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(Customer.class)); networkAdapterUpdateTasks.updateNetwork(execution); - - verify(networkAdapterResources, times(1)).updateNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); - assertNull(execution.getVariable("NetworkAdapterUpdateNetworkResponse")); + verify(networkAdapterObjectMapper, times(1)).createNetworkUpdateRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, network, userInput, customer); + assertEquals(updateNetworkRequest, execution.getVariable("networkAdapterRequest")); } - @Test - public void updateNetworkExceptionTest() throws UnsupportedEncodingException, NetworkAdapterClientException { - expectedException.expect(BpmnError.class); - doThrow(new NetworkAdapterClientException("ERROR")).when(networkAdapterResources).updateNetwork(any(RequestContext.class),any(CloudRegion.class), - any(OrchestrationContext.class),eq(serviceInstance),eq(network),any(Map.class),any(Customer.class)); - doThrow(new BpmnError("BPMN Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(Exception.class)); - networkAdapterUpdateTasks.updateNetwork(execution); - } + } -- cgit 1.2.3-korg