Search in sources :

Example 11 with RequestProcessingData

use of org.onap.so.db.request.beans.RequestProcessingData in project so by onap.

the class OrchestrationRequests method getOrchestrationRequest.

@GET
@Path("/{version:[vV][4-8]}")
@Operation(description = "Find Orchestrated Requests for a URI Information", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@Context UriInfo ui, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
    List<InfraActiveRequests> activeRequests;
    GetOrchestrationListResponse orchestrationList;
    Map<String, List<String>> orchestrationMap;
    String apiVersion = version.substring(1);
    try {
        orchestrationMap = msoRequest.getOrchestrationFilters(queryParams);
        if (orchestrationMap.isEmpty()) {
            throw new ValidationException("At least one filter query param must be specified");
        }
    } catch (ValidationException ex) {
        logger.error("Exception occurred", ex);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    activeRequests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
    orchestrationList = new GetOrchestrationListResponse();
    List<RequestList> requestLists = new ArrayList<>();
    for (InfraActiveRequests infraActive : activeRequests) {
        RequestList requestList = new RequestList();
        Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, format, version);
        if (isRequestProcessingDataRequired(format)) {
            List<RequestProcessingData> requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(infraActive.getRequestId());
            if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
                request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
            }
        }
        requestList.setRequest(request);
        requestLists.add(requestList);
    }
    orchestrationList.setRequestList(requestLists);
    return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationList, apiVersion);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) GetOrchestrationListResponse(org.onap.so.serviceinstancebeans.GetOrchestrationListResponse) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) ArrayList(java.util.ArrayList) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) List(java.util.List) ArrayList(java.util.ArrayList) RequestList(org.onap.so.serviceinstancebeans.RequestList) RequestList(org.onap.so.serviceinstancebeans.RequestList) 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 12 with RequestProcessingData

use of org.onap.so.db.request.beans.RequestProcessingData in project so by onap.

the class RequestsDbClient method saveRequestProcessingData.

public void saveRequestProcessingData(RequestProcessingData requestProcessingData) {
    HttpHeaders headers = getHttpHeaders();
    URI uri = getUri(requestProcessingDataURI);
    HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
    restTemplate.postForLocation(uri, entity);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) HttpEntity(org.springframework.http.HttpEntity) URI(java.net.URI)

Example 13 with RequestProcessingData

use of org.onap.so.db.request.beans.RequestProcessingData in project so by onap.

the class RequestDbClientTest method updateRequestProcessingDataTest.

@Test
public void updateRequestProcessingDataTest() {
    RequestProcessingData requestProcessingData = new RequestProcessingData();
    requestProcessingData.setId(1);
    URI uri = URI.create("/requestProcessingData/1");
    requestsDbClient.updateRequestProcessingData(requestProcessingData);
    Mockito.verify(restTemplate, times(1)).put(eq(uri), isA(HttpEntity.class));
}
Also used : RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) HttpEntity(org.springframework.http.HttpEntity) URI(java.net.URI) Test(org.junit.Test)

Example 14 with RequestProcessingData

use of org.onap.so.db.request.beans.RequestProcessingData in project so by onap.

the class RequestProcessingDataRequestDbQueryTest method testGetRequestProcessingDataBySoRequestIdAndIsInternalData.

@Test
@Transactional
public void testGetRequestProcessingDataBySoRequestIdAndIsInternalData() {
    String soRequestId = "00032ab7-na18-42e5-965d-8ea592502018";
    String tag = "pincFabricConfigRequest";
    RequestProcessingData firstEntry = new RequestProcessingData();
    List<RequestProcessingData> expectedList = new ArrayList<>();
    firstEntry.setSoRequestId(soRequestId);
    firstEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
    firstEntry.setName("configurationId");
    firstEntry.setValue("52234bc0-d6a6-41d4-a901-79015e4877e2");
    firstEntry.setTag(tag);
    expectedList.add(firstEntry);
    List<RequestProcessingData> dataFound = client.getExternalRequestProcessingDataBySoRequestId(soRequestId);
    assertEquals(1, dataFound.size());
    assertEquals(dataFound.get(0).getSoRequestId(), firstEntry.getSoRequestId());
    assertEquals(dataFound.get(0).getGroupingId(), firstEntry.getGroupingId());
    assertEquals(dataFound.get(0).getName(), firstEntry.getName());
    assertEquals(dataFound.get(0).getValue(), firstEntry.getValue());
    assertEquals(dataFound.get(0).getTag(), firstEntry.getTag());
}
Also used : RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(javax.transaction.Transactional)

Example 15 with RequestProcessingData

use of org.onap.so.db.request.beans.RequestProcessingData in project so by onap.

the class StackStatusHandler method updateStackStatus.

@Async
public void updateStackStatus(Stack stack, String requestId) {
    try {
        String stackStatus = mapper.writeValueAsString(stack);
        RequestProcessingData requestProcessingData = requestDBClient.getRequestProcessingDataBySoRequestIdAndNameAndGrouping(requestId, stack.getStackName(), stack.getId());
        if (requestProcessingData == null) {
            requestProcessingData = new RequestProcessingData();
            requestProcessingData.setGroupingId(stack.getId());
            requestProcessingData.setName(stack.getStackName());
            requestProcessingData.setTag("StackInformation");
            requestProcessingData.setSoRequestId(requestId);
            requestProcessingData.setValue(stackStatus);
            requestDBClient.saveRequestProcessingData(requestProcessingData);
        } else {
            requestProcessingData.setValue(stackStatus);
            requestDBClient.updateRequestProcessingData(requestProcessingData);
        }
    } catch (Exception e) {
        logger.warn("Error adding stack status to request database", e);
    }
}
Also used : RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) Async(org.springframework.scheduling.annotation.Async)

Aggregations

RequestProcessingData (org.onap.so.db.request.beans.RequestProcessingData)15 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 URI (java.net.URI)4 Transactional (javax.transaction.Transactional)4 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)4 HttpEntity (org.springframework.http.HttpEntity)4 HttpHeaders (org.springframework.http.HttpHeaders)3 Stack (com.woorea.openstack.heat.model.Stack)2 Operation (io.swagger.v3.oas.annotations.Operation)2 IOException (java.io.IOException)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)2 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)2 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)2 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)2 ValidationException (org.onap.so.exceptions.ValidationException)2