Skip to content

Commit b69b402

Browse files
committed
DefaultApplications: use process v3 for healtchecks
1 parent 41e0d6c commit b69b402

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public interface Applications {
9292
Flux<ApplicationEvent> getEvents(GetApplicationEventsRequest request);
9393

9494
/**
95-
* Retrieve the Health Check Type of an application
95+
* Retrieve the Health Check Type of the web process of an application.
9696
*
9797
* @param request the get health check request
9898
* @return the health check

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
import org.cloudfoundry.client.v3.applications.ApplicationResource;
112112
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
113113
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
114+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessRequest;
115+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessResponse;
114116
import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsRequest;
115117
import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsResponse;
116118
import org.cloudfoundry.client.v3.applications.GetApplicationResponse;
@@ -135,6 +137,8 @@
135137
import org.cloudfoundry.client.v3.packages.PackageState;
136138
import org.cloudfoundry.client.v3.packages.PackageType;
137139
import org.cloudfoundry.client.v3.packages.UploadPackageRequest;
140+
import org.cloudfoundry.client.v3.processes.HealthCheck;
141+
import org.cloudfoundry.client.v3.processes.HealthCheckType;
138142
import org.cloudfoundry.client.v3.processes.ProcessState;
139143
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
140144
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
@@ -366,7 +370,11 @@ public Flux<ApplicationEvent> getEvents(GetApplicationEventsRequest request) {
366370

367371
@Override
368372
public Mono<ApplicationHealthCheck> getHealthCheck(GetApplicationHealthCheckRequest request) {
369-
return getApplication(request.getName())
373+
return getApplicationV3(request.getName())
374+
.map(ApplicationResource::getId)
375+
.flatMap(this::requestApplicationWebProcess)
376+
.map(GetApplicationProcessResponse::getHealthCheck)
377+
.map(HealthCheck::getType)
370378
.map(DefaultApplications::toHealthCheck)
371379
.transform(OperationsLogging.log("Get Application Health Check"))
372380
.checkpoint();
@@ -1654,6 +1662,16 @@ private Mono<GetApplicationProcessStatisticsResponse> requestApplicationStatisti
16541662
.build());
16551663
}
16561664

1665+
private Mono<GetApplicationProcessResponse> requestApplicationWebProcess(String applicationId) {
1666+
return this.cloudFoundryClient
1667+
.applicationsV3()
1668+
.getProcess(
1669+
GetApplicationProcessRequest.builder()
1670+
.applicationId(applicationId)
1671+
.type("web")
1672+
.build());
1673+
}
1674+
16571675
private Flux<org.cloudfoundry.client.v3.routes.RouteResource> requestApplicationRoutes(
16581676
String applicationId) {
16591677
return PaginationUtils.requestClientV3Resources(
@@ -2417,17 +2435,15 @@ private static DomainSummary toDomain(PrivateDomainResource resource) {
24172435
.build();
24182436
}
24192437

2420-
private static ApplicationHealthCheck toHealthCheck(AbstractApplicationResource resource) {
2421-
String type = resource.getEntity().getHealthCheckType();
2422-
2423-
if (ApplicationHealthCheck.HTTP.getValue().equals(type)) {
2438+
private static ApplicationHealthCheck toHealthCheck(HealthCheckType type) {
2439+
if (type == HealthCheckType.HTTP) {
24242440
return ApplicationHealthCheck.HTTP;
2425-
} else if (ApplicationHealthCheck.NONE.getValue().equals(type)) {
2426-
return ApplicationHealthCheck.NONE;
2427-
} else if (ApplicationHealthCheck.PORT.getValue().equals(type)) {
2441+
} else if (type == HealthCheckType.PORT) {
24282442
return ApplicationHealthCheck.PORT;
2429-
} else if (ApplicationHealthCheck.PROCESS.getValue().equals(type)) {
2443+
} else if (type == HealthCheckType.PROCESS) {
24302444
return ApplicationHealthCheck.PROCESS;
2445+
} else if (type == HealthCheckType.NONE) {
2446+
return ApplicationHealthCheck.NONE;
24312447
} else {
24322448
return null;
24332449
}

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127
import org.cloudfoundry.client.v3.applications.ApplicationState;
128128
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentRequest;
129129
import org.cloudfoundry.client.v3.applications.GetApplicationEnvironmentResponse;
130+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessRequest;
131+
import org.cloudfoundry.client.v3.applications.GetApplicationProcessResponse;
130132
import org.cloudfoundry.client.v3.applications.GetApplicationProcessStatisticsResponse;
131133
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledRequest;
132134
import org.cloudfoundry.client.v3.applications.GetApplicationSshEnabledResponse;
@@ -136,6 +138,8 @@
136138
import org.cloudfoundry.client.v3.applications.ListApplicationsResponse;
137139
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureRequest;
138140
import org.cloudfoundry.client.v3.applications.UpdateApplicationFeatureResponse;
141+
import org.cloudfoundry.client.v3.processes.HealthCheck;
142+
import org.cloudfoundry.client.v3.processes.HealthCheckType;
139143
import org.cloudfoundry.client.v3.processes.ProcessState;
140144
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
141145
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
@@ -154,6 +158,8 @@
154158
import org.cloudfoundry.util.FluentMap;
155159
import org.cloudfoundry.util.ResourceMatchingUtils;
156160
import org.junit.jupiter.api.Test;
161+
import org.junit.jupiter.params.ParameterizedTest;
162+
import org.junit.jupiter.params.provider.ValueSource;
157163
import org.springframework.core.io.ClassPathResource;
158164
import reactor.core.publisher.Flux;
159165
import reactor.core.publisher.Mono;
@@ -970,21 +976,27 @@ void getEventsTwo() {
970976
.verify(Duration.ofSeconds(5));
971977
}
972978

973-
@Test
974-
void getHealthCheck() {
975-
requestApplications(
979+
@ParameterizedTest
980+
@ValueSource(strings = {"http", "process"})
981+
void getHealthCheck(String healthCheckType) {
982+
requestApplicationsV3(
976983
this.cloudFoundryClient,
977984
"test-application-name",
978985
TEST_SPACE_ID,
979-
"test-metadata-id");
986+
"test-application-id");
987+
requestApplicationProcesses(
988+
this.cloudFoundryClient,
989+
"test-application-id",
990+
HealthCheckType.from(healthCheckType));
980991

981992
this.applications
982993
.getHealthCheck(
983994
GetApplicationHealthCheckRequest.builder()
984995
.name("test-application-name")
985996
.build())
997+
.map(ApplicationHealthCheck::getValue)
986998
.as(StepVerifier::create)
987-
.expectNext(ApplicationHealthCheck.PORT)
999+
.expectNext(healthCheckType)
9881000
.expectComplete()
9891001
.verify(Duration.ofSeconds(5));
9901002
}
@@ -4780,6 +4792,22 @@ private static void requestApplicationsV3(
47804792
.build()));
47814793
}
47824794

4795+
private static void requestApplicationProcesses(
4796+
CloudFoundryClient cloudFoundryClient, String applicationId, HealthCheckType type) {
4797+
when(cloudFoundryClient
4798+
.applicationsV3()
4799+
.getProcess(
4800+
GetApplicationProcessRequest.builder()
4801+
.applicationId(applicationId)
4802+
.type("web")
4803+
.build()))
4804+
.thenReturn(
4805+
Mono.just(
4806+
fill(GetApplicationProcessResponse.builder())
4807+
.healthCheck(fill(HealthCheck.builder()).type(type).build())
4808+
.build()));
4809+
}
4810+
47834811
private static void requestApplicationsWithSsh(
47844812
CloudFoundryClient cloudFoundryClient,
47854813
String application,

0 commit comments

Comments
 (0)