use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method launchTask.
protected SingularityTask launchTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, long updateTime, int instanceNo, TaskState initialTaskState, boolean separateHost, Optional<String> runId) {
SingularityTask task = prepTask(request, deploy, launchTime, instanceNo, separateHost, runId);
taskManager.createTaskAndDeletePendingTask(task);
statusUpdate(task, initialTaskState, Optional.of(updateTime));
return task;
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityStartupTest method testFailuresInLaunchPath.
@Test
public void testFailuresInLaunchPath() {
initRequest();
initFirstDeploy();
SingularityTask task = prepTask();
taskManager.createTaskAndDeletePendingTask(task);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
startup.checkSchedulerForInconsistentState();
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
taskManager.deleteActiveTask(task.getTaskId().getId());
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 0);
startup.checkSchedulerForInconsistentState();
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().size() == 1);
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityTaskShellCommandTest method testTaskShellCommandPersistence.
@Test
public void testTaskShellCommandPersistence() {
initRequest();
initFirstDeploy();
SingularityTask task = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
// test bad command first:
setShellCommandsConfiguration();
// bad shell cmd
try {
taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("test-cmd", Optional.of(Arrays.asList("one", "two")), user, Optional.absent()));
} catch (WebApplicationException exception) {
assertEquals(400, exception.getResponse().getStatus());
}
// bad option
try {
taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d1", Optional.of(Arrays.asList("one", "two")), user, Optional.absent()));
} catch (WebApplicationException exception) {
assertEquals(400, exception.getResponse().getStatus());
}
SingularityTaskShellCommandRequest firstShellRequest = taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d1", Optional.of(Arrays.asList("o1", "o2")), user, Optional.absent()));
try {
Thread.sleep(3);
} catch (Exception e) {
}
SingularityTaskShellCommandRequest secondShellRequest = taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d2", Optional.<List<String>>absent(), user, Optional.absent()));
assertEquals(2, taskManager.getAllQueuedTaskShellCommandRequests().size());
dispatchPoller.runActionOnPoll();
assertEquals(0, taskManager.getAllQueuedTaskShellCommandRequests().size());
assertEquals(2, taskManager.getTaskShellCommandRequestsForTask(task.getTaskId()).size());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(firstShellRequest.getId(), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(new SingularityTaskShellCommandRequestId(task.getTaskId(), "wat", System.currentTimeMillis()), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(new SingularityTaskShellCommandRequestId(new SingularityTaskId("makingitup", "did", System.currentTimeMillis(), 1, "host", "rack"), "wat", System.currentTimeMillis()), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
assertEquals(true, taskManager.getTaskHistory(task.getTaskId()).get().getShellCommandHistory().get(1).getShellUpdates().get(0).getUpdateType() == UpdateType.STARTED);
assertEquals(1, taskManager.getTaskShellCommandUpdates(firstShellRequest.getId()).size());
assertEquals(0, taskManager.getTaskShellCommandUpdates(secondShellRequest.getId()).size());
}
use of com.hubspot.singularity.SingularityTask 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());
}
use of com.hubspot.singularity.SingularityTask in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployFailsAfterMaxTaskRetries.
@Test
public void testDeployFailsAfterMaxTaskRetries() {
initRequest();
SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, firstDeployId);
db.setMaxTaskRetries(Optional.of(1));
SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
deployChecker.checkDeploys();
Assert.assertTrue(!deployManager.getDeployResult(requestId, firstDeployId).isPresent());
SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
deployChecker.checkDeploys();
Assert.assertEquals(deployManager.getPendingDeploys().get(0).getCurrentDeployState(), DeployState.WAITING);
SingularityTask taskTryTwo = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
deployChecker.checkDeploys();
Assert.assertEquals(deployManager.getDeployResult(requestId, firstDeployId).get().getDeployState(), DeployState.FAILED);
}
Aggregations