diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java index 7e43bd5820..769e278aad 100644 --- a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java @@ -16,6 +16,7 @@ package org.cloudfoundry.reactor.client; +import jakarta.annotation.PostConstruct; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.ApplicationsV2; import org.cloudfoundry.client.v2.applicationusageevents.ApplicationUsageEvents; @@ -34,8 +35,6 @@ import org.cloudfoundry.client.v2.routemappings.RouteMappings; import org.cloudfoundry.client.v2.routes.Routes; import org.cloudfoundry.client.v2.securitygroups.SecurityGroups; -import org.cloudfoundry.client.v3.organizationquotadefinitions.OrganizationQuotaDefinitionsV3; -import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v2.servicebindings.ServiceBindingsV2; import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokers; import org.cloudfoundry.client.v2.serviceinstances.ServiceInstances; @@ -60,17 +59,20 @@ import org.cloudfoundry.client.v3.droplets.Droplets; import org.cloudfoundry.client.v3.isolationsegments.IsolationSegments; import org.cloudfoundry.client.v3.jobs.JobsV3; +import org.cloudfoundry.client.v3.organizationquotadefinitions.OrganizationQuotaDefinitionsV3; import org.cloudfoundry.client.v3.organizations.OrganizationsV3; import org.cloudfoundry.client.v3.packages.Packages; import org.cloudfoundry.client.v3.processes.Processes; import org.cloudfoundry.client.v3.resourcematch.ResourceMatchV3; import org.cloudfoundry.client.v3.roles.RolesV3; import org.cloudfoundry.client.v3.routes.RoutesV3; -import org.cloudfoundry.client.v3.serviceinstances.ServiceInstancesV3; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3; import org.cloudfoundry.client.v3.servicebrokers.ServiceBrokersV3; +import org.cloudfoundry.client.v3.serviceinstances.ServiceInstancesV3; import org.cloudfoundry.client.v3.serviceofferings.ServiceOfferingsV3; import org.cloudfoundry.client.v3.serviceplans.ServicePlansV3; +import org.cloudfoundry.client.v3.spacequotas.SpaceQuotasV3; import org.cloudfoundry.client.v3.spaces.SpacesV3; import org.cloudfoundry.client.v3.stacks.StacksV3; import org.cloudfoundry.client.v3.tasks.Tasks; @@ -93,8 +95,6 @@ import org.cloudfoundry.reactor.client.v2.routemappings.ReactorRouteMappings; import org.cloudfoundry.reactor.client.v2.routes.ReactorRoutes; import org.cloudfoundry.reactor.client.v2.securitygroups.ReactorSecurityGroups; -import org.cloudfoundry.reactor.client.v3.organizationquotadefinitions.ReactorOrganizationQuotaDefinitionsV3; -import org.cloudfoundry.reactor.client.v3.securitygroups.ReactorSecurityGroupsV3; import org.cloudfoundry.reactor.client.v2.servicebindings.ReactorServiceBindingsV2; import org.cloudfoundry.reactor.client.v2.servicebrokers.ReactorServiceBrokers; import org.cloudfoundry.reactor.client.v2.serviceinstances.ReactorServiceInstances; @@ -119,24 +119,26 @@ import org.cloudfoundry.reactor.client.v3.droplets.ReactorDroplets; import org.cloudfoundry.reactor.client.v3.isolationsegments.ReactorIsolationSegments; import org.cloudfoundry.reactor.client.v3.jobs.ReactorJobsV3; +import org.cloudfoundry.reactor.client.v3.organizationquotadefinitions.ReactorOrganizationQuotaDefinitionsV3; import org.cloudfoundry.reactor.client.v3.organizations.ReactorOrganizationsV3; import org.cloudfoundry.reactor.client.v3.packages.ReactorPackages; import org.cloudfoundry.reactor.client.v3.processes.ReactorProcesses; import org.cloudfoundry.reactor.client.v3.resourcematch.ReactorResourceMatchV3; import org.cloudfoundry.reactor.client.v3.roles.ReactorRolesV3; import org.cloudfoundry.reactor.client.v3.routes.ReactorRoutesV3; +import org.cloudfoundry.reactor.client.v3.securitygroups.ReactorSecurityGroupsV3; import org.cloudfoundry.reactor.client.v3.servicebindings.ReactorServiceBindingsV3; import org.cloudfoundry.reactor.client.v3.servicebrokers.ReactorServiceBrokersV3; import org.cloudfoundry.reactor.client.v3.serviceinstances.ReactorServiceInstancesV3; import org.cloudfoundry.reactor.client.v3.serviceofferings.ReactorServiceOfferingsV3; import org.cloudfoundry.reactor.client.v3.serviceplans.ReactorServicePlansV3; +import org.cloudfoundry.reactor.client.v3.spacequotas.ReactorSpaceQuotasV3; import org.cloudfoundry.reactor.client.v3.spaces.ReactorSpacesV3; import org.cloudfoundry.reactor.client.v3.stacks.ReactorStacksV3; import org.cloudfoundry.reactor.client.v3.tasks.ReactorTasks; import org.immutables.value.Value; import reactor.core.publisher.Mono; -import jakarta.annotation.PostConstruct; import java.util.Collections; import java.util.Map; @@ -457,6 +459,13 @@ public SpaceQuotaDefinitions spaceQuotaDefinitions() { getRequestTags()); } + @Override + @Value.Derived + public SpaceQuotasV3 spaceQuotasV3() { + return new ReactorSpaceQuotasV3(getConnectionContext(), getRootV3(), getTokenProvider(), + getRequestTags()); + } + @Override @Value.Derived public Spaces spaces() { diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3.java new file mode 100644 index 0000000000..efbcc82676 --- /dev/null +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3.java @@ -0,0 +1,91 @@ +/* + * Copyright 2013-2025 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.reactor.client.v3.spacequotas; + +import java.util.Map; +import org.cloudfoundry.client.v3.spacequotas.*; +import org.cloudfoundry.client.v3.spacequotas.CreateSpaceQuotaResponse; +import org.cloudfoundry.reactor.ConnectionContext; +import org.cloudfoundry.reactor.TokenProvider; +import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; +import reactor.core.publisher.Mono; + +/** + * The Reactor-based implementation of {@link ReactorSpaceQuotasV3} + */ +public class ReactorSpaceQuotasV3 extends AbstractClientV3Operations implements SpaceQuotasV3 { + + /** + * Creates an instance + * + * @param connectionContext the {@link ConnectionContext} to use when communicating with the server + * @param root the root URI of the server. Typically, something like {@code https://api.run.pivotal.io}. + * @param tokenProvider the {@link TokenProvider} to use when communicating with the server + * @param requestTags map with custom http headers which will be added to web request + */ + public ReactorSpaceQuotasV3( + ConnectionContext connectionContext, + Mono root, + TokenProvider tokenProvider, + Map requestTags) { + super(connectionContext, root, tokenProvider, requestTags); + } + + @Override + public Mono create(CreateSpaceQuotaRequest request) { + return post( + request, + CreateSpaceQuotaResponse.class, + builder -> builder.pathSegment("space_quotas")) + .checkpoint(); + } + + @Override + public Mono get(GetSpaceQuotaRequest request) { + return get( + request, + GetSpaceQuotaResponse.class, + builder -> builder.pathSegment("space_quotas", request.getSpaceQuotaId())) + .checkpoint(); + } + + @Override + public Mono list(ListSpaceQuotasRequest request) { + return get( + request, + ListSpaceQuotasResponse.class, + builder -> builder.pathSegment("space_quotas")) + .checkpoint(); + } + + @Override + public Mono update(UpdateSpaceQuotaRequest request) { + return patch( + request, + UpdateSpaceQuotaResponse.class, + builder -> builder.pathSegment("space_quotas", request.getSpaceQuotaId())) + .checkpoint(); + } + + @Override + public Mono delete(DeleteSpaceQuotaRequest request) { + return delete( + request, + builder -> builder.pathSegment("space_quotas", request.getSpaceQuotaId())) + .checkpoint(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3Test.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3Test.java new file mode 100644 index 0000000000..957f8a21bd --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotas/ReactorSpaceQuotasV3Test.java @@ -0,0 +1,317 @@ +/* + * Copyright 2013-2025 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.reactor.client.v3.spacequotas; + +import static io.netty.handler.codec.http.HttpMethod.DELETE; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpMethod.PATCH; +import static io.netty.handler.codec.http.HttpMethod.POST; +import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; + +import java.time.Duration; +import java.util.Collections; +import org.cloudfoundry.client.v3.Link; +import org.cloudfoundry.client.v3.Pagination; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToManyRelationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.cloudfoundry.client.v3.spacequotas.*; +import org.cloudfoundry.client.v3.spacequotas.SpaceQuotaResource; +import org.cloudfoundry.reactor.InteractionContext; +import org.cloudfoundry.reactor.TestRequest; +import org.cloudfoundry.reactor.TestResponse; +import org.cloudfoundry.reactor.client.AbstractClientApiTest; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; +import reactor.test.StepVerifier; + +class ReactorSpaceQuotasV3Test extends AbstractClientApiTest { + + public static final String EXPECTED_SPACE_QUOTA_ID_1 = "f919ef8a-e333-472a-8172-baaf2c30d301"; + + private final ReactorSpaceQuotasV3 spaceQuotasV3 = + new ReactorSpaceQuotasV3( + CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap()); + + @Test + void create() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(POST) + .path("/space_quotas") + .payload( + "fixtures/client/v3/space_quotas/POST_request.json") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/space_quotas/POST_response.json") + .build()) + .build()); + + SpaceQuotaRelationships relationships = + SpaceQuotaRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id("9b370018-c38e-44c9-86d6-155c76801104") + .build()) + .build()) + .spaces( + ToManyRelationship.builder() + .data( + Collections.singletonList( + Relationship.builder() + .id( + "dcfd6a55-62b9-496e-a26f-0064cec076bf") + .build())) + .build()) + .build(); + this.spaceQuotasV3 + .create( + CreateSpaceQuotaRequest.builder() + .name("my-quota") + .relationships(relationships) + .build()) + .as(StepVerifier::create) + .expectNext( + CreateSpaceQuotaResponse.builder() + .from(expectedSpaceQuotaResource1()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void delete() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(DELETE) + .path("/space_quotas/test-space-quota-id") + .build()) + .response( + TestResponse.builder() + .status(ACCEPTED) + .header( + "Location", + "https://api.example.org/v3/jobs/test-job-id") + .build()) + .build()); + + this.spaceQuotasV3 + .delete( + DeleteSpaceQuotaRequest.builder() + .spaceQuotaId("test-space-quota-id") + .build()) + .as(StepVerifier::create) + .expectNext("test-job-id") + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void get() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(GET) + .path("/space_quotas/" + EXPECTED_SPACE_QUOTA_ID_1) + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/space_quotas/GET_{id}_response.json") + .build()) + .build()); + + this.spaceQuotasV3 + .get(GetSpaceQuotaRequest.builder().spaceQuotaId(EXPECTED_SPACE_QUOTA_ID_1).build()) + .as(StepVerifier::create) + .expectNext( + GetSpaceQuotaResponse.builder().from(expectedSpaceQuotaResource1()).build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void list() { + mockRequest( + InteractionContext.builder() + .request(TestRequest.builder().method(GET).path("/space_quotas").build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/space_quotas/GET_response.json") + .build()) + .build()); + + this.spaceQuotasV3 + .list(ListSpaceQuotasRequest.builder().build()) + .as(StepVerifier::create) + .expectNext( + ListSpaceQuotasResponse.builder() + .pagination( + Pagination.builder() + .totalResults(2) + .totalPages(1) + .first( + Link.builder() + .href( + "https://api.example.org/v3/space_quotas?page=1&per_page=50") + .build()) + .last( + Link.builder() + .href( + "https://api.example.org/v3/space_quotas?page=1&per_page=50") + .build()) + .build()) + .resource( + SpaceQuotaResource.builder() + .from(expectedSpaceQuotaResource1()) + .build()) + .resource( + SpaceQuotaResource.builder() + .from(expectedSpaceQuotaResource2()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + void update() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(PATCH) + .path("/space_quotas/" + EXPECTED_SPACE_QUOTA_ID_1) + .payload( + "fixtures/client/v3/space_quotas/PATCH_{id}_request.json") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/space_quotas/PATCH_{id}_response.json") + .build()) + .build()); + + this.spaceQuotasV3 + .update( + UpdateSpaceQuotaRequest.builder() + .spaceQuotaId(EXPECTED_SPACE_QUOTA_ID_1) + .build()) + .as(StepVerifier::create) + .expectNext( + UpdateSpaceQuotaResponse.builder() + .from(expectedSpaceQuotaResource1()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @NotNull + private static SpaceQuotaResource expectedSpaceQuotaResource1() { + return buildSpaceQuotaResource( + EXPECTED_SPACE_QUOTA_ID_1, + "my-quota", + "9b370018-c38e-44c9-86d6-155c76801104", + "dcfd6a55-62b9-496e-a26f-0064cec076bf"); + } + + private static SpaceQuotaResource expectedSpaceQuotaResource2() { + return buildSpaceQuotaResource( + "bb49bf20-ad98-4729-93ae-38fbc564b630", + "my-quota-2", + "9b370018-c38e-44c9-86d6-155c76801104", + null); + } + + @NotNull + private static SpaceQuotaResource buildSpaceQuotaResource( + String id, String name, String relatedOrganizationId, String relatedSpaceId) { + + Apps apps = + Apps.builder() + .totalMemoryInMb(5120) + .perProcessMemoryInMb(1024) + .totalInstances(10) + .perAppTasks(5) + .build(); + Services services = + Services.builder() + .isPaidServicesAllowed(true) + .totalServiceInstances(10) + .totalServiceKeys(20) + .build(); + Routes routes = Routes.builder().totalRoutes(8).totalReservedPorts(4).build(); + + ToOneRelationship organizationRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(relatedOrganizationId).build()) + .build(); + ToManyRelationship spaceRelationships = + ToManyRelationship.builder().data(Collections.emptyList()).build(); + if (relatedSpaceId != null) { + spaceRelationships = + ToManyRelationship.builder() + .data( + Collections.singletonList( + Relationship.builder().id(relatedSpaceId).build())) + .build(); + } + SpaceQuotaRelationships relationships = + SpaceQuotaRelationships.builder() + .organization(organizationRelationship) + .spaces(spaceRelationships) + .build(); + + return SpaceQuotaResource.builder() + .createdAt("2016-05-04T17:00:41Z") + .id(id) + .link( + "self", + Link.builder() + .href("https://api.example.org/v3/space_quotas/" + id) + .build()) + .link( + "organization", + Link.builder() + .href( + "https://api.example.org/v3/organizations/" + + relatedOrganizationId) + .build()) + .name(name) + .updatedAt("2016-05-04T18:00:41Z") + .apps(apps) + .services(services) + .routes(routes) + .relationships(relationships) + .build(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_response.json new file mode 100644 index 0000000000..c695fa74b7 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_response.json @@ -0,0 +1,98 @@ +{ + "pagination": { + "total_results": 2, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/space_quotas?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/space_quotas?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "guid": "f919ef8a-e333-472a-8172-baaf2c30d301", + "created_at": "2016-05-04T17:00:41Z", + "updated_at": "2016-05-04T18:00:41Z", + "name": "my-quota", + "apps": { + "total_memory_in_mb": 5120, + "per_process_memory_in_mb": 1024, + "total_instances": 10, + "per_app_tasks": 5 + }, + "services": { + "paid_services_allowed": true, + "total_service_instances": 10, + "total_service_keys": 20 + }, + "routes": { + "total_routes": 8, + "total_reserved_ports": 4 + }, + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [ + { + "guid": "dcfd6a55-62b9-496e-a26f-0064cec076bf" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/space_quotas/f919ef8a-e333-472a-8172-baaf2c30d301" + }, + "organization": { + "href": "https://api.example.org/v3/organizations/9b370018-c38e-44c9-86d6-155c76801104" + } + } + }, + { + "guid": "bb49bf20-ad98-4729-93ae-38fbc564b630", + "created_at": "2016-05-04T17:00:41Z", + "updated_at": "2016-05-04T18:00:41Z", + "name": "my-quota-2", + "apps": { + "total_memory_in_mb": 5120, + "per_process_memory_in_mb": 1024, + "total_instances": 10, + "per_app_tasks": 5 + }, + "services": { + "paid_services_allowed": true, + "total_service_instances": 10, + "total_service_keys": 20 + }, + "routes": { + "total_routes": 8, + "total_reserved_ports": 4 + }, + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/space_quotas/bb49bf20-ad98-4729-93ae-38fbc564b630" + }, + "organization": { + "href": "https://api.example.org/v3/organizations/9b370018-c38e-44c9-86d6-155c76801104" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_{id}_response.json new file mode 100644 index 0000000000..c90b41bbd2 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/GET_{id}_response.json @@ -0,0 +1,43 @@ +{ + "guid": "f919ef8a-e333-472a-8172-baaf2c30d301", + "created_at": "2016-05-04T17:00:41Z", + "updated_at": "2016-05-04T18:00:41Z", + "name": "my-quota", + "apps": { + "total_memory_in_mb": 5120, + "per_process_memory_in_mb": 1024, + "total_instances": 10, + "per_app_tasks": 5 + }, + "services": { + "paid_services_allowed": true, + "total_service_instances": 10, + "total_service_keys": 20 + }, + "routes": { + "total_routes": 8, + "total_reserved_ports": 4 + }, + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [ + { + "guid": "dcfd6a55-62b9-496e-a26f-0064cec076bf" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/space_quotas/f919ef8a-e333-472a-8172-baaf2c30d301" + }, + "organization": { + "href": "https://api.example.org/v3/organizations/9b370018-c38e-44c9-86d6-155c76801104" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_request.json new file mode 100644 index 0000000000..7a73a41bfd --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_request.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_response.json new file mode 100644 index 0000000000..c90b41bbd2 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/PATCH_{id}_response.json @@ -0,0 +1,43 @@ +{ + "guid": "f919ef8a-e333-472a-8172-baaf2c30d301", + "created_at": "2016-05-04T17:00:41Z", + "updated_at": "2016-05-04T18:00:41Z", + "name": "my-quota", + "apps": { + "total_memory_in_mb": 5120, + "per_process_memory_in_mb": 1024, + "total_instances": 10, + "per_app_tasks": 5 + }, + "services": { + "paid_services_allowed": true, + "total_service_instances": 10, + "total_service_keys": 20 + }, + "routes": { + "total_routes": 8, + "total_reserved_ports": 4 + }, + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [ + { + "guid": "dcfd6a55-62b9-496e-a26f-0064cec076bf" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/space_quotas/f919ef8a-e333-472a-8172-baaf2c30d301" + }, + "organization": { + "href": "https://api.example.org/v3/organizations/9b370018-c38e-44c9-86d6-155c76801104" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_request.json new file mode 100644 index 0000000000..59745ba5ea --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_request.json @@ -0,0 +1,17 @@ +{ + "name": "my-quota", + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [ + { + "guid": "dcfd6a55-62b9-496e-a26f-0064cec076bf" + } + ] + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_response.json new file mode 100644 index 0000000000..883b8ef463 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/space_quotas/POST_response.json @@ -0,0 +1,43 @@ +{ + "guid": "f919ef8a-e333-472a-8172-baaf2c30d301", + "created_at": "2016-05-04T17:00:41Z", + "updated_at": "2016-05-04T18:00:41Z", + "name": "my-quota", + "apps": { + "total_memory_in_mb": 5120, + "per_process_memory_in_mb": 1024, + "total_instances": 10, + "per_app_tasks": 5 + }, + "services": { + "paid_services_allowed": true, + "total_service_instances": 10, + "total_service_keys": 20 + }, + "routes": { + "total_routes": 8, + "total_reserved_ports": 4 + }, + "relationships": { + "organization": { + "data": { + "guid": "9b370018-c38e-44c9-86d6-155c76801104" + } + }, + "spaces": { + "data": [ + { + "guid": "dcfd6a55-62b9-496e-a26f-0064cec076bf" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/space_quotas/f919ef8a-e333-472a-8172-baaf2c30d301" + }, + "organization": { + "href": "https://api.example.org/v3/organizations/9b370018-c38e-44c9-86d6-155c76801104" + } + } +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java index d5339f3512..d7b9b7612f 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java @@ -70,6 +70,7 @@ import org.cloudfoundry.client.v3.serviceinstances.ServiceInstancesV3; import org.cloudfoundry.client.v3.serviceofferings.ServiceOfferingsV3; import org.cloudfoundry.client.v3.serviceplans.ServicePlansV3; +import org.cloudfoundry.client.v3.spacequotas.SpaceQuotasV3; import org.cloudfoundry.client.v3.spaces.SpacesV3; import org.cloudfoundry.client.v3.stacks.StacksV3; import org.cloudfoundry.client.v3.tasks.Tasks; @@ -334,6 +335,11 @@ public interface CloudFoundryClient { */ SpaceQuotaDefinitions spaceQuotaDefinitions(); + /** + * Main entry point to the Cloud Foundry Space V3 Client API + */ + SpaceQuotasV3 spaceQuotasV3(); + /** * Main entry point to the Cloud Foundry Spaces V2 Client API */ diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuota.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuota.java new file mode 100644 index 0000000000..4125369e1f --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuota.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.Resource; + +/** + * Base class for responses that are Space Quotas + */ +public abstract class SpaceQuota extends Resource { + + /** + * Name of the quota + */ + @JsonProperty("name") + abstract String getName(); + + /** + * Quotas that affect applications and application sub-resources + */ + @JsonProperty("apps") + @Nullable + abstract Apps getApps(); + + /** + * Quotas that affect services + */ + @JsonProperty("services") + @Nullable + abstract Services getServices(); + + /** + * Quotas that affect routes + */ + @JsonProperty("routes") + @Nullable + abstract Routes getRoutes(); + + /** + * A relationship to the space where the quota is applied + * A space quota must have a relationship to an organization + */ + @JsonProperty("relationships") + abstract SpaceQuotaRelationships getRelationships(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuotasV3.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuotasV3.java new file mode 100644 index 0000000000..8d0ebe48b9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/SpaceQuotasV3.java @@ -0,0 +1,69 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import reactor.core.publisher.Mono; + +/** + * Main entry point to the Cloud Foundry Space Quota Client API + */ +public interface SpaceQuotasV3 { + + /** + * Makes the Create Space Quota + * request + * + * @param request the Create Space Quota request + * @return the response from the Create Space Quota request + */ + Mono create(CreateSpaceQuotaRequest request); + + /** + * Makes the Get Space Quota + * request + * + * @param request the Get Space Quota request + * @return the response from the Get Space Quota request + */ + Mono get(GetSpaceQuotaRequest request); + + /** + * Makes the List all Space Quota + * request + * + * @param request the List all Space Quotas request + * @return the response from the Space all Organization Quotas request + */ + Mono list(ListSpaceQuotasRequest request); + + /** Makes the Update Space Quota + * request + * + * @param request the Update Space Quota request + * @return the response from the Update Space Quota request + */ + Mono update(UpdateSpaceQuotaRequest request); + + /** + * Makes the Delete Space Quota + * request + * + * @param request the Delete Space Quota request + * @return the response from the Space Organization Quota request + */ + Mono delete(DeleteSpaceQuotaRequest request); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Apps.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Apps.java new file mode 100644 index 0000000000..0b61bd3df8 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Apps.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * Quotas that affect applications and application sub-resources + */ +@JsonDeserialize +@Value.Immutable +abstract class _Apps { + + /** + * Maximum memory for a single process or task + * @return the maximum memory for a single process or task + */ + @JsonProperty("per_process_memory_in_mb") + @Nullable + abstract Integer getPerProcessMemoryInMb(); + + /** + * Total memory allowed for all the started processes and running tasks in a space + * @return the total memory allowed for all the started processes and running tasks in a space + */ + @JsonProperty("total_memory_in_mb") + @Nullable + abstract Integer getTotalMemoryInMb(); + + /** + * Total instances of all the started processes allowed in a space + * @return the total instances of all the started processes allowed in a space + */ + @JsonProperty("total_instances") + @Nullable + abstract Integer getTotalInstances(); + + /** + * Total log rate limit allowed for all the started processes and running tasks in a space + */ + @JsonProperty("log_rate_limit_in_bytes_per_second") + @Nullable + abstract Integer getLogRateLimitInBytesPerSecond(); + + /** + * Maximum number of running tasks in a space + * @return the maximum number of running tasks in a space + */ + @JsonProperty("per_app_tasks") + @Nullable + abstract Integer getPerAppTasks(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaRequest.java new file mode 100644 index 0000000000..6c54d0e583 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaRequest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * The request payload to Create a new Space Quota + */ +@JsonSerialize +@Value.Immutable +abstract class _CreateSpaceQuotaRequest { + + /** + * Name of the quota + */ + @JsonProperty("name") + abstract String getName(); + + /** + * A relationship to the organizations and spaces where the quota is applied + */ + @JsonProperty("relationships") + abstract SpaceQuotaRelationships getRelationships(); + + /** + * Quotas that affect applications and application sub-resources + */ + @JsonProperty("apps") + @Nullable + abstract Apps getApps(); + + /** + * Quotas that affect services + */ + @JsonProperty("services") + @Nullable + abstract Services getServices(); + + /** + * Quotas that affect routes + */ + @JsonProperty("routes") + @Nullable + abstract Routes getRoutes(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaResponse.java new file mode 100644 index 0000000000..daaa0ca8ff --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_CreateSpaceQuotaResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Create a Space Quota + */ +@JsonDeserialize +@Value.Immutable +abstract class _CreateSpaceQuotaResponse extends SpaceQuota { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_DeleteSpaceQuotaRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_DeleteSpaceQuotaRequest.java new file mode 100644 index 0000000000..0ee5210677 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_DeleteSpaceQuotaRequest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Delete a Space Quota + */ +@Value.Immutable +abstract class _DeleteSpaceQuotaRequest { + + /** + * The space quota id + */ + @JsonIgnore + abstract String getSpaceQuotaId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaRequest.java new file mode 100644 index 0000000000..80dfe3e2d0 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaRequest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Retrieve a Particular Space Quota + */ +@Value.Immutable +abstract class _GetSpaceQuotaRequest { + + /** + * The space quota id + */ + @JsonIgnore + abstract String getSpaceQuotaId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaResponse.java new file mode 100644 index 0000000000..03b9cb677c --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_GetSpaceQuotaResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Retrieve a Particular Space Quota + */ +@JsonDeserialize +@Value.Immutable +abstract class _GetSpaceQuotaResponse extends SpaceQuota { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasRequest.java new file mode 100644 index 0000000000..f2728981b9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasRequest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.FilterParameter; +import org.cloudfoundry.client.v3.PaginatedRequest; +import org.immutables.value.Value; + +import java.util.List; + +/** + * The request payload for the List all Space Quotas + */ +@Value.Immutable +abstract class _ListSpaceQuotasRequest extends PaginatedRequest { + + /** + * Comma-delimited list of space quota guids to filter by + */ + @FilterParameter("guids") + @Nullable + abstract List getGuids(); + + /** + * Comma-delimited list of space quota names to filter by + */ + @FilterParameter("names") + @Nullable + abstract List getNames(); + + /** + * Comma-delimited list of organization guids to filter by + */ + @FilterParameter("organization_guids") + @Nullable + abstract List getOrganizationGuids(); + + /** + * Comma-delimited list of space guids to filter by + */ + @FilterParameter("space_guids") + @Nullable + abstract List getSpaceGuids(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasResponse.java new file mode 100644 index 0000000000..428078e538 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_ListSpaceQuotasResponse.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.client.v3.PaginatedResponse; +import org.immutables.value.Value; + +/** + * The response payload for the List all Space Quotas + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListSpaceQuotasResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Routes.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Routes.java new file mode 100644 index 0000000000..03451f2d18 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Routes.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * Quotas that affect routes + */ +@JsonDeserialize +@Value.Immutable +abstract class _Routes { + + /** + * Total number of routes allowed in a space + * + * @return the total number of routes allowed in a space + */ + @JsonProperty("total_routes") + @Nullable + abstract Integer getTotalRoutes(); + + /** + * Total number of ports that are reservable by routes in a space + * + * @return the total number of reserved ports allowed in a space + */ + @JsonProperty("total_reserved_ports") + @Nullable + abstract Integer getTotalReservedPorts(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Services.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Services.java new file mode 100644 index 0000000000..311e51b86a --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_Services.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * Quotas that affect services + */ +@JsonDeserialize +@Value.Immutable +abstract class _Services { + + /** + * Specifies whether instances of paid service plans can be created + * @return true if instances of paid service plans can be created, false otherwise + */ + @JsonProperty("paid_services_allowed") + abstract boolean isPaidServicesAllowed(); + + /** + * Total number of service instances allowed in a space + * @return the total number of service instances allowed in a space + */ + @JsonProperty("total_service_instances") + @Nullable + abstract Integer getTotalServiceInstances(); + + /** + * Total number of service keys allowed in a space + * @return the total number of service keys allowed in a space + */ + @JsonProperty("total_service_keys") + @Nullable + abstract Integer getTotalServiceKeys(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaRelationships.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaRelationships.java new file mode 100644 index 0000000000..2f1fd6d595 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaRelationships.java @@ -0,0 +1,47 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.ToManyRelationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.immutables.value.Value; + +/** + * The relationships for the Space Quota entity + */ + +@Value.Immutable +@JsonDeserialize +abstract class _SpaceQuotaRelationships { + + /** + * A relationship to the organization where the quota belongs + */ + @JsonProperty("organization") + abstract ToOneRelationship getOrganization(); + + /** + * A relationship to the spaces where the quota is applied + */ + @JsonProperty("spaces") + @Nullable + abstract ToManyRelationship getSpaces(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaResource.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaResource.java new file mode 100644 index 0000000000..54f13c8a7b --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_SpaceQuotaResource.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * Base class for resources that contain Space Quota + */ +@JsonDeserialize +@Value.Immutable +abstract class _SpaceQuotaResource extends SpaceQuota { + +} + diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaRequest.java new file mode 100644 index 0000000000..73728bf8b6 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaRequest.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * The request payload to update a Space Quota + */ +@JsonSerialize +@Value.Immutable +abstract class _UpdateSpaceQuotaRequest { + + /** + * The space quota id + */ + @JsonIgnore + abstract String getSpaceQuotaId(); + + /** + * Name of the quota + */ + @JsonProperty("name") + @Nullable + abstract String getName(); + + /** + * Quotas that affect applications and application sub-resources + */ + @JsonProperty("apps") + @Nullable + abstract Apps getApps(); + + /** + * Quotas that affect services + */ + @JsonProperty("services") + @Nullable + abstract Services getServices(); + + /** + * Quotas that affect routes + */ + @JsonProperty("routes") + @Nullable + abstract Routes getRoutes(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaResponse.java new file mode 100644 index 0000000000..e16a1d077d --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotas/_UpdateSpaceQuotaResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Update a Space Quota + */ +@JsonDeserialize +@Value.Immutable +abstract class _UpdateSpaceQuotaResponse extends SpaceQuota { + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/CreateSpaceQuotaRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/CreateSpaceQuotaRequestTest.java new file mode 100644 index 0000000000..be290c5957 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/CreateSpaceQuotaRequestTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.UUID; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToOneRelationship; +import org.junit.jupiter.api.Test; + +final class CreateSpaceQuotaRequestTest { + + @Test + void noName() { + assertThrows(IllegalStateException.class, () -> CreateSpaceQuotaRequest.builder().build()); + } + + @Test + void noOrganizationsRelationship() { + assertThrows( + IllegalStateException.class, + () -> CreateSpaceQuotaRequest.builder().name("test-quota").build()); + } + + @Test + void valid() { + + String organizationGuid = UUID.randomUUID().toString(); + ToOneRelationship organizationsRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(organizationGuid).build()) + .build(); + SpaceQuotaRelationships relationships = + SpaceQuotaRelationships.builder().organization(organizationsRelationship).build(); + CreateSpaceQuotaRequest.builder().name("test-quota").relationships(relationships).build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/DeleteSpaceQuotaRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/DeleteSpaceQuotaRequestTest.java new file mode 100644 index 0000000000..8216851d0c --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/DeleteSpaceQuotaRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class DeleteSpaceQuotaRequestTest { + + @Test + void noSpaceQuotaId() { + assertThrows(IllegalStateException.class, () -> DeleteSpaceQuotaRequest.builder().build()); + } + + @Test + void valid() { + DeleteSpaceQuotaRequest.builder().spaceQuotaId("test-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/GetSpaceQuotaRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/GetSpaceQuotaRequestTest.java new file mode 100644 index 0000000000..befab21151 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/GetSpaceQuotaRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class GetSpaceQuotaRequestTest { + + @Test + void noSpaceQuotaId() { + assertThrows(IllegalStateException.class, () -> GetSpaceQuotaRequest.builder().build()); + } + + @Test + void valid() { + GetSpaceQuotaRequest.builder().spaceQuotaId("test-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/ListSpaceQuotasRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/ListSpaceQuotasRequestTest.java new file mode 100644 index 0000000000..699c0451d5 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/ListSpaceQuotasRequestTest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import org.junit.jupiter.api.Test; + +public class ListSpaceQuotasRequestTest { + + @Test + void valid() { + ListSpaceQuotasRequest.builder().build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/UpdateSpaceQuotaRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/UpdateSpaceQuotaRequestTest.java new file mode 100644 index 0000000000..1b9b833f23 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotas/UpdateSpaceQuotaRequestTest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2025 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.spacequotas; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class UpdateSpaceQuotaRequestTest { + + @Test + void noSpaceQuotaId() { + assertThrows(IllegalStateException.class, () -> UpdateSpaceQuotaRequest.builder().build()); + } + + @Test + void valid() { + UpdateSpaceQuotaRequest.builder().spaceQuotaId("test-id").build(); + } +} diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotasTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotasTest.java new file mode 100644 index 0000000000..e66f27ead7 --- /dev/null +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotasTest.java @@ -0,0 +1,369 @@ +/* + * Copyright 2013-2025 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 static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import org.cloudfoundry.AbstractIntegrationTest; +import org.cloudfoundry.CloudFoundryVersion; +import org.cloudfoundry.IfCloudFoundryVersion; +import org.cloudfoundry.client.CloudFoundryClient; +import org.cloudfoundry.client.v3.organizations.CreateOrganizationRequest; +import org.cloudfoundry.client.v3.organizations.Organization; +import org.cloudfoundry.client.v3.spacequotas.*; +import org.cloudfoundry.client.v3.spacequotas.CreateSpaceQuotaResponse; +import org.cloudfoundry.client.v3.spacequotas.DeleteSpaceQuotaRequest; +import org.cloudfoundry.client.v3.spacequotas.GetSpaceQuotaRequest; +import org.cloudfoundry.client.v3.spacequotas.GetSpaceQuotaResponse; +import org.cloudfoundry.client.v3.spacequotas.ListSpaceQuotasRequest; +import org.cloudfoundry.client.v3.spacequotas.SpaceQuotaRelationships; +import org.cloudfoundry.client.v3.spacequotas.SpaceQuotaResource; +import org.cloudfoundry.client.v3.spacequotas.UpdateSpaceQuotaRequest; +import org.cloudfoundry.client.v3.spaces.CreateSpaceRequest; +import org.cloudfoundry.client.v3.spaces.Space; +import org.cloudfoundry.client.v3.spaces.SpaceRelationships; +import org.cloudfoundry.util.JobUtils; +import org.cloudfoundry.util.PaginationUtils; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +@IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) +public final class SpaceQuotasTest extends AbstractIntegrationTest { + + @Autowired private CloudFoundryClient cloudFoundryClient; + + private String organizationId; + private String spaceId; + + @BeforeEach + public void createOrganization() { + String orgName = this.nameFactory.getOrganizationName(); + String spaceName = this.nameFactory.getSpaceName(); + + organizationId = createOrganization(this.cloudFoundryClient, orgName).getId(); + spaceId = createSpace(this.cloudFoundryClient, organizationId, spaceName).getId(); + } + + @Test + public void create() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + SpaceQuotaRelationships spaceQuotaRelationships = + createSpaceQuotaRelationships(organizationId); + + Apps spaceQuotaAppLimits = + Apps.builder() + .perProcessMemoryInMb(1024) + .totalMemoryInMb(2048) + .logRateLimitInBytesPerSecond(0) + .build(); + Services spaceQuotaServiceLimits = + Services.builder().isPaidServicesAllowed(false).totalServiceInstances(10).build(); + Routes spaceQuotaRouteLimits = Routes.builder().totalRoutes(10).build(); + + this.cloudFoundryClient + .spaceQuotasV3() + .create( + CreateSpaceQuotaRequest.builder() + .name(spaceQuotaName) + .apps(spaceQuotaAppLimits) + .services(spaceQuotaServiceLimits) + .routes(spaceQuotaRouteLimits) + .relationships(spaceQuotaRelationships) + .build()) + .thenMany(requestListSpaceQuotas(this.cloudFoundryClient, spaceQuotaName)) + .single() + .as(StepVerifier::create) + .assertNext( + spaceQuotaResource -> { + assertThat(spaceQuotaResource).isNotNull(); + assertThat(spaceQuotaResource.getId()).isNotNull(); + assertThat(spaceQuotaResource.getName()).isEqualTo(spaceQuotaName); + assertThat(spaceQuotaResource.getApps()).isEqualTo(spaceQuotaAppLimits); + assertThat(spaceQuotaResource.getServices()) + .isEqualTo(spaceQuotaServiceLimits); + assertThat(spaceQuotaResource.getRoutes()) + .isEqualTo(spaceQuotaRouteLimits); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void createWithSpaceRelationship() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + SpaceQuotaRelationships spaceQuotaRelationships = + createSpaceQuotaRelationships(organizationId, spaceId); + + Apps spaceQuotaAppLimits = + Apps.builder() + .perProcessMemoryInMb(1024) + .totalMemoryInMb(2048) + .logRateLimitInBytesPerSecond(0) + .build(); + Services spaceQuotaServiceLimits = + Services.builder().isPaidServicesAllowed(false).totalServiceInstances(10).build(); + Routes spaceQuotaRouteLimits = Routes.builder().totalRoutes(10).build(); + + this.cloudFoundryClient + .spaceQuotasV3() + .create( + CreateSpaceQuotaRequest.builder() + .name(spaceQuotaName) + .apps(spaceQuotaAppLimits) + .services(spaceQuotaServiceLimits) + .routes(spaceQuotaRouteLimits) + .relationships(spaceQuotaRelationships) + .build()) + .thenMany(requestListSpaceQuotas(this.cloudFoundryClient, spaceQuotaName)) + .single() + .as(StepVerifier::create) + .assertNext( + spaceQuotaResource -> { + assertThat(spaceQuotaResource).isNotNull(); + assertThat(spaceQuotaResource.getId()).isNotNull(); + assertThat(spaceQuotaResource.getName()).isEqualTo(spaceQuotaName); + assertThat(spaceQuotaResource.getApps()).isEqualTo(spaceQuotaAppLimits); + assertThat(spaceQuotaResource.getServices()) + .isEqualTo(spaceQuotaServiceLimits); + assertThat(spaceQuotaResource.getRoutes()) + .isEqualTo(spaceQuotaRouteLimits); + assertThat(spaceQuotaResource.getRelationships()).isNotNull(); + assertThat(spaceQuotaResource.getRelationships().getOrganization()) + .isNotNull(); + assertThat(spaceQuotaResource.getRelationships().getSpaces()) + .isNotNull(); + assertThat( + spaceQuotaResource + .getRelationships() + .getOrganization() + .getData() + .getId()) + .isEqualTo(organizationId); + assertThat( + spaceQuotaResource + .getRelationships() + .getSpaces() + .getData() + .get(0) + .getId()) + .isEqualTo(spaceId); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void get() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + + createSpaceQuotaId(this.cloudFoundryClient, spaceQuotaName, organizationId) + .flatMap( + spaceQuotaId -> + this.cloudFoundryClient + .spaceQuotasV3() + .get( + GetSpaceQuotaRequest.builder() + .spaceQuotaId(spaceQuotaId) + .build())) + .map(GetSpaceQuotaResponse::getName) + .as(StepVerifier::create) + .expectNext(spaceQuotaName) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void list() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + + createSpaceQuota(this.cloudFoundryClient, spaceQuotaName, organizationId) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .spaceQuotasV3() + .list( + ListSpaceQuotasRequest.builder() + .page(page) + .build()))) + .filter(resource -> spaceQuotaName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void update() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + int totalMemoryLimit = 64 * 1024; // 64 GB + + createSpaceQuotaId(this.cloudFoundryClient, spaceQuotaName, organizationId) + .flatMap( + spaceQuotaId -> + this.cloudFoundryClient + .spaceQuotasV3() + .update( + UpdateSpaceQuotaRequest.builder() + .spaceQuotaId(spaceQuotaId) + .apps( + Apps.builder() + .totalMemoryInMb( + totalMemoryLimit) + .build()) + .routes( + Routes.builder() + .totalRoutes(100) + .build()) + .services( + Services.builder() + .isPaidServicesAllowed(true) + .totalServiceInstances(100) + .build()) + .build())) + .thenMany(requestListSpaceQuotas(this.cloudFoundryClient, spaceQuotaName)) + .as(StepVerifier::create) + .consumeNextWith( + organizationQuotaResource -> { + assertThat(organizationQuotaResource.getApps().getTotalMemoryInMb()) + .isEqualTo(totalMemoryLimit); + assertThat(organizationQuotaResource.getRoutes().getTotalRoutes()) + .isEqualTo(100); + assertThat( + organizationQuotaResource + .getServices() + .getTotalServiceInstances()) + .isEqualTo(100); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void delete() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + + createSpaceQuotaId(this.cloudFoundryClient, spaceQuotaName, organizationId) + .flatMap( + spaceQuotaId -> + this.cloudFoundryClient + .spaceQuotasV3() + .delete( + DeleteSpaceQuotaRequest.builder() + .spaceQuotaId(spaceQuotaId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListSpaceQuotas(this.cloudFoundryClient, spaceQuotaName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Organization createOrganization( + CloudFoundryClient cloudFoundryClient, String orgName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(orgName).build()) + .block(Duration.ofMinutes(5)); + } + + private static Space createSpace( + CloudFoundryClient cloudFoundryClient, String orgGuid, String spaceName) { + ToOneRelationship organizationRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(orgGuid).build()) + .build(); + SpaceRelationships spaceRelationships = + SpaceRelationships.builder().organization(organizationRelationship).build(); + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships(spaceRelationships) + .build()) + .block(Duration.ofMinutes(5)); + } + + @NotNull + private static SpaceQuotaRelationships createSpaceQuotaRelationships(String orgGuid) { + ToOneRelationship organizationRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(orgGuid).build()) + .build(); + return SpaceQuotaRelationships.builder().organization(organizationRelationship).build(); + } + + @NotNull + private static SpaceQuotaRelationships createSpaceQuotaRelationships( + String orgGuid, String spaceGuid) { + ToOneRelationship organizationRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(orgGuid).build()) + .build(); + ToManyRelationship spaceRelationships = + ToManyRelationship.builder() + .data(Relationship.builder().id(spaceGuid).build()) + .build(); + return SpaceQuotaRelationships.builder() + .organization(organizationRelationship) + .spaces(spaceRelationships) + .build(); + } + + private static Mono createSpaceQuotaId( + CloudFoundryClient cloudFoundryClient, String spaceQuotaName, String orgGuid) { + return createSpaceQuota(cloudFoundryClient, spaceQuotaName, orgGuid) + .map(CreateSpaceQuotaResponse::getId); + } + + private static Mono createSpaceQuota( + CloudFoundryClient cloudFoundryClient, String spaceQuotaName, String orgGuid) { + SpaceQuotaRelationships spaceQuotaRelationships = createSpaceQuotaRelationships(orgGuid); + return cloudFoundryClient + .spaceQuotasV3() + .create( + CreateSpaceQuotaRequest.builder() + .name(spaceQuotaName) + .relationships(spaceQuotaRelationships) + .build()); + } + + private static Flux requestListSpaceQuotas( + CloudFoundryClient cloudFoundryClient, String spaceName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .spaceQuotasV3() + .list( + ListSpaceQuotasRequest.builder() + .name(spaceName) + .page(page) + .build())); + } +}