Search in sources :

Example 1 with DeviceConfigurationException

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;
    }
}
Also used : IotShadowClient(software.amazon.awssdk.iot.iotshadow.IotShadowClient) DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)

Example 2 with DeviceConfigurationException

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;
}
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 3 with DeviceConfigurationException

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));
}
Also used : IotCloudHelper(com.aws.greengrass.iot.IotCloudHelper) DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException) Test(org.junit.jupiter.api.Test)

Example 4 with DeviceConfigurationException

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();
}
Also used : ChildChanged(com.aws.greengrass.config.ChildChanged) Node(com.aws.greengrass.config.Node) DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException) Test(org.junit.jupiter.api.Test)

Example 5 with DeviceConfigurationException

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();
}
Also used : DeviceConfigurationException(com.aws.greengrass.deployment.exceptions.DeviceConfigurationException) Test(org.junit.jupiter.api.Test)

Aggregations

DeviceConfigurationException (com.aws.greengrass.deployment.exceptions.DeviceConfigurationException)9 Test (org.junit.jupiter.api.Test)5 ChildChanged (com.aws.greengrass.config.ChildChanged)2 Node (com.aws.greengrass.config.Node)2 DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)1 DeploymentQueue (com.aws.greengrass.deployment.DeploymentQueue)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)1 AWSIotException (com.aws.greengrass.deployment.exceptions.AWSIotException)1 ComponentConfigurationValidationException (com.aws.greengrass.deployment.exceptions.ComponentConfigurationValidationException)1 ServiceUpdateException (com.aws.greengrass.deployment.exceptions.ServiceUpdateException)1 Deployment (com.aws.greengrass.deployment.model.Deployment)1 IotCloudHelper (com.aws.greengrass.iot.IotCloudHelper)1 IotCloudResponse (com.aws.greengrass.iot.model.IotCloudResponse)1 BaseRetryableAccessor (com.aws.greengrass.util.BaseRetryableAccessor)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Map (java.util.Map)1