aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java34
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java123
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClient.java8
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java28
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java22
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/NetworkAdapterResources.java27
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasksTest.java14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasksTest.java26
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1Test.java19
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapperTest.java56
11 files changed, 317 insertions, 58 deletions
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<String, String> userInput = gBBInput.getUserInput();
String cloudRegionPo = execution.getVariable("cloudRegionPo");
- Optional<CreateNetworkResponse> 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<DeleteNetworkResponse> 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> 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 <T> Object unmarshalXml(String xmlString, Class<T> 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<Response> createNetworkAsync(CreateNetworkRequest createNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException {
+
+ return Optional.of(networkAdapterClient.createNetworkAsync(createNetworkRequest));
+ }
+
+ public Optional<Response> deleteNetworkAsync(DeleteNetworkRequest deleteNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException {
+
+ return Optional.of(networkAdapterClient.deleteNetworkAsync(deleteNetworkRequest.getNetworkId(), deleteNetworkRequest));
+ }
+
+ public Optional<RollbackNetworkResponse> rollbackCreateNetwork(String networkId, RollbackNetworkRequest rollbackNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException {
+
+ return Optional.of(networkAdapterClient.rollbackNetwork(networkId, rollbackNetworkRequest));
+ }
+
+ public Optional<UpdateNetworkResponse> updateNetwork(UpdateNetworkRequest updateNetworkRequest) throws UnsupportedEncodingException, NetworkAdapterClientException {
+
+ return Optional.of(networkAdapterClient.updateNetwork(updateNetworkRequest.getNetworkId(), updateNetworkRequest));
+ }
+
+ public Optional<DeleteNetworkResponse> 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<CreateNetworkResponse> 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<DeleteNetworkResponse> 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><createNetworkResponse><messageId>ec37c121-e3ec-4697-8adf-2d7dca7044fc</messageId><networkCreated>true</networkCreated><networkFqdn>someNetworkFqdn</networkFqdn><networkId>991ec7bf-c9c4-4ac1-bb9c-4b61645bddb3</networkId><networkStackId>someStackId</networkStackId><neutronNetworkId>9c47521a-2916-4018-b2bc-71ab767497e3</neutronNetworkId><rollback><cloudId>someCloudId</cloudId><modelCustomizationUuid>b7171cdd-8b05-459b-80ef-2093150e8983</modelCustomizationUuid><msoRequest><requestId>90b32315-176e-4dab-bcf1-80eb97a1c4f4</requestId><serviceInstanceId>71e7db22-7907-4d78-8fcc-8d89d28e90be</serviceInstanceId></msoRequest><networkCreated>true</networkCreated><networkStackId>someStackId</networkStackId><networkType>SomeNetworkType</networkType><neutronNetworkId>9c47521a-2916-4018-b2bc-71ab767497e3</neutronNetworkId><tenantId>b60da4f71c1d4b35b8113d4eca6deaa1</tenantId></rollback><subnetMap><entry><key>6b381fa9-48ce-4e16-9978-d75309565bb6</key><value>bc1d5537-860b-4894-8eba-6faff41e648c</value></entry></subnetMap></createNetworkResponse>";
+ 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"));