use of com.hubspot.singularity.SingularityRequest 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.SingularityRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method itSetsRequestStateToDeletedAfterAllTasksAreCleanedUp.
@Test
public void itSetsRequestStateToDeletedAfterAllTasksAreCleanedUp() {
initRequest();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
initFirstDeploy();
launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
launchTask(request, firstDeploy, 2, TaskState.TASK_RUNNING);
Assert.assertEquals(requestId, requestManager.getActiveRequests().iterator().next().getRequest().getId());
Assert.assertEquals(2, taskManager.getActiveTaskIds().size());
requestManager.startDeletingRequest(request, Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent());
Assert.assertEquals(requestId, requestManager.getCleanupRequests().get(0).getRequestId());
Assert.assertEquals(RequestState.DELETING, requestManager.getRequest(requestId).get().getState());
cleaner.drainCleanupQueue();
Assert.assertEquals(0, taskManager.getCleanupTaskIds().size());
killKilledTasks();
cleaner.drainCleanupQueue();
Assert.assertFalse(requestManager.getRequest(requestId).isPresent());
}
use of com.hubspot.singularity.SingularityRequest in project Singularity by HubSpot.
the class SingularitySchedulerTest method testCleanerFindsTasksWithSkippedHealthchecks.
@Test
public void testCleanerFindsTasksWithSkippedHealthchecks() {
initRequest();
// set up slaves so scale validate will pass
resourceOffers(2);
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
long now = System.currentTimeMillis();
requestManager.saveHistory(new SingularityRequestHistory(now, Optional.<String>absent(), RequestHistoryType.UPDATED, request.toBuilder().setSkipHealthchecks(Optional.of(true)).setInstances(Optional.of(2)).build(), Optional.<String>absent()));
firstDeploy = initDeploy(new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")).setHealthcheckUri(Optional.of("http://uri")), System.currentTimeMillis());
SingularityTask taskOne = launchTask(request, firstDeploy, now + 1000, now + 2000, 1, TaskState.TASK_RUNNING);
finishDeploy(new SingularityDeployMarker(requestId, firstDeployId, now + 2000, Optional.<String>absent(), Optional.<String>absent()), firstDeploy);
SingularityRequest updatedRequest = request.toBuilder().setSkipHealthchecks(Optional.<Boolean>absent()).setInstances(Optional.of(2)).build();
requestManager.saveHistory(new SingularityRequestHistory(now + 3000, Optional.<String>absent(), RequestHistoryType.UPDATED, updatedRequest, Optional.<String>absent()));
SingularityTask newTaskTwoWithCheck = prepTask(updatedRequest, firstDeploy, now + 4000, 2);
taskManager.createTaskAndDeletePendingTask(newTaskTwoWithCheck);
statusUpdate(newTaskTwoWithCheck, TaskState.TASK_RUNNING, Optional.of(now + 5000));
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), newTaskTwoWithCheck.getTaskId(), Optional.<Boolean>absent()));
SingularityTask unhealthyTaskThree = prepTask(updatedRequest, firstDeploy, now + 4000, 3);
taskManager.createTaskAndDeletePendingTask(unhealthyTaskThree);
statusUpdate(unhealthyTaskThree, TaskState.TASK_RUNNING, Optional.of(now + 5000));
List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(requestId);
List<SingularityTaskId> healthyTaskIds = deployHealthHelper.getHealthyTasks(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false);
Assert.assertTrue(!healthyTaskIds.contains(unhealthyTaskThree.getTaskId()));
// Healthchecked and skip-healthchecked tasks should both be here
Assert.assertEquals(2, healthyTaskIds.size());
Assert.assertEquals(DeployHealth.WAITING, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), now + 6000, Optional.<String>absent(), Optional.<String>absent(), unhealthyTaskThree.getTaskId(), Optional.<Boolean>absent()));
Assert.assertEquals(DeployHealth.HEALTHY, deployHealthHelper.getDeployHealth(updatedRequest, Optional.of(firstDeploy), activeTaskIds, false));
}
use of com.hubspot.singularity.SingularityRequest 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.SingularityRequest 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