Skip to content

Commit 43bfacd

Browse files
committed
Rolled in review comments
1 parent 48b5164 commit 43bfacd

File tree

5 files changed

+77
-58
lines changed

5 files changed

+77
-58
lines changed

basics_scenarios/sitewise_scenario/SPECIFICATION.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,48 @@ The AWS IoT SiteWise Basics scenario executes the following operations.
2525
2. **Create an AWS IoT SiteWise Asset**:
2626
- Description: This operation creates an AWS SiteWise asset.
2727
- The method `createAsset` is called to obtain the asset ID.
28-
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so,
28+
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown if the asset model id provided in the request is invalid. If so,
2929
display the message and end the program.
3030

3131
3. **Retrieve the property ID values**:
3232
- Description: To send data to an asset, we need to get the property ID values for the
3333
the model properties. This scenario uses temperature and humidity properties.
34-
- The method `listAssetModelProperties()` is called to retrieve the property ID values.
34+
- The method `listAssetModelProperties` is called to retrieve the property ID values.
3535
- Exception Handling: Check to see if an `IoTSiteWiseException` is thrown. There are not
3636
many other useful exceptions for this specific call. If so, display the message and end the program.
3737

3838
4. **Send data to an AWS IoT SiteWise Asset**:
3939
- Description: This operation sends data to an IoT SiteWise Asset.
40-
- This step uses the method `batchPutAssetPropertyValue()`.
40+
- This step uses the method `batchPutAssetPropertyValue`.
4141
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program.
4242

4343
5. **Retrieve the value of the IoT SiteWise Asset property**:
4444
- Description: This operation gets data from the asset.
45-
- This step uses the method `getAssetPropertyValue()`.
45+
- This step uses the method `getAssetPropertyValue`.
4646
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program.
4747

4848
6. **Create an IoT SiteWise Portal**:
4949
- Description: This operation creates an IoT SiteWise portal.
5050
- The method `createPortal` is called.
51-
- Exception Handling: Check to see if an `IoTSiteWiseException` is thrown.
51+
- Exception Handling: Check to see if an `IoTSiteWiseException` is thrown. If so, display the message and end the program.
5252

5353
7. **Describe the Portal**:
5454
- Description: This operation describes the portal and returns a URL for the portal.
55-
- The method `describePortal()` is called and returns the URL.
55+
- The method `describePortal` is called and returns the URL.
5656
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program.
5757

58-
8. **Create an IoTSiteWise Gateway**:
58+
8. **Create an IoT SiteWise Gateway**:
5959
- Description: This operation creates an IoT SiteWise Gateway.
6060
- The method `createGateway` is called.
61-
- Exception Handling: Check to see if an `IoTSiteWiseException` is thrown.
61+
- Exception Handling: Check to see if an `IoTSiteWiseException` is thrown. If so, display the message and end the program.
6262

6363
9. **Describe the IoT SiteWise Gateway**:
6464
- Description: This operation describes the Gateway.
65-
- The method `describeGateway()` is called.
65+
- The method `describeGateway` is called.
6666
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program.
6767

6868
10. **Delete the AWS IoT SiteWise Assets**:
69-
- The `delete()` methods are called to clean up the resources.
69+
- The `delete` methods are called to clean up the resources.
7070
- Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program."
7171

7272
### Program execution
@@ -319,14 +319,13 @@ The following table describes the metadata used in this Basics Scenario.
319319
| `describePortal` | iot_sitewise_metadata.yaml | iotsitewise_DescribePortal |
320320
| `listAssetModels` | iot_sitewise_metadata.yaml | iotsitewise_ListAssetModels |
321321
| `deletePortal` | iot_sitewise_metadata.yaml | iotsitewise_DeletePortal |
322-
| `createPortals` | iot_sitewise_metadata.yaml | iotsitewise_CreatePortal |
322+
| `createPortal` | iot_sitewise_metadata.yaml | iotsitewise_CreatePortal |
323323
| `deleteAssetModel` | iot_sitewise_metadata.yaml | iotsitewise_DeleteAssetModel |
324324
| `deleteAsset` | iot_sitewise_metadata.yaml | iotsitewise_DeleteAsset |
325325
| `describeAssetModel` | iot_sitewise_metadata.yaml | iotsitewise_DescribeAssetModel |
326326
| `getAssetPropertyValue` | iot_sitewise_metadata.yaml | iotsitewise_GetAssetPropertyValue |
327327
| `batchPutAssetPropertyValue` | iot_sitewise_metadata.yaml | iotsitewise_BatchPutAssetPropertyValue |
328328
| `createAsset` | iot_sitewise_metadata.yaml | iotsitewise_CreateAsset |
329-
| `createAsset` | iot_sitewise_metadata.yaml | iotsitewise_CreateAsset |
330329
| `createAssetModel ` | iot_sitewise_metadata.yaml | iotsitewise_CreateAssetModel |
331330
| `scenario` | iot_sitewise_metadata.yaml | iotsitewise_Scenario |
332331
| `hello` | iot_sitewise_metadata.yaml | iotsitewise_Hello |

javav2/example_code/iotsitewise/pom.xml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,12 @@
8888
<artifactId>gson</artifactId>
8989
<version>2.10.1</version>
9090
</dependency>
91-
<dependency>
92-
<groupId>software.amazon.awssdk</groupId>
93-
<artifactId>sso</artifactId>
94-
</dependency>
95-
<dependency>
96-
<groupId>software.amazon.awssdk</groupId>
97-
<artifactId>ssooidc</artifactId>
98-
</dependency>
9991
<dependency>
10092
<groupId>org.junit.platform</groupId>
10193
<artifactId>junit-platform-launcher</artifactId>
10294
<version>1.9.2</version>
10395
<scope>test</scope>
10496
</dependency>
105-
<dependency>
106-
<groupId>software.amazon.awssdk</groupId>
107-
<artifactId>ec2</artifactId>
108-
</dependency>
109-
<dependency>
110-
<groupId>software.amazon.awssdk</groupId>
111-
<artifactId>ssm</artifactId>
112-
</dependency>
11397
<dependency>
11498
<groupId>software.amazon.awssdk</groupId>
11599
<artifactId>sso</artifactId>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public static void main(String[] args) {
4242
*/
4343
public static void fetchAssets(String modelId) {
4444
IoTSiteWiseAsyncClient siteWiseAsyncClient = IoTSiteWiseAsyncClient.builder()
45-
.region(Region.US_EAST_1)
4645
.build();
4746

4847
ListAssetsRequest assetsRequest = ListAssetsRequest.builder()

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class CloudFormationHelper {
3030

3131
private static CloudFormationAsyncClient getCloudFormationClient() {
3232
CloudFormationAsyncClient cfClient = CloudFormationAsyncClient.builder()
33-
.region(Region.US_EAST_1)
3433
.build();
3534

3635
return cfClient;

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

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import software.amazon.awssdk.services.iotsitewise.model.DescribeGatewayRequest;
1616
import software.amazon.awssdk.services.iotsitewise.model.DescribeGatewayResponse;
1717
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
18-
import software.amazon.awssdk.core.retry.RetryPolicy;
1918
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
2019
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
2120
import software.amazon.awssdk.services.iotsitewise.IoTSiteWiseAsyncClient;
@@ -28,7 +27,6 @@
2827
import software.amazon.awssdk.services.iotsitewise.model.CreateAssetRequest;
2928
import software.amazon.awssdk.services.iotsitewise.model.CreateAssetResponse;
3029
import software.amazon.awssdk.services.iotsitewise.model.CreatePortalRequest;
31-
import software.amazon.awssdk.services.iotsitewise.model.CreatePortalResponse;
3230
import software.amazon.awssdk.services.iotsitewise.model.DeleteAssetModelRequest;
3331
import software.amazon.awssdk.services.iotsitewise.model.DeleteAssetModelResponse;
3432
import software.amazon.awssdk.services.iotsitewise.model.DeleteAssetRequest;
@@ -48,6 +46,7 @@
4846
import software.amazon.awssdk.services.iotsitewise.model.PutAssetPropertyValueEntry;
4947
import software.amazon.awssdk.services.iotsitewise.model.TimeInNanos;
5048
import software.amazon.awssdk.services.iotsitewise.model.Variant;
49+
5150
import java.time.Duration;
5251
import java.time.Instant;
5352
import java.util.Arrays;
@@ -88,8 +87,9 @@ private static IoTSiteWiseAsyncClient getAsyncClient() {
8887
}
8988

9089
// snippet-start:[sitewise.java2_create_asset_model.main]
90+
9191
/**
92-
* Creates an asset model asynchronously.
92+
* Creates an asset model.
9393
*
9494
* @param name the name of the asset model to create
9595
* @return a {@link CompletableFuture} that completes with the created {@link CreateAssetModelResponse} when the operation is complete
@@ -115,7 +115,6 @@ public CompletableFuture<CreateAssetModelResponse> createAssetModelAsync(String
115115
.type(humidity)
116116
.build();
117117

118-
119118
CreateAssetModelRequest createAssetModelRequest = CreateAssetModelRequest.builder()
120119
.assetModelName(name)
121120
.assetModelDescription("This is my asset model")
@@ -133,10 +132,11 @@ public CompletableFuture<CreateAssetModelResponse> createAssetModelAsync(String
133132
// snippet-end:[sitewise.java2_create_asset_model.main]
134133

135134
// snippet-start:[sitewise.java2_create_asset.main]
135+
136136
/**
137-
* Asynchronously creates an asset with the specified name and model ARN.
137+
* Creates an asset with the specified name and model ARN.
138138
*
139-
* @param assetName the name of the asset to create
139+
* @param assetName the name of the asset to create
140140
* @param assetModelArn the ARN of the asset model to associate with the asset
141141
* @return a {@link CompletableFuture} that completes with the {@link CreateAssetResponse} when the asset creation is complete
142142
* @throws RuntimeException if the asset creation fails
@@ -153,12 +153,21 @@ public CompletableFuture<CreateAssetResponse> createAssetAsync(String assetName,
153153
if (exception != null) {
154154
throw new RuntimeException("Failed to create asset: " + exception.getMessage(), exception);
155155
}
156-
return response; // Return the response if successful
156+
return response;
157157
});
158158
}
159159
// snippet-end:[sitewise.java2_create_asset.main]
160160

161161
// snippet-start:[sitewise.java2_put_batch_property.main]
162+
163+
/**
164+
* Sends data to the SiteWise service.
165+
*
166+
* @param assetId the ID of the asset to which the data will be sent
167+
* @param tempPropertyId the ID of the temperature property
168+
* @param humidityPropId the ID of the humidity property
169+
* @return a CompletableFuture representing the response from the SiteWise service
170+
*/
162171
public CompletableFuture<BatchPutAssetPropertyValueResponse> sendDataToSiteWiseAsync(String assetId, String tempPropertyId, String humidityPropId) {
163172
Map<String, Double> sampleData = generateSampleData();
164173
long timestamp = Instant.now().toEpochMilli();
@@ -211,7 +220,15 @@ public CompletableFuture<BatchPutAssetPropertyValueResponse> sendDataToSiteWiseA
211220
// snippet-end:[sitewise.java2_put_batch_property.main]
212221

213222
// snippet-start:[sitewise.java2_get_property.main]
214-
// TODO -- fix this including Javadoc
223+
224+
/**
225+
* Asynchronously fetches the value of an asset property.
226+
*
227+
* @param propName the name of the asset property to fetch
228+
* @param propId the ID of the asset property to fetch
229+
* @param assetId the ID of the asset to fetch the property value for
230+
* @throws RuntimeException if an error occurs while fetching the property value
231+
*/
215232
public void getAssetPropValueAsync(String propName, String propId, String assetId) {
216233
GetAssetPropertyValueRequest assetPropertyValueRequest = GetAssetPropertyValueRequest.builder()
217234
.propertyId(propId)
@@ -232,26 +249,31 @@ public void getAssetPropValueAsync(String propName, String propId, String assetI
232249
// snippet-end:[sitewise.java2_get_property.main]
233250

234251
// snippet-start:[sitewise.java2.describe.asset.model.main]
252+
235253
/**
236-
* @param assetModelId The Id of the asset model.
237-
* @return A map of the asset model properties when the CompletableFuture completes.
254+
* Retrieves the property IDs associated with a specific asset model.
255+
*
256+
* @param assetModelId the ID of the asset model to retrieve the property IDs for
257+
* @return a {@link CompletableFuture} that, when completed, contains a {@link Map} mapping the property names to their corresponding IDs
258+
* @throws CompletionException if an error occurs while retrieving the asset model properties
238259
*/
239-
public CompletableFuture<Map<String, String>> getPropertyIds(String assetModelId){
260+
public CompletableFuture<Map<String, String>> getPropertyIds(String assetModelId) {
240261
ListAssetModelPropertiesRequest modelPropertiesRequest = ListAssetModelPropertiesRequest.builder().assetModelId(assetModelId).build();
241262
return getAsyncClient().listAssetModelProperties(modelPropertiesRequest)
242-
.handle( (response, throwable) -> {
243-
if (response != null){
244-
return response.assetModelPropertySummaries().stream()
245-
.collect(Collectors
246-
.toMap(AssetModelPropertySummary::name, AssetModelPropertySummary::id));
247-
} else {
248-
throw (CompletionException) throwable.getCause();
249-
}
250-
});
263+
.handle((response, throwable) -> {
264+
if (response != null) {
265+
return response.assetModelPropertySummaries().stream()
266+
.collect(Collectors
267+
.toMap(AssetModelPropertySummary::name, AssetModelPropertySummary::id));
268+
} else {
269+
throw (CompletionException) throwable.getCause();
270+
}
271+
});
251272
}
252273
// snippet-end:[sitewise.java2.describe.asset.model.main]
253274

254275
// snippet-start:[sitewise.java2.delete.asset.main]
276+
255277
/**
256278
* Deletes an asset asynchronously.
257279
*
@@ -277,7 +299,7 @@ public CompletableFuture<DeleteAssetResponse> deleteAssetAsync(String assetId) {
277299

278300
// snippet-start:[sitewise.java2.delete.asset.model.main]
279301
/**
280-
* Asynchronously deletes an Asset Model with the specified ID.
302+
* Deletes an Asset Model with the specified ID.
281303
*
282304
* @param assetModelId the ID of the Asset Model to delete
283305
* @return a {@link CompletableFuture} that completes with the {@link DeleteAssetModelResponse} when the operation is complete
@@ -298,11 +320,12 @@ public CompletableFuture<DeleteAssetModelResponse> deleteAssetModelAsync(String
298320
// snippet-end:[sitewise.java2.delete.asset.model.main]
299321

300322
// snippet-start:[sitewise.java2.create.portal.main]
323+
301324
/**
302-
* Creates a new IoT SiteWise portal asynchronously.
325+
* Creates a new IoT SiteWise portal.
303326
*
304-
* @param portalName the name of the portal to create
305-
* @param iamRole the IAM role ARN to use for the portal
327+
* @param portalName the name of the portal to create
328+
* @param iamRole the IAM role ARN to use for the portal
306329
* @param contactEmail the email address of the portal contact
307330
* @return a {@link CompletableFuture} that completes with the portal ID when the portal is created successfully, or throws a {@link RuntimeException} if the creation fails
308331
*/
@@ -315,7 +338,7 @@ public CompletableFuture<String> createPortalAsync(String portalName, String iam
315338
.build();
316339

317340
return getAsyncClient().createPortal(createPortalRequest)
318-
.handle ((response, exception) -> {
341+
.handle((response, exception) -> {
319342
if (exception != null) {
320343
logger.error("Failed to create portal: {} ", exception.getCause().getMessage());
321344
throw (CompletionException) exception;
@@ -327,7 +350,7 @@ public CompletableFuture<String> createPortalAsync(String portalName, String iam
327350

328351
// snippet-start:[sitewise.java2.delete.portal.main]
329352
/**
330-
* Deletes a portal asynchronously.
353+
* Deletes a portal.
331354
*
332355
* @param portalId the ID of the portal to be deleted
333356
* @return a {@link CompletableFuture} containing the {@link DeletePortalResponse} when the operation is complete
@@ -349,7 +372,7 @@ public CompletableFuture<DeletePortalResponse> deletePortalAsync(String portalId
349372

350373
// snippet-start:[sitewise.java2.list.asset.model.main]
351374
/**
352-
* Retrieves the asset model ID asynchronously for the given asset model name.
375+
* Retrieves the asset model ID for the given asset model name.
353376
*
354377
* @param assetModelName the name of the asset model to retrieve the ID for
355378
* @return a {@link CompletableFuture} that, when completed, contains the asset model ID, or {@code null} if the asset model is not found
@@ -363,7 +386,7 @@ public CompletableFuture<String> getAssetModelIdAsync(String assetModelName) {
363386
}
364387
for (AssetModelSummary assetModelSummary : listAssetModelsResponse.assetModelSummaries()) {
365388
if (assetModelSummary.name().equals(assetModelName)) {
366-
return assetModelSummary.id(); // Return the ARN if found.
389+
return assetModelSummary.id();
367390
}
368391
}
369392
return null;
@@ -433,6 +456,13 @@ public CompletableFuture<String> createGatewayAsync(String gatewayName, String m
433456
// snippet-end:[sitewise.java2.create.gateway.main]
434457

435458
// snippet-start:[sitewise.java2.delete.gateway.main]
459+
460+
/**
461+
* Deletes the specified gateway asynchronously.
462+
*
463+
* @param gatewayARN the Amazon Resource Name (ARN) of the gateway to be deleted
464+
* @return a {@link CompletableFuture} representing the asynchronous operation of deleting the gateway
465+
*/
436466
public CompletableFuture<DeleteGatewayResponse> deleteGatewayAsync(String gatewayARN) {
437467
DeleteGatewayRequest deleteGatewayRequest = DeleteGatewayRequest.builder()
438468
.gatewayId(gatewayARN)
@@ -450,6 +480,14 @@ public CompletableFuture<DeleteGatewayResponse> deleteGatewayAsync(String gatewa
450480
// snippet-end:[sitewise.java2.delete.gateway.main]
451481

452482
// snippet-start:[sitewise.java2.describe.gateway.main]
483+
/**
484+
* Asynchronously describes the specified gateway.
485+
*
486+
* @param gatewayId the ID of the gateway to describe
487+
* @return a {@link CompletableFuture} that represents the asynchronous operation,
488+
* which will complete with a {@link DescribeGatewayResponse} containing
489+
* information about the specified gateway
490+
*/
453491
public CompletableFuture<DescribeGatewayResponse> describeGatewayAsync(String gatewayId) {
454492
DescribeGatewayRequest request = DescribeGatewayRequest.builder()
455493
.gatewayId(gatewayId)

0 commit comments

Comments
 (0)