Skip to content

Commit

Permalink
Add the List all Service Bindings for the App V2 operation.
Browse files Browse the repository at this point in the history
This commit adds the v2 API to List all Service Bindings for an App
(GET /v2/apps/:guid/service_bindings).

[#107069280]
  • Loading branch information
Steve Powell committed Nov 26, 2015
1 parent e1fb879 commit c9d5d3d
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.cloudfoundry.client.v2.applications.GetApplicationResponse;
import org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationRoutesResponse;
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsResponse;
import org.cloudfoundry.client.v2.applications.ListApplicationsRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationsResponse;
import org.cloudfoundry.client.v2.applications.RestageApplicationRequest;
Expand Down Expand Up @@ -130,6 +132,16 @@ public Publisher<ListApplicationRoutesResponse> listRoutes(ListApplicationRoutes
});
}

@Override
public Publisher<ListApplicationServiceBindingsResponse> listServiceBindings
(ListApplicationServiceBindingsRequest request) {
return get(request, ListApplicationServiceBindingsResponse.class, builder -> {
builder.pathSegment("v2", "apps", request.getId(), "service_bindings");
FilterBuilder.augment(builder, request);
QueryBuilder.augment(builder, request);
});
}

@Override
public Publisher<RestageApplicationResponse> restage(RestageApplicationRequest request) {
return post(request, RestageApplicationResponse.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.cloudfoundry.client.v2.applications.JobEntity;
import org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationRoutesResponse;
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsResponse;
import org.cloudfoundry.client.v2.applications.ListApplicationsRequest;
import org.cloudfoundry.client.v2.applications.ListApplicationsResponse;
import org.cloudfoundry.client.v2.applications.RestageApplicationEntity;
Expand All @@ -54,6 +56,8 @@
import org.cloudfoundry.client.v2.routes.Route;
import org.cloudfoundry.client.v2.routes.RouteEntity;
import org.cloudfoundry.client.v2.routes.RouteResource;
import org.cloudfoundry.client.v2.serviceinstances.ServiceBindingEntity;
import org.cloudfoundry.client.v2.serviceinstances.ServiceBindingResource;
import org.cloudfoundry.client.v2.serviceinstances.ServiceInstance;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
Expand Down Expand Up @@ -639,6 +643,69 @@ public void listRoutesInvalidRequest() {
Streams.wrap(this.applications.listRoutes(request)).next().get();
}

@Test
public void listServiceBindings() {
mockRequest(new RequestContext()
.method(GET)
.path("v2/apps/test-id/service_bindings?q=service_instance_guid%20IN%20test-instance-id&page=-1")
.status(OK)
.responsePayload("v2/apps/GET_{id}_service_bindings_response.json"));

ListApplicationServiceBindingsRequest request = ListApplicationServiceBindingsRequest.builder()
.id("test-id")
.serviceInstanceId("test-instance-id")
.page(-1)
.build();

ListApplicationServiceBindingsResponse expected = ListApplicationServiceBindingsResponse.builder()
.totalResults(1)
.totalPages(1)
.resource(ServiceBindingResource.builder()
.metadata(Resource.Metadata.builder()
.createdAt("2015-07-27T22:43:20Z")
.id("42eda707-fe4d-4eed-9b39-7cb5e665c226")
.url("/v2/service_bindings/42eda707-fe4d-4eed-9b39-7cb5e665c226")
.build())
.entity(ServiceBindingEntity.builder()
.applicationId("26ddc1de-3eeb-424b-82f3-f7f30a38b610")
.serviceInstanceId("650d0eb7-3b83-414a-82a0-d503d1c8eb5f")
.credential("creds-key-356", "creds-val-356")
.gatewayName("")
.applicationUrl("/v2/apps/26ddc1de-3eeb-424b-82f3-f7f30a38b610")
.serviceInstanceUrl("/v2/service_instances/650d0eb7-3b83-414a-82a0-d503d1c8eb5f")
.build())
.build())
.build();

ListApplicationServiceBindingsResponse actual = Streams.wrap(this.applications.listServiceBindings(request))
.next().get();

assertEquals(expected, actual);
verify();
}

@Test(expected = CloudFoundryException.class)
public void listServiceBindingsError() {
mockRequest(new RequestContext()
.method(GET).path("v2/apps/test-id/service_bindings?page=-1")
.errorResponse());

ListApplicationServiceBindingsRequest request = ListApplicationServiceBindingsRequest.builder()
.id("test-id")
.page(-1)
.build();

Streams.wrap(this.applications.listServiceBindings(request)).next().get();
}

@Test(expected = RequestValidationException.class)
public void listServiceBindingsInvalidRequest() {
ListApplicationServiceBindingsRequest request = ListApplicationServiceBindingsRequest.builder()
.build();

Streams.wrap(this.applications.listServiceBindings(request)).next().get();
}

@Test
public void restage() {
mockRequest(new RequestContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"total_results": 1,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"guid": "42eda707-fe4d-4eed-9b39-7cb5e665c226",
"url": "/v2/service_bindings/42eda707-fe4d-4eed-9b39-7cb5e665c226",
"created_at": "2015-07-27T22:43:20Z",
"updated_at": null
},
"entity": {
"app_guid": "26ddc1de-3eeb-424b-82f3-f7f30a38b610",
"service_instance_guid": "650d0eb7-3b83-414a-82a0-d503d1c8eb5f",
"credentials": {
"creds-key-356": "creds-val-356"
},
"binding_options": {

},
"gateway_data": null,
"gateway_name": "",
"syslog_drain_url": null,
"app_url": "/v2/apps/26ddc1de-3eeb-424b-82f3-f7f30a38b610",
"service_instance_url": "/v2/service_instances/650d0eb7-3b83-414a-82a0-d503d1c8eb5f"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,24 @@ public interface ApplicationsV2 {
Publisher<ListApplicationsResponse> list(ListApplicationsRequest request);

/**
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/list_all_routes_for_the_app.html">List all Routes
* for the Application</a> request
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/list_all_routes_for_the_app.html">List all Routes for
* the Application</a> request
*
* @param request the List all Routes for the Application request
* @return the response from the List all Routes for the Application request
*/
Publisher<ListApplicationRoutesResponse> listRoutes(ListApplicationRoutesRequest request);

/**
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/list_all_service_bindings_for_the_app.html">List all
* Service Bindings for the App</a> request
*
* @param request the List Service Bindings request
* @return the response from the List Service Bindings request
*/
Publisher<ListApplicationServiceBindingsResponse> listServiceBindings(ListApplicationServiceBindingsRequest
request);

/**
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/restage_an_app.html">Restage an App</a> request
*
Expand Down Expand Up @@ -121,7 +131,7 @@ public interface ApplicationsV2 {
Publisher<SummaryApplicationResponse> summary(SummaryApplicationRequest request);

/**
* Makes the
* Makes the
* <a href="http://apidocs.cloudfoundry.org/214/apps/terminate_the_running_app_instance_at_the_given_index.html">
* Terminate Application Instance</a> request
*
Expand All @@ -131,8 +141,8 @@ public interface ApplicationsV2 {
Publisher<Void> terminateInstance(TerminateApplicationInstanceRequest request);

/**
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html">Upload the bits
* for an App</a> request
* Makes the <a href="http://apidocs.cloudfoundry.org/214/apps/uploads_the_bits_for_an_app.html">Upload the bits for
* an App</a> request
*
* @param request the Upload Application request
* @return the response from the Upload Application request
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright 2013-2015 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.v2.applications;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Singular;
import lombok.ToString;
import org.cloudfoundry.client.Validatable;
import org.cloudfoundry.client.ValidationResult;
import org.cloudfoundry.client.v2.FilterParameter;
import org.cloudfoundry.client.v2.PaginatedRequest;

import java.util.List;

/**
* The request payload for the List all Service Bindings for the App operation
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public final class ListApplicationServiceBindingsRequest extends PaginatedRequest implements Validatable {

/**
* The ids of the service instances
*
* @param serviceInstanceIds the ids of the service instances to filter on
* @return the ids of the service instances to filter on
*/
@Getter(onMethod = @__(@FilterParameter("service_instance_guid")))
private volatile List<String> serviceInstanceIds;

/**
* The id of the App
*
* @param id the id of the App
* @return the id of the App
*/
@Getter(onMethod = @__(@JsonIgnore))
private volatile String id;

@Builder
ListApplicationServiceBindingsRequest(OrderDirection orderDirection,
Integer page,
Integer resultsPerPage,
@Singular List<String> serviceInstanceIds,
String id) {
super(orderDirection, page, resultsPerPage);
this.serviceInstanceIds = serviceInstanceIds;
this.id = id;
}

@Override
public ValidationResult isValid() {
ValidationResult.ValidationResultBuilder builder = ValidationResult.builder();

if (this.id == null) {
builder.message("id must be specified");
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2013-2015 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.v2.applications;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Singular;
import lombok.ToString;
import org.cloudfoundry.client.v2.PaginatedResponse;
import org.cloudfoundry.client.v2.serviceinstances.ServiceBindingResource;

import java.util.List;

/**
* The response payload for the List all Service Bindings for the App operation
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public final class ListApplicationServiceBindingsResponse extends PaginatedResponse<ServiceBindingResource> {

@Builder
ListApplicationServiceBindingsResponse(@JsonProperty("next_url") String nextUrl,
@JsonProperty("prev_url") String previousUrl,
@JsonProperty("resources") @Singular List<ServiceBindingResource> resources,
@JsonProperty("total_pages") Integer totalPages,
@JsonProperty("total_results") Integer totalResults) {

super(nextUrl, previousUrl, resources, totalPages, totalResults);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2013-2015 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.v2.serviceinstances;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.Singular;

import java.util.Map;

/**
* The entity response payload for the Service Binding resource
*/
@Data
public final class ServiceBindingEntity {

private final String applicationId;

private final String applicationUrl;

private final Map<String, Object> bindingOptions;

private final Map<String, Object> credentials;

private final Map<String, Object> gatewayData;

private final String gatewayName;

private final String serviceInstanceId;

private final String serviceInstanceUrl;

private final String syslogDrainUrl;

@Builder
ServiceBindingEntity(@JsonProperty("app_guid") String applicationId,
@JsonProperty("app_url") String applicationUrl,
@JsonProperty("binding_options") @Singular Map<String, Object> bindingOptions,
@JsonProperty("credentials") @Singular Map<String, Object> credentials,
@JsonProperty("gateway_data") Map<String, Object> gatewayData,
@JsonProperty("gateway_name") String gatewayName,
@JsonProperty("service_instance_guid") String serviceInstanceId,
@JsonProperty("service_instance_url") String serviceInstanceUrl,
@JsonProperty("syslog_drain_url") String syslogDrainUrl) {

this.applicationId = applicationId;
this.applicationUrl = applicationUrl;
this.bindingOptions = bindingOptions;
this.credentials = credentials;
this.gatewayData = gatewayData;
this.gatewayName = gatewayName;
this.serviceInstanceId = serviceInstanceId;
this.serviceInstanceUrl = serviceInstanceUrl;
this.syslogDrainUrl = syslogDrainUrl;
}
}
Loading

0 comments on commit c9d5d3d

Please sign in to comment.