Search in sources :

Example 11 with ErrorLoggerInfo

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

the class ServiceIntentApiHandler method processServiceIntentRequest.

/**
 * Process Service Intent request and send request to corresponding workflow
 *
 * @param request
 * @param action
 * @param version
 * @return
 * @throws ApiException
 */
private Response processServiceIntentRequest(ServiceIntentCommonRequest request, Action action, String version, String requestId, HashMap<String, String> instanceIdMap, String requestUri) throws ApiException {
    String defaultServiceModelName = "COMMON_SI_DEFAULT";
    String requestScope = ModelType.service.name();
    String apiVersion = version.substring(1);
    String serviceRequestJson = toString.apply(request);
    String instanceName = null;
    String modelUuid = null;
    String serviceInstanceId = null;
    try {
        if (action == Action.createInstance) {
            instanceName = ((ServiceIntentCreationRequest) request).getName();
            modelUuid = ((ServiceIntentCreationRequest) request).getModelUuid();
        } else if (action == Action.updateInstance) {
            instanceName = ((ServiceIntentModificationRequest) request).getName();
            serviceInstanceId = ((ServiceIntentModificationRequest) request).getServiceInstanceID();
        } else if (action == Action.deleteInstance) {
            serviceInstanceId = ((ServiceIntentDeletionRequest) request).getServiceInstanceID();
        }
    } catch (Exception e) {
        logger.error("ERROR: processCllServiceRequest: Exception: ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, MsoException.ServiceException, "processCllServiceRequest error", ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        return response;
    }
    if (serviceRequestJson != null) {
        InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, requestScope, serviceRequestJson);
        requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
        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(modelUuid, action, defaultServiceModelName);
        } catch (Exception e) {
            logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communicate 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();
        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 RequestClientParameter 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 : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ServiceIntentModificationRequest(org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentModificationRequest) 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) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)

Example 12 with ErrorLoggerInfo

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

the class WorkflowSpecificationsHandler method catchAndThrowValidationEx.

private Response catchAndThrowValidationEx(JsonProcessingException e) throws ValidateException {
    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;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException)

Example 13 with ErrorLoggerInfo

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

the class RequestHandlerUtils method buildErrorOnDuplicateRecord.

public void buildErrorOnDuplicateRecord(InfraActiveRequests currentActiveReq, Actions action, Map<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) throws ApiException {
    String instance = null;
    if (instanceName != null) {
        instance = instanceName;
    } else {
        instance = instanceIdMap.get(requestScope + "InstanceId");
    }
    ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DUPLICATE_FOUND, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
    DuplicateRequestException dupException = new DuplicateRequestException.Builder(requestScope, instance, dup.getRequestStatus(), dup.getRequestId(), HttpStatus.SC_CONFLICT, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
    updateStatus(currentActiveReq, Status.FAILED, dupException.getMessage());
    throw dupException;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) DuplicateRequestException(org.onap.so.apihandlerinfra.exceptions.DuplicateRequestException)

Example 14 with ErrorLoggerInfo

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

Example 15 with ErrorLoggerInfo

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

the class CreateEcompOperationalEnvironmentTest method testProcessException.

@Test
public void testProcessException() throws JsonProcessingException {
    wireMockServer.stubFor(put(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_ACCEPTED)));
    wireMockServer.stubFor(post(urlPathMatching("/events/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND)));
    ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
    ValidateException expectedException = new ValidateException.Builder("Could not publish DMaap", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    InfraActiveRequests iar = new InfraActiveRequests();
    String uuid = UUID.randomUUID().toString();
    iar.setRequestId(uuid);
    iar.setOperationalEnvName("myOpEnv");
    iar.setRequestScope("create");
    iar.setRequestStatus("PENDING");
    iar.setRequestAction("UNKNOWN");
    wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + uuid)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
    wireMockServer.stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(containing("{\"requestId\":\"" + uuid + "\",\"requestStatus\":\"FAILED\",\"statusMessage\":\"FAILURE, operationalEnvironmentId - operationalEnvId; Error message:")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
    try {
        createEcompOpEn.execute(uuid, getCloudOrchestrationRequest());
    } catch (ApiException e) {
        assertThat(e, sameBeanAs((ApiException) expectedException).ignoring("cause"));
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

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