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 health check interval value
*/
@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,7 @@ 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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 {

private static final String HTTP = "http";
private static final String PORT = "port";
private static final String ENDPOINT = "/health";
private static final Integer TIMEOUT = 60;
private static final Integer INVOCATION_TIMEOUT = 5;
private static final Integer INTERVAL = 30;

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

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

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

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

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

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

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

HealthCheckInfo info = HealthCheckInfo.fromStaging(staging);

assertNull(info.getInterval());
}

@Test
void testFromProcessPopulatesInterval() {
CloudProcess process = ImmutableCloudProcess.builder()
.command("")
.diskInMb(0)
.instances(1)
.memoryInMb(256)
.healthCheckType(HealthCheckType.HTTP)
.healthCheckTimeout(TIMEOUT)
.healthCheckInvocationTimeout(INVOCATION_TIMEOUT)
.healthCheckHttpEndpoint(ENDPOINT)
.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() {
CloudProcess process = ImmutableCloudProcess.builder()
.command("")
.diskInMb(0)
.instances(1)
.memoryInMb(256)
.healthCheckType(HealthCheckType.PORT)
.build();

HealthCheckInfo info = HealthCheckInfo.fromProcess(process);

assertNull(info.getInterval());
}

@Test
void testEqualsWhenAllFieldsMatchIncludingInterval() {
HealthCheckInfo a = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));
HealthCheckInfo b = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));

assertEquals(a, b);
}

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

@Test
void testEqualsWhenIntervalDiffers() {
HealthCheckInfo a = HealthCheckInfo.fromStaging(buildStagingWithInterval(30));
HealthCheckInfo b = HealthCheckInfo.fromStaging(buildStagingWithInterval(60));

assertNotEquals(a, b);
}

@Test
void testEqualsWhenOneIntervalIsNull() {
HealthCheckInfo a = HealthCheckInfo.fromStaging(buildStagingWithInterval(INTERVAL));
HealthCheckInfo b = HealthCheckInfo.fromStaging(buildStagingWithInterval(null));

assertNotEquals(a, b);
}

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

assertEquals(info, info);
}

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

assertNotEquals(info, "not a HealthCheckInfo");

Check warning on line 150 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=AZ50YWSnF3xLCN6d8fAW&open=AZ50YWSnF3xLCN6d8fAW&pullRequest=1849
}

}
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 @@ -189,7 +190,8 @@ public class SupportedParameters {
DEFAULT_LIVE_URI, DEFAULT_LIVE_URL, DEFAULT_URI, DEFAULT_URL,
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_TIMEOUT, HEALTH_CHECK_INVOCATION_TIMEOUT, HEALTH_CHECK_INTERVAL,
HEALTH_CHECK_TYPE,
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.BUILDPACK;
import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.BUILDPACKS;
import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.DOCKER;
import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.HEALTH_CHECK_INTERVAL;
import static org.cloudfoundry.multiapps.controller.core.model.SupportedParameters.LIFECYCLE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -138,6 +139,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 testHealthCheckIntervalDefaultsToNullWhenMissing() {
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 @@ -40,6 +40,18 @@
readinessHealthCheckInvocationTimeout, readinessHealthCheckInterval,
buildpacks.toString(), module.getType());
}
String healthCheckType = (String) module.getParameters()
.get(SupportedParameters.HEALTH_CHECK_TYPE);
String healthCheckHttpEndpoint = (String) module.getParameters()
.get(SupportedParameters.HEALTH_CHECK_HTTP_ENDPOINT);
Integer healthCheckInvocationTimeout = (Integer) module.getParameters()
.get(SupportedParameters.HEALTH_CHECK_INVOCATION_TIMEOUT);
Integer healthCheckInterval = (Integer) module.getParameters()
.get(SupportedParameters.HEALTH_CHECK_INTERVAL);
if (healthCheckType != null) {
reportUsageOfHealthCheckParameters(mtaId, correlationId, healthCheckType, healthCheckHttpEndpoint, healthCheckInvocationTimeout,
healthCheckInterval, buildpacks.toString(), module.getType());
}
}

// this method is being observed by Dynatrace, be careful if you change it
Expand All @@ -51,4 +63,13 @@
mtaId, correlationId, readinessHealthCheckType, readinessHealthCheckHttpEndpoint,
readinessHealthCheckInvocationTimeout, readinessHealthCheckInterval, buildpacks, moduleType));
}

// this method is being observed by Dynatrace, be careful if you change it
private void reportUsageOfHealthCheckParameters(String mtaId, String correlationId, String healthCheckType,

Check warning on line 68 in multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/util/AdditionalModuleParametersReporter.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Method has 8 parameters, which is greater than 7 authorized.

See more on https://sonarcloud.io/project/issues?id=cloudfoundry_multiapps-controller&issues=AZ50YWQ5F3xLCN6d8fAV&open=AZ50YWQ5F3xLCN6d8fAV&pullRequest=1849
String healthCheckHttpEndpoint, Integer healthCheckInvocationTimeout,
Integer healthCheckInterval, String buildpacks, String moduleType) {
LOGGER.info(MessageFormat.format("MTA with ID \"{0}\" associated with operation ID \"{1}\" uses health check parameters: type=\"{2}\", httpEndpoint=\"{3}\", invocationTimeout=\"{4}\", interval=\"{5}\", buildpacks=\"{6}\", moduleType=\"{7}\"",
mtaId, correlationId, healthCheckType, healthCheckHttpEndpoint, healthCheckInvocationTimeout,
healthCheckInterval, buildpacks, moduleType));

Check warning on line 73 in multiapps-controller-process/src/main/java/org/cloudfoundry/multiapps/controller/process/util/AdditionalModuleParametersReporter.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Invoke method(s) only conditionally.

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