Search in sources :

Example 1 with SingularityPendingTask

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

the class SingularityWebCache method cachePendingTasks.

public void cachePendingTasks(List<SingularityPendingTask> pendingTasks) {
    pendingMissMeter.mark();
    Map<SingularityPendingTaskId, SingularityPendingTask> newPendingTasks = new HashMap<>(pendingTasks.size());
    for (SingularityPendingTask pendingTask : pendingTasks) {
        newPendingTasks.put(pendingTask.getPendingTaskId(), pendingTask);
    }
    cachedPendingTasks = newPendingTasks;
    lastPendingTaskCache = System.currentTimeMillis();
}
Also used : HashMap(java.util.HashMap) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId)

Example 2 with SingularityPendingTask

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

the class SingularitySchedulerTest method testCustomResourcesWithRunNowRequest.

@Test
public void testCustomResourcesWithRunNowRequest() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    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 pendingTaskWithResourcs = taskManager.getPendingTasks().get(0);
    Assert.assertTrue(pendingTaskWithResourcs.getResources().isPresent());
    Assert.assertEquals(pendingTaskWithResourcs.getResources().get().getCpus(), 2, 0.0);
    sms.resourceOffers(Arrays.asList(createOffer(5, 5, 5, "slave1", "host1", Optional.of("rack1"))));
    SingularityTask task = taskManager.getActiveTasks().get(0);
    Assert.assertEquals(MesosUtils.getNumCpus(mesosProtosUtils.toResourceList(task.getMesosTask().getResources()), Optional.<String>absent()), 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 3 with SingularityPendingTask

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

the class SingularitySchedulerTestBase method createAndSchedulePendingTask.

protected SingularityPendingTask createAndSchedulePendingTask(String deployId) {
    Random random = new Random();
    SingularityPendingTaskId pendingTaskId = new SingularityPendingTaskId(requestId, deployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(random.nextInt(3)), random.nextInt(10), PendingType.NEW_DEPLOY, System.currentTimeMillis());
    SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).build();
    taskManager.savePendingTask(pendingTask);
    return pendingTask;
}
Also used : Random(java.util.Random) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

Example 4 with SingularityPendingTask

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

the class SingularityDeploysTest method testDeployClearsObsoleteScheduledTasks.

@Test
public void testDeployClearsObsoleteScheduledTasks() {
    initRequest();
    initFirstDeploy();
    initSecondDeploy();
    SingularityPendingTaskId taskIdOne = new SingularityPendingTaskId(requestId, firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 1, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskOne = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdOne).build();
    SingularityPendingTaskId taskIdTwo = new SingularityPendingTaskId(requestId, firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1), 2, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskTwo = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdTwo).build();
    SingularityPendingTaskId taskIdThree = new SingularityPendingTaskId(requestId, secondDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 1, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskThree = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdThree).build();
    SingularityPendingTaskId taskIdFour = new SingularityPendingTaskId(requestId + "hi", firstDeployId, System.currentTimeMillis() + TimeUnit.DAYS.toMillis(3), 5, PendingType.IMMEDIATE, System.currentTimeMillis());
    SingularityPendingTask taskFour = new SingularityPendingTaskBuilder().setPendingTaskId(taskIdFour).build();
    taskManager.savePendingTask(taskOne);
    taskManager.savePendingTask(taskTwo);
    taskManager.savePendingTask(taskThree);
    taskManager.savePendingTask(taskFour);
    launchTask(request, secondDeploy, 1, TaskState.TASK_RUNNING);
    deployChecker.checkDeploys();
    List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
    Assert.assertTrue(!pendingTaskIds.contains(taskIdOne));
    Assert.assertTrue(!pendingTaskIds.contains(taskIdTwo));
    Assert.assertTrue(pendingTaskIds.contains(taskIdThree));
    Assert.assertTrue(pendingTaskIds.contains(taskIdFour));
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Test(org.junit.Test)

Example 5 with SingularityPendingTask

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

the class SingularitySchedulerTestBase method buildPendingTask.

protected SingularityPendingTask buildPendingTask(SingularityRequest request, SingularityDeploy deploy, long launchTime, int instanceNo, Optional<String> runId) {
    SingularityPendingTaskId pendingTaskId = new SingularityPendingTaskId(request.getId(), deploy.getId(), launchTime, instanceNo, PendingType.IMMEDIATE, launchTime);
    SingularityPendingTask pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(pendingTaskId).setRunId(runId).build();
    return pendingTask;
}
Also used : SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder)

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