Search in sources :

Example 21 with ApiException

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

the class Onap3gppServiceInstances method processServiceInstanceRequest.

/**
 * Process allocate service request and send request to corresponding workflow
 *
 * @param request
 * @param action
 * @param version
 * @return
 * @throws ApiException
 */
private Response processServiceInstanceRequest(Allocate3gppService 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(request.getModelUuid(), 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();
        RequestClientParameter parameter;
        try {
            parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(null).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 22 with ApiException

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

the class Onap3gppServiceInstances 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 23 with ApiException

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

the class Onap3gppServiceInstances method getSubnetCapabilities.

private Response getSubnetCapabilities(List<SubnetTypes> subnetTypes, String version) throws ApiException {
    ObjectMapper oMapper = new ObjectMapper();
    String inputFileString = "";
    Map<String, Object> subnetCapability = new HashMap<>();
    BufferedReader br = null;
    try {
        logger.debug("Reading SubnetCapability file");
        br = new BufferedReader(new FileReader(new File(subnetCapabilityConfigFile)));
        StringBuilder sb = new StringBuilder();
        String line = br.readLine();
        while (line != null) {
            sb.append(line);
            sb.append("\n");
            line = br.readLine();
        }
        inputFileString = sb.toString();
        subnetCapability = oMapper.readValue(inputFileString, Map.class);
    } catch (Exception e) {
        logger.debug("Exception while reading subnet capability value from json", e);
    }
    Map<String, Object> responseMap = new HashMap<>();
    for (SubnetTypes value : subnetTypes) {
        if (subnetCapability.containsKey(value.toString())) {
            responseMap.put(value.toString(), subnetCapability.get(value.toString()));
        }
    }
    String response = null;
    try {
        response = oMapper.writeValueAsString(responseMap);
    } catch (JsonProcessingException e) {
        logger.debug("Exception while converting subnet capability object to String {}", e);
    }
    return builder.buildResponse(HttpStatus.SC_OK, null, response, version);
}
Also used : HashMap(java.util.HashMap) 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) SubnetTypes(org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.SubnetTypes) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 24 with ApiException

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

the class OrchestrationRequests method infraActiveRequestLookup.

protected InfraActiveRequests infraActiveRequestLookup(String requestId) throws ApiException {
    InfraActiveRequests infraActiveRequest = null;
    try {
        infraActiveRequest = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
    } catch (Exception e) {
        logger.error("Exception occurred while communicating with RequestDb during InfraActiveRequest 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 InfraActiveRequest lookup", HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    if (infraActiveRequest == null) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, 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();
        throw validateException;
    }
    return infraActiveRequest;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) 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) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException)

Example 25 with ApiException

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

the class OrchestrationRequests method unlockOrchestrationRequest.

@POST
@Path("/{version: [vV][4-7]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock Orchestrated Requests for a given requestId", responses = @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
    logger.debug("requestId is: {}", requestId);
    ServiceInstancesRequest sir;
    try {
        ObjectMapper mapper = new ObjectMapper();
        sir = mapper.readValue(requestJSON, ServiceInstancesRequest.class);
    } 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 : " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    try {
        msoRequest.parseOrchestration(sir);
    } catch (Exception e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        ValidateException validateException = new ValidateException.Builder("Error parsing request: " + e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    InfraActiveRequests infraActiveRequest = infraActiveRequestLookup(requestId);
    String status = infraActiveRequest.getRequestStatus();
    if (Status.IN_PROGRESS.toString().equalsIgnoreCase(status) || Status.PENDING.toString().equalsIgnoreCase(status) || Status.PENDING_MANUAL_TASK.toString().equalsIgnoreCase(status)) {
        infraActiveRequest.setRequestStatus(Status.UNLOCKED.toString());
        infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
        infraActiveRequest.setRequestId(requestId);
        requestsDbClient.save(infraActiveRequest);
    } else {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " has a status of " + status + " and can not be unlocked", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).entity("").build();
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) IOException(java.io.IOException) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ValidationException(org.onap.so.exceptions.ValidationException) 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

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