Skip to content
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public CloudProcess derive() {
Integer healthCheckTimeout = null;
String healthCheckHttpEndpoint = null;
Integer healthCheckInvocationTimeout = null;
Integer healthCheckInterval = null;
if (healthCheck.getData() != null) {
Data healthCheckData = healthCheck.getData();
healthCheckTimeout = healthCheckData.getTimeout();
healthCheckInvocationTimeout = healthCheckData.getInvocationTimeout();
healthCheckHttpEndpoint = healthCheckData.getEndpoint();
healthCheckInterval = healthCheckData.getInterval();
}
Integer readinessHealthCheckInvocationTimeout = null;
String readinessHealthCheckHttpEndpoint = null;
Expand All @@ -49,6 +51,7 @@ public CloudProcess derive() {
.healthCheckHttpEndpoint(healthCheckHttpEndpoint)
.healthCheckTimeout(healthCheckTimeout)
.healthCheckInvocationTimeout(healthCheckInvocationTimeout)
.healthCheckInterval(healthCheckInterval)
.readinessHealthCheckType(readinessHealthCheckType.getType()
.getValue())
.readinessHealthCheckHttpEndpoint(readinessHealthCheckHttpEndpoint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public abstract class CloudProcess extends CloudEntity implements Derivable<Clou
@Nullable
public abstract Integer getHealthCheckTimeout();

@Nullable
public abstract Integer getHealthCheckInterval();

@Nullable
public abstract Integer getReadinessHealthCheckInterval();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public interface Staging {
@Nullable
String getHealthCheckHttpEndpoint();

/**
* @return liveness health check interval
*/
@Nullable
Integer getHealthCheckInterval();

/**
* @return readiness health check interval
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ private HealthCheck buildHealthCheck(Staging staging) {
.endpoint(staging.getHealthCheckHttpEndpoint())
.timeout(staging.getHealthCheckTimeout())
.invocationTimeout(staging.getInvocationTimeout())
.interval(staging.getHealthCheckInterval())
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ public class HealthCheckInfo {
private final String type;
private final Integer timeout;
private final Integer invocationTimeout;
private final Integer interval;
private final String httpEndpoint;

private HealthCheckInfo(String type, Integer timeout, Integer invocationTimeout, String httpEndpoint) {
private HealthCheckInfo(String type, Integer timeout, Integer invocationTimeout, Integer interval, String httpEndpoint) {
this.type = type;
this.timeout = timeout;
this.invocationTimeout = invocationTimeout;
this.interval = interval;
this.httpEndpoint = httpEndpoint;
}

Expand All @@ -26,16 +28,18 @@ public static HealthCheckInfo fromStaging(Staging staging) {
}
var timeout = staging.getHealthCheckTimeout();
var invocationTimeout = staging.getInvocationTimeout();
var interval = staging.getHealthCheckInterval();
var httpEndpoint = staging.getHealthCheckHttpEndpoint();
return new HealthCheckInfo(type, timeout, invocationTimeout, httpEndpoint);
return new HealthCheckInfo(type, timeout, invocationTimeout, interval, httpEndpoint);
}

public static HealthCheckInfo fromProcess(CloudProcess process) {
var type = process.getHealthCheckType();
var timeout = process.getHealthCheckTimeout();
var invocationTimeout = process.getHealthCheckInvocationTimeout();
var interval = process.getHealthCheckInterval();
var httpEndpoint = process.getHealthCheckHttpEndpoint();
return new HealthCheckInfo(type.toString(), timeout, invocationTimeout, httpEndpoint);
return new HealthCheckInfo(type.toString(), timeout, invocationTimeout, interval, httpEndpoint);
}

public String getType() {
Expand All @@ -50,6 +54,10 @@ public Integer getInvocationTimeout() {
return invocationTimeout;
}

public Integer getInterval() {
return interval;
}

public String getHttpEndpoint() {
return httpEndpoint;
}
Expand All @@ -66,6 +74,7 @@ public boolean equals(Object obj) {
return Objects.equals(getType(), other.getType())
&& Objects.equals(getTimeout(), other.getTimeout())
&& Objects.equals(getInvocationTimeout(), other.getInvocationTimeout())
&& Objects.equals(getInterval(), other.getInterval())
&& Objects.equals(getHttpEndpoint(), other.getHttpEndpoint());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.cloudfoundry.multiapps.controller.client.facade.adapters;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.cloudfoundry.client.v3.processes.Data;
import org.cloudfoundry.client.v3.processes.HealthCheck;
import org.cloudfoundry.client.v3.processes.HealthCheckType;
import org.cloudfoundry.client.v3.processes.Process;
import org.cloudfoundry.client.v3.processes.ReadinessHealthCheck;
import org.cloudfoundry.client.v3.processes.ReadinessHealthCheckType;
import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudProcess;
import org.junit.jupiter.api.Test;

class RawCloudProcessTest {

@Test
void testDeriveCarriesLivenessIntervalFromHealthCheckData() {
Process process = buildProcess(buildHealthCheck(15), buildReadinessHealthCheck(null));

CloudProcess derived = ImmutableRawCloudProcess.of(process)
.derive();

assertEquals(15, derived.getHealthCheckInterval());
}

@Test
void testDeriveLivenessIntervalIsNullWhenAbsent() {
Process process = buildProcess(buildHealthCheck(null), buildReadinessHealthCheck(null));

CloudProcess derived = ImmutableRawCloudProcess.of(process)
.derive();

assertNull(derived.getHealthCheckInterval());
}

@Test
void testDeriveLivenessIntervalIsNullWhenHealthCheckDataIsNull() {
HealthCheck healthCheck = mock(HealthCheck.class);
when(healthCheck.getData()).thenReturn(null);
when(healthCheck.getType()).thenReturn(HealthCheckType.PORT);
Process process = buildProcess(healthCheck, buildReadinessHealthCheck(null));

CloudProcess derived = ImmutableRawCloudProcess.of(process)
.derive();

assertNull(derived.getHealthCheckInterval());
}

private static Process buildProcess(HealthCheck healthCheck, ReadinessHealthCheck readinessHealthCheck) {
Process process = mock(Process.class);
when(process.getCommand()).thenReturn("test-command");
when(process.getInstances()).thenReturn(1);
when(process.getMemoryInMb()).thenReturn(256);
when(process.getDiskInMb()).thenReturn(512);
when(process.getHealthCheck()).thenReturn(healthCheck);
when(process.getReadinessHealthCheck()).thenReturn(readinessHealthCheck);
return process;
}

private static HealthCheck buildHealthCheck(Integer interval) {
Data.Builder dataBuilder = Data.builder();
if (interval != null) {
dataBuilder.interval(interval);
}
return HealthCheck.builder()
.type(HealthCheckType.PORT)
.data(dataBuilder.build())
.build();
}

private static ReadinessHealthCheck buildReadinessHealthCheck(Integer interval) {
Data.Builder dataBuilder = Data.builder();
if (interval != null) {
dataBuilder.interval(interval);
}
return ReadinessHealthCheck.builder()
.type(ReadinessHealthCheckType.PORT)
.data(dataBuilder.build())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package org.cloudfoundry.multiapps.controller.client.lib.domain;

import org.cloudfoundry.multiapps.controller.client.facade.domain.CloudProcess;
import org.cloudfoundry.multiapps.controller.client.facade.domain.HealthCheckType;
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableCloudProcess;
import org.cloudfoundry.multiapps.controller.client.facade.domain.ImmutableStaging;
import org.cloudfoundry.multiapps.controller.client.facade.domain.Staging;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class HealthCheckInfoTest {

@Test
void testFromStagingCarriesInterval() {
Staging staging = ImmutableStaging.builder()
.healthCheckType("http")
.healthCheckTimeout(30)
.invocationTimeout(5)
.healthCheckInterval(15)
.healthCheckHttpEndpoint("/health")
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertEquals("http", info.getType());
assertEquals(30, info.getTimeout());
assertEquals(5, info.getInvocationTimeout());
assertEquals(15, info.getInterval());
assertEquals("/health", info.getHttpEndpoint());
}

@Test
void testFromStagingIntervalIsNullWhenAbsent() {
Staging staging = ImmutableStaging.builder()
.healthCheckType("port")
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertNull(info.getInterval());
}

@Test
void testFromStagingDefaultsTypeToPortWhenNull() {
Staging staging = ImmutableStaging.builder()
.healthCheckInterval(10)
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertEquals("port", info.getType());
assertEquals(10, info.getInterval());
}

@Test
void testFromProcessCarriesInterval() {
CloudProcess process = ImmutableCloudProcess.builder()
.command("test-cmd")
.diskInMb(512)
.instances(1)
.memoryInMb(256)
.healthCheckType(HealthCheckType.HTTP)
.healthCheckTimeout(45)
.healthCheckInvocationTimeout(7)
.healthCheckInterval(20)
.healthCheckHttpEndpoint("/live")
.build();

HealthCheckInfo info = HealthCheckInfo.fromProcess(process);

assertEquals("http", info.getType());
assertEquals(45, info.getTimeout());
assertEquals(7, info.getInvocationTimeout());
assertEquals(20, info.getInterval());
assertEquals("/live", info.getHttpEndpoint());
}

@Test
void testFromProcessIntervalIsNullWhenAbsent() {
CloudProcess process = ImmutableCloudProcess.builder()
.command("test-cmd")
.diskInMb(512)
.instances(1)
.memoryInMb(256)
.healthCheckType(HealthCheckType.PORT)
.build();

HealthCheckInfo info = HealthCheckInfo.fromProcess(process);

assertNull(info.getInterval());
}

@Test
void testEqualsReturnsFalseWhenIntervalDiffers() {
Staging stagingA = ImmutableStaging.builder()
.healthCheckType("port")
.healthCheckInterval(10)
.build();
Staging stagingB = ImmutableStaging.builder()
.healthCheckType("port")
.healthCheckInterval(20)
.build();

assertNotEquals(HealthCheckInfo.fromStaging(stagingA), HealthCheckInfo.fromStaging(stagingB));
}

@Test
void testEqualsReturnsTrueWhenAllFieldsMatchIncludingInterval() {
Staging stagingA = ImmutableStaging.builder()
.healthCheckType("port")
.healthCheckTimeout(30)
.invocationTimeout(5)
.healthCheckInterval(10)
.healthCheckHttpEndpoint("/health")
.build();
Staging stagingB = ImmutableStaging.builder()
.healthCheckType("port")
.healthCheckTimeout(30)
.invocationTimeout(5)
.healthCheckInterval(10)
.healthCheckHttpEndpoint("/health")
.build();

assertEquals(HealthCheckInfo.fromStaging(stagingA), HealthCheckInfo.fromStaging(stagingB));
}

@Test
void testEqualsReturnsFalseWhenOneIntervalIsNull() {
Staging stagingWithInterval = ImmutableStaging.builder()
.healthCheckType("port")
.healthCheckInterval(10)
.build();
Staging stagingWithoutInterval = ImmutableStaging.builder()
.healthCheckType("port")
.build();

assertNotEquals(HealthCheckInfo.fromStaging(stagingWithInterval), HealthCheckInfo.fromStaging(stagingWithoutInterval));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class SupportedParameters {
public static final String HEALTH_CHECK_TIMEOUT = "health-check-timeout";
public static final String HEALTH_CHECK_TYPE = "health-check-type";
public static final String HEALTH_CHECK_HTTP_ENDPOINT = "health-check-http-endpoint";
public static final String HEALTH_CHECK_INTERVAL = "health-check-interval";
public static final String READINESS_HEALTH_CHECK_TYPE = "readiness-health-check-type";
public static final String READINESS_HEALTH_CHECK_HTTP_ENDPOINT = "readiness-health-check-http-endpoint";
public static final String READINESS_HEALTH_CHECK_INVOCATION_TIMEOUT = "readiness-health-check-invocation-timeout";
Expand Down Expand Up @@ -190,6 +191,7 @@ public class SupportedParameters {
DEPENDENCY_TYPE, DISK_QUOTA, DOCKER, DOMAIN, DOMAINS, DEFAULT_DOMAIN,
ENABLE_SSH, ENABLE_PARALLEL_SERVICE_BINDINGS, HEALTH_CHECK_HTTP_ENDPOINT,
HEALTH_CHECK_TIMEOUT, HEALTH_CHECK_INVOCATION_TIMEOUT, HEALTH_CHECK_TYPE,
HEALTH_CHECK_INTERVAL,
HOST, HOSTS, IDLE_DOMAIN, IDLE_DOMAINS, IDLE_HOST, IDLE_HOSTS, IDLE_ROUTES,
INSTANCES, KEEP_EXISTING_APPLICATION_ATTRIBUTES_UPDATE_STRATEGY,
KEEP_EXISTING_ROUTES, MEMORY, NO_ROUTE, NO_START, RESTART_ON_ENV_CHANGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public Staging parse(List<Map<String, Object>> parametersList) {
Integer healthCheckInvocationTimeout = (Integer) PropertiesUtil.getPropertyValue(parametersList,
SupportedParameters.HEALTH_CHECK_INVOCATION_TIMEOUT,
null);
Integer healthCheckInterval = (Integer) PropertiesUtil.getPropertyValue(parametersList,
SupportedParameters.HEALTH_CHECK_INTERVAL, null);
String healthCheckType = (String) PropertiesUtil.getPropertyValue(parametersList, SupportedParameters.HEALTH_CHECK_TYPE, null);
String healthCheckHttpEndpoint = (String) PropertiesUtil.getPropertyValue(parametersList,
SupportedParameters.HEALTH_CHECK_HTTP_ENDPOINT,
Expand Down Expand Up @@ -67,6 +69,7 @@ public Staging parse(List<Map<String, Object>> parametersList) {
.stackName(stackName)
.healthCheckTimeout(healthCheckTimeout)
.invocationTimeout(healthCheckInvocationTimeout)
.healthCheckInterval(healthCheckInterval)
.healthCheckType(healthCheckType)
.healthCheckHttpEndpoint(healthCheckHttpEndpoint)
.readinessHealthCheckType(readinessHealthCheckType)
Expand Down
Loading
Loading