diff --git a/.doc_gen/metadata/iot_fleetwise_metadata.yaml b/.doc_gen/metadata/iot_fleetwise_metadata.yaml deleted file mode 100644 index a3dc7c6d7e2..00000000000 --- a/.doc_gen/metadata/iot_fleetwise_metadata.yaml +++ /dev/null @@ -1,399 +0,0 @@ -# zexi 0.4.0 -iotfleetwise_Hello: - title: Hello &FWlong; - title_abbrev: Hello &FW; - synopsis: get started using &FW;. - category: Hello - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.hello.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.hello.main - services: - iotfleetwise: {listSignalCatalogsPaginator} -iotfleetwise_CreateSignalCatalog: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.create.catalog.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.create.catalog.main - services: - iotfleetwise: {createSignalCatalog} -iotfleetwise_CreateDecoderManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.create.decoder.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.create.decoder.main - services: - iotfleetwise: {createDecoderManifest} -iotfleetwise_DeleteDecoderManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.delete.decoder.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.delete.decoder.main - services: - iotfleetwise: {deleteDecoderManifest} -iotfleetwise_DeleteVehicle: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.delete.vehicle.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.delete.vehicle.main - services: - iotfleetwise: {deleteVehicle} -iotfleetwise_UpdateModelManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.update.manifest.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.update.manifest.main - services: - iotfleetwise: {updateModelManifest} -iotfleetwise_UpdateDecoderManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.update.decoder.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.update.decoder.main - services: - iotfleetwise: {updateDecoderManifest} -iotfleetwise_CreateVehicle: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.create.vehicle.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.create.vehicle.main - services: - iotfleetwise: {createVehicle} -iotfleetwise_GetDecoderManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.decoder.active.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.decoder.active.main - services: - iotfleetwise: {getDecoderManifest} -iotfleetwise_GetModelManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.get.manifest.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.get.manifest.main - services: - iotfleetwise: {getModelManifest} -iotfleetwise_GetVehicle: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.get.vehicle.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.get.vehicle.main - services: - iotfleetwise: {getVehicle} -iotfleetwise_DeleteModelManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.delete.model.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.delete.model.main - services: - iotfleetwise: {deleteModelManifest} -iotfleetwise_DeleteSignalCatalog: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.delete.catalog.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.delete.catalog.main - services: - iotfleetwise: {deleteSignalCatalog} -iotfleetwise_ListSignalCatalogNodes: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.list.catalogs.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.list.catalogs.main - services: - iotfleetwise: {listSignalCatalogNodes} -iotfleetwise_CreateModelManifest: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.create.model.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.create.model.main - services: - iotfleetwise: {createModelManifest} -iotfleetwise_DeleteFleet: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.delete.fleet.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.delete.fleet.main - services: - iotfleetwise: {deleteFleet} -iotfleetwise_CreateFleet: - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - snippet_tags: - - iotfleetwise.kotlin.create.fleet.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: - snippet_tags: - - iotfleetwise.java2.create.fleet.main - services: - iotfleetwise: {createFleet} -iotfleetwise_Scenario: - synopsis_list: - - Create a collection of standardized signals. - - Create a fleet that represents a group of vehicles. - - Create a model manifest. - - Create a decoder manifest. - - Check the status of the model manifest. - - Check the status of the decoder. - - Create an IoT Thing. - - Create a vehicle. - - Display vehicle details. - - Delete the &FW; Assets. - category: Basics - languages: - Kotlin: - versions: - - sdk_version: 1 - github: kotlin/services/iotfleetwise - sdkguide: - excerpts: - - description: Run an interactive scenario demonstrating &ITSW; features. - snippet_tags: - - iotfleetwise.kotlin.scenario.main - Java: - versions: - - sdk_version: 2 - github: javav2/example_code/iotfleetwise - sdkguide: - excerpts: - - description: Run an interactive scenario demonstrating &ITSW; features. - snippet_tags: - - iotfleetwise.java2.scenario.main - - description: A wrapper class for &FW; SDK methods. - snippet_tags: - - iotfleetwise.java2.scenario.actions.main - services: - iotfleetwise: {createSignalCatalog, createFleet, createModelManifest, createDecoderManifest, getModelManifest, getDecoderManifest, createVehicle, getVehicle, updateModelManifest, updateDecoderManifest, listSignalCatalogNodes, deleteVehicle, deleteDecoderManifest, deleteModelManifest, deleteFleet, deleteSignalCatalog} diff --git a/javav2/example_code/iotfleetwise/.gitignore b/javav2/example_code/iotfleetwise/.gitignore deleted file mode 100644 index 5ff6309b719..00000000000 --- a/javav2/example_code/iotfleetwise/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/README.md b/javav2/example_code/iotfleetwise/README.md deleted file mode 100644 index 561d41c061d..00000000000 --- a/javav2/example_code/iotfleetwise/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# AWS IoT FleetWise code examples for the SDK for Java 2.x - -## Overview - -Shows how to use the AWS SDK for Java 2.x to work with AWS IoT FleetWise. - - - - -_AWS IoT FleetWise provides a secure and scalable platform for collecting, storing, and analyzing data from connected vehicles and fleets._ - -## ⚠ Important - -* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/). -* Running the tests might result in charges to your AWS account. -* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). -* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). - - - - -## Code examples - -### Prerequisites - -For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder. - - - - - -### Get started - -- [Hello AWS IoT FleetWise](src/main/java/com/example/fleetwise/HelloFleetwise.java#L12) (`listSignalCatalogsPaginator`) - - -### Basics - -Code examples that show you how to perform the essential operations within a service. - -- [Learn the basics](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.java) - - -### Single actions - -Code excerpts that show you how to call individual service functions. - -- [createDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L172) -- [createFleet](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L763) -- [createModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L680) -- [createSignalCatalog](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L61) -- [createVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L348) -- [deleteDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L252) -- [deleteFleet](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L735) -- [deleteModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L602) -- [deleteSignalCatalog](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L630) -- [deleteVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L274) -- [getDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L387) -- [getModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L456) -- [getVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L525) -- [listSignalCatalogNodes](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L658) -- [updateDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L324) -- [updateModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java#L301) - - - - - -## Run the examples - -### Instructions - - - - - -#### Hello AWS IoT FleetWise - -This example shows you how to get started using AWS IoT FleetWise. - - -#### Learn the basics - -This example shows you how to do the following: - -- Create a collection of standardized signals. -- Create a fleet that represents a group of vehicles. -- Create a model manifest. -- Create a decoder manifest. -- Check the status of the model manifest. -- Check the status of the decoder. -- Create an IoT Thing. -- Create a vehicle. -- Display vehicle details. -- Delete the AWS IoT FleetWise Assets. - - - - - - - - - -### Tests - -⚠ Running tests might result in charges to your AWS account. - - -To find instructions for running these tests, see the [README](../../README.md#Tests) -in the `javav2` folder. - - - - - - -## Additional resources - -- [AWS IoT FleetWise Developer Guide](https://docs.aws.amazon.com/iot-fleetwise/latest/developerguide/what-is-fleetwise.html) -- [AWS IoT FleetWise API Reference](https://docs.aws.amazon.com/iot-fleetwise/latest/APIReference/Welcome.html) -- [SDK for Java 2.x AWS IoT FleetWise reference](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/iotsitewise/package-summary.html) - - - - ---- - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 diff --git a/javav2/example_code/iotfleetwise/pom.xml b/javav2/example_code/iotfleetwise/pom.xml deleted file mode 100644 index a520c5e72f1..00000000000 --- a/javav2/example_code/iotfleetwise/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - 4.0.0 - org.example - iotfleetwise - 1.0-SNAPSHOT - - 21 - 21 - 21 - UTF-8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.5.2 - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${java.version} - ${java.version} - - - - - - - - software.amazon.awssdk - bom - 2.35.10 - pom - import - - - org.apache.logging.log4j - log4j-bom - 2.23.1 - pom - import - - - - - - org.junit.jupiter - junit-jupiter - 5.11.4 - test - - - software.amazon.awssdk - secretsmanager - - - software.amazon.awssdk - netty-nio-client - - - software.amazon.awssdk - iotfleetwise - - - software.amazon.awssdk - iot - - - com.google.code.gson - gson - 2.10.1 - - - software.amazon.awssdk - sso - - - software.amazon.awssdk - ssooidc - - - org.apache.logging.log4j - log4j-core - - - org.slf4j - slf4j-api - 2.0.13 - - - software.amazon.awssdk - cloudformation - - - org.apache.logging.log4j - log4j-slf4j2-impl - - - org.apache.logging.log4j - log4j-1.2-api - - - \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.java b/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.java deleted file mode 100644 index 0ac7791c1c5..00000000000 --- a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.example.fleetwise; - -import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.iotfleetwise.IoTFleetWiseClient; -import software.amazon.awssdk.services.iotfleetwise.model.*; -import software.amazon.awssdk.services.iotfleetwise.paginators.ListSignalCatalogsIterable; - -// snippet-start:[iotfleetwise.java2.hello.main] -public class HelloFleetwise { - - public static void main(String[] args) { - ListSignalCatalogs(); - } - - public static void ListSignalCatalogs() { - try (IoTFleetWiseClient fleetWiseClient = IoTFleetWiseClient.builder() - .region(Region.US_EAST_1) - .credentialsProvider(DefaultCredentialsProvider.create()) - .build()) { - - ListSignalCatalogsRequest request = ListSignalCatalogsRequest.builder() - .maxResults(10) // Optional: limit per page - .build(); - - ListSignalCatalogsIterable paginator = fleetWiseClient.listSignalCatalogsPaginator(request); - boolean found = false; - - for (ListSignalCatalogsResponse response : paginator) { - for (SignalCatalogSummary summary : response.summaries()) { - found = true; - System.out.println("Catalog Name: " + summary.name()); - System.out.println("ARN: " + summary.arn()); - System.out.println("Created: " + summary.creationTime()); - System.out.println("Last Modified: " + summary.lastModificationTime()); - System.out.println("---------------"); - } - } - - if (!found) { - System.out.println("No AWS Fleetwise Signal Catalogs were found."); - } - - } catch (IoTFleetWiseException e) { - System.err.println("Error listing signal catalogs: " + e.awsErrorDetails().errorMessage()); - throw new RuntimeException(e); - } - } - } -// snippet-end:[iotfleetwise.java2.hello.main] \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java b/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java deleted file mode 100644 index 587d51e26f0..00000000000 --- a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseActions.java +++ /dev/null @@ -1,799 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.example.fleetwise.scenario; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; -import software.amazon.awssdk.core.retry.RetryMode; -import software.amazon.awssdk.http.async.SdkAsyncHttpClient; -import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.iot.IotAsyncClient; -import software.amazon.awssdk.services.iot.model.CreateThingRequest; -import software.amazon.awssdk.services.iot.model.ResourceAlreadyExistsException; -import software.amazon.awssdk.services.iotfleetwise.IoTFleetWiseAsyncClient; -import software.amazon.awssdk.services.iotfleetwise.model.Node; -import software.amazon.awssdk.services.iotfleetwise.model.*; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -// snippet-start:[iotfleetwise.java2.scenario.actions.main] -public class FleetwiseActions { - private static final Logger logger = LoggerFactory.getLogger(FleetwiseActions.class); - private static IoTFleetWiseAsyncClient ioTFleetWiseAsyncClient; - - private static IoTFleetWiseAsyncClient getAsyncClient() { - if (ioTFleetWiseAsyncClient == null) { - SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder() - .maxConcurrency(100) - .connectionTimeout(Duration.ofSeconds(60)) - .readTimeout(Duration.ofSeconds(60)) - .writeTimeout(Duration.ofSeconds(60)) - .build(); - - ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder() - .apiCallTimeout(Duration.ofMinutes(2)) - .apiCallAttemptTimeout(Duration.ofSeconds(90)) - .retryStrategy(RetryMode.STANDARD) - .build(); - - ioTFleetWiseAsyncClient = IoTFleetWiseAsyncClient.builder() - .httpClient(httpClient) - .overrideConfiguration(overrideConfig) - .build(); - } - return ioTFleetWiseAsyncClient; - } - - // snippet-start:[iotfleetwise.java2.create.catalog.main] - - /** - * Creates a signal catalog. - * - * @param signalCatalogName the name of the signal catalog to be created - * @return a {@link CompletableFuture} that completes with the Amazon Resource Name (ARN) of the created signal catalog - */ - public CompletableFuture createSignalCatalogAsync(String signalCatalogName) { - return deleteSignalCatalogIfExistsAsync(signalCatalogName) - .thenCompose(ignored -> delayAsync(2000)) // Wait for 2 seconds - .thenCompose(ignored -> { - List nodes = List.of( - Node.builder().branch( - Branch.builder() - .fullyQualifiedName("Vehicle") - .description("Root branch") - .build() - ).build(), - Node.builder().branch( - Branch.builder() - .fullyQualifiedName("Vehicle.Powertrain") - .description("Powertrain branch") - .build() - ).build(), - Node.builder().sensor( - Sensor.builder() - .fullyQualifiedName("Vehicle.Powertrain.EngineRPM") - .description("Engine RPM") - .dataType(NodeDataType.DOUBLE) - .unit("rpm") - .build() - ).build(), - Node.builder().sensor( - Sensor.builder() - .fullyQualifiedName("Vehicle.Powertrain.VehicleSpeed") - .description("Vehicle Speed") - .dataType(NodeDataType.DOUBLE) - .unit("km/h") - .build() - ).build() - ); - - CreateSignalCatalogRequest request = CreateSignalCatalogRequest.builder() - .name(signalCatalogName) - .nodes(nodes) - .build(); - - CompletableFuture result = new CompletableFuture<>(); - - getAsyncClient().createSignalCatalog(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - - if (cause instanceof ValidationException) { - result.completeExceptionally(cause); - } else { - result.completeExceptionally(new RuntimeException("Error creating the catalog", cause)); - } - } else { - result.complete(response.arn()); - } - }); - - return result; - }); - } - // snippet-end:[iotfleetwise.java2.create.catalog.main] - - /** - * Delays the execution of the current thread asynchronously for the specified duration. - * - * @param millis the duration of the delay in milliseconds - * @return a {@link CompletableFuture} that completes after the specified delay - */ - private static CompletableFuture delayAsync(long millis) { - return CompletableFuture.runAsync(() -> { - try { - Thread.sleep(millis); - } catch (InterruptedException e) { - throw new CompletionException("Sleep interrupted", e); - } - }); - } - - /** - * Deletes the specified signal catalog. - * - * @param signalCatalogName the name of the signal catalog to delete - * @return a {@link CompletableFuture} representing the asynchronous operation. - */ - public static CompletableFuture deleteSignalCatalogIfExistsAsync(String signalCatalogName) { - DeleteSignalCatalogRequest request = DeleteSignalCatalogRequest.builder() - .name(signalCatalogName) - .build(); - - return getAsyncClient().deleteSignalCatalog(request) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw new CompletionException(new RuntimeException("Signal Catalog not found: " + signalCatalogName)); - } - throw new RuntimeException("Failed to delete signal catalog: " + signalCatalogName, cause); - } - return null; - }); - } - - - // snippet-start:[iotfleetwise.java2.create.decoder.main] - /** - * Creates a new decoder manifest. - * - * @param name the name of the decoder manifest - * @param modelManifestArn the ARN of the model manifest - * @return a {@link CompletableFuture} that completes with the ARN of the created decoder manifest - */ - public CompletableFuture createDecoderManifestAsync(String name, String modelManifestArn) { - String interfaceId = "can0"; - NetworkInterface networkInterface = NetworkInterface.builder() - .interfaceId(interfaceId) - .type(NetworkInterfaceType.CAN_INTERFACE) - .canInterface(CanInterface.builder() - .name("canInterface0") - .protocolName("CAN") - .protocolVersion("1.0") - .build()) - .build(); - - // Vehicle.Powertrain.EngineRPM decoder. - SignalDecoder engineRpmDecoder = SignalDecoder.builder() - .fullyQualifiedName("Vehicle.Powertrain.EngineRPM") - .interfaceId(interfaceId) - .type(SignalDecoderType.CAN_SIGNAL) - .canSignal(CanSignal.builder() - .messageId(100) - .isBigEndian(false) - .isSigned(false) - .startBit(0) - .length(16) - .factor(1.0) - .offset(0.0) - .build()) - .build(); - - // Vehicle.Powertrain.VehicleSpeed decoder. - SignalDecoder vehicleSpeedDecoder = SignalDecoder.builder() - .fullyQualifiedName("Vehicle.Powertrain.VehicleSpeed") - .interfaceId(interfaceId) - .type(SignalDecoderType.CAN_SIGNAL) - .canSignal(CanSignal.builder() - .messageId(101) - .isBigEndian(false) - .isSigned(false) - .startBit(16) - .length(16) - .factor(1.0) - .offset(0.0) - .build()) - .build(); - - CreateDecoderManifestRequest request = CreateDecoderManifestRequest.builder() - .name(name) - .modelManifestArn(modelManifestArn) - .networkInterfaces(List.of(networkInterface)) - .signalDecoders(List.of(engineRpmDecoder, vehicleSpeedDecoder)) - .build(); - - CompletableFuture result = new CompletableFuture<>(); - - getAsyncClient().createDecoderManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - - if (cause instanceof DecoderManifestValidationException) { - result.completeExceptionally(new CompletionException("The request contains signal decoders with validation errors: " + cause.getMessage(), cause)); - } else { - result.completeExceptionally(new CompletionException("Failed to create decoder manifest: " + exception.getMessage(), exception)); - } - } else { - result.complete(response.arn()); // Complete successfully with the ARN - } - }); - - return result; - } - // snippet-end:[iotfleetwise.java2.create.decoder.main] - - // snippet-start:[iotfleetwise.java2.delete.decoder.main] - /** - * Deletes a decoder manifest. - * - * @param name the name of the decoder manifest to delete - * @return a {@link CompletableFuture} that completes when the decoder manifest has been deleted - */ - public CompletableFuture deleteDecoderManifestAsync(String name) { - return getAsyncClient().deleteDecoderManifest(DeleteDecoderManifestRequest.builder().name(name).build()) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw (ResourceNotFoundException) cause; - } - throw new RuntimeException("Failed to delete the decoder manifest: " + cause); - } - return null; - }); - } - // snippet-end:[iotfleetwise.java2.delete.decoder.main] - - // snippet-start:[iotfleetwise.java2.delete.vehicle.main] - - /** - * Deletes a vehicle with the specified name. - * - * @param vecName the name of the vehicle to be deleted - * @return a {@link CompletableFuture} that completes when the vehicle has been deleted - */ - public CompletableFuture deleteVehicleAsync(String vecName) { - DeleteVehicleRequest request = DeleteVehicleRequest.builder() - .vehicleName(vecName) - .build(); - - return getAsyncClient().deleteVehicle(request) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw (ResourceNotFoundException) cause; - } - throw new RuntimeException("Failed to delete the vehicle: " + cause); - } - return null; - }); - } - // snippet-end:[iotfleetwise.java2.delete.vehicle.main] - - // snippet-start:[iotfleetwise.java2.update.manifest.main] - - /** - * Updates the model manifest. - * - * @param name the name of the model manifest to update - */ - public void updateModelManifestAsync(String name) { - UpdateModelManifestRequest request = UpdateModelManifestRequest.builder() - .name(name) - .status(ManifestStatus.ACTIVE) - .build(); - - getAsyncClient().updateModelManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - throw new CompletionException("Failed to update model manifest: " + exception.getMessage(), exception); - } - }) - .thenApply(response -> null); - } - // snippet-end:[iotfleetwise.java2.update.manifest.main] - - // snippet-start:[iotfleetwise.java2.update.decoder.main] - - /** - * Updates the decoder manifest with the given name. - * - * @param name the name of the decoder manifest to update - * @return a {@link CompletableFuture} that completes when the update operation is finished - */ - public CompletableFuture updateDecoderManifestAsync(String name) { - UpdateDecoderManifestRequest request = UpdateDecoderManifestRequest.builder() - .name(name) - .status(ManifestStatus.ACTIVE) - .build(); - - return getAsyncClient().updateDecoderManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - throw new CompletionException("Failed to update decoder manifest: " + exception.getMessage(), exception); - } - }) - .thenApply(response -> null); - } - // snippet-end:[iotfleetwise.java2.update.decoder.main] - - // snippet-start:[iotfleetwise.java2.create.vehicle.main] - - /** - * Creates a new vehicle in the system. - * - * @param vecName the name of the vehicle to be created - * @param manifestArn the Amazon Resource Name (ARN) of the model manifest for the vehicle - * @param decArn the Amazon Resource Name (ARN) of the decoder manifest for the vehicle - * @return a {@link CompletableFuture} that completes when the vehicle has been created, or throws a - */ - public CompletableFuture createVehicleAsync(String vecName, String manifestArn, String decArn) { - CreateVehicleRequest request = CreateVehicleRequest.builder() - .vehicleName(vecName) - .modelManifestArn(manifestArn) - .decoderManifestArn(decArn) - .build(); - - CompletableFuture result = new CompletableFuture<>(); - getAsyncClient().createVehicle(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception; - - if (cause instanceof ResourceNotFoundException) { - result.completeExceptionally(cause); - } else { - result.completeExceptionally(new RuntimeException("Failed to create vehicle: " + cause.getMessage(), cause)); - } - } else { - logger.info("Vehicle '{}' created successfully.", vecName); - result.complete(null); // mark future as complete - } - }); - - return result; - } - - // snippet-end:[iotfleetwise.java2.create.vehicle.main] - - // snippet-start:[iotfleetwise.java2.decoder.active.main] - /** - * Waits for the decoder manifest to become active. - * - * @param decoderName the name of the decoder to wait for - * @return a {@link CompletableFuture} that completes when the decoder manifest becomes active, or exceptionally if an error occurs or the manifest becomes invalid - */ - public CompletableFuture waitForDecoderManifestActiveAsync(String decoderName) { - CompletableFuture result = new CompletableFuture<>(); - - ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); - AtomicInteger secondsElapsed = new AtomicInteger(0); - AtomicReference lastStatus = new AtomicReference<>(ManifestStatus.DRAFT); - - logger.info(" Elapsed: 0s | Decoder Status: DRAFT"); - - final Runnable pollTask = new Runnable() { - @Override - public void run() { - int elapsed = secondsElapsed.incrementAndGet(); - - // Check status every 5 seconds - if (elapsed % 5 == 0) { - GetDecoderManifestRequest request = GetDecoderManifestRequest.builder() - .name(decoderName) - .build(); - - getAsyncClient().getDecoderManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception; - - scheduler.shutdown(); - if (cause instanceof ResourceNotFoundException) { - result.completeExceptionally(new RuntimeException("Decoder manifest not found: " + cause.getMessage(), cause)); - } else { - result.completeExceptionally(new RuntimeException("Error while polling decoder manifest status: " + exception.getMessage(), exception)); - } - return; - } - - ManifestStatus status = response.status(); - lastStatus.set(status); - - if (status == ManifestStatus.ACTIVE) { - logger.info("\r Elapsed: {}s | Decoder Status: ACTIVE", elapsed); - scheduler.shutdown(); - result.complete(null); - } else if (status == ManifestStatus.INVALID) { - logger.info("\r Elapsed: {}s | Decoder Status: INVALID", elapsed); - scheduler.shutdown(); - result.completeExceptionally(new RuntimeException("Decoder manifest became INVALID. Cannot proceed.")); - } else { - logger.info("\r⏱ Elapsed: {}s | Decoder Status: {}", elapsed, status); - } - }); - } else { - logger.info("\r Elapsed: {}s | Decoder Status: {}", elapsed, lastStatus.get()); - } - } - }; - - // Start the task with an initial delay of 1 second, and repeat every second - scheduler.scheduleAtFixedRate(pollTask, 1, 1, TimeUnit.SECONDS); - return result; - } - - // snippet-end:[iotfleetwise.java2.decoder.active.main] - - // snippet-start:[iotfleetwise.java2.get.manifest.main] - - /** - * Waits for the specified model manifest to become active. - * - * @param manifestName the name of the model manifest to wait for - */ - public CompletableFuture waitForModelManifestActiveAsync(String manifestName) { - CompletableFuture result = new CompletableFuture<>(); - - ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); - AtomicInteger secondsElapsed = new AtomicInteger(0); - AtomicReference lastStatus = new AtomicReference<>(ManifestStatus.DRAFT); - - logger.info("Elapsed: 0s | Status: DRAFT"); - - final Runnable pollTask = new Runnable() { - @Override - public void run() { - int elapsed = secondsElapsed.incrementAndGet(); - - // Only check status every 5 seconds - if (elapsed % 5 == 0) { - GetModelManifestRequest request = GetModelManifestRequest.builder() - .name(manifestName) - .build(); - - getAsyncClient().getModelManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception; - - scheduler.shutdown(); - if (cause instanceof ResourceNotFoundException) { - result.completeExceptionally(new RuntimeException("Model manifest not found: " + cause.getMessage(), cause)); - } else { - result.completeExceptionally(new RuntimeException("Error while polling model manifest status: " + exception.getMessage(), exception)); - } - return; - } - - ManifestStatus status = response.status(); - lastStatus.set(status); - - if (status == ManifestStatus.ACTIVE) { - logger.info("\rElapsed: {}s | Status: ACTIVE", elapsed); - scheduler.shutdown(); - result.complete(null); - } else if (status == ManifestStatus.INVALID) { - logger.info("\rElapsed: {}s | Status: INVALID", elapsed); - scheduler.shutdown(); - result.completeExceptionally(new RuntimeException("Model manifest became INVALID. Cannot proceed.")); - } else { - logger.info("\rElapsed: {}s | Status: {}", elapsed, status); - } - }); - } else { - logger.info("\rElapsed: {}s | Status: {}", elapsed, lastStatus.get()); - } - } - }; - - // Start the task with an initial delay of 1 second, and repeat every second - scheduler.scheduleAtFixedRate(pollTask, 1, 1, TimeUnit.SECONDS); - return result; - } - - // snippet-end:[iotfleetwise.java2.get.manifest.main] - - // snippet-start:[iotfleetwise.java2.get.vehicle.main] - - /** - * Fetches the details of a vehicle. - * - * @param vehicleName the name of the vehicle to fetch details for - * @return a {@link CompletableFuture} that completes when the vehicle details have been fetched - */ - public CompletableFuture getVehicleDetailsAsync(String vehicleName) { - GetVehicleRequest request = GetVehicleRequest.builder() - .vehicleName(vehicleName) - .build(); - - CompletableFuture result = new CompletableFuture<>(); - - getAsyncClient().getVehicle(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception instanceof CompletionException ? exception.getCause() : exception; - - if (cause instanceof ResourceNotFoundException) { - result.completeExceptionally(cause); // don't rewrap - } else { - result.completeExceptionally(new RuntimeException("Failed to fetch vehicle details: " + cause.getMessage(), cause)); - } - } else { - Map details = new HashMap<>(); - details.put("vehicleName", response.vehicleName()); - details.put("arn", response.arn()); - details.put("modelManifestArn", response.modelManifestArn()); - details.put("decoderManifestArn", response.decoderManifestArn()); - details.put("attributes", response.attributes()); - details.put("creationTime", response.creationTime().toString()); - details.put("lastModificationTime", response.lastModificationTime().toString()); - - logger.info("Vehicle Details:"); - details.forEach((key, value) -> logger.info("• {} : {}", key, value)); - - result.complete(null); // mark as successful - } - }); - - return result; - } - - // snippet-end:[iotfleetwise.java2.get.vehicle.main] - - /** - * Creates an IoT Thing if it does not already exist. - * - * @param thingName the name of the IoT Thing to create - * @return a {@link CompletableFuture} that completes when the IoT Thing has been created or if it already exists - */ - public CompletableFuture createThingIfNotExistsAsync(String thingName) { - IotAsyncClient iotClient = IotAsyncClient.builder() - .region(Region.US_EAST_1) - .build(); - - CreateThingRequest request = CreateThingRequest.builder() - .thingName(thingName) - .build(); - - return iotClient.createThing(request) - .whenComplete((response, exception) -> { - if (exception != null) { - if (exception instanceof ResourceAlreadyExistsException) { - logger.info(" IoT Thing already exists: " + thingName); - } else { - throw new CompletionException("Failed to create IoT Thing: " + thingName, exception); - } - } else { - logger.info("IoT Thing created: " + response.thingName()); - } - }) - .thenApply(response -> null); - } - - // snippet-start:[iotfleetwise.java2.delete.model.main] - - /** - * Deletes a model manifest. - * - * @param name the name of the model manifest to delete - * @return a {@link CompletableFuture} that completes when the model manifest has been deleted - */ - public CompletableFuture deleteModelManifestAsync(String name) { - DeleteModelManifestRequest request = DeleteModelManifestRequest.builder() - .name(name) - .build(); - - return getAsyncClient().deleteModelManifest(request) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw (ResourceNotFoundException) cause; - } - throw new RuntimeException("Failed to delete the model manifest: " + cause); - } - logger.info("{} was successfully deleted", name); - return null; - }); - } - // snippet-end:[iotfleetwise.java2.delete.model.main] - - // snippet-start:[iotfleetwise.java2.delete.catalog.main] - - /** - * Deletes a signal catalog. - * - * @param name the name of the signal catalog to delete - * @return a {@link CompletableFuture} that completes when the signal catalog is deleted - */ - public CompletableFuture deleteSignalCatalogAsync(String name) { - DeleteSignalCatalogRequest request = DeleteSignalCatalogRequest.builder() - .name(name) - .build(); - - return getAsyncClient().deleteSignalCatalog(request) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw (ResourceNotFoundException) cause; - } - throw new RuntimeException("Failed to delete the signal catalog: " + cause); - } - logger.info("{} was successfully deleted", name); - return null; - }); - } - // snippet-end:[iotfleetwise.java2.delete.catalog.main] - - // snippet-start:[iotfleetwise.java2.list.catalogs.main] - /** - * Asynchronously retrieves a list of all nodes in the specified signal catalog. - * - * @param signalCatalogName the name of the signal catalog to retrieve nodes for - * @return a {@link CompletableFuture} that, when completed, contains a {@link List} of {@link Node} objects - * representing all the nodes in the specified signal catalog - */ - public CompletableFuture> listSignalCatalogNodeAsync(String signalCatalogName) { - ListSignalCatalogNodesRequest request = ListSignalCatalogNodesRequest.builder() - .name(signalCatalogName) - .build(); - - List allNodes = new ArrayList<>(); - - return getAsyncClient().listSignalCatalogNodesPaginator(request) - .subscribe(response -> allNodes.addAll(response.nodes())) - .thenApply(v -> allNodes); - } - - // snippet-end:[iotfleetwise.java2.list.catalogs.main] - - // snippet-start:[iotfleetwise.java2.create.model.main] - - /** - * Creates a model manifest. - * - * @param name the name of the model manifest to create - * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog - * @param nodes a list of nodes to include in the model manifest - * @return a {@link CompletableFuture} that completes with the ARN of the created model manifest - */ - public CompletableFuture createModelManifestAsync(String name, - String signalCatalogArn, - List nodes) { - // Extract the fully qualified names (FQNs) from each Node in the provided list. - List fqnList = nodes.stream() - .map(node -> { - if (node.sensor() != null) { - return node.sensor().fullyQualifiedName(); - } else if (node.branch() != null) { - return node.branch().fullyQualifiedName(); - } else if (node.attribute() != null) { - return node.attribute().fullyQualifiedName(); - } else { - throw new RuntimeException("Unsupported node type"); - } - }) - .toList(); - - CreateModelManifestRequest request = CreateModelManifestRequest.builder() - .name(name) - .signalCatalogArn(signalCatalogArn) - .nodes(fqnList) - .build(); - - - CompletableFuture result = new CompletableFuture<>(); - getAsyncClient().createModelManifest(request) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - - if (cause instanceof InvalidSignalsException) { - result.completeExceptionally(new CompletionException("The request contains signals that aren't valid: " + cause.getMessage(), cause)); - } else { - result.completeExceptionally(new CompletionException("Failed to create model manifest: " + exception.getMessage(), exception)); - } - } else { - result.complete(response.arn()); // Complete successfully with the ARN - } - }); - - return result; - } - // snippet-end:[iotfleetwise.java2.create.model.main] - - // snippet-start:[iotfleetwise.java2.delete.fleet.main] - - /** - * Deletes a fleet based on the provided fleet ID. - * - * @param fleetId the ID of the fleet to be deleted - */ - public CompletableFuture deleteFleetAsync(String fleetId) { - DeleteFleetRequest request = DeleteFleetRequest.builder() - .fleetId(fleetId) - .build(); - - return getAsyncClient().deleteFleet(request) - .handle((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - if (cause instanceof ResourceNotFoundException) { - throw (ResourceNotFoundException) cause; - } - throw new RuntimeException("Failed to delete the fleet: " + cause); - } - logger.info("{} was successfully deleted", fleetId); - return null; - }); - } - // snippet-end:[iotfleetwise.java2.delete.fleet.main] - - - // snippet-start:[iotfleetwise.java2.create.fleet.main] - - /** - * Creates a new fleet. - * - * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet - * @param fleetId the unique identifier for the fleet - * @return a {@link CompletableFuture} that completes with the ID of the created fleet - */ - public CompletableFuture createFleetAsync(String catARN, String fleetId) { - CreateFleetRequest fleetRequest = CreateFleetRequest.builder() - .fleetId(fleetId) - .signalCatalogArn(catARN) - .description("Built using the AWS For Java V2") - .build(); - - CompletableFuture result = new CompletableFuture<>(); - getAsyncClient().createFleet(fleetRequest) - .whenComplete((response, exception) -> { - if (exception != null) { - Throwable cause = exception.getCause() != null ? exception.getCause() : exception; - - if (cause instanceof ResourceNotFoundException) { - result.completeExceptionally(cause); - } else { - result.completeExceptionally(new RuntimeException("An unexpected error occurred", cause)); - } - } else { - result.complete(response.id()); - } - }); - - return result; - } - // snippet-end:[iotfleetwise.java2.create.fleet.main] -} -// snippet-end:[iotfleetwise.java2.scenario.actions.main] \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.java b/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.java deleted file mode 100644 index 52d18e8363a..00000000000 --- a/javav2/example_code/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.java +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.example.fleetwise.scenario; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.services.iot.model.ResourceAlreadyExistsException; -import software.amazon.awssdk.services.iotfleetwise.model.Node; -import software.amazon.awssdk.services.iotfleetwise.model.ResourceNotFoundException; -import software.amazon.awssdk.services.iotfleetwise.model.ValidationException; - -import java.util.List; -import java.util.Scanner; -import java.util.concurrent.CompletionException; - -// snippet-start:[iotfleetwise.java2.scenario.main] -public class FleetwiseScenario { - public static final String DASHES = new String(new char[80]).replace("\0", "-"); - static FleetwiseActions actions = new FleetwiseActions(); - private static final Logger logger = LoggerFactory.getLogger(FleetwiseScenario.class); - static Scanner scanner = new Scanner(System.in); - - public static void main(String[] args) { - final String usage = - """ - Usage: - - - Where: - signalCatalogName - The name of the Signal Catalog to create (eg, catalog30). - manifestName - The name of the Vehicle Model (Model Manifest) to create (eg, manifest30). - fleetId - The ID of the Fleet to create (eg, fleet30). - vecName - The name of the Vehicle to create (eg, vehicle30). - decName - The name of the Decoder Manifest to create (eg, decManifest30). - """; - - if (args.length != 5) { - logger.info(usage); - return; - } - - String signalCatalogName = args[0]; - String manifestName = args[1]; - String fleetId = args[2]; - String vecName = args[3]; - String decName = args[4]; - - logger.info( - """ - AWS IoT FleetWise is a managed service that simplifies the - process of collecting, organizing, and transmitting vehicle - data to the cloud in near real-time. Designed for automakers - and fleet operators, it allows you to define vehicle models, - specify the exact data you want to collect (such as engine - temperature, speed, or battery status), and send this data to - AWS for analysis. By using intelligent data collection - techniques, IoT FleetWise reduces the volume of data - transmitted by filtering and transforming it at the edge, - helping to minimize bandwidth usage and costs. - - At its core, AWS IoT FleetWise helps organizations build - scalable systems for vehicle data management and analytics, - supporting a wide variety of vehicles and sensor configurations. - You can define signal catalogs and decoder manifests that describe - how raw CAN bus signals are translated into readable data, making - the platform highly flexible and extensible. This allows - manufacturers to optimize vehicle performance, improve safety, - and reduce maintenance costs by gaining real-time visibility - into fleet operations. - """); - - waitForInputToContinue(scanner); - logger.info(DASHES); - try { - runScenario(signalCatalogName, manifestName, fleetId, vecName, decName); - } catch (RuntimeException e) { - logger.info(e.getMessage()); - } - } - - private static void runScenario(String signalCatalogName, - String manifestName, - String fleetId, - String vecName, - String decName) { - logger.info(DASHES); - logger.info("1. Creates a collection of standardized signals that can be reused to create vehicle models"); - String signalCatalogArn; - try { - signalCatalogArn = actions.createSignalCatalogAsync(signalCatalogName).join(); - logger.info("The collection ARN is " + signalCatalogArn); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - if (cause instanceof ValidationException) { - logger.error("The request failed due to a validation issue: {}", cause.getMessage()); - } else { - logger.error("An unexpected error occurred.", cause); - } - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("2. Create a fleet that represents a group of vehicles"); - logger.info( - """ - Creating an IoT FleetWise fleet allows you to efficiently collect, - organize, and transfer vehicle data to the cloud, enabling real-time - insights into vehicle performance and health. - - It helps reduce data costs by allowing you to filter and prioritize - only the most relevant vehicle signals, supporting advanced analytics - and predictive maintenance use cases. - """); - - waitForInputToContinue(scanner); - String fleetid; - try { - fleetid = actions.createFleetAsync(signalCatalogArn, fleetId).join(); - logger.info("The fleet Id is " + fleetid); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - if (cause instanceof ResourceNotFoundException) { - logger.error("The resource was not found: {}", cause.getMessage()); - } else { - logger.error("An unexpected error occurred.", cause); - } - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("3. Create a model manifest"); - logger.info( - """ - An AWS IoT FleetWise manifest defines the structure and - relationships of vehicle data. The model manifest specifies - which signals to collect and how they relate to vehicle systems, - while the decoder manifest defines how to decode raw vehicle data - into meaningful signals. - """); - waitForInputToContinue(scanner); - String manifestArn; - try { - List nodes = actions.listSignalCatalogNodeAsync(signalCatalogName).join(); - manifestArn = actions.createModelManifestAsync(manifestName, signalCatalogArn, nodes).join(); - logger.info("The manifest ARN is {}", manifestArn); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - logger.error("An unexpected error occurred.", cause); - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("4. Create a decoder manifest"); - logger.info( - """ - A decoder manifest in AWS IoT FleetWise defines how raw vehicle - data (such as CAN signals) should be interpreted and decoded - into meaningful signals. It acts as a translation layer - that maps vehicle-specific protocols to standardized data formats - using decoding rules. This is crucial for extracting usable - data from different vehicle models, even when their data - formats vary. - - """); - waitForInputToContinue(scanner); - String decArn; - try { - decArn = actions.createDecoderManifestAsync(decName, manifestArn).join(); - logger.info("The decoder manifest ARN is {}", decArn); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - logger.error("An unexpected error occurred.", cause); - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info("5. Check the status of the model manifest"); - logger.info( - """ - The model manifest must be in an ACTIVE state before it can be used - to create or update a vehicle. - """); - waitForInputToContinue(scanner); - try { - actions.updateModelManifestAsync(manifestName); - actions.waitForModelManifestActiveAsync(manifestName).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - logger.error("An unexpected error occurred while waiting for the model manifest status.", cause); - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info("6. Check the status of the decoder"); - logger.info( - """ - The decoder manifest must be in an ACTIVE state before it can be used - to create or update a vehicle. - """); - waitForInputToContinue(scanner); - try { - actions.updateDecoderManifestAsync(decName); - actions.waitForDecoderManifestActiveAsync(decName).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - logger.error("An unexpected error occurred while waiting for the decoder manifest status.", cause); - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("7. Create an IoT Thing"); - logger.info( - """ - AWS IoT FleetWise expects an existing AWS IoT Thing with the same - name as the vehicle name you are passing to createVehicle method. - Before calling createVehicle(), you must create an AWS IoT Thing - with the same name using the AWS IoT Core service. - """); - waitForInputToContinue(scanner); - try { - actions.createThingIfNotExistsAsync(vecName).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - if (cause instanceof ResourceAlreadyExistsException) { - logger.error("The resource exists: {}", cause.getMessage()); - } else { - logger.error("An unexpected error occurred.", cause); - return; - } - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("8. Create a vehicle"); - logger.info( - """ - Creating a vehicle in AWS IoT FleetWise allows you to digitally - represent and manage a physical vehicle within the AWS ecosystem. - This enables efficient ingestion, transformation, and transmission - of vehicle telemetry data to the cloud for analysis. - """); - waitForInputToContinue(scanner); - try { - actions.createVehicleAsync(vecName, manifestArn, decArn).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - - if (cause instanceof ResourceNotFoundException) { - logger.error("The required resource was not found: {}", cause.getMessage()); - } else { - logger.error("An unexpected error occurred while creating vehicle.", cause); - } - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("9. Display vehicle details"); - waitForInputToContinue(scanner); - try { - actions.getVehicleDetailsAsync(vecName).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - if (cause instanceof ResourceNotFoundException) { - logger.error("The resource was not found: {}", cause.getMessage()); - } else { - logger.error("An unexpected error occurred.", cause); - } - return; - } - waitForInputToContinue(scanner); - logger.info(DASHES); - - logger.info(DASHES); - logger.info("10. Delete the AWS IoT Fleetwise Assets"); - logger.info("Would you like to delete the IoT Fleetwise Assets? (y/n)"); - String delAns = scanner.nextLine().trim(); - if (delAns.equalsIgnoreCase("y")) { - try { - actions.deleteVehicleAsync(vecName).join(); - actions.deleteDecoderManifestAsync(decName).join(); - actions.deleteModelManifestAsync(manifestName).join(); - actions.deleteFleetAsync(fleetid).join(); - actions.deleteSignalCatalogAsync(signalCatalogName).join(); - } catch (CompletionException ce) { - Throwable cause = ce.getCause(); - if (cause instanceof ResourceNotFoundException) { - // Handle the case where the resource is not found. - logger.error("The resource was not found: {}", cause.getMessage()); - } else if (cause instanceof RuntimeException) { - // Handle other runtime exceptions. - logger.error("An unexpected error occurred: {}", cause.getMessage()); - } else { - // Catch any other unexpected exceptions. - logger.error("An unknown error occurred.", cause); - } - return; - } - - logger.info(DASHES); - logger.info( - """ - Thank you for checking out the AWS IoT Fleetwise Service Use demo. We hope you - learned something new, or got some inspiration for your own apps today. - For more AWS code examples, have a look at: - https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html - """); - logger.info(DASHES); - } else { - logger.info("The AWS resources will not be deleted."); - } - } - - private static void waitForInputToContinue(Scanner scanner) { - while (true) { - logger.info(""); - logger.info("Enter 'c' followed by to continue:"); - String input = scanner.nextLine(); - - if (input.trim().equalsIgnoreCase("c")) { - logger.info("Continuing with the program..."); - logger.info(""); - break; - } else { - logger.info("Invalid input. Please try again."); - } - } - } -} -// snippet-end:[iotfleetwise.java2.scenario.main] \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/src/main/resources/log4j2.xml b/javav2/example_code/iotfleetwise/src/main/resources/log4j2.xml deleted file mode 100644 index 914470047e7..00000000000 --- a/javav2/example_code/iotfleetwise/src/main/resources/log4j2.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/javav2/example_code/iotfleetwise/src/test/java/FleetwiseTest.java b/javav2/example_code/iotfleetwise/src/test/java/FleetwiseTest.java deleted file mode 100644 index 7553d3d6d79..00000000000 --- a/javav2/example_code/iotfleetwise/src/test/java/FleetwiseTest.java +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import com.example.fleetwise.HelloFleetwise; -import com.example.fleetwise.scenario.FleetwiseActions; -import org.junit.jupiter.api.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import software.amazon.awssdk.services.iotfleetwise.model.Node; -import java.util.List; -import static org.junit.jupiter.api.Assertions.*; - -@TestInstance(TestInstance.Lifecycle.PER_METHOD) -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class FleetwiseTest { - private static final Logger logger = LoggerFactory.getLogger(FleetwiseTest.class); - private static String signalCatalogName = "catalogtest"; - private static String manifestName = "manifesttest"; - private static String fleetId = "fleettest"; - private static String vecName = "vehicletest"; - private static String decName = "decManifesttest"; - private static String signalCatalogArn = "" ; - private static String fleetid = "" ; - private static String manifestArn = ""; - private static String decArn = ""; - static FleetwiseActions actions = new FleetwiseActions(); - - @Test - @Tag("IntegrationTest") - @Order(1) - public void testHelloService() { - assertDoesNotThrow(HelloFleetwise::ListSignalCatalogs); - logger.info("Test 1 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(2) - public void testCreateCollection() { - assertDoesNotThrow(() -> { - signalCatalogArn = actions.createSignalCatalogAsync(signalCatalogName).join(); - assertTrue(signalCatalogArn.startsWith("arn:"), "The ARN should start with 'arn:'"); - }); - logger.info("Test 2 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(3) - public void testCreateFleet() { - assertDoesNotThrow(() -> { - fleetid = actions.createFleetAsync(signalCatalogArn, fleetId).join();; - assertNotNull(fleetid, "The returned fleet ID should not be null"); - }); - logger.info("Test 3 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(4) - public void testCreateManifest() { - assertDoesNotThrow(() -> { - List nodes = actions.listSignalCatalogNodeAsync(signalCatalogName).join(); - assertNotNull(nodes, "The returned node list should not be null"); - manifestArn = actions.createModelManifestAsync(manifestName,signalCatalogArn,nodes).join();; - assertNotNull(manifestArn, "The returned manifest Arn should not be null"); - }); - logger.info("Test 4 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(5) - public void testCreateDecoder() { - assertDoesNotThrow(() -> { - decArn = actions.createDecoderManifestAsync(decName ,manifestArn).join(); - assertNotNull(decArn, "The returned decoder should not be null"); - }); - logger.info("Test 5 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(6) - public void testModelStatus() { - assertDoesNotThrow(() -> { - actions.updateModelManifestAsync(manifestName); - actions.waitForModelManifestActiveAsync(manifestName).join(); - }); - logger.info("Test 6 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(7) - public void testMDecoderStatus() { - assertDoesNotThrow(() -> { - actions.updateDecoderManifestAsync(decName); - actions.waitForDecoderManifestActiveAsync(decName).join() ; - }); - logger.info("Test 7 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(8) - public void testCreateThing() { - assertDoesNotThrow(() -> { - actions.createThingIfNotExistsAsync(vecName).join(); - }); - logger.info("Test 8 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(9) - public void testCreateVehicle() { - assertDoesNotThrow(() -> { - actions.createVehicleAsync(vecName, manifestArn,decArn).join(); - }); - logger.info("Test 9 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(10) - public void testGetVehicle() { - assertDoesNotThrow(() -> { - actions.getVehicleDetailsAsync(vecName).join(); - }); - logger.info("Test 10 passed"); - } - - @Test - @Tag("IntegrationTest") - @Order(11) - public void testGDeleteResources() { - assertDoesNotThrow(() -> { - actions.deleteVehicleAsync(vecName).join(); - actions.deleteDecoderManifestAsync(decName).join(); - actions.deleteModelManifestAsync(manifestName).join(); - actions.deleteFleetAsync(fleetid).join(); - actions.deleteSignalCatalogAsync(signalCatalogName).join(); - }); - logger.info("Test 11 passed"); - } -} diff --git a/kotlin/services/iotfleetwise/README.md b/kotlin/services/iotfleetwise/README.md deleted file mode 100644 index 8b73b432b5f..00000000000 --- a/kotlin/services/iotfleetwise/README.md +++ /dev/null @@ -1,131 +0,0 @@ -# AWS IoT FleetWise code examples for the SDK for Kotlin - -## Overview - -Shows how to use the AWS SDK for Kotlin to work with AWS IoT FleetWise. - - - - -_AWS IoT FleetWise provides a secure and scalable platform for collecting, storing, and analyzing data from connected vehicles and fleets._ - -## ⚠ Important - -* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/). -* Running the tests might result in charges to your AWS account. -* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege). -* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). - - - - -## Code examples - -### Prerequisites - -For prerequisites, see the [README](../../README.md#Prerequisites) in the `kotlin` folder. - - - - - -### Get started - -- [Hello AWS IoT FleetWise](src/main/java/com/example/fleetwise/HelloFleetwise.kt#L9) (`listSignalCatalogsPaginator`) - - -### Basics - -Code examples that show you how to perform the essential operations within a service. - -- [Learn the basics](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt) - - -### Single actions - -Code excerpts that show you how to call individual service functions. - -- [createDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L461) -- [createFleet](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L634) -- [createModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L584) -- [createSignalCatalog](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L656) -- [createVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L294) -- [deleteDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L448) -- [deleteFleet](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L549) -- [deleteModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L567) -- [deleteSignalCatalog](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L532) -- [deleteVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L255) -- [getDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L338) -- [getModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L384) -- [getVehicle](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L268) -- [listSignalCatalogNodes](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L614) -- [updateDecoderManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L325) -- [updateModelManifest](src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt#L430) - - - - - -## Run the examples - -### Instructions - - - - - -#### Hello AWS IoT FleetWise - -This example shows you how to get started using AWS IoT FleetWise. - - -#### Learn the basics - -This example shows you how to do the following: - -- Create a collection of standardized signals. -- Create a fleet that represents a group of vehicles. -- Create a model manifest. -- Create a decoder manifest. -- Check the status of the model manifest. -- Check the status of the decoder. -- Create an IoT Thing. -- Create a vehicle. -- Display vehicle details. -- Delete the AWS IoT FleetWise Assets. - - - - - - - - - -### Tests - -⚠ Running tests might result in charges to your AWS account. - - -To find instructions for running these tests, see the [README](../../README.md#Tests) -in the `kotlin` folder. - - - - - - -## Additional resources - -- [AWS IoT FleetWise Developer Guide](https://docs.aws.amazon.com/iot-fleetwise/latest/developerguide/what-is-fleetwise.html) -- [AWS IoT FleetWise API Reference](https://docs.aws.amazon.com/iot-fleetwise/latest/APIReference/Welcome.html) -- [SDK for Kotlin AWS IoT FleetWise reference](https://sdk.amazonaws.com/kotlin/api/latest/iot/index.html) - - - - ---- - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 diff --git a/kotlin/services/iotfleetwise/build.gradle.kts b/kotlin/services/iotfleetwise/build.gradle.kts deleted file mode 100644 index 40162d7e630..00000000000 --- a/kotlin/services/iotfleetwise/build.gradle.kts +++ /dev/null @@ -1,56 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -plugins { - kotlin("jvm") version "2.1.0" - application -} - -group = "me.scmacdon" -version = "1.0-SNAPSHOT" - -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -buildscript { - repositories { - maven("https://plugins.gradle.org/m2/") - } - dependencies { - classpath("org.jlleitschuh.gradle:ktlint-gradle:10.3.0") - } -} - -repositories { - mavenCentral() -} -apply(plugin = "org.jlleitschuh.gradle.ktlint") -dependencies { - implementation(platform("aws.sdk.kotlin:bom:1.5.63")) - implementation("aws.sdk.kotlin:iot") - implementation("aws.sdk.kotlin:iotfleetwise") - implementation("aws.sdk.kotlin:secretsmanager") - implementation("aws.smithy.kotlin:http-client-engine-okhttp") - implementation("aws.smithy.kotlin:http-client-engine-crt") - implementation("com.google.code.gson:gson:2.10") - testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4") - implementation("org.slf4j:slf4j-api:2.0.15") - implementation("org.slf4j:slf4j-simple:2.0.15") - testImplementation(kotlin("test")) -} -tasks.withType { - kotlinOptions.jvmTarget = "17" -} - -tasks.test { - useJUnitPlatform() - testLogging { - events("passed", "skipped", "failed") - } - - // Define the test source set - testClassesDirs += files("build/classes/kotlin/test") - classpath += files("build/classes/kotlin/main", "build/resources/main") -} diff --git a/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.kt b/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.kt deleted file mode 100644 index 25732b84c39..00000000000 --- a/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/HelloFleetwise.kt +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.example.fleetwise - -import aws.sdk.kotlin.services.iotfleetwise.IotFleetWiseClient -import aws.sdk.kotlin.services.iotfleetwise.model.ListSignalCatalogsRequest - -// snippet-start:[iotfleetwise.kotlin.hello.main] -/** -Before running this Kotlin code example, set up your development environment, -including your credentials. - -For more information, see the following documentation topic: -https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html - */ -suspend fun main() { - listSignalCatalogs() -} - -/** - * Lists the AWS FleetWise Signal Catalogs associated with the current AWS account. - */ -suspend fun listSignalCatalogs() { - val request = ListSignalCatalogsRequest { - maxResults = 10 - } - - IotFleetWiseClient { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.listSignalCatalogs(request) - val summaries = response.summaries - - if (summaries.isNullOrEmpty()) { - println("No AWS FleetWise Signal Catalogs were found.") - } else { - summaries.forEach { summary -> - with(summary) { - println("Catalog Name: $name") - println("ARN: $arn") - println("Created: $creationTime") - println("Last Modified: $lastModificationTime") - println("---------------") - } - } - } - } -} -// snippet-end:[iotfleetwise.kotlin.hello.main] diff --git a/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt b/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt deleted file mode 100644 index 543c8c2422c..00000000000 --- a/kotlin/services/iotfleetwise/src/main/java/com/example/fleetwise/scenario/FleetwiseScenario.kt +++ /dev/null @@ -1,725 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package com.example.fleetwise.scenario - -import aws.sdk.kotlin.services.iot.IotClient -import aws.sdk.kotlin.services.iot.model.CreateThingRequest -import aws.sdk.kotlin.services.iotfleetwise.IotFleetWiseClient -import aws.sdk.kotlin.services.iotfleetwise.model.Branch -import aws.sdk.kotlin.services.iotfleetwise.model.CanInterface -import aws.sdk.kotlin.services.iotfleetwise.model.CanSignal -import aws.sdk.kotlin.services.iotfleetwise.model.CreateDecoderManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.CreateFleetRequest -import aws.sdk.kotlin.services.iotfleetwise.model.CreateModelManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.CreateSignalCatalogRequest -import aws.sdk.kotlin.services.iotfleetwise.model.CreateVehicleRequest -import aws.sdk.kotlin.services.iotfleetwise.model.DeleteDecoderManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.DeleteFleetRequest -import aws.sdk.kotlin.services.iotfleetwise.model.DeleteModelManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.DeleteSignalCatalogRequest -import aws.sdk.kotlin.services.iotfleetwise.model.DeleteVehicleRequest -import aws.sdk.kotlin.services.iotfleetwise.model.GetDecoderManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.GetModelManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.GetVehicleRequest -import aws.sdk.kotlin.services.iotfleetwise.model.ListSignalCatalogNodesRequest -import aws.sdk.kotlin.services.iotfleetwise.model.ManifestStatus -import aws.sdk.kotlin.services.iotfleetwise.model.NetworkInterface -import aws.sdk.kotlin.services.iotfleetwise.model.NetworkInterfaceType -import aws.sdk.kotlin.services.iotfleetwise.model.Node -import aws.sdk.kotlin.services.iotfleetwise.model.NodeDataType -import aws.sdk.kotlin.services.iotfleetwise.model.Sensor -import aws.sdk.kotlin.services.iotfleetwise.model.SignalDecoder -import aws.sdk.kotlin.services.iotfleetwise.model.SignalDecoderType -import aws.sdk.kotlin.services.iotfleetwise.model.UpdateDecoderManifestRequest -import aws.sdk.kotlin.services.iotfleetwise.model.UpdateModelManifestRequest -import kotlinx.coroutines.delay -import java.util.Scanner - -// snippet-start:[iotfleetwise.kotlin.scenario.main] -/** -Before running this Kotlin code example, set up your development environment, -including your credentials. - -For more information, see the following documentation topic: -https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/setup.html - */ -var scanner = Scanner(System.`in`) -val DASHES = String(CharArray(80)).replace("\u0000", "-") -suspend fun main(args: Array) { - val usage = - """ - Usage: - - - Where: - signalCatalogName - The name of the Signal Catalog to create (eg, catalog30). - manifestName - The name of the Vehicle Model (Model Manifest) to create (eg, manifest30). - fleetId - The ID of the Fleet to create (eg, fleet30). - vecName - The name of the Vehicle to create (eg, vehicle30). - decName - The name of the Decoder Manifest to create (eg, decManifest30). - - """.trimIndent() - - if (args.size != 5) { - println(usage) - return - } - - val signalCatalogName = args[0] - val manifestName = args[1] - val fleetId = args[2] - val vecName = args[3] - val decName = args[4] - - println( - """ - AWS IoT FleetWise is a managed service that simplifies the - process of collecting, organizing, and transmitting vehicle - data to the cloud in near real-time. Designed for automakers - and fleet operators, it allows you to define vehicle models, - specify the exact data you want to collect (such as engine - temperature, speed, or battery status), and send this data to - AWS for analysis. By using intelligent data collection - techniques, IoT FleetWise reduces the volume of data - transmitted by filtering and transforming it at the edge, - helping to minimize bandwidth usage and costs. - - At its core, AWS IoT FleetWise helps organizations build - scalable systems for vehicle data management and analytics, - supporting a wide variety of vehicles and sensor configurations. - You can define signal catalogs and decoder manifests that describe - how raw CAN bus signals are translated into readable data, making - the platform highly flexible and extensible. This allows - manufacturers to optimize vehicle performance, improve safety, - and reduce maintenance costs by gaining real-time visibility - into fleet operations. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - println(DASHES) - runScenario(signalCatalogName, fleetId, manifestName, decName, vecName) -} - -suspend fun runScenario(signalCatalogName: String, fleetIdVal: String, manifestName: String, decName: String, vecName: String) { - println(DASHES) - println("1. Creates a collection of standardized signals that can be reused to create vehicle models") - waitForInputToContinue(scanner) - val signalCatalogArn = createbranchVehicle(signalCatalogName) - println("The collection ARN is $signalCatalogArn") - waitForInputToContinue(scanner) - println(DASHES) - - println(DASHES) - println("2. Create a fleet that represents a group of vehicles") - println( - """ - Creating an IoT FleetWise fleet allows you to efficiently collect, - organize, and transfer vehicle data to the cloud, enabling real-time - insights into vehicle performance and health. - - It helps reduce data costs by allowing you to filter and prioritize - only the most relevant vehicle signals, supporting advanced analytics - and predictive maintenance use cases. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - val fleetid = createFleet(signalCatalogArn, fleetIdVal) - println("The fleet Id is $fleetid") - waitForInputToContinue(scanner) - val nodeList = listSignalCatalogNode(signalCatalogName) - println(DASHES) - - println(DASHES) - println("3. Create a model manifest") - println( - """ - An AWS IoT FleetWise manifest defines the structure and - relationships of vehicle data. The model manifest specifies - which signals to collect and how they relate to vehicle systems, - while the decoder manifest defines how to decode raw vehicle data - into meaningful signals. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - val nodes = listSignalCatalogNode(signalCatalogName) - val manifestArn = nodes?.let { createModelManifest(manifestName, signalCatalogArn, it) } - println("The manifest ARN is $manifestArn") - println(DASHES) - - println(DASHES) - println("4. Create a decoder manifest") - println( - """ - A decoder manifest in AWS IoT FleetWise defines how raw vehicle - data (such as CAN signals) should be interpreted and decoded - into meaningful signals. It acts as a translation layer - that maps vehicle-specific protocols to standardized data formats - using decoding rules. This is crucial for extracting usable - data from different vehicle models, even when their data - formats vary. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - val decArn = createDecoderManifest(decName, manifestArn) - println("The decoder manifest ARN is $decArn") - waitForInputToContinue(scanner) - println(DASHES) - - println(DASHES) - println("5. Check the status of the model manifest") - println( - """ - The model manifest must be in an ACTIVE state before it can be used - to create or update a vehicle. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - updateModelManifest(manifestName) - waitForModelManifestActive(manifestName) - waitForInputToContinue(scanner) - println(DASHES) - - println(DASHES) - println("6. Check the status of the decoder") - println( - """ - The decoder manifest must be in an ACTIVE state before it can be used - to create or update a vehicle. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - updateDecoderManifest(decName) - waitForDecoderManifestActive(decName) - waitForInputToContinue(scanner) - println(DASHES) - - println(DASHES) - println("7. Create an IoT Thing") - println( - """ - AWS IoT FleetWise expects an existing AWS IoT Thing with the same - name as the vehicle name you are passing to createVehicle method. - Before calling createVehicle(), you must create an AWS IoT Thing - with the same name using the AWS IoT Core service. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - createThingIfNotExist(vecName) - println(DASHES) - - println(DASHES) - println("8. Create a vehicle") - println( - """ - Creating a vehicle in AWS IoT FleetWise allows you to digitally - represent and manage a physical vehicle within the AWS ecosystem. - This enables efficient ingestion, transformation, and transmission - of vehicle telemetry data to the cloud for analysis. - """.trimIndent(), - ) - waitForInputToContinue(scanner) - createVehicle(vecName, manifestArn, decArn) - println(DASHES) - - println(DASHES) - println("9. Display vehicle details") - waitForInputToContinue(scanner) - getVehicleDetails(vecName) - waitForInputToContinue(scanner) - println(DASHES) - println(DASHES) - println("10. Delete the AWS IoT Fleetwise Assets") - println("Would you like to delete the IoT Fleetwise Assets? (y/n)") - val delAns = scanner.nextLine().trim() - if (delAns.equals("y", ignoreCase = true)) { - deleteVehicle(vecName) - deleteDecoderManifest(decName) - deleteModelManifest(manifestName) - deleteFleet(fleetid) - deleteSignalCatalog(signalCatalogName) - } - - println(DASHES) - println( - """ - Thank you for checking out the AWS IoT Fleetwise Service Use demo. We hope you - learned something new, or got some inspiration for your own apps today. - For more AWS code examples, have a look at: - https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html - """.trimIndent(), - ) - println(DASHES) -} - -// snippet-start:[iotfleetwise.kotlin.delete.vehicle.main] -suspend fun deleteVehicle(vecName: String) { - val request = DeleteVehicleRequest { - vehicleName = vecName - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.deleteVehicle(request) - println("Vehicle $vecName was deleted successfully.") - } -} -// snippet-end:[iotfleetwise.kotlin.delete.vehicle.main] - -// snippet-start:[iotfleetwise.kotlin.get.vehicle.main] -suspend fun getVehicleDetails(vehicleNameVal: String) { - val request = GetVehicleRequest { - vehicleName = vehicleNameVal - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.getVehicle(request) - val details = mapOf( - "vehicleName" to response.vehicleName, - "arn" to response.arn, - "modelManifestArn" to response.modelManifestArn, - "decoderManifestArn" to response.decoderManifestArn, - "attributes" to response.attributes.toString(), - "creationTime" to response.creationTime.toString(), - "lastModificationTime" to response.lastModificationTime.toString(), - ) - - println("Vehicle Details:") - for ((key, value) in details) { - println("• %-20s : %s".format(key, value)) - } - } -} -// snippet-end:[iotfleetwise.kotlin.get.vehicle.main] - -// snippet-start:[iotfleetwise.kotlin.create.vehicle.main] -suspend fun createVehicle(vecName: String, manifestArn: String?, decArn: String) { - val request = CreateVehicleRequest { - vehicleName = vecName - modelManifestArn = manifestArn - decoderManifestArn = decArn - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.createVehicle(request) - println("Vehicle $vecName was created successfully.") - } -} -// snippet-end:[iotfleetwise.kotlin.create.vehicle.main] - -/** - * Creates an IoT Thing if it does not already exist. - * - * @param vecName the name of the IoT Thing to create - */ -suspend fun createThingIfNotExist(vecName: String) { - val request = CreateThingRequest { - thingName = vecName - } - - IotClient.fromEnvironment { region = "us-east-1" }.use { client -> - client.createThing(request) - println("The $vecName IoT Thing was successfully created") - } -} - -// snippet-start:[iotfleetwise.kotlin.update.decoder.main] -suspend fun updateDecoderManifest(nameVal: String) { - val request = UpdateDecoderManifestRequest { - name = nameVal - status = ManifestStatus.Active - } - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.updateDecoderManifest(request) - println("$nameVal was successfully updated") - } -} -// snippet-end:[iotfleetwise.kotlin.update.decoder.main] - -// snippet-start:[iotfleetwise.kotlin.decoder.active.main] -/** - * Waits for the specified model manifest to become active. - * - * @param decNameVal the name of the model manifest to wait for - */ -suspend fun waitForDecoderManifestActive(decNameVal: String) { - var elapsedSeconds = 0 - var lastStatus: ManifestStatus = ManifestStatus.Draft - - print("⏳ Elapsed: 0s | Status: DRAFT") - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - while (true) { - delay(1000) - elapsedSeconds++ - if (elapsedSeconds % 5 == 0) { - val request = GetDecoderManifestRequest { - name = decNameVal - } - - val response = fleetwiseClient.getDecoderManifest(request) - lastStatus = response.status ?: ManifestStatus.Draft - - when (lastStatus) { - ManifestStatus.Active -> { - print("\rElapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") - return - } - - ManifestStatus.Invalid -> { - print("\rElapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") - throw RuntimeException("Model manifest became INVALID. Cannot proceed.") - } - - else -> { - print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") - } - } - } else { - print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") - } - } - } -} -// snippet-end:[iotfleetwise.kotlin.decoder.active.main] - -// snippet-start:[iotfleetwise.kotlin.get.manifest.main] -/** - * Waits for the specified model manifest to become active. - * - * @param manifestName the name of the model manifest to wait for - */ -suspend fun waitForModelManifestActive(manifestNameVal: String) { - var elapsedSeconds = 0 - var lastStatus: ManifestStatus = ManifestStatus.Draft - - print("⏳ Elapsed: 0s | Status: DRAFT") - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - while (true) { - delay(1000) - elapsedSeconds++ - if (elapsedSeconds % 5 == 0) { - val request = GetModelManifestRequest { - name = manifestNameVal - } - - val response = fleetwiseClient.getModelManifest(request) - lastStatus = response.status ?: ManifestStatus.Draft - - when (lastStatus) { - ManifestStatus.Active -> { - print("\r Elapsed: ${elapsedSeconds}s | Status: ACTIVE ✅\n") - return - } - - ManifestStatus.Invalid -> { - print("\r Elapsed: ${elapsedSeconds}s | Status: INVALID ❌\n") - throw RuntimeException("Model manifest became INVALID. Cannot proceed.") - } - - else -> { - print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") - } - } - } else { - print("\r Elapsed: ${elapsedSeconds}s | Status: $lastStatus") - } - } - } -} -// snippet-end:[iotfleetwise.kotlin.get.manifest.main] - -// snippet-start:[iotfleetwise.kotlin.update.manifest.main] -/** - * Updates the model manifest. - * - * @param nameVal the name of the model manifest to update - */ -suspend fun updateModelManifest(nameVal: String) { - val request = UpdateModelManifestRequest { - name = nameVal - status = ManifestStatus.Active - } - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.updateModelManifest(request) - println("$nameVal was successfully updated") - } -} -// snippet-end:[iotfleetwise.kotlin.update.manifest.main] - -// snippet-start:[iotfleetwise.kotlin.delete.decoder.main] -suspend fun deleteDecoderManifest(nameVal: String) { - val request = DeleteDecoderManifestRequest { - name = nameVal - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.deleteDecoderManifest(request) - println("$nameVal was successfully deleted") - } -} -// snippet-end:[iotfleetwise.kotlin.delete.decoder.main] - -// snippet-start:[iotfleetwise.kotlin.create.decoder.main] -/** - * Creates a new decoder manifest. - * - * @param decName the name of the decoder manifest - * @param modelManifestArnVal the ARN of the model manifest - * @return the ARN of the decoder manifest - */ -suspend fun createDecoderManifest(decName: String, modelManifestArnVal: String?): String { - val interfaceIdVal = "can0" - - val canInter = CanInterface { - name = "canInterface0" - protocolName = "CAN" - protocolVersion = "1.0" - } - - val networkInterface = NetworkInterface { - interfaceId = interfaceIdVal - type = NetworkInterfaceType.CanInterface - canInterface = canInter - } - - val carRpmSig = CanSignal { - messageId = 100 - isBigEndian = false - isSigned = false - startBit = 16 - length = 16 - factor = 1.0 - offset = 0.0 - } - - val carSpeedSig = CanSignal { - messageId = 101 - isBigEndian = false - isSigned = false - startBit = 0 - length = 16 - factor = 1.0 - offset = 0.0 - } - - val engineRpmDecoder = SignalDecoder { - fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" - interfaceId = interfaceIdVal - type = SignalDecoderType.CanSignal - canSignal = carRpmSig - } - - val vehicleSpeedDecoder = SignalDecoder { - fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" - interfaceId = interfaceIdVal - type = SignalDecoderType.CanSignal - canSignal = carSpeedSig - } - - val request = CreateDecoderManifestRequest { - name = decName - modelManifestArn = modelManifestArnVal - networkInterfaces = listOf(networkInterface) - signalDecoders = listOf(engineRpmDecoder, vehicleSpeedDecoder) - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.createDecoderManifest(request) - return response.arn - } -} -// snippet-end:[iotfleetwise.kotlin.create.decoder.main] - -// snippet-start:[iotfleetwise.kotlin.delete.catalog.main] -/** - * Deletes a signal catalog. - * - * @param name the name of the signal catalog to delete - */ -suspend fun deleteSignalCatalog(catName: String) { - val request = DeleteSignalCatalogRequest { - name = catName - } - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.deleteSignalCatalog(request) - println(" $catName was successfully deleted") - } -} -// snippet-end:[iotfleetwise.kotlin.delete.catalog.main] - -// snippet-start:[iotfleetwise.kotlin.delete.fleet.main] -/** - * Deletes a fleet based on the provided fleet ID. - * - * @param fleetId the ID of the fleet to be deleted - */ -suspend fun deleteFleet(fleetIdVal: String) { - val request = DeleteFleetRequest { - fleetId = fleetIdVal - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.deleteFleet(request) - println(" $fleetIdVal was successfully deleted") - } -} -// snippet-end:[iotfleetwise.kotlin.delete.fleet.main] - -// snippet-start:[iotfleetwise.kotlin.delete.model.main] -/** - * Deletes a model manifest. - * - * @param nameVal the name of the model manifest to delete - */ -suspend fun deleteModelManifest(nameVal: String) { - val request = DeleteModelManifestRequest { - name = nameVal - } - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - fleetwiseClient.deleteModelManifest(request) - println(" $nameVal was successfully deleted") - } -} -// snippet-end:[iotfleetwise.kotlin.delete.model.main] - -// snippet-start:[iotfleetwise.kotlin.create.model.main] -/** - * Creates a model manifest. - * - * @param name the name of the model manifest to create - * @param signalCatalogArn the Amazon Resource Name (ARN) of the signal catalog - * @param nodes a list of nodes to include in the model manifest - * @return a {@link CompletableFuture} that completes with the ARN of the created model manifest - */ -suspend fun createModelManifest(nameVal: String, signalCatalogArnVal: String, nodesList: List): String { - val fqnList: List = nodesList.map { node -> - when (node) { - is Node.Sensor -> node.asSensor().fullyQualifiedName - is Node.Branch -> node.asBranch().fullyQualifiedName - else -> throw RuntimeException("Unsupported node type") - } - } - - val request = CreateModelManifestRequest { - name = nameVal - signalCatalogArn = signalCatalogArnVal - nodes = fqnList - } - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.createModelManifest(request) - return response.arn - } -} -// snippet-end:[iotfleetwise.kotlin.create.model.main] - -// snippet-start:[iotfleetwise.kotlin.list.catalogs.main] -/** - * Lists the signal catalog nodes asynchronously. - * - * @param signalCatalogName the name of the signal catalog - * @return a CompletableFuture that, when completed, contains a list of nodes in the specified signal catalog - * @throws CompletionException if an exception occurs during the asynchronous operation - */ -suspend fun listSignalCatalogNode(signalCatalogName: String): List? { - val request = ListSignalCatalogNodesRequest { - name = signalCatalogName - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.listSignalCatalogNodes(request) - return response.nodes - } -} -// snippet-end:[iotfleetwise.kotlin.list.catalogs.main] - -// snippet-start:[iotfleetwise.kotlin.create.fleet.main] -/** - * Creates a new fleet. - * - * @param catARN the Amazon Resource Name (ARN) of the signal catalog to associate with the fleet - * @param fleetId the unique identifier for the fleet - * @return the ID of the created fleet - */ -suspend fun createFleet(catARN: String, fleetIdVal: String): String { - val fleetRequest = CreateFleetRequest { - fleetId = fleetIdVal - signalCatalogArn = catARN - description = "Built using the AWS For Kotlin" - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.createFleet(fleetRequest) - return response.id - } -} -// snippet-end:[iotfleetwise.kotlin.create.fleet.main] - -// snippet-start:[iotfleetwise.kotlin.create.catalog.main] -/** - * Creates a signal catalog. - * - * @param signalCatalogName the name of the signal catalog to create the branch vehicle in - * @return the ARN (Amazon Resource Name) of the created signal catalog - */ -suspend fun createbranchVehicle(signalCatalogName: String): String { - delay(2000) // Wait for 2 seconds - val branchVehicle = Branch { - fullyQualifiedName = "Vehicle" - description = "Root branch" - } - - val branchPowertrain = Branch { - fullyQualifiedName = "Vehicle.Powertrain" - description = "Powertrain branch" - } - - val sensorRPM = Sensor { - fullyQualifiedName = "Vehicle.Powertrain.EngineRPM" - description = "Engine RPM" - dataType = NodeDataType.Double - unit = "rpm" - } - - val sensorKM = Sensor { - fullyQualifiedName = "Vehicle.Powertrain.VehicleSpeed" - description = "Vehicle Speed" - dataType = NodeDataType.Double - unit = "km/h" - } - - // Wrap each specific node type (Branch and Sensor) into the sealed Node class - // so they can be included in the CreateSignalCatalogRequest. - val myNodes = listOf( - Node.Branch(branchVehicle), - Node.Branch(branchPowertrain), - Node.Sensor(sensorRPM), - Node.Sensor(sensorKM), - ) - - val request = CreateSignalCatalogRequest { - name = signalCatalogName - nodes = myNodes - } - - IotFleetWiseClient.fromEnvironment { region = "us-east-1" }.use { fleetwiseClient -> - val response = fleetwiseClient.createSignalCatalog(request) - return response.arn - } -} -// snippet-end:[iotfleetwise.kotlin.create.catalog.main] - -private fun waitForInputToContinue(scanner: Scanner) { - while (true) { - println("") - println("Enter 'c' followed by to continue:") - val input = scanner.nextLine() - - if (input.trim { it <= ' ' }.equals("c", ignoreCase = true)) { - println("Continuing with the program...") - println("") - break - } else { - println("Invalid input. Please try again.") - } - } -} -// snippet-end:[iotfleetwise.kotlin.scenario.main] diff --git a/kotlin/services/iotfleetwise/src/test/java/FleetwiseTest.kt b/kotlin/services/iotfleetwise/src/test/java/FleetwiseTest.kt deleted file mode 100644 index 6d2ac1aa067..00000000000 --- a/kotlin/services/iotfleetwise/src/test/java/FleetwiseTest.kt +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -import com.example.fleetwise.listSignalCatalogs -import com.example.fleetwise.scenario.createDecoderManifest -import com.example.fleetwise.scenario.createFleet -import com.example.fleetwise.scenario.createModelManifest -import com.example.fleetwise.scenario.createThingIfNotExist -import com.example.fleetwise.scenario.createVehicle -import com.example.fleetwise.scenario.createbranchVehicle -import com.example.fleetwise.scenario.deleteDecoderManifest -import com.example.fleetwise.scenario.deleteFleet -import com.example.fleetwise.scenario.deleteModelManifest -import com.example.fleetwise.scenario.deleteSignalCatalog -import com.example.fleetwise.scenario.deleteVehicle -import com.example.fleetwise.scenario.getVehicleDetails -import com.example.fleetwise.scenario.listSignalCatalogNode -import com.example.fleetwise.scenario.updateDecoderManifest -import com.example.fleetwise.scenario.updateModelManifest -import com.example.fleetwise.scenario.waitForDecoderManifestActive -import com.example.fleetwise.scenario.waitForModelManifestActive -import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.MethodOrderer -import org.junit.jupiter.api.Order -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance -import org.junit.jupiter.api.TestMethodOrder - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -@TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class FleetwiseTest { - private val signalCatalogName = "catalogTest10" - private val manifestName = "manifest10" - private val fleetName = "fleet10" - private val vecName = "vehicle10" - private val decName = "decManifest10" - private var signalCatalogArn = "" - private var fleetValue = "" - private var manifestArn = "" - private var decArn = "" - - @Test - @Order(1) - fun testHello() = runBlocking { - runCatching { - listSignalCatalogs() - }.onSuccess { - println("Test 1 Passed Successfully!") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(2) - fun testCat() = runBlocking { - runCatching { - signalCatalogArn = createbranchVehicle(signalCatalogName) - }.onSuccess { - println("Test 2 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(3) - fun testFleet(): Unit = runBlocking { - runCatching { - fleetValue = createFleet(signalCatalogArn, fleetName) - }.onSuccess { - println("Test 3 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(4) - fun testModelManifest(): Unit = runBlocking { - runCatching { - val nodes = listSignalCatalogNode(signalCatalogName) - manifestArn = nodes?.let { createModelManifest(manifestName, signalCatalogArn, it) }.toString() - }.onSuccess { - println("Test 4 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(5) - fun testDecodeManifest(): Unit = runBlocking { - runCatching { - decArn = createDecoderManifest(decName, manifestArn) - }.onSuccess { - println("Test 5 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(6) - fun testManifestStatus(): Unit = runBlocking { - runCatching { - updateModelManifest(manifestName) - waitForModelManifestActive(manifestName) - }.onSuccess { - println("Test 6 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(7) - fun testDecoderStatus(): Unit = runBlocking { - runCatching { - updateDecoderManifest(decName) - waitForDecoderManifestActive(decName) - }.onSuccess { - println("Test 7 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(8) - fun testIoTThing(): Unit = runBlocking { - runCatching { - createThingIfNotExist(vecName) - }.onSuccess { - println("Test 8 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(9) - fun testVehicle(): Unit = runBlocking { - runCatching { - createVehicle(vecName, manifestArn, decArn) - }.onSuccess { - println("Test 9 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(10) - fun testGetVehicle(): Unit = runBlocking { - runCatching { - getVehicleDetails(vecName) - }.onSuccess { - println("Test 10 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(11) - fun testDelVehicle() = runBlocking { - runCatching { - deleteVehicle(vecName) - }.onSuccess { - println("Test 11 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(12) - fun testDelDecoder() = runBlocking { - runCatching { - deleteDecoderManifest(decName) - }.onSuccess { - println("Test 12 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(13) - fun testDelMan() = runBlocking { - runCatching { - deleteModelManifest(manifestName) - }.onSuccess { - println("Test 13 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(14) - fun testDelFleet() = runBlocking { - runCatching { - deleteFleet(fleetName) - }.onSuccess { - println("Test 14 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } - - @Test - @Order(15) - fun testDelCat() = runBlocking { - runCatching { - deleteSignalCatalog(signalCatalogName) - }.onSuccess { - println("Test 15 Passed Successfully") - }.onFailure { - it.printStackTrace() - }.getOrThrow() - } -} diff --git a/scenarios/basics/fleetwise/README.md b/scenarios/basics/fleetwise/README.md deleted file mode 100644 index 5c3da3454c2..00000000000 --- a/scenarios/basics/fleetwise/README.md +++ /dev/null @@ -1,39 +0,0 @@ -## Overview -This AWS IoT Fleetwise basic scenario demonstrates how to interact with the AWS IoT FleetWise service using an AWS SDK. The scenario covers various operations such as creating a collection of standardized signals, creating a model manifest, creating a vehicle, and so on. - -## Key Operations - -1. **Create an AWS Fleetwise signal catalog**: - - This step creates an AWS Fleetwise signal catalog by invoking the `createSignalCatalog`method. - -2. **Create an AWS IoT Fleetwise fleet**: - - This operation creates an AWS Fleetwise fleet by invoking the `createFleet`method. - -3. **Create a model manifest**: - - This operation creates an AWS Fleetwise model manifest by invoking the `createModelManifest`method. - -4. **Create a decoder manifest**: - - This operation creates an AWS Fleetwise decoder manifest by invoking the `createDecoderManifest`method. - -5. **Create a vehicle**: - - This operation creates an AWS Fleetwise vehicle by invoking the `createVehicle`method. - -**Note** See the [Engineering specification](SPECIFICATION.md) for a full listing of operations. - -## Resources - -This Basics scenario does not require any additional AWS resources. - -## Implementations - -This scenario example will be implemented in the following languages: - -- Java -- JavaScript -- Kotlin - -## Additional Reading - -- [AWS IoT Fleetwise Documentation](https://docs.aws.amazon.com/iot-fleetwise/latest/developerguide/what-is-iotfleetwise.html) - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 diff --git a/scenarios/basics/fleetwise/SPECIFICATION.md b/scenarios/basics/fleetwise/SPECIFICATION.md deleted file mode 100644 index 9c14824e093..00000000000 --- a/scenarios/basics/fleetwise/SPECIFICATION.md +++ /dev/null @@ -1,313 +0,0 @@ -# AWS IoT Fleetwise Service Scenario Specification - -## Overview -This SDK Basics scenario demonstrates how to interact with AWS IoT Fleetwise using an AWS SDK. -It demonstrates various tasks such as creating a Fleetwise catelog, creating an fleet, -creating a vehicle, and so on. Finally this scenario demonstrates how -to clean up resources. Its purpose is to demonstrate how to get up and running with -AWS Fleetwise and an AWS SDK. - -## Resources -This Basics scenario does not require any additional AWS resources. - -## Hello AWS Fleetwise -This program is intended for users not familiar with the AWS IoT Fleetwise Service to easily get up and running. The program uses a `listSignalCatalogsPaginator` to demonstrate how you can read through catalog information. If there are no catalogs, print out a message to inform the user. - -## Basics Scenario Program Flow -The AWS IoT Fleetwise Basics scenario executes the following operations. - -1. **Create an AWS FleetWise collection**: - - Description: Creates an AWS Fleetwise collection by invoking `createSignalCatalog`. - - Exception Handling: Check to see if a `ValidationException` is thrown. - If it is thrown, if so, display the message and end the program. - -2. **Create an IoT Fleetwise fleet**: - - Description: Creates an AWS Fleetwise fleet by invoking `createFleet`. - - Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If it is thrown, if so, display the message and end the program. - -3. **Create a model manifest**: - - Description: Creates a model manifest by invoking `listSignalCatalogNodes` to retrieve a list of nodes. This node list is passed to `createModelManifest()`. - - Exception Handling: Check to see if an `InvalidSignalsException` is thrown. If so, display the message and end the program. - -4. **Create a decoder manifest**: - - Description: Creates a decoder manifest by invoking `createDecoderManifest`. - - Exception Handling: Check to see if a `DecoderManifestValidationException` is thrown. If so, display the message and end the program. - -5. **Check the status of the model manifest**: - - Description: Checks the status of the model manifest by invoking `updateModelManifest`and `getModelManifest`. - - Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program. - -6. **Check the status of the decoder**: - - Description: Checks the status of the decoder manifest by invoking `updateDecoderManifest`and `getDecoderManifest`. - - Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program. - - -7. **Create an IoT Thing**: - - Description: Creates an IoT Thing which is required to create a vehicle by invoking `createThing`. - - Exception Handling: Check to see if a `ResourceAlreadyExistsException` is thrown. If so, display the message and end the program. - -8. **Create a vehicle**: - - Description: Creates a vehicle by invoking `createVehicle`. - - Exception Handling: Check to see if an `ResourceNotFoundException` is thrown. If so, display the message and end the program. - -9. **Display vehicle details**: - - Description: Describes the vehicle by invoking `getVehicle`. - - Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program. - -10. **Delete the AWS IoT Fleetwise Assets**: - - The `delete` methods are called to clean up the resources. - - Exception Handling: Check to see if a `ResourceNotFoundException` is thrown. If so, display the message and end the program." - -### Program execution -The following shows the output of the AWS IoT Fleetwise Basics scenario. - -``` - AWS IoT FleetWise is a managed service that simplifies the - process of collecting, organizing, and transmitting vehicle - data to the cloud in near real-time. Designed for automakers - and fleet operators, it allows you to define vehicle models, - specify the exact data you want to collect (such as engine - temperature, speed, or battery status), and send this data to - AWS for analysis. By using intelligent data collection - techniques, IoT FleetWise reduces the volume of data - transmitted by filtering and transforming it at the edge, - helping to minimize bandwidth usage and costs. - -At its core, AWS IoT FleetWise helps organizations build -scalable systems for vehicle data management and analytics, -supporting a wide variety of vehicles and sensor configurations. -You can define signal catalogs and decoder manifests that describe -how raw CAN bus signals are translated into readable data, making -the platform highly flexible and extensible. This allows -manufacturers to optimize vehicle performance, improve safety, -and reduce maintenance costs by gaining real-time visibility -into fleet operations. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -1. Creates a collection of standardized signals that can be reused to create vehicle models -The collection ARN is arn:aws:iotfleetwise:us-east-1:814548047983:signal-catalog/catalog60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -2. Create a fleet that represents a group of vehicles -Creating an IoT FleetWise fleet allows you to efficiently collect, -organize, and transfer vehicle data to the cloud, enabling real-time -insights into vehicle performance and health. - -It helps reduce data costs by allowing you to filter and prioritize -only the most relevant vehicle signals, supporting advanced analytics -and predictive maintenance use cases. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -The fleet Id is fleet60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -3. Create a model manifest -An AWS IoT FleetWise manifest defines the structure and -relationships of vehicle data. The model manifest specifies -which signals to collect and how they relate to vehicle systems, -while the decoder manifest defines how to decode raw vehicle data -into meaningful signals. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -The manifest ARN is arn:aws:iotfleetwise:us-east-1:814548047983:model-manifest/manifest60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -4. Create a decoder manifest -A decoder manifest in AWS IoT FleetWise defines how raw vehicle -data (such as CAN signals) should be interpreted and decoded -into meaningful signals. It acts as a translation layer -that maps vehicle-specific protocols to standardized data formats -using decoding rules. This is crucial for extracting usable -data from different vehicle models, even when their data -formats vary. - - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -The decoder manifest ARN is arn:aws:iotfleetwise:us-east-1:814548047983:decoder-manifest/decManifest60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- -5. Check the status of the model manifest -The model manifest must be in an ACTIVE state before it can be used -to create or update a vehicle. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -Elapsed: 0s | Status: DRAFT -Elapsed: 1s | Status: DRAFT -Elapsed: 2s | Status: DRAFT -Elapsed: 3s | Status: DRAFT -Elapsed: 4s | Status: DRAFT -Elapsed: 5s | Status: ACTIVE - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- -6. Check the status of the decoder -The decoder manifest must be in an ACTIVE state before it can be used -to create or update a vehicle. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - - Elapsed: 0s | Decoder Status: DRAFT - Elapsed: 1s | Decoder Status: DRAFT - Elapsed: 2s | Decoder Status: DRAFT - Elapsed: 3s | Decoder Status: DRAFT - Elapsed: 4s | Decoder Status: DRAFT - Elapsed: 5s | Decoder Status: ACTIVE - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -7. Create an IoT Thing -AWS IoT FleetWise expects an existing AWS IoT Thing with the same -name as the vehicle name you are passing to createVehicle method. -Before calling createVehicle(), you must create an AWS IoT Thing -with the same name using the AWS IoT Core service. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -IoT Thing created: vehicle60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -8. Create a vehicle -Creating a vehicle in AWS IoT FleetWise allows you to digitally -represent and manage a physical vehicle within the AWS ecosystem. -This enables efficient ingestion, transformation, and transmission -of vehicle telemetry data to the cloud for analysis. - - -Enter 'c' followed by to continue: -c -Continuing with the program... - -Vehicle 'vehicle60' created successfully. - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -9. Display vehicle details - -Enter 'c' followed by to continue: -c -Continuing with the program... - -Vehicle Details: -• modelManifestArn : arn:aws:iotfleetwise:us-east-1:814548047983:model-manifest/manifest60 -• vehicleName : vehicle60 -• creationTime : 2025-04-29T16:00:02.147Z -• lastModificationTime : 2025-04-29T16:00:02.147Z -• decoderManifestArn : arn:aws:iotfleetwise:us-east-1:814548047983:decoder-manifest/decManifest60 -• attributes : {} -• arn : arn:aws:iotfleetwise:us-east-1:814548047983:vehicle/vehicle60 - -Enter 'c' followed by to continue: -c -Continuing with the program... - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -10. Delete the AWS IoT Fleetwise Assets -Would you like to delete the IoT Fleetwise Assets? (y/n) -y -vehicle60 was successfully deleted -decManifest60 was successfully deleted -manifest60 was successfully deleted -fleet60 was successfully deleted -catalog60 was successfully deleted --------------------------------------------------------------------------------- -Thank you for checking out the AWS IoT Fleetwise Service Use demo. We hope you -learned something new, or got some inspiration for your own apps today. -For more AWS code examples, have a look at: -https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html - --------------------------------------------------------------------------------- -``` - -## SOS Tags - -The following table describes the metadata used in this Basics Scenario. - - -| action | metadata file | metadata key | -|------------------------|----------------------------|------------------------------------- | -|`createSignalCatalog` |iot_fleetwise_metadata.yaml |iotfleetwise_CreateSignalCatalog | -|`createFleet` |iot_fleetwise_metadata.yaml |iotfleetwise_CreateFleet | -|`createModelManifest` iot_fleetwise_metadata.yaml |iotfleetwise_CreateModelManifest | -|`createDecoderManifest` |iot_fleetwise_metadata.yaml |iotfleetwise_CreateDecoderManifest | -|`updateModelManifest` |iot_fleetwise_metadata.yaml |iotfleetwise_UpdateModelManifest | -| `createPortal` |iot_fleetwise_metadata.yaml |iotfleetwise_CreatePortal | -|`waitForModelManifest` |iot_fleetwise_metadata.yaml |iotfleetwise_WaitForModelManifest | -|`updateDecoderManifest` |iot_fleetwise_metadata.yaml |iotfleetwise_updateDecoder | -| `describeAssetModel` |iot_fleetwise_metadata.yaml |iotfleetwise_DescribeAssetModel | -| `waitForDecoder ` |iot_fleetwise_metadata.yaml |iotfleetwise_WaitForDecoder | -| `createVehicle` |iot_fleetwise_metadata.yaml |iotfleetwise_CreateVehicle | -| `getVehicle` |iot_fleetwise_metadata.yaml |iotfleetwise_GetVehicle | -| `deleteVehicle ` |iot_fleetwise_metadata.yaml |iotfleetwise_DeleteVehicle | -|`deleteDecoderManifest` |iot_fleetwise_metadata.yaml |iotfleetwise_DeleteDecoder | -| `deleteFleet ` |iot_fleetwise_metadata.yaml |iotfleetwise_DeleteFleet | -| `deleteModel` |iot_fleetwise_metadata.yaml |iotfleetwise_DeleteModel | -| `deleteSignalCatalog ` |iot_fleetwise_metadata.yaml|iotfleetwise_DeleteSignalCatalog | -| `scenario` |iot_fleetwise_metadata.yaml |iotfleetwise_Scenario | -| `hello` |iot_fleetwise_metadata.yaml |iotfleetwise_Hello | - - -