Search in sources :

Example 6 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testQueueMultipleOneOffs.

@Test
public void testQueueMultipleOneOffs() {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.ON_DEMAND);
    requestResource.postRequest(bldr.build(), singularityUser);
    deploy("on_demand_deploy");
    deployChecker.checkDeploys();
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
    requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, "on_demand_deploy", System.currentTimeMillis(), Optional.<String>absent(), PendingType.ONEOFF, Optional.<List<String>>absent(), Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent()));
    scheduler.drainPendingQueue();
    Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 7 with SingularityRequestBuilder

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

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

the class SingularitySchedulerTest method testRunOnceDontMoveDuringDecomission.

@Test
public void testRunOnceDontMoveDuringDecomission() {
    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();
    validateTaskDoesntMoveDuringDecommission();
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Test(org.junit.Test)

Example 9 with SingularityRequestBuilder

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

the class SingularitySchedulerTest method testDifferentQuartzTimeZones.

@Test
public void testDifferentQuartzTimeZones() {
    final Optional<String> schedule = Optional.of("* 30 14 22 3 ? 2083");
    SingularityRequest requestEST = new SingularityRequestBuilder("est_id", RequestType.SCHEDULED).setSchedule(schedule).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(// fixed in relation to GMT
    Optional.of("EST")).build();
    SingularityRequest requestGMT = new SingularityRequestBuilder("gmt_id", RequestType.SCHEDULED).setSchedule(schedule).setScheduleType(Optional.of(ScheduleType.QUARTZ)).setScheduleTimeZone(Optional.of("GMT")).build();
    requestResource.postRequest(requestEST, singularityUser);
    requestResource.postRequest(requestGMT, singularityUser);
    SingularityDeploy deployEST = new SingularityDeployBuilder(requestEST.getId(), "est_deploy_id").setCommand(Optional.of("sleep 1")).build();
    SingularityDeploy deployGMT = new SingularityDeployBuilder(requestGMT.getId(), "gmt_deploy_id").setCommand(Optional.of("sleep 1")).build();
    deployResource.deploy(new SingularityDeployRequest(deployEST, Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    deployResource.deploy(new SingularityDeployRequest(deployGMT, Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
    deployChecker.checkDeploys();
    scheduler.drainPendingQueue();
    final long nextRunEST;
    final long nextRunGMT;
    final long fiveHoursInMilliseconds = TimeUnit.HOURS.toMillis(5);
    final List<SingularityPendingTaskId> pendingTaskIds = taskManager.getPendingTaskIds();
    if (pendingTaskIds.get(0).getRequestId().equals(requestEST.getId())) {
        nextRunEST = pendingTaskIds.get(0).getNextRunAt();
        nextRunGMT = pendingTaskIds.get(1).getNextRunAt();
    } else {
        nextRunEST = pendingTaskIds.get(1).getNextRunAt();
        nextRunGMT = pendingTaskIds.get(0).getNextRunAt();
    }
    // GMT happens first, so EST is a larger timestamp
    Assert.assertEquals(nextRunEST - nextRunGMT, fiveHoursInMilliseconds);
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityDeployRequest(com.hubspot.singularity.api.SingularityDeployRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) Test(org.junit.Test)

Example 10 with SingularityRequestBuilder

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

the class SingularitySchedulerTestBase method createRequest.

protected SingularityRequest createRequest(String requestId) {
    SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.SERVICE);
    bldr.setInstances(Optional.of(5));
    bldr.setSlavePlacement(Optional.of(SlavePlacement.SEPARATE));
    SingularityRequest request = bldr.build();
    saveRequest(bldr.build());
    return request;
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityRequest(com.hubspot.singularity.SingularityRequest)

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