From 89737518482f3c9c9106a9eb9d666e6a46a51992 Mon Sep 17 00:00:00 2001 From: Stefan Yonkov Date: Wed, 9 Oct 2024 09:38:13 +0300 Subject: [PATCH] Introduce CNB as a new LifecycleType --- .../v3/packages/ReactorPackagesTest.java | 68 ++++++++++++++++--- .../packages/GET_{id}_droplets_response.json | 44 +++++++++++- .../cloudfoundry/client/v3/LifecycleType.java | 6 +- .../org/cloudfoundry/client/v3/_CnbData.java | 47 +++++++++++++ .../cloudfoundry/client/v3/_Lifecycle.java | 3 +- 5 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_CnbData.java diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/packages/ReactorPackagesTest.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/packages/ReactorPackagesTest.java index 6c7a65b141..6ac5f2792c 100644 --- a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/packages/ReactorPackagesTest.java +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/packages/ReactorPackagesTest.java @@ -29,16 +29,7 @@ import java.nio.charset.Charset; import java.time.Duration; import java.util.Collections; -import org.cloudfoundry.client.v3.BuildpackData; -import org.cloudfoundry.client.v3.Checksum; -import org.cloudfoundry.client.v3.ChecksumType; -import org.cloudfoundry.client.v3.KpackData; -import org.cloudfoundry.client.v3.Lifecycle; -import org.cloudfoundry.client.v3.LifecycleType; -import org.cloudfoundry.client.v3.Link; -import org.cloudfoundry.client.v3.Pagination; -import org.cloudfoundry.client.v3.Relationship; -import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.*; import org.cloudfoundry.client.v3.droplets.Buildpack; import org.cloudfoundry.client.v3.droplets.DropletResource; import org.cloudfoundry.client.v3.droplets.DropletState; @@ -497,7 +488,7 @@ void listDroplets() { ListPackageDropletsResponse.builder() .pagination( Pagination.builder() - .totalResults(3) + .totalResults(4) .totalPages(1) .first( Link.builder() @@ -627,6 +618,61 @@ void listDroplets() { .method("PATCH") .build()) .build()) + .resource( + DropletResource.builder() + .id("e351a2f2-dfc6-454b-8777-60ed2ff98edb") + .state(DropletState.STAGED) + .error(null) + .lifecycle( + Lifecycle.builder() + .type(LifecycleType.CNB) + .data(CnbData.builder().build()) + .build()) + .image(null) + .executionMetadata("PRIVATE DATA HIDDEN") + .processType( + "redacted_message", + "[PRIVATE DATA HIDDEN IN LISTS]") + .checksum( + Checksum.builder() + .type(ChecksumType.SHA256) + .value( + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") + .build()) + .buildpack( + Buildpack.builder() + .name("ruby_buildpack") + .detectOutput("ruby 1.6.14") + .build()) + .stack("cflinuxfs2") + .createdAt("2016-03-28T23:39:34Z") + .updatedAt("2016-03-28T23:39:47Z") + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/droplets/e351a2f2-dfc6-454b-8777-60ed2ff98edb") + .build()) + .link( + "package", + Link.builder() + .href( + "https://api.example.org/v3/packages/45c63fe0-f5f4-4f23-963e-a8311193d11e") + .build()) + .link( + "app", + Link.builder() + .href( + "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058398") + .build()) + .link( + "assign_current_droplet", + Link.builder() + .href( + "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058398/relationships/current_droplet") + .method("PATCH") + .build()) + .build()) .resource( DropletResource.builder() .id("fdf3851c-def8-4de1-87f1-6d4543189e22") diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/packages/GET_{id}_droplets_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/packages/GET_{id}_droplets_response.json index be2e3b946a..64bb8756c0 100644 --- a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/packages/GET_{id}_droplets_response.json +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/packages/GET_{id}_droplets_response.json @@ -1,6 +1,6 @@ { "pagination": { - "total_results": 3, + "total_results": 4, "total_pages": 1, "first": { "href": "https://api.example.org/v3/packages/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50" @@ -98,6 +98,48 @@ } } }, + { + "guid": "e351a2f2-dfc6-454b-8777-60ed2ff98edb", + "state": "STAGED", + "error": null, + "lifecycle": { + "type": "cnb", + "data": {} + }, + "image": null, + "execution_metadata": "PRIVATE DATA HIDDEN", + "process_types": { + "redacted_message": "[PRIVATE DATA HIDDEN IN LISTS]" + }, + "checksum": { + "type": "sha256", + "value": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "buildpacks": [ + { + "name": "ruby_buildpack", + "detect_output": "ruby 1.6.14" + } + ], + "stack": "cflinuxfs2", + "created_at": "2016-03-28T23:39:34Z", + "updated_at": "2016-03-28T23:39:47Z", + "links": { + "self": { + "href": "https://api.example.org/v3/droplets/e351a2f2-dfc6-454b-8777-60ed2ff98edb" + }, + "package": { + "href": "https://api.example.org/v3/packages/45c63fe0-f5f4-4f23-963e-a8311193d11e" + }, + "app": { + "href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058398" + }, + "assign_current_droplet": { + "href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058398/relationships/current_droplet", + "method": "PATCH" + } + } + }, { "guid": "fdf3851c-def8-4de1-87f1-6d4543189e22", "state": "STAGED", diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/LifecycleType.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/LifecycleType.java index 4a5d0408e0..953d731df3 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/LifecycleType.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/LifecycleType.java @@ -24,7 +24,9 @@ public enum LifecycleType { DOCKER("docker"), - KPACK("kpack"); + KPACK("kpack"), + + CNB("cnb"); private final String value; @@ -41,6 +43,8 @@ public static LifecycleType from(String s) { return DOCKER; case "kpack": return KPACK; + case "cnb": + return CNB; default: throw new IllegalArgumentException(String.format("Unknown lifecycle type: %s", s)); } diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_CnbData.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_CnbData.java new file mode 100644 index 0000000000..a3fafea714 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_CnbData.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +import java.util.List; + +/** + * Data type for the Buildpack + */ +@JsonDeserialize +@Value.Immutable +abstract class _CnbData implements LifecycleData { + + /** + * The buildpack + */ + @JsonProperty("buildpacks") + @Nullable + abstract List getBuildpacks(); + + /** + * The stack + */ + @JsonProperty("stack") + @Nullable + abstract String getStack(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Lifecycle.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Lifecycle.java index 054b6c6c38..8a691bb415 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Lifecycle.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Lifecycle.java @@ -36,7 +36,8 @@ abstract class _Lifecycle { @JsonSubTypes({ @JsonSubTypes.Type(name = "buildpack", value = BuildpackData.class), @JsonSubTypes.Type(name = "docker", value = DockerData.class), - @JsonSubTypes.Type(name = "kpack", value = KpackData.class) + @JsonSubTypes.Type(name = "kpack", value = KpackData.class), + @JsonSubTypes.Type(name = "cnb", value = CnbData.class) }) @JsonProperty("data") abstract LifecycleData getData();