use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testFinishedRequestCanBeDeployed.
@Test
public void testFinishedRequestCanBeDeployed() {
initScheduledRequest();
initFirstDeploy();
schedule = "*/1 * * * * ? 1995";
// cause it to be pending
requestResource.postRequest(request.toBuilder().setQuartzSchedule(Optional.of(schedule)).build(), singularityUser);
scheduler.drainPendingQueue();
Assert.assertTrue(requestResource.getActiveRequests(singularityUser, false, false, false, 10, Collections.emptyList()).isEmpty());
Assert.assertTrue(requestManager.getRequest(requestId).get().getState() == RequestState.FINISHED);
SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, secondDeployId);
initDeploy(db, System.currentTimeMillis());
deployChecker.checkDeploys();
Assert.assertEquals(RequestState.ACTIVE, requestManager.getRequest(requestId).get().getState());
Assert.assertEquals(1, requestManager.getPendingRequests().size());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testDecommissionDoesntKillPendingDeploy.
@Test
public void testDecommissionDoesntKillPendingDeploy() {
initRequest();
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.getNumActiveTasks());
slaveResource.decommissionSlave(singularityUser, taskManager.getActiveTasks().get(0).getAgentId().getValue(), null);
scheduler.checkForDecomissions();
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertEquals(1, taskManager.getNumActiveTasks());
Assert.assertEquals(1, taskManager.getNumCleanupTasks());
Assert.assertEquals(0, taskManager.getKilledTaskIdRecords().size());
configuration.setPendingDeployHoldTaskDuringDecommissionMillis(1);
try {
Thread.sleep(2);
} catch (InterruptedException e) {
}
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertEquals(0, taskManager.getNumActiveTasks());
Assert.assertEquals(0, taskManager.getNumCleanupTasks());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRunOnceRunOnlyOnce.
@Test
public void testRunOnceRunOnlyOnce() {
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();
resourceOffers();
Assert.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_LOST);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(requestId, "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
scheduler.drainPendingQueue();
deployChecker.checkDeploys();
resourceOffers();
Assert.assertTrue(deployManager.getRequestDeployState(requestId).get().getActiveDeploy().isPresent());
Assert.assertTrue(!deployManager.getRequestDeployState(requestId).get().getPendingDeploy().isPresent());
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
statusUpdate(taskManager.getActiveTasks().get(0), TaskState.TASK_FINISHED);
resourceOffers();
Assert.assertTrue(taskManager.getActiveTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTest method testRequestedPorts.
@Test
public void testRequestedPorts() {
final SingularityDeployBuilder deployBuilder = dockerDeployWithPorts();
initRequest();
initAndFinishDeploy(request, deployBuilder, Optional.of(new Resources(1, 64, 3, 0)));
requestResource.postRequest(request.toBuilder().setInstances(Optional.of(2)).build(), singularityUser);
scheduler.drainPendingQueue();
String[] portRangeWithNoRequestedPorts = { "65:70" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNoRequestedPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithSomeRequestedPorts = { "80:82" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithSomeRequestedPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithRequestedButNotEnoughPorts = { "80:80", "8080:8080" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithRequestedButNotEnoughPorts)));
Assert.assertEquals(0, taskManager.getActiveTasks().size());
String[] portRangeWithNeededPorts = { "80:83", "8080:8080" };
sms.resourceOffers(Arrays.asList(createOffer(20, 20000, 50000, "slave1", "host1", Optional.<String>absent(), Collections.<String, String>emptyMap(), portRangeWithNeededPorts)));
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method initSecondDeploy.
protected SingularityDeployMarker initSecondDeploy() {
secondDeployMarker = new SingularityDeployMarker(requestId, secondDeployId, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent());
secondDeploy = new SingularityDeployBuilder(requestId, secondDeployId).setCommand(Optional.of("sleep 100")).build();
deployManager.saveDeploy(request, secondDeployMarker, secondDeploy);
startDeploy(secondDeployMarker, System.currentTimeMillis());
return secondDeployMarker;
}
Aggregations