Search in sources :

Example 1 with HealthcheckProtocol

use of com.hubspot.singularity.HealthcheckProtocol in project Singularity by HubSpot.

the class SingularityHealthchecker method getHealthcheckUri.

private Optional<String> getHealthcheckUri(SingularityTask task) {
    if (!task.getTaskRequest().getDeploy().getHealthcheck().isPresent()) {
        return Optional.absent();
    }
    HealthcheckOptions options = task.getTaskRequest().getDeploy().getHealthcheck().get();
    final String hostname = task.getHostname();
    Optional<Long> healthcheckPort = options.getPortNumber().or(MesosUtils.getPortByIndex(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), options.getPortIndex().or(0)));
    if (!healthcheckPort.isPresent() || healthcheckPort.get() < 1L) {
        LOG.warn("Couldn't find a port for health check for task {}", task);
        return Optional.absent();
    }
    String uri = task.getTaskRequest().getDeploy().getHealthcheck().get().getUri();
    if (uri.startsWith("/")) {
        uri = uri.substring(1);
    }
    HealthcheckProtocol protocol = options.getProtocol().or(DEFAULT_HEALTH_CHECK_SCHEME);
    return Optional.of(String.format("%s://%s:%d/%s", protocol.getProtocol(), hostname, healthcheckPort.get(), uri));
}
Also used : HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) HealthcheckProtocol(com.hubspot.singularity.HealthcheckProtocol)

Aggregations

HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)1 HealthcheckProtocol (com.hubspot.singularity.HealthcheckProtocol)1