Search in sources :

Example 11 with CreateVfModuleRequest

use of org.onap.so.adapters.vnfrest.CreateVfModuleRequest in project so by onap.

the class VnfAdapterVfModuleResourcesTest method test_createVfModuleWithVolumeGroup.

@Test
public void test_createVfModuleWithVolumeGroup() throws Exception {
    volumeGroup = buildVolumeGroup();
    doReturn(createVfModuleRequest).when(MOCK_vnfAdapterVfModuleObjectMapper).createVfModuleRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
    CreateVfModuleRequest actualCreateVfModuleRequest = vnfAdapterVfModuleResources.createVfModuleRequest(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
    verify(MOCK_vnfAdapterVfModuleObjectMapper, times(1)).createVfModuleRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, vfModule, volumeGroup, sdncVnfQueryResponse, sdncVfModuleQueryResponse);
    assertNotNull(createVfModuleRequest);
    assertNotNull(actualCreateVfModuleRequest);
    assertEquals(createVfModuleRequest, actualCreateVfModuleRequest);
}
Also used : CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) Test(org.junit.Test)

Example 12 with CreateVfModuleRequest

use of org.onap.so.adapters.vnfrest.CreateVfModuleRequest in project so by onap.

the class JAXBMarshallingTest method xmlMarshalTest.

@Test
public void xmlMarshalTest() throws IOException, JAXBException {
    CreateVfModuleRequest request = new CreateVfModuleRequest();
    request.getVfModuleParams().put("test-null", null);
    request.getVfModuleParams().put("vcpe_image_name", "ubuntu-16-04-cloud-amd64");
    request.getVfModuleParams().put("test-empty", "");
    request.getVfModuleParams().put("test array", Arrays.asList("a", "b", "c"));
    request.getVfModuleParams().put("test map", Collections.singletonMap("d", "e"));
    request.getVfModuleParams().put("marshalling error", new ArrayList());
    assertEquals("documents should be equal", new String(Files.readAllBytes(Paths.get("src/test/resources/VfRequest-marshalled-with-complex-object.xml"))).replaceAll("\\R", "\n"), request.toXmlString());
}
Also used : CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with CreateVfModuleRequest

use of org.onap.so.adapters.vnfrest.CreateVfModuleRequest 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 14 with CreateVfModuleRequest

use of org.onap.so.adapters.vnfrest.CreateVfModuleRequest in project so by onap.

the class StackService method createVfModule.

private void createVfModule(String xmlRequest, Holder<String> canonicalStackId, MutableBoolean backout, MutableBoolean success) throws VnfException {
    CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
    String completeVnfVfModuleType = req.getVnfType() + "::" + req.getVfModuleType();
    boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
    if (isMulticloud) {
        vnfPluginImpl.createVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), completeVnfVfModuleType, req.getVnfVersion(), req.getVnfId(), req.getVfModuleName(), req.getVfModuleId(), req.getRequestType(), req.getVolumeGroupStackId(), req.getBaseVfModuleStackId(), req.getModelCustomizationUuid(), req.getVfModuleParams(), false, false, req.getEnableBridge(), req.getMsoRequest(), canonicalStackId);
    } else {
        vnfAdapterImpl.createVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), completeVnfVfModuleType, req.getVnfVersion(), req.getVnfId(), req.getVfModuleName(), req.getVfModuleId(), req.getRequestType(), req.getVolumeGroupStackId(), req.getBaseVfModuleStackId(), req.getModelCustomizationUuid(), req.getVfModuleParams(), false, false, req.getEnableBridge(), req.getMsoRequest(), canonicalStackId);
    }
    success.setTrue();
    backout.setValue(req.getBackout());
}
Also used : CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) StringReader(java.io.StringReader)

Example 15 with CreateVfModuleRequest

use of org.onap.so.adapters.vnfrest.CreateVfModuleRequest in project so by onap.

the class RollbackService method executeExternalTask.

public void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
    mdcSetup.setupMDC(externalTask);
    logger.debug("Starting External Task Rollback Service");
    Map<String, Object> variables = new HashMap<>();
    boolean success = false;
    boolean pollRollbackStatus = false;
    try {
        String xmlRequest = externalTask.getVariable("openstackAdapterTaskRequest");
        if (xmlRequest != null) {
            Optional<String> requestType = findRequestType(xmlRequest);
            if ("createVolumeGroupRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Volume Group");
                CreateVolumeGroupRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVolumeGroupRequest.class);
                boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), null, req.getMsoRequest(), new Holder<>());
                    pollRollbackStatus = true;
                    success = true;
                } else {
                    vnfPluginImpl.deleteVnf(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVolumeGroupName(), req.getMsoRequest());
                    pollRollbackStatus = false;
                    success = true;
                }
            } else if ("createVfModuleRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Vf Module");
                CreateVfModuleRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateVfModuleRequest.class);
                boolean isMulticloud = vnfAdapterUtils.isMulticloudMode(null, req.getCloudSiteId());
                if (!isMulticloud) {
                    vnfAdapterImpl.deleteVfModule(req.getCloudSiteId(), req.getCloudOwner(), req.getTenantId(), req.getVfModuleName(), req.getModelCustomizationUuid(), req.getMsoRequest(), new Holder<>());
                    pollRollbackStatus = true;
                    success = true;
                } else {
                    pollRollbackStatus = false;
                    success = true;
                }
            } else if ("createNetworkRequest".equals(requestType.get())) {
                logger.debug("Executing External Task Rollback Service for Create Network");
                CreateNetworkRequest req = JAXB.unmarshal(new StringReader(xmlRequest), CreateNetworkRequest.class);
                networkAdapterImpl.deleteNetwork(req.getCloudSiteId(), req.getTenantId(), req.getNetworkType(), req.getModelCustomizationUuid(), req.getNetworkName(), req.getMsoRequest());
                pollRollbackStatus = true;
                success = true;
            }
        }
    } catch (Exception e) {
        logger.error("Error during External Task Rollback Service", e);
    }
    variables.put("OpenstackRollbackSuccess", success);
    variables.put("rollbackPerformed", true);
    variables.put("PollRollbackStatus", pollRollbackStatus);
    if (success) {
        externalTaskService.complete(externalTask, variables);
        logger.debug("The External Task Id: {}  Successful", externalTask.getId());
    } else {
        logger.debug("The External Task Id: {}  Failed. Not Retrying", externalTask.getId());
        externalTaskService.complete(externalTask, variables);
    }
}
Also used : CreateVolumeGroupRequest(org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest) CreateNetworkRequest(org.onap.so.adapters.nwrest.CreateNetworkRequest) HashMap(java.util.HashMap) Holder(javax.xml.ws.Holder) CreateVfModuleRequest(org.onap.so.adapters.vnfrest.CreateVfModuleRequest) StringReader(java.io.StringReader)

Aggregations

CreateVfModuleRequest (org.onap.so.adapters.vnfrest.CreateVfModuleRequest)24 Test (org.junit.Test)18 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)14 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)13 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)13 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)13 OrchestrationContext (org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext)13 RequestContext (org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)13 HashMap (java.util.HashMap)11 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)10 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)10 ModelInfoVfModule (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule)10 StringReader (java.io.StringReader)3 VolumeGroup (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup)3 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 CreateNetworkRequest (org.onap.so.adapters.nwrest.CreateNetworkRequest)2 CreateVolumeGroupRequest (org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest)2 DeleteVfModuleRequest (org.onap.so.adapters.vnfrest.DeleteVfModuleRequest)2 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1