use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularityCachedOffersTest method testLeftoverCachedOffersAreReturnedToCache.
@Test
public void testLeftoverCachedOffersAreReturnedToCache() throws Exception {
configuration.setCacheOffers(true);
Offer neededOffer = createOffer(1, 128, 1024, "slave1", "host1", Optional.absent(), Collections.emptyMap(), new String[] { "80:81" });
Offer extraOffer = createOffer(4, 256, 1024, "slave1", "host1", Optional.absent(), Collections.emptyMap(), new String[] { "83:84" });
sms.resourceOffers(ImmutableList.of(neededOffer, extraOffer));
initRequest();
firstDeploy = initAndFinishDeploy(request, new SingularityDeployBuilder(request.getId(), firstDeployId).setCommand(Optional.of("sleep 100")), Optional.of(new Resources(1, 128, 2, 0)));
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, firstDeployId, System.currentTimeMillis(), Optional.absent(), PendingType.TASK_DONE, Optional.absent(), Optional.absent()));
schedulerPoller.runActionOnPoll();
List<Offer> cachedOffers = offerCache.peekOffers();
Assert.assertEquals(1, cachedOffers.size());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularityDeploysTest method testUsesNewRequestDataFromPendingDeploy.
@Test
public void testUsesNewRequestDataFromPendingDeploy() {
initRequest();
initFirstDeploy();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(2)));
scheduler.drainPendingQueue();
Assert.assertEquals(2, taskManager.getPendingTaskIds().size());
Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
String deployId = "test_new_request_data";
SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
List<SingularityPendingTaskId> pendingTaskIdsForNewDeploy = new ArrayList<>();
for (SingularityPendingTaskId pendingTaskId : taskManager.getPendingTaskIds()) {
if (pendingTaskId.getDeployId().equals(deployId)) {
pendingTaskIdsForNewDeploy.add(pendingTaskId);
}
}
Assert.assertEquals(1, pendingTaskIdsForNewDeploy.size());
Assert.assertEquals(2, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
resourceOffers();
for (SingularityTaskId taskId : taskManager.getActiveTaskIdsForDeploy(requestId, deployId)) {
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
}
deployChecker.checkDeploys();
Assert.assertEquals(1, requestManager.getRequest(requestId).get().getRequest().getInstancesSafe());
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularityDeploysTest method testCannotUpdateRequestDuringPendingDeployWithNewData.
@Test(expected = WebApplicationException.class)
public void testCannotUpdateRequestDuringPendingDeployWithNewData() {
initRequest();
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
SingularityRequest newRequest = request.toBuilder().setInstances(Optional.of(1)).build();
String deployId = "test_new_request_data";
SingularityDeploy deploy = new SingularityDeployBuilder(request.getId(), deployId).setCommand(Optional.of("sleep 100")).build();
deployResource.deploy(new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent(), Optional.of(newRequest)), singularityUser);
requestResource.postRequest(newRequest, singularityUser);
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployFailsAfterMaxTaskRetries.
@Test
public void testDeployFailsAfterMaxTaskRetries() {
initRequest();
SingularityDeployBuilder db = new SingularityDeployBuilder(requestId, firstDeployId);
db.setMaxTaskRetries(Optional.of(1));
SingularityDeploy deploy = initDeploy(db, System.currentTimeMillis());
deployChecker.checkDeploys();
Assert.assertTrue(!deployManager.getDeployResult(requestId, firstDeployId).isPresent());
SingularityTask task = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
deployChecker.checkDeploys();
Assert.assertEquals(deployManager.getPendingDeploys().get(0).getCurrentDeployState(), DeployState.WAITING);
SingularityTask taskTryTwo = launchTask(request, deploy, System.currentTimeMillis(), 1, TaskState.TASK_FAILED);
deployChecker.checkDeploys();
Assert.assertEquals(deployManager.getDeployResult(requestId, firstDeployId).get().getDeployState(), DeployState.FAILED);
}
use of com.hubspot.singularity.SingularityDeployBuilder in project Singularity by HubSpot.
the class SingularityDeploysTest method testDeployWithImmediateRunSchedulesAfterRunningImmediately.
@Test
public void testDeployWithImmediateRunSchedulesAfterRunningImmediately() {
initRequestWithType(RequestType.SCHEDULED, false);
String deployId = "d1";
SingularityRunNowRequest runNowRequest = new SingularityRunNowRequestBuilder().setMessage("Message").build();
SingularityDeploy deploy = new SingularityDeployBuilder(requestId, deployId).setRunImmediately(Optional.of(runNowRequest)).setCommand(Optional.of("printenv > tmp.txt")).build();
SingularityDeployRequest deployRequest = new SingularityDeployRequest(deploy, Optional.absent(), Optional.absent());
deployResource.deploy(deployRequest, singularityUser);
deployChecker.checkDeploys();
scheduler.drainPendingQueue();
resourceOffers();
SingularityTaskId taskId = taskManager.getActiveTaskIdsForDeploy(requestId, deployId).get(0);
SingularityTask task = taskManager.getTask(taskId).get();
statusUpdate(task, TaskState.TASK_RUNNING);
statusUpdate(task, TaskState.TASK_FINISHED);
scheduler.drainPendingQueue();
resourceOffers();
Assert.assertEquals(0, taskManager.getNumActiveTasks());
Assert.assertEquals(1, taskManager.getNumScheduledTasks());
}
Aggregations