Skip to content

Commit 15d243f

Browse files
committed
DefaultApplications: setHealthCheck uses v3 api
1 parent 8986d79 commit 15d243f

File tree

3 files changed

+59
-25
lines changed

3 files changed

+59
-25
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
@@ -225,7 +225,7 @@ public interface Applications {
225225
Mono<Void> setEnvironmentVariable(SetEnvironmentVariableApplicationRequest request);
226226

227227
/**
228-
* Set the Health Check Type of an application
228+
* Set the Health Check Type of the web process of an application
229229
*
230230
* @param request the set health check request
231231
* @return a completion indicator

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import org.cloudfoundry.client.v3.processes.HealthCheckType;
140140
import org.cloudfoundry.client.v3.processes.ProcessState;
141141
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
142+
import org.cloudfoundry.client.v3.processes.UpdateProcessRequest;
142143
import org.cloudfoundry.client.v3.resourcematch.MatchedResource;
143144
import org.cloudfoundry.client.v3.spaces.ApplyManifestRequest;
144145
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
@@ -641,12 +642,12 @@ public Mono<Void> setEnvironmentVariable(SetEnvironmentVariableApplicationReques
641642

642643
@Override
643644
public Mono<Void> setHealthCheck(SetApplicationHealthCheckRequest request) {
644-
return getApplicationId(request.getName())
645+
return getApplicationIdV3(request.getName())
646+
.flatMap(this::requestApplicationWebProcess)
645647
.flatMap(
646-
applicationId ->
647-
requestUpdateApplicationHealthCheckType(
648-
applicationId, request.getType()))
649-
.then()
648+
webProcess ->
649+
this.requestUpdateProcessHealthCheckType(
650+
webProcess.getId(), fromHealthCheck(request.getType())))
650651
.transform(OperationsLogging.log("Set Application Health Check"))
651652
.checkpoint();
652653
}
@@ -1668,6 +1669,18 @@ private Mono<GetApplicationProcessResponse> requestApplicationWebProcess(String
16681669
.build());
16691670
}
16701671

1672+
private Mono<Void> requestUpdateProcessHealthCheckType(
1673+
String processId, HealthCheckType healthCheckType) {
1674+
return this.cloudFoundryClient
1675+
.processes()
1676+
.update(
1677+
UpdateProcessRequest.builder()
1678+
.processId(processId)
1679+
.healthCheck(HealthCheck.builder().type(healthCheckType).build())
1680+
.build())
1681+
.then();
1682+
}
1683+
16711684
private Flux<org.cloudfoundry.client.v3.routes.RouteResource> requestApplicationRoutes(
16721685
String applicationId) {
16731686
return PaginationUtils.requestClientV3Resources(
@@ -2460,6 +2473,20 @@ private static ApplicationHealthCheck toHealthCheck(HealthCheckType type) {
24602473
}
24612474
}
24622475

2476+
private static HealthCheckType fromHealthCheck(ApplicationHealthCheck type) {
2477+
if (type == ApplicationHealthCheck.HTTP) {
2478+
return HealthCheckType.HTTP;
2479+
} else if (type == ApplicationHealthCheck.PORT) {
2480+
return HealthCheckType.PORT;
2481+
} else if (type == ApplicationHealthCheck.PROCESS) {
2482+
return HealthCheckType.PROCESS;
2483+
} else if (type == ApplicationHealthCheck.NONE) {
2484+
return HealthCheckType.NONE;
2485+
} else {
2486+
return null;
2487+
}
2488+
}
2489+
24632490
private static InstanceDetail toInstanceDetail(
24642491
Map.Entry<String, ApplicationInstanceInfo> entry,
24652492
ApplicationStatisticsResponse statisticsResponse) {

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
import static org.cloudfoundry.client.v3.LifecycleType.DOCKER;
2222
import static org.cloudfoundry.operations.TestObjects.fill;
2323
import static org.mockito.ArgumentMatchers.any;
24+
import static org.mockito.ArgumentMatchers.argThat;
2425
import static org.mockito.Mockito.RETURNS_SMART_NULLS;
2526
import static org.mockito.Mockito.mock;
27+
import static org.mockito.Mockito.verify;
2628
import static org.mockito.Mockito.when;
2729

2830
import java.io.IOException;
@@ -140,6 +142,8 @@
140142
import org.cloudfoundry.client.v3.processes.HealthCheckType;
141143
import org.cloudfoundry.client.v3.processes.ProcessState;
142144
import org.cloudfoundry.client.v3.processes.ProcessStatisticsResource;
145+
import org.cloudfoundry.client.v3.processes.UpdateProcessRequest;
146+
import org.cloudfoundry.client.v3.processes.UpdateProcessResponse;
143147
import org.cloudfoundry.client.v3.tasks.CancelTaskRequest;
144148
import org.cloudfoundry.client.v3.tasks.CancelTaskResponse;
145149
import org.cloudfoundry.client.v3.tasks.CreateTaskRequest;
@@ -3695,13 +3699,15 @@ void setEnvironmentVariableNoApp() {
36953699

36963700
@Test
36973701
void setHealthCheck() {
3698-
requestApplications(
3702+
requestApplicationsV3(
36993703
this.cloudFoundryClient,
37003704
"test-application-name",
37013705
TEST_SPACE_ID,
37023706
"test-application-id");
3707+
requestApplicationProcesses(
3708+
cloudFoundryClient, "test-application-id", HealthCheckType.HTTP);
37033709
requestUpdateApplicationHealthCheck(
3704-
this.cloudFoundryClient, "test-application-id", ApplicationHealthCheck.PORT);
3710+
this.cloudFoundryClient, "test-process-id", ApplicationHealthCheck.PORT);
37053711

37063712
this.applications
37073713
.setHealthCheck(
@@ -3712,6 +3718,14 @@ void setHealthCheck() {
37123718
.as(StepVerifier::create)
37133719
.expectComplete()
37143720
.verify(Duration.ofSeconds(5));
3721+
3722+
verify(this.cloudFoundryClient.processes())
3723+
.update(
3724+
argThat(
3725+
argument ->
3726+
argument.getHealthCheck()
3727+
.getType()
3728+
.equals(HealthCheckType.PORT)));
37153729
}
37163730

37173731
@Test
@@ -4782,7 +4796,7 @@ private static void requestApplicationProcesses(
47824796
.build()))
47834797
.thenReturn(
47844798
Mono.just(
4785-
fill(GetApplicationProcessResponse.builder())
4799+
fill(GetApplicationProcessResponse.builder(), "process-")
47864800
.healthCheck(fill(HealthCheck.builder()).type(type).build())
47874801
.build()));
47884802
}
@@ -5860,25 +5874,18 @@ private static void requestUpdateApplicationEnvironment(
58605874
}
58615875

58625876
private static void requestUpdateApplicationHealthCheck(
5863-
CloudFoundryClient cloudFoundryClient,
5864-
String applicationId,
5865-
ApplicationHealthCheck type) {
5877+
CloudFoundryClient cloudFoundryClient, String processId, ApplicationHealthCheck type) {
58665878
when(cloudFoundryClient
5867-
.applicationsV2()
5879+
.processes()
58685880
.update(
5869-
UpdateApplicationRequest.builder()
5870-
.applicationId(applicationId)
5871-
.healthCheckType(type.getValue())
5872-
.build()))
5873-
.thenReturn(
5874-
Mono.just(
5875-
fill(UpdateApplicationResponse.builder())
5876-
.entity(
5877-
fill(
5878-
ApplicationEntity.builder(),
5879-
"application-entity-")
5881+
UpdateProcessRequest.builder()
5882+
.processId(processId)
5883+
.healthCheck(
5884+
HealthCheck.builder()
5885+
.type(HealthCheckType.from(type.getValue()))
58805886
.build())
5881-
.build()));
5887+
.build()))
5888+
.thenReturn(Mono.just(fill(UpdateProcessResponse.builder()).build()));
58825889
}
58835890

58845891
private static void requestUpdateApplicationRename(

0 commit comments

Comments
 (0)