Search in sources :

Example 11 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class ServiceIntentApiHandler method postBPELRequest.

private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, String orchestrationURI, String requestScope) throws ApiException {
    ResponseEntity<String> response = requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI);
    logger.debug("BPEL response : " + response);
    int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue());
    String jsonResponse;
    try {
        responseHandler.acceptedResponse(response);
        CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response);
        String responseBody = camundaResponse.getResponse();
        if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) {
            jsonResponse = responseBody;
        } else {
            BPMNFailureException bpmnException = new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build();
            requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage());
            throw bpmnException;
        }
    } catch (ApiException e) {
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage());
        throw e;
    }
    return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, parameter.getApiVersion());
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 12 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class E2EServiceInstances method updateE2EserviceInstances.

private Response updateE2EserviceInstances(String requestJSON, Action action, String version) throws ApiException {
    String requestId = UUID.randomUUID().toString();
    E2EServiceInstanceRequest e2eSir;
    String serviceId = instanceIdMap.get(SERVICE_ID);
    ObjectMapper mapper = new ObjectMapper();
    try {
        e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
    } catch (Exception e) {
        logger.debug("Mapping of request to JSON object failed : ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
    sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
    try {
        parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
    } catch (Exception e) {
        logger.debug("Validation failed: ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Error parsing request.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        if (requestId != null) {
            logger.debug("Logging failed message to the database");
        }
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    RecipeLookupResult recipeLookupResult;
    try {
        recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
    } 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 = e2eSir.getService().getServiceType();
    String sirRequestJson = convertToString(sir);
    RequestClientParameter postParam = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType).setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
    return postRequest(recipeLookupResult.getOrchestrationURI(), postParam, version);
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) E2EServiceInstanceRequest(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Example 13 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class E2EServiceInstances method processE2EserviceInstances.

private Response processE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
    String requestId = UUID.randomUUID().toString();
    E2EServiceInstanceRequest e2eSir;
    MsoRequest msoRequest = new MsoRequest();
    ObjectMapper mapper = new ObjectMapper();
    try {
        e2eSir = mapper.readValue(requestJSON, E2EServiceInstanceRequest.class);
    } catch (Exception e) {
        logger.debug("Mapping of request to JSON object failed : ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    ServiceInstancesRequest sir = mapReqJsonToSvcInstReq(e2eSir, requestJSON);
    sir.getRequestDetails().getRequestParameters().setaLaCarte(true);
    try {
        parseRequest(sir, instanceIdMap, action, version, requestJSON, false, requestId);
    } catch (Exception e) {
        logger.debug("Validation failed: ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Error parsing request.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        if (requestId != null) {
            logger.debug("Logging failed message to the database");
        }
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    RecipeLookupResult recipeLookupResult;
    try {
        recipeLookupResult = getServiceInstanceOrchestrationURI(e2eSir.getService().getServiceUuid(), action);
    } 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 = e2eSir.getService().getServiceType();
    String serviceId = e2eSir.getService().getServiceId();
    String sirRequestJson = convertToString(sir);
    RequestClientParameter parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType).setRequestDetails(sirRequestJson).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
    return postRequest(recipeLookupResult.getOrchestrationURI(), parameter, version);
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) E2EServiceInstanceRequest(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Example 14 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class E2EServiceInstances method compareModelwithTargetVersion.

private Response compareModelwithTargetVersion(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
    String requestId = UUID.randomUUID().toString();
    CompareModelsRequest e2eCompareModelReq;
    ObjectMapper mapper = new ObjectMapper();
    try {
        e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);
    } catch (Exception e) {
        logger.debug("Mapping of request to JSON object failed : ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity().toString());
        return response;
    }
    return runCompareModelBPMWorkflow(e2eCompareModelReq, requestJSON, requestId, action, version);
}
Also used : CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) CompareModelsRequest(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException)

Example 15 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException in project so by onap.

the class InstanceManagement method getInstanceManagementWorkflowRecipe.

private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException {
    RecipeLookupResult recipeLookupResult;
    try {
        recipeLookupResult = getCustomWorkflowUri(workflowUuid);
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
        throw validateException;
    }
    if (recipeLookupResult == null) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        RecipeNotFoundException recipeNotFoundExceptionException = new RecipeNotFoundException.Builder("Recipe could not be retrieved from catalog DB.", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, recipeNotFoundExceptionException.getMessage());
        throw recipeNotFoundExceptionException;
    }
    return recipeLookupResult;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RecipeNotFoundException(org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) RecipeNotFoundException(org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException)

Aggregations

ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)34 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)28 IOException (java.io.IOException)23 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)18 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)16 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)15 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)14 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)14 Response (javax.ws.rs.core.Response)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)12 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 ValidationException (org.onap.so.exceptions.ValidationException)10 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 JSONObject (org.json.JSONObject)7 GetE2EServiceInstanceResponse (org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Operation (io.swagger.v3.oas.annotations.Operation)4 Transactional (javax.transaction.Transactional)4