Search in sources :

Example 16 with OperationalEnvServiceModelStatus

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

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

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

the class ActivateVnfStatusOperationalEnvironment method processActivateSDCStatus.

/**
 * The Method to process the Activation Status from SDC
 *
 * @param sdcDistributionId - string
 * @param sdcStatus - Distribution object
 * @param queryDistributionDbResponse - OperationalEnvDistributionStatus object
 * @param queryServiceModelResponse - OperationalEnvServiceModelStatus object
 * @return void - nothing
 */
public void processActivateSDCStatus(String sdcDistributionId, Distribution sdcStatus, OperationalEnvDistributionStatus queryDistributionDbResponse, OperationalEnvServiceModelStatus queryServiceModelResponse) throws ApiException {
    String sdcStatusValue = sdcStatus.getStatus().toString();
    String recoveryAction = queryServiceModelResponse.getRecoveryAction();
    int retryCount = queryServiceModelResponse.getRetryCount();
    // Validate/process status
    if (sdcStatus.getStatus().toString().equals(DISTRIBUTION_STATUS_OK)) {
        // should update 1 row, update status to "DISTRIBUTION_COMPLETE_OK"
        OperationalEnvDistributionStatus updateDistStatusOk = dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse, sdcStatusValue, "");
        client.save(updateDistStatusOk);
        // should update 1 row, update status and retryCount = 0 (ie, serviceModelVersionId is DONE!)
        OperationalEnvServiceModelStatus updateRetryCountZeroAndStatusOk = dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse, sdcStatusValue, RETRY_COUNT_ZERO);
        client.save(updateRetryCountZeroAndStatusOk);
    } else {
        // "DISTRIBUTION_COMPLETE_ERROR", Check if recoveryAction is "RETRY"
        if (recoveryAction.equals(RECOVERY_ACTION_RETRY) && retryCount > RETRY_COUNT_ZERO) {
            // RESEND / RETRY serviceModelVersionId to SDC
            JSONObject jsonResponse = callSDClientForRetry(queryDistributionDbResponse, queryServiceModelResponse, sdcStatus);
        } else {
            if (recoveryAction.equals(RECOVERY_ACTION_SKIP) || recoveryAction.equals(RECOVERY_ACTION_ABORT)) {
                String modifiedStatus = "";
                String errorReason = "";
                if (recoveryAction.equals(RECOVERY_ACTION_SKIP)) {
                    // considered SUCCESS
                    modifiedStatus = DISTRIBUTION_STATUS_OK;
                } else {
                    if (recoveryAction.equals(RECOVERY_ACTION_ABORT)) {
                        // ABORT, error
                        modifiedStatus = DISTRIBUTION_STATUS_ERROR;
                        errorReason = ERROR_REASON_ABORTED;
                    }
                }
                sdcStatusValue = modifiedStatus;
                OperationalEnvServiceModelStatus updateRetryCountZeroAndStatus = dbHelper.updateRetryCountAndStatusInOperationalEnvServiceModelStatus(queryServiceModelResponse, modifiedStatus, RETRY_COUNT_ZERO);
                client.save(updateRetryCountZeroAndStatus);
                OperationalEnvDistributionStatus updateDistStatus = dbHelper.updateStatusInOperationalEnvDistributionStatus(queryDistributionDbResponse, modifiedStatus, errorReason);
                client.save(updateDistStatus);
            } else {
            // RETRY & Count = 0 (do nothing!)
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) OperationalEnvDistributionStatus(org.onap.so.db.request.beans.OperationalEnvDistributionStatus) OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)

Example 19 with OperationalEnvServiceModelStatus

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

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

the class RequestsDbClientTest method findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdTest.

@Test
public void findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdTest() {
    OperationalEnvServiceModelStatus operationalEnvServiceModelStatus = requestsDbClient.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("1234", "TEST1234", "00032ab7-3fb3-42e5-965d-8ea592502017");
    assertNotNull(operationalEnvServiceModelStatus);
    assertEquals("1234", operationalEnvServiceModelStatus.getOperationalEnvId());
    assertEquals("TEST1234", operationalEnvServiceModelStatus.getServiceModelVersionId());
    OperationalEnvServiceModelStatus operationalEnvServiceModelStatus1 = requestsDbClient.findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId("1234", "TEST1235", "00032ab7-3fb3-42e5-965d-8ea592502018");
    assertNotNull(operationalEnvServiceModelStatus1);
    assertEquals("00032ab7-3fb3-42e5-965d-8ea592502018", operationalEnvServiceModelStatus1.getRequestId());
    assertEquals("1234", operationalEnvServiceModelStatus1.getOperationalEnvId());
    assertEquals("TEST1235", operationalEnvServiceModelStatus1.getServiceModelVersionId());
}
Also used : OperationalEnvServiceModelStatus(org.onap.so.db.request.beans.OperationalEnvServiceModelStatus) Test(org.junit.Test)

Aggregations

OperationalEnvServiceModelStatus (org.onap.so.db.request.beans.OperationalEnvServiceModelStatus)20 Test (org.junit.Test)13 BaseTest (org.onap.so.apihandlerinfra.BaseTest)11 OperationalEnvDistributionStatus (org.onap.so.db.request.beans.OperationalEnvDistributionStatus)11 JSONObject (org.json.JSONObject)7 Distribution (org.onap.so.apihandlerinfra.tenantisolationbeans.Distribution)7 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)7 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)4 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)3 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 AAIFluentTypeBuilder (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder)1 ServiceModelList (org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList)1 NoEntityFoundException (org.onap.so.db.request.exceptions.NoEntityFoundException)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1