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