Search in sources :

Example 1 with WatchdogDistributionStatus

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

the class ASDCController method treatNotification.

public void treatNotification(INotificationData iNotif) {
    int noOfArtifacts = 0;
    for (IResourceInstance resource : iNotif.getResources()) {
        noOfArtifacts += resource.getArtifacts().size();
    }
    logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF.toString(), noOfArtifacts, iNotif.getServiceUUID(), "ASDC");
    try {
        if (iNotif.getDistributionID() != null && !iNotif.getDistributionID().isEmpty()) {
            MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, iNotif.getDistributionID());
        }
        logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
        logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(), "ASDC", "treatNotification");
        this.changeControllerStatus(ASDCControllerStatus.BUSY);
        Optional<String> notificationMessage = getNotificationJson(iNotif);
        toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage, asdcConfig.getConsumerID());
        // Process only the Resource artifacts in MSO
        this.processResourceNotification(iNotif);
        // ********************************************************************************************************
        // Start Watchdog loop and wait for all components to complete before reporting final status back.
        // **If timer expires first then we will report a Distribution Error back to ASDC
        // ********************************************************************************************************
        long initialStartTime = System.currentTimeMillis();
        boolean componentsComplete = false;
        String distributionStatus = null;
        String watchdogError = null;
        String overallStatus = null;
        int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000;
        boolean isDeploySuccess = false;
        while (!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout) {
            try {
                distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
                Thread.sleep(watchDogTimeout / 10);
            } catch (Exception e) {
                logger.debug("Exception in Watchdog Loop {}", e.getMessage());
                Thread.sleep(watchDogTimeout / 10);
            }
            if (distributionStatus != null && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())) {
                if (distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())) {
                    isDeploySuccess = true;
                    overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name();
                } else {
                    overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
                }
                componentsComplete = true;
            }
        }
        if (!componentsComplete) {
            logger.debug("Timeout of {} seconds was reached before all components reported status", watchDogTimeout);
            watchdogError = "Timeout occurred while waiting for all components to report status";
            overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
        }
        if (distributionStatus == null) {
            overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
            logger.debug("DistributionStatus is null for DistributionId: {}", iNotif.getDistributionID());
        }
        try {
            wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus);
            logger.debug("A&AI Updated succefully with Distribution Status!");
        } catch (Exception e) {
            logger.debug("Exception in Watchdog executePatchAAI(): {}", e.getMessage());
            watchdogError = "Error calling A&AI " + e.getMessage();
            if (e.getCause() != null) {
                logger.debug("Exception caused by: {}", e.getCause().getMessage());
            }
        }
        wd.updateCatalogDBStatus(iNotif.getServiceInvariantUUID(), overallStatus);
        if (isDeploySuccess && watchdogError == null) {
            sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, null);
            WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
            wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString());
            wdsRepo.save(wds);
        } else {
            sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError);
            WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
            wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
            wdsRepo.save(wds);
        }
    } catch (ObjectOptimisticLockingFailureException e) {
        logger.debug("OptimisticLockingFailure for DistributionId: {} Another process " + "has already altered this distribution, so not going to process it on this site.", iNotif.getDistributionID());
        logger.error(LoggingAnchor.FIVE, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Database concurrency exception: ", "ASDC", "treatNotification", ErrorCode.BusinessProcessError.getValue(), "RuntimeException in treatNotification", e);
    } catch (Exception e) {
        logger.error("", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Unexpected exception caught during the notification processing", "ASDC", "treatNotification", ErrorCode.SchemaError.getValue(), "RuntimeException in treatNotification", e);
        try {
            wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
            logger.debug("A&AI Updated succefully with Distribution Status of {}", DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
        } catch (Exception aaiException) {
            logger.debug("Exception in executePatchAAI(): {}", aaiException);
            if (aaiException.getCause() != null) {
                logger.debug("Exception caused by: {}", aaiException.getCause().getMessage());
            }
        }
        sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, e.getMessage());
        WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
        wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
        wdsRepo.save(wds);
    } finally {
        this.changeControllerStatus(ASDCControllerStatus.IDLE);
    }
}
Also used : IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) ASDCParametersException(org.onap.so.asdc.client.exceptions.ASDCParametersException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException)

Example 2 with WatchdogDistributionStatus

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

the class WatchdogDistribution method getOverallDistributionStatus.

public String getOverallDistributionStatus(String distributionId) throws Exception {
    logger.debug("Entered getOverallDistributionStatus method for distrubutionId: {}", distributionId);
    String status = null;
    try {
        WatchdogDistributionStatus watchdogDistributionStatus = watchdogDistributionStatusRepository.findById(distributionId).orElseGet(() -> null);
        if (watchdogDistributionStatus == null) {
            watchdogDistributionStatus = new WatchdogDistributionStatus();
            watchdogDistributionStatus.setDistributionId(distributionId);
            watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
        }
        String distributionStatus = watchdogDistributionStatus.getDistributionIdStatus();
        if (DistributionStatus.TIMEOUT.name().equalsIgnoreCase(distributionStatus)) {
            logger.debug("Ignoring to update WatchdogDistributionStatus as distributionId: {} status is set to: {}", distributionId, distributionStatus);
            return DistributionStatus.TIMEOUT.name();
        } else {
            List<WatchdogComponentDistributionStatus> results = watchdogCDStatusRepository.findByDistributionId(distributionId);
            logger.debug("Executed RequestDB getWatchdogComponentDistributionStatus for distrubutionId: {}", distributionId);
            // *************************************************************************************************************************************************
            // **** Compare config values verse DB watchdog component names to see if every component has reported
            // status before returning final result back to ASDC
            // **************************************************************************************************************************************************
            List<WatchdogComponentDistributionStatus> cdStatuses = watchdogCDStatusRepository.findByDistributionId(distributionId);
            boolean allComponentsComplete = true;
            for (String name : componentNames) {
                boolean match = false;
                for (WatchdogComponentDistributionStatus cdStatus : cdStatuses) {
                    if (name.equals(cdStatus.getComponentName())) {
                        logger.debug("Found componentName {} in the WatchDog Component DB", name);
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    logger.debug("{} has not be updated in the the WatchDog Component DB yet, so ending the loop", name);
                    allComponentsComplete = false;
                    break;
                }
            }
            if (allComponentsComplete) {
                logger.debug("Components Size matched with the WatchdogComponentDistributionStatus results.");
                for (WatchdogComponentDistributionStatus componentDist : results) {
                    String componentDistributionStatus = componentDist.getComponentDistributionStatus();
                    logger.debug("Component status: {} on componentName: ", componentDistributionStatus, componentDist.getComponentName());
                    if (componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_ERROR")) {
                        status = DistributionStatus.FAILURE.name();
                        break;
                    } else if (componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_OK")) {
                        status = DistributionStatus.SUCCESS.name();
                    } else {
                        throw new Exception("Invalid Component distribution status: " + componentDistributionStatus);
                    }
                }
                logger.debug("Updating overall DistributionStatus to: {} for distributionId: ", status, distributionId);
                watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
            } else {
                logger.debug("Components Size Didn't match with the WatchdogComponentDistributionStatus results.");
                status = DistributionStatus.INCOMPLETE.name();
                return status;
            }
        }
    } catch (Exception e) {
        logger.debug("Exception occurred on getOverallDistributionStatus : {}", e.getMessage());
        logger.error("Exception occurred", e);
        throw new Exception(e);
    }
    logger.debug("Exiting getOverallDistributionStatus method in WatchdogDistribution");
    return status;
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus)

Example 3 with WatchdogDistributionStatus

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

the class ASDCStatusCallBack method activateCallback.

@Override
public void activateCallback(IStatusData iStatus) {
    String event = "Receive a callback componentStatus in ASDC, for componentName: " + iStatus.getComponentName() + " and status of " + iStatus.getStatus() + " distributionID of " + iStatus.getDistributionID();
    try {
        if (iStatus.getStatus() == null) {
            logger.info("Missing status on Status Object. ");
            return;
        }
        if (!iStatus.getStatus().equals(DistributionStatusEnum.COMPONENT_DONE_OK) && !iStatus.getStatus().equals(DistributionStatusEnum.COMPONENT_DONE_ERROR)) {
            logger.info("Status is not 'Component Done OK' or 'Component Done Error'");
            return;
        }
        WatchdogDistributionStatus watchdogDistributionStatus = watchdogDistributionStatusRepository.findById(iStatus.getDistributionID()).orElseGet(() -> null);
        if (watchdogDistributionStatus == null) {
            watchdogDistributionStatus = new WatchdogDistributionStatus();
            watchdogDistributionStatus.setDistributionId(iStatus.getDistributionID());
            watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
        }
        logger.debug(event);
        toscaInstaller.installTheComponentStatus(iStatus);
    } catch (ArtifactInstallerException e) {
        logger.error("Error in ASDCStatusCallback {}", e.getMessage(), e);
        logger.debug("Error in ASDCStatusCallback {}", e.getMessage());
    }
}
Also used : WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException)

Example 4 with WatchdogDistributionStatus

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

the class ToscaResourceInstaller method processWatchdog.

public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification, String consumerId) {
    WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID, distributionNotification, consumerId);
    watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
    try {
        WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
        watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
    } catch (ObjectOptimisticLockingFailureException e) {
        logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : {} ", e);
        throw e;
    }
}
Also used : WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) WatchdogServiceModVerIdLookup(org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException)

Aggregations

WatchdogDistributionStatus (org.onap.so.db.request.beans.WatchdogDistributionStatus)4 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)2 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)1 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)1 ASDCDownloadException (org.onap.so.asdc.client.exceptions.ASDCDownloadException)1 ASDCParametersException (org.onap.so.asdc.client.exceptions.ASDCParametersException)1 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)1 WatchdogServiceModVerIdLookup (org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup)1