Skip to content

Commit 7041647

Browse files
committed
DefaultApplications: all stacks() references now use v3 API
1 parent 0a30f77 commit 7041647

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@
9494
import org.cloudfoundry.client.v2.spaces.ListSpaceServiceInstancesRequest;
9595
import org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary;
9696
import org.cloudfoundry.client.v2.spaces.SpaceResource;
97-
import org.cloudfoundry.client.v2.stacks.GetStackRequest;
98-
import org.cloudfoundry.client.v2.stacks.GetStackResponse;
99-
import org.cloudfoundry.client.v2.stacks.ListStacksRequest;
100-
import org.cloudfoundry.client.v2.stacks.StackResource;
10197
import org.cloudfoundry.client.v3.BuildpackData;
10298
import org.cloudfoundry.client.v3.Lifecycle;
10399
import org.cloudfoundry.client.v3.Relationship;
@@ -144,6 +140,10 @@
144140
import org.cloudfoundry.client.v3.processes.UpdateProcessRequest;
145141
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
146142
import org.cloudfoundry.client.v3.spaces.ApplyManifestRequest;
143+
import org.cloudfoundry.client.v3.stacks.GetStackRequest;
144+
import org.cloudfoundry.client.v3.stacks.GetStackResponse;
145+
import org.cloudfoundry.client.v3.stacks.ListStacksRequest;
146+
import org.cloudfoundry.client.v3.stacks.StackResource;
147147
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
148148
import org.cloudfoundry.client.v3.tasks.CancelTaskResponse;
149149
import org.cloudfoundry.client.v3.tasks.CreateTaskRequest;
@@ -1111,7 +1111,7 @@ private Mono<ApplicationResource> getApplicationV3(String application) {
11111111
Tuple5<
11121112
List<String>,
11131113
SummaryApplicationResponse,
1114-
GetStackResponse,
1114+
String,
11151115
List<InstanceDetail>,
11161116
List<String>>>
11171117
getAuxiliaryContent(AbstractApplicationResource applicationResource) {
@@ -1130,7 +1130,7 @@ private Mono<ApplicationResource> getApplicationV3(String application) {
11301130
Mono.zip(
11311131
getApplicationBuildpacks(applicationId),
11321132
Mono.just(summaryApplicationResponse),
1133-
requestStack(stackId),
1133+
getStackName(stackId),
11341134
toInstanceDetailList(
11351135
applicationInstancesResponse,
11361136
applicationStatisticsResponse),
@@ -1376,18 +1376,20 @@ private Mono<String> getSpaceOrganizationId(String spaceId) {
13761376
.map(response -> ResourceUtils.getEntity(response).getOrganizationId());
13771377
}
13781378

1379-
private Mono<String> getStackId(String stack) {
1380-
return requestStacks(stack)
1381-
.map(ResourceUtils::getId)
1379+
private Mono<String> getStackId(String stackName) {
1380+
return requestStacks(stackName)
1381+
.map(StackResource::getId)
13821382
.single()
13831383
.onErrorResume(
13841384
NoSuchElementException.class,
1385-
t -> ExceptionUtils.illegalArgument("Stack %s does not exist", stack));
1385+
t -> ExceptionUtils.illegalArgument("Stack %s does not exist", stackName));
13861386
}
13871387

13881388
private Mono<String> getStackName(String stackId) {
1389-
return requestStack(stackId)
1390-
.map(getStackResponse -> getStackResponse.getEntity().getName());
1389+
return this.cloudFoundryClient
1390+
.stacksV3()
1391+
.get(GetStackRequest.builder().stackId(stackId).build())
1392+
.map(GetStackResponse::getName);
13911393
}
13921394

13931395
private Mono<String> getTaskId(String applicationId, Integer sequenceId) {
@@ -2042,17 +2044,11 @@ private Mono<GetSpaceSummaryResponse> requestSpaceSummary() {
20422044
.getSummary(GetSpaceSummaryRequest.builder().spaceId(this.spaceId).build());
20432045
}
20442046

2045-
private Mono<GetStackResponse> requestStack(String stackId) {
2046-
return this.cloudFoundryClient
2047-
.stacks()
2048-
.get(GetStackRequest.builder().stackId(stackId).build());
2049-
}
2050-
20512047
private Flux<StackResource> requestStacks(String stack) {
2052-
return PaginationUtils.requestClientV2Resources(
2048+
return PaginationUtils.requestClientV3Resources(
20532049
page ->
20542050
this.cloudFoundryClient
2055-
.stacks()
2051+
.stacksV3()
20562052
.list(ListStacksRequest.builder().page(page).name(stack).build()));
20572053
}
20582054

@@ -2305,7 +2301,7 @@ private Mono<AbstractApplicationResource> stopApplicationIfNotStopped(
23052301
private static ApplicationDetail toApplicationDetail(
23062302
List<String> buildpacks,
23072303
SummaryApplicationResponse summaryApplicationResponse,
2308-
GetStackResponse getStackResponse,
2304+
String stackName,
23092305
List<InstanceDetail> instanceDetails,
23102306
List<String> urls) {
23112307
if (buildpacks.size() == 0) {
@@ -2324,7 +2320,7 @@ private static ApplicationDetail toApplicationDetail(
23242320
.name(summaryApplicationResponse.getName())
23252321
.requestedState(summaryApplicationResponse.getState())
23262322
.runningInstances(summaryApplicationResponse.getRunningInstances())
2327-
.stack(getStackResponse.getEntity().getName())
2323+
.stack(stackName)
23282324
.urls(urls)
23292325
.build();
23302326
}

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,6 @@
112112
import org.cloudfoundry.client.v2.spaces.SpaceApplicationSummary;
113113
import org.cloudfoundry.client.v2.spaces.SpaceEntity;
114114
import org.cloudfoundry.client.v2.spaces.SpaceResource;
115-
import org.cloudfoundry.client.v2.stacks.GetStackRequest;
116-
import org.cloudfoundry.client.v2.stacks.GetStackResponse;
117-
import org.cloudfoundry.client.v2.stacks.ListStacksRequest;
118-
import org.cloudfoundry.client.v2.stacks.ListStacksResponse;
119-
import org.cloudfoundry.client.v2.stacks.StackEntity;
120115
import org.cloudfoundry.client.v3.BuildpackData;
121116
import org.cloudfoundry.client.v3.DockerData;
122117
import org.cloudfoundry.client.v3.Lifecycle;
@@ -146,6 +141,9 @@
146141
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
147142
import org.cloudfoundry.client.v3.processes.UpdateProcessRequest;
148143
import org.cloudfoundry.client.v3.processes.UpdateProcessResponse;
144+
import org.cloudfoundry.client.v3.stacks.GetStackRequest;
145+
import org.cloudfoundry.client.v3.stacks.ListStacksRequest;
146+
import org.cloudfoundry.client.v3.stacks.ListStacksResponse;
149147
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
150148
import org.cloudfoundry.client.v3.tasks.CancelTaskResponse;
151149
import org.cloudfoundry.client.v3.tasks.CreateTaskRequest;
@@ -5699,19 +5697,19 @@ private static void requestSpaceSummary(CloudFoundryClient cloudFoundryClient, S
56995697
}
57005698

57015699
private static void requestStack(CloudFoundryClient cloudFoundryClient, String stackId) {
5702-
when(cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build()))
5700+
when(cloudFoundryClient.stacksV3().get(GetStackRequest.builder().stackId(stackId).build()))
57035701
.thenReturn(
57045702
Mono.just(
5705-
fill(GetStackResponse.builder())
5706-
.entity(
5707-
fill(StackEntity.builder(), "stack-entity-")
5708-
.build())
5703+
fill(
5704+
org.cloudfoundry.client.v3.stacks.GetStackResponse
5705+
.builder(),
5706+
"stack-entity-")
57095707
.build()));
57105708
}
57115709

57125710
private static void requestStackIdEmpty(CloudFoundryClient cloudFoundryClient, String stack) {
57135711
when(cloudFoundryClient
5714-
.stacks()
5712+
.stacksV3()
57155713
.list(ListStacksRequest.builder().name(stack).page(1).build()))
57165714
.thenReturn(Mono.just(fill(ListStacksResponse.builder()).build()));
57175715
}

0 commit comments

Comments
 (0)