Search in sources :

Example 6 with RequestClientParameter

use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.

the class VfModuleRestHandlerTest method test_buildRequestParams.

@Test
public void test_buildRequestParams() throws Exception {
    RequestClientParameter expected = new RequestClientParameter.Builder().setRequestId("requestId").setServiceInstanceId("serviceInstanceId").setVnfId("vnfId").setVfModuleId("vfModuleId").setALaCarte(true).setRequestDetails(mapper.writeValueAsString(createTestRequest())).setRequestAction(Action.deleteInstance.toString()).setRequestUri("http://localhost:8080/serviceInstances").setApiVersion("v8").build();
    RequestClientParameter actual = restHandler.buildRequestParams(createTestRequest(), "http://localhost:8080/serviceInstances", "requestId", "serviceInstanceId", "vnfId", "vfModuleId");
    assertThat(actual, sameBeanAs(expected));
}
Also used : RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) Test(org.junit.Test)

Example 7 with RequestClientParameter

use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.

the class ServiceInstanceRestHandlerTest method test_buildRequestParams.

@Test
public void test_buildRequestParams() throws Exception {
    RequestClientParameter expected = new RequestClientParameter.Builder().setRequestId("requestId").setServiceInstanceId("serviceInstanceId").setALaCarte(true).setRequestDetails(mapper.writeValueAsString(createTestRequest())).setRequestAction(Action.deleteInstance.toString()).setRequestUri("http://localhost:8080/serviceInstances").setApiVersion("v8").build();
    RequestClientParameter actual = restHandler.buildRequestParams(createTestRequest(), "http://localhost:8080/serviceInstances", "requestId", "serviceInstanceId");
    assertThat(actual, sameBeanAs(expected));
}
Also used : RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) Test(org.junit.Test)

Example 8 with RequestClientParameter

use of org.onap.so.apihandler.common.RequestClientParameter 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 RequestClientParameter

use of org.onap.so.apihandler.common.RequestClientParameter 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 RequestClientParameter

use of org.onap.so.apihandler.common.RequestClientParameter in project so by onap.

the class ResumeOrchestrationRequest method resumeRequest.

protected Response resumeRequest(InfraActiveRequests infraActiveRequest, InfraActiveRequests currentActiveRequest, String version, String requestUri) throws ApiException {
    String requestBody = infraActiveRequest.getRequestBody();
    Action action = Action.valueOf(infraActiveRequest.getRequestAction());
    String requestId = currentActiveRequest.getRequestId();
    String requestScope = infraActiveRequest.getRequestScope();
    String instanceName = getInstanceName(infraActiveRequest, requestScope, currentActiveRequest);
    HashMap<String, String> instanceIdMap = setInstanceIdMap(infraActiveRequest, requestScope);
    checkForInProgressRequest(currentActiveRequest, instanceIdMap, requestScope, instanceName, action);
    ServiceInstancesRequest sir = null;
    sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestBody, action, requestId, requestUri);
    Boolean aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
    String pnfCorrelationId = serviceInstances.getPnfCorrelationId(sir);
    RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, msoRequest.getAlacarteFlag(sir), currentActiveRequest);
    requestDbSave(currentActiveRequest);
    if (aLaCarte == null) {
        aLaCarte = setALaCarteFlagIfNull(requestScope, action);
    }
    RequestClientParameter requestClientParameter = setRequestClientParameter(recipeLookupResult, version, infraActiveRequest, currentActiveRequest, pnfCorrelationId, aLaCarte, sir);
    return requestHandlerUtils.postBPELRequest(currentActiveRequest, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter)

Aggregations

RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)26 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)16 IOException (java.io.IOException)15 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)14 Response (javax.ws.rs.core.Response)13 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)11 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)11 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)11 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)11 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)11 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)10 Test (org.junit.Test)9 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)8 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)8 GetE2EServiceInstanceResponse (org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JSONObject (org.json.JSONObject)4 ValidationException (org.onap.so.exceptions.ValidationException)4 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)3