Skip to content

Commit fcca362

Browse files
committed
Merge branch 'v3-orgs' into 3.x
2 parents d13e4e2 + 0a4bcf9 commit fcca362

15 files changed

Lines changed: 551 additions & 9 deletions

File tree

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/organizations/ReactorOrganizationsV3.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import org.cloudfoundry.client.v3.organizations.AssignOrganizationDefaultIsolationSegmentResponse;
2121
import org.cloudfoundry.client.v3.organizations.CreateOrganizationRequest;
2222
import org.cloudfoundry.client.v3.organizations.CreateOrganizationResponse;
23+
import org.cloudfoundry.client.v3.organizations.DeleteOrganizationRequest;
2324
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultDomainRequest;
2425
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultDomainResponse;
2526
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultIsolationSegmentRequest;
2627
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultIsolationSegmentResponse;
2728
import org.cloudfoundry.client.v3.organizations.GetOrganizationRequest;
2829
import org.cloudfoundry.client.v3.organizations.GetOrganizationResponse;
30+
import org.cloudfoundry.client.v3.organizations.GetOrganizationUsageSummaryRequest;
31+
import org.cloudfoundry.client.v3.organizations.GetOrganizationUsageSummaryResponse;
2932
import org.cloudfoundry.client.v3.organizations.ListOrganizationDomainsRequest;
3033
import org.cloudfoundry.client.v3.organizations.ListOrganizationDomainsResponse;
3134
import org.cloudfoundry.client.v3.organizations.ListOrganizationsRequest;
@@ -66,15 +69,19 @@ public Mono<AssignOrganizationDefaultIsolationSegmentResponse> assignDefaultIsol
6669

6770
@Override
6871
public Mono<CreateOrganizationResponse> create(CreateOrganizationRequest request) {
69-
return post(request, CreateOrganizationResponse.class, builder ->
70-
builder.pathSegment("organizations"))
72+
return post(request, CreateOrganizationResponse.class, builder -> builder.pathSegment("organizations"))
73+
.checkpoint();
74+
}
75+
76+
@Override
77+
public Mono<String> delete(DeleteOrganizationRequest request) {
78+
return delete(request, builder -> builder.pathSegment("organizations", request.getOrganizationId()))
7179
.checkpoint();
7280
}
7381

7482
@Override
7583
public Mono<GetOrganizationResponse> get(GetOrganizationRequest request) {
76-
return get(request, GetOrganizationResponse.class, builder ->
77-
builder.pathSegment("organizations", request.getOrganizationId()))
84+
return get(request, GetOrganizationResponse.class, builder -> builder.pathSegment("organizations", request.getOrganizationId()))
7885
.checkpoint();
7986
}
8087

@@ -91,6 +98,12 @@ public Mono<GetOrganizationDefaultIsolationSegmentResponse> getDefaultIsolationS
9198
.checkpoint();
9299
}
93100

101+
@Override
102+
public Mono<GetOrganizationUsageSummaryResponse> getUsageSummary(GetOrganizationUsageSummaryRequest request) {
103+
return get(request, GetOrganizationUsageSummaryResponse.class, builder -> builder.pathSegment("organizations", request.getOrganizationId(), "usage_summary"))
104+
.checkpoint();
105+
}
106+
94107
@Override
95108
public Mono<ListOrganizationsResponse> list(ListOrganizationsRequest request) {
96109
return get(request, ListOrganizationsResponse.class, builder -> builder.pathSegment("organizations"))

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/organizations/ReactorOrganizationsV3Test.java

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@
2222
import org.cloudfoundry.client.v3.Relationship;
2323
import org.cloudfoundry.client.v3.ToManyRelationship;
2424
import org.cloudfoundry.client.v3.ToOneRelationship;
25+
import org.cloudfoundry.client.v3.UsageSummary;
2526
import org.cloudfoundry.client.v3.domains.DomainRelationships;
2627
import org.cloudfoundry.client.v3.domains.DomainResource;
2728
import org.cloudfoundry.client.v3.organizations.AssignOrganizationDefaultIsolationSegmentRequest;
2829
import org.cloudfoundry.client.v3.organizations.AssignOrganizationDefaultIsolationSegmentResponse;
2930
import org.cloudfoundry.client.v3.organizations.CreateOrganizationRequest;
3031
import org.cloudfoundry.client.v3.organizations.CreateOrganizationResponse;
32+
import org.cloudfoundry.client.v3.organizations.DeleteOrganizationRequest;
33+
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultDomainRequest;
34+
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultDomainResponse;
3135
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultIsolationSegmentRequest;
3236
import org.cloudfoundry.client.v3.organizations.GetOrganizationDefaultIsolationSegmentResponse;
3337
import org.cloudfoundry.client.v3.organizations.GetOrganizationRequest;
3438
import org.cloudfoundry.client.v3.organizations.GetOrganizationResponse;
39+
import org.cloudfoundry.client.v3.organizations.GetOrganizationUsageSummaryRequest;
40+
import org.cloudfoundry.client.v3.organizations.GetOrganizationUsageSummaryResponse;
3541
import org.cloudfoundry.client.v3.organizations.ListOrganizationDomainsRequest;
3642
import org.cloudfoundry.client.v3.organizations.ListOrganizationDomainsResponse;
3743
import org.cloudfoundry.client.v3.organizations.ListOrganizationsRequest;
@@ -49,10 +55,13 @@
4955
import java.time.Duration;
5056
import java.util.Collections;
5157

58+
import static io.netty.handler.codec.http.HttpMethod.DELETE;
5259
import static io.netty.handler.codec.http.HttpMethod.GET;
5360
import static io.netty.handler.codec.http.HttpMethod.PATCH;
5461
import static io.netty.handler.codec.http.HttpMethod.POST;
62+
import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
5563
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
64+
import static org.cloudfoundry.client.v3.routes.Protocol.HTTP;
5665

5766
public class ReactorOrganizationsV3Test extends AbstractClientApiTest {
5867

@@ -129,6 +138,28 @@ public void create() {
129138
.verify(Duration.ofSeconds(5));
130139
}
131140

141+
@Test
142+
public void delete() {
143+
mockRequest(InteractionContext.builder()
144+
.request(TestRequest.builder()
145+
.method(DELETE).path("/organizations/test-organization-id")
146+
.build())
147+
.response(TestResponse.builder()
148+
.status(ACCEPTED)
149+
.header("Location", "https://api.example.org/v3/jobs/test-job-id")
150+
.build())
151+
.build());
152+
153+
this.organizations
154+
.delete(DeleteOrganizationRequest.builder()
155+
.organizationId("test-organization-id")
156+
.build())
157+
.as(StepVerifier::create)
158+
.expectNext("test-job-id")
159+
.expectComplete()
160+
.verify(Duration.ofSeconds(5));
161+
}
162+
132163
@Test
133164
public void get() {
134165
mockRequest(InteractionContext.builder()
@@ -163,6 +194,66 @@ public void get() {
163194
.verify(Duration.ofSeconds(5));
164195
}
165196

197+
@Test
198+
public void getDefaultDomain() {
199+
mockRequest(InteractionContext.builder()
200+
.request(TestRequest.builder()
201+
.method(GET).path("/organizations/test-organization-id/domains/default")
202+
.build())
203+
.response(TestResponse.builder()
204+
.status(OK)
205+
.payload("fixtures/client/v3/organizations/GET_{id}_domains_default_response.json")
206+
.build())
207+
.build());
208+
209+
this.organizations
210+
.getDefaultDomain(GetOrganizationDefaultDomainRequest.builder()
211+
.organizationId("test-organization-id")
212+
.build())
213+
.as(StepVerifier::create)
214+
.expectNext(GetOrganizationDefaultDomainResponse.builder()
215+
.id("3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
216+
.createdAt("2019-03-08T01:06:19Z")
217+
.updatedAt("2019-03-08T01:06:19Z")
218+
.name("test-domain.com")
219+
.isInternal(false)
220+
.supportedProtocol(HTTP)
221+
.metadata(Metadata.builder()
222+
.annotations(Collections.emptyMap())
223+
.labels(Collections.emptyMap())
224+
.build())
225+
.relationships(DomainRelationships.builder()
226+
.organization(ToOneRelationship.builder()
227+
.data(Relationship.builder()
228+
.id("3a3f3d89-3f89-4f05-8188-751b298c79d5")
229+
.build())
230+
.build())
231+
.sharedOrganizations(ToManyRelationship.builder()
232+
.data(Relationship.builder()
233+
.id("404f3d89-3f89-6z72-8188-751b298d88d5")
234+
.build())
235+
.data(Relationship.builder()
236+
.id("416d3d89-3f89-8h67-2189-123b298d3592")
237+
.build())
238+
.build())
239+
.build())
240+
.link("self", Link.builder()
241+
.href("https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5")
242+
.build())
243+
.link("organization", Link.builder()
244+
.href("https://api.example.org/v3/organizations/3a3f3d89-3f89-4f05-8188-751b298c79d5")
245+
.build())
246+
.link("route_reservations", Link.builder()
247+
.href("https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5/route_reservations")
248+
.build())
249+
.link("shared_organizations", Link.builder()
250+
.href("https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5/relationships/shared_organizations")
251+
.build())
252+
.build())
253+
.expectComplete()
254+
.verify(Duration.ofSeconds(5));
255+
}
256+
166257
@Test
167258
public void getDefaultIsolationSegment() {
168259
mockRequest(InteractionContext.builder()
@@ -195,6 +286,39 @@ public void getDefaultIsolationSegment() {
195286
.verify(Duration.ofSeconds(5));
196287
}
197288

289+
@Test
290+
public void getUsageSummary() {
291+
mockRequest(InteractionContext.builder()
292+
.request(TestRequest.builder()
293+
.method(GET).path("/organizations/test-organization-id/usage_summary")
294+
.build())
295+
.response(TestResponse.builder()
296+
.status(OK)
297+
.payload("fixtures/client/v3/organizations/GET_{id}_usage_summary_response.json")
298+
.build())
299+
.build());
300+
301+
this.organizations
302+
.getUsageSummary(GetOrganizationUsageSummaryRequest.builder()
303+
.organizationId("test-organization-id")
304+
.build())
305+
.as(StepVerifier::create)
306+
.expectNext(GetOrganizationUsageSummaryResponse.builder()
307+
.usageSummary(UsageSummary.builder()
308+
.startedInstances(3)
309+
.memoryInMb(50)
310+
.build())
311+
.link("self", Link.builder()
312+
.href("https://api.example.org/v3/organizations/d4c91047-7b29-4fda-b7f9-04033e5c9c9f/usage_summary")
313+
.build())
314+
.link("organization", Link.builder()
315+
.href("https://api.example.org/v3/organizations/d4c91047-7b29-4fda-b7f9-04033e5c9c9f")
316+
.build())
317+
.build())
318+
.expectComplete()
319+
.verify(Duration.ofSeconds(5));
320+
}
321+
198322
@Test
199323
public void list() {
200324
mockRequest(InteractionContext.builder()
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"guid": "3a5d3d89-3f89-4f05-8188-8a2b298c79d5",
3+
"created_at": "2019-03-08T01:06:19Z",
4+
"updated_at": "2019-03-08T01:06:19Z",
5+
"name": "test-domain.com",
6+
"internal": false,
7+
"router_group": null,
8+
"supported_protocols": [
9+
"http"
10+
],
11+
"metadata": {
12+
"labels": {},
13+
"annotations": {}
14+
},
15+
"relationships": {
16+
"organization": {
17+
"data": {
18+
"guid": "3a3f3d89-3f89-4f05-8188-751b298c79d5"
19+
}
20+
},
21+
"shared_organizations": {
22+
"data": [
23+
{
24+
"guid": "404f3d89-3f89-6z72-8188-751b298d88d5"
25+
},
26+
{
27+
"guid": "416d3d89-3f89-8h67-2189-123b298d3592"
28+
}
29+
]
30+
}
31+
},
32+
"links": {
33+
"self": {
34+
"href": "https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5"
35+
},
36+
"organization": {
37+
"href": "https://api.example.org/v3/organizations/3a3f3d89-3f89-4f05-8188-751b298c79d5"
38+
},
39+
"route_reservations": {
40+
"href": "https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5/route_reservations"
41+
},
42+
"shared_organizations": {
43+
"href": "https://api.example.org/v3/domains/3a5d3d89-3f89-4f05-8188-8a2b298c79d5/relationships/shared_organizations"
44+
}
45+
}
46+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"usage_summary": {
3+
"started_instances": 3,
4+
"memory_in_mb": 50
5+
},
6+
"links": {
7+
"self": {
8+
"href": "https://api.example.org/v3/organizations/d4c91047-7b29-4fda-b7f9-04033e5c9c9f/usage_summary"
9+
},
10+
"organization": {
11+
"href": "https://api.example.org/v3/organizations/d4c91047-7b29-4fda-b7f9-04033e5c9c9f"
12+
}
13+
}
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2013-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.immutables.value.Value;
22+
23+
/**
24+
* Represents a summary of resource usage
25+
*/
26+
@JsonDeserialize
27+
@Value.Immutable
28+
abstract class _UsageSummary {
29+
30+
/**
31+
* The total memory usage
32+
*/
33+
@JsonProperty("memory_in_mb")
34+
abstract Integer getMemoryInMb();
35+
36+
/**
37+
* The number of started instances
38+
*/
39+
@JsonProperty("started_instances")
40+
abstract Integer getStartedInstances();
41+
42+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/domains/Domain.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
package org.cloudfoundry.client.v3.domains;
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import org.cloudfoundry.AllowNulls;
2021
import org.cloudfoundry.Nullable;
2122
import org.cloudfoundry.client.v3.Metadata;
2223
import org.cloudfoundry.client.v3.Resource;
24+
import org.cloudfoundry.client.v3.routes.Protocol;
25+
26+
import java.util.List;
2327

2428
public abstract class Domain extends Resource {
2529

@@ -43,6 +47,21 @@ public abstract class Domain extends Resource {
4347
@JsonProperty("relationships")
4448
public abstract DomainRelationships getRelationships();
4549

50+
/**
51+
* Router group information
52+
*/
53+
@AllowNulls
54+
@JsonProperty("router_group")
55+
@Nullable
56+
public abstract RouterGroup getRouterGroup();
57+
58+
/**
59+
* Available protocols for routes using the domain
60+
*/
61+
@JsonProperty("supported_protocols")
62+
@Nullable
63+
public abstract List<Protocol> getSupportedProtocols();
64+
4665
/**
4766
* Whether the domain is used for internal (container-to-container) traffic.
4867
*/

0 commit comments

Comments
 (0)