diff options
author | Boslet, Cory <cory.boslet@att.com> | 2020-04-16 10:43:38 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-04-16 10:43:44 -0400 |
commit | fa9a707c87654330dfb5788a6029b8199c6cdf17 (patch) | |
tree | ebd981e12166281957b47353a45b6b3c9b3ee490 /bpmn/so-bpmn-tasks/src/main/java/org/onap | |
parent | b0f5ac59c297f81b7f17c1f367e64257ef7be2d2 (diff) |
move network adapter to an external client task
Began impelenting new network external task.
Made the vnfAdapterTask subflow an openstack subflow, refactored infra
flows and BB to call it for network functions.
Fixed bugs discovered through a robot dry run, added unit test, added
support for rollback network request
Updated junit test files for comparison due to not polling for response
Removed the no longer used network adapter rest task from bpmn tasks
Removed the unused network adapter async and its beans
Removed network async client package from open pojo scan
Issue-ID: SO-2813
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I4c25892012cc86659ab122448ed1aca5cab91671
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org/onap')
5 files changed, 108 insertions, 170 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 0ec28d901c..fb5c81a52e 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 @@ -63,7 +63,7 @@ public class NetworkAdapterCreateTasks { gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, userInput, cloudRegionPo, gBBInput.getCustomer()); - execution.setVariable("networkAdapterRequest", createNetworkRequest); + execution.setVariable("networkAdapterRequest", createNetworkRequest.toXmlString()); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } @@ -81,13 +81,14 @@ public class NetworkAdapterCreateTasks { execution.setVariable("networkAdapterCreateRollback", true); } } else { - throw new Exception("No response was sent back from NetworkAdapterRestV1 subflow."); + throw new Exception("No response was sent back from NetworkAdapter subflow."); } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + // TODO is this even used anywhere? public void rollbackCreateNetwork(BuildingBlockExecution execution) { try { GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); 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 7a7d681762..df5e7d2b34 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 @@ -53,7 +53,7 @@ public class NetworkAdapterDeleteTasks { DeleteNetworkRequest deleteNetworkRequest = networkAdapterObjectMapper.deleteNetworkRequestMapper( gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, l3Network); - execution.setVariable("networkAdapterRequest", deleteNetworkRequest); + execution.setVariable("networkAdapterRequest", deleteNetworkRequest.toXmlString()); } 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/NetworkAdapterImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java new file mode 100644 index 0000000000..5a84910a29 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterImpl.java @@ -0,0 +1,103 @@ +package org.onap.so.bpmn.infrastructure.adapter.network.tasks; + +import java.io.ByteArrayInputStream; +import java.io.StringReader; +import java.util.Optional; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +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.adapters.nwrest.UpdateNetworkError; +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.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.exception.ExceptionBuilder; +import org.onap.so.utils.Components; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NetworkAdapterImpl { + + private static final Logger logger = LoggerFactory.getLogger(NetworkAdapterImpl.class); + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private ExceptionBuilder exceptionUtil; + + public void preProcessNetworkAdapter(BuildingBlockExecution execution) { + try { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + execution.setVariable("mso-request-id", gBBInput.getRequestContext().getMsoRequestId()); + execution.setVariable("mso-service-instance-id", serviceInstance.getServiceInstanceId()); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void postProcessNetworkAdapter(BuildingBlockExecution execution) { + try { + String workflowResponse = (String) execution.getVariable("WorkflowResponse"); + if (workflowResponse != null) { + Optional<String> responseType = findResponseType(workflowResponse); + if ("createNetworkResponse".equals(responseType.get())) { + CreateNetworkResponse createNetworkResponse = + (CreateNetworkResponse) unmarshalXml(workflowResponse, CreateNetworkResponse.class); + execution.setVariable("createNetworkResponse", createNetworkResponse); + } else if ("deleteNetworkResponse".equals(responseType.get())) { + DeleteNetworkResponse deleteNetworkResponse = + (DeleteNetworkResponse) unmarshalXml(workflowResponse, DeleteNetworkResponse.class); + execution.setVariable("deleteNetworkResponse", deleteNetworkResponse); + } else if ("updateNetworkResponse".equals(responseType.get())) { + UpdateNetworkResponse updateNetworkResponse = + (UpdateNetworkResponse) unmarshalXml(workflowResponse, UpdateNetworkResponse.class); + execution.setVariable("updateNetworkResponse", updateNetworkResponse); + } else { + logger.warn("Unable to determine network response type"); + } + } + } catch (Exception e) { + logger.error("Error Network Adapter post process", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), Components.OPENSTACK); + } + } + + 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); + } + + protected Optional<String> findResponseType(String xmlString) { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + org.w3c.dom.Document doc; + doc = builder.parse(new ByteArrayInputStream(xmlString.getBytes("UTF-8"))); + return Optional.of(doc.getDocumentElement().getNodeName()); + } catch (Exception e) { + logger.error("Error Finding Response Type", e); + return Optional.empty(); + } + } + +} 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 deleted file mode 100644 index 2705d00d6b..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterRestV1.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.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.adapters.nwrest.UpdateNetworkError; -import org.onap.so.adapters.nwrest.UpdateNetworkRequest; -import org.onap.so.adapters.nwrest.UpdateNetworkResponse; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.orchestration.NetworkAdapterResources; -import org.onap.logging.filter.base.ONAPComponents; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.onap.so.utils.Components; - -@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); - } else if (networkAdapterRequest instanceof UpdateNetworkRequest) { - UpdateNetworkRequest updateNetworkRequest = (UpdateNetworkRequest) networkAdapterRequest; - execution.setVariable(NETWORK_CORRELATOR, updateNetworkRequest.getMessageId()); - response = networkAdapterResources.updateNetworkAsync(updateNetworkRequest); - } - 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, ONAPComponents.SO); - } - } - - 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); - } - } else if (networkAdapterRequest instanceof UpdateNetworkRequest) { - if (callback.contains("updateNetworkError")) { - UpdateNetworkError updateNetworkError = - (UpdateNetworkError) unmarshalXml(callback, UpdateNetworkError.class); - throw new Exception(updateNetworkError.getMessage()); - } else { - UpdateNetworkResponse updateNetworkResponse = - (UpdateNetworkResponse) unmarshalXml(callback, UpdateNetworkResponse.class); - execution.setVariable("updateNetworkResponse", updateNetworkResponse); - } - } - } - } catch (Exception e) { - logger.error("Error in Openstack Adapter callback", e); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e.getMessage(), Components.OPENSTACK); - } - } - - 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", ONAPComponents.SO); - } - - 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, Components.OPENSTACK); - } -} 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 e238a4fdd3..c64491f71a 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 @@ -55,7 +55,7 @@ public class NetworkAdapterUpdateTasks { UpdateNetworkRequest updateNetworkRequest = networkAdapterObjectMapper.createNetworkUpdateRequestMapper( gBBInput.getRequestContext(), gBBInput.getCloudRegion(), gBBInput.getOrchContext(), serviceInstance, l3Network, gBBInput.getUserInput(), gBBInput.getCustomer()); - execution.setVariable("networkAdapterRequest", updateNetworkRequest); + execution.setVariable("networkAdapterRequest", updateNetworkRequest.toXmlString()); } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); |