Search in sources :

Example 1 with KernelUpdateActivator

use of com.aws.greengrass.deployment.activator.KernelUpdateActivator in project aws-greengrass-nucleus by aws-greengrass.

the class DeploymentConfigMerger method mergeInNewConfig.

/**
 * Merge in new configuration values and new services.
 *
 * @param deployment deployment object
 * @param newConfig  the map of new configuration
 * @return future which completes only once the config is merged and all the services in the config are running
 */
public Future<DeploymentResult> mergeInNewConfig(Deployment deployment, Map<String, Object> newConfig) {
    CompletableFuture<DeploymentResult> totallyCompleteFuture = new CompletableFuture<>();
    DeploymentActivator activator;
    try {
        activator = kernel.getContext().get(DeploymentActivatorFactory.class).getDeploymentActivator(newConfig);
    } catch (ServiceUpdateException | ComponentConfigurationValidationException e) {
        // Failed to pre-process new config, no rollback needed
        logger.atError().setEventType(MERGE_ERROR_LOG_EVENT_KEY).setCause(e).log("Failed to process new configuration for activation");
        totallyCompleteFuture.complete(new DeploymentResult(DeploymentResult.DeploymentStatus.FAILED_NO_STATE_CHANGE, e));
        return totallyCompleteFuture;
    }
    boolean ggcRestart = false;
    if (activator instanceof KernelUpdateActivator) {
        ggcRestart = true;
    }
    DeploymentDocument deploymentDocument = deployment.getDeploymentDocumentObj();
    if (DeploymentComponentUpdatePolicyAction.NOTIFY_COMPONENTS.equals(deploymentDocument.getComponentUpdatePolicy().getComponentUpdatePolicyAction())) {
        kernel.getContext().get(UpdateSystemPolicyService.class).addUpdateAction(deploymentDocument.getDeploymentId(), new UpdateAction(deploymentDocument.getDeploymentId(), ggcRestart, deploymentDocument.getComponentUpdatePolicy().getTimeout(), () -> updateActionForDeployment(newConfig, deployment, activator, totallyCompleteFuture)));
    } else {
        logger.atInfo().log("Deployment is configured to skip update policy check," + " not waiting for disruptable time to update");
        updateActionForDeployment(newConfig, deployment, activator, totallyCompleteFuture);
    }
    return totallyCompleteFuture;
}
Also used : UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) CompletableFuture(java.util.concurrent.CompletableFuture) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) UpdateAction(com.aws.greengrass.lifecyclemanager.UpdateAction) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) KernelUpdateActivator(com.aws.greengrass.deployment.activator.KernelUpdateActivator) ServiceUpdateException(com.aws.greengrass.deployment.exceptions.ServiceUpdateException) DeploymentActivator(com.aws.greengrass.deployment.activator.DeploymentActivator)

Example 2 with KernelUpdateActivator

use of com.aws.greengrass.deployment.activator.KernelUpdateActivator in project aws-greengrass-nucleus by aws-greengrass.

the class PluginComponentTest method GIVEN_kernel_WHEN_deploy_updated_plugin_THEN_request_kernel_restart.

@Test
void GIVEN_kernel_WHEN_deploy_updated_plugin_THEN_request_kernel_restart(ExtensionContext context) throws Exception {
    ignoreExceptionOfType(context, PackageDownloadException.class);
    ignoreExceptionOfType(context, IOException.class);
    ignoreExceptionOfType(context, SdkClientException.class);
    Kernel kernelSpy = spy(kernel.parseArgs());
    setupPackageStoreAndConfigWithDigest();
    String deploymentId = "deployment1";
    KernelAlternatives kernelAltsSpy = spy(kernelSpy.getContext().get(KernelAlternatives.class));
    kernelSpy.getContext().put(KernelAlternatives.class, kernelAltsSpy);
    // In actual workflow, DeploymentService will setup deployment artifacts directory per deployment before
    // submitting task. Here in test, it's called explicitly because the directory is required by snapshot file.
    kernelSpy.getContext().get(DeploymentDirectoryManager.class).createNewDeploymentDirectory(deploymentId);
    kernelSpy.getContext().put(KernelUpdateActivator.class, new KernelUpdateActivator(kernelSpy, kernelSpy.getContext().get(BootstrapManager.class)));
    // launch Nucleus
    kernelSpy.launch();
    // Ensure that the dependency isn't somehow in our class loader already
    assertThrows(ClassNotFoundException.class, () -> Class.forName("com.aws.greengrass.integrationtests.lifecyclemanager.resource.PluginDependency"));
    // First deployment to add plugin-1.0.0 to kernel
    submitSampleJobDocument(getPluginDeploymentDocument(System.currentTimeMillis(), "1.0.0", deploymentId, FailureHandlingPolicy.DO_NOTHING, componentName), kernelSpy).get(30, TimeUnit.SECONDS);
    GreengrassService eg = kernelSpy.locate(componentName);
    assertEquals("com.aws.greengrass.integrationtests.lifecyclemanager.resource.APluginService", eg.getClass().getName());
    assertEquals(componentId.getVersion().toString(), Coerce.toString(eg.getServiceConfig().findLeafChild(VERSION_CONFIG_KEY)));
    kernelSpy.getContext().get(EZPlugins.class).forName("com.aws.greengrass.integrationtests.lifecyclemanager.resource.PluginDependency");
    // setup again because local files removed by cleanup in the previous deployment
    setupPackageStoreAndConfigWithDigest();
    String deploymentId2 = "deployment2";
    // No need to actually verify directory setup or make directory changes here.
    doReturn(true).when(kernelAltsSpy).isLaunchDirSetup();
    doNothing().when(kernelAltsSpy).prepareBootstrap(eq(deploymentId2));
    doNothing().when(kernelSpy).shutdown(anyInt(), eq(REQUEST_RESTART));
    // Second deployment to add plugin-1.1.0 to kernel which should enter kernel restart workflow
    assertThrows(TimeoutException.class, () -> submitSampleJobDocument(getPluginDeploymentDocument(System.currentTimeMillis(), "1.1.0", deploymentId2, FailureHandlingPolicy.DO_NOTHING, componentName), kernelSpy).get(10, TimeUnit.SECONDS));
    verify(kernelSpy).shutdown(eq(30), eq(REQUEST_RESTART));
}
Also used : EZPlugins(com.aws.greengrass.dependency.EZPlugins) KernelAlternatives(com.aws.greengrass.lifecyclemanager.KernelAlternatives) GreengrassService(com.aws.greengrass.lifecyclemanager.GreengrassService) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) Kernel(com.aws.greengrass.lifecyclemanager.Kernel) KernelUpdateActivator(com.aws.greengrass.deployment.activator.KernelUpdateActivator) Test(org.junit.jupiter.api.Test)

Aggregations

KernelUpdateActivator (com.aws.greengrass.deployment.activator.KernelUpdateActivator)2 EZPlugins (com.aws.greengrass.dependency.EZPlugins)1 DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)1 DeploymentActivator (com.aws.greengrass.deployment.activator.DeploymentActivator)1 ComponentConfigurationValidationException (com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)1 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)1 GreengrassService (com.aws.greengrass.lifecyclemanager.GreengrassService)1 Kernel (com.aws.greengrass.lifecyclemanager.Kernel)1 KernelAlternatives (com.aws.greengrass.lifecyclemanager.KernelAlternatives)1 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)1 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.jupiter.api.Test)1