Search in sources :

Example 1 with GetOrchestrationResponse

use of org.onap.so.serviceinstancebeans.GetOrchestrationResponse 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));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Request(org.onap.so.serviceinstancebeans.Request) ArrayList(java.util.ArrayList) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) RequestProcessingData(org.onap.so.serviceinstancebeans.RequestProcessingData) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with GetOrchestrationResponse

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

the class OrchestrationRequestsTest method testGetOrchestrationRequestInvalidRequestID.

@Test
public void testGetOrchestrationRequestInvalidRequestID() throws Exception {
    setupTestGetOrchestrationRequest();
    // TEST INVALID REQUESTID
    GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
    Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
    testResponse.setRequest(request);
    String testRequestId = "00032ab7-pfb3-42e5-965d-8ea592502016";
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
    ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Request(org.onap.so.serviceinstancebeans.Request) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) Test(org.junit.Test)

Example 3 with GetOrchestrationResponse

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

the class OrchestrationRequests method getOrchestrationRequest.

@GET
@Path("/{version:[vV][4-8]}/{requestId}")
@Operation(description = "Find Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@PathParam("requestId") String requestId, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
    GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse();
    InfraActiveRequests infraActiveRequest = null;
    List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = null;
    if (!UUIDChecker.isValidUUID(requestId)) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MODIFIED_BY_APIHANDLER).build();
        throw new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    infraActiveRequest = infraActiveRequestLookup(requestId);
    if (isRequestProcessingDataRequired(format)) {
        try {
            requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId);
        } catch (Exception e) {
            logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
            ValidateException validateException = new ValidateException.Builder("Exception occurred while communicating with RequestDb during requestProcessingData lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format, version);
    if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
        request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
    }
    request.setRequestId(requestId);
    orchestrationResponse.setRequest(request);
    return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationResponse, version);
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Example 4 with GetOrchestrationResponse

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

the class OrchestrationRequestsTest method testGetOrchestrationRequestInstanceGroup.

@Test
public void testGetOrchestrationRequestInstanceGroup() throws Exception {
    setupTestGetOrchestrationRequestInstanceGroup();
    // TEST VALID REQUEST
    GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
    Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest();
    testResponse.setRequest(request);
    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);
    String testRequestId = request.getRequestId();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
    ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Request(org.onap.so.serviceinstancebeans.Request) ArrayList(java.util.ArrayList) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) RequestProcessingData(org.onap.so.serviceinstancebeans.RequestProcessingData) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Example 5 with GetOrchestrationResponse

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

the class OrchestrationRequestsTest method testGetOrchestrationRequest.

@Test
public void testGetOrchestrationRequest() throws Exception {
    setupTestGetOrchestrationRequest();
    // TEST VALID REQUEST
    GetOrchestrationResponse testResponse = new GetOrchestrationResponse();
    Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest();
    testResponse.setRequest(request);
    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);
    String testRequestId = request.getRequestId();
    HttpHeaders headers = new HttpHeaders();
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    headers.set(ONAPLogConstants.Headers.REQUEST_ID, "1e45215d-b7b3-4c5a-9316-65bdddaf649f");
    HttpEntity<Request> entity = new HttpEntity<Request>(null, headers);
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId));
    ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp"));
    assertNull(response.getBody().getRequest().getInstanceReferences().getRequestorId());
    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("1e45215d-b7b3-4c5a-9316-65bdddaf649f", response.getHeaders().get("X-TransactionID").get(0));
    assertNotNull(response.getBody().getRequest().getFinishTime());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Request(org.onap.so.serviceinstancebeans.Request) ArrayList(java.util.ArrayList) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) RequestProcessingData(org.onap.so.serviceinstancebeans.RequestProcessingData) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test)

Aggregations

GetOrchestrationResponse (org.onap.so.serviceinstancebeans.GetOrchestrationResponse)6 Request (org.onap.so.serviceinstancebeans.Request)6 Test (org.junit.Test)5 HttpEntity (org.springframework.http.HttpEntity)5 HttpHeaders (org.springframework.http.HttpHeaders)5 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 RequestProcessingData (org.onap.so.serviceinstancebeans.RequestProcessingData)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Operation (io.swagger.v3.oas.annotations.Operation)1 IOException (java.io.IOException)1 Transactional (javax.transaction.Transactional)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)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