Search in sources :

Example 26 with SingularityTask

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;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask)

Example 27 with SingularityTask

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);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) Test(org.junit.Test)

Example 28 with SingularityTask

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) WebApplicationException(javax.ws.rs.WebApplicationException) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand) SingularityTaskShellCommandRequest(com.hubspot.singularity.SingularityTaskShellCommandRequest) SingularityTaskShellCommandUpdate(com.hubspot.singularity.SingularityTaskShellCommandUpdate) ArrayList(java.util.ArrayList) List(java.util.List) ByteString(com.google.protobuf.ByteString) SingularityTaskShellCommandRequestId(com.hubspot.singularity.SingularityTaskShellCommandRequestId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) WebApplicationException(javax.ws.rs.WebApplicationException) Test(org.junit.Test)

Example 29 with SingularityTask

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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Test(org.junit.Test)

Example 30 with SingularityTask

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);
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Aggregations

SingularityTask (com.hubspot.singularity.SingularityTask)94 Test (org.junit.Test)66 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)33 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)15 SingularityRequest (com.hubspot.singularity.SingularityRequest)15 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)12 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)11 HealthcheckOptions (com.hubspot.deploy.HealthcheckOptions)9 HealthcheckOptionsBuilder (com.hubspot.deploy.HealthcheckOptionsBuilder)9 Resources (com.hubspot.mesos.Resources)7 ArrayList (java.util.ArrayList)7 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)6 List (java.util.List)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)5 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)5 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)4 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)4 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)3