Search in sources :

Example 6 with ErrorLoggerInfo

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

the class RequestHandlerUtils method getRequestId.

@Override
public String getRequestId(ContainerRequestContext requestContext) throws ValidateException {
    String requestId = null;
    if (requestContext.getProperty("requestId") != null) {
        requestId = requestContext.getProperty("requestId").toString();
    }
    if (UUIDChecker.isValidUUID(requestId)) {
        return requestId;
    } else {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder)

Example 7 with ErrorLoggerInfo

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

the class RequestHandlerUtils method getIsBaseVfModule.

protected Boolean getIsBaseVfModule(ModelInfo modelInfo, Actions action, String vnfType, String sdcServiceModelVersion, InfraActiveRequests currentActiveReq) throws ApiException {
    // Get VF Module-specific base module indicator
    VfModule vfm = null;
    String modelVersionId = modelInfo.getModelVersionId();
    Boolean isBaseVfModule = false;
    if (modelVersionId != null) {
        vfm = catalogDbClient.getVfModuleByModelUUID(modelVersionId);
    } else if (modelInfo.getModelInvariantId() != null && modelInfo.getModelVersion() != null) {
        vfm = catalogDbClient.getVfModuleByModelInvariantUUIDAndModelVersion(modelInfo.getModelInvariantId(), modelInfo.getModelVersion());
    }
    if (vfm != null) {
        if (vfm.getIsBase()) {
            isBaseVfModule = true;
        }
    } else if (action == Action.createInstance || action == Action.updateInstance) {
        String serviceVersionText = "";
        if (sdcServiceModelVersion != null && !sdcServiceModelVersion.isEmpty()) {
            serviceVersionText = " with version " + sdcServiceModelVersion;
        }
        String errorMessage = "VnfType " + vnfType + " and VF Module Model Name " + modelInfo.getModelName() + serviceVersionText + " not found in MSO Catalog DB";
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        VfModuleNotFoundException vfModuleException = new VfModuleNotFoundException.Builder(errorMessage, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
        updateStatus(currentActiveReq, Status.FAILED, vfModuleException.getMessage());
        throw vfModuleException;
    }
    return isBaseVfModule;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) VfModuleNotFoundException(org.onap.so.apihandlerinfra.exceptions.VfModuleNotFoundException) VfModule(org.onap.so.db.catalog.beans.VfModule)

Example 8 with ErrorLoggerInfo

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

the class RequestHandlerUtils method getServiceInstanceOrchestrationURI.

public RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, boolean alaCarteFlag, InfraActiveRequests currentActiveReq) throws ApiException {
    RecipeLookupResult recipeLookupResult = null;
    // if the aLaCarte flag is set to TRUE, the API-H should choose the VID_DEFAULT recipe for the requested action
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) {
        recipeLookupResult = getDefaultVnfUri(sir, action);
    } else if (action == Action.addMembers || action == Action.removeMembers) {
        recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
    } else if (modelInfo.getModelType().equals(ModelType.service)) {
        try {
            recipeLookupResult = getServiceURI(sir, action, alaCarteFlag);
        } catch (IOException 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();
            updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
            throw validateException;
        }
    } else if (modelInfo.getModelType().equals(ModelType.vfModule) || modelInfo.getModelType().equals(ModelType.volumeGroup) || modelInfo.getModelType().equals(ModelType.vnf)) {
        try {
            recipeLookupResult = getVnfOrVfModuleUri(sir, action);
        } catch (ValidationException 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();
            updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
            throw validateException;
        }
    } else if (modelInfo.getModelType().equals(ModelType.network)) {
        try {
            recipeLookupResult = getNetworkUri(sir, action);
        } catch (ValidationException 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();
            updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
            throw validateException;
        }
    } else if (modelInfo.getModelType().equals(ModelType.instanceGroup)) {
        recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
    }
    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();
        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) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) RecipeNotFoundException(org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) IOException(java.io.IOException)

Example 9 with ErrorLoggerInfo

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

the class Onap3gppServiceInstances method updateServiceInstances.

/**
 * process modify service request and call corresponding workflow
 *
 * @param request
 * @param action
 * @param version
 * @return
 * @throws ApiException
 */
private Response updateServiceInstances(Modify3gppService 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);
        String instanceName = request.getName();
        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(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 10 with ErrorLoggerInfo

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

the class Onap3gppServiceInstances method activateOrDeactivateServiceInstances.

/**
 * process activate/deactivate service request and call corresponding workflow
 *
 * @param request the request object for activate/deactivate service
 * @param action the action for the service
 * @param version
 * @return
 * @throws ApiException
 */
private Response activateOrDeactivateServiceInstances(ActivateOrDeactivate3gppService 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);
        if (action == Action.activateInstance) {
            requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, request.getServiceInstanceID());
        } else {
            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)

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