use of com.hubspot.singularity.SingularityDeploy in project Singularity by HubSpot.
the class DeployManager method getDeploysForKeys.
public Map<SingularityDeployKey, SingularityDeploy> getDeploysForKeys(Collection<SingularityDeployKey> deployKeys) {
final List<String> paths = Lists.newArrayListWithCapacity(deployKeys.size());
for (SingularityDeployKey deployKey : deployKeys) {
paths.add(getDeployDataPath(deployKey.getRequestId(), deployKey.getDeployId()));
}
final List<SingularityDeploy> deploys = getAsync("getDeploysForKeys", paths, deployTranscoder, deploysCache);
final Map<SingularityDeployKey, SingularityDeploy> deployKeyToDeploy = Maps.uniqueIndex(deploys, new Function<SingularityDeploy, SingularityDeployKey>() {
@Override
public SingularityDeployKey apply(SingularityDeploy input) {
return SingularityDeployKey.fromDeploy(input);
}
});
return deployKeyToDeploy;
}
use of com.hubspot.singularity.SingularityDeploy in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCronScheduleChanges.
@Test
public void testCronScheduleChanges() throws Exception {
final String requestId = "test-change-cron";
final String oldSchedule = "*/5 * * * *";
final String oldScheduleQuartz = "0 */5 * * * ?";
final String newSchedule = "*/30 * * * *";
final String newScheduleQuartz = "0 */30 * * * ?";
SingularityRequest request = new SingularityRequestBuilder(requestId, RequestType.SCHEDULED).setSchedule(Optional.of(oldSchedule)).build();
request = validator.checkSingularityRequest(request, Optional.<SingularityRequest>absent(), Optional.<SingularityDeploy>absent(), Optional.<SingularityDeploy>absent());
saveRequest(request);
Assert.assertEquals(oldScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
initAndFinishDeploy(request, "1");
scheduler.drainPendingQueue();
final SingularityRequest newRequest = request.toBuilder().setSchedule(Optional.of(newSchedule)).setQuartzSchedule(Optional.<String>absent()).build();
final SingularityDeploy newDeploy = new SingularityDeployBuilder(request.getId(), "2").setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(newDeploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
Assert.assertEquals(newScheduleQuartz, requestManager.getRequest(requestId).get().getRequest().getQuartzScheduleSafe());
}
use of com.hubspot.singularity.SingularityDeploy in project Singularity by HubSpot.
the class SingularitySchedulerTest method testSchedulerDropsMultipleScheduledTaskInstances.
@Test
public void testSchedulerDropsMultipleScheduledTaskInstances() {
initScheduledRequest();
SingularityDeploy deploy = SingularityDeploy.newBuilder(requestId, firstDeployId).setCommand(Optional.of("sleep 100")).build();
SingularityDeployRequest singularityDeployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.absent());
deployResource.deploy(singularityDeployRequest, singularityUser);
scheduler.drainPendingQueue();
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, Instant.now().plus(3, ChronoUnit.DAYS).toEpochMilli(), Optional.absent(), PendingType.NEW_DEPLOY, Optional.absent(), Optional.absent()));
SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().build();
requestResource.scheduleImmediately(singularityUser, requestId, runNowRequest);
Assert.assertEquals("Both requests make it into the pending queue", 2, requestManager.getPendingRequests().size());
Assert.assertEquals(PendingType.IMMEDIATE, requestManager.getPendingRequests().get(0).getPendingType());
Assert.assertEquals(PendingType.NEW_DEPLOY, requestManager.getPendingRequests().get(1).getPendingType());
scheduler.drainPendingQueue();
Assertions.assertThat(taskManager.getPendingTaskIds()).describedAs("Only the immediate request gets run").hasSize(1).extracting(SingularityPendingTaskId::getPendingType).containsExactly(PendingType.IMMEDIATE);
Assertions.assertThat(requestManager.getPendingRequests()).describedAs("The scheduled request is dropped from the pending queue").hasSize(0);
}
use of com.hubspot.singularity.SingularityDeploy 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.SingularityDeploy in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method deployRequest.
protected SingularityDeploy deployRequest(SingularityRequest request, double cpus, double memoryMb) {
Resources r = new Resources(cpus, memoryMb, 0);
SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), "deploy1").setCommand(Optional.of("sleep 1")).setResources(Optional.of(r)).build();
deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent()), singularityUser);
return deploy;
}
Aggregations