Search in sources :

Example 66 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class ResumeOrchestrationRequest method checkForInProgressRequest.

protected void checkForInProgressRequest(InfraActiveRequests currentActiveRequest, HashMap<String, String> instanceIdMap, String requestScope, String instanceName, Action action) throws ApiException {
    boolean inProgress = false;
    InfraActiveRequests requestInProgress = requestHandlerUtils.duplicateCheck(action, instanceIdMap, instanceName, requestScope, currentActiveRequest);
    if (requestInProgress != null) {
        inProgress = requestHandlerUtils.camundaHistoryCheck(requestInProgress, currentActiveRequest);
    }
    if (inProgress) {
        requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveRequest, action, instanceIdMap, instanceName, requestScope, requestInProgress);
    }
}
Also used : InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests)

Example 67 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests 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 68 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class ServiceIntentApiHandler method createRequestObject.

private InfraActiveRequests createRequestObject(ServiceIntentCommonRequest request, Action action, String requestId, Status status, String requestScope, String requestJson) {
    InfraActiveRequests aq = new InfraActiveRequests();
    try {
        String serviceInstanceName = null;
        String serviceInstanceId = null;
        String serviceType = request.getServiceType();
        if (action.name().equals("createInstance")) {
            serviceInstanceName = ((ServiceIntentCreationRequest) request).getName();
            aq.setServiceInstanceName(serviceInstanceName);
        } else if (action.name().equals("updateInstance")) {
            serviceInstanceName = ((ServiceIntentModificationRequest) request).getName();
            serviceInstanceId = ((ServiceIntentModificationRequest) request).getServiceInstanceID();
            aq.setServiceInstanceName(serviceInstanceName);
            aq.setServiceInstanceId(serviceInstanceId);
        } else if (action.name().equals("deleteInstance")) {
            serviceInstanceId = ((ServiceIntentDeletionRequest) request).getServiceInstanceID();
            aq.setServiceInstanceId(serviceInstanceId);
        }
        aq.setRequestId(requestId);
        aq.setRequestAction(action.toString());
        aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
        Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis());
        aq.setStartTime(startTimeStamp);
        aq.setRequestScope(requestScope);
        aq.setRequestBody(requestJson);
        aq.setRequestStatus(status.toString());
        aq.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
        aq.setServiceType(serviceType);
    } catch (Exception e) {
        logger.error("Exception when creation record request", e);
        if (!status.equals(Status.FAILED)) {
            throw e;
        }
    }
    return aq;
}
Also used : ServiceIntentModificationRequest(org.onap.so.apihandlerinfra.serviceintentinstancebeans.ServiceIntentModificationRequest) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) Timestamp(java.sql.Timestamp) 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)

Example 69 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class RequestHandlerUtils method createNewRecordCopyFromInfraActiveRequest.

protected InfraActiveRequests createNewRecordCopyFromInfraActiveRequest(InfraActiveRequests infraActiveRequest, String requestId, Timestamp startTimeStamp, String source, String requestUri, String requestorId, String originalRequestId) throws ApiException {
    InfraActiveRequests request = new InfraActiveRequests();
    request.setRequestId(requestId);
    request.setStartTime(startTimeStamp);
    request.setSource(source);
    request.setRequestUrl(requestUri);
    request.setProgress(new Long(5));
    request.setRequestorId(requestorId);
    request.setRequestStatus(Status.IN_PROGRESS.toString());
    request.setOriginalRequestId(originalRequestId);
    request.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
    if (infraActiveRequest != null) {
        request.setTenantId(infraActiveRequest.getTenantId());
        request.setRequestBody(updateRequestorIdInRequestBody(infraActiveRequest, requestorId));
        request.setCloudRegion(infraActiveRequest.getCloudRegion());
        request.setRequestScope(infraActiveRequest.getRequestScope());
        request.setRequestAction(infraActiveRequest.getRequestAction());
        setInstanceIdAndName(infraActiveRequest, request);
    }
    return request;
}
Also used : InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests)

Example 70 with InfraActiveRequests

use of org.onap.so.db.request.beans.InfraActiveRequests in project so by onap.

the class MsoHeatUtils method saveStackRequest.

protected void saveStackRequest(CreateStackParam request, String requestId, String stackName) {
    try {
        ObjectMapper mapper = new ObjectMapper();
        InfraActiveRequests foundRequest = requestDBClient.getInfraActiveRequestbyRequestId(requestId);
        CreateStackRequest createStackRequest = new CreateStackRequest();
        createStackRequest.setEnvironment(request.getEnvironment());
        createStackRequest.setParameters(request.getParameters());
        String stackRequest = mapper.writeValueAsString(createStackRequest);
        CloudApiRequests cloudReq = new CloudApiRequests();
        cloudReq.setCloudIdentifier(stackName);
        cloudReq.setRequestBody(stackRequest);
        cloudReq.setRequestId(requestId);
        CloudApiRequests foundCloudReq = foundRequest.getCloudApiRequests().stream().filter(cloudReqToFind -> stackName.equals(cloudReq.getCloudIdentifier())).findAny().orElse(null);
        if (foundCloudReq != null) {
            foundCloudReq.setRequestBody(stackRequest);
        } else {
            foundRequest.getCloudApiRequests().add(cloudReq);
        }
        requestDBClient.updateInfraActiveRequests(foundRequest);
    } catch (Exception e) {
        logger.error("Error updating in flight request with Openstack Create Request", e);
    }
}
Also used : CloudApiRequests(org.onap.so.db.request.beans.CloudApiRequests) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CreateStackRequest(org.onap.so.openstack.beans.CreateStackRequest) VduException(org.onap.so.adapters.vdu.VduException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Aggregations

InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)214 Test (org.junit.Test)119 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)29 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 Timestamp (java.sql.Timestamp)23 HttpEntity (org.springframework.http.HttpEntity)21 IOException (java.io.IOException)20 HashMap (java.util.HashMap)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)20 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)19 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)19 BaseTest (org.onap.so.apihandlerinfra.BaseTest)18 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)18 ArrayList (java.util.ArrayList)16 ValidationException (org.onap.so.exceptions.ValidationException)15 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)13 Transactional (javax.transaction.Transactional)13 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)11