Search in sources :

Example 1 with DeploymentActivator

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;
}
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 DeploymentActivator

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());
}
Also used : UpdateSystemPolicyService(com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService) DeploymentActivatorFactory(com.aws.greengrass.deployment.activator.DeploymentActivatorFactory) ComponentUpdatePolicy(com.aws.greengrass.deployment.model.ComponentUpdatePolicy) DeploymentDocument(com.aws.greengrass.deployment.model.DeploymentDocument) DeploymentActivator(com.aws.greengrass.deployment.activator.DeploymentActivator) Test(org.junit.jupiter.api.Test)

Aggregations

DeploymentActivator (com.aws.greengrass.deployment.activator.DeploymentActivator)2 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)2 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)2 DeploymentActivatorFactory (com.aws.greengrass.deployment.activator.DeploymentActivatorFactory)1 KernelUpdateActivator (com.aws.greengrass.deployment.activator.KernelUpdateActivator)1 ComponentConfigurationValidationException (com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 ComponentUpdatePolicy (com.aws.greengrass.deployment.model.ComponentUpdatePolicy)1 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)1 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.jupiter.api.Test)1