本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
开发自定义配置插件
要开发自定义配置插件,请创建一个 Java 类来实现com.aws.greengrass.provisioning.DeviceIdentityInterface
界面。您可以在项目中包含 Greengrass Nucleus JAR 文件来访问此接口及其类。此接口定义了一种输入插件配置并输出置备配置的方法。配置配置定义了系统的配置和Greengrass Core 组件. 这些区域有:Amazon IoT Greengrass核心软件安装程序使用此配置配置来配置Amazon IoT Greengrass设备上的核心软件。
开发自定义配置插件后,将其构建为 JAR 文件,您可以提供给Amazon IoT Greengrass核心软件安装程序在安装过程中运行插件。安装程序在安装程序使用的同一 JVM 中运行自定义配置插件,因此您可以创建仅包含插件代码的 JAR。
注意
这些区域有:Amazon IoT队列预置插件实现DeviceIdentityInterface
在安装期间使用队列预置。队列配置插件是开源的,因此您可以浏览其源代码以查看如何使用 Provisioning 插件界面的示例。有关更多信息,请参阅 。Amazon IoT队列预置插件
要求
要开发自定义配置插件,必须创建符合以下要求的 Java 类:
-
使用
com.aws.greengrass
包裹,或者内的包裹com.aws.greengrass
程序包。 -
有没有任何参数的构造函数。
-
实现
DeviceIdentityInterface
界面。有关更多信息,请参阅 实现 DeviceIdentityInterface 界面。
实现 DeviceIdentityInterface 界面
使用com.aws.greengrass.provisioning.DeviceIdentityInterface
在自定义插件中的界面中,将 Greengrass Nucleus 作为项目的依赖项添加。
使用 DeviceIdentityInterface 在自定义配置插件项目中
-
您可以将 Greengrass Nucleus JAR 文件添加为库,或者添加 Greengrass 核心作为 Maven 依赖项。请执行下列操作之一:
-
要将 Greengrass Nucleus JAR 文件添加为库,请下载Amazon IoT Greengrass核心软件,其中包含 Greengrass 核心 JAR。您可以下载最新版本的Amazon IoT Greengrass来自以下位置的核心软件:
您可以找到 Greengrass Core JAR 文件(
Greengrass.jar
) 在lib
ZIP 文件中的文件夹。将此 JAR 文件添加到项目中。 -
要在 Maven 项目中消耗 Greengrass 核心,请在
nucleus
中的神器com.aws.greengrass
组中)。您还必须添加greengrass-common
存储库,因为 Greengrass 核心在 Maven 中央存储库中不可用。<project
...
>...
<repositories> <repository> <id>greengrass-common</id> <name>greengrass common</name> <url>https://d2jrmugq4soldf.cloudfront.net/snapshots</url> </repository> </repositories>...
<dependencies> <dependency> <groupId>com.aws.greengrass</groupId> <artifactId>nucleus</artifactId> <version>2.5.0-SNAPSHOT</version> <scope>provided</scope> </dependency> </dependencies> </project>
-
接口设备 Identity
这些区域有:com.aws.greengrass.provisioning.DeviceIdentityInterface
界面具有以下形态。
注意
您还可以在com.aws.greengrass.配置程序包
public interface com.aws.greengrass.provisioning.DeviceIdentityInterface { ProvisionConfiguration updateIdentityConfiguration(ProvisionContext context) throws RetryableProvisioningException, InterruptedException; // Return the name of the plugin. String name(); } com.aws.greengrass.provisioning.ProvisionConfiguration { SystemConfiguration systemConfiguration; NucleusConfiguration nucleusConfiguration } com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration { String certificateFilePath; String privateKeyPath; String rootCAPath; String thingName; } com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration { String awsRegion; String iotCredentialsEndpoint; String iotDataEndpoint; String iotRoleAlias; } com.aws.greengrass.provisioning.ProvisioningContext { Map<String, Object> parameterMap; String provisioningPolicy; // The policy is always "PROVISION_IF_NOT_PROVISIONED". } com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException {}
中的每个配置值SystemConfiguration
和NucleusConfiguration
需要安装Amazon IoT Greengrass核心软件,但你可以返回null
. 如果你的自定义配置插件返回null
对于任何配置值,在创建config.yaml
要提供给Amazon IoT Greengrass核心软件安装程序。如果您的自定义配置插件为您也在中定义的选项返回非空值config.yaml
,然后安装程序将替换中的值config.yaml
使用插件返回的值。