Search in sources :

Example 1 with ComponentConfigurationValidationException

use of com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException in project aws-greengrass-nucleus by aws-greengrass.

the class BootstrapManager method defaultRunWithChanged.

private boolean defaultRunWithChanged(Map<String, Object> newNucleusParameters, DeviceConfiguration currentDeviceConfiguration) throws ComponentConfigurationValidationException {
    Map<String, Object> runWithDefault = (Map<String, Object>) newNucleusParameters.getOrDefault(RUN_WITH_TOPIC, Collections.emptyMap());
    Map<String, Object> currentValues = currentDeviceConfiguration.getRunWithTopic().toPOJO();
    boolean changed = false;
    if (Utils.stringHasChanged(Coerce.toString(currentValues.get(RUN_WITH_DEFAULT_POSIX_USER)), Coerce.toString(runWithDefault.get(RUN_WITH_DEFAULT_POSIX_USER)))) {
        logger.atInfo().kv(RUN_WITH_TOPIC + "." + RUN_WITH_DEFAULT_POSIX_USER, runWithDefault.get(RUN_WITH_DEFAULT_POSIX_USER)).log(RESTART_REQUIRED_MESSAGE);
        changed = true;
    }
    if (Utils.stringHasChanged(Coerce.toString(currentValues.getOrDefault(RUN_WITH_DEFAULT_POSIX_SHELL, RUN_WITH_DEFAULT_POSIX_SHELL_VALUE)), Coerce.toString(runWithDefault.getOrDefault(RUN_WITH_DEFAULT_POSIX_SHELL, RUN_WITH_DEFAULT_POSIX_SHELL_VALUE)))) {
        logger.atInfo().kv(RUN_WITH_TOPIC + "." + RUN_WITH_DEFAULT_POSIX_SHELL, runWithDefault.get(RUN_WITH_DEFAULT_POSIX_SHELL)).log(RESTART_REQUIRED_MESSAGE);
        changed = true;
    }
    if (changed) {
        try {
            platform.getRunWithGenerator().validateDefaultConfiguration(runWithDefault);
        } catch (DeviceConfigurationException e) {
            throw new ComponentConfigurationValidationException(e);
        }
        try {
            logger.atInfo().kv("changed", RUN_WITH_TOPIC).kv("old", SerializerFactory.getFailSafeJsonObjectMapper().writeValueAsString(currentValues)).kv("new", SerializerFactory.getFailSafeJsonObjectMapper().writeValueAsString(runWithDefault)).log(RESTART_REQUIRED_MESSAGE);
        } catch (JsonProcessingException e) {
            throw new ComponentConfigurationValidationException(e);
        }
        return true;
    }
    return false;
}
Also used : DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException) Map(java.util.Map) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with ComponentConfigurationValidationException

use of com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException 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 3 with ComponentConfigurationValidationException

use of com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException in project aws-greengrass-nucleus by aws-greengrass.

the class DynamicComponentConfigurationValidatorTest method GIVEN_config_validation_needed_WHEN_error_requesting_validation_THEN_fail_deployment.

@Test
void GIVEN_config_validation_needed_WHEN_error_requesting_validation_THEN_fail_deployment() throws Exception {
    when(configStoreIPCEventStreamAgent.validateConfiguration(any(), any(), any(), any())).thenThrow(ValidateEventRegistrationException.class);
    createMockGenericExternalService("OldService");
    HashMap<String, Object> servicesConfig = new HashMap<String, Object>() {

        {
            put("OldService", new HashMap<String, Object>() {

                {
                    put(CONFIGURATION_CONFIG_KEY, new HashMap<String, Object>() {

                        {
                            put("ConfigKey1", "ConfigValue2");
                        }
                    });
                    put(VERSION_CONFIG_KEY, DEFAULT_EXISTING_SERVICE_VERSION);
                }
            });
        }
    };
    assertFalse(validator.validate(servicesConfig, createTestDeployment(), deploymentResultFuture));
    verify(configStoreIPCEventStreamAgent, times(1)).validateConfiguration(any(), any(), any(), any());
    DeploymentResult deploymentResult = deploymentResultFuture.get();
    assertEquals(DeploymentResult.DeploymentStatus.FAILED_NO_STATE_CHANGE, deploymentResult.getDeploymentStatus());
    assertTrue(deploymentResult.getFailureCause() instanceof ComponentConfigurationValidationException);
    assertTrue(deploymentResult.getFailureCause().getMessage() != null && deploymentResult.getFailureCause().getMessage().contains("Error requesting validation from component OldService"));
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) Test(org.junit.jupiter.api.Test)

Example 4 with ComponentConfigurationValidationException

use of com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException in project aws-greengrass-nucleus by aws-greengrass.

the class DynamicComponentConfigurationValidatorTest method GIVEN_validation_requested_WHEN_validation_request_times_out_THEN_fail_deployment.

@Test
void GIVEN_validation_requested_WHEN_validation_request_times_out_THEN_fail_deployment(ExtensionContext context) throws Exception {
    ignoreExceptionUltimateCauseOfType(context, TimeoutException.class);
    when(configStoreIPCEventStreamAgent.validateConfiguration(any(), any(), any(), any())).thenReturn(true);
    createMockGenericExternalService("OldService");
    HashMap<String, Object> servicesConfig = new HashMap<String, Object>() {

        {
            put("OldService", new HashMap<String, Object>() {

                {
                    put(CONFIGURATION_CONFIG_KEY, new HashMap<String, Object>() {

                        {
                            put("ConfigKey1", "ConfigValue2");
                        }
                    });
                    put(VERSION_CONFIG_KEY, DEFAULT_EXISTING_SERVICE_VERSION);
                }
            });
        }
    };
    assertFalse(validator.validate(servicesConfig, createTestDeployment(), deploymentResultFuture));
    verify(configStoreIPCEventStreamAgent, times(1)).validateConfiguration(any(), any(), any(), any());
    DeploymentResult deploymentResult = deploymentResultFuture.get();
    assertEquals(DeploymentResult.DeploymentStatus.FAILED_NO_STATE_CHANGE, deploymentResult.getDeploymentStatus());
    assertTrue(deploymentResult.getFailureCause() instanceof ComponentConfigurationValidationException);
    assertTrue(deploymentResult.getFailureCause().getMessage() != null && deploymentResult.getFailureCause().getMessage().contains("Error while waiting for validation report for one or more components"));
}
Also used : HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) DeploymentResult(com.aws.greengrass.deployment.model.DeploymentResult) ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) Test(org.junit.jupiter.api.Test)

Example 5 with ComponentConfigurationValidationException

use of com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException in project aws-greengrass-nucleus by aws-greengrass.

the class DeviceConfigurationTest method GIVEN_bad_data_endpoint_config_WHEN_validate_THEN_fails.

@Test
void GIVEN_bad_data_endpoint_config_WHEN_validate_THEN_fails() {
    deviceConfiguration = new DeviceConfiguration(mockKernel);
    ComponentConfigurationValidationException ex = assertThrows(ComponentConfigurationValidationException.class, () -> deviceConfiguration.validateEndpoints("us-east-1", "xxxxxx.credentials.iot.us-east-1.amazonaws.com", "xxxxxx-ats.iot.us-east-2.amazonaws.com"));
    assertEquals("IoT data endpoint region xxxxxx-ats.iot.us-east-2.amazonaws.com does not match the AWS region us-east-1 of the device", ex.getMessage());
}
Also used : ComponentConfigurationValidationException(com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentConfigurationValidationException (com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException)11 DeploymentResult (com.aws.greengrass.deployment.model.DeploymentResult)8 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ConfigurationValidityReport (software.amazon.awssdk.aws.greengrass.model.ConfigurationValidityReport)4 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 ValidateEventRegistrationException (com.aws.greengrass.builtin.services.configstore.exceptions.ValidateEventRegistrationException)1 Topics (com.aws.greengrass.config.Topics)1 DeploymentActivator (com.aws.greengrass.deployment.activator.DeploymentActivator)1 KernelUpdateActivator (com.aws.greengrass.deployment.activator.KernelUpdateActivator)1 DeviceConfigurationException (com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)1 InvalidConfigFormatException (com.aws.greengrass.deployment.exceptions.InvalidConfigFormatException)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 DeploymentDocument (com.aws.greengrass.deployment.model.DeploymentDocument)1 UpdateAction (com.aws.greengrass.lifecyclemanager.UpdateAction)1 UpdateSystemPolicyService (com.aws.greengrass.lifecyclemanager.UpdateSystemPolicyService)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1