use of org.onap.so.serviceinstancebeans.CloudRequestData in project so by onap.
the class OrchestrationRequestsTest method testGetOrchestrationRequestWithOpenstackDetails.
@Test
public void testGetOrchestrationRequestWithOpenstackDetails() throws Exception {
setupTestGetOrchestrationRequestOpenstackDetails("00032ab7-3fb3-42e5-965d-8ea592502017", "COMPLETED");
// Test request with modelInfo request body
GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
Request request = ORCHESTRATION_LIST.getRequestList().get(0).getRequest();
List<CloudRequestData> cloudRequestData = new ArrayList<>();
CloudRequestData cloudData = new CloudRequestData();
cloudData.setCloudIdentifier("heatstackName/123123");
ObjectMapper mapper = new ObjectMapper();
Object reqData = mapper.readValue("{\r\n \"test\": \"00032ab7-3fb3-42e5-965d-8ea592502016\",\r\n \"test2\": \"deleteInstance\",\r\n \"test3\": \"COMPLETE\",\r\n \"test4\": \"Vf Module has been deleted successfully.\",\r\n \"test5\": 100\r\n}", Object.class);
cloudData.setCloudRequest(reqData);
cloudRequestData.add(cloudData);
request.setCloudRequestData(cloudRequestData);
testResponse.setRequest(request);
String testRequestId = request.getRequestId();
testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>());
RequestProcessingData e = new RequestProcessingData();
e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714");
List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
HashMap<String, String> data1 = new HashMap<String, String>();
data1.put("requestAction", "assign");
data.add(data1);
e.setDataPairs(data);
testResponse.getRequest().getRequestProcessingData().add(e);
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
headers.set(ONAPLogConstants.Headers.REQUEST_ID, "0321e28d-3dde-4b31-9b28-1e0f07231b93");
HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId + "?includeCloudRequest=true"));
ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
System.out.println("Response :" + response.getBody().toString());
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0));
assertEquals("0321e28d-3dde-4b31-9b28-1e0f07231b93", response.getHeaders().get("X-TransactionID").get(0));
}
use of org.onap.so.serviceinstancebeans.CloudRequestData 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;
}
Aggregations