use of com.aws.greengrass.deployment.exceptions.DeviceConfigurationException in project aws-greengrass-nucleus by aws-greengrass.
the class ShadowDeploymentListener method postInject.
@Override
public void postInject() {
if (iotShadowClient == null) {
this.iotShadowClient = new IotShadowClient(getMqttClientConnection());
}
mqttClient.addToCallbackEvents(callbacks);
deviceConfiguration.onAnyChange((what, node) -> {
if (WhatHappened.childChanged.equals(what) && node != null && deviceConfiguration.provisionInfoNodeChanged(node, isSubscribedToShadowTopics.get())) {
try {
connectToShadowService(deviceConfiguration);
} catch (DeviceConfigurationException e) {
logger.atWarn().kv("errorMessage", e.getMessage()).log(DEVICE_OFFLINE_MESSAGE);
return;
}
}
});
try {
connectToShadowService(deviceConfiguration);
} catch (DeviceConfigurationException e) {
logger.atWarn().log(DEVICE_OFFLINE_MESSAGE);
return;
}
}
use of com.aws.greengrass.deployment.exceptions.DeviceConfigurationException 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.DeviceConfigurationException in project aws-greengrass-nucleus by aws-greengrass.
the class IotCloudHelperTest method GIVEN_error_code_once_WHEN_client_and_endpoint_null_THEN_unsuccessful.
@Test
void GIVEN_error_code_once_WHEN_client_and_endpoint_null_THEN_unsuccessful() throws Exception {
when(mockConnectionManager.getURI()).thenThrow(new DeviceConfigurationException("Credentials endpoint not " + "configured"));
IotCloudHelper cloudHelper = new IotCloudHelper();
assertThrows(AWSIotException.class, () -> cloudHelper.sendHttpRequest(mockConnectionManager, null, IOT_CREDENTIALS_PATH, CredentialRequestHandler.IOT_CREDENTIALS_HTTP_VERB, null));
}
use of com.aws.greengrass.deployment.exceptions.DeviceConfigurationException in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method GIVEN_device_configured_WHEN_connecting_to_iot_cloud_THEN_connection_retry_on_provisioning.
@Test
void GIVEN_device_configured_WHEN_connecting_to_iot_cloud_THEN_connection_retry_on_provisioning() throws Exception {
doThrow(new DeviceConfigurationException("Error")).doNothing().when(deviceConfiguration).validate();
iotJobsHelper.postInject();
ArgumentCaptor<ChildChanged> ccCaptor = ArgumentCaptor.forClass(ChildChanged.class);
verify(deviceConfiguration).onAnyChange(ccCaptor.capture());
Node mockNode = mock(Node.class);
lenient().doReturn(true).when(mockNode).childOf(eq(DEVICE_PARAM_IOT_DATA_ENDPOINT));
ccCaptor.getValue().childChanged(WhatHappened.childChanged, mockNode);
verify(mockMqttClient, times(1)).addToCallbackEvents(any());
verify(mockIotJobsClientWrapper, times(1)).SubscribeToJobExecutionsChangedEvents(any(), any(), any());
verify(mockIotJobsClientWrapper, times(1)).SubscribeToDescribeJobExecutionAccepted(any(), any(), any());
verify(mockIotJobsClientWrapper, times(1)).SubscribeToDescribeJobExecutionRejected(any(), any(), any());
verify(mockFleetStatusService, times(1)).updateFleetStatusUpdateForAllComponents();
}
use of com.aws.greengrass.deployment.exceptions.DeviceConfigurationException in project aws-greengrass-nucleus by aws-greengrass.
the class IotJobsHelperTest method GIVEN_device_not_configured_WHEN_connecting_to_iot_cloud_THEN_connection_unsuccessful.
@Test
void GIVEN_device_not_configured_WHEN_connecting_to_iot_cloud_THEN_connection_unsuccessful() throws Exception {
doThrow(new DeviceConfigurationException("Error")).when(deviceConfiguration).validate();
iotJobsHelper.postInject();
verify(mockMqttClient, times(1)).addToCallbackEvents(any());
verify(mockIotJobsClientWrapper, times(0)).SubscribeToJobExecutionsChangedEvents(any(), any(), any());
verify(mockIotJobsClientWrapper, times(0)).SubscribeToDescribeJobExecutionAccepted(any(), any(), any());
verify(mockIotJobsClientWrapper, times(0)).SubscribeToDescribeJobExecutionRejected(any(), any(), any());
verify(mockFleetStatusService, times(0)).updateFleetStatusUpdateForAllComponents();
}
Aggregations