Skip to content

Commit

Permalink
liblab SDK update for version v0.9.0-alpha.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorquico committed Sep 17, 2024
1 parent e32244d commit 1c97e66
Show file tree
Hide file tree
Showing 16 changed files with 341 additions and 28 deletions.
26 changes: 17 additions & 9 deletions .manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"liblabVersion": "2.3.1",
"date": "2024-09-11T23:34:32.905Z",
"liblabVersion": "2.4.0",
"date": "2024-09-17T04:36:05.118Z",
"config": {
"apiId": 1126,
"sdkName": "salad-cloud-imds-sdk",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"liblabVersion": "2",
"deliveryMethods": ["zip"],
"languages": ["java"],
Expand All @@ -25,15 +25,15 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-dotnet",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
},
"go": {
"goModuleName": "github.com/saladtechnologies/salad-cloud-imds-sdk-go",
"githubRepoName": "salad-cloud-imds-sdk-go",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
},
"java": {
Expand All @@ -57,7 +57,7 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-java",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
},
"python": {
Expand Down Expand Up @@ -100,7 +100,7 @@
"githubRepoName": "salad-cloud-imds-sdk-python",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
},
"typescript": {
Expand All @@ -123,7 +123,7 @@
"homepage": "https://github.com/saladtechnologies/salad-cloud-imds-sdk-javascript",
"ignoreFiles": [".gitignore", "./LICENSE"],
"liblabVersion": "2",
"sdkVersion": "0.9.0-alpha.2",
"sdkVersion": "0.9.0-alpha.3",
"targetBranch": "main"
}
},
Expand Down Expand Up @@ -155,7 +155,7 @@
},
"multiTenant": true,
"hooksLocation": {
"bucketKey": "7096/hooks.zip",
"bucketKey": "7207/hooks.zip",
"bucketName": "prod-liblab-api-stack-hooks"
},
"includeWatermark": false,
Expand Down Expand Up @@ -205,6 +205,14 @@
},
"files": [
"pom.xml",
"src/main/java/com/salad/cloud/imdssdk/validation/Violation.java",
"src/main/java/com/salad/cloud/imdssdk/validation/ViolationAggregator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/validators/AbstractValidator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/validators/ListValidator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/validators/NumericValidator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/validators/StringValidator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/validators/Validator.java",
"src/main/java/com/salad/cloud/imdssdk/validation/exceptions/ValidationException.java",
"src/main/java/com/salad/cloud/imdssdk/validation/annotation/Length.java",
"src/main/java/com/salad/cloud/imdssdk/validation/annotation/Max.java",
"src/main/java/com/salad/cloud/imdssdk/validation/annotation/Min.java",
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SaladCloudImdsSdk Java SDK 0.9.0-alpha.2
# SaladCloudImdsSdk Java SDK 0.9.0-alpha.3

Welcome to the SaladCloudImdsSdk SDK documentation. This guide will help you get started with integrating and using the SaladCloudImdsSdk SDK in your project.

## Versions

- API version: `0.9.0-alpha.1`
- SDK version: `0.9.0-alpha.2`
- SDK version: `0.9.0-alpha.3`

## About the API

Expand Down Expand Up @@ -36,14 +36,14 @@ If you use Maven, place the following within the _dependency_ tag in your `pom.x
<dependency>
<groupId>com.salad.cloud</groupId>
<artifactId>imds-sdk</artifactId>
<version>0.9.0-alpha.2</version>
<version>0.9.0-alpha.3</version>
</dependency>
```

If you use Gradle, paste the next line inside the _dependencies_ block of your `build.gradle` file:

```Gradle
implementation group: com.salad.cloud, name: imds-sdk, version: 0.9.0-alpha.2
implementation group: com.salad.cloud, name: imds-sdk, version: 0.9.0-alpha.3
```

If you use JAR files, package the SDK by running the following command:
Expand Down
8 changes: 4 additions & 4 deletions documentation/models/ContainerStatus.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Represents the health statuses of the running container.

**Properties**

| Name | Type | Required | Description |
| :------ | :-------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ready | `Boolean` || `true` if the running container is ready. If a readiness probe is defined, this returns the latest result of the probe. If a readiness probe is not defined but a startup probe is defined, this returns the same value as the `started` property. If neither a readiness probe nor a startup probe are defined, returns `true`. |
| started | `Boolean` || `true` if the running container is started. If a startup probe is defined, this returns the latest result of the probe. If a startup probe is not defined, returns `true`. |
| Name | Type | Required | Description |
| :------ | :------ | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ready | Boolean || `true` if the running container is ready. If a readiness probe is defined, this returns the latest result of the probe. If a readiness probe is not defined but a startup probe is defined, this returns the same value as the `started` property. If neither a readiness probe nor a startup probe are defined, returns `true`. |
| started | Boolean || `true` if the running container is started. If a startup probe is defined, this returns the latest result of the probe. If a startup probe is not defined, returns `true`. |
6 changes: 3 additions & 3 deletions documentation/models/ContainerToken.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Represents the identity token of the running container.

**Properties**

| Name | Type | Required | Description |
| :--- | :------- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| jwt | `String` || The JSON Web Token (JWT) that may be used to identify the running container. The JWT may be verified using the JSON Web Key Set (JWKS) available at https://matrix-rest-api.salad.com/.well-known/stash-jwks.json. |
| Name | Type | Required | Description |
| :--- | :----- | :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| jwt | String || The JSON Web Token (JWT) that may be used to identify the running container. The JWT may be verified using the JSON Web Key Set (JWKS) available at https://matrix-rest-api.salad.com/.well-known/stash-jwks.json. |
6 changes: 3 additions & 3 deletions documentation/models/ReallocateContainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Represents a request to reallocate a container.

**Properties**

| Name | Type | Required | Description |
| :----- | :------- | :------- | :---------------------------------------------------------------------------------------------------------------------------- |
| reason | `String` || The reason for reallocating the container. This value is reported to SaladCloud support for quality assurance of Salad Nodes. |
| Name | Type | Required | Description |
| :----- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------- |
| reason | String || The reason for reallocating the container. This value is reported to SaladCloud support for quality assurance of Salad Nodes. |
6 changes: 3 additions & 3 deletions documentation/services/MetadataService.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Reallocates the running container to another Salad Node

**Parameters**

| Name | Type | Required | Description |
| :------------------ | :-------------------------------------------------------- | :------- | :----------- |
| reallocateContainer | `[ReallocateContainer](../models/ReallocateContainer.md)` || Request Body |
| Name | Type | Required | Description |
| :------------------ | :------------------------------------------------------ | :------- | :----------- |
| reallocateContainer | [ReallocateContainer](../models/ReallocateContainer.md) || Request Body |

**Example Usage Code Snippet**

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>com.salad.cloud</groupId>
<artifactId>imds-sdk</artifactId>
<version>0.9.0-alpha.2</version>
<version>0.9.0-alpha.3</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>com.salad.cloud</groupId>
<artifactId>imds-sdk</artifactId>
<version>0.9.0-alpha.2</version>
<version>0.9.0-alpha.3</version>

<!-- See https://central.sonatype.org/publish/requirements/#project-name-description-and-url -->
<name>${project.groupId}:${project.artifactId}</name>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/salad/cloud/imdssdk/validation/Violation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.salad.cloud.imdssdk.validation;

public class Violation {

private final String path;
private final String message;

public Violation(String path, String message) {
this.path = path;
this.message = message;
}

public String getPath() {
return path;
}

public String getMessage() {
return message;
}

@Override
public String toString() {
return String.format("%s: %s", path, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.salad.cloud.imdssdk.validation;

import com.salad.cloud.imdssdk.validation.exceptions.ValidationException;
import com.salad.cloud.imdssdk.validation.validators.AbstractValidator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ViolationAggregator {

List<Violation> violations = new ArrayList<>();

public <T> ViolationAggregator add(AbstractValidator<T> validator, T value) {
Violation[] violations = validator.validate(value);
if (violations.length > 0) {
this.violations.addAll(Arrays.asList(violations));
}
return this;
}

public Violation[] aggregate() {
return violations.toArray(new Violation[0]);
}

public void validateAll() {
if (!violations.isEmpty()) {
throw new ValidationException(aggregate());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.salad.cloud.imdssdk.validation.exceptions;

import com.salad.cloud.imdssdk.validation.Violation;
import lombok.Getter;

public class ValidationException extends RuntimeException {

@Getter
private final Violation[] violations;

public ValidationException(Violation[] violations) {
super();
this.violations = violations;
}

@Override
public String getMessage() {
return "Validation failed with the following violations: " + this.buildViolationsString();
}

private String buildViolationsString() {
StringBuilder sb = new StringBuilder();
for (Violation violation : this.violations) {
sb.append(violation.toString()).append("\n");
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.salad.cloud.imdssdk.validation.validators;

public abstract class AbstractValidator<T> implements Validator<T> {

private String fieldName;

public AbstractValidator(String fieldName) {
this.fieldName = fieldName;
}

public AbstractValidator() {
this.fieldName = "";
}

public String getFieldName() {
return fieldName;
}

public AbstractValidator<T> setFieldName(String fieldName) {
this.fieldName = fieldName;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.salad.cloud.imdssdk.validation.validators;

import com.salad.cloud.imdssdk.validation.Violation;
import java.util.ArrayList;
import java.util.List;

public class ListValidator<T> extends AbstractValidator<List<T>> {

private AbstractValidator<T> itemValidator;
private Integer minLength;
private Integer maxLength;
private Boolean uniqueItems;

public ListValidator(String fieldName) {
super(fieldName);
}

public ListValidator() {}

public ListValidator<T> minLength(Integer minLength) {
this.minLength = minLength;
return this;
}

public ListValidator<T> maxLength(Integer maxLength) {
this.maxLength = maxLength;
return this;
}

public ListValidator<T> uniqueItems(Boolean uniqueItems) {
this.uniqueItems = uniqueItems;
return this;
}

public ListValidator<T> itemValidator(AbstractValidator<T> itemValidator) {
this.itemValidator = itemValidator;
return this;
}

@Override
public Violation[] validate(List<T> list) {
List<Violation> errors = new ArrayList<>();

if (minLength != null && list.size() < minLength) {
errors.add(new Violation(getFieldName(), String.format("must have at least %d items", minLength)));
}

if (maxLength != null && list.size() > maxLength) {
errors.add(new Violation(getFieldName(), String.format("must have at most %d items", maxLength)));
}

if (uniqueItems != null && list.stream().distinct().count() != list.size()) {
errors.add(new Violation(getFieldName(), "must have unique items"));
}

if (itemValidator != null) {
for (int i = 0; i < list.size(); i++) {
T item = list.get(i);
Violation[] itemErrors = itemValidator.setFieldName(String.valueOf(i)).validate(item);
for (Violation itemError : itemErrors) {
errors.add(
new Violation(String.format("%s[%s]", getFieldName(), itemValidator.getFieldName()), itemError.getMessage())
);
}
}
}

return errors.toArray(new Violation[0]);
}
}
Loading

0 comments on commit 1c97e66

Please sign in to comment.