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));
}
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));
}
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;
}
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));
}
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));
}
Aggregations