Skip to content

Commit d9827a8

Browse files
committed
updated the Action class
1 parent 473e1e8 commit d9827a8

2 files changed

Lines changed: 61 additions & 44 deletions

File tree

javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,13 @@ public CompletableFuture<Void> getVehicleDetailsAsync(String vehicleName) {
519519
return getAsyncClient().getVehicle(request)
520520
.whenComplete((response, exception) -> {
521521
if (exception != null) {
522-
throw new CompletionException("Failed to fetch vehicle details: " + exception.getMessage(), exception);
522+
Throwable cause = exception.getCause() != null ? exception.getCause() : exception;
523+
524+
if (cause instanceof ResourceNotFoundException) {
525+
throw new CompletionException((ResourceNotFoundException) cause);
526+
} else {
527+
throw new CompletionException("Failed to fetch vehicle details: " + cause.getMessage(), cause);
528+
}
523529
} else {
524530
Map<String, Object> details = new HashMap<>();
525531
details.put("vehicleName", response.vehicleName());
@@ -537,7 +543,7 @@ public CompletableFuture<Void> getVehicleDetailsAsync(String vehicleName) {
537543
});
538544
}
539545
})
540-
.thenApply(response -> null); // returning CompletableFuture<Void>
546+
.thenApply(response -> null); // CompletableFuture<Void>
541547
}
542548
// snippet-end:[iotfleetwise.java2.get.vehicle.main]
543549

javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.java

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import software.amazon.awssdk.services.iotfleetwise.model.Node;
1010
import software.amazon.awssdk.services.iotfleetwise.model.ResourceNotFoundException;
1111
import software.amazon.awssdk.services.iotfleetwise.model.ValidationException;
12+
1213
import java.util.List;
1314
import java.util.Scanner;
1415
import java.util.concurrent.CompletionException;
@@ -22,17 +23,17 @@ public class FleetwiseScenario {
2223

2324
public static void main(String[] args) {
2425
final String usage =
25-
"""
26-
Usage:
27-
<signalCatalogName> <manifestName> <fleetId> <vecName> <decName>
26+
"""
27+
Usage:
28+
<signalCatalogName> <manifestName> <fleetId> <vecName> <decName>
2829
29-
Where:
30-
signalCatalogName - The name of the Signal Catalog to create (eg, catalog30).
31-
manifestName - The name of the Vehicle Model (Model Manifest) to create (eg, manifest30).
32-
fleetId - The ID of the Fleet to create (eg, fleet30).
33-
vecName - The name of the Vehicle to create (eg, vehicle30).
34-
decName - The name of the Decoder Manifest to create (eg, decManifest30).
35-
""";
30+
Where:
31+
signalCatalogName - The name of the Signal Catalog to create (eg, catalog30).
32+
manifestName - The name of the Vehicle Model (Model Manifest) to create (eg, manifest30).
33+
fleetId - The ID of the Fleet to create (eg, fleet30).
34+
vecName - The name of the Vehicle to create (eg, vehicle30).
35+
decName - The name of the Decoder Manifest to create (eg, decManifest30).
36+
""";
3637

3738
if (args.length != 5) {
3839
System.out.println(usage);
@@ -46,28 +47,28 @@ public static void main(String[] args) {
4647
String decName = args[4];
4748

4849
logger.info(
49-
"""
50-
AWS IoT FleetWise is a managed service that simplifies the
51-
process of collecting, organizing, and transmitting vehicle
52-
data to the cloud in near real-time. Designed for automakers
53-
and fleet operators, it allows you to define vehicle models,
54-
specify the exact data you want to collect (such as engine
55-
temperature, speed, or battery status), and send this data to
56-
AWS for analysis. By using intelligent data collection
57-
techniques, IoT FleetWise reduces the volume of data
58-
transmitted by filtering and transforming it at the edge,
59-
helping to minimize bandwidth usage and costs.
60-
61-
At its core, AWS IoT FleetWise helps organizations build
62-
scalable systems for vehicle data management and analytics,
63-
supporting a wide variety of vehicles and sensor configurations.
64-
You can define signal catalogs and decoder manifests that describe
65-
how raw CAN bus signals are translated into readable data, making
66-
the platform highly flexible and extensible. This allows
67-
manufacturers to optimize vehicle performance, improve safety,
68-
and reduce maintenance costs by gaining real-time visibility
69-
into fleet operations.
70-
""");
50+
"""
51+
AWS IoT FleetWise is a managed service that simplifies the
52+
process of collecting, organizing, and transmitting vehicle
53+
data to the cloud in near real-time. Designed for automakers
54+
and fleet operators, it allows you to define vehicle models,
55+
specify the exact data you want to collect (such as engine
56+
temperature, speed, or battery status), and send this data to
57+
AWS for analysis. By using intelligent data collection
58+
techniques, IoT FleetWise reduces the volume of data
59+
transmitted by filtering and transforming it at the edge,
60+
helping to minimize bandwidth usage and costs.
61+
62+
At its core, AWS IoT FleetWise helps organizations build
63+
scalable systems for vehicle data management and analytics,
64+
supporting a wide variety of vehicles and sensor configurations.
65+
You can define signal catalogs and decoder manifests that describe
66+
how raw CAN bus signals are translated into readable data, making
67+
the platform highly flexible and extensible. This allows
68+
manufacturers to optimize vehicle performance, improve safety,
69+
and reduce maintenance costs by gaining real-time visibility
70+
into fleet operations.
71+
""");
7172

7273
waitForInputToContinue(scanner);
7374
logger.info(DASHES);
@@ -104,15 +105,15 @@ private static void runScenario(String signalCatalogName,
104105
logger.info(DASHES);
105106
logger.info("2. Create a fleet that represents a group of vehicles");
106107
logger.info(
107-
"""
108-
Creating an IoT FleetWise fleet allows you to efficiently collect,
109-
organize, and transfer vehicle data to the cloud, enabling real-time
110-
insights into vehicle performance and health.
111-
112-
It helps reduce data costs by allowing you to filter and prioritize
113-
only the most relevant vehicle signals, supporting advanced analytics
114-
and predictive maintenance use cases.
115-
""");
108+
"""
109+
Creating an IoT FleetWise fleet allows you to efficiently collect,
110+
organize, and transfer vehicle data to the cloud, enabling real-time
111+
insights into vehicle performance and health.
112+
113+
It helps reduce data costs by allowing you to filter and prioritize
114+
only the most relevant vehicle signals, supporting advanced analytics
115+
and predictive maintenance use cases.
116+
""");
116117

117118
waitForInputToContinue(scanner);
118119
String fleetid;
@@ -262,7 +263,17 @@ Before calling createVehicle(), you must create an AWS IoT Thing
262263
logger.info(DASHES);
263264
logger.info("9. Display vehicle details");
264265
waitForInputToContinue(scanner);
265-
actions.getVehicleDetailsAsync(vecName).join();
266+
try {
267+
actions.getVehicleDetailsAsync(vecName).join();
268+
} catch (CompletionException ce) {
269+
Throwable cause = ce.getCause();
270+
if (cause instanceof ResourceNotFoundException) {
271+
logger.error("The resource was not found: {}", cause.getMessage());
272+
} else {
273+
logger.error("An unexpected error occurred.", cause);
274+
}
275+
return;
276+
}
266277
waitForInputToContinue(scanner);
267278
logger.info(DASHES);
268279

0 commit comments

Comments
 (0)