Search in sources :

Example 41 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class ActivateVnfOperationalEnvironment method processActivateSDCRequest.

/**
 * The Method to send the Activation Requests to SDC
 *
 * @param requestId - String
 * @param operationalEnvironmentId - String
 * @param serviceModelVersionIdList - List<ServiceModelList> list
 * @param workloadContext - String
 * @return jsonResponse - JSONObject object
 */
public void processActivateSDCRequest(String requestId, String operationalEnvironmentId, List<ServiceModelList> serviceModelVersionIdList, String workloadContext, String vnfOperationalEnvironmentId) throws ApiException {
    JSONObject jsonResponse = null;
    int retryCount = 0;
    try {
        retryCount = Integer.parseInt(sdcRetryCount);
    } catch (NumberFormatException e) {
        retryCount = DEFAULT_ACTIVATE_RETRY_COUNT;
    }
    // loop through the serviceModelVersionId, and send request SDC
    for (ServiceModelList serviceModelList : serviceModelVersionIdList) {
        String serviceModelVersionId = serviceModelList.getServiceModelVersionId();
        String recoveryAction = serviceModelList.getRecoveryAction().toString().toUpperCase();
        // should insert 1 row
        OperationalEnvServiceModelStatus serviceModelStatus = dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, DISTRIBUTION_STATUS_SENT, recoveryAction, retryCount, workloadContext, vnfOperationalEnvironmentId);
        client.save(serviceModelStatus);
        String distributionId = "";
        jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext);
        String statusCode = jsonResponse.get("statusCode").toString();
        if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
            distributionId = jsonResponse.get("distributionId").toString();
            // should insert 1 row
            OperationalEnvDistributionStatus distStatus = dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId, operationalEnvironmentId, serviceModelVersionId, requestId, DISTRIBUTION_STATUS_SENT, "");
            client.save(distStatus);
        } else {
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
            String dbErrorMessage = " Failure calling SDC: statusCode: " + statusCode + "; messageId: " + jsonResponse.get("messageId") + "; message: " + jsonResponse.get("message");
            requestDb.updateInfraFailureCompletion(dbErrorMessage, requestId, operationalEnvironmentId);
            throw new ValidateException.Builder(dbErrorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        }
    }
}
Also used : ServiceModelList(org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)

Example 42 with ErrorLoggerInfo

use of org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo in project so by onap.

the class DeactivateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    String operationalEnvironmentId = request.getOperationalEnvironmentId();
    OperationalEnvironment aaiOpEnv = getAAIOperationalEnvironment(operationalEnvironmentId);
    if (aaiOpEnv != null) {
        String operationalEnvironmentStatus = aaiOpEnv.getOperationalEnvironmentStatus();
        if (StringUtils.isBlank(operationalEnvironmentStatus)) {
            String error = "OperationalEnvironmentStatus is null on OperationalEnvironmentId: " + operationalEnvironmentId;
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
            throw new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
        }
        if (operationalEnvironmentStatus.equalsIgnoreCase("ACTIVE")) {
            aaiOpEnv.setOperationalEnvironmentStatus("INACTIVE");
            aaiHelper.updateAaiOperationalEnvironment(operationalEnvironmentId, aaiOpEnv);
        } else if (!operationalEnvironmentStatus.equalsIgnoreCase("INACTIVE")) {
            String error = "Invalid OperationalEnvironmentStatus on OperationalEnvironmentId: " + operationalEnvironmentId;
            ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
            ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
            requestDb.updateInfraFailureCompletion(error, requestId, operationalEnvironmentId);
            throw validateException;
        }
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY Deactivated OperationalEnvironment", requestId, operationalEnvironmentId);
    }
}
Also used : ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment)

Aggregations

ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)42 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)34 IOException (java.io.IOException)22 ResponseBuilder (org.onap.so.apihandler.common.ResponseBuilder)20 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)19 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)18 ValidationException (org.onap.so.exceptions.ValidationException)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)10 RequestDbFailureException (org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException)10 Operation (io.swagger.v3.oas.annotations.Operation)9 Transactional (javax.transaction.Transactional)9 Path (javax.ws.rs.Path)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Produces (javax.ws.rs.Produces)8 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)8 Consumes (javax.ws.rs.Consumes)6 Response (javax.ws.rs.core.Response)6 BPMNFailureException (org.onap.so.apihandlerinfra.exceptions.BPMNFailureException)6 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)5