Search in sources :

Example 21 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo 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 22 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class RequestHandlerUtils method updateStatus.

@Override
public void updateStatus(InfraActiveRequests aq, Status status, String errorMessage) throws RequestDbFailureException {
    if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
        aq.setStatusMessage(errorMessage);
        aq.setProgress(new Long(100));
        aq.setRequestStatus(status.toString());
        Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
        aq.setEndTime(endTimeStamp);
        try {
            infraActiveRequestsClient.save(aq);
        } catch (Exception e) {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
            throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
        }
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Timestamp(java.sql.Timestamp) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) RestClientException(org.springframework.web.client.RestClientException) DuplicateRequestException(org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) ContactCamundaException(org.onap.so.apihandlerinfra.exceptions.ContactCamundaException) IOException(java.io.IOException) VfModuleNotFoundException(org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException) RecipeNotFoundException(org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException)

Example 23 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class Onap3gppServiceInstances method deleteServiceInstances.

/**
 * process delete service instance request and call corresponding workflow
 *
 * @param request
 * @param action
 * @param version
 * @return
 * @throws ApiException
 */
private Response deleteServiceInstances(DeAllocate3gppService request, Action action, String version, String requestId, HashMap<String, String> instanceIdMap, String requestUri) throws ApiException {
    String defaultServiceModelName = "COMMON_SS_DEFAULT";
    String requestScope = ModelType.service.name();
    String apiVersion = version.substring(1);
    String serviceRequestJson = toString.apply(request);
    if (serviceRequestJson != null) {
        InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, requestScope, serviceRequestJson);
        requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
        try {
            requestsDbClient.save(currentActiveReq);
        } catch (Exception e) {
            logger.error("Exception occurred", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
            throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
        }
        RecipeLookupResult recipeLookupResult;
        try {
            recipeLookupResult = getServiceInstanceOrchestrationURI(null, action, defaultServiceModelName);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }
        if (recipeLookupResult == null) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
            Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
            logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
            return response;
        }
        String serviceInstanceType = request.getSubscriptionServiceType();
        String serviceInstanceId = request.getServiceInstanceID();
        RequestClientParameter parameter;
        try {
            parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceInstanceId).setServiceType(serviceInstanceType).setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build();
        } catch (Exception e) {
            logger.error("Exception occurred", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
            throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
        }
        return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope);
    } else {
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        return response;
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Example 24 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ResumeOrchestrationRequest method setRequestClientParameter.

protected RequestClientParameter setRequestClientParameter(RecipeLookupResult recipeLookupResult, String version, InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String pnfCorrelationId, Boolean aLaCarte, ServiceInstancesRequest sir) throws ApiException {
    RequestClientParameter requestClientParameter = null;
    Action action = Action.valueOf(infraActiveRequest.getRequestAction());
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    Boolean isBaseVfModule = false;
    if (requestHandlerUtils.getModelType(action, modelInfo).equals(ModelType.vfModule)) {
        isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, infraActiveRequest.getVnfType(), msoRequest.getSDCServiceModelVersion(sir), currentActiveRequest);
    }
    try {
        requestClientParameter = new RequestClientParameter.Builder().setRequestId(currentActiveRequest.getRequestId()).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(infraActiveRequest.getRequestAction()).setServiceInstanceId(infraActiveRequest.getServiceInstanceId()).setPnfCorrelationId(pnfCorrelationId).setVnfId(infraActiveRequest.getVnfId()).setVfModuleId(infraActiveRequest.getVfModuleId()).setVolumeGroupId(infraActiveRequest.getVolumeGroupId()).setNetworkId(infraActiveRequest.getNetworkId()).setServiceType(infraActiveRequest.getServiceType()).setVnfType(infraActiveRequest.getVnfType()).setVfModuleType(msoRequest.getVfModuleType(sir, infraActiveRequest.getRequestScope())).setNetworkType(infraActiveRequest.getNetworkType()).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(infraActiveRequest.getRequestBody(), sir, aLaCarte, action)).setApiVersion(version).setALaCarte(aLaCarte).setRequestUri(currentActiveRequest.getRequestUrl()).setInstanceGroupId(infraActiveRequest.getInstanceGroupId()).build();
    } catch (IOException e) {
        logger.error("IOException while generating requestClientParameter to send to BPMN", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new ValidateException.Builder("IOException while generating requestClientParameter to send to BPMN: " + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    return requestClientParameter;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) IOException(java.io.IOException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Example 25 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ResumeOrchestrationRequest method resumeOrchestrationRequest.

@POST
@Path("/{version:[vV][7]}/{requestId}/resume")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Resume request for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response resumeOrchestrationRequest(@PathParam("requestId") String requestId, @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException {
    Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
    String currentRequestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
    logger.info("Beginning resume operation for new request: {}", currentRequestId);
    InfraActiveRequests infraActiveRequest = null;
    String source = MDC.get(MdcConstants.ORIGINAL_PARTNER_NAME);
    String requestorId = MDC.get(HttpHeadersConstants.REQUESTOR_ID);
    requestHandlerUtils.getRequestUri(requestContext, uriPrefix);
    String requestUri = MDC.get(LogConstants.HTTP_URL);
    version = version.substring(1);
    try {
        infraActiveRequest = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
    } catch (HttpClientErrorException e) {
        logger.error("Error occurred while performing requestDb lookup by requestId: " + requestId, e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
        throw new ValidateException.Builder("Exception while performing requestDb lookup by requestId", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
    }
    InfraActiveRequests currentActiveRequest = requestHandlerUtils.createNewRecordCopyFromInfraActiveRequest(infraActiveRequest, currentRequestId, startTimeStamp, source, requestUri, requestorId, requestId);
    if (infraActiveRequest == null) {
        logger.error("No infraActiveRequest record found for requestId: {} in requesteDb lookup", requestId);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.BusinessProcessError).build();
        ValidateException validateException = new ValidateException.Builder("Null response from requestDB when searching by requestId: " + requestId, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveRequest, Status.FAILED, validateException.getMessage());
        throw validateException;
    }
    return resumeRequest(infraActiveRequest, currentActiveRequest, version, requestUri);
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Timestamp(java.sql.Timestamp) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) Transactional(javax.transaction.Transactional)

Aggregations

ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)42 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)34 IOException (java.io.IOException)22 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)19 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 ValidationException (org.onap.so.exceptions.ValidationException)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)10 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 Operation (io.swagger.v3.oas.annotations.Operation)9 Transactional (javax.transaction.Transactional)9 Path (javax.ws.rs.Path)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 Consumes (javax.ws.rs.Consumes)6 Response (javax.ws.rs.core.Response)6 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)6 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5