Search in sources :

Example 1 with RequestProcessingData

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

the class BBInputSetupUtilsTest method loadOriginalFlowExecutionPathTest.

@Test
public void loadOriginalFlowExecutionPathTest() throws IOException {
    final String requestId = "123";
    final String originalRequestId = "originalRequestId";
    final String flowsToExecuteString = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "FlowsToExecute.json")), StandardCharsets.UTF_8);
    InfraActiveRequests request = new InfraActiveRequests();
    ExecuteBuildingBlock[] expectedFlowsToExecute = mapper.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class);
    request.setRequestId(requestId);
    request.setOriginalRequestId(originalRequestId);
    doReturn(request).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(requestId);
    RequestProcessingData requestProcessingData = new RequestProcessingData();
    requestProcessingData.setValue(flowsToExecuteString);
    doReturn(requestProcessingData).when(MOCK_requestsDbClient).getRequestProcessingDataBySoRequestIdAndName(anyString(), anyString());
    List<ExecuteBuildingBlock> flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId);
    assertEquals(mapper.writeValueAsString(expectedFlowsToExecute), mapper.writeValueAsString(flowsToExecute));
}
Also used : RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Test(org.junit.Test)

Example 2 with RequestProcessingData

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

the class RequestsDbClient method updateRequestProcessingData.

public void updateRequestProcessingData(RequestProcessingData requestProcessingData) {
    HttpHeaders headers = getHttpHeaders();
    URI uri = getUri(requestProcessingDataURI + "/" + requestProcessingData.getId());
    HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers);
    restTemplate.put(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 3 with RequestProcessingData

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

the class RequestsDbClient method persistProcessingData.

public void persistProcessingData(String flowExecutionPath, String requestId) {
    HttpHeaders headers = getHttpHeaders();
    URI uri = getUri(requestProcessingDataURI);
    RequestProcessingData rpd = new RequestProcessingData();
    rpd.setName(FLOW_EXECUTION_PATH);
    rpd.setSoRequestId(requestId);
    rpd.setValue(flowExecutionPath);
    rpd.setTag(BPMN_EXECUTION_DATA_TAG);
    rpd.setIsDataInternal(true);
    HttpEntity<RequestProcessingData> entity = new HttpEntity<>(rpd, 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 4 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]}/{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 5 with RequestProcessingData

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

the class OrchestrationRequests method mapRequestProcessingData.

public List<org.onap.so.serviceinstancebeans.RequestProcessingData> mapRequestProcessingData(List<org.onap.so.db.request.beans.RequestProcessingData> processingData) {
    List<org.onap.so.serviceinstancebeans.RequestProcessingData> addedRequestProcessingData = new ArrayList<>();
    org.onap.so.serviceinstancebeans.RequestProcessingData finalProcessingData = new org.onap.so.serviceinstancebeans.RequestProcessingData();
    String currentGroupingId = null;
    HashMap<String, String> tempMap = new HashMap<>();
    List<HashMap<String, String>> tempList = new ArrayList<>();
    for (RequestProcessingData data : processingData) {
        String groupingId = data.getGroupingId();
        String tag = data.getTag();
        if (currentGroupingId == null || !currentGroupingId.equals(groupingId)) {
            if (!tempMap.isEmpty()) {
                tempList.add(tempMap);
                finalProcessingData.setDataPairs(tempList);
                addedRequestProcessingData.add(finalProcessingData);
            }
            finalProcessingData = new org.onap.so.serviceinstancebeans.RequestProcessingData();
            if (groupingId != null) {
                finalProcessingData.setGroupingId(groupingId);
            }
            if (tag != null) {
                finalProcessingData.setTag(tag);
            }
            currentGroupingId = groupingId;
            tempMap = new HashMap<>();
            tempList = new ArrayList<>();
            if (data.getName() != null && data.getValue() != null) {
                tempMap.put(data.getName(), data.getValue());
            }
        } else {
            if (data.getName() != null && data.getValue() != null) {
                tempMap.put(data.getName(), data.getValue());
            }
        }
    }
    if (tempMap.size() > 0) {
        tempList.add(tempMap);
        finalProcessingData.setDataPairs(tempList);
    }
    addedRequestProcessingData.add(finalProcessingData);
    return addedRequestProcessingData;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData)

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