Search in sources :

Example 1 with ProvisionConfiguration

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;
}
Also used : ProvisionConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration)

Example 2 with 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;
}
Also used : ProvisionConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration)

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

Example 4 with ProvisionConfiguration

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;
}
Also used : ProvisionConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration) NucleusConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration) SystemConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration)

Example 5 with 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());
}
Also used : EZPlugins(com.aws.greengrass.dependency.EZPlugins) DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) ProvisionConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration) NucleusConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration) ImplementingClassMatchProcessor(io.github.lukehutch.fastclasspathscanner.matchprocessor.ImplementingClassMatchProcessor) SystemConfiguration(com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

ProvisionConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration)5 NucleusConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration)2 SystemConfiguration (com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration)2 Topics (com.aws.greengrass.config.Topics)1 EZPlugins (com.aws.greengrass.dependency.EZPlugins)1 InputValidationException (com.aws.greengrass.lifecyclemanager.exceptions.InputValidationException)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1 DeviceIdentityInterface (com.aws.greengrass.provisioning.DeviceIdentityInterface)1 ProvisionContext (com.aws.greengrass.provisioning.ProvisionContext)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 ImplementingClassMatchProcessor (io.github.lukehutch.fastclasspathscanner.matchprocessor.ImplementingClassMatchProcessor)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 Test (org.junit.jupiter.api.Test)1