use of com.aws.greengrass.provisioning.ProvisionConfiguration in project aws-greengrass-nucleus by aws-greengrass.
the class AdditionalDeviceProvisioningPluginForJar method updateIdentityConfiguration.
@Override
public ProvisionConfiguration updateIdentityConfiguration(ProvisionContext provisionContext) throws RetryableProvisioningException, InterruptedException {
Map<String, Object> parameterMap = provisionContext.getParameterMap();
ProvisionConfiguration.SystemConfiguration systemConfiguration = new ProvisionConfiguration.SystemConfiguration();
systemConfiguration.setCertificateFilePath(parameterMap.get("certificateFilePath") == null ? "" : parameterMap.get("certificateFilePath").toString());
systemConfiguration.setPrivateKeyPath(parameterMap.get("privateKeyPath") == null ? "" : parameterMap.get("privateKeyPath").toString());
systemConfiguration.setRootCAPath(parameterMap.get("rootCAPath") == null ? "" : parameterMap.get("rootCAPath").toString());
systemConfiguration.setThingName(parameterMap.get("thingName") == null ? "" : parameterMap.get("thingName").toString());
ProvisionConfiguration.NucleusConfiguration nucleusConfiguration = new ProvisionConfiguration.NucleusConfiguration();
nucleusConfiguration.setAwsRegion(parameterMap.get("awsRegion") == null ? "" : parameterMap.get("awsRegion").toString());
nucleusConfiguration.setIotCredentialsEndpoint(parameterMap.get("iotCredentialsEndpoint") == null ? "" : parameterMap.get("iotCredentialsEndpoint").toString());
nucleusConfiguration.setIotDataEndpoint(parameterMap.get("iotDataEndpoint") == null ? "" : parameterMap.get("iotDataEndpoint").toString());
nucleusConfiguration.setIotRoleAlias(parameterMap.get("iotRoleAlias") == null ? "" : parameterMap.get("iotRoleAlias").toString());
ProvisionConfiguration provisionConfiguration = new ProvisionConfiguration();
provisionConfiguration.setSystemConfiguration(systemConfiguration);
provisionConfiguration.setNucleusConfiguration(nucleusConfiguration);
try {
if (parameterMap.get("waitTime") != null) {
Thread.sleep(Long.valueOf(parameterMap.get("waitTime").toString()));
}
} catch (InterruptedException e) {
throw e;
}
return provisionConfiguration;
}
use of com.aws.greengrass.provisioning.ProvisionConfiguration in project aws-greengrass-nucleus by aws-greengrass.
the class TestDeviceProvisioningPluginForJar method updateIdentityConfiguration.
@Override
public ProvisionConfiguration updateIdentityConfiguration(ProvisionContext provisionContext) throws RetryableProvisioningException, InterruptedException {
Map<String, Object> parameterMap = provisionContext.getParameterMap();
ProvisionConfiguration.SystemConfiguration systemConfiguration = new ProvisionConfiguration.SystemConfiguration();
systemConfiguration.setCertificateFilePath(parameterMap.get("certificateFilePath") == null ? "" : parameterMap.get("certificateFilePath").toString());
systemConfiguration.setPrivateKeyPath(parameterMap.get("privateKeyPath") == null ? "" : parameterMap.get("privateKeyPath").toString());
systemConfiguration.setRootCAPath(parameterMap.get("rootCAPath") == null ? "" : parameterMap.get("rootCAPath").toString());
systemConfiguration.setThingName(parameterMap.get("thingName") == null ? "" : parameterMap.get("thingName").toString());
ProvisionConfiguration.NucleusConfiguration nucleusConfiguration = new ProvisionConfiguration.NucleusConfiguration();
nucleusConfiguration.setAwsRegion(parameterMap.get("awsRegion") == null ? "" : parameterMap.get("awsRegion").toString());
nucleusConfiguration.setIotCredentialsEndpoint(parameterMap.get("iotCredentialsEndpoint") == null ? "" : parameterMap.get("iotCredentialsEndpoint").toString());
nucleusConfiguration.setIotDataEndpoint(parameterMap.get("iotDataEndpoint") == null ? "" : parameterMap.get("iotDataEndpoint").toString());
nucleusConfiguration.setIotRoleAlias(parameterMap.get("iotRoleAlias") == null ? "" : parameterMap.get("iotRoleAlias").toString());
ProvisionConfiguration provisionConfiguration = new ProvisionConfiguration();
provisionConfiguration.setSystemConfiguration(systemConfiguration);
provisionConfiguration.setNucleusConfiguration(nucleusConfiguration);
try {
if (parameterMap.get("waitTime") != null) {
Thread.sleep(Long.valueOf(parameterMap.get("waitTime").toString()));
}
} catch (InterruptedException e) {
throw e;
}
return provisionConfiguration;
}
use of com.aws.greengrass.provisioning.ProvisionConfiguration 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);
});
}
use of com.aws.greengrass.provisioning.ProvisionConfiguration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelLifecycleTest method createMockProvisioningConforguration.
private ProvisionConfiguration createMockProvisioningConforguration() {
ProvisionConfiguration provisionConfiguration = new ProvisionConfiguration();
NucleusConfiguration nucleusConfiguration = new NucleusConfiguration();
nucleusConfiguration.setIotRoleAlias(MOCK_IOT_ROLE_ALIAS);
nucleusConfiguration.setAwsRegion(MOCK_AWS_REGION);
nucleusConfiguration.setIotDataEndpoint(MOCK_IOT_DATA_ENDPOINT);
nucleusConfiguration.setIotCredentialsEndpoint(MOCK_IOT_CREDENTIAL_ENDPOINT);
provisionConfiguration.setNucleusConfiguration(nucleusConfiguration);
SystemConfiguration systemConfiguration = new SystemConfiguration();
systemConfiguration.setThingName(MOCK_THING_NAME);
systemConfiguration.setRootCAPath(MOCK_ROOT_CA_PATH);
systemConfiguration.setPrivateKeyPath(MOCK_PRIVATE_KEY_PATH);
systemConfiguration.setCertificateFilePath(MOCK_CERTIFICATE_KEY_PATH);
provisionConfiguration.setSystemConfiguration(systemConfiguration);
return provisionConfiguration;
}
use of com.aws.greengrass.provisioning.ProvisionConfiguration in project aws-greengrass-nucleus by aws-greengrass.
the class KernelLifecycleTest method GIVEN_kernel_WHEN_launch_with_provisioning_plugin_THEN_configuration_is_updated.
@SuppressWarnings("PMD.CloseResource")
@Test
void GIVEN_kernel_WHEN_launch_with_provisioning_plugin_THEN_configuration_is_updated() throws Exception {
mockProvisioning();
ProvisionConfiguration mockProvisionConfiguration = createMockProvisioningConforguration();
when(mockProvisioningPlugin.updateIdentityConfiguration(any())).thenReturn(mockProvisionConfiguration);
EZPlugins pluginMock = mock(EZPlugins.class);
when(mockContext.get(EZPlugins.class)).thenReturn(pluginMock);
doAnswer((i) -> {
ImplementingClassMatchProcessor func = i.getArgument(1);
func.processMatch(mockPluginClass);
return null;
}).when(pluginMock).implementing(eq(DeviceIdentityInterface.class), any());
kernelLifecycle.launch();
ArgumentCaptor<NucleusConfiguration> nucleusConfigCaptor = ArgumentCaptor.forClass(NucleusConfiguration.class);
verify(mockProvisioningConfigUpdateHelper, timeout(500).times(1)).updateNucleusConfiguration(nucleusConfigCaptor.capture(), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
ArgumentCaptor<SystemConfiguration> systemConfigCaptor = ArgumentCaptor.forClass(SystemConfiguration.class);
verify(mockProvisioningConfigUpdateHelper, timeout(500).times(1)).updateSystemConfiguration(systemConfigCaptor.capture(), eq(UpdateBehaviorTree.UpdateBehavior.MERGE));
assertEquals(mockProvisionConfiguration.getNucleusConfiguration(), nucleusConfigCaptor.getValue());
assertEquals(mockProvisionConfiguration.getSystemConfiguration(), systemConfigCaptor.getValue());
}
Aggregations