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;
}
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));
}
Aggregations