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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations