Skip to content

Commit bd89eb9

Browse files
authored
Merge pull request #852 from GoogleCloudPlatform/iot-snippets
Updates sample to work as commandline
2 parents e0ffe50 + 29b51be commit bd89eb9

File tree

7 files changed

+965
-358
lines changed

7 files changed

+965
-358
lines changed

iot/api-client/manager/README.md

+107-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PubSub topic for Cloud IoT as described in [the parent README](../README.md).
1010
Manually install [the provided client library](https://cloud.google.com/iot/resources/java/cloud-iot-core-library.jar)
1111
for Cloud IoT Core to Maven:
1212

13-
mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.google.apis \
13+
mvn install:install-file -Dfile=cloud-iot-core-library.jar -DgroupId=com.example.apis \
1414
-DartifactId=google-api-services-cloudiot -Dversion=v1beta1-rev20170418-1.22.0-SNAPSHOT \
1515
-Dpackaging=jar
1616

@@ -21,23 +21,116 @@ mvn clean compile assembly:single
2121

2222
## Running the sample
2323

24-
The following command summarizes the sample usage:
24+
The following description summarizes the sample usage:
2525

26-
mvn exec:java \
27-
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
28-
-Dexec.args="-project_id=my-project-id \
29-
-pubsub_topic=projects/my-project-id/topics/my-topic-id \
30-
-ec_public_key_file=/path/to/ec_public.pem \
31-
-rsa_certificate_file=/path/to/rsa_cert.pem"
26+
usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
27+
[--ec_public_key_file <arg>] --project_id <arg> --pubsub_topic
28+
<arg> --registry_name <arg> [--rsa_certificate_file <arg>]
29+
30+
Cloud IoT Core Commandline Example (Device / Registry management):
31+
32+
--cloud_region <arg> GCP cloud region.
33+
--command <arg> Command to run:
34+
create-iot-topic
35+
create-rsa
36+
create-es
37+
create-unauth
38+
create-registry
39+
delete-device
40+
delete-registry
41+
get-device
42+
get-registry
43+
list-devices
44+
list-registries
45+
patch-device-es
46+
patch-device-rsa
47+
--ec_public_key_file <arg> Path to ES256 public key file.
48+
--project_id <arg> GCP cloud project name.
49+
--pubsub_topic <arg> Pub/Sub topic to create registry in.
50+
--registry_name <arg> Name for your Device Registry.
51+
--rsa_certificate_file <arg> Path to RS256 certificate file.
52+
53+
https://cloud.google.com/iot-core
3254

3355
For example, if your project ID is `blue-jet-123`, your service account
3456
credentials are stored in your home folder in creds.json and you have generated
3557
your credentials using the shell script provided in the parent folder, you can
3658
run the sample as:
3759

38-
mvn exec:java \
39-
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
40-
-Dexec.args="-project_id=blue-jet-123 \
41-
-pubsub_topic=projects/blue-jet-123/topics/device-events \
42-
-ec_public_key_file=../ec_public.pem \
43-
-rsa_certificate_file=../rsa_cert.pem"
60+
61+
## Usage Examples
62+
63+
Create a PubSub topic, `hello-java`, for the project, `blue-jet-123`:
64+
65+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
66+
com.example.cloud.iot.examples.DeviceRegistryExample \
67+
-project_id=blue-jet-123 -pubsub_topic=hello-java
68+
-command=create-iot-topic
69+
70+
Create an ES device:
71+
72+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
73+
com.example.cloud.iot.examples.DeviceRegistryExample \
74+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
75+
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
76+
-device_id="java-device-0" -command=create-es
77+
78+
Create an RSA device:
79+
80+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
81+
com.example.cloud.iot.examples.DeviceRegistryExample \
82+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
83+
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
84+
-device_id="java-device-1" -command=create-rsa
85+
86+
Create a device without authorization:
87+
88+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
89+
com.example.cloud.iot.examples.DeviceRegistryExample \
90+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
91+
-registry_name=hello-java -device_id="java-device-3" \
92+
-command=create-unauth
93+
94+
Create a device registry:
95+
96+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
97+
com.example.cloud.iot.examples.DeviceRegistryExample \
98+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
99+
-registry_name=hello-java -command=create-registry \
100+
101+
Get a device registry:
102+
103+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
104+
com.example.cloud.iot.examples.DeviceRegistryExample \
105+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
106+
-registry_name=hello-java -command=get-registry
107+
108+
List devices:
109+
110+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
111+
com.example.cloud.iot.examples.DeviceRegistryExample \
112+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
113+
-registry_name=hello-java -command=list-devices
114+
115+
List device registries:
116+
117+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
118+
com.example.cloud.iot.examples.DeviceRegistryExample \
119+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
120+
-registry_name=hello-java -command=list-registries
121+
122+
Patch a device with ES:
123+
124+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
125+
com.example.cloud.iot.examples.DeviceRegistryExample \
126+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
127+
-registry_name=hello-java -ec_public_key_file ../ec_public.pem \
128+
-device_id="java-device-1" -command=patch-device-es
129+
130+
Patch a device with RSA:
131+
132+
java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
133+
com.example.cloud.iot.examples.DeviceRegistryExample \
134+
-project_id=blue-jet-123 -pubsub_topic=hello-java \
135+
-registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
136+
-device_id="java-device-0" -command=patch-device-rsa

iot/api-client/manager/pom.xml

+19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
<artifactId>google-api-services-cloudiot</artifactId>
4343
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
4444
</dependency>
45+
<dependency>
46+
<groupId>com.google.cloud</groupId>
47+
<artifactId>google-cloud-pubsub</artifactId>
48+
<version>0.21.1-beta</version>
49+
</dependency>
4550
<dependency>
4651
<groupId>com.google.oauth-client</groupId>
4752
<artifactId>google-oauth-client</artifactId>
@@ -57,6 +62,20 @@
5762
<artifactId>commons-cli</artifactId>
5863
<version>1.3</version>
5964
</dependency>
65+
66+
<!-- Test dependencies -->
67+
<dependency>
68+
<groupId>junit</groupId>
69+
<artifactId>junit</artifactId>
70+
<version>4.12</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.google.truth</groupId>
75+
<artifactId>truth</artifactId>
76+
<version>0.34</version>
77+
<scope>test</scope>
78+
</dependency>
6079
</dependencies>
6180

6281
<build>

0 commit comments

Comments
 (0)