14
14
import software .amazon .awssdk .services .iot .model .CreateThingRequest ;
15
15
import software .amazon .awssdk .services .iot .model .ResourceAlreadyExistsException ;
16
16
import software .amazon .awssdk .services .iotfleetwise .IoTFleetWiseAsyncClient ;
17
+ import software .amazon .awssdk .services .iotfleetwise .model .Node ;
17
18
import software .amazon .awssdk .services .iotfleetwise .model .*;
18
19
import java .time .Duration ;
19
20
import java .util .HashMap ;
@@ -56,8 +57,9 @@ private static IoTFleetWiseAsyncClient getAsyncClient() {
56
57
}
57
58
58
59
// snippet-start:[iotfleetwise.java2.create.catalog.main]
60
+
59
61
/**
60
- * Creates a signal catalog asynchronously .
62
+ * Creates a signal catalog.
61
63
*
62
64
* @param signalCatalogName the name of the signal catalog to be created
63
65
* @return a {@link CompletableFuture} that completes with the Amazon Resource Name (ARN) of the created signal catalog
@@ -106,7 +108,7 @@ public CompletableFuture<String> createSignalCatalogAsync(String signalCatalogNa
106
108
.whenComplete ((response , exception ) -> {
107
109
if (exception != null ) {
108
110
Throwable cause = exception .getCause ();
109
- if (cause instanceof software .amazon .awssdk .services .iot .model .ValidationException ) {
111
+ if (cause instanceof software .amazon .awssdk .services .iotfleetwise .model .ValidationException ) {
110
112
throw new CompletionException ("A validation error occurred: " + cause .getMessage (), cause );
111
113
}
112
114
throw new CompletionException ("Error performing place search" , exception );
@@ -135,14 +137,15 @@ private static CompletableFuture<Void> delayAsync(long millis) {
135
137
}
136
138
137
139
// snippet-start:[iotfleetwise.java2.delete.catalog.main]
140
+
138
141
/**
139
- * Deletes the specified signal catalog asynchronously, if it exists .
142
+ * Deletes the specified signal catalog.
140
143
*
141
144
* @param signalCatalogName the name of the signal catalog to delete
142
145
* @return a {@link CompletableFuture} representing the asynchronous operation.
143
- * The future will complete without a result if the signal catalog was successfully
144
- * deleted or if the signal catalog does not exist. If an exception occurs during
145
- * the deletion, the future will complete exceptionally with the corresponding exception.
146
+ * The future will complete without a result if the signal catalog was successfully
147
+ * deleted or if the signal catalog does not exist. If an exception occurs during
148
+ * the deletion, the future will complete exceptionally with the corresponding exception.
146
149
*/
147
150
public static CompletableFuture <Void > deleteSignalCatalogIfExistsAsync (String signalCatalogName ) {
148
151
DeleteSignalCatalogRequest request = DeleteSignalCatalogRequest .builder ()
@@ -165,7 +168,7 @@ public static CompletableFuture<Void> deleteSignalCatalogIfExistsAsync(String si
165
168
166
169
// snippet-start:[iotfleetwise.java2.create.decoder.main]
167
170
/**
168
- * Creates a new decoder manifest asynchronously .
171
+ * Creates a new decoder manifest.
169
172
*
170
173
* @param name the name of the decoder manifest
171
174
* @param modelManifestArn the ARN of the model manifest
@@ -174,8 +177,6 @@ public static CompletableFuture<Void> deleteSignalCatalogIfExistsAsync(String si
174
177
*/
175
178
public CompletableFuture <String > createDecoderManifestAsync (String name , String modelManifestArn ) {
176
179
String interfaceId = "can0" ;
177
-
178
- // Define CAN interface.
179
180
NetworkInterface networkInterface = NetworkInterface .builder ()
180
181
.interfaceId (interfaceId )
181
182
.type (NetworkInterfaceType .CAN_INTERFACE )
@@ -218,7 +219,6 @@ public CompletableFuture<String> createDecoderManifestAsync(String name, String
218
219
.build ())
219
220
.build ();
220
221
221
- // Create decoder manifest request.
222
222
CreateDecoderManifestRequest request = CreateDecoderManifestRequest .builder ()
223
223
.name (name )
224
224
.modelManifestArn (modelManifestArn )
@@ -237,8 +237,9 @@ public CompletableFuture<String> createDecoderManifestAsync(String name, String
237
237
// snippet-end:[iotfleetwise.java2.create.decoder.main]
238
238
239
239
// snippet-start:[iotfleetwise.java2.delete.decoder.main]
240
+
240
241
/**
241
- * Deletes a decoder manifest asynchronously .
242
+ * Deletes a decoder manifest.
242
243
*
243
244
* @param name the name of the decoder manifest to delete
244
245
* @return a {@link CompletableFuture} that completes when the decoder manifest has been deleted
@@ -266,6 +267,7 @@ public CompletableFuture<Void> deleteDecoderManifestAsync(String name) {
266
267
// snippet-end:[iotfleetwise.java2.delete.decoder.main]
267
268
268
269
// snippet-start:[iotfleetwise.java2.delete.vehicle.main]
270
+
269
271
/**
270
272
* Asynchronously deletes a vehicle with the specified name.
271
273
*
@@ -295,6 +297,7 @@ public CompletableFuture<Void> deleteVehicleAsync(String vecName) {
295
297
// snippet-end:[iotfleetwise.java2.delete.vehicle.main]
296
298
297
299
// snippet-start:[iotfleetwise.java2.update.manifest.main]
300
+
298
301
/**
299
302
* Updates the model manifest asynchronously.
300
303
*
@@ -317,6 +320,7 @@ public void updateModelManifestAsync(String name) {
317
320
// snippet-end:[iotfleetwise.java2.update.manifest.main]
318
321
319
322
// snippet-start:[iotfleetwise.java2.update.decoder.main]
323
+
320
324
/**
321
325
* Asynchronously updates the decoder manifest with the given name.
322
326
*
@@ -341,14 +345,15 @@ public CompletableFuture<Void> updateDecoderManifestAsync(String name) {
341
345
// snippet-end:[iotfleetwise.java2.update.decoder.main]
342
346
343
347
// snippet-start:[iotfleetwise.java2.create.vehicle.main]
348
+
344
349
/**
345
350
* Asynchronously creates a new vehicle in the system.
346
351
*
347
- * @param vecName the name of the vehicle to be created
348
- * @param manifestArn the Amazon Resource Name (ARN) of the model manifest for the vehicle
349
- * @param decArn the Amazon Resource Name (ARN) of the decoder manifest for the vehicle
352
+ * @param vecName the name of the vehicle to be created
353
+ * @param manifestArn the Amazon Resource Name (ARN) of the model manifest for the vehicle
354
+ * @param decArn the Amazon Resource Name (ARN) of the decoder manifest for the vehicle
350
355
* @return a {@link CompletableFuture} that completes when the vehicle has been created, or throws a
351
- * {@link CompletionException} if there was an error during the creation process
356
+ * {@link CompletionException} if there was an error during the creation process
352
357
*/
353
358
public CompletableFuture <Void > createVehicleAsync (String vecName , String manifestArn , String decArn ) {
354
359
CreateVehicleRequest request = CreateVehicleRequest .builder ()
@@ -374,6 +379,7 @@ public CompletableFuture<Void> createVehicleAsync(String vecName, String manifes
374
379
// snippet-end:[iotfleetwise.java2.create.vehicle.main]
375
380
376
381
// snippet-start:[iotfleetwise.java2.decoder.active.main]
382
+
377
383
/**
378
384
* Waits for the decoder manifest to become active asynchronously.
379
385
*
@@ -393,7 +399,7 @@ public CompletableFuture<Void> waitForDecoderManifestActiveAsync(String decoderN
393
399
public void run () {
394
400
int elapsed = secondsElapsed .incrementAndGet ();
395
401
396
- // Only check status every 5 seconds
402
+ // Check status every 5 seconds.
397
403
if (elapsed % 5 == 0 ) {
398
404
GetDecoderManifestRequest request = GetDecoderManifestRequest .builder ()
399
405
.name (decoderName )
@@ -412,21 +418,20 @@ public void run() {
412
418
lastStatus .set (status );
413
419
414
420
if (status == ManifestStatus .ACTIVE ) {
415
- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: ACTIVE ✅\n " );
421
+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: ACTIVE ✅\n " );
416
422
scheduler .shutdown ();
417
423
result .complete (null );
418
424
} else if (status == ManifestStatus .INVALID ) {
419
- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: INVALID ❌\n " );
425
+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: INVALID ❌\n " );
420
426
scheduler .shutdown ();
421
427
result .completeExceptionally (
422
428
new RuntimeException ("Decoder manifest became INVALID. Cannot proceed." ));
423
429
} else {
424
- // Just update the status text
425
- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + status );
430
+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + status );
426
431
}
427
432
});
428
433
} else {
429
- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + lastStatus .get ());
434
+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Decoder Status: " + lastStatus .get ());
430
435
}
431
436
}
432
437
};
@@ -437,6 +442,7 @@ public void run() {
437
442
// snippet-end:[iotfleetwise.java2.decoder.active.main]
438
443
439
444
// snippet-start:[iotfleetwise.java2.get.manifest.main]
445
+
440
446
/**
441
447
* Waits for the specified model manifest to become active.
442
448
*
@@ -475,7 +481,7 @@ public void run() {
475
481
lastStatus .set (status );
476
482
477
483
if (status == ManifestStatus .ACTIVE ) {
478
- System . out . print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: ACTIVE ✅\n " );
484
+ logger . info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: ACTIVE ✅\n " );
479
485
scheduler .shutdown ();
480
486
result .complete (null );
481
487
} else if (status == ManifestStatus .INVALID ) {
@@ -484,13 +490,11 @@ public void run() {
484
490
result .completeExceptionally (
485
491
new RuntimeException ("Model manifest became INVALID. Cannot proceed." ));
486
492
} else {
487
- // Just update the status text
488
- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + status );
493
+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + status );
489
494
}
490
495
});
491
496
} else {
492
- // Still print even if not polling yet
493
- System .out .print ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + lastStatus .get ());
497
+ logger .info ("\r ⏱️ Elapsed: " + elapsed + "s | Status: " + lastStatus .get ());
494
498
}
495
499
}
496
500
};
@@ -501,6 +505,7 @@ public void run() {
501
505
// snippet-end:[iotfleetwise.java2.get.manifest.main]
502
506
503
507
// snippet-start:[iotfleetwise.java2.get.vehicle.main]
508
+
504
509
/**
505
510
* Asynchronously fetches the details of a vehicle.
506
511
*
@@ -568,8 +573,9 @@ public CompletableFuture<Void> createThingIfNotExistsAsync(String thingName) {
568
573
}
569
574
570
575
// snippet-start:[iotfleetwise.java2.delete.model.main]
576
+
571
577
/**
572
- * Deletes a model manifest asynchronously .
578
+ * Deletes a model manifest.
573
579
*
574
580
* @param name the name of the model manifest to delete
575
581
* @return a {@link CompletableFuture} that completes when the model manifest has been deleted
@@ -597,9 +603,10 @@ public CompletableFuture<Void> deleteModelManifestAsync(String name) {
597
603
598
604
// snippet-end:[iotfleetwise.java2.delete.model.main]
599
605
600
- // snippet-start:[iotfleetwise.java2.delete.catalog.main]
606
+ // snippet-start:[iotfleetwise.java2.delete.catalog.main]
607
+
601
608
/**
602
- * Deletes a signal catalog asynchronously .
609
+ * Deletes a signal catalog.
603
610
*
604
611
* @param name the name of the signal catalog to delete
605
612
* @return a {@link CompletableFuture} that completes when the signal catalog is deleted
@@ -628,8 +635,9 @@ public CompletableFuture<Void> deleteSignalCatalogAsync(String name) {
628
635
// snippet-end:[iotfleetwise.java2.delete.catalog.main]
629
636
630
637
// snippet-start:[iotfleetwise.java2.list.catalogs.main]
638
+
631
639
/**
632
- * Lists the signal catalog nodes asynchronously .
640
+ * Lists the signal catalog nodes.
633
641
*
634
642
* @param signalCatalogName the name of the signal catalog
635
643
* @return a CompletableFuture that, when completed, contains a list of nodes in the specified signal catalog
@@ -651,21 +659,22 @@ public CompletableFuture<List<Node>> listSignalCatalogNodeAsync(String signalCat
651
659
// snippet-end:[iotfleetwise.java2.list.catalogs.main]
652
660
653
661
// snippet-start:[iotfleetwise.java2.create.model.main]
662
+
654
663
/**
655
- * Creates a model manifest asynchronously .
664
+ * Creates a model manifest.
656
665
*
657
- * @param name the name of the model manifest to create
658
- * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog
659
- * @param nodes a list of nodes to include in the model manifest
666
+ * @param name the name of the model manifest to create
667
+ * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog
668
+ * @param nodes a list of nodes to include in the model manifest
660
669
* @return a {@link CompletableFuture} that completes with the ARN of the created model manifest
661
- * @throws RuntimeException if an unsupported node type is encountered
670
+ * @throws RuntimeException if an unsupported node type is encountered
662
671
* @throws CompletionException if there is a failure during the model manifest creation
663
672
*/
664
673
665
674
public CompletableFuture <String > createModelManifestAsync (String name ,
666
- String signalCatalogArn ,
667
- List <Node > nodes ) {
668
- // Extract fully qualified names from each Node
675
+ String signalCatalogArn ,
676
+ List <Node > nodes ) {
677
+ // Extract fully qualified names from each Node.
669
678
List <String > fqnList = nodes .stream ()
670
679
.map (node -> {
671
680
if (node .sensor () != null ) {
@@ -726,10 +735,11 @@ public CompletableFuture<Void> deleteFleetAsync(String fleetId) {
726
735
727
736
728
737
// snippet-start:[iotfleetwise.java2.create.fleet.main]
738
+
729
739
/**
730
- * Creates a new fleet asynchronously using the AWS SDK for Java V2 .
740
+ * Creates a new fleet.
731
741
*
732
- * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
742
+ * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet
733
743
* @param fleetId the unique identifier for the fleet
734
744
* @return a {@link CompletableFuture} that completes with the ID of the created fleet
735
745
* @throws RuntimeException if there was an error creating the fleet
0 commit comments