Search in sources :

Example 11 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest 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 12 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testImmediateRunReplacesScheduledTask.

@Test
public void testImmediateRunReplacesScheduledTask() {
    initScheduledRequest();
    SingularityDeploy deploy = SingularityDeploy.newBuilder(requestId, firstDeployId).setCommand(Optional.of("sleep 100")).build();
    SingularityDeployRequest singularityDeployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.absent());
    deployResource.deploy(singularityDeployRequest, singularityUser);
    scheduler.drainPendingQueue();
    SingularityPendingTask task1 = createAndSchedulePendingTask(firstDeployId);
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(PendingType.NEW_DEPLOY, taskManager.getPendingTaskIds().get(0).getPendingType());
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, deploy.getId(), System.currentTimeMillis(), Optional.absent(), PendingType.IMMEDIATE, deploy.getSkipHealthchecksOnDeploy(), Optional.absent()));
    scheduler.drainPendingQueue();
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(PendingType.IMMEDIATE, taskManager.getPendingTaskIds().get(0).getPendingType());
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 13 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testMultipleRunOnceTasks.

@Test
public void testMultipleRunOnceTasks() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
    request = bldr.build();
    saveRequest(request);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    deployChecker.checkDeploys();
    Assert.assertEquals(1, requestManager.getSizeOfPendingQueue());
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    deployChecker.checkDeploys();
    Assert.assertEquals(2, requestManager.getSizeOfPendingQueue());
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 14 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testPriorityFreezeDoesntLaunchTasks.

@Test
public void testPriorityFreezeDoesntLaunchTasks() {
    // deploy lowPriorityRequest (affected by priority freeze)
    final SingularityRequest lowPriorityRequest = new SingularityRequestBuilder("lowPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.25)).build();
    saveRequest(lowPriorityRequest);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(lowPriorityRequest.getId(), "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    // deploy medium priority request (NOT affected by priority freeze)
    final SingularityRequest mediumPriorityRequest = new SingularityRequestBuilder("mediumPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.5)).build();
    saveRequest(mediumPriorityRequest);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(mediumPriorityRequest.getId(), "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    // create priority freeze
    priorityManager.createPriorityFreeze(new SingularityPriorityFreezeParent(new SingularityPriorityFreeze(0.3, true, Optional.<String>absent(), Optional.<String>absent()), System.currentTimeMillis(), Optional.<String>absent()));
    // launch both tasks
    requestResource.scheduleImmediately(singularityUser, lowPriorityRequest.getId());
    requestResource.scheduleImmediately(singularityUser, mediumPriorityRequest.getId());
    // drain pending queue
    scheduler.drainPendingQueue();
    resourceOffers();
    // assert that lowPriorityRequest has a pending task
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(lowPriorityRequest.getId(), taskManager.getPendingTaskIds().get(0).getRequestId());
    // assert that only mediumPriorityRequest has an active task
    Assert.assertEquals(0, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
    // delete priority freeze
    Assert.assertEquals(SingularityDeleteResult.DELETED, priorityManager.deleteActivePriorityFreeze());
    // drain pending
    scheduler.drainPendingQueue();
    resourceOffers();
    // check that both requests have active tasks
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
}
Also used : SingularityPriorityFreeze(com.hubspot.singularity.api.SingularityPriorityFreeze) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 15 with SingularityDeployRequest

use of com.hubspot.singularity.api.SingularityDeployRequest in project Singularity by HubSpot.

the class SingularitySchedulerTest method testDecommissionDoesntKillPendingDeploy.

@Test
public void testDecommissionDoesntKillPendingDeploy() {
    initRequest();
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    deployChecker.checkDeploys();
    resourceOffers();
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
    slaveResource.decommissionSlave(singularityUser, taskManager.getActiveTasks().get(0).getAgentId().getValue(), null);
    scheduler.checkForDecomissions();
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
    Assert.assertEquals(1, taskManager.getNumCleanupTasks());
    Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
    configuration.setPendingDeployHoldTaskDuringDecommissionMillis(1);
    try {
        Thread.sleep(2);
    } catch (InterruptedException e) {
    }
    cleaner.drainCleanupQueue();
    killKilledTasks();
    Assert.assertEquals(0, taskManager.getNumActiveTasks());
    Assert.assertEquals(0, taskManager.getNumCleanupTasks());
}
Also used : SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Aggregations

SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)18 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 Test (org.junit.Test)14 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)10 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)8 SingularityRequest (com.hubspot.singularity.SingularityRequest)6 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)3 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 HttpResponse (com.hubspot.horizon.HttpResponse)1 Resources (com.hubspot.mesos.Resources)1 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)1 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)1 SingularityPriorityFreezeParent (com.hubspot.singularity.SingularityPriorityFreezeParent)1 SingularityRequestParent (com.hubspot.singularity.SingularityRequestParent)1 SingularityPriorityFreeze (com.hubspot.singularity.api.SingularityPriorityFreeze)1 ArrayList (java.util.ArrayList)1