Search in sources :

Example 21 with SingularityTaskId

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

the class SingularityDeploysTest method testCancelDeploy.

@Test
public void testCancelDeploy() {
    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_RUNNING);
    deployResource.cancelDeploy(singularityUser, requestId, secondDeployId);
    deployChecker.checkDeploys();
    Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstNewTaskId));
    Assert.assertFalse(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
    Assert.assertEquals(DeployState.CANCELED, 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 22 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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 23 with SingularityTaskId

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

the class SingularityDeploysTest method testDeployAllInstancesAtOnce.

@Test
public void testDeployAllInstancesAtOnce() {
    initRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
    initFirstDeploy();
    launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
    deploy(secondDeployId);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
    Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId)) {
        statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
    }
    deployChecker.checkDeploys();
    Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
    Assert.assertEquals(DeployState.SUCCEEDED, deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState());
    Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
}
Also used : SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 24 with SingularityTaskId

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

the class SingularityDeploysTest method testScaleDownDuringDeploy.

@Test
public void testScaleDownDuringDeploy() {
    initRequest();
    SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
    requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
    initFirstDeploy();
    launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
    launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
    deploy(secondDeployId);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId).size());
    for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, secondDeployId)) {
        statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
    }
    requestResource.postRequest(request.toBuilder().setInstances(Optional.of(1)).build(), singularityUser);
    scheduler.drainPendingQueue();
    Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
    deployChecker.checkDeploys();
    Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
    // Extra task from the new deploy should get cleaned up as well
    scheduler.drainPendingQueue();
    Assert.assertEquals(3, taskManager.getCleanupTaskIds().size());
}
Also used : SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 25 with SingularityTaskId

use of com.hubspot.singularity.SingularityTaskId 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)

Aggregations

SingularityTaskId (com.hubspot.singularity.SingularityTaskId)106 Test (org.junit.Test)44 SingularityTask (com.hubspot.singularity.SingularityTask)34 SingularityRequest (com.hubspot.singularity.SingularityRequest)26 ArrayList (java.util.ArrayList)26 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)14 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)13 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)12 List (java.util.List)11 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)10 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)9 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)8 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)7 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)7 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)7 HashMap (java.util.HashMap)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)6 SingularitySlaveUsage (com.hubspot.singularity.SingularitySlaveUsage)6