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..c5aaf9197b 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.spacequotadefinitions.SpaceQuotaDefinitionsV3; 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.spacequotadefinition.ReactorSpaceQuotaDefinitionsV3; 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 SpaceQuotaDefinitionsV3 spaceQuotaDefinitionsV3() { + return new ReactorSpaceQuotaDefinitionsV3(getConnectionContext(), getRootV3(), getTokenProvider(), + getRequestTags()); + } + @Override @Value.Derived public Spaces spaces() { diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3.java new file mode 100644 index 0000000000..ffd4f11997 --- /dev/null +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3.java @@ -0,0 +1,108 @@ +/* + * 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.spacequotadefinition; + +import java.util.Map; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.DeleteSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.ListSpaceQuotaDefinitionsRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.ListSpaceQuotaDefinitionsResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.SpaceQuotaDefinitionsV3; +import org.cloudfoundry.client.v3.spacequotadefinitions.UpdateSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.UpdateSpaceQuotaDefinitionResponse; +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 ReactorSpaceQuotaDefinitionsV3} + */ +public class ReactorSpaceQuotaDefinitionsV3 extends AbstractClientV3Operations + implements SpaceQuotaDefinitionsV3 { + + /** + * 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 ReactorSpaceQuotaDefinitionsV3( + ConnectionContext connectionContext, + Mono root, + TokenProvider tokenProvider, + Map requestTags) { + super(connectionContext, root, tokenProvider, requestTags); + } + + @Override + public Mono create( + CreateSpaceQuotaDefinitionRequest request) { + return post( + request, + CreateSpaceQuotaDefinitionResponse.class, + builder -> builder.pathSegment("space_quotas")) + .checkpoint(); + } + + @Override + public Mono get(GetSpaceQuotaDefinitionRequest request) { + return get( + request, + GetSpaceQuotaDefinitionResponse.class, + builder -> + builder.pathSegment( + "space_quotas", request.getSpaceQuotaDefinitionId())) + .checkpoint(); + } + + @Override + public Mono list(ListSpaceQuotaDefinitionsRequest request) { + return get( + request, + ListSpaceQuotaDefinitionsResponse.class, + builder -> builder.pathSegment("space_quotas")) + .checkpoint(); + } + + @Override + public Mono update( + UpdateSpaceQuotaDefinitionRequest request) { + return patch( + request, + UpdateSpaceQuotaDefinitionResponse.class, + builder -> + builder.pathSegment( + "space_quotas", request.getSpaceQuotaDefinitionId())) + .checkpoint(); + } + + @Override + public Mono delete(DeleteSpaceQuotaDefinitionRequest request) { + return delete( + request, + builder -> + builder.pathSegment( + "space_quotas", request.getSpaceQuotaDefinitionId())) + .checkpoint(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3Test.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3Test.java new file mode 100644 index 0000000000..79f1a8b68f --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/spacequotadefinition/ReactorSpaceQuotaDefinitionsV3Test.java @@ -0,0 +1,334 @@ +/* + * 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.spacequotadefinition; + +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.spacequotadefinitions.Apps; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.DeleteSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.ListSpaceQuotaDefinitionsRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.ListSpaceQuotaDefinitionsResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.Routes; +import org.cloudfoundry.client.v3.spacequotadefinitions.Services; +import org.cloudfoundry.client.v3.spacequotadefinitions.SpaceQuotaDefinitionRelationships; +import org.cloudfoundry.client.v3.spacequotadefinitions.SpaceQuotaDefinitionResource; +import org.cloudfoundry.client.v3.spacequotadefinitions.UpdateSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.UpdateSpaceQuotaDefinitionResponse; +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 ReactorSpaceQuotaDefinitionsV3Test extends AbstractClientApiTest { + + public static final String EXPECTED_SPACE_QUOTA_ID_1 = "f919ef8a-e333-472a-8172-baaf2c30d301"; + + private final ReactorSpaceQuotaDefinitionsV3 spaceQuotaDefinitionsV3 = + new ReactorSpaceQuotaDefinitionsV3( + 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()); + + SpaceQuotaDefinitionRelationships relationships = + SpaceQuotaDefinitionRelationships.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.spaceQuotaDefinitionsV3 + .create( + CreateSpaceQuotaDefinitionRequest.builder() + .name("my-quota") + .relationships(relationships) + .build()) + .as(StepVerifier::create) + .expectNext( + CreateSpaceQuotaDefinitionResponse.builder() + .from(expectedSpaceQuotaDefinitionResource1()) + .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.spaceQuotaDefinitionsV3 + .delete( + DeleteSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId("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.spaceQuotaDefinitionsV3 + .get( + GetSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(EXPECTED_SPACE_QUOTA_ID_1) + .build()) + .as(StepVerifier::create) + .expectNext( + GetSpaceQuotaDefinitionResponse.builder() + .from(expectedSpaceQuotaDefinitionResource1()) + .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.spaceQuotaDefinitionsV3 + .list(ListSpaceQuotaDefinitionsRequest.builder().build()) + .as(StepVerifier::create) + .expectNext( + ListSpaceQuotaDefinitionsResponse.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( + SpaceQuotaDefinitionResource.builder() + .from(expectedSpaceQuotaDefinitionResource1()) + .build()) + .resource( + SpaceQuotaDefinitionResource.builder() + .from(expectedSpaceQuotaDefinitionResource2()) + .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.spaceQuotaDefinitionsV3 + .update( + UpdateSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(EXPECTED_SPACE_QUOTA_ID_1) + .build()) + .as(StepVerifier::create) + .expectNext( + UpdateSpaceQuotaDefinitionResponse.builder() + .from(expectedSpaceQuotaDefinitionResource1()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @NotNull + private static SpaceQuotaDefinitionResource expectedSpaceQuotaDefinitionResource1() { + return buildSpaceQuotaDefinitionResource( + EXPECTED_SPACE_QUOTA_ID_1, + "my-quota", + "9b370018-c38e-44c9-86d6-155c76801104", + "dcfd6a55-62b9-496e-a26f-0064cec076bf"); + } + + private static SpaceQuotaDefinitionResource expectedSpaceQuotaDefinitionResource2() { + return buildSpaceQuotaDefinitionResource( + "bb49bf20-ad98-4729-93ae-38fbc564b630", + "my-quota-2", + "9b370018-c38e-44c9-86d6-155c76801104", + null); + } + + @NotNull + private static SpaceQuotaDefinitionResource buildSpaceQuotaDefinitionResource( + 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(); + } + SpaceQuotaDefinitionRelationships relationships = + SpaceQuotaDefinitionRelationships.builder() + .organization(organizationRelationship) + .spaces(spaceRelationships) + .build(); + + return SpaceQuotaDefinitionResource.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 c229b37230..a1df244917 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.spacequotadefinitions.SpaceQuotaDefinitionsV3; 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 Definitions V3 Client API + */ + SpaceQuotaDefinitionsV3 spaceQuotaDefinitionsV3(); + /** * Main entry point to the Cloud Foundry Spaces V2 Client API */ diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinition.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinition.java new file mode 100644 index 0000000000..c0d27d8dd6 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinition.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.spacequotadefinitions; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v3.Resource; + +/** + * Base class for responses that are space quota definitions + */ +public abstract class SpaceQuotaDefinition 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 SpaceQuotaDefinitionRelationships getRelationships(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinitionsV3.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinitionsV3.java new file mode 100644 index 0000000000..b97326da11 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/SpaceQuotaDefinitionsV3.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.spacequotadefinitions; + +import reactor.core.publisher.Mono; + +/** + * Main entry point to the Cloud Foundry Space Quota Definitions Client API + */ +public interface SpaceQuotaDefinitionsV3 { + + /** + * Makes the Create Space Quota + * request + * + * @param request the Create Space Quota Definition request + * @return the response from the Create Space Quota Definition request + */ + Mono create(CreateSpaceQuotaDefinitionRequest request); + + /** + * Makes the Get Space Quota + * request + * + * @param request the Get Space Quota Definition request + * @return the response from the Get Space Quota request + */ + Mono get(GetSpaceQuotaDefinitionRequest request); + + /** + * Makes the List all Space Quota Definitions + * request + * + * @param request the List all Space Quota Definitions request + * @return the response from the Space all Organization Quota Definitions request + */ + Mono list(ListSpaceQuotaDefinitionsRequest request); + + /** Makes the Update Space Quota Definition + * request + * + * @param request the Update Space Quota Definition request + * @return the response from the Update Space Quota Definition request + */ + Mono update(UpdateSpaceQuotaDefinitionRequest request); + + /** + * Makes the Delete Space Quota Definition + * request + * + * @param request the Delete Space Quota Definition request + * @return the response from the Space Organization Quota Definition request + */ + Mono delete(DeleteSpaceQuotaDefinitionRequest request); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_Apps.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_Apps.java new file mode 100644 index 0000000000..732afd6ae2 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_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.spacequotadefinitions; + +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/spacequotadefinitions/_CreateSpaceQuotaDefinitionRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_CreateSpaceQuotaDefinitionRequest.java new file mode 100644 index 0000000000..e8d2fd207e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_CreateSpaceQuotaDefinitionRequest.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.spacequotadefinitions; + +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 creates a new space quota + */ +@JsonSerialize +@Value.Immutable +abstract class _CreateSpaceQuotaDefinitionRequest { + + /** + * Name of the quota + */ + @JsonProperty("name") + abstract String getName(); + + /** + * A relationship to the organizations and spaces where the quota is applied + */ + @JsonProperty("relationships") + abstract SpaceQuotaDefinitionRelationships 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/spacequotadefinitions/_CreateSpaceQuotaDefinitionResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_CreateSpaceQuotaDefinitionResponse.java new file mode 100644 index 0000000000..678390a6f3 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_CreateSpaceQuotaDefinitionResponse.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.spacequotadefinitions; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Create an Space Quota Definition operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _CreateSpaceQuotaDefinitionResponse extends SpaceQuotaDefinition { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_DeleteSpaceQuotaDefinitionRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_DeleteSpaceQuotaDefinitionRequest.java new file mode 100644 index 0000000000..d41e4fb0c8 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_DeleteSpaceQuotaDefinitionRequest.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.spacequotadefinitions; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Delete an Space Quota Definition operation + */ +@Value.Immutable +abstract class _DeleteSpaceQuotaDefinitionRequest { + + /** + * The quota definition id + */ + @JsonIgnore + abstract String getSpaceQuotaDefinitionId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionRequest.java new file mode 100644 index 0000000000..d73bfa7d98 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionRequest.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.spacequotadefinitions; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Retrieve a Particular Space Quota Definition operation + */ +@Value.Immutable +abstract class _GetSpaceQuotaDefinitionRequest { + + /** + * The quota definition id + */ + @JsonIgnore + abstract String getSpaceQuotaDefinitionId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionResponse.java new file mode 100644 index 0000000000..8aa7f7dc94 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_GetSpaceQuotaDefinitionResponse.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.spacequotadefinitions; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Retrieve a Particular Space Quota Definition operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _GetSpaceQuotaDefinitionResponse extends SpaceQuotaDefinition { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_ListSpaceQuotaDefinitionsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_ListSpaceQuotaDefinitionsRequest.java new file mode 100644 index 0000000000..99a075bdc3 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_ListSpaceQuotaDefinitionsRequest.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.spacequotadefinitions; + +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 Quota Definitions operation + */ +@Value.Immutable +abstract class _ListSpaceQuotaDefinitionsRequest 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/spacequotadefinitions/_ListSpaceQuotaDefinitionsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_ListSpaceQuotaDefinitionsResponse.java new file mode 100644 index 0000000000..bfc64840b6 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_ListSpaceQuotaDefinitionsResponse.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.spacequotadefinitions; + +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 Quota Definitions operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListSpaceQuotaDefinitionsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_Routes.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_Routes.java new file mode 100644 index 0000000000..5c69e2fba4 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_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.spacequotadefinitions; + +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/spacequotadefinitions/_Services.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_Services.java new file mode 100644 index 0000000000..813e248e33 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_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.spacequotadefinitions; + +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/spacequotadefinitions/_SpaceQuotaDefinitionRelationships.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_SpaceQuotaDefinitionRelationships.java new file mode 100644 index 0000000000..9400adcba2 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_SpaceQuotaDefinitionRelationships.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.spacequotadefinitions; + +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 SpaceQuotaDefinition entity + */ + +@Value.Immutable +@JsonDeserialize +abstract class _SpaceQuotaDefinitionRelationships { + + /** + * 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/spacequotadefinitions/_SpaceQuotaDefinitionResource.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_SpaceQuotaDefinitionResource.java new file mode 100644 index 0000000000..4a9e5fb228 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_SpaceQuotaDefinitionResource.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.spacequotadefinitions; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * Base class for resources that contain Space Quota Definitions + */ +@JsonDeserialize +@Value.Immutable +abstract class _SpaceQuotaDefinitionResource extends SpaceQuotaDefinition { + +} + diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_UpdateSpaceQuotaDefinitionRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_UpdateSpaceQuotaDefinitionRequest.java new file mode 100644 index 0000000000..ec10a0786b --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_UpdateSpaceQuotaDefinitionRequest.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.spacequotadefinitions; + +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 an space quota definition + */ +@JsonSerialize +@Value.Immutable +abstract class _UpdateSpaceQuotaDefinitionRequest { + + /** + * The space quota definition id + */ + @JsonIgnore + abstract String getSpaceQuotaDefinitionId(); + + /** + * 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/spacequotadefinitions/_UpdateSpaceQuotaDefinitionResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_UpdateSpaceQuotaDefinitionResponse.java new file mode 100644 index 0000000000..e1df4f8b85 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/spacequotadefinitions/_UpdateSpaceQuotaDefinitionResponse.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.spacequotadefinitions; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Update an Space Quota Definition operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _UpdateSpaceQuotaDefinitionResponse extends SpaceQuotaDefinition { + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/CreateSpaceQuotaDefinitionRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/CreateSpaceQuotaDefinitionRequestTest.java new file mode 100644 index 0000000000..d2d10b68ea --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/CreateSpaceQuotaDefinitionRequestTest.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.spacequotadefinitions; + +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 CreateSpaceQuotaDefinitionRequestTest { + + @Test + void noName() { + assertThrows( + IllegalStateException.class, + () -> CreateSpaceQuotaDefinitionRequest.builder().build()); + } + + @Test + void noOrganizationsRelationship() { + assertThrows( + IllegalStateException.class, + () -> CreateSpaceQuotaDefinitionRequest.builder().name("test-quota").build()); + } + + @Test + void valid() { + + String organizationGuid = UUID.randomUUID().toString(); + ToOneRelationship organizationsRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(organizationGuid).build()) + .build(); + SpaceQuotaDefinitionRelationships relationships = + SpaceQuotaDefinitionRelationships.builder() + .organization(organizationsRelationship) + .build(); + CreateSpaceQuotaDefinitionRequest.builder() + .name("test-quota") + .relationships(relationships) + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/DeleteSpaceQuotaDefinitionRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/DeleteSpaceQuotaDefinitionRequestTest.java new file mode 100644 index 0000000000..f38f48ad69 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/DeleteSpaceQuotaDefinitionRequestTest.java @@ -0,0 +1,36 @@ +/* + * 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.spacequotadefinitions; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class DeleteSpaceQuotaDefinitionRequestTest { + + @Test + void noSpaceQuotaDefinitionId() { + assertThrows( + IllegalStateException.class, + () -> DeleteSpaceQuotaDefinitionRequest.builder().build()); + } + + @Test + void valid() { + DeleteSpaceQuotaDefinitionRequest.builder().spaceQuotaDefinitionId("test-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/GetSpaceQuotaDefinitionRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/GetSpaceQuotaDefinitionRequestTest.java new file mode 100644 index 0000000000..5141b92ef4 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/GetSpaceQuotaDefinitionRequestTest.java @@ -0,0 +1,36 @@ +/* + * 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.spacequotadefinitions; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class GetSpaceQuotaDefinitionRequestTest { + + @Test + void noSpaceQuotaDefinitionId() { + assertThrows( + IllegalStateException.class, + () -> GetSpaceQuotaDefinitionRequest.builder().build()); + } + + @Test + void valid() { + GetSpaceQuotaDefinitionRequest.builder().spaceQuotaDefinitionId("test-id").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/ListSpaceQuotaDefinitionsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/ListSpaceQuotaDefinitionsRequestTest.java new file mode 100644 index 0000000000..8f0e0f4f8c --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/ListSpaceQuotaDefinitionsRequestTest.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.spacequotadefinitions; + +import org.junit.jupiter.api.Test; + +public class ListSpaceQuotaDefinitionsRequestTest { + + @Test + void valid() { + ListSpaceQuotaDefinitionsRequest.builder().build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/UpdateSpaceQuotaDefinitionRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/UpdateSpaceQuotaDefinitionRequestTest.java new file mode 100644 index 0000000000..d5ea3e7c08 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/spacequotadefinitions/UpdateSpaceQuotaDefinitionRequestTest.java @@ -0,0 +1,36 @@ +/* + * 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.spacequotadefinitions; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +final class UpdateSpaceQuotaDefinitionRequestTest { + + @Test + void noSpaceQuotaDefinitionId() { + assertThrows( + IllegalStateException.class, + () -> UpdateSpaceQuotaDefinitionRequest.builder().build()); + } + + @Test + void valid() { + UpdateSpaceQuotaDefinitionRequest.builder().spaceQuotaDefinitionId("test-id").build(); + } +} diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotaDefinitionsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotaDefinitionsTest.java new file mode 100644 index 0000000000..7b69f77f24 --- /dev/null +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpaceQuotaDefinitionsTest.java @@ -0,0 +1,278 @@ +/* + * 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.spacequotadefinitions.Apps; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.CreateSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.DeleteSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.GetSpaceQuotaDefinitionResponse; +import org.cloudfoundry.client.v3.spacequotadefinitions.ListSpaceQuotaDefinitionsRequest; +import org.cloudfoundry.client.v3.spacequotadefinitions.Routes; +import org.cloudfoundry.client.v3.spacequotadefinitions.Services; +import org.cloudfoundry.client.v3.spacequotadefinitions.SpaceQuotaDefinitionRelationships; +import org.cloudfoundry.client.v3.spacequotadefinitions.SpaceQuotaDefinitionResource; +import org.cloudfoundry.client.v3.spacequotadefinitions.UpdateSpaceQuotaDefinitionRequest; +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 SpaceQuotaDefinitionsTest extends AbstractIntegrationTest { + + @Autowired private CloudFoundryClient cloudFoundryClient; + + private String organizationId; + + @BeforeEach + public void createOrganization() { + String orgName = this.nameFactory.getOrganizationName(); + organizationId = createOrganization(this.cloudFoundryClient, orgName).getId(); + } + + @Test + public void create() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + SpaceQuotaDefinitionRelationships spaceQuotaDefinitionRelationships = + createSpaceQuotaDefinitionRelationships(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 + .spaceQuotaDefinitionsV3() + .create( + CreateSpaceQuotaDefinitionRequest.builder() + .name(spaceQuotaName) + .apps(spaceQuotaAppLimits) + .services(spaceQuotaServiceLimits) + .routes(spaceQuotaRouteLimits) + .relationships(spaceQuotaDefinitionRelationships) + .build()) + .thenMany(requestListSpaceQuotas(this.cloudFoundryClient, spaceQuotaName)) + .single() + .as(StepVerifier::create) + .assertNext( + spaceQuotaDefinitionResource -> { + assertThat(spaceQuotaDefinitionResource).isNotNull(); + assertThat(spaceQuotaDefinitionResource.getId()).isNotNull(); + assertThat(spaceQuotaDefinitionResource.getName()) + .isEqualTo(spaceQuotaName); + assertThat(spaceQuotaDefinitionResource.getApps()) + .isEqualTo(spaceQuotaAppLimits); + assertThat(spaceQuotaDefinitionResource.getServices()) + .isEqualTo(spaceQuotaServiceLimits); + assertThat(spaceQuotaDefinitionResource.getRoutes()) + .isEqualTo(spaceQuotaRouteLimits); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void get() { + String spaceQuotaName = this.nameFactory.getQuotaDefinitionName(); + + createSpaceQuotaId(this.cloudFoundryClient, spaceQuotaName, organizationId) + .flatMap( + spaceQuotaId -> + this.cloudFoundryClient + .spaceQuotaDefinitionsV3() + .get( + GetSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(spaceQuotaId) + .build())) + .map(GetSpaceQuotaDefinitionResponse::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 + .spaceQuotaDefinitionsV3() + .list( + ListSpaceQuotaDefinitionsRequest.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 + .spaceQuotaDefinitionsV3() + .update( + UpdateSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(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( + organizationQuotaDefinitionResource -> { + assertThat( + organizationQuotaDefinitionResource + .getApps() + .getTotalMemoryInMb()) + .isEqualTo(totalMemoryLimit); + assertThat( + organizationQuotaDefinitionResource + .getRoutes() + .getTotalRoutes()) + .isEqualTo(100); + assertThat( + organizationQuotaDefinitionResource + .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 + .spaceQuotaDefinitionsV3() + .delete( + DeleteSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(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)); + } + + @NotNull + private static SpaceQuotaDefinitionRelationships createSpaceQuotaDefinitionRelationships( + String orgGuid) { + ToOneRelationship organizationRelationship = + ToOneRelationship.builder() + .data(Relationship.builder().id(orgGuid).build()) + .build(); + return SpaceQuotaDefinitionRelationships.builder() + .organization(organizationRelationship) + .build(); + } + + private static Mono createSpaceQuotaId( + CloudFoundryClient cloudFoundryClient, String spaceQuotaName, String orgGuid) { + return createSpaceQuota(cloudFoundryClient, spaceQuotaName, orgGuid) + .map(CreateSpaceQuotaDefinitionResponse::getId); + } + + private static Mono createSpaceQuota( + CloudFoundryClient cloudFoundryClient, String spaceQuotaName, String orgGuid) { + SpaceQuotaDefinitionRelationships spaceQuotaDefinitionRelationships = + createSpaceQuotaDefinitionRelationships(orgGuid); + return cloudFoundryClient + .spaceQuotaDefinitionsV3() + .create( + CreateSpaceQuotaDefinitionRequest.builder() + .name(spaceQuotaName) + .relationships(spaceQuotaDefinitionRelationships) + .build()); + } + + private static Flux requestListSpaceQuotas( + CloudFoundryClient cloudFoundryClient, String spaceName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .spaceQuotaDefinitionsV3() + .list( + ListSpaceQuotaDefinitionsRequest.builder() + .name(spaceName) + .page(page) + .build())); + } +}