Search in sources :

Example 21 with ValidateException

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

the class ActivateVnfStatusOperationalEnvironment method callSDClientForRetry.

/**
 * The Method to call SDC for recoveryActioin RETRY
 *
 * @param queryDistributionDbResponse - OperationalEnvDistributionStatus object
 * @param queryServiceModelResponse - OperationalEnvServiceModelStatus object
 * @param sdcStatus - Distribution object
 * @return JSONObject object
 */
public JSONObject callSDClientForRetry(OperationalEnvDistributionStatus queryDistributionDbResponse, OperationalEnvServiceModelStatus queryServiceModelResponse, Distribution sdcStatus) throws ApiException {
    JSONObject jsonResponse = null;
    String operEnvironmentId = queryDistributionDbResponse.getOperationalEnvId();
    String serviceModelVersionId = queryDistributionDbResponse.getServiceModelVersionId();
    String originalRequestId = queryServiceModelResponse.getRequestId();
    int retryCount = queryServiceModelResponse.getRetryCount();
    String workloadContext = queryServiceModelResponse.getWorkloadContext();
    jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operEnvironmentId, workloadContext);
    String statusCode = jsonResponse.get("statusCode").toString();
    if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
        String newDistributionId = jsonResponse.get("distributionId").toString();
        // should insert 1 row, NEW distributionId for replacement of the serviceModelServiceId record
        OperationalEnvDistributionStatus insertNewDistributionId = dbHelper.insertRecordToOperationalEnvDistributionStatus(newDistributionId, operEnvironmentId, serviceModelVersionId, originalRequestId, DISTRIBUTION_STATUS_SENT, "");
        client.save(insertNewDistributionId);
        // update retryCount (less 1) for the serviceModelServiceId
        retryCount = retryCount - 1;
        // should update 1 row, original insert
        OperationalEnvServiceModelStatus updateRetryCountAndStatus = dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse, DISTRIBUTION_STATUS_SENT, retryCount);
        client.save(updateRetryCountAndStatus);
        // should update 1 row, OLD distributionId set to status error (ie, old distributionId is DONE!).
        OperationalEnvDistributionStatus updateStatus = dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse, DISTRIBUTION_STATUS_ERROR, sdcStatus.getErrorReason());
        client.save(updateStatus);
    } else {
        String dbErrorMessage = "Failure calling SDC: statusCode: " + statusCode + "; messageId: " + jsonResponse.get("messageId") + "; message: " + jsonResponse.get("message");
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
        ValidateException validateException = new ValidateException.Builder(dbErrorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        requestDb.updateInfraFailureCompletion(dbErrorMessage, this.origRequestId, operEnvironmentId);
        throw validateException;
    }
    return jsonResponse;
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)

Example 22 with ValidateException

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

the class ActivateVnfStatusOperationalEnvironment method checkOrUpdateOverallStatus.

/**
 * The Method to check the overall status of the Activation for an operationalEnvironmentId
 *
 * @param operationalEnvironmentId - string
 * @param origRequestId - string
 * @return void - nothing
 */
public void checkOrUpdateOverallStatus(String operationalEnvironmentId, String origRequestId) throws ApiException {
    List<OperationalEnvServiceModelStatus> queryServiceModelResponseList = client.getAllByOperationalEnvIdAndRequestId(operationalEnvironmentId, origRequestId);
    String status = "Waiting";
    int count = 0;
    // loop through the statuses of the service model
    for (OperationalEnvServiceModelStatus querySrvModelResponse : queryServiceModelResponseList) {
        status = querySrvModelResponse.getServiceModelVersionDistrStatus();
        // all should be OK to be completed.
        if ((status.equals(DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString()) && (querySrvModelResponse.getRetryCount() == 0))) {
            status = "Completed";
            count++;
        }
        // one error with zero retry, means all are failures.
        if ((status.equals(DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString()) && (querySrvModelResponse.getRetryCount() == 0))) {
            status = "Failure";
            count = queryServiceModelResponseList.size();
            break;
        }
    }
    if (status.equals("Completed") && queryServiceModelResponseList.size() == count) {
        String messageStatus = "Overall Activation process is complete. " + status;
        isOverallSuccess = true;
        requestDb.updateInfraSuccessCompletion(messageStatus, origRequestId, operationalEnvironmentId);
    } else {
        if (status.equals("Failure") && queryServiceModelResponseList.size() == count) {
            this.errorMessage = "Overall Activation process is a Failure. " + status;
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
            ValidateException validateException = new ValidateException.Builder(this.errorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
            requestDb.updateInfraFailureCompletion(this.errorMessage, origRequestId, operationalEnvironmentId);
            throw validateException;
        }
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)

Example 23 with ValidateException

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

the class CreateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    try {
        setRequest(request);
        ObjectMapper objectMapper = new ObjectMapper();
        AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
        if (aaiResultWrapper.isEmpty()) {
            throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
        }
        OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
        // Find ECOMP environments in GRM
        logger.debug(" Start of GRM findRunningServicesAsString");
        String searchKey = getSearchKey(aaiEnv);
        String tenantContext = getTenantContext().toUpperCase();
        String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
        ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
        if (sel.getServiceEndPointList().size() == 0) {
            throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
        }
        // Replicate end-point for VNF Operating environment in GRM
        List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
        int ctr = 0;
        int total = serviceEndpointRequestList.size();
        for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
            logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
            getGrmClient().addServiceEndPoint(requestList);
        }
        // Create VNF operating in A&AI
        aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
        aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
        // Update request database
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
}
Also used : ServiceEndPointList(org.onap.so.client.grm.beans.ServiceEndPointList) ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) AAIClientObjectBuilder(org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder) NotFoundException(javax.ws.rs.NotFoundException) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) NotFoundException(javax.ws.rs.NotFoundException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 24 with ValidateException

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

the class CloudOrchestration method convertJsonToCloudOrchestrationRequest.

private CloudOrchestrationRequest convertJsonToCloudOrchestrationRequest(String requestJSON, Action action, long startTime, CloudOrchestrationRequest cor) throws ApiException {
    try {
        logger.debug("Converting incoming JSON request to Object");
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
    } catch (IOException 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();
        if (tenantIsolationRequest.getRequestId() != null) {
            tenantIsolationRequest.createRequestRecord(Status.FAILED, action);
        }
        throw validateException;
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 25 with ValidateException

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

the class CloudResourcesOrchestration method unlockOrchestrationRequest.

@POST
@Path("/{version: [vV][1]}/{requestId}/unlock")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Unlock CloudOrchestration requests for a specified requestId")
@Transactional
public Response unlockOrchestrationRequest(String requestJSON, @PathParam("requestId") String requestId, @PathParam("version") String version) throws ApiException {
    TenantIsolationRequest msoRequest = new TenantIsolationRequest(requestId);
    InfraActiveRequests infraActiveRequest;
    CloudOrchestrationRequest cor;
    logger.debug("requestId is: {}", requestId);
    try {
        ObjectMapper mapper = new ObjectMapper();
        cor = mapper.readValue(requestJSON, CloudOrchestrationRequest.class);
    } catch (IOException 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(cor);
    } catch (ValidationException e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
    try {
        infraActiveRequest = requestDbClient.getInfraActiveRequestbyRequestId(requestId);
    } catch (Exception e) {
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).build();
        throw validateException;
    }
    if (infraActiveRequest == null) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.BusinessProcessError).build();
        ValidateException validateException = new ValidateException.Builder("Orchestration RequestId " + requestId + " is not found in DB", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        throw validateException;
    } else {
        String status = infraActiveRequest.getRequestStatus();
        if ("IN_PROGRESS".equalsIgnoreCase(status) || "PENDING".equalsIgnoreCase(status) || "PENDING_MANUAL_TASK".equalsIgnoreCase(status)) {
            infraActiveRequest.setRequestStatus("UNLOCKED");
            infraActiveRequest.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER);
            infraActiveRequest.setRequestId(requestId);
            requestDbClient.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 : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) IOException(java.io.IOException) 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) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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

ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)29 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)25 IOException (java.io.IOException)16 ValidationException (org.onap.so.exceptions.ValidationException)14 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)11 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)11 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Operation (io.swagger.v3.oas.annotations.Operation)8 Transactional (javax.transaction.Transactional)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)7 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)4 GET (javax.ws.rs.GET)3 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)3 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SimpleDateFormat (java.text.SimpleDateFormat)2