Search in sources :

Example 1 with UpdateNetworkResponse

use of org.onap.so.adapters.nwrest.UpdateNetworkResponse in project so by onap.

the class NetworkAdapterImpl method postProcessNetworkAdapter.

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);
    }
}
Also used : DeleteNetworkResponse(org.onap.so.adapters.nwrest.DeleteNetworkResponse) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) JAXBException(javax.xml.bind.JAXBException)

Example 2 with UpdateNetworkResponse

use of org.onap.so.adapters.nwrest.UpdateNetworkResponse in project so by onap.

the class PollService method executeExternalTask.

public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
    mdcSetup.setupMDC(externalTask);
    logger.debug("Starting External Task Poll Service");
    Map<String, Object> variables = new HashMap<>();
    MutableBoolean success = new MutableBoolean();
    String errorMessage = null;
    Optional<String> response = Optional.empty();
    boolean isMulticloud = false;
    try {
        String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
        if (xmlRequest != null) {
            Optional<String> requestType = findRequestType(xmlRequest);
            if ("createVolumeGroupRequest".equals(requestType.get())) {
                CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
                isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                response = determineCreateVolumeGroupStatus(req, externalTask, success, isMulticloud);
            } else if ("createVfModuleRequest".equals(requestType.get())) {
                CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
                isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                response = determineCreateVfModuleStatus(req, externalTask, success, isMulticloud);
            } else if ("deleteVfModuleRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Poll Service for Delete Vf Module");
                String stackId = externalTask.getVariable("stackId");
                DeleteVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVfModuleRequest.class);
                isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    int timeoutMinutes = msoHeatUtils.getVfHeatTimeoutValue(req.getModelCustomizationUuid(), false);
                    StackInfo stack = pollDeleteResource(timeoutMinutes, req.getCloudSiteId(), req.getTenantId(), stackId, success);
                    DeleteVfModuleResponse deleteResponse = new DeleteVfModuleResponse(req.getVnfId(), req.getVfModuleId(), Boolean.TRUE, req.getMessageId(), vnfAdapterImpl.copyStringOutputs(stack.getOutputs()));
                    response = Optional.of(deleteResponse.toXmlString());
                }
            } else if ("deleteVolumeGroupRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Poll Service for Delete Volume Group");
                String stackId = externalTask.getVariable("stackId");
                DeleteVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteVolumeGroupRequest.class);
                isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success);
                    DeleteVolumeGroupResponse deleteResponse = new DeleteVolumeGroupResponse(true, req.getMessageId());
                    response = Optional.of(deleteResponse.toXmlString());
                }
            } else if ("createNetworkRequest".equals(requestType.get())) {
                CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
                response = determineCreateNetworkStatus(req, externalTask, success);
            } else if ("deleteNetworkRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Poll Service for Delete Network");
                String stackId = externalTask.getVariable("stackId");
                DeleteNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), DeleteNetworkRequest.class);
                pollDeleteResource(118, req.getCloudSiteId(), req.getTenantId(), stackId, success);
                DeleteNetworkResponse deleteResponse = new DeleteNetworkResponse(req.getNetworkId(), true, req.getMessageId());
                response = Optional.of(deleteResponse.toXmlString());
            } else if ("updateNetworkRequest".equals(requestType.get())) {
                UpdateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), UpdateNetworkRequest.class);
                pollUpdateResource(req.getCloudSiteId(), req.getTenantId(), externalTask, success);
                UpdateNetworkResponse updateResponse = new UpdateNetworkResponse(req.getNetworkId(), null, null, req.getMessageId());
                response = Optional.of(updateResponse.toXmlString());
            } else if ("rollbackNetworkRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Poll Service for Rollback Network");
                String stackId = externalTask.getVariable("stackId");
                RollbackNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), RollbackNetworkRequest.class);
                pollDeleteResource(118, req.getNetworkRollback().getCloudId(), req.getNetworkRollback().getTenantId(), stackId, success);
            }
        }
    } catch (Exception e) {
        logger.error("Error during External Task Poll Service", e);
        errorMessage = e.toString();
        variables.put("openstackAdapterErrorMessage", errorMessage);
    }
    if (isMulticloud) {
        success.setTrue();
    }
    if (response.isPresent()) {
        variables.put("WorkflowResponse", response.get());
    }
    variables.put("OpenstackPollSuccess", success.booleanValue());
    if (success.isTrue()) {
        externalTaskService.complete(externalTask, variables);
        logger.debug("The External Task Id: {}  Successful", externalTask.getId());
    } else {
        if (externalTask.getRetries() == null) {
            logger.debug("The External Task Id: {}  Failed, Setting Retries to Default Start Value: {}", externalTask.getId(), getRetrySequence().length);
            externalTaskService.handleFailure(externalTask, "errorMessage", "errorDetails", getRetrySequence().length, 10000);
        } else if (externalTask.getRetries() != null && externalTask.getRetries() - 1 == 0) {
            logger.debug("The External Task Id: {}  Failed, All Retries Exhausted", externalTask.getId());
            externalTaskService.complete(externalTask, variables);
        } else {
            logger.debug("The External Task Id: {}  Failed, Decrementing Retries: {} , Retry Delay: {}", externalTask.getId(), externalTask.getRetries() - 1, calculateRetryDelay(externalTask.getRetries()));
            externalTaskService.handleFailure(externalTask, "errorMessage", "errorDetails", externalTask.getRetries() - 1, calculateRetryDelay(externalTask.getRetries()));
        }
    }
}
Also used : DeleteNetworkResponse(org.onap.so.adapters.nwrest.DeleteNetworkResponse) CreateVolumeGroupRequest(org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) RollbackNetworkRequest(org.onap.so.adapters.nwrest.RollbackNetworkRequest) DeleteVolumeGroupResponse(org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse) DeleteVfModuleResponse(org.onap.so.adapters.vnfrest.DeleteVfModuleResponse) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) MsoException(org.onap.so.openstack.exceptions.MsoException) CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) DeleteNetworkRequest(org.onap.so.adapters.nwrest.DeleteNetworkRequest) StringReader(java.io.StringReader) DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) StackInfo(org.onap.so.openstack.beans.StackInfo) DeleteVfModuleRequest(org.onap.so.adapters.vnfrest.DeleteVfModuleRequest)

Example 3 with UpdateNetworkResponse

use of org.onap.so.adapters.nwrest.UpdateNetworkResponse in project so by onap.

the class NetworkAdapterClientIT method updateNetworkTest.

@Test
public void updateNetworkTest() throws NetworkAdapterClientException, JsonProcessingException {
    UpdateNetworkRequest request = new UpdateNetworkRequest();
    request.setCloudSiteId(TESTING_ID);
    request.setNetworkId("test1");
    UpdateNetworkResponse mockResponse = new UpdateNetworkResponse();
    mockResponse.setNetworkId("test1");
    wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(200)));
    UpdateNetworkResponse response = client.updateNetwork(AAI_NETWORK_ID, request);
    assertEquals("Testing UpdateVfModule response", "test1", response.getNetworkId());
}
Also used : UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) BaseIntegrationTest(org.onap.so.BaseIntegrationTest) Test(org.junit.Test)

Example 4 with UpdateNetworkResponse

use of org.onap.so.adapters.nwrest.UpdateNetworkResponse in project so by onap.

the class AAIUpdateTasks method updateNetworkUpdated.

/**
 * BPMN access method to update L3Network after it was updated in cloud
 */
public void updateNetworkUpdated(BuildingBlockExecution execution) throws Exception {
    L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
    L3Network copiedl3network = l3network.shallowCopyId();
    UpdateNetworkResponse response = execution.getVariable("updateNetworkResponse");
    try {
        copiedl3network.setNeutronNetworkId(response.getNeutronNetworkId());
        aaiNetworkResources.updateNetwork(copiedl3network);
        Map<String, String> subnetMap = response.getSubnetMap();
        List<Subnet> subnets = l3network.getSubnets();
        if (subnets != null && subnetMap != null) {
            for (Subnet subnet : subnets) {
                Subnet copiedSubnet = subnet.shallowCopyId();
                copiedSubnet.setNeutronSubnetId(subnetMap.get(copiedSubnet.getSubnetId()));
                copiedSubnet.setOrchestrationStatus(OrchestrationStatus.CREATED);
                aaiNetworkResources.updateSubnet(copiedl3network, copiedSubnet);
            }
        }
    } catch (Exception ex) {
        logger.error("Exception occurred in AAIUpdateTasks updateNetworkUpdated", ex);
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse)

Example 5 with UpdateNetworkResponse

use of org.onap.so.adapters.nwrest.UpdateNetworkResponse in project so by onap.

the class NetworkAdapterClientIT method updateNetworkTestAsync.

@Test
public void updateNetworkTestAsync() throws NetworkAdapterClientException, JsonProcessingException {
    UpdateNetworkRequest request = new UpdateNetworkRequest();
    request.setCloudSiteId(TESTING_ID);
    request.setNetworkId("test1");
    UpdateNetworkResponse mockResponse = new UpdateNetworkResponse();
    mockResponse.setNetworkId("test1");
    wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(mapper.writeValueAsString(mockResponse)).withStatus(200)));
    Response response = client.updateNetworkAsync(AAI_NETWORK_ID, request);
    assertNotNull(response.getEntity());
}
Also used : DeleteNetworkResponse(org.onap.so.adapters.nwrest.DeleteNetworkResponse) QueryNetworkResponse(org.onap.so.adapters.nwrest.QueryNetworkResponse) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Response(javax.ws.rs.core.Response) RollbackNetworkResponse(org.onap.so.adapters.nwrest.RollbackNetworkResponse) CreateNetworkResponse(org.onap.so.adapters.nwrest.CreateNetworkResponse) UpdateNetworkRequest(org.onap.so.adapters.nwrest.UpdateNetworkRequest) UpdateNetworkResponse(org.onap.so.adapters.nwrest.UpdateNetworkResponse) BaseIntegrationTest(org.onap.so.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

UpdateNetworkResponse (org.onap.so.adapters.nwrest.UpdateNetworkResponse)7 Test (org.junit.Test)4 UpdateNetworkRequest (org.onap.so.adapters.nwrest.UpdateNetworkRequest)4 DeleteNetworkResponse (org.onap.so.adapters.nwrest.DeleteNetworkResponse)3 HashMap (java.util.HashMap)2 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 CreateNetworkResponse (org.onap.so.adapters.nwrest.CreateNetworkResponse)2 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 StringReader (java.io.StringReader)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1 JAXBException (javax.xml.bind.JAXBException)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)1 DeleteNetworkRequest (org.onap.so.adapters.nwrest.DeleteNetworkRequest)1 QueryNetworkResponse (org.onap.so.adapters.nwrest.QueryNetworkResponse)1 RollbackNetworkRequest (org.onap.so.adapters.nwrest.RollbackNetworkRequest)1 RollbackNetworkResponse (org.onap.so.adapters.nwrest.RollbackNetworkResponse)1 CreateVfModuleRequest (org.onap.so.adapters.vnfrest.CreateVfModuleRequest)1 CreateVolumeGroupRequest (org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest)1