Search in sources :

Example 41 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testPriorityFreezeDoesntLaunchTasks.

@Test
public void testPriorityFreezeDoesntLaunchTasks() {
    // deploy lowPriorityRequest (affected by priority freeze)
    final SingularityRequest lowPriorityRequest = new SingularityRequestBuilder("lowPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.25)).build();
    saveRequest(lowPriorityRequest);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(lowPriorityRequest.getId(), "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    // deploy medium priority request (NOT affected by priority freeze)
    final SingularityRequest mediumPriorityRequest = new SingularityRequestBuilder("mediumPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.5)).build();
    saveRequest(mediumPriorityRequest);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(mediumPriorityRequest.getId(), "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    // create priority freeze
    priorityManager.createPriorityFreeze(new SingularityPriorityFreezeParent(new SingularityPriorityFreeze(0.3, true, Optional.<String>absent(), Optional.<String>absent()), System.currentTimeMillis(), Optional.<String>absent()));
    // launch both tasks
    requestResource.scheduleImmediately(singularityUser, lowPriorityRequest.getId());
    requestResource.scheduleImmediately(singularityUser, mediumPriorityRequest.getId());
    // drain pending queue
    scheduler.drainPendingQueue();
    resourceOffers();
    // assert that lowPriorityRequest has a pending task
    Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
    Assert.assertEquals(lowPriorityRequest.getId(), taskManager.getPendingTaskIds().get(0).getRequestId());
    // assert that only mediumPriorityRequest has an active task
    Assert.assertEquals(0, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
    // delete priority freeze
    Assert.assertEquals(SingularityDeleteResult.DELETED, priorityManager.deleteActivePriorityFreeze());
    // drain pending
    scheduler.drainPendingQueue();
    resourceOffers();
    // check that both requests have active tasks
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
    Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
}
Also used : SingularityPriorityFreeze(com.hubspot.singularity.api.SingularityPriorityFreeze) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 42 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testOnDemandTasksPersist.

@Test
public void testOnDemandTasksPersist() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("d2");
    deployChecker.checkDeploys();
    requestResource.scheduleImmediately(singularityUser, requestId);
    resourceOffers();
    requestResource.scheduleImmediately(singularityUser, requestId);
    resourceOffers();
    Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
    requestResource.scheduleImmediately(singularityUser, requestId);
    scheduler.drainPendingQueue();
    requestResource.scheduleImmediately(singularityUser, requestId);
    scheduler.drainPendingQueue();
    Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
    resourceOffers();
    Assert.assertEquals(4, taskManager.getActiveTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) Test(org.junit.Test)

Example 43 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testOneOffsDontMoveDuringDecomission.

@Test
public void testOneOffsDontMoveDuringDecomission() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("d2");
    requestResource.scheduleImmediately(singularityUser, requestId);
    validateTaskDoesntMoveDuringDecommission();
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) Test(org.junit.Test)

Example 44 with SingularityRequestBuilder

use of com.hubspot.singularity.SingularityRequestBuilder 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 45 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testRunOnceRunOnlyOnce.

@Test
public void testRunOnceRunOnlyOnce() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
    request = bldr.build();
    saveRequest(request);
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    deployChecker.checkDeploys();
    resourceOffers();
    Assert.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
    Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
    resourceOffers();
    Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
    deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
    scheduler.drainPendingQueue();
    deployChecker.checkDeploys();
    resourceOffers();
    Assert.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
    Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
    Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
    statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_FINISHED);
    resourceOffers();
    Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Aggregations

SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)52 Test (org.junit.Test)48 SingularityRequest (com.hubspot.singularity.SingularityRequest)37 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)22 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)17 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)12 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)10 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)9 Resources (com.hubspot.mesos.Resources)8 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)8 SingularityMesosTaskHolder (com.hubspot.singularity.helpers.SingularityMesosTaskHolder)8 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)7 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)5 SingularityContainerInfo (com.hubspot.mesos.SingularityContainerInfo)4 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)4 SingularityDockerInfo (com.hubspot.mesos.SingularityDockerInfo)3 SingularityDockerPortMapping (com.hubspot.mesos.SingularityDockerPortMapping)3 SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)3 SingularityTask (com.hubspot.singularity.SingularityTask)3 ArrayList (java.util.ArrayList)3