Skip to content

Commit 9cecf12

Browse files
committed
updated Sitewise Java files
1 parent a6bfd41 commit 9cecf12

File tree

6 files changed

+282
-30
lines changed

6 files changed

+282
-30
lines changed

javav2/example_code/iotsitewise/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
<version>5.9.2</version>
6767
<scope>test</scope>
6868
</dependency>
69+
<dependency>
70+
<groupId>software.amazon.awssdk</groupId>
71+
<artifactId>secretsmanager</artifactId>
72+
</dependency>
6973
<dependency>
7074
<groupId>software.amazon.awssdk</groupId>
7175
<artifactId>netty-nio-client</artifactId>

javav2/example_code/iotsitewise/src/main/java/com/example/iotsitewise/HelloSitewise.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ public static void main(String[] args) {
3232
}
3333

3434
String assetModelId = args[0];
35-
IoTSiteWiseAsyncClient siteWiseAsyncClient = IoTSiteWiseAsyncClient.builder()
36-
.region(Region.US_EAST_1)
37-
.build();
38-
39-
fetchAssets(siteWiseAsyncClient, assetModelId);
35+
fetchAssets(assetModelId);
4036
}
4137

4238
/**
4339
* Fetches assets from AWS IoT SiteWise using the provided {@link IoTSiteWiseAsyncClient}.
4440
*
45-
* @param siteWiseAsyncClient the AWS IoT SiteWise asynchronous client to use for the request
4641
* @param modelId the ID of the asset model to fetch assets for
4742
*/
48-
public static void fetchAssets(IoTSiteWiseAsyncClient siteWiseAsyncClient, String modelId) {
43+
public static void fetchAssets(String modelId) {
44+
IoTSiteWiseAsyncClient siteWiseAsyncClient = IoTSiteWiseAsyncClient.builder()
45+
.region(Region.US_EAST_1)
46+
.build();
47+
4948
ListAssetsRequest assetsRequest = ListAssetsRequest.builder()
5049
.maxResults(10)
5150
.assetModelId(modelId)

javav2/example_code/iotsitewise/src/main/java/com/example/iotsitewise/scenario/CloudFormationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static Boolean describeStack(String stackName) {
9292
}
9393
return false;
9494
}
95-
static void destroyCloudFormationStack(String stackName) {
95+
public static void destroyCloudFormationStack(String stackName) {
9696
getCloudFormationClient().deleteStack(b -> b.stackName(stackName))
9797
.whenComplete((dsr, t) -> {
9898
if (dsr != null) {

javav2/example_code/iotsitewise/src/main/java/com/example/iotsitewise/scenario/SitewiseActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void getAssetPropValueAsync(String propName, String propId, String assetI
236236
* @param assetModelId The Id of the asset model.
237237
* @return A map of the asset model properties when the CompletableFuture completes.
238238
*/
239-
CompletableFuture<Map<String, String>> getPropertyIds(String assetModelId){
239+
public CompletableFuture<Map<String, String>> getPropertyIds(String assetModelId){
240240
ListAssetModelPropertiesRequest modelPropertiesRequest = ListAssetModelPropertiesRequest.builder().assetModelId(assetModelId).build();
241241
return getAsyncClient().listAssetModelProperties(modelPropertiesRequest)
242242
.handle( (response, throwable) -> {

javav2/example_code/iotsitewise/src/main/java/com/example/iotsitewise/scenario/SitewiseScenario.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55

66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
8-
import software.amazon.awssdk.services.iotsitewise.model.BatchPutAssetPropertyValueResponse;
98
import software.amazon.awssdk.services.iotsitewise.model.CreateAssetModelResponse;
109
import software.amazon.awssdk.services.iotsitewise.model.CreateAssetResponse;
11-
import software.amazon.awssdk.services.iotsitewise.model.CreateGatewayResponse;
12-
import software.amazon.awssdk.services.iotsitewise.model.DeleteAssetModelResponse;
13-
import software.amazon.awssdk.services.iotsitewise.model.DeleteAssetResponse;
14-
import software.amazon.awssdk.services.iotsitewise.model.DeletePortalResponse;
15-
import software.amazon.awssdk.services.iotsitewise.model.DescribeGatewayResponse;
1610
import software.amazon.awssdk.services.iotsitewise.model.IoTSiteWiseException;
1711
import software.amazon.awssdk.services.iotsitewise.model.ResourceAlreadyExistsException;
1812
import software.amazon.awssdk.services.iotsitewise.model.ResourceNotFoundException;
19-
20-
import java.util.List;
2113
import java.util.Map;
2214
import java.util.Scanner;
2315
import java.util.concurrent.CompletableFuture;
@@ -48,18 +40,18 @@ public static void main(String[] args) throws Throwable {
4840
myThing - The name of the IoT thing or device that is connected to the IoT SiteWise gateway.
4941
""";
5042

51-
//if (args.length != 6) {
52-
// logger.info(usage);
53-
// return;
54-
// }
43+
if (args.length != 6) {
44+
logger.info(usage);
45+
return;
46+
}
5547

5648
Scanner scanner = new Scanner(System.in);
57-
String assetModelName = "MyAssetModel";
58-
String assetName = "MyAsset";
59-
String portalName = "MyPortal";
60-
String contactEmail = "[email protected]";
61-
String gatewayName = "myGateway11";
62-
String myThing = "myThing78";
49+
String assetModelName = args[0];
50+
String assetName = args[1];
51+
String portalName = args[2];
52+
String contactEmail = args[3];
53+
String gatewayName = args[4];
54+
String myThing = args[5];
6355

6456
logger.info("""
6557
AWS IoT SiteWise is a fully managed software-as-a-service (SaaS) that
@@ -140,6 +132,8 @@ public static void runScenario(String assetModelName, String assetName, String
140132
an asset from the asset model.
141133
142134
""");
135+
logger.info("Let's wait 1 minute for the asset model to be ready.");
136+
countdown(1);
143137
waitForInputToContinue(scanner);
144138
String assetId;
145139
try {
@@ -229,7 +223,7 @@ public static void runScenario(String assetModelName, String assetName, String
229223
""");
230224
waitForInputToContinue(scanner);
231225
try {
232-
sitewiseActions.getAssetPropValueAsync("Temperature property", tempPropId, assetId); // FIXME <------------------
226+
sitewiseActions.getAssetPropValueAsync("Temperature property", tempPropId, assetId);
233227
waitForInputToContinue(scanner);
234228
} catch (RuntimeException rt) {
235229
Throwable cause = rt.getCause();
@@ -246,7 +240,7 @@ public static void runScenario(String assetModelName, String assetName, String
246240
}
247241
throw cause;
248242
}
249-
sitewiseActions.getAssetPropValueAsync("Humidity property", humPropId, assetId); // FIXME <------------------
243+
sitewiseActions.getAssetPropValueAsync("Humidity property", humPropId, assetId);
250244
waitForInputToContinue(scanner);
251245
logger.info(DASHES);
252246

@@ -257,7 +251,7 @@ public static void runScenario(String assetModelName, String assetName, String
257251
such as sensors, equipment, and control systems, into a centralized platform.
258252
""");
259253
waitForInputToContinue(scanner);
260-
String portalId = "";
254+
String portalId;
261255
try {
262256
portalId = sitewiseActions.createPortalAsync(portalName, iamRole, contactEmail).join();
263257
logger.info("Portal created successfully. Portal ID {}", portalId);

0 commit comments

Comments
 (0)