use of com.hubspot.singularity.SingularityDeploy in project Singularity by HubSpot.
the class HistoryPersisterTest method testDeployCountPurging.
@Test
public void testDeployCountPurging() {
SingularityRequest requestOne = buildRequest("request1");
SingularityRequest requestTwo = buildRequest("request2");
SingularityDeploy requestOneDeployOne = initAndFinishDeploy(requestOne, "r1d1");
SingularityDeploy requestOneDeployTwo = initAndFinishDeploy(requestOne, "r1d2");
SingularityDeploy requestOneDeployThree = initAndFinishDeploy(requestOne, "r1d3");
// r1d4 is the active deploy, not eligible for purging
SingularityDeploy requestOneDeployFour = initAndFinishDeploy(requestOne, "r1d4");
SingularityDeploy requestTwoDeployOne = initAndFinishDeploy(requestTwo, "r2d1");
// r2d2 is the active deploy, not eligible for purging
SingularityDeploy requestTwoDeployTwo = initAndFinishDeploy(requestTwo, "r2d2");
configuration.setMaxStaleDeploysPerRequestInZkWhenNoDatabase(Optional.of(2));
deployHistoryPersister.runActionOnPoll();
Assert.assertTrue(!deployManager.getDeployHistory(requestOneDeployOne.getRequestId(), requestOneDeployOne.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployTwo.getRequestId(), requestOneDeployTwo.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployThree.getRequestId(), requestOneDeployThree.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestOneDeployFour.getRequestId(), requestOneDeployFour.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployOne.getRequestId(), requestTwoDeployOne.getId(), true).isPresent());
Assert.assertTrue(deployManager.getDeployHistory(requestTwoDeployTwo.getRequestId(), requestTwoDeployTwo.getId(), true).isPresent());
}
use of com.hubspot.singularity.SingularityDeploy 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.SingularityDeploy 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.SingularityDeploy 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.SingularityDeploy 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