Search in sources :

Example 1 with REQUEST_RESTART

use of com.aws.greengrass.deployment.bootstrap.BootstrapSuccessCode.REQUEST_RESTART in project aws-greengrass-nucleus by aws-greengrass.

the class KernelUpdateDeploymentTask method call.

@SuppressWarnings({ "PMD.AvoidDuplicateLiterals" })
@Override
public DeploymentResult call() {
    Deployment.DeploymentStage stage = deployment.getDeploymentStage();
    try {
        List<GreengrassService> servicesToTrack = kernel.orderedDependencies().stream().filter(GreengrassService::shouldAutoStart).filter(o -> !kernel.getMain().equals(o)).collect(Collectors.toList());
        long mergeTimestamp = kernel.getConfig().lookup("system", "rootpath").getModtime();
        logger.atDebug().kv("serviceToTrack", servicesToTrack).kv("mergeTime", mergeTimestamp).log("Nucleus update workflow waiting for services to complete update");
        DeploymentConfigMerger.waitForServicesToStart(servicesToTrack, mergeTimestamp);
        DeploymentResult result = null;
        if (KERNEL_ACTIVATION.equals(stage)) {
            result = new DeploymentResult(DeploymentResult.DeploymentStatus.SUCCESSFUL, null);
        } else if (KERNEL_ROLLBACK.equals(stage)) {
            result = new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_ROLLBACK_COMPLETE, getDeploymentStatusDetails());
        }
        componentManager.cleanupStaleVersions();
        return result;
    } catch (InterruptedException e) {
        logger.atError("deployment-interrupted", e).log();
        try {
            saveDeploymentStatusDetails(e.getMessage());
        } catch (IOException ioException) {
            logger.atError().log("Failed to persist deployment error information", ioException);
        }
        // Interrupted workflow. Shutdown kernel and retry this stage.
        kernel.shutdown(30, REQUEST_RESTART);
        return null;
    } catch (ServiceUpdateException e) {
        logger.atError("deployment-errored", e).log();
        if (KERNEL_ACTIVATION.equals(stage)) {
            try {
                deployment.setDeploymentStage(KERNEL_ROLLBACK);
                saveDeploymentStatusDetails(e.getMessage());
                // Rollback workflow. Flip symlinks and restart kernel
                kernel.getContext().get(KernelAlternatives.class).prepareRollback();
                kernel.shutdown(30, REQUEST_RESTART);
            } catch (IOException ioException) {
                logger.atError().log("Failed to set up Nucleus rollback directory", ioException);
                return new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_UNABLE_TO_ROLLBACK, e);
            }
            return null;
        } else if (KERNEL_ROLLBACK.equals(stage)) {
            logger.atError().log("Nucleus update workflow failed on rollback", e);
            return new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_UNABLE_TO_ROLLBACK, getDeploymentStatusDetails());
        }
        return null;
    }
}
Also used : KERNEL_ROLLBACK(com.aws.greengrass.deployment.model.Deployment.DeploymentStage.KERNEL_ROLLBACK) Deployment(com.aws.greengrass.deployment.model.Deployment) IOException(java.io.IOException) DeploymentTask(com.aws.greengrass.deployment.model.DeploymentTask) Collectors(java.util.stream.Collectors) ComponentManager(com.aws.greengrass.componentmanager.ComponentManager) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) List(java.util.List) Utils(com.aws.greengrass.util.Utils) DEPLOYMENT_ID_LOG_KEY(com.aws.greengrass.deployment.DeploymentConfigMerger.DEPLOYMENT_ID_LOG_KEY) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) KernelAlternatives(com.aws.greengrass.lifecyclemanager.KernelAlternatives) REQUEST_RESTART(com.aws.greengrass.deployment.bootstrap.BootstrapSuccessCode.REQUEST_RESTART) KERNEL_ACTIVATION(com.aws.greengrass.deployment.model.Deployment.DeploymentStage.KERNEL_ACTIVATION) Logger(com.aws.greengrass.logging.api.Logger) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) Deployment(com.aws.greengrass.deployment.model.Deployment) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) IOException(java.io.IOException) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException)

Aggregations

ComponentManager (com.aws.greengrass.componentmanager.ComponentManager)1 DEPLOYMENT_ID_LOG_KEY (com.aws.greengrass.deployment.DeploymentConfigMerger.DEPLOYMENT_ID_LOG_KEY)1 REQUEST_RESTART (com.aws.greengrass.deployment.bootstrap.BootstrapSuccessCode.REQUEST_RESTART)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 Deployment (com.aws.greengrass.deployment.model.Deployment)1 KERNEL_ACTIVATION (com.aws.greengrass.deployment.model.Deployment.DeploymentStage.KERNEL_ACTIVATION)1 KERNEL_ROLLBACK (com.aws.greengrass.deployment.model.Deployment.DeploymentStage.KERNEL_ROLLBACK)1 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)1 DeploymentTask (com.aws.greengrass.deployment.model.DeploymentTask)1 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)1 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)1 KernelAlternatives (com.aws.greengrass.lifecyclemanager.KernelAlternatives)1 Logger (com.aws.greengrass.logging.api.Logger)1 Utils (com.aws.greengrass.util.Utils)1 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1