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());
}
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);
}
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();
}
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);
}
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;
}
Aggregations