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