Search in sources :

Example 6 with InstanceReferences

use of org.onap.so.serviceinstancebeans.InstanceReferences in project so by onap.

the class OrchestrationRequestsUnitTest method mapInfraActiveRequestToRequestWithOriginalRequestIdTest.

@Test
public void mapInfraActiveRequestToRequestWithOriginalRequestIdTest() throws ApiException {
    doReturn("Last task executed: Call SDNC").when(camundaRequestHandler).getTaskName(REQUEST_ID);
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", FLOW_STATUS + TASK_INFORMATION, RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, "The vf module already exist"));
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setOriginalRequestId(ORIGINAL_REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    iar.setOriginalRequestId(ORIGINAL_REQUEST_ID);
    Request result = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.DETAIL.toString(), "v7");
    assertThat(result, sameBeanAs(expected));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Example 7 with InstanceReferences

use of org.onap.so.serviceinstancebeans.InstanceReferences in project so by onap.

the class OrchestrationRequestsUnitTest method mapRequestStatusNoTaskInfoTest.

@Test
public void mapRequestStatusNoTaskInfoTest() throws ApiException {
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setStatusMessage("FLOW STATUS: FlowStatus RETRY STATUS: RetryStatusMessage ROLLBACK STATUS: RollbackStatusMessage RESOURCE STATUS: The vf module already exist");
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    includeCloudRequest = false;
    Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.SIMPLENOTASKINFO.toString(), "v7");
    assertThat(expected, sameBeanAs(actual));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Example 8 with InstanceReferences

use of org.onap.so.serviceinstancebeans.InstanceReferences in project so by onap.

the class OrchestrationRequests method mapInfraActiveRequestToRequest.

protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, String format, String version) throws ApiException {
    String requestBody = iar.getRequestBody();
    Request request = new Request();
    ObjectMapper mapper = new ObjectMapper();
    request.setRequestId(iar.getRequestId());
    request.setRequestScope(iar.getRequestScope());
    request.setRequestType(iar.getRequestAction());
    String originalRequestId = iar.getOriginalRequestId();
    if (originalRequestId != null) {
        request.setOriginalRequestId(originalRequestId);
    }
    if (!version.matches("v[1-7]")) {
        String workflowName = iar.getWorkflowName();
        if (workflowName == null) {
            workflowName = iar.getRequestAction();
        }
        request.setWorkflowName(workflowName);
        String operationName = iar.getOperationName();
        if (operationName != null) {
            request.setOperationName(operationName);
        }
    }
    InstanceReferences ir = new InstanceReferences();
    if (iar.getNetworkId() != null)
        ir.setNetworkInstanceId(iar.getNetworkId());
    if (iar.getNetworkName() != null)
        ir.setNetworkInstanceName(iar.getNetworkName());
    if (iar.getServiceInstanceId() != null)
        ir.setServiceInstanceId(iar.getServiceInstanceId());
    if (iar.getServiceInstanceName() != null)
        ir.setServiceInstanceName(iar.getServiceInstanceName());
    if (iar.getVfModuleId() != null)
        ir.setVfModuleInstanceId(iar.getVfModuleId());
    if (iar.getVfModuleName() != null)
        ir.setVfModuleInstanceName(iar.getVfModuleName());
    if (iar.getVnfId() != null)
        ir.setVnfInstanceId(iar.getVnfId());
    if (iar.getVnfName() != null)
        ir.setVnfInstanceName(iar.getVnfName());
    if (iar.getVolumeGroupId() != null)
        ir.setVolumeGroupInstanceId(iar.getVolumeGroupId());
    if (iar.getVolumeGroupName() != null)
        ir.setVolumeGroupInstanceName(iar.getVolumeGroupName());
    if (iar.getInstanceGroupId() != null)
        ir.setInstanceGroupId(iar.getInstanceGroupId());
    if (iar.getInstanceGroupName() != null)
        ir.setInstanceGroupName(iar.getInstanceGroupName());
    request.setInstanceReferences(ir);
    RequestDetails requestDetails = null;
    if (StringUtils.isNotBlank(requestBody)) {
        try {
            if (requestBody.contains("\"requestDetails\":")) {
                ServiceInstancesRequest sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
                requestDetails = sir.getRequestDetails();
            } else {
                requestDetails = mapper.readValue(requestBody, RequestDetails.class);
            }
            if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) {
                requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName());
            }
            if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) {
                requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName());
            }
        } catch (IOException e) {
            logger.error("Exception occurred", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
            ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    request.setRequestDetails(requestDetails);
    if (iar.getStartTime() != null) {
        String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
        request.setStartTime(startTimeStamp);
    }
    if (iar.getEndTime() != null) {
        String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
        request.setFinishTime(endTimeStamp);
    }
    RequestStatus status = new RequestStatus();
    if (iar.getModifyTime() != null) {
        String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT";
        status.setTimeStamp(timeStamp);
    }
    status.setRequestState(mapRequestStatusToRequest(iar, format));
    if (iar.getProgress() != null) {
        status.setPercentProgress(iar.getProgress().intValue());
    }
    if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) {
        iar.getCloudApiRequests().stream().forEach(cloudRequest -> {
            try {
                request.getCloudRequestData().add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), cloudRequest.getCloudIdentifier()));
            } catch (Exception e) {
                logger.error("Error reading Cloud Request", e);
            }
        });
    }
    mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version);
    request.setRequestStatus(status);
    return request;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) IOException(java.io.IOException) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus)

Example 9 with InstanceReferences

use of org.onap.so.serviceinstancebeans.InstanceReferences in project so by onap.

the class OrchestrationRequestsUnitTest method mapRequestStatusAndExtSysErrSrcToRequestFlowStatusSuccessfulRollbackTest.

@Test
public void mapRequestStatusAndExtSysErrSrcToRequestFlowStatusSuccessfulRollbackTest() throws ApiException {
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setStatusMessage(String.format("FLOW STATUS: %s RETRY STATUS: %s ROLLBACK STATUS: %s RESOURCE STATUS: %s", "All Rollback flows have completed successfully", RETRY_STATUS_MESSAGE, ROLLBACK_STATUS_MESSAGE, "The vf module already exist"));
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    includeCloudRequest = false;
    iar.setFlowStatus("All Rollback flows have completed successfully");
    Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.DETAIL.toString(), "v7");
    assertThat(actual, sameBeanAs(expected));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Example 10 with InstanceReferences

use of org.onap.so.serviceinstancebeans.InstanceReferences in project so by onap.

the class OrchestrationRequestsUnitTest method mapRequestStatusAndExtSysErrSrcToRequestStatusDetailTest.

@Test
public void mapRequestStatusAndExtSysErrSrcToRequestStatusDetailTest() throws ApiException {
    doReturn(null).when(camundaRequestHandler).getTaskName(REQUEST_ID);
    InstanceReferences instanceReferences = new InstanceReferences();
    instanceReferences.setServiceInstanceId(SERVICE_INSTANCE_ID);
    RequestStatus requestStatus = new RequestStatus();
    requestStatus.setExtSystemErrorSource(EXT_SYSTEM_ERROR_SOURCE);
    requestStatus.setRollbackExtSystemErrorSource(ROLLBACK_EXT_SYSTEM_ERROR_SOURCE);
    requestStatus.setRequestState(iar.getRequestStatus());
    requestStatus.setFlowStatus(FLOW_STATUS);
    requestStatus.setRollbackStatusMessage(ROLLBACK_STATUS_MESSAGE);
    requestStatus.setRetryStatusMessage(RETRY_STATUS_MESSAGE);
    Request expected = new Request();
    expected.setRequestId(REQUEST_ID);
    expected.setInstanceReferences(instanceReferences);
    expected.setRequestStatus(requestStatus);
    expected.setRequestScope(SERVICE);
    expected.setStartTime(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(startTime) + " GMT");
    includeCloudRequest = false;
    Request actual = orchestrationRequests.mapInfraActiveRequestToRequest(iar, includeCloudRequest, OrchestrationRequestFormat.STATUSDETAIL.toString(), "v7");
    assertThat(actual, sameBeanAs(expected));
}
Also used : InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) Request(org.onap.so.serviceinstancebeans.Request) SimpleDateFormat(java.text.SimpleDateFormat) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus) Test(org.junit.Test)

Aggregations

InstanceReferences (org.onap.so.serviceinstancebeans.InstanceReferences)15 Request (org.onap.so.serviceinstancebeans.Request)15 SimpleDateFormat (java.text.SimpleDateFormat)14 Test (org.junit.Test)14 RequestStatus (org.onap.so.serviceinstancebeans.RequestStatus)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 ValidationException (org.onap.so.exceptions.ValidationException)1 CloudRequestData (org.onap.so.serviceinstancebeans.CloudRequestData)1 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)1 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)1