From e8df6b72e12189ff3d3ad81237deb8c8760aed1b Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Sun, 20 Jan 2019 18:30:39 -0500 Subject: convert from sync to async fixed network adapter object mapper test issues fixed all test issues and compilation issues remove setting of notification url for rollback covert sync calls for create and delete network to async removed async after from invoke sdnc adapter task remove unwanted changes that were committed earlier fix unmarshalling of response back from openstack adap added in code to throw an error when AIC issue Change-Id: Ic9fa39584ed2bcb70804fbd74586f1cc119c7d8b Issue-ID: SO-1404 Signed-off-by: Benjamin, Max (mb388a) --- .../main/resources/subprocess/SDNCAdapterV1.bpmn | 2 +- .../subprocess/BuildingBlock/CreateNetworkBB.bpmn | 95 ++++++---- .../subprocess/BuildingBlock/DeleteNetworkBB.bpmn | 52 ++++-- .../BuildingBlock/NetworkAdapterRestV1.bpmn | 198 +++++++++++++++++++++ .../network/tasks/NetworkAdapterCreateTasks.java | 34 ++-- .../network/tasks/NetworkAdapterDeleteTasks.java | 18 +- .../network/tasks/NetworkAdapterRestV1.java | 123 +++++++++++++ .../adapter/network/NetworkAdapterClient.java | 8 + .../adapter/network/NetworkAdapterClientImpl.java | 28 +++ .../network/mapper/NetworkAdapterObjectMapper.java | 22 ++- .../orchestration/NetworkAdapterResources.java | 27 +++ .../tasks/NetworkAdapterCreateTasksTest.java | 14 +- .../tasks/NetworkAdapterDeleteTasksTest.java | 26 +-- .../network/tasks/NetworkAdapterRestV1Test.java | 19 ++ .../mapper/NetworkAdapterObjectMapperTest.java | 56 ++++++ 15 files changed, 617 insertions(+), 105 deletions(-) create mode 100644 bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/NetworkAdapterRestV1.bpmn create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java diff --git a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn index 0032b0e0b7..0ef6c84494 100644 --- a/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn +++ b/bpmn/MSOCommonBPMN/src/main/resources/subprocess/SDNCAdapterV1.bpmn @@ -20,7 +20,7 @@ ExceptionUtil exceptionUtil = new ExceptionUtil() exceptionUtil.buildWorkflowException(execution, 7000, "Could not communicate with the SDNC Adapter" )]]> - + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkBB.bpmn index 21f2fbeeb9..52b9249468 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1maepy7 @@ -13,7 +13,7 @@ SequenceFlow_1eqfh23 - SequenceFlow_0innva6 + SequenceFlow_1fm99t6 SequenceFlow_0n42zi5 @@ -24,12 +24,11 @@ SequenceFlow_1h9kkhb - SequenceFlow_0innva6 + SequenceFlow_16152be SequenceFlow_0sissul - @@ -45,7 +44,7 @@ - SequenceFlow_04w6hdq + SequenceFlow_0y0w60u @@ -56,11 +55,27 @@ SequenceFlow_03ebe6c + + + + + + + SequenceFlow_1fm99t6 + SequenceFlow_0qpu80i + + + SequenceFlow_0qpu80i + SequenceFlow_16152be + + + + SequenceFlow_1h9kkhb - SequenceFlow_04w6hdq + SequenceFlow_0y0w60u - + @@ -73,9 +88,9 @@ - + - + @@ -91,7 +106,7 @@ - + @@ -107,18 +122,11 @@ - - - - - - - - - + + - + @@ -147,16 +155,16 @@ - + - + - + - + @@ -183,14 +191,41 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteNetworkBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteNetworkBB.bpmn index 95e481db4f..74b78ef735 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteNetworkBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/DeleteNetworkBB.bpmn @@ -5,19 +5,29 @@ SequenceFlow_1mc3d3f - SequenceFlow_1c906im + SequenceFlow_0gnafn2 SequenceFlow_0nhd7b7 - SequenceFlow_1mc3d3f - SequenceFlow_1c906im + SequenceFlow_16ti327 SequenceFlow_0nhd7b7 + + + + + + + SequenceFlow_16ti327 + SequenceFlow_0gnafn2 + + + @@ -38,24 +48,17 @@ - + - + - - - - - - - - + - + @@ -64,10 +67,27 @@ - + - + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/NetworkAdapterRestV1.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/NetworkAdapterRestV1.bpmn new file mode 100644 index 0000000000..583ec9444e --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/NetworkAdapterRestV1.bpmn @@ -0,0 +1,198 @@ + + + + + SequenceFlow_27 + + + + + + SequenceFlow_1286mqm + SequenceFlow_28 + + SequenceFlow_25 + SequenceFlow_26 + + + + + SequenceFlow_25 + + + + SequenceFlow_26 + + + + + + + SequenceFlow_34 + + + + SequenceFlow_06donih + + + SequenceFlow_9 + + + + SequenceFlow_9 + SequenceFlow_1286mqm + + + SequenceFlow_1qckanf + + + SequenceFlow_27 + SequenceFlow_34 + + + SequenceFlow_28 + SequenceFlow_06donih + + + + SequenceFlow_1qckanf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java index bc3845d760..4c531d46f9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java @@ -21,8 +21,8 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; import java.util.Map; -import java.util.Optional; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; @@ -30,24 +30,23 @@ 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.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class NetworkAdapterCreateTasks { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NetworkAdapterCreateTasks.class); @Autowired private ExtractPojosForBB extractPojosForBB; @Autowired - private NetworkAdapterResources networkAdapterResources; - @Autowired private ExceptionBuilder exceptionUtil; - - + @Autowired + private NetworkAdapterObjectMapper networkAdapterObjectMapper; + @Autowired + private NetworkAdapterResources networkAdapterResources; public void createNetwork(BuildingBlockExecution execution) { execution.setVariable("networkAdapterCreateRollback", false); @@ -59,18 +58,29 @@ public class NetworkAdapterCreateTasks { Map userInput = gBBInput.getUserInput(); String cloudRegionPo = execution.getVariable("cloudRegionPo"); - Optional oCreateNetworkResponse = networkAdapterResources.createNetwork(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, userInput, cloudRegionPo, gBBInput.getCustomer()); - if (oCreateNetworkResponse.isPresent()){ - CreateNetworkResponse createNetworkResponse = oCreateNetworkResponse.get(); + CreateNetworkRequest createNetworkRequest = networkAdapterObjectMapper.createNetworkRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, userInput, cloudRegionPo, gBBInput.getCustomer()); + + execution.setVariable("networkAdapterRequest", createNetworkRequest); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void processResponseFromOpenstack(BuildingBlockExecution execution) { + try { + L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); + + CreateNetworkResponse createNetworkResponse = execution.getVariable("createNetworkResponse"); + if(createNetworkResponse != null) { l3Network.setHeatStackId(createNetworkResponse.getNetworkStackId()); if (createNetworkResponse.getNetworkCreated()){ //setting rollback TRUE only if network was actually created (not a silent success OP) - execution.setVariable("createNetworkResponse", createNetworkResponse); execution.setVariable("networkAdapterCreateRollback", true); } + } else { + 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/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java index 1baa3f5dc9..41dabf9302 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java @@ -20,18 +20,15 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; -import java.util.Optional; - -import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; 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.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -42,7 +39,7 @@ public class NetworkAdapterDeleteTasks { @Autowired private ExtractPojosForBB extractPojosForBB; @Autowired - private NetworkAdapterResources networkAdapterResources; + private NetworkAdapterObjectMapper networkAdapterObjectMapper; @Autowired private ExceptionBuilder exceptionUtil; @@ -53,14 +50,9 @@ public class NetworkAdapterDeleteTasks { L3Network l3Network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID, execution.getLookupMap().get(ResourceKey.NETWORK_ID)); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); - Optional oDeleteNetworkResponse = networkAdapterResources.deleteNetwork(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, l3Network); + DeleteNetworkRequest deleteNetworkRequest = networkAdapterObjectMapper.deleteNetworkRequestMapper(gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, l3Network); - if (oDeleteNetworkResponse.isPresent()){ - DeleteNetworkResponse deleteNetworkResponse = oDeleteNetworkResponse.get(); - if (deleteNetworkResponse.getNetworkDeleted()) { - execution.setVariable("deleteNetworkResponse", deleteNetworkResponse); - } - } + execution.setVariable("networkAdapterRequest", deleteNetworkRequest); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java new file mode 100644 index 0000000000..d821223507 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java @@ -0,0 +1,123 @@ +package org.onap.so.bpmn.infrastructure.adapter.network.tasks; + +import java.io.StringReader; +import java.util.Optional; + +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.adapters.nwrest.CreateNetworkError; +import org.onap.so.adapters.nwrest.CreateNetworkRequest; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkError; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; +import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.NetworkAdapterResources; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NetworkAdapterRestV1 { + + private static final Logger logger = LoggerFactory.getLogger(NetworkAdapterRestV1.class); + + private static final String NETWORK_REQUEST = "networkAdapterRequest"; + private static final String NETWORK_MESSAGE = "NetworkAResponse_MESSAGE"; + private static final String NETWORK_SYNC_CODE = "NETWORKREST_networkAdapterStatusCode"; + private static final String NETWORK_SYNC_RESPONSE = "NETWORKREST_networkAdapterResponse"; + private static final String NETWORK_CORRELATOR = "NetworkAResponse_CORRELATOR"; + + @Autowired + private ExceptionBuilder exceptionBuilder; + + @Autowired + private NetworkAdapterResources networkAdapterResources; + + public void callNetworkAdapter (DelegateExecution execution) { + try { + Object networkAdapterRequest = execution.getVariable(NETWORK_REQUEST); + if (networkAdapterRequest != null) { + Optional response = Optional.empty(); + if (networkAdapterRequest instanceof CreateNetworkRequest) { + CreateNetworkRequest createNetworkRequest = (CreateNetworkRequest) networkAdapterRequest; + execution.setVariable(NETWORK_CORRELATOR, createNetworkRequest.getMessageId()); + response = networkAdapterResources.createNetworkAsync(createNetworkRequest); + } else if (networkAdapterRequest instanceof DeleteNetworkRequest) { + DeleteNetworkRequest deleteNetworkRequest = (DeleteNetworkRequest) networkAdapterRequest; + execution.setVariable(NETWORK_CORRELATOR, deleteNetworkRequest.getMessageId()); + response = networkAdapterResources.deleteNetworkAsync(deleteNetworkRequest); + } + if(response.isPresent()) { + String statusCode = Integer.toString(response.get().getStatus()); + String responseString = ""; + if(response.get().getEntity() != null) { + responseString = (String) response.get().getEntity(); + } + execution.setVariable(NETWORK_SYNC_CODE, statusCode); + execution.setVariable(NETWORK_SYNC_RESPONSE, responseString); + } else { + throw new Exception("No Ack response from Openstack Adapter"); + } + } else { + throw new Exception("No Network Request was created. networkAdapterRequest was null."); + } + } catch (Exception ex) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, ex.getStackTrace().toString()); + } + } + + public void processCallback (DelegateExecution execution) { + try { + Object networkAdapterRequest = execution.getVariable(NETWORK_REQUEST); + String callback = (String) execution.getVariable(NETWORK_MESSAGE); + String logCallbackMessage = "Callback from OpenstackAdapter: " + callback; + logger.debug(logCallbackMessage); + if (networkAdapterRequest != null) { + if (networkAdapterRequest instanceof CreateNetworkRequest) { + if(callback.contains("createNetworkError")) { + CreateNetworkError createNetworkError = (CreateNetworkError) unmarshalXml(callback, CreateNetworkError.class); + throw new Exception(createNetworkError.getMessage()); + } else { + CreateNetworkResponse createNetworkResponse = (CreateNetworkResponse) unmarshalXml(callback, CreateNetworkResponse.class); + execution.setVariable("createNetworkResponse", createNetworkResponse); + } + } else if (networkAdapterRequest instanceof DeleteNetworkRequest) { + if(callback.contains("deleteNetworkError")) { + DeleteNetworkError deleteNetworkError = (DeleteNetworkError) unmarshalXml(callback, DeleteNetworkError.class); + throw new Exception(deleteNetworkError.getMessage()); + } else { + DeleteNetworkResponse deleteNetworkResponse = (DeleteNetworkResponse) unmarshalXml(callback, DeleteNetworkResponse.class); + execution.setVariable("deleteNetworkResponse", deleteNetworkResponse); + } + } + } + } catch (Exception e) { + logger.error("Error in Openstack Adapter callback", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage()); + } + } + + protected Object unmarshalXml(String xmlString, Class resultClass) throws JAXBException { + StringReader reader = new StringReader(xmlString); + JAXBContext context = JAXBContext.newInstance(resultClass); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return unmarshaller.unmarshal(reader); + } + + public void handleTimeOutException (DelegateExecution execution) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, "Error timed out waiting on Openstack Async-Response"); + } + + public void handleSyncError (DelegateExecution execution) { + String statusCode = (String) execution.getVariable(NETWORK_SYNC_CODE); + String responseString = (String) execution.getVariable(NETWORK_SYNC_RESPONSE); + String errorMessage = "Error with Openstack Adapter Sync Request: StatusCode = " + statusCode + " Response = " + responseString; + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, errorMessage); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClient.java index 45f28df756..cdb24401b3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClient.java @@ -20,6 +20,8 @@ package org.onap.so.client.adapter.network; +import javax.ws.rs.core.Response; + import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; @@ -44,4 +46,10 @@ public interface NetworkAdapterClient { UpdateNetworkResponse updateNetwork(String aaiNetworkId, UpdateNetworkRequest req) throws NetworkAdapterClientException; + + Response createNetworkAsync(CreateNetworkRequest req) throws NetworkAdapterClientException; + + Response deleteNetworkAsync(String aaiNetworkId, DeleteNetworkRequest req) throws NetworkAdapterClientException; + + Response rollbackNetworkAsync(String aaiNetworkId, RollbackNetworkRequest req) throws NetworkAdapterClientException; } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java index 9b052b4484..7092fe04c6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java @@ -22,6 +22,7 @@ package org.onap.so.client.adapter.network; import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import org.onap.so.adapters.nwrest.CreateNetworkRequest; @@ -54,6 +55,15 @@ public class NetworkAdapterClientImpl implements NetworkAdapterClient { throw new NetworkAdapterClientException(e.getMessage()); } } + + @Override + public Response createNetworkAsync(CreateNetworkRequest req) throws NetworkAdapterClientException{ + try { + return new AdapterRestClient(this.props, this.getUri("").build()).post(req); + } catch (InternalServerErrorException e) { + throw new NetworkAdapterClientException(e.getMessage()); + } + } @Override public DeleteNetworkResponse deleteNetwork(String aaiNetworkId, DeleteNetworkRequest req) throws NetworkAdapterClientException { @@ -64,6 +74,15 @@ public class NetworkAdapterClientImpl implements NetworkAdapterClient { throw new NetworkAdapterClientException(e.getMessage()); } } + + @Override + public Response deleteNetworkAsync(String aaiNetworkId, DeleteNetworkRequest req) throws NetworkAdapterClientException { + try { + return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req); + } catch (InternalServerErrorException e) { + throw new NetworkAdapterClientException(e.getMessage()); + } + } @Override public RollbackNetworkResponse rollbackNetwork(String aaiNetworkId, RollbackNetworkRequest req) throws NetworkAdapterClientException { @@ -74,6 +93,15 @@ public class NetworkAdapterClientImpl implements NetworkAdapterClient { throw new NetworkAdapterClientException(e.getMessage()); } } + + @Override + public Response rollbackNetworkAsync(String aaiNetworkId, RollbackNetworkRequest req) throws NetworkAdapterClientException { + try { + return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req); + } catch (InternalServerErrorException e) { + throw new NetworkAdapterClientException(e.getMessage()); + } + } @Override public QueryNetworkResponse queryNetwork(String aaiNetworkId, String cloudSiteId, String tenantId, diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java index 3081ab86d8..794314bf8c 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; +import org.apache.commons.lang3.StringUtils; import org.modelmapper.ModelMapper; import org.modelmapper.PropertyMap; import org.onap.so.adapters.nwrest.ContrailNetwork; @@ -106,8 +107,7 @@ public class NetworkAdapterObjectMapper { String messageId = getRandomUuid(); createNetworkRequest.setMessageId(messageId); - //TODO clarify callback URL build process - //createNetworkRequest.setNotificationUrl(createCallbackUrl("NetworkAResponse", messageId)); + createNetworkRequest.setNotificationUrl(createCallbackUrl("NetworkAResponse", messageId)); return createNetworkRequest; } @@ -137,11 +137,18 @@ public class NetworkAdapterObjectMapper { deleteNetworkRequest.setMsoRequest(createMsoRequest(requestContext, serviceInstance)); deleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); - deleteNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + if (!StringUtils.isEmpty(l3Network.getHeatStackId())){ + deleteNetworkRequest.setNetworkStackId(l3Network.getHeatStackId()); + } + else { + deleteNetworkRequest.setNetworkStackId(l3Network.getNetworkName()); + } deleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); deleteNetworkRequest.setSkipAAI(true); deleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); + deleteNetworkRequest.setNotificationUrl(createCallbackUrl("NetworkAResponse", messageId)); + return deleteNetworkRequest; } @@ -187,11 +194,10 @@ public class NetworkAdapterObjectMapper { return updateNetworkRequest; } - private RollbackNetworkRequest setCommonRollbackRequestFields(RollbackNetworkRequest request,RequestContext requestContext){ - //TODO confirm flag value + private RollbackNetworkRequest setCommonRollbackRequestFields(RollbackNetworkRequest request,RequestContext requestContext) throws UnsupportedEncodingException{ request.setSkipAAI(true); - request.setMessageId(requestContext.getMsoRequestId()); - //TODO clarify callback URL build process. This will also set SYNC flag + String messageId = requestContext.getMsoRequestId(); + request.setMessageId(messageId); //request.setNotificationUrl(createCallbackUrl("NetworkAResponse", messageId)); return request; } @@ -365,4 +371,4 @@ public class NetworkAdapterObjectMapper { updateNetworkRequest.setBackout(Boolean.TRUE.equals(orchestrationContext.getIsRollbackEnabled())); //NetworkTechnology(NetworkTechnology.NEUTRON); NOOP - default } -} +} \ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NetworkAdapterResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NetworkAdapterResources.java index 64a86fc731..feb6ed4013 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NetworkAdapterResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NetworkAdapterResources.java @@ -24,6 +24,8 @@ import java.io.UnsupportedEncodingException; import java.util.Map; import java.util.Optional; +import javax.ws.rs.core.Response; + import org.onap.so.adapters.nwrest.CreateNetworkRequest; import org.onap.so.adapters.nwrest.CreateNetworkResponse; import org.onap.so.adapters.nwrest.DeleteNetworkRequest; @@ -79,4 +81,29 @@ public class NetworkAdapterResources { DeleteNetworkRequest deleteNetworkRequest = networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); return Optional.of(networkAdapterClient.deleteNetwork(l3Network.getNetworkId(), deleteNetworkRequest)); } + + public Optional createNetworkAsync(CreateNetworkRequest createNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException { + + return Optional.of(networkAdapterClient.createNetworkAsync(createNetworkRequest)); + } + + public Optional deleteNetworkAsync(DeleteNetworkRequest deleteNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException { + + return Optional.of(networkAdapterClient.deleteNetworkAsync(deleteNetworkRequest.getNetworkId(), deleteNetworkRequest)); + } + + public Optional rollbackCreateNetwork(String networkId, RollbackNetworkRequest rollbackNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException { + + return Optional.of(networkAdapterClient.rollbackNetwork(networkId, rollbackNetworkRequest)); + } + + public Optional updateNetwork(UpdateNetworkRequest updateNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException { + + return Optional.of(networkAdapterClient.updateNetwork(updateNetworkRequest.getNetworkId(), updateNetworkRequest)); + } + + public Optional deleteNetwork(DeleteNetworkRequest deleteNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException { + + return Optional.of(networkAdapterClient.deleteNetwork(deleteNetworkRequest.getNetworkId(), deleteNetworkRequest)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java index 3dc03b2988..3034f0bd67 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java @@ -20,7 +20,9 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -33,6 +35,7 @@ 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.CreateNetworkResponse; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; @@ -76,17 +79,14 @@ public class NetworkAdapterCreateTasksTest extends BaseTaskTest{ @Test public void createNetworkTest() throws Exception { - CreateNetworkResponse createNetworkResponse = new CreateNetworkResponse(); - createNetworkResponse.setNetworkStackId("networkStackId"); - createNetworkResponse.setNetworkCreated(true); - Optional oCreateNetworkResponse = Optional.of(createNetworkResponse); - String cloudRegionPo = "cloudRegionPo"; + CreateNetworkRequest createNetworkRequest = new CreateNetworkRequest(); execution.setVariable("cloudRegionPo", cloudRegionPo); - doReturn(oCreateNetworkResponse).when(networkAdapterResources).createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo,customer); + doReturn(createNetworkRequest).when(networkAdapterObjectMapper).createNetworkRequestMapper(isA(RequestContext.class), isA(CloudRegion.class), isA(OrchestrationContext.class), isA(ServiceInstance.class), isA(L3Network.class), isA(Map.class), isA(String.class), isA(Customer.class)); networkAdapterCreateTasks.createNetwork(execution); - verify(networkAdapterResources, times(1)).createNetwork(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo,customer); + verify(networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); + assertEquals(createNetworkRequest, execution.getVariable("networkAdapterRequest")); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java index 33a2e6a7a8..5b534e00e7 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java @@ -20,10 +20,8 @@ package org.onap.so.bpmn.infrastructure.adapter.network.tasks; -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.times; @@ -31,7 +29,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.io.UnsupportedEncodingException; -import java.util.Optional; import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; @@ -39,17 +36,16 @@ import org.junit.Test; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.onap.so.adapters.nwrest.DeleteNetworkResponse; +import org.onap.so.adapters.nwrest.DeleteNetworkRequest; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; -import org.onap.so.client.adapter.network.NetworkAdapterClientException; -import org.onap.so.client.exception.BBObjectNotFoundException; -import org.onap.so.client.orchestration.NetworkAdapterResources; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.adapter.network.NetworkAdapterClientException; +import org.onap.so.client.exception.BBObjectNotFoundException; public class NetworkAdapterDeleteTasksTest extends BaseTaskTest{ @@ -77,25 +73,19 @@ public class NetworkAdapterDeleteTasksTest extends BaseTaskTest{ @Test public void test_deleteNetwork() throws UnsupportedEncodingException, NetworkAdapterClientException { - DeleteNetworkResponse deleteNetworkResponse = new DeleteNetworkResponse(); - deleteNetworkResponse.setNetworkDeleted(true); - deleteNetworkResponse.setNetworkId(l3Network.getNetworkId()); - Optional oDeleteNetworkResponse = Optional.of(deleteNetworkResponse); - - when(networkAdapterResources.deleteNetwork(any(RequestContext.class), any(CloudRegion.class), eq(serviceInstance), eq(l3Network))).thenReturn(oDeleteNetworkResponse); + DeleteNetworkRequest deleteNetworkRequest = new DeleteNetworkRequest(); + doReturn(deleteNetworkRequest).when(networkAdapterObjectMapper).deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); networkAdapterDeleteTasks.deleteNetwork(execution); - - verify(networkAdapterResources, times(1)).deleteNetwork(requestContext, cloudRegion, serviceInstance, l3Network); - assertEquals(deleteNetworkResponse, execution.getVariable("deleteNetworkResponse")); + verify(networkAdapterObjectMapper, times(1)).deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); } @Test public void test_deleteNetwork_exception() throws UnsupportedEncodingException, NetworkAdapterClientException { expectedException.expect(BpmnError.class); - doThrow(NetworkAdapterClientException.class).when(networkAdapterResources). - deleteNetwork(any(RequestContext.class), any(CloudRegion.class), any(ServiceInstance.class), eq(l3Network)); + doThrow(RuntimeException.class).when(networkAdapterObjectMapper). + deleteNetworkRequestMapper(any(RequestContext.class), any(CloudRegion.class), any(ServiceInstance.class), eq(l3Network)); networkAdapterDeleteTasks.deleteNetwork(execution); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java new file mode 100644 index 0000000000..2ba8cb4b57 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java @@ -0,0 +1,19 @@ +package org.onap.so.bpmn.infrastructure.adapter.network.tasks; + +import java.io.IOException; + +import javax.xml.bind.JAXBException; + +import org.junit.Test; +import org.onap.so.adapters.nwrest.CreateNetworkResponse; + +public class NetworkAdapterRestV1Test { + + @Test + public void testUnmarshalXml() throws IOException, JAXBException { + String xml = "ec37c121-e3ec-4697-8adf-2d7dca7044fctruesomeNetworkFqdn991ec7bf-c9c4-4ac1-bb9c-4b61645bddb3someStackId9c47521a-2916-4018-b2bc-71ab767497e3someCloudIdb7171cdd-8b05-459b-80ef-2093150e898390b32315-176e-4dab-bcf1-80eb97a1c4f471e7db22-7907-4d78-8fcc-8d89d28e90betruesomeStackIdSomeNetworkType9c47521a-2916-4018-b2bc-71ab767497e3b60da4f71c1d4b35b8113d4eca6deaa16b381fa9-48ce-4e16-9978-d75309565bb6bc1d5537-860b-4894-8eba-6faff41e648c"; + CreateNetworkResponse response = (CreateNetworkResponse) new NetworkAdapterRestV1().unmarshalXml(xml, CreateNetworkResponse.class); + String returnedXml = response.toXmlString(); + System.out.println(returnedXml); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java index 6f353fa622..1a86d713a2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java @@ -22,6 +22,7 @@ package org.onap.so.client.adapter.network.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.*; +import static org.mockito.Matchers.isA; import static org.mockito.Mockito.doReturn; import java.io.UnsupportedEncodingException; @@ -135,6 +136,8 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ expectedCreateNetworkRequest.setMsoRequest(msoRequest); expectedCreateNetworkRequest.setSkipAAI(true); + expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + Subnet openstackSubnet = new Subnet(); HostRoute hostRoute = new HostRoute(); hostRoute.setHostRouteId("hostRouteId"); @@ -146,6 +149,9 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ l3Network.getSubnets().add(openstackSubnet); l3Network.setNetworkTechnology("Contrail"); + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, l3Network, userInput, cloudRegionPo, customer); assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("contrailRequest").ignoring("contrailNetwork").ignoring("providerVlanNetwork").ignoring("subnets").ignoring("networkParams").ignoring("messageId")); @@ -295,6 +301,51 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); + + assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); + } + + @Test + public void deleteNetworkRequestNoHeatIdMapperTest() throws Exception { + DeleteNetworkRequest expectedDeleteNetworkRequest = new DeleteNetworkRequest(); + + String messageId = "messageId"; + expectedDeleteNetworkRequest.setMessageId(messageId); + doReturn(messageId).when(SPY_networkAdapterObjectMapper).getRandomUuid(); + + ModelInfoNetwork modelInfoNetwork = new ModelInfoNetwork(); + l3Network.setModelInfoNetwork(modelInfoNetwork); + modelInfoNetwork.setModelCustomizationUUID("modelCustomizationUuid"); + expectedDeleteNetworkRequest.setModelCustomizationUuid(modelInfoNetwork.getModelCustomizationUUID()); + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(requestContext.getMsoRequestId()); + msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId()); + expectedDeleteNetworkRequest.setMsoRequest(msoRequest); + + expectedDeleteNetworkRequest.setNetworkId(l3Network.getNetworkId()); + + l3Network.setNetworkName("heatStackId"); + expectedDeleteNetworkRequest.setNetworkStackId("heatStackId"); + + expectedDeleteNetworkRequest.setNetworkType(l3Network.getNetworkType()); + + expectedDeleteNetworkRequest.setSkipAAI(true); + + expectedDeleteNetworkRequest.setTenantId(cloudRegion.getTenantId()); + + expectedDeleteNetworkRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId()); + + expectedDeleteNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); DeleteNetworkRequest deleteNetworkRequest = SPY_networkAdapterObjectMapper.deleteNetworkRequestMapper(requestContext, cloudRegion, serviceInstance, l3Network); assertThat(expectedDeleteNetworkRequest, sameBeanAs(deleteNetworkRequest)); @@ -316,6 +367,11 @@ public class NetworkAdapterObjectMapperTest extends TestDataSetup{ org.onap.so.adapters.nwrest.CreateNetworkRequest.class); String cloudRegionPo = "cloudRegionPo"; + + expectedCreateNetworkRequest.setNotificationUrl("endpoint/NetworkAResponse/messageId"); + + doReturn("endpoint/").when(SPY_networkAdapterObjectMapper).getEndpoint(); + doReturn("messageId").when(SPY_networkAdapterObjectMapper).getRandomUuid(); CreateNetworkRequest createNetworkRequest = SPY_networkAdapterObjectMapper.createNetworkRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, myNetwork, userInput, cloudRegionPo, customer); //ignoring dynamic fields and networkParams that throws parsing exception on json file load assertThat(createNetworkRequest, sameBeanAs(expectedCreateNetworkRequest).ignoring("messageId").ignoring("msoRequest.requestId").ignoring("networkParams")); -- cgit 1.2.3-korg