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; }
public static ExecHealthCheck of(final String... command) { return ExecHealthCheck.of(Arrays.asList(command)); }
public ExecHealthCheck build() { if (command == null || command.isEmpty()) { throw new IllegalArgumentException("You must specify a command for an exec health check."); } return new ExecHealthCheck(this); } }
public static ExecHealthCheck.Builder newExecHealthCheck() { return ExecHealthCheck.newBuilder(); }
public static ExecHealthCheck of(final List<String> command) { return newBuilder().setCommand(command).build(); }
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.");
builder.setHealthCheck(ExecHealthCheck.of(execHealthCheck)); } else if (!isNullOrEmpty(httpHealthCheck)) { final String[] parts = httpHealthCheck.split(":", 2);
healthCheck.getCommand().toArray(new String[healthCheck.getCommand().size()]);
final HealthCheck healthCheck = ExecHealthCheck.of("test", "-e", "file");
private static String formatHealthCheck(final HealthCheck healthCheck) { if (healthCheck == null) { return ""; } String s = String.format("type: %s", String.valueOf(healthCheck.getType())); if (healthCheck instanceof HttpHealthCheck) { final HttpHealthCheck httpHealthCheck = (HttpHealthCheck) healthCheck; s += String.format(", port: %s, path: %s", httpHealthCheck.getPort(), httpHealthCheck.getPath()); } else if (healthCheck instanceof TcpHealthCheck) { final TcpHealthCheck tcpHealthCheck = (TcpHealthCheck) healthCheck; s += String.format(", port: %s", tcpHealthCheck.getPort()); } else if (healthCheck instanceof ExecHealthCheck) { final ExecHealthCheck execHealthCheck = (ExecHealthCheck) healthCheck; s += String.format(", command: %s", Joiner.on(" ").join(execHealthCheck.getCommand())); } return s; }
builder.setHealthCheck(ExecHealthCheck.of(execHealthCheck)); } else if (!isNullOrEmpty(httpHealthCheck)) { final String[] parts = httpHealthCheck.split(":", 2);
@Override public boolean check(final String containerId) { // Make sure we are on a docker version that supports exec health checks if (!compatibleDockerVersion(docker)) { throw new UnsupportedOperationException( "docker exec healthcheck is not supported on your docker version"); } try { final List<String> cmd = healthCheck.getCommand(); final String execId = docker.execCreate(containerId, cmd.toArray(new String[cmd.size()]), DockerClient.ExecParameter.STDOUT, DockerClient.ExecParameter.STDERR); final String output; try (LogStream stream = docker.execStart(execId)) { output = stream.readFully(); } final int exitCode = docker.execInspect(execId).exitCode(); if (exitCode != 0) { log.info("healthcheck failed with exit code {}. output {}", exitCode, output); return false; } return true; } catch (DockerException e) { return false; } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } }