Skip to content

Commit 00e022e

Browse files
committed
DefaultApplications: use applicationsV3 to determine app started
1 parent b287d58 commit 00e022e

File tree

3 files changed

+630
-675
lines changed

3 files changed

+630
-675
lines changed

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

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
import org.cloudfoundry.client.v3.applications.GetApplicationResponse;
117117
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
118118
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
119-
import org.cloudfoundry.client.v3.applications.ListApplicationProcessesRequest;
120119
import org.cloudfoundry.client.v3.applications.ListApplicationRoutesRequest;
121120
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
122121
import org.cloudfoundry.client.v3.applications.SetApplicationCurrentDropletRequest;
@@ -136,8 +135,6 @@
136135
import org.cloudfoundry.client.v3.packages.PackageState;
137136
import org.cloudfoundry.client.v3.packages.PackageType;
138137
import org.cloudfoundry.client.v3.packages.UploadPackageRequest;
139-
import org.cloudfoundry.client.v3.processes.GetProcessStatisticsRequest;
140-
import org.cloudfoundry.client.v3.processes.GetProcessStatisticsResponse;
141138
import org.cloudfoundry.client.v3.processes.ProcessState;
142139
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
143140
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
@@ -2655,61 +2652,7 @@ private Mono<Void> waitForRunning(
26552652

26562653
private Mono<Void> waitForRunningV3(
26572654
String applicationName, String applicationId, Duration startupTimeout) {
2658-
Duration timeout = Optional.ofNullable(startupTimeout).orElse(Duration.ofMinutes(5));
2659-
2660-
return PaginationUtils.requestClientV3Resources(
2661-
page ->
2662-
this.cloudFoundryClient
2663-
.applicationsV3()
2664-
.listProcesses(
2665-
ListApplicationProcessesRequest.builder()
2666-
.applicationId(applicationId)
2667-
.page(page)
2668-
.build()))
2669-
.filter(p -> p.getInstances() != 0)
2670-
.flatMap(
2671-
process ->
2672-
this.cloudFoundryClient
2673-
.processes()
2674-
.getStatistics(
2675-
GetProcessStatisticsRequest.builder()
2676-
.processId(process.getId())
2677-
.build())
2678-
.flatMapIterable(GetProcessStatisticsResponse::getResources)
2679-
.map(ProcessStatisticsResource::getState)
2680-
.filter(
2681-
state ->
2682-
EnumSet.of(
2683-
ProcessState.RUNNING,
2684-
ProcessState.CRASHED)
2685-
.contains(state))
2686-
.reduce(
2687-
(totalState, instanceState) ->
2688-
totalState.ordinal()
2689-
< instanceState.ordinal()
2690-
? totalState
2691-
: instanceState) // CRASHED takes
2692-
// precedence over
2693-
// RUNNING
2694-
.repeatWhenEmpty(
2695-
exponentialBackOff(
2696-
Duration.ofSeconds(1),
2697-
Duration.ofSeconds(15),
2698-
timeout))
2699-
.filter(state -> state == ProcessState.RUNNING)
2700-
.switchIfEmpty(
2701-
ExceptionUtils.illegalState(
2702-
"Process %s of Application %s failed during"
2703-
+ " start",
2704-
process.getId(), applicationName))
2705-
.onErrorResume(
2706-
DelayTimeoutException.class,
2707-
t ->
2708-
ExceptionUtils.illegalState(
2709-
"Process %s of Application %s timed"
2710-
+ " out during start",
2711-
process.getId(), applicationName)))
2712-
.then();
2655+
return waitForRunning(applicationName, applicationId, startupTimeout);
27132656
}
27142657

27152658
private Mono<Void> waitForStaging(

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.cloudfoundry.client.v3.domains.DomainsV3;
4949
import org.cloudfoundry.client.v3.jobs.JobsV3;
5050
import org.cloudfoundry.client.v3.organizations.OrganizationsV3;
51+
import org.cloudfoundry.client.v3.processes.Processes;
5152
import org.cloudfoundry.client.v3.routes.RoutesV3;
5253
import org.cloudfoundry.client.v3.spaces.SpacesV3;
5354
import org.cloudfoundry.client.v3.stacks.StacksV3;
@@ -117,6 +118,7 @@ public abstract class AbstractOperationsTest {
117118
protected final Organizations organizations = mock(Organizations.class, RETURNS_SMART_NULLS);
118119
protected final OrganizationsV3 organizationsV3 =
119120
mock(OrganizationsV3.class, RETURNS_SMART_NULLS);
121+
protected final Processes processes = mock(Processes.class, RETURNS_SMART_NULLS);
120122

121123
protected final PrivateDomains privateDomains = mock(PrivateDomains.class, RETURNS_SMART_NULLS);
122124

@@ -188,6 +190,7 @@ public final void mockClient() {
188190
when(this.cloudFoundryClient.organizationQuotaDefinitions())
189191
.thenReturn(this.organizationQuotaDefinitions);
190192
when(this.cloudFoundryClient.privateDomains()).thenReturn(this.privateDomains);
193+
when(this.cloudFoundryClient.processes()).thenReturn(this.processes);
191194
when(this.cloudFoundryClient.resourceMatch()).thenReturn(this.resourceMatch);
192195
when(this.cloudFoundryClient.routes()).thenReturn(this.routes);
193196
when(this.cloudFoundryClient.routesV3()).thenReturn(this.routesV3);

0 commit comments

Comments
 (0)