Skip to content

Commit 5e22e96

Browse files
committed
DefaultApplications: use applicationsV3 for routes
1 parent 016e3c9 commit 5e22e96

File tree

2 files changed

+723
-635
lines changed

2 files changed

+723
-635
lines changed

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

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.cloudfoundry.client.v2.applications.CreateApplicationResponse;
5757
import org.cloudfoundry.client.v2.applications.DockerCredentials;
5858
import org.cloudfoundry.client.v2.applications.InstanceStatistics;
59-
import org.cloudfoundry.client.v2.applications.ListApplicationRoutesRequest;
6059
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest;
6160
import org.cloudfoundry.client.v2.applications.RemoveApplicationRouteRequest;
6261
import org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest;
@@ -112,10 +111,13 @@
112111
import org.cloudfoundry.client.v3.applications.ApplicationResource;
113112
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
114113
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
114+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsRequest;
115+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsResponse;
115116
import org.cloudfoundry.client.v3.applications.GetApplicationResponse;
116117
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
117118
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
118119
import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest;
120+
import org.cloudfoundry.client.v3.applications.ListApplicationRoutesRequest;
119121
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
120122
import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest;
121123
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest;
@@ -821,14 +823,15 @@ private static String cleanName(ApplicationManifest manifest) {
821823
return manifest.getName().replaceAll("\\.", "");
822824
}
823825

824-
private static BiFunction<String, String, String> collectStates() {
826+
public static BiFunction<ProcessState, ProcessState, ProcessState> collectStates() {
825827
return (totalState, instanceState) -> {
826-
if ("RUNNING".equals(instanceState) || "RUNNING".equals(totalState)) {
827-
return "RUNNING";
828+
if (ProcessState.RUNNING.equals(instanceState)
829+
|| ProcessState.RUNNING.equals(totalState)) {
830+
return ProcessState.RUNNING;
828831
}
829832

830-
if ("FLAPPING".equals(instanceState) || "CRASHED".equals(instanceState)) {
831-
return "FAILED";
833+
if (ProcessState.CRASHED.equals(instanceState)) {
834+
return ProcessState.CRASHED;
832835
}
833836

834837
return totalState;
@@ -1096,7 +1099,8 @@ private Mono<ApplicationInstancesResponse> getApplicationInstances(String applic
10961099
t -> Mono.just(ApplicationInstancesResponse.builder().build()));
10971100
}
10981101

1099-
private Mono<List<RouteResource>> getApplicationRoutes(String applicationId) {
1102+
private Mono<List<org.cloudfoundry.client.v3.routes.RouteResource>> getApplicationRoutes(
1103+
String applicationId) {
11001104
return requestApplicationRoutes(applicationId).collectList();
11011105
}
11021106

@@ -1433,8 +1437,8 @@ private static boolean isIdentical(String s, String t) {
14331437
return Objects.equals(s, t);
14341438
}
14351439

1436-
private static Predicate<String> isInstanceComplete() {
1437-
return state -> "RUNNING".equals(state) || "FAILED".equals(state);
1440+
private static Predicate<ProcessState> isInstanceComplete() {
1441+
return state -> ProcessState.RUNNING.equals(state) || ProcessState.CRASHED.equals(state);
14381442
}
14391443

14401444
private static Predicate<AbstractApplicationResource> isNotIn(String expectedState) {
@@ -1451,8 +1455,8 @@ private static boolean isRestartRequired(
14511455
&& STARTED_STATE.equals(ResourceUtils.getEntity(applicationResource).getState());
14521456
}
14531457

1454-
private static Predicate<String> isRunning() {
1455-
return "RUNNING"::equals;
1458+
private static Predicate<ProcessState> isRunning() {
1459+
return ProcessState.RUNNING::equals;
14561460
}
14571461

14581462
private static Predicate<String> isStaged() {
@@ -1490,11 +1494,11 @@ private Mono<Void> prepareDomainsAndRoutes(
14901494
String applicationId,
14911495
List<DomainSummary> availableDomains,
14921496
ApplicationManifest manifest,
1493-
List<RouteResource> existingRoutes,
1497+
List<org.cloudfoundry.client.v3.routes.RouteResource> existingRoutes,
14941498
RandomWords randomWords) {
14951499
if (Optional.ofNullable(manifest.getNoRoute()).orElse(false)) {
14961500
return Flux.fromIterable(existingRoutes)
1497-
.map(ResourceUtils::getId)
1501+
.map(org.cloudfoundry.client.v3.routes.RouteResource::getId)
14981502
.flatMap(routeId -> requestRemoveRouteFromApplication(applicationId, routeId))
14991503
.then();
15001504
}
@@ -1524,7 +1528,9 @@ private Mono<Void> prepareDomainsAndRoutes(
15241528
}
15251529

15261530
List<String> existingRouteIds =
1527-
existingRoutes.stream().map(ResourceUtils::getId).collect(Collectors.toList());
1531+
existingRoutes.stream()
1532+
.map(org.cloudfoundry.client.v3.routes.RouteResource::getId)
1533+
.collect(Collectors.toList());
15281534

15291535
return getPushRouteIdFromRoute(availableDomains, manifest, randomWords)
15301536
.filter(routeId -> !existingRouteIds.contains(routeId))
@@ -1640,11 +1646,23 @@ private Mono<ApplicationInstancesResponse> requestApplicationInstances(String ap
16401646
ApplicationInstancesRequest.builder().applicationId(applicationId).build());
16411647
}
16421648

1643-
private Flux<RouteResource> requestApplicationRoutes(String applicationId) {
1644-
return PaginationUtils.requestClientV2Resources(
1649+
private Mono<GetApplicationProcessStatisticsResponse> requestApplicationStatisticsV3(
1650+
String applicationId) {
1651+
return this.cloudFoundryClient
1652+
.applicationsV3()
1653+
.getProcessStatistics(
1654+
GetApplicationProcessStatisticsRequest.builder()
1655+
.applicationId(applicationId)
1656+
.type("web")
1657+
.build());
1658+
}
1659+
1660+
private Flux<org.cloudfoundry.client.v3.routes.RouteResource> requestApplicationRoutes(
1661+
String applicationId) {
1662+
return PaginationUtils.requestClientV3Resources(
16451663
page ->
16461664
this.cloudFoundryClient
1647-
.applicationsV2()
1665+
.applicationsV3()
16481666
.listRoutes(
16491667
ListApplicationRoutesRequest.builder()
16501668
.applicationId(applicationId)
@@ -2616,10 +2634,10 @@ private Mono<Void> waitForRunning(
26162634
String application, String applicationId, Duration startupTimeout) {
26172635
Duration timeout = Optional.ofNullable(startupTimeout).orElse(Duration.ofMinutes(5));
26182636

2619-
return requestApplicationInstances(applicationId)
2620-
.flatMapMany(response -> Flux.fromIterable(response.getInstances().values()))
2621-
.map(ApplicationInstanceInfo::getState)
2622-
.reduce("UNKNOWN", collectStates())
2637+
return requestApplicationStatisticsV3(applicationId)
2638+
.flatMapIterable(GetApplicationProcessStatisticsResponse::getResources)
2639+
.map(ProcessStatisticsResource::getState)
2640+
.reduce(ProcessState.STARTING, collectStates())
26232641
.filter(isInstanceComplete())
26242642
.repeatWhenEmpty(
26252643
exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), timeout))

0 commit comments

Comments
 (0)