Search in sources :

Example 1 with Request

use of org.onap.so.apihandlerinfra.tenantisolationbeans.Request in project so by onap.

the class CloudResourcesOrchestration method mapInfraActiveRequestToRequest.

private Request mapInfraActiveRequestToRequest(InfraActiveRequests iar) throws ApiException {
    Request request = new Request();
    request.setRequestId(iar.getRequestId());
    request.setRequestScope(iar.getRequestScope());
    request.setRequestType(iar.getRequestAction());
    InstanceReferences ir = new InstanceReferences();
    if (iar.getOperationalEnvId() != null)
        ir.setOperationalEnvironmentId(iar.getOperationalEnvId());
    if (iar.getOperationalEnvName() != null)
        ir.setOperationalEnvName(iar.getOperationalEnvName());
    if (iar.getRequestorId() != null)
        ir.setRequestorId(iar.getRequestorId());
    request.setInstanceReferences(ir);
    String requestBody = iar.getRequestBody();
    RequestDetails requestDetails = null;
    if (requestBody != null) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            requestDetails = mapper.readValue(requestBody, RequestDetails.class);
        } catch (IOException 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.  " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    request.setRequestDetails(requestDetails);
    String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
    request.setStartTime(startTimeStamp);
    RequestStatus status = new RequestStatus();
    if (iar.getStatusMessage() != null) {
        status.setStatusMessage(iar.getStatusMessage());
    }
    if (iar.getEndTime() != null) {
        String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
        status.setTimeStamp(endTimeStamp);
    }
    if (iar.getRequestStatus() != null) {
        status.setRequestState(iar.getRequestStatus());
    }
    if (iar.getProgress() != null) {
        status.setPercentProgress(iar.getProgress().toString());
    }
    request.setRequestStatus(status);
    return request;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) InstanceReferences(org.onap.so.apihandlerinfra.tenantisolationbeans.InstanceReferences) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.apihandlerinfra.tenantisolationbeans.Request) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) RequestDetails(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus)

Example 2 with Request

use of org.onap.so.apihandlerinfra.tenantisolationbeans.Request in project so by onap.

the class CloudResourcesOrchestration method getOperationEnvironmentStatusFilter.

@GET
@Path("/{version:[vV][1]}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Get status of an Operational Environment based on filter criteria", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response getOperationEnvironmentStatusFilter(@Context UriInfo ui, @PathParam("version") String version) throws ApiException {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
    List<String> requestIdKey = queryParams.get("requestId");
    String apiVersion = version.substring(1);
    if (queryParams.size() == 1 && requestIdKey != null) {
        String requestId = requestIdKey.get(0);
        CloudOrchestrationResponse cloudOrchestrationGetResponse = new CloudOrchestrationResponse();
        InfraActiveRequests requestDB;
        try {
            requestDB = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
        } catch (Exception e) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
            ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        if (requestDB == null) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, ErrorCode.BusinessProcessError).build();
            ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_NO_CONTENT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        Request request = mapInfraActiveRequestToRequest(requestDB);
        cloudOrchestrationGetResponse.setRequest(request);
        return builder.buildResponse(HttpStatus.SC_OK, requestId, cloudOrchestrationGetResponse, apiVersion);
    } else {
        TenantIsolationRequest tenantIsolationRequest = new TenantIsolationRequest();
        List<InfraActiveRequests> activeRequests;
        CloudOrchestrationRequestList orchestrationList;
        Map<String, String> orchestrationMap;
        try {
            orchestrationMap = tenantIsolationRequest.getOrchestrationFilters(queryParams);
        } catch (ValidationException ex) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
            ValidateException validateException = new ValidateException.Builder(ex.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
        activeRequests = requestDbClient.getCloudOrchestrationFiltersFromInfraActive(orchestrationMap);
        orchestrationList = new CloudOrchestrationRequestList();
        List<CloudOrchestrationResponse> requestLists = new ArrayList<>();
        for (InfraActiveRequests infraActive : activeRequests) {
            Request request = mapInfraActiveRequestToRequest(infraActive);
            CloudOrchestrationResponse requestList = new CloudOrchestrationResponse();
            requestList.setRequest(request);
            requestLists.add(requestList);
        }
        orchestrationList.setRequestList(requestLists);
        return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationList, apiVersion);
    }
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.apihandlerinfra.tenantisolationbeans.Request) ArrayList(java.util.ArrayList) CloudOrchestrationResponse(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationResponse) 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) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CloudOrchestrationRequestList(org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationRequestList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Aggregations

IOException (java.io.IOException)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 Request (org.onap.so.apihandlerinfra.tenantisolationbeans.Request)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Operation (io.swagger.v3.oas.annotations.Operation)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Transactional (javax.transaction.Transactional)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 CloudOrchestrationRequestList (org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationRequestList)1 CloudOrchestrationResponse (org.onap.so.apihandlerinfra.tenantisolationbeans.CloudOrchestrationResponse)1 InstanceReferences (org.onap.so.apihandlerinfra.tenantisolationbeans.InstanceReferences)1 RequestDetails (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestDetails)1 RequestStatus (org.onap.so.apihandlerinfra.tenantisolationbeans.RequestStatus)1