From 14df569fd812098bad6defa4012848a21de311be Mon Sep 17 00:00:00 2001 From: Giovanni Grano Date: Mon, 9 Dec 2024 09:39:01 -0500 Subject: [PATCH 1/2] add java docs --- .../tools/localstack-sdk/java/index.md | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 content/en/user-guide/tools/localstack-sdk/java/index.md diff --git a/content/en/user-guide/tools/localstack-sdk/java/index.md b/content/en/user-guide/tools/localstack-sdk/java/index.md new file mode 100644 index 0000000000..f01f3be05f --- /dev/null +++ b/content/en/user-guide/tools/localstack-sdk/java/index.md @@ -0,0 +1,78 @@ +--- +title: "Java" +weight: 1 +description: Use the LocalStack SDK for Java +--- + +## Introduction + +You can use the LocalStack SDK for Java to develop Java applications that interact with the LocalStack platform and internal developer endpoints. +The SDK extends the REST API, offering an object-oriented interface for easier use. + +The LocalStack SDK for Java currently supports these features: + +- Save, list, load, and delete Cloud Pods. +- Manage fault configurations for the Chaos API. + +{{< callout >}} +This SDK is still in a preview phase, and will be subject to fast and breaking changes. +{{< /callout >}} + +## Installation + +The best way to use the LocalStack SDK for Java in your project is to consume it from Maven Central. +You can use Maven to import the entire SDK into your project. + +```xml + + cloud.localstack + localstack-sdk + 0.0.1 + +``` + +Similarly, you can copy the following line in the dependencies blog of your `build.gradle(.kts)` file if you are using Gradle as a build tool. + +```kotlin +implementation("cloud.localstack:localstack-sdk:0.0.1") +``` + +## Quick Start + +Currently, the LocalStack SDK for Java only supports Chaos and Cloud Pods APIs. +Both these features have a client that can be instantiated from the `cloud.localstack.sdk.chaos` and +`cloud.localstack.sdk.pods` package, respectively. + +The clients build requests by using the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern). +For instance, let us imagine the case in which we want to add a fault rule for S3 on the `us-east-1` region. +You first need to use the `FaultRuleRequest` class to build a fault rule request. +Then, you need to pass such a request object to the `addFaultRules` method of a created `ChaosClient`. + +```java +import cloud.localstack.sdk.chaos.ChaosClient; +import cloud.localstack.sdk.chaos.requests.FaultRuleRequest; + +var client = new ChaosClient(); +var faultRuleRequest = new FaultRuleRequest.Builder().faultRule("s3", "us-east-1").build(); +var addedRules = client.addFaultRules(request); +``` + +As a second example, let us look at the necessary code to save and load a Cloud Pod. +The `PodsClient` exposes two functions, `savePod` and `loadPod`, which expect a `SavePodRequest` and a +`LoadPodRequest`, respectively. +The resulting code is the following: + +```java +import cloud.localstack.sdk.pods.PodsClient; +import cloud.localstack.sdk.pods.requests.LoadPodRequest; +import cloud.localstack.sdk.pods.requests.SavePodRequest; + +var podsClient = new PodsClient(); +// save a cloud pod +var saveRequest = new SavePodRequest.Builder().podName(POD_NAME).build(); +podsClient.savePod(saveRequest); + +//load a cloud pod +var loadRequest = new LoadPodRequest.Builder().podName(POD_NAME).build(); +podsClient.loadPod(loadRequest); +``` From a49174da0c7067569447a8c9aefacdb8dfe1b23a Mon Sep 17 00:00:00 2001 From: Giovanni Grano Date: Mon, 9 Dec 2024 09:46:11 -0500 Subject: [PATCH 2/2] minor --- content/en/user-guide/tools/localstack-sdk/java/index.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/content/en/user-guide/tools/localstack-sdk/java/index.md b/content/en/user-guide/tools/localstack-sdk/java/index.md index f01f3be05f..1acdd45d01 100644 --- a/content/en/user-guide/tools/localstack-sdk/java/index.md +++ b/content/en/user-guide/tools/localstack-sdk/java/index.md @@ -31,7 +31,7 @@ You can use Maven to import the entire SDK into your project. ``` -Similarly, you can copy the following line in the dependencies blog of your `build.gradle(.kts)` file if you are using Gradle as a build tool. +Similarly, you can copy the following line in the dependencies block of your `build.gradle(.kts)` file, if you are using Gradle as a build tool. ```kotlin implementation("cloud.localstack:localstack-sdk:0.0.1") @@ -43,8 +43,8 @@ Currently, the LocalStack SDK for Java only supports Chaos and Cloud Pods APIs. Both these features have a client that can be instantiated from the `cloud.localstack.sdk.chaos` and `cloud.localstack.sdk.pods` package, respectively. -The clients build requests by using the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern). -For instance, let us imagine the case in which we want to add a fault rule for S3 on the `us-east-1` region. +The clients accept requests built by using the [builder pattern](https://en.wikipedia.org/wiki/Builder_pattern). +For instance, let us imagine the case in which you want to add a fault rule for S3 on the `us-east-1` region. You first need to use the `FaultRuleRequest` class to build a fault rule request. Then, you need to pass such a request object to the `addFaultRules` method of a created `ChaosClient`. @@ -58,8 +58,7 @@ var addedRules = client.addFaultRules(request); ``` As a second example, let us look at the necessary code to save and load a Cloud Pod. -The `PodsClient` exposes two functions, `savePod` and `loadPod`, which expect a `SavePodRequest` and a -`LoadPodRequest`, respectively. +Similarly to the `ChaosClient`, the `PodsClient` exposes two functions, `savePod` and `loadPod`, which expect a `SavePodRequest` and a `LoadPodRequest`, respectively. The resulting code is the following: ```java