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