Search in sources :

Example 6 with ApiException

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

the class OrchestrationRequests method getOrchestrationRequest.

@GET
@Path("/{version:[vV][4-8]}/{requestId}")
@Operation(description = "Find Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public Response getOrchestrationRequest(@PathParam("requestId") String requestId, @PathParam("version") String version, @QueryParam("includeCloudRequest") boolean includeCloudRequest, @QueryParam(value = "format") String format) throws ApiException {
    GetOrchestrationResponse orchestrationResponse = new GetOrchestrationResponse();
    InfraActiveRequests infraActiveRequest = null;
    List<org.onap.so.db.request.beans.RequestProcessingData> requestProcessingData = null;
    if (!UUIDChecker.isValidUUID(requestId)) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MODIFIED_BY_APIHANDLER).build();
        throw new ValidateException.Builder("Request Id " + requestId + " is not a valid UUID", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    infraActiveRequest = infraActiveRequestLookup(requestId);
    if (isRequestProcessingDataRequired(format)) {
        try {
            requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId);
        } catch (Exception e) {
            logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", e);
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build();
            ValidateException validateException = new ValidateException.Builder("Exception occurred while communicating with RequestDb during requestProcessingData lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format, version);
    if (null != requestProcessingData && !requestProcessingData.isEmpty()) {
        request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData));
    }
    request.setRequestId(requestId);
    orchestrationResponse.setRequest(request);
    return builder.buildResponse(HttpStatus.SC_OK, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID), orchestrationResponse, version);
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestProcessingData(org.onap.so.db.request.beans.RequestProcessingData) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) 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) GetOrchestrationResponse(org.onap.so.serviceinstancebeans.GetOrchestrationResponse) 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 7 with ApiException

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

the class OrchestrationRequests method mapInfraActiveRequestToRequest.

protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, String format, String version) throws ApiException {
    String requestBody = iar.getRequestBody();
    Request request = new Request();
    ObjectMapper mapper = new ObjectMapper();
    request.setRequestId(iar.getRequestId());
    request.setRequestScope(iar.getRequestScope());
    request.setRequestType(iar.getRequestAction());
    String originalRequestId = iar.getOriginalRequestId();
    if (originalRequestId != null) {
        request.setOriginalRequestId(originalRequestId);
    }
    if (!version.matches("v[1-7]")) {
        String workflowName = iar.getWorkflowName();
        if (workflowName == null) {
            workflowName = iar.getRequestAction();
        }
        request.setWorkflowName(workflowName);
        String operationName = iar.getOperationName();
        if (operationName != null) {
            request.setOperationName(operationName);
        }
    }
    InstanceReferences ir = new InstanceReferences();
    if (iar.getNetworkId() != null)
        ir.setNetworkInstanceId(iar.getNetworkId());
    if (iar.getNetworkName() != null)
        ir.setNetworkInstanceName(iar.getNetworkName());
    if (iar.getServiceInstanceId() != null)
        ir.setServiceInstanceId(iar.getServiceInstanceId());
    if (iar.getServiceInstanceName() != null)
        ir.setServiceInstanceName(iar.getServiceInstanceName());
    if (iar.getVfModuleId() != null)
        ir.setVfModuleInstanceId(iar.getVfModuleId());
    if (iar.getVfModuleName() != null)
        ir.setVfModuleInstanceName(iar.getVfModuleName());
    if (iar.getVnfId() != null)
        ir.setVnfInstanceId(iar.getVnfId());
    if (iar.getVnfName() != null)
        ir.setVnfInstanceName(iar.getVnfName());
    if (iar.getVolumeGroupId() != null)
        ir.setVolumeGroupInstanceId(iar.getVolumeGroupId());
    if (iar.getVolumeGroupName() != null)
        ir.setVolumeGroupInstanceName(iar.getVolumeGroupName());
    if (iar.getInstanceGroupId() != null)
        ir.setInstanceGroupId(iar.getInstanceGroupId());
    if (iar.getInstanceGroupName() != null)
        ir.setInstanceGroupName(iar.getInstanceGroupName());
    request.setInstanceReferences(ir);
    RequestDetails requestDetails = null;
    if (StringUtils.isNotBlank(requestBody)) {
        try {
            if (requestBody.contains("\"requestDetails\":")) {
                ServiceInstancesRequest sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
                requestDetails = sir.getRequestDetails();
            } else {
                requestDetails = mapper.readValue(requestBody, RequestDetails.class);
            }
            if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) {
                requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName());
            }
            if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) {
                requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName());
            }
        } catch (IOException e) {
            logger.error("Exception occurred", 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 : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
            throw validateException;
        }
    }
    request.setRequestDetails(requestDetails);
    if (iar.getStartTime() != null) {
        String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
        request.setStartTime(startTimeStamp);
    }
    if (iar.getEndTime() != null) {
        String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
        request.setFinishTime(endTimeStamp);
    }
    RequestStatus status = new RequestStatus();
    if (iar.getModifyTime() != null) {
        String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT";
        status.setTimeStamp(timeStamp);
    }
    status.setRequestState(mapRequestStatusToRequest(iar, format));
    if (iar.getProgress() != null) {
        status.setPercentProgress(iar.getProgress().intValue());
    }
    if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) {
        iar.getCloudApiRequests().stream().forEach(cloudRequest -> {
            try {
                request.getCloudRequestData().add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), cloudRequest.getCloudIdentifier()));
            } catch (Exception e) {
                logger.error("Error reading Cloud Request", e);
            }
        });
    }
    mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version);
    request.setRequestStatus(status);
    return request;
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) Request(org.onap.so.serviceinstancebeans.Request) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) IOException(java.io.IOException) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) 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) InstanceReferences(org.onap.so.serviceinstancebeans.InstanceReferences) CloudRequestData(org.onap.so.serviceinstancebeans.CloudRequestData) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestStatus(org.onap.so.serviceinstancebeans.RequestStatus)

Example 8 with ApiException

use of org.onap.so.apihandlerinfra.exceptions.ApiException 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 9 with ApiException

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

Example 10 with ApiException

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

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