Search in sources :

Example 31 with SingularityTask

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

the class SingularityDeploysTest method testDeployWithImmediateRunSchedulesAfterRunningImmediately.

@Test
public void testDeployWithImmediateRunSchedulesAfterRunningImmediately() {
    initRequestWithType(RequestType.SCHEDULED, false);
    String deployId = "d1";
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setMessage("Message").build();
    SingularityDeploy deploy = new SingularityDeployBuilder(requestId, deployId).setRunImmediately(Optional.of(runNowRequest)).setCommand(Optional.of("printenv > tmp.txt")).build();
    SingularityDeployRequest deployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent());
    deployResource.deploy(deployRequest, singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    resourceOffers();
    SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
    SingularityTask task = taskManager.getTask(taskId).get();
    statusUpdate(task, TaskState.TASK_RUNNING);
    statusUpdate(task, TaskState.TASK_FINISHED);
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
    Assert.assertEquals(1, taskManager.getNumScheduledTasks());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 32 with SingularityTask

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

the class SingularityDeploysTest method testDeployFails.

@Test
public void testDeployFails() {
    initRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    initFirstDeploy();
    SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    deploy(secondDeployId, Optional.<Boolean>absent(), Optional.of(1), Optional.of(false), false);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    SingularityTaskId firstNewTaskId = taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).get(0);
    statusUpdate(taskManager.getTask(firstNewTaskId).get(), TaskState.TASK_FAILED);
    deployChecker.checkDeploys();
    Assert.assertFalse(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
    Assert.assertEquals(DeployState.FAILED, deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 33 with SingularityTask

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

the class SingularityDeploysTest method testLbUpdatesAfterEachDeployStep.

@Test
public void testLbUpdatesAfterEachDeployStep() {
    initLoadBalancedRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
    initFirstDeploy();
    SingularityTask firstTask = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    SingularityTask secondTask = launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
    deploy(secondDeployId, Optional.<Boolean>absent(), Optional.of(1), Optional.<Boolean>absent(), true);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    SingularityTaskId firstNewTaskId = taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).get(0);
    statusUpdate(taskManager.getTask(firstNewTaskId).get(), TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    SingularityPendingDeploy pendingDeploy = deployManager.getPendingDeploy(requestId).get();
    Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
    deployChecker.checkDeploys();
    pendingDeploy = deployManager.getPendingDeploy(requestId).get();
    Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
    deployChecker.checkDeploys();
    Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
    pendingDeploy = deployManager.getPendingDeploy(requestId).get();
    SingularityDeployProgress deployProgressStepOne = pendingDeploy.getDeployProgress().get();
    Assert.assertTrue(deployProgressStepOne.isStepComplete());
    Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
    cleaner.drainCleanupQueue();
    statusUpdate(firstTask, TaskState.TASK_KILLED);
    deployChecker.checkDeploys();
    pendingDeploy = deployManager.getPendingDeploy(requestId).get();
    Assert.assertFalse(pendingDeploy.getDeployProgress().get().isStepComplete());
    Assert.assertEquals(2, pendingDeploy.getDeployProgress().get().getTargetActiveInstances());
    scheduler.drainPendingQueue();
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    SingularityTaskId secondNewTaskId = null;
    for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId)) {
        if (taskId.getInstanceNo() == 2) {
            secondNewTaskId = taskId;
        }
    }
    statusUpdate(taskManager.getTask(secondNewTaskId).get(), TaskState.TASK_RUNNING);
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.WAITING);
    deployChecker.checkDeploys();
    pendingDeploy = deployManager.getPendingDeploy(requestId).get();
    Assert.assertEquals(DeployState.WAITING, pendingDeploy.getCurrentDeployState());
    testingLbClient.setNextBaragonRequestState(BaragonRequestState.SUCCESS);
    deployChecker.checkDeploys();
    Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    Assert.assertEquals(DeployState.SUCCEEDED, deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployProgress(com.hubspot.singularity.SingularityDeployProgress) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 34 with SingularityTask

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

the class SingularityExpiringActionsTest method testExpiringPause.

@Test
public void testExpiringPause() {
    initRequest();
    initFirstDeploy();
    SingularityTask taskOne = startTask(firstDeploy);
    requestResource.pause(requestId, Optional.of(new SingularityPauseRequest(Optional.absent(), Optional.of(1L), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
    statusUpdate(taskOne, TaskState.TASK_KILLED);
    resourceOffers();
    Assert.assertEquals(0, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, taskManager.getPendingTasks().size());
    Assert.assertEquals(RequestState.PAUSED, requestManager.getRequest(requestId).get().getState());
    Assert.assertEquals(requestId, requestManager.getPausedRequests(false).iterator().next().getRequest().getId());
    try {
        Thread.sleep(2);
    } catch (InterruptedException ie) {
    }
    expiringUserActionPoller.runActionOnPoll();
    resourceOffers();
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(0, taskManager.getPendingTasks().size());
    Assert.assertEquals(RequestState.ACTIVE, requestManager.getRequest(requestId).get().getState());
    Assert.assertEquals(requestId, requestManager.getActiveRequests(false).iterator().next().getRequest().getId());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPauseRequest(com.hubspot.singularity.api.SingularityPauseRequest) Test(org.junit.Test)

Example 35 with SingularityTask

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

the class SingularityHealthchecksTest method testHealthchecksDuringBounce.

@Test
public void testHealthchecksDuringBounce() {
    initRequest();
    initHCDeploy();
    startTask(firstDeploy);
    requestResource.bounce(requestId, Optional.absent(), singularityUser);
    cleaner.drainCleanupQueue();
    SingularityTask secondTask = startTask(firstDeploy);
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getNumCleanupTasks());
    Assert.assertEquals(2, taskManager.getNumActiveTasks());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(503), Optional.of(1000L), 1, Optional.<String>absent(), Optional.<String>absent(), secondTask.getTaskId(), Optional.<Boolean>absent()));
    cleaner.drainCleanupQueue();
    Assert.assertEquals(1, taskManager.getNumCleanupTasks());
    Assert.assertEquals(2, taskManager.getNumActiveTasks());
    taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), secondTask.getTaskId(), Optional.<Boolean>absent()));
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(0, taskManager.getNumCleanupTasks());
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
}
Also used : SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Aggregations

SingularityTask (com.hubspot.singularity.SingularityTask)94 Test (org.junit.Test)66 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)33 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 SingularityRequest (com.hubspot.singularity.SingularityRequest)15 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)12 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)11 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 Resources (com.hubspot.mesos.Resources)7 ArrayList (java.util.ArrayList)7 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)6 List (java.util.List)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)5 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)5 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)4 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)4 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3