Search in sources :

Example 6 with HealthcheckOptionsBuilder

use of com.hubspot.deploy.HealthcheckOptionsBuilder in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testPortNumber.

@Test
public void testPortNumber() {
    try {
        setConfigurationForNoDelay();
        initRequest();
        HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setPortNumber(Optional.of(81L)).setStartupDelaySeconds(Optional.of(0)).build();
        firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setResources(Optional.of(new Resources(1, 64, 3, 0))).setHealthcheck(Optional.of(options)), Optional.absent());
        requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
        scheduler.drainPendingQueue();
        String[] portRange = { "80:82" };
        sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRange)));
        SingularityTaskId firstTaskId = taskManager.getActiveTaskIdsForRequest(requestId).get(0);
        SingularityTask firstTask = taskManager.getTask(firstTaskId).get();
        statusUpdate(firstTask, TaskState.TASK_RUNNING);
        newTaskChecker.enqueueNewTaskCheck(firstTask, requestManager.getRequest(requestId), healthchecker);
        Awaitility.await("healthcheck present").atMost(5, TimeUnit.SECONDS).until(() -> taskManager.getLastHealthcheck(firstTask.getTaskId()).isPresent());
        Assert.assertTrue(taskManager.getLastHealthcheck(firstTask.getTaskId()).get().toString().contains("host1:81"));
    } finally {
        unsetConfigurationForNoDelay();
    }
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 7 with HealthcheckOptionsBuilder

use of com.hubspot.deploy.HealthcheckOptionsBuilder in project Singularity by HubSpot.

the class ValidatorTest method itForbidsHealthCheckStartupDelaysLongerThanKillWait.

@Test
public void itForbidsHealthCheckStartupDelaysLongerThanKillWait() {
    // Default kill wait time is 10 minutes (600 seconds)
    HealthcheckOptions healthCheck = new HealthcheckOptionsBuilder("/").setPortNumber(Optional.of(8080L)).setStartupDelaySeconds(Optional.of(10000)).build();
    SingularityDeploy deploy = SingularityDeploy.newBuilder("1234567", "1234567").setHealthcheck(Optional.of(healthCheck)).build();
    SingularityRequest request = new SingularityRequestBuilder("1234567", RequestType.SERVICE).build();
    WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList()));
    assertThat((String) exn.getResponse().getEntity()).contains("Health check startup delay");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityRequest(com.hubspot.singularity.SingularityRequest) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 8 with HealthcheckOptionsBuilder

use of com.hubspot.deploy.HealthcheckOptionsBuilder in project Singularity by HubSpot.

the class ValidatorTest method itForbidsHealthCheckGreaterThanMaxTotalHealthCheck.

@Test
public void itForbidsHealthCheckGreaterThanMaxTotalHealthCheck() {
    singularityConfiguration.setHealthcheckMaxTotalTimeoutSeconds(Optional.of(100));
    createValidator();
    // Total wait time on this request is (startup time) + ((interval) + (http timeout)) * (1 + retries)
    // = 50 + (5 + 5) * (9 + 1)
    // = 150
    HealthcheckOptions healthCheck = new HealthcheckOptionsBuilder("/").setPortNumber(Optional.of(8080L)).setStartupTimeoutSeconds(Optional.of(50)).setIntervalSeconds(Optional.of(5)).setResponseTimeoutSeconds(Optional.of(5)).setMaxRetries(Optional.of(9)).build();
    SingularityDeploy deploy = SingularityDeploy.newBuilder("1234567", "1234567").setHealthcheck(Optional.of(healthCheck)).setCommand(Optional.of("sleep 100;")).build();
    SingularityRequest request = new SingularityRequestBuilder("1234567", RequestType.SERVICE).build();
    WebApplicationException exn = (WebApplicationException) catchThrowable(() -> validator.checkDeploy(request, deploy, Collections.emptyList(), Collections.emptyList()));
    assertThat((String) exn.getResponse().getEntity()).contains("Max healthcheck time");
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityRequest(com.hubspot.singularity.SingularityRequest) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 9 with HealthcheckOptionsBuilder

use of com.hubspot.deploy.HealthcheckOptionsBuilder in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testMaxHealthcheckRetries.

@Test
public void testMaxHealthcheckRetries() {
    initRequest();
    final String deployId = "retry_test";
    HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setMaxRetries(Optional.of(2)).build();
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, deployId).setHealthcheck(Optional.of(options));
    SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis() + 1, Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis() + 1, Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    Assert.assertEquals(DeployState.FAILED, deployManager.getDeployResult(requestId, deployId).get().getDeployState());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 10 with HealthcheckOptionsBuilder

use of com.hubspot.deploy.HealthcheckOptionsBuilder in project Singularity by HubSpot.

the class SingularityHealthchecksTest method testHealthchecksSuccess.

@Test
public void testHealthchecksSuccess() {
    initRequest();
    final String deployId = "hc_test";
    HealthcheckOptions options = new HealthcheckOptionsBuilder("http://uri").setMaxRetries(Optional.of(2)).build();
    SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, deployId).setHealthcheck(Optional.of(options));
    SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    Assert.assertTrue(!deployManager.getDeployResult(requestId, deployId).isPresent());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis() + 1, Optional.<String>absent(), Optional.<String>absent(), task.getTaskId(), Optional.<Boolean>absent()));
    deployChecker.checkDeploys();
    Assert.assertEquals(DeployState.SUCCEEDED, deployManager.getDeployResult(requestId, deployId).get().getDeployState());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) HealthcheckOptions(com.hubspot.deploy.HealthcheckOptions) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) HealthcheckOptionsBuilder(com.hubspot.deploy.HealthcheckOptionsBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)11 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)11 Test (org.junit.Test)11 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)9 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)9 SingularityTask (com.hubspot.singularity.SingularityTask)9 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)7 Resources (com.hubspot.mesos.Resources)2 SingularityRequest (com.hubspot.singularity.SingularityRequest)2 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 WebApplicationException (javax.ws.rs.WebApplicationException)2