use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRetries.
@Test
public void testRetries() {
SingularityRequestBuilder bldr = new SingularityRequestBuilder(requestId, RequestType.RUN_ONCE);
request = bldr.setNumRetriesOnFailure(Optional.of(2)).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();
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityDeployBuilder 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.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method dockerDeployWithPorts.
private SingularityDeployBuilder dockerDeployWithPorts() {
final SingularityDockerPortMapping literalMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 80, Optional.of(SingularityPortMappingType.LITERAL), 8080, Optional.<String>absent());
final SingularityDockerPortMapping offerMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 81, Optional.of(SingularityPortMappingType.FROM_OFFER), 0, Optional.of("udp"));
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(SingularityContainerType.DOCKER, Optional.<List<SingularityVolume>>absent(), Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.BRIDGE, Optional.of(Arrays.asList(literalMapping, offerMapping)), Optional.of(false), Optional.of(ImmutableMap.of("env", "var=value")), Optional.absent())));
final SingularityDeployBuilder deployBuilder = new SingularityDeployBuilder(requestId, "test-docker-ports-deploy");
deployBuilder.setContainerInfo(Optional.of(containerInfo));
return deployBuilder;
}
use of com.hubspot.singularity.SingularityDeployBuilder 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.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRemovedRequestData.
@Test
public void testRemovedRequestData() {
long now = System.currentTimeMillis();
initRequest();
SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, firstDeployId);
db.setMaxTaskRetries(Optional.of(1));
initDeploy(db, now);
deployChecker.checkDeploys();
Assert.assertEquals(DeployState.WAITING, deployManager.getPendingDeploys().get(0).getCurrentDeployState());
requestManager.startDeletingRequest(request, Optional.absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent());
requestManager.markDeleted(request, now, Optional.<String>absent(), Optional.<String>absent());
deployChecker.checkDeploys();
SingularityDeployResult deployResult = deployManager.getDeployResult(requestId, firstDeployId).get();
Assert.assertEquals(DeployState.FAILED, deployResult.getDeployState());
Assert.assertTrue(deployResult.getMessage().get().contains("MISSING"));
}
Aggregations