Search in sources :

Example 1 with DeleteVolumeGroupRequest

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

the class VnfVolumeAdapterClientIT method deleteVolumeGroupTestThrowException.

@Test(expected = VnfAdapterClientException.class)
public void deleteVolumeGroupTestThrowException() throws VnfAdapterClientException {
    DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest();
    request.setCloudSiteId(TESTING_ID);
    DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse();
    mockResponse.setVolumeGroupDeleted(true);
    VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class);
    AdapterRestClient mockClient = mock(AdapterRestClient.class);
    doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID);
    when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenThrow(new InternalServerErrorException("Error in delete volume group"));
    MockitoAnnotations.initMocks(this);
    client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request);
}
Also used : AdapterRestClient(org.onap.so.client.adapter.rest.AdapterRestClient) DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) DeleteVolumeGroupResponse(org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 2 with DeleteVolumeGroupRequest

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

the class VnfVolumeAdapterClientIT method deleteVolumeGroupTest.

@Test
public void deleteVolumeGroupTest() throws VnfAdapterClientException {
    DeleteVolumeGroupRequest request = new DeleteVolumeGroupRequest();
    request.setCloudSiteId(TESTING_ID);
    DeleteVolumeGroupResponse mockResponse = new DeleteVolumeGroupResponse();
    mockResponse.setVolumeGroupDeleted(true);
    VnfVolumeAdapterClientImpl client = spy(VnfVolumeAdapterClientImpl.class);
    AdapterRestClient mockClient = mock(AdapterRestClient.class);
    doReturn(mockClient).when(client).getAdapterRestClient("/" + AAI_VOLUME_GROUP_ID);
    when(mockClient.delete(request, DeleteVolumeGroupResponse.class)).thenReturn(mockResponse);
    MockitoAnnotations.initMocks(this);
    DeleteVolumeGroupResponse response = client.deleteVNFVolumes(AAI_VOLUME_GROUP_ID, request);
    assertEquals("Testing DeleteVolumeGroup response", mockResponse.getVolumeGroupDeleted(), response.getVolumeGroupDeleted());
}
Also used : AdapterRestClient(org.onap.so.client.adapter.rest.AdapterRestClient) DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) DeleteVolumeGroupResponse(org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse) Test(org.junit.Test) BaseIntegrationTest(org.onap.so.BaseIntegrationTest)

Example 3 with DeleteVolumeGroupRequest

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

the class VnfAdapterObjectMapperTest method test_deleteVolumeGroupRequestMapper.

private void test_deleteVolumeGroupRequestMapper(String heatStackId) throws Exception {
    DeleteVolumeGroupRequest expectedDeleteVolumeGroupRequest = new DeleteVolumeGroupRequest();
    CloudRegion cloudRegion = new CloudRegion();
    cloudRegion.setLcpCloudRegionId("lcpCloudRegionId");
    expectedDeleteVolumeGroupRequest.setCloudSiteId(cloudRegion.getLcpCloudRegionId());
    cloudRegion.setTenantId("tenantId");
    expectedDeleteVolumeGroupRequest.setTenantId(cloudRegion.getTenantId());
    VolumeGroup volumeGroup = new VolumeGroup();
    volumeGroup.setVolumeGroupId("volumeGroupId");
    expectedDeleteVolumeGroupRequest.setVolumeGroupId(volumeGroup.getVolumeGroupId());
    if (heatStackId != null) {
        volumeGroup.setHeatStackId("heatStackId");
        expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getHeatStackId());
    } else {
        volumeGroup.setVolumeGroupName("volumeGroupName");
        expectedDeleteVolumeGroupRequest.setVolumeGroupStackId(volumeGroup.getVolumeGroupName());
    }
    expectedDeleteVolumeGroupRequest.setSkipAAI(true);
    MsoRequest msoRequest = new MsoRequest();
    RequestContext requestContext = new RequestContext();
    requestContext.setMsoRequestId("msoRequestId");
    msoRequest.setRequestId(requestContext.getMsoRequestId());
    ServiceInstance serviceInstance = new ServiceInstance();
    serviceInstance.setServiceInstanceId("serviceInstanceId");
    msoRequest.setServiceInstanceId(serviceInstance.getServiceInstanceId());
    expectedDeleteVolumeGroupRequest.setMsoRequest(msoRequest);
    String messageId = "messageId";
    String endpoint = "endpoint";
    doReturn(messageId).when(vnfAdapterObjectMapper).getRandomUuid();
    doReturn(endpoint).when(vnfAdapterObjectMapper).getProperty(isA(String.class));
    expectedDeleteVolumeGroupRequest.setMessageId(messageId);
    expectedDeleteVolumeGroupRequest.setNotificationUrl(endpoint + "/VNFAResponse/" + messageId);
    DeleteVolumeGroupRequest actualDeleteVolumeGroupRequest = vnfAdapterObjectMapper.deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup);
    assertThat(actualDeleteVolumeGroupRequest, sameBeanAs(expectedDeleteVolumeGroupRequest));
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) VolumeGroup(org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup) DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) MsoRequest(org.onap.so.entity.MsoRequest) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) RequestContext(org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext)

Example 4 with DeleteVolumeGroupRequest

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

the class VnfAdapterVolumeGroupResourcesTest method test_deleteVolumeGroup.

@Test
public void test_deleteVolumeGroup() throws Exception {
    DeleteVolumeGroupRequest deleteVolumeGroupRequest = new DeleteVolumeGroupRequest();
    doReturn(deleteVolumeGroupRequest).when(MOCK_vnfAdapterObjectMapper).deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup);
    DeleteVolumeGroupRequest expectedDeleteVolumeGroupRequest = new DeleteVolumeGroupRequest();
    DeleteVolumeGroupRequest actualDeleteVolumeGroupRequest = vnfAdapterVolumeGroupResources.deleteVolumeGroupRequest(requestContext, cloudRegion, serviceInstance, volumeGroup);
    verify(MOCK_vnfAdapterObjectMapper, times(1)).deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup);
    assertThat(expectedDeleteVolumeGroupRequest, Matchers.sameBeanAs(actualDeleteVolumeGroupRequest));
}
Also used : DeleteVolumeGroupRequest(org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest) Test(org.junit.Test)

Example 5 with DeleteVolumeGroupRequest

use of org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest 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)

Aggregations

DeleteVolumeGroupRequest (org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest)9 Test (org.junit.Test)4 DeleteVolumeGroupResponse (org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse)3 StringReader (java.io.StringReader)2 BaseIntegrationTest (org.onap.so.BaseIntegrationTest)2 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)2 VolumeGroup (org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup)2 AdapterRestClient (org.onap.so.client.adapter.rest.AdapterRestClient)2 HashMap (java.util.HashMap)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)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 DeleteNetworkResponse (org.onap.so.adapters.nwrest.DeleteNetworkResponse)1 RollbackNetworkRequest (org.onap.so.adapters.nwrest.RollbackNetworkRequest)1 UpdateNetworkRequest (org.onap.so.adapters.nwrest.UpdateNetworkRequest)1 UpdateNetworkResponse (org.onap.so.adapters.nwrest.UpdateNetworkResponse)1 CreateVfModuleRequest (org.onap.so.adapters.vnfrest.CreateVfModuleRequest)1 CreateVolumeGroupRequest (org.onap.so.adapters.vnfrest.CreateVolumeGroupRequest)1 DeleteVfModuleRequest (org.onap.so.adapters.vnfrest.DeleteVfModuleRequest)1