Search in sources :

Example 6 with SingularityRunNowRequestBuilder

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

the class SingularitySchedulerTest method testOnDemandRunNowJobRespectsSpecifiedRunAtTime.

@Test
public void testOnDemandRunNowJobRespectsSpecifiedRunAtTime() {
    initOnDemandRequest();
    initFirstDeploy();
    long requestedLaunchTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
    requestResource.scheduleImmediately(singularityUser, requestId, new SingularityRunNowRequestBuilder().setRunAt(requestedLaunchTime).build());
    scheduler.drainPendingQueue();
    SingularityPendingTaskId task = taskManager.getPendingTaskIds().get(0);
    long runAt = task.getNextRunAt();
    Assert.assertEquals(requestedLaunchTime, runAt);
}
Also used : SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) Test(org.junit.Test)

Example 7 with SingularityRunNowRequestBuilder

use of com.hubspot.singularity.SingularityRunNowRequestBuilder 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 8 with SingularityRunNowRequestBuilder

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

the class SingularitySchedulerTest method testScheduledRunNowJobRespectsSpecifiedRunAtTime.

@Test
public void testScheduledRunNowJobRespectsSpecifiedRunAtTime() {
    initScheduledRequest();
    initFirstDeploy();
    long requestedLaunchTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
    requestResource.scheduleImmediately(singularityUser, requestId, new SingularityRunNowRequestBuilder().setRunAt(requestedLaunchTime).build());
    scheduler.drainPendingQueue();
    SingularityPendingTaskId task = taskManager.getPendingTaskIds().get(0);
    long runAt = task.getNextRunAt();
    Assert.assertEquals(requestedLaunchTime, runAt);
}
Also used : SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) Test(org.junit.Test)

Example 9 with SingularityRunNowRequestBuilder

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

the class SingularityDeploysTest method testDeployWithImmediateRunIsLaunchedImmediately.

@Test
public void testDeployWithImmediateRunIsLaunchedImmediately() {
    initRequestWithType(RequestType.SCHEDULED, false);
    String deployId = "d1";
    SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setMessage("Message").build();
    SingularityDeploy deploy = new SingularityDeployBuilder(requestId, deployId).setRunImmediately(Optional.of(runNowRequest)).setCommand(Optional.of("printenv > tmp.txt")).build();
    SingularityDeployRequest deployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent());
    deployResource.deploy(deployRequest, singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    resourceOffers();
    Assert.assertEquals(1, taskManager.getNumActiveTasks());
    Assert.assertEquals(0, taskManager.getNumScheduledTasks());
    SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
    SingularityTask task = taskManager.getTask(taskId).get();
    Map<String, Object> command = (Map<String, Object>) task.getMesosTask().getAllOtherFields().get("command");
    Assert.assertEquals("printenv > tmp.txt", (String) command.get("value"));
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRunNowRequestBuilder(com.hubspot.singularity.SingularityRunNowRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Map(java.util.Map) Test(org.junit.Test)

Aggregations

SingularityRunNowRequestBuilder (com.hubspot.singularity.SingularityRunNowRequestBuilder)9 Test (org.junit.Test)9 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)6 SingularityTask (com.hubspot.singularity.SingularityTask)5 Resources (com.hubspot.mesos.Resources)3 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)3 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)3 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)3 SingularityDeployRequest (com.hubspot.singularity.api.SingularityDeployRequest)3 SingularityDeployBuilder (com.hubspot.singularity.SingularityDeployBuilder)2 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 SingularityDeployStatistics (com.hubspot.singularity.SingularityDeployStatistics)1 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 Map (java.util.Map)1