Search in sources :

Example 1 with DeviceIdentityInterface

use of com.aws.greengrass.provisioning.DeviceIdentityInterface 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 DeviceIdentityInterface

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

the class KernelLifecycle method findProvisioningPlugins.

@SuppressWarnings("PMD.CloseResource")
private List<DeviceIdentityInterface> findProvisioningPlugins() {
    List<DeviceIdentityInterface> provisioningPlugins = new ArrayList<>();
    Set<String> provisioningPluginNames = new HashSet<>();
    EZPlugins ezPlugins = kernel.getContext().get(EZPlugins.class);
    try {
        ezPlugins.withCacheDirectory(nucleusPaths.pluginPath());
        ezPlugins.implementing(DeviceIdentityInterface.class, (c) -> {
            try {
                if (!provisioningPluginNames.contains(c.getName())) {
                    provisioningPlugins.add(provisioningPluginFactory.getPluginInstance(c));
                    provisioningPluginNames.add(c.getName());
                }
            } catch (InstantiationException | IllegalAccessException e) {
                logger.atError().kv("Plugin", c.getName()).setCause(e).log("Error instantiating a provisioning plugin");
            }
        });
    } catch (IOException t) {
        logger.atError().log("Error finding provisioning plugins", t);
    }
    return provisioningPlugins;
}
Also used : EZPlugins(com.aws.greengrass.dependency.EZPlugins) DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) ArrayList(java.util.ArrayList) Utils.deepToString(com.aws.greengrass.util.Utils.deepToString) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 3 with DeviceIdentityInterface

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

the class KernelLifecycle method launch.

/**
 * Startup the Kernel and all services.
 */
public void launch() {
    logger.atInfo("system-start").kv("version", kernel.getContext().get(DeviceConfiguration.class).getNucleusVersion()).kv("rootPath", nucleusPaths.rootPath()).kv("configPath", nucleusPaths.configPath()).log("Launch Nucleus");
    // This guarantees that IPC, for example, is running before any user code
    for (Class<? extends Startable> c : startables) {
        kernel.getContext().get(c).startup();
    }
    final List<DeviceIdentityInterface> provisioningPlugins = findProvisioningPlugins();
    // Must be called before everything else so that these are available to be
    // referenced by main/dependencies of main
    // NOPMD
    final Queue<String> autostart = findBuiltInServicesAndPlugins();
    loadPlugins();
    // run the provisioning if device is not provisioned
    if (!kernel.getContext().get(DeviceConfiguration.class).isDeviceConfiguredToTalkToCloud() && !provisioningPlugins.isEmpty()) {
        // There is also no compelling use case right now for multiple provisioning plugins.
        if (provisioningPlugins.size() > 1) {
            String errorString = String.format(MULTIPLE_PROVISIONING_PLUGINS_FOUND_EXCEPTION, provisioningPlugins.toString());
            throw new RuntimeException(errorString);
        }
        executeProvisioningPlugin(provisioningPlugins.get(0));
    }
    mainService = kernel.locateIgnoreError(KernelCommandLine.MAIN_SERVICE_NAME);
    autostart.forEach(s -> {
        try {
            mainService.addOrUpdateDependency(kernel.locate(s), DependencyType.HARD, true);
        } catch (ServiceLoadException se) {
            logger.atError().log("Unable to load service {}", s, se);
        } catch (InputValidationException e) {
            logger.atError().log("Unable to add auto-starting dependency {} to main", s, e);
        }
    });
    kernel.writeEffectiveConfig();
    logger.atInfo().setEventType("system-start").addKeyValue("main", kernel.getMain()).log();
    startupAllServices();
}
Also used : DeviceIdentityInterface(com.aws.greengrass.provisioning.DeviceIdentityInterface) InputValidationException(com.aws.greengrass.lifecyclemanager.exceptions.InputValidationException) Utils.deepToString(com.aws.greengrass.util.Utils.deepToString) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration) ServiceLoadException(com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)

Aggregations

DeviceIdentityInterface (com.aws.greengrass.provisioning.DeviceIdentityInterface)3 Utils.deepToString (com.aws.greengrass.util.Utils.deepToString)2 EZPlugins (com.aws.greengrass.dependency.EZPlugins)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 InputValidationException (com.aws.greengrass.lifecyclemanager.exceptions.InputValidationException)1 ServiceLoadException (com.aws.greengrass.lifecyclemanager.exceptions.ServiceLoadException)1 ProvisionContext (com.aws.greengrass.provisioning.ProvisionContext)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1