Skip to content

Commit ecf74ab

Browse files
Adding support for service instance update. Adding support for service instance metadata.
1 parent 3df72c1 commit ecf74ab

File tree

11 files changed

+216
-0
lines changed

11 files changed

+216
-0
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/serviceinstances/ReactorServiceInstancesV3.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceRequest;
2525
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceResponse;
2626
import org.cloudfoundry.client.v3.serviceInstances.UnshareServiceInstanceRequest;
27+
import org.cloudfoundry.client.v3.serviceInstances.UpdateServiceInstanceRequest;
28+
import org.cloudfoundry.client.v3.serviceInstances.UpdateServiceInstanceResponse;
2729
import org.cloudfoundry.reactor.ConnectionContext;
2830
import org.cloudfoundry.reactor.TokenProvider;
2931
import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations;
@@ -69,4 +71,8 @@ public Mono<Void> unshare(UnshareServiceInstanceRequest request) {
6971
.checkpoint();
7072
}
7173

74+
@Override
75+
public Mono<UpdateServiceInstanceResponse> update(UpdateServiceInstanceRequest request) {
76+
return patch(request, UpdateServiceInstanceResponse.class, builder -> builder.pathSegment("service_instances", request.getServiceInstanceId()));
77+
}
7278
}

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/serviceInstances/ReactorServiceInstancesV3Test.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.cloudfoundry.reactor.client.v3.serviceInstances;
1818

1919
import org.cloudfoundry.client.v3.Link;
20+
import org.cloudfoundry.client.v3.Metadata;
2021
import org.cloudfoundry.client.v3.Pagination;
2122
import org.cloudfoundry.client.v3.Relationship;
2223
import org.cloudfoundry.client.v3.ToOneRelationship;
@@ -29,6 +30,8 @@
2930
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceRequest;
3031
import org.cloudfoundry.client.v3.serviceInstances.ShareServiceInstanceResponse;
3132
import org.cloudfoundry.client.v3.serviceInstances.UnshareServiceInstanceRequest;
33+
import org.cloudfoundry.client.v3.serviceInstances.UpdateServiceInstanceRequest;
34+
import org.cloudfoundry.client.v3.serviceInstances.UpdateServiceInstanceResponse;
3235
import org.cloudfoundry.reactor.InteractionContext;
3336
import org.cloudfoundry.reactor.TestRequest;
3437
import org.cloudfoundry.reactor.TestResponse;
@@ -42,6 +45,7 @@
4245
import static io.netty.handler.codec.http.HttpMethod.DELETE;
4346
import static io.netty.handler.codec.http.HttpMethod.GET;
4447
import static io.netty.handler.codec.http.HttpMethod.POST;
48+
import static io.netty.handler.codec.http.HttpMethod.PATCH;
4549
import static io.netty.handler.codec.http.HttpResponseStatus.CREATED;
4650
import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT;
4751
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
@@ -224,4 +228,39 @@ public void unshare() {
224228
.expectComplete()
225229
.verify(Duration.ofSeconds(5));
226230
}
231+
232+
@Test
233+
public void update() {
234+
mockRequest(InteractionContext.builder()
235+
.request(TestRequest.builder()
236+
.method(PATCH).path("/service_instances/68d54d31-9b3a-463b-ba94-e8e4c32edbac")
237+
.payload("fixtures/client/v3/serviceinstances/PATCH_request.json")
238+
.build())
239+
.response(TestResponse.builder()
240+
.status(OK)
241+
.payload("fixtures/client/v3/serviceinstances/PATCH_response.json")
242+
.build())
243+
.build());
244+
245+
this.serviceInstances
246+
.update(UpdateServiceInstanceRequest.builder()
247+
.serviceInstanceId("68d54d31-9b3a-463b-ba94-e8e4c32edbac")
248+
.metadata(Metadata.builder()
249+
.label("test", "yes")
250+
.annotation("data", "potato")
251+
.build())
252+
.build())
253+
.as(StepVerifier::create)
254+
.expectNext(UpdateServiceInstanceResponse.builder()
255+
.id("68d54d31-9b3a-463b-ba94-e8e4c32edbac")
256+
.metadata(Metadata.builder()
257+
.label("test", "yes")
258+
.annotation("data", "potato")
259+
.build())
260+
.name("my_service_instance1")
261+
.createdAt("2017-11-17T13:54:21Z")
262+
.build())
263+
.expectComplete()
264+
.verify(Duration.ofSeconds(5));
265+
}
227266
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"metadata": {
3+
"labels": {
4+
"test": "yes"
5+
},
6+
"annotations": {
7+
"data": "potato"
8+
}
9+
}
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"guid": "68d54d31-9b3a-463b-ba94-e8e4c32edbac",
3+
"created_at": "2017-11-17T13:54:21Z",
4+
"name": "my_service_instance1",
5+
"metadata": {
6+
"labels": {
7+
"test": "yes"
8+
},
9+
"annotations": {
10+
"data": "potato"
11+
}
12+
}
13+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Metadata.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Map;
2020

21+
import org.cloudfoundry.AllowNulls;
2122
import org.cloudfoundry.Nullable;
2223
import org.immutables.value.Value;
2324

@@ -35,13 +36,15 @@ abstract class _Metadata {
3536
* The metadata lables
3637
*/
3738
@JsonProperty("labels")
39+
@AllowNulls
3840
@Nullable
3941
abstract Map<String, String> getLabels();
4042

4143
/**
4244
* The metadata annotations
4345
*/
4446
@JsonProperty("annotations")
47+
@AllowNulls
4548
@Nullable
4649
abstract Map<String, String> getAnnotations();
4750

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/serviceInstances/ServiceInstance.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.fasterxml.jackson.annotation.JsonProperty;
2020
import org.cloudfoundry.Nullable;
21+
import org.cloudfoundry.client.v3.Metadata;
2122
import org.cloudfoundry.client.v3.Resource;
2223

2324
/**
@@ -37,5 +38,12 @@ public abstract class ServiceInstance extends Resource {
3738
@JsonProperty("relationships")
3839
@Nullable
3940
public abstract ServiceInstanceRelationships getRelationships();
41+
42+
/**
43+
* The metadata
44+
*/
45+
@JsonProperty("metadata")
46+
@Nullable
47+
public abstract Metadata getMetadata();
4048

4149
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/serviceInstances/ServiceInstancesV3.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,13 @@ public interface ServiceInstancesV3 {
5757
* @return the response from the Unshare Service Instance From Another Space request
5858
*/
5959
Mono<Void> unshare(UnshareServiceInstanceRequest request);
60+
61+
/**
62+
* Makes the <a href="http://v3-apidocs.cloudfoundry.org/version/release-candidate/index.html#update-a-service-instance">
63+
* Update a service instance</a> request
64+
*
65+
* @param request the Update Service Instance request
66+
* @return the response from the Update Service Instance request
67+
*/
68+
Mono<UpdateServiceInstanceResponse> update(UpdateServiceInstanceRequest request);
6069
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/serviceInstances/_ListServiceInstancesRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.cloudfoundry.client.v3.serviceInstances;
1818

19+
import org.cloudfoundry.Nullable;
1920
import org.cloudfoundry.client.v3.FilterParameter;
2021
import org.cloudfoundry.client.v3.PaginatedRequest;
2122
import org.immutables.value.Value;
@@ -39,4 +40,11 @@ abstract class _ListServiceInstancesRequest extends PaginatedRequest {
3940
*/
4041
@FilterParameter("space_guids")
4142
abstract List<String> getSpaceIds();
43+
44+
/**
45+
* The metadata query
46+
*/
47+
@FilterParameter("label_selector")
48+
@Nullable
49+
abstract String getLabelSelector();
4250
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2013-2019 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.serviceInstances;
18+
19+
import org.cloudfoundry.client.v3.Metadata;
20+
import org.immutables.value.Value;
21+
22+
import com.fasterxml.jackson.annotation.JsonIgnore;
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
25+
26+
/**
27+
* The request payload for the Update Application operation
28+
*/
29+
@JsonSerialize
30+
@Value.Immutable
31+
abstract class _UpdateServiceInstanceRequest {
32+
33+
/**
34+
* The service instance id
35+
*/
36+
@JsonIgnore
37+
abstract String getServiceInstanceId();
38+
39+
/**
40+
* The metadata
41+
*/
42+
@JsonProperty("metadata")
43+
abstract Metadata getMetadata();
44+
45+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013-2019 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.serviceInstances;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
import org.immutables.value.Value;
21+
22+
/**
23+
* The response payload for the Update Application operation
24+
*/
25+
@JsonDeserialize
26+
@Value.Immutable
27+
abstract class _UpdateServiceInstanceResponse extends ServiceInstance {
28+
29+
}

0 commit comments

Comments
 (0)