Search in sources :

Example 1 with ExecHealthCheck

use of com.spotify.helios.common.descriptors.ExecHealthCheck in project helios by spotify.

the class JobValidator method validateJobHealthCheck.

/**
   * Validate the Job's health check.
   * @param job The Job to check.
   * @return A set of error Strings
   */
private Set<String> validateJobHealthCheck(final Job job) {
    final HealthCheck healthCheck = job.getHealthCheck();
    if (healthCheck == null) {
        return emptySet();
    }
    final Set<String> errors = Sets.newHashSet();
    if (healthCheck instanceof ExecHealthCheck) {
        final List<String> command = ((ExecHealthCheck) healthCheck).getCommand();
        if (command == null || command.isEmpty()) {
            errors.add("A command must be defined for `docker exec`-based health checks.");
        }
    } else if (healthCheck instanceof HttpHealthCheck || healthCheck instanceof TcpHealthCheck) {
        final String port;
        if (healthCheck instanceof HttpHealthCheck) {
            port = ((HttpHealthCheck) healthCheck).getPort();
        } else {
            port = ((TcpHealthCheck) healthCheck).getPort();
        }
        final Map<String, PortMapping> ports = job.getPorts();
        if (isNullOrEmpty(port)) {
            errors.add("A port must be defined for HTTP and TCP health checks.");
        } else if (!ports.containsKey(port)) {
            errors.add(format("Health check port '%s' not defined in the job. Known ports are '%s'", port, Joiner.on(", ").join(ports.keySet())));
        }
    }
    return errors;
}
Also used : HttpHealthCheck(com.spotify.helios.common.descriptors.HttpHealthCheck) TcpHealthCheck(com.spotify.helios.common.descriptors.TcpHealthCheck) HttpHealthCheck(com.spotify.helios.common.descriptors.HttpHealthCheck) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck) TcpHealthCheck(com.spotify.helios.common.descriptors.TcpHealthCheck) HealthCheck(com.spotify.helios.common.descriptors.HealthCheck) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck) Map(java.util.Map)

Example 2 with ExecHealthCheck

use of com.spotify.helios.common.descriptors.ExecHealthCheck in project helios by spotify.

the class ExecHealthCheckerTest method setUp.

@Before
public void setUp() throws Exception {
    final ExecHealthCheck healthCheck = ExecHealthCheck.of("exit 0");
    final Info info = mock(Info.class);
    when(info.executionDriver()).thenReturn("native-0.2");
    final Version version = mock(Version.class);
    when(version.apiVersion()).thenReturn("1.18");
    final ExecState execState = mock(ExecState.class);
    when(execState.exitCode()).thenReturn(0);
    final LogStream log = mock(LogStream.class);
    when(log.readFully()).thenReturn("");
    docker = mock(DockerClient.class);
    when(docker.info()).thenReturn(info);
    when(docker.version()).thenReturn(version);
    when(docker.execCreate(eq(CONTAINER_ID), any(String[].class), (DockerClient.ExecCreateParam) anyVararg())).thenReturn(ExecCreation.create(EXEC_ID, emptyList()));
    when(docker.execStart(eq(EXEC_ID), (ExecStartParameter) anyVararg())).thenReturn(log);
    when(docker.execInspect(EXEC_ID)).thenReturn(execState);
    checker = new ExecHealthChecker(healthCheck, docker);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Version(com.spotify.docker.client.messages.Version) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck) ExecState(com.spotify.docker.client.messages.ExecState) LogStream(com.spotify.docker.client.LogStream) Info(com.spotify.docker.client.messages.Info) ExecHealthChecker(com.spotify.helios.agent.HealthCheckerFactory.ExecHealthChecker) Before(org.junit.Before)

Example 3 with ExecHealthCheck

use of com.spotify.helios.common.descriptors.ExecHealthCheck in project helios by spotify.

the class JobInspectCommand method formatHealthCheck.

private static String formatHealthCheck(final HealthCheck healthCheck) {
    if (healthCheck == null) {
        return "";
    }
    String str = String.format("type: %s", String.valueOf(healthCheck.getType()));
    if (healthCheck instanceof HttpHealthCheck) {
        final HttpHealthCheck httpHealthCheck = (HttpHealthCheck) healthCheck;
        str += String.format(", port: %s, path: %s", httpHealthCheck.getPort(), httpHealthCheck.getPath());
    } else if (healthCheck instanceof TcpHealthCheck) {
        final TcpHealthCheck tcpHealthCheck = (TcpHealthCheck) healthCheck;
        str += String.format(", port: %s", tcpHealthCheck.getPort());
    } else if (healthCheck instanceof ExecHealthCheck) {
        final ExecHealthCheck execHealthCheck = (ExecHealthCheck) healthCheck;
        str += String.format(", command: %s", Joiner.on(" ").join(execHealthCheck.getCommand()));
    }
    return str;
}
Also used : HttpHealthCheck(com.spotify.helios.common.descriptors.HttpHealthCheck) TcpHealthCheck(com.spotify.helios.common.descriptors.TcpHealthCheck) ExecHealthCheck(com.spotify.helios.common.descriptors.ExecHealthCheck)

Aggregations

ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)3 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)2 TcpHealthCheck (com.spotify.helios.common.descriptors.TcpHealthCheck)2 DockerClient (com.spotify.docker.client.DockerClient)1 LogStream (com.spotify.docker.client.LogStream)1 ExecState (com.spotify.docker.client.messages.ExecState)1 Info (com.spotify.docker.client.messages.Info)1 Version (com.spotify.docker.client.messages.Version)1 ExecHealthChecker (com.spotify.helios.agent.HealthCheckerFactory.ExecHealthChecker)1 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)1 Map (java.util.Map)1 Before (org.junit.Before)1