use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployManagerHandlesFailedLBTask.
@Test
public void testDeployManagerHandlesFailedLBTask() {
initLoadBalancedRequest();
initFirstDeploy();
SingularityTask firstTask = startTask(firstDeploy);
initSecondDeploy();
SingularityTask secondTask = startTask(secondDeploy);
// this should cause an LB call to happen:
deployChecker.checkDeploys();
Assert.assertTrue(taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.ADD).isPresent());
Assert.assertTrue(!taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.DEPLOY).isPresent());
Assert.assertTrue(!taskManager.getLoadBalancerState(secondTask.getTaskId(), LoadBalancerRequestType.REMOVE).isPresent());
statusUpdate(secondTask, TaskState.TASK_FAILED);
statusUpdate(firstTask, TaskState.TASK_FAILED);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
Assert.assertTrue(deployManager.getDeployResult(requestId, secondDeployId).get().getDeployState() == DeployState.FAILED);
List<SingularityPendingTask> pendingTasks = taskManager.getPendingTasks();
Assert.assertTrue(pendingTasks.size() == 1);
Assert.assertTrue(pendingTasks.get(0).getPendingTaskId().getDeployId().equals(firstDeployId));
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testCanceledDeployTasksStayActiveUntilReplaced.
@Test
public void testCanceledDeployTasksStayActiveUntilReplaced() {
initRequest();
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(), 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);
deployChecker.checkDeploys();
Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
SingularityDeployProgress deployProgressStepOne = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertTrue(deployProgressStepOne.isStepComplete());
Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
cleaner.drainCleanupQueue();
statusUpdate(firstTask, TaskState.TASK_KILLED);
deployChecker.checkDeploys();
deployResource.cancelDeploy(singularityUser, requestId, secondDeployId);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
Assert.assertEquals(1, pendingTaskIds.size());
Assert.assertEquals(firstDeployId, pendingTaskIds.get(0).getDeployId());
cleaner.drainCleanupQueue();
List<SingularityTaskId> cleanupTaskIds = taskManager.getCleanupTaskIds();
Assert.assertEquals(1, cleanupTaskIds.size());
Assert.assertEquals(secondDeployId, cleanupTaskIds.get(0).getDeployId());
resourceOffers();
for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, firstDeployId)) {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
}
cleaner.drainCleanupQueue();
Assert.assertEquals(0, taskManager.getCleanupTaskIds().size());
Assert.assertEquals(2, taskManager.getActiveTaskIdsForDeploy(requestId, firstDeployId).size());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployWithImmediateRunIsLaunchedImmediately.
@Test
public void testDeployWithImmediateRunIsLaunchedImmediately() {
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();
Assert.assertEquals(1, taskManager.getNumActiveTasks());
Assert.assertEquals(0, taskManager.getNumScheduledTasks());
SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
SingularityTask task = taskManager.getTask(taskId).get();
Map<String, Object> command = (Map<String, Object>) task.getMesosTask().getAllOtherFields().get("command");
Assert.assertEquals("printenv > tmp.txt", (String) command.get("value"));
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployOneInstanceAtATime.
@Test
public void testDeployOneInstanceAtATime() {
initRequest();
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(), 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);
deployChecker.checkDeploys();
Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
Assert.assertTrue(taskManager.getCleanupTaskIds().contains(firstTask.getTaskId()));
SingularityDeployProgress deployProgressStepOne = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertTrue(deployProgressStepOne.isStepComplete());
Assert.assertEquals(1, deployProgressStepOne.getTargetActiveInstances());
cleaner.drainCleanupQueue();
statusUpdate(firstTask, TaskState.TASK_KILLED);
deployChecker.checkDeploys();
SingularityDeployProgress deployProgressStepTwo = deployManager.getPendingDeploys().get(0).getDeployProgress().get();
Assert.assertFalse(deployProgressStepTwo.isStepComplete());
Assert.assertEquals(2, deployProgressStepTwo.getTargetActiveInstances());
scheduler.drainPendingQueue();
Assert.assertEquals(1, 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.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 testExpiringSkipHealthchecks.
@Test
public void testExpiringSkipHealthchecks() {
initRequest();
initHCDeploy();
SingularityTask firstTask = startTask(firstDeploy);
Assert.assertTrue(healthchecker.cancelHealthcheck(firstTask.getTaskId().getId()));
requestResource.skipHealthchecks(requestId, new SingularitySkipHealthchecksRequest(Optional.of(true), Optional.of(1L), Optional.absent(), Optional.absent()), singularityUser);
statusUpdate(firstTask, TaskState.TASK_FAILED);
SingularityTask secondTask = startTask(firstDeploy);
Assert.assertFalse(healthchecker.cancelHealthcheck(secondTask.getTaskId().getId()));
statusUpdate(secondTask, TaskState.TASK_FAILED);
expiringUserActionPoller.runActionOnPoll();
SingularityTask thirdTask = startTask(firstDeploy);
Assert.assertTrue(healthchecker.cancelHealthcheck(thirdTask.getTaskId().getId()));
}
Aggregations