Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -11,12 +11,14 @@ public class HealthCheckInfo {
private final Integer timeout;
private final Integer invocationTimeout;
private final String httpEndpoint;
private final Integer interval;

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

public static HealthCheckInfo fromStaging(Staging staging) {
Expand All @@ -27,15 +29,17 @@ public static HealthCheckInfo fromStaging(Staging staging) {
var timeout = staging.getHealthCheckTimeout();
var invocationTimeout = staging.getInvocationTimeout();
var httpEndpoint = staging.getHealthCheckHttpEndpoint();
return new HealthCheckInfo(type, timeout, invocationTimeout, httpEndpoint);
var interval = staging.getHealthCheckInterval();
return new HealthCheckInfo(type, timeout, invocationTimeout, httpEndpoint, interval);
}

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

public String getType() {
Expand All @@ -54,6 +58,10 @@ public String getHttpEndpoint() {
return httpEndpoint;
}

public Integer getInterval() {
return interval;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
Expand All @@ -66,6 +74,12 @@ public boolean equals(Object obj) {
return Objects.equals(getType(), other.getType())
&& Objects.equals(getTimeout(), other.getTimeout())
&& Objects.equals(getInvocationTimeout(), other.getInvocationTimeout())
&& Objects.equals(getHttpEndpoint(), other.getHttpEndpoint());
&& Objects.equals(getHttpEndpoint(), other.getHttpEndpoint())
&& Objects.equals(getInterval(), other.getInterval());
}

@Override
public int hashCode() {
return Objects.hash(getType(), getTimeout(), getInvocationTimeout(), getHttpEndpoint(), getInterval());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.DEFAULT_DOMAIN;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.DISK_IN_MB;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.HEALTH_CHECK_ENDPOINT;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.HEALTH_CHECK_INTERVAL;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.HEALTH_CHECK_TIMEMOUT;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.JAVA_BUILDPACK;
import static org.cloudfoundry.multiapps.controller.client.facade.IntegrationTestConstants.JAVA_BUILDPACK_URL;
Expand Down Expand Up @@ -88,10 +89,14 @@ void createApplication() {
.healthCheckType(HealthCheckType.PROCESS.getValue())
.healthCheckHttpEndpoint(HEALTH_CHECK_ENDPOINT)
.healthCheckTimeout(HEALTH_CHECK_TIMEMOUT)
.healthCheckInterval(HEALTH_CHECK_INTERVAL)
.build();
CloudRoute route = getImmutableCloudRoute();
try {
verifyApplicationWillBeCreated(applicationName, staging, Set.of(route));
UUID applicationGuid = client.getApplicationGuid(applicationName);
CloudProcess cloudProcess = client.getApplicationProcess(applicationGuid);
assertEquals(HEALTH_CHECK_INTERVAL, cloudProcess.getHealthCheckInterval());
} catch (Exception e) {
fail(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ private IntegrationTestConstants() {
public static final String NODEJS_BUILDPACK = "nodejs_buildpack";
public static final String STATICFILE_BUILDPACK = "staticfile_buildpack";
public static final int HEALTH_CHECK_TIMEMOUT = 100;
public static final int HEALTH_CHECK_INTERVAL = 60;
public static final int DISK_IN_MB = 128;
public static final int MEMORY_IN_MB = 128;
public static final String DEFAULT_DOMAIN = "deploy-service.custom.domain.for.integration.tests";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package org.cloudfoundry.multiapps.controller.client.lib.domain;

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 {

private static final String HTTP_TYPE = "http";
private static final String PORT_TYPE = "port";
private static final String ENDPOINT = "/health";
private static final Integer TIMEOUT = 10;
private static final Integer INVOCATION_TIMEOUT = 5;
private static final Integer INTERVAL = 30;

@Test
void testFromStagingExposesAllFieldsIncludingInterval() {
Staging staging = ImmutableStaging.builder()
.healthCheckType(HTTP_TYPE)
.healthCheckTimeout(TIMEOUT)
.invocationTimeout(INVOCATION_TIMEOUT)
.healthCheckHttpEndpoint(ENDPOINT)
.healthCheckInterval(INTERVAL)
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertEquals(HTTP_TYPE, info.getType());
assertEquals(TIMEOUT, info.getTimeout());
assertEquals(INVOCATION_TIMEOUT, info.getInvocationTimeout());
assertEquals(ENDPOINT, info.getHttpEndpoint());
assertEquals(INTERVAL, info.getInterval());
}

@Test
void testFromStagingDefaultsTypeToPortWhenAbsent() {
Staging staging = ImmutableStaging.builder()
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertEquals(PORT_TYPE, info.getType());
assertNull(info.getTimeout());
assertNull(info.getInvocationTimeout());
assertNull(info.getHttpEndpoint());
assertNull(info.getInterval());
}

@Test
void testFromStagingPropagatesNullInterval() {
Staging staging = ImmutableStaging.builder()
.healthCheckType(HTTP_TYPE)
.build();

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertEquals(HTTP_TYPE, info.getType());
assertNull(info.getInterval());
}

@Test
void testFromProcessExposesAllFieldsIncludingInterval() {
ImmutableCloudProcess process = ImmutableCloudProcess.builder()
.command("./run.sh")
.diskInMb(1024)
.instances(1)
.memoryInMb(512)
.healthCheckType(HealthCheckType.HTTP)
.healthCheckHttpEndpoint(ENDPOINT)
.healthCheckTimeout(TIMEOUT)
.healthCheckInvocationTimeout(INVOCATION_TIMEOUT)
.healthCheckInterval(INTERVAL)
.build();

HealthCheckInfo info = HealthCheckInfo.fromProcess(process);

assertEquals(HealthCheckType.HTTP.toString(), info.getType());
assertEquals(TIMEOUT, info.getTimeout());
assertEquals(INVOCATION_TIMEOUT, info.getInvocationTimeout());
assertEquals(ENDPOINT, info.getHttpEndpoint());
assertEquals(INTERVAL, info.getInterval());
}

@Test
void testFromProcessPropagatesNullInterval() {
ImmutableCloudProcess process = ImmutableCloudProcess.builder()
.command("./run.sh")
.diskInMb(1024)
.instances(1)
.memoryInMb(512)
.healthCheckType(HealthCheckType.PORT)
.build();

HealthCheckInfo info = HealthCheckInfo.fromProcess(process);

assertEquals(HealthCheckType.PORT.toString(), info.getType());
assertNull(info.getInterval());
}

@Test
void testEqualsReturnsTrueForSameValues() {
HealthCheckInfo first = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));
HealthCheckInfo second = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));

assertEquals(first, second);
assertEquals(first.hashCode(), second.hashCode());
}

private static Staging buildStagingWithInterval(Integer interval) {
return ImmutableStaging.builder()
.healthCheckType(HTTP_TYPE)
.healthCheckTimeout(TIMEOUT)
.invocationTimeout(INVOCATION_TIMEOUT)
.healthCheckHttpEndpoint(ENDPOINT)
.healthCheckInterval(interval)
.build();
}

@Test
void testEqualsReturnsFalseWhenIntervalDiffers() {
HealthCheckInfo first = HealthCheckInfo.fromStaging(buildStagingWithInterval(30));
HealthCheckInfo second = HealthCheckInfo.fromStaging(buildStagingWithInterval(60));

assertNotEquals(first, second);
}

@Test
void testEqualsReturnsFalseWhenIntervalIsNullOnOneSide() {
HealthCheckInfo first = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));
HealthCheckInfo second = HealthCheckInfo.fromStaging(buildStagingWithInterval(null));

assertNotEquals(first, second);
}

@Test
void testEqualsReturnsTrueForReferenceIdentity() {
HealthCheckInfo info = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));

assertEquals(info, info);
}

@Test
void testEqualsReturnsFalseForUnrelatedType() {
HealthCheckInfo info = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));

assertNotEquals(info, "not-a-health-check-info");

Check warning on line 152 in multiapps-controller-client/src/test/java/org/cloudfoundry/multiapps/controller/client/lib/domain/HealthCheckInfoTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Swap these 2 arguments so they are in the correct order: expected value, actual value.

See more on https://sonarcloud.io/project/issues?id=cloudfoundry_multiapps-controller&issues=AZ6DyHHTUpn8FbF7fDuo&open=AZ6DyHHTUpn8FbF7fDuo&pullRequest=1852
}

@Test
void testHashCodeRemainsStableAcrossInvocations() {
HealthCheckInfo info = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));

int firstHash = info.hashCode();
int secondHash = info.hashCode();

assertEquals(firstHash, secondHash);
}
}
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,9 @@ 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 +70,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
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ void testValidateWithAllParametersMissing() {
assertNull(staging.getDockerInfo());
}

@Test
void testHealthCheckIntervalIsParsedWhenProvided() {
parametersList.add(mapOf("health-check-interval", 45));

Staging staging = parser.parse(parametersList);

assertNotNull(staging);
assertEquals(Integer.valueOf(45), staging.getHealthCheckInterval());
}

@Test
void testHealthCheckIntervalIsNullWhenAbsent() {
Staging staging = parser.parse(parametersList);

assertNotNull(staging);
assertNull(staging.getHealthCheckInterval());
}

private static Map<String, Object> mapOf(String key, Object value) {
return Collections.singletonMap(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"buildpacks": [],
"healthCheckType": "http",
"healthCheckHttpEndpoint": "/health",
"healthCheckInterval": 45,
"appFeatures": {}
},
"routes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"staging": {
"buildpacks": [],
"healthCheckType": "port",
"healthCheckInterval": 30,
"appFeatures": {}
},
"routes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ modules:
parameters:
health-check-type: http
health-check-http-endpoint: /health
health-check-interval: 45
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ modules:
type: foo
parameters:
health-check-type: port
health-check-interval: 30
Loading
Loading