Search in sources :

Example 16 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularitySchedulerTest method testSchedulerIsolatesPendingTasksBasedOnDeploy.

@Test
public void testSchedulerIsolatesPendingTasksBasedOnDeploy() {
    initRequest();
    initFirstDeploy();
    initSecondDeploy();
    SingularityPendingTask p1 = pendingTask(requestId, firstDeployId, PendingType.ONEOFF);
    SingularityPendingTask p2 = pendingTask(requestId, firstDeployId, PendingType.TASK_DONE);
    SingularityPendingTask p3 = pendingTask(requestId, secondDeployId, PendingType.TASK_DONE);
    taskManager.savePendingTask(p1);
    taskManager.savePendingTask(p2);
    taskManager.savePendingTask(p3);
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, secondDeployId, System.currentTimeMillis(), Optional.<String>absent(), PendingType.NEW_DEPLOY, Optional.<Boolean>absent(), Optional.<String>absent()));
    scheduler.drainPendingQueue();
    // we expect there to be 3 pending tasks :
    List<SingularityPendingTask> returnedScheduledTasks = taskManager.getPendingTasks();
    Assert.assertEquals(3, returnedScheduledTasks.size());
    Assert.assertTrue(returnedScheduledTasks.contains(p1));
    Assert.assertTrue(returnedScheduledTasks.contains(p2));
    Assert.assertTrue(!returnedScheduledTasks.contains(p3));
    boolean found = false;
    for (SingularityPendingTask pendingTask : returnedScheduledTasks) {
        if (pendingTask.getPendingTaskId().getDeployId().equals(secondDeployId)) {
            found = true;
            Assert.assertEquals(PendingType.NEW_DEPLOY, pendingTask.getPendingTaskId().getPendingType());
        }
    }
    Assert.assertTrue(found);
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Test(org.junit.Test)

Example 17 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularitySchedulerTest method testAcceptOffersWithRoleForRequestWithRole.

@Test
public void testAcceptOffersWithRoleForRequestWithRole() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    bldr.setRequiredRole(Optional.of("test-role"));
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("d2");
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setResources(new Resources(2, 2, 0)).build();
    requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
    scheduler.drainPendingQueue();
    SingularityPendingTask pendingTaskWithResources = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResources.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResources.getResources().get().getCpus(), 2, 0.0);
    sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5)));
    pendingTaskWithResources = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResources.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResources.getResources().get().getCpus(), 2, 0.0);
    sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5, Optional.of("test-role"))));
    SingularityTask task = taskManager.getActiveTasks().get(0);
    Assert.assertEquals(MesosUtils.getNumCpus(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), Optional.of("test-role")), 2.0, 0.0);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) Resources(com.hubspot.mesos.Resources) Test(org.junit.Test)

Example 18 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method prepTask.

protected SingularityTask prepTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, boolean separateHosts, Optional<String> runId) {
    SingularityPendingTask pendingTask = buildPendingTask(request, deploy, launchTime, instanceNo, runId);
    SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
    Offer offer;
    if (separateHosts) {
        offer = createOffer(125, 1024, 2048, String.format("slave%s", instanceNo), String.format("host%s", instanceNo));
    } else {
        offer = createOffer(125, 1024, 2048);
    }
    SingularityTaskId taskId = new SingularityTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, offer.getHostname(), "rack1");
    TaskID taskIdProto = TaskID.newBuilder().setValue(taskId.toString()).build();
    TaskInfo taskInfo = TaskInfo.newBuilder().setAgentId(offer.getAgentId()).setExecutor(ExecutorInfo.newBuilder().setExecutorId(ExecutorID.newBuilder().setValue("executorID"))).setTaskId(taskIdProto).setName("name").build();
    SingularityTask task = new SingularityTask(taskRequest, taskId, Collections.singletonList(mesosProtosUtils.offerFromProtos(offer)), mesosProtosUtils.taskFromProtos(taskInfo), Optional.of("rack1"));
    taskManager.savePendingTask(pendingTask);
    return task;
}
Also used : TaskInfo(org.apache.mesos.v1.Protos.TaskInfo) TaskID(org.apache.mesos.v1.Protos.TaskID) SingularityTask(com.hubspot.singularity.SingularityTask) Offer(org.apache.mesos.v1.Protos.Offer) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 19 with SingularityPendingTask

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

Example 20 with SingularityPendingTask

use of com.hubspot.singularity.SingularityPendingTask in project Singularity by HubSpot.

the class SingularityMesosTaskBuilderTest method testEnvironmentVariableOverrides.

@Test
public void testEnvironmentVariableOverrides() {
    Map<String, String> overrideVariables = new HashMap<>();
    overrideVariables.put("MY_NEW_ENV_VAR", "test");
    overrideVariables.put("STARTED_BY_USER", "notTestUser");
    final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
    final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1").setCommand(Optional.of("/bin/echo hi")).build();
    final SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).setEnvOverrides(overrideVariables).build();
    final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
    final TaskInfo task = builder.buildTask(offerHolder, null, taskRequest, taskResources, executorResources).getMesosTask();
    Map<String, String> environmentVariables = task.getCommand().getEnvironment().getVariablesList().stream().collect(Collectors.toMap(Variable::getName, Variable::getValue));
    for (String key : overrideVariables.keySet()) {
        assertEquals("Environment variable " + key + " not overridden.", environmentVariables.get(key), overrideVariables.get(key));
    }
}
Also used : TaskInfo(org.apache.mesos.v1.Protos.TaskInfo) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) HashMap(java.util.HashMap) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Test(org.junit.Test)

Aggregations

SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)22 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Test (org.junit.Test)8 SingularityTask (com.hubspot.singularity.SingularityTask)6 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)6 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)6 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)4 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)4 SingularityRequest (com.hubspot.singularity.SingularityRequest)4 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 Resources (com.hubspot.mesos.Resources)3 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)3 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)3 Timed (com.codahale.metrics.annotation.Timed)2 MachineState (com.hubspot.singularity.MachineState)2 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)2 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)2 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)2 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)2 TaskInfo (org.apache.mesos.v1.Protos.TaskInfo)2