Search in sources :

Example 1 with ProvisionContext

use of com.aws.greengrass.provisioning.ProvisionContext in project aws-greengrass-nucleus by aws-greengrass.

the class KernelLifecycleTest method createMockProvisioningPlugin.

@BeforeAll
public static void createMockProvisioningPlugin() {
    DeviceIdentityInterface mockDeviceIdentityInterfaceImpl = new DeviceIdentityInterface() {

        @Override
        public ProvisionConfiguration updateIdentityConfiguration(ProvisionContext provisionContext) throws RetryableProvisioningException {
            return null;
        }

        @Override
        public String name() {
            return null;
        }
    };
    mockPluginClass = mockDeviceIdentityInterfaceImpl.getClass();
}
Also used : DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) ProvisionContext(com.aws.greengrass.provisioning.ProvisionContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with ProvisionContext

use of com.aws.greengrass.provisioning.ProvisionContext in project aws-greengrass-nucleus by aws-greengrass.

the class KernelLifecycle method executeProvisioningPlugin.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void executeProvisioningPlugin(DeviceIdentityInterface provisioningPlugin) {
    logger.atDebug().kv("plugin", provisioningPlugin.name()).log("Found provisioning plugin to run");
    RetryUtils.RetryConfig retryConfig = RetryUtils.RetryConfig.builder().maxAttempt(MAX_PROVISIONING_PLUGIN_RETRY_ATTEMPTS).retryableExceptions(Collections.singletonList(RetryableProvisioningException.class)).build();
    ExecutorService executorService = kernel.getContext().get(ExecutorService.class);
    executorService.execute(() -> {
        String pluginName = provisioningPlugin.name();
        logger.atInfo().log("Running provisioning plugin: " + pluginName);
        Topics pluginConfig = kernel.getConfig().findTopics(SERVICES_NAMESPACE_TOPIC, pluginName, CONFIGURATION_CONFIG_KEY);
        ProvisionConfiguration provisionConfiguration = null;
        try {
            provisionConfiguration = RetryUtils.runWithRetry(retryConfig, () -> provisioningPlugin.updateIdentityConfiguration(new ProvisionContext(DEFAULT_PROVISIONING_POLICY, pluginConfig == null ? Collections.emptyMap() : pluginConfig.toPOJO())), "Running provisioning plugin", logger);
        } catch (Exception e) {
            logger.atError().setCause(e).log("Caught exception while running provisioning plugin. " + "Moving on to run Greengrass without provisioning");
            return;
        }
        provisioningConfigUpdateHelper.updateSystemConfiguration(provisionConfiguration.getSystemConfiguration(), UpdateBehaviorTree.UpdateBehavior.MERGE);
        provisioningConfigUpdateHelper.updateNucleusConfiguration(provisionConfiguration.getNucleusConfiguration(), UpdateBehaviorTree.UpdateBehavior.MERGE);
        logger.atDebug().kv("PluginName", pluginName).log(UPDATED_PROVISIONING_MESSAGE);
    });
}
Also used : Topics(com.aws.greengrass.config.Topics) ProvisionContext(com.aws.greengrass.provisioning.ProvisionContext) ProvisionConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) RetryUtils(com.aws.greengrass.util.RetryUtils) Utils.deepToString(com.aws.greengrass.util.Utils.deepToString) TimeoutException(java.util.concurrent.TimeoutException) InputValidationException(com.aws.greengrass.lifecyclemanager.exceptions.InputValidationException) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RetryableProvisioningException(com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException)

Aggregations

ProvisionContext (com.aws.greengrass.provisioning.ProvisionContext)2 Topics (com.aws.greengrass.config.Topics)1 InputValidationException (com.aws.greengrass.lifecyclemanager.exceptions.InputValidationException)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1 DeviceIdentityInterface (com.aws.greengrass.provisioning.DeviceIdentityInterface)1 ProvisionConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration)1 RetryableProvisioningException (com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException)1 RetryUtils (com.aws.greengrass.util.RetryUtils)1 Utils.deepToString (com.aws.greengrass.util.Utils.deepToString)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1