use of com.aws.greengrass.deployment.activator.DeploymentActivator 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.DeploymentActivator in project aws-greengrass-nucleus by aws-greengrass.
the class DeploymentConfigMergerTest method GIVEN_deployment_WHEN_check_safety_selected_THEN_check_safety_before_update.
@Test
void GIVEN_deployment_WHEN_check_safety_selected_THEN_check_safety_before_update() throws Exception {
UpdateSystemPolicyService updateSystemPolicyService = mock(UpdateSystemPolicyService.class);
when(context.get(UpdateSystemPolicyService.class)).thenReturn(updateSystemPolicyService);
DeploymentActivatorFactory deploymentActivatorFactory = mock(DeploymentActivatorFactory.class);
DeploymentActivator deploymentActivator = mock(DeploymentActivator.class);
when(deploymentActivatorFactory.getDeploymentActivator(any())).thenReturn(deploymentActivator);
when(context.get(DeploymentActivatorFactory.class)).thenReturn(deploymentActivatorFactory);
DeploymentConfigMerger merger = new DeploymentConfigMerger(kernel, deviceConfiguration, validator);
DeploymentDocument doc = new DeploymentDocument();
doc.setConfigurationArn("NoSafetyCheckDeploy");
doc.setComponentUpdatePolicy(new ComponentUpdatePolicy(0, SKIP_NOTIFY_COMPONENTS));
merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
verify(updateSystemPolicyService, times(0)).addUpdateAction(any(), any());
doc.setConfigurationArn("DeploymentId");
doc.setComponentUpdatePolicy(new ComponentUpdatePolicy(60, NOTIFY_COMPONENTS));
merger.mergeInNewConfig(createMockDeployment(doc), new HashMap<>());
verify(updateSystemPolicyService).addUpdateAction(any(), any());
}
Aggregations