use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularitySchedulerTest method testBounceOnRunningInstancesReleasesLock.
@Test
public void testBounceOnRunningInstancesReleasesLock() {
initRequest();
initFirstDeploy();
startTask(firstDeploy, 1);
Assert.assertEquals(1, taskManager.getActiveTaskIds().size());
requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.of(true), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent())), singularityUser);
Assert.assertTrue(requestManager.isBouncing(requestId));
cleaner.drainCleanupQueue();
// It acquires a lock on the bounce
Assert.assertTrue("Lock on bounce should be acquired during bounce", requestManager.getExpiringBounce(requestId).isPresent());
scheduler.drainPendingQueue();
resourceOffers();
for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
taskManager.saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(singularityTaskId, System.currentTimeMillis(), ExtendedTaskState.TASK_RUNNING, Optional.absent(), Optional.absent(), Collections.emptySet()));
}
Assert.assertTrue("Need to start at least 1 instance to begin killing old instances", taskManager.getActiveTaskIds().size() >= 2);
Assert.assertTrue(requestManager.isBouncing(requestId));
cleaner.drainCleanupQueue();
killKilledTasks();
Assert.assertFalse(requestManager.isBouncing(requestId));
// It finishes with one task running and the bounce released
Assert.assertEquals("Should end bounce with target number of tasks", 1, taskManager.getActiveTaskIds().size());
for (SingularityTaskId singularityTaskId : taskManager.getActiveTaskIds()) {
String statusMessage = taskManager.getTaskHistoryUpdates(singularityTaskId).get(0).getStatusMessage().get();
Assert.assertTrue("Task was started by bounce", statusMessage.contains("BOUNCE"));
}
Assert.assertFalse("Lock on bounce should be released after bounce", requestManager.getExpiringBounce(requestId).isPresent());
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularitySchedulerTest method testScaleDownTakesHighestInstancesWithPendingTask.
@Test
public void testScaleDownTakesHighestInstancesWithPendingTask() {
initRequest();
initFirstDeploy();
saveAndSchedule(request.toBuilder().setInstances(Optional.of(5)));
resourceOffers();
Assert.assertEquals(5, taskManager.getActiveTaskIds().size());
SingularityTaskId instance2 = null;
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
if (taskId.getInstanceNo() == 2) {
instance2 = taskId;
}
}
statusUpdate(taskManager.getTask(instance2).get(), TaskState.TASK_KILLED);
killKilledTasks();
scheduler.drainPendingQueue();
requestResource.scale(requestId, new SingularityScaleRequest(Optional.of(3), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent()), singularityUser);
scheduler.drainPendingQueue();
cleaner.drainCleanupQueue();
// instances 4 and 5 should get killed
Assert.assertEquals(2, taskManager.getKilledTaskIdRecords().size());
killKilledTasks();
resourceOffers();
// instances 1,2,3 should be active
Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
Assert.assertTrue(taskId.getInstanceNo() < 4);
}
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularitySchedulerTestBase method runLaunchedTasks.
protected void runLaunchedTasks() {
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
Collection<SingularityTaskHistoryUpdate> updates = taskManager.getTaskHistoryUpdates(taskId);
SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
switch(currentState) {
case UNKNOWN:
case WAITING:
statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
break;
case DONE:
case RUNNING:
break;
}
}
}
use of com.hubspot.singularity.SingularityTaskId in project Singularity by HubSpot.
the class SingularityTaskShellCommandTest method testTaskShellCommandPersistence.
@Test
public void testTaskShellCommandPersistence() {
initRequest();
initFirstDeploy();
SingularityTask task = launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
// test bad command first:
setShellCommandsConfiguration();
// bad shell cmd
try {
taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("test-cmd", Optional.of(Arrays.asList("one", "two")), user, Optional.absent()));
} catch (WebApplicationException exception) {
assertEquals(400, exception.getResponse().getStatus());
}
// bad option
try {
taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d1", Optional.of(Arrays.asList("one", "two")), user, Optional.absent()));
} catch (WebApplicationException exception) {
assertEquals(400, exception.getResponse().getStatus());
}
SingularityTaskShellCommandRequest firstShellRequest = taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d1", Optional.of(Arrays.asList("o1", "o2")), user, Optional.absent()));
try {
Thread.sleep(3);
} catch (Exception e) {
}
SingularityTaskShellCommandRequest secondShellRequest = taskResource.runShellCommand(singularityUser, task.getTaskId().getId(), new SingularityShellCommand("d2", Optional.<List<String>>absent(), user, Optional.absent()));
assertEquals(2, taskManager.getAllQueuedTaskShellCommandRequests().size());
dispatchPoller.runActionOnPoll();
assertEquals(0, taskManager.getAllQueuedTaskShellCommandRequests().size());
assertEquals(2, taskManager.getTaskShellCommandRequestsForTask(task.getTaskId()).size());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(firstShellRequest.getId(), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(new SingularityTaskShellCommandRequestId(task.getTaskId(), "wat", System.currentTimeMillis()), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
mesosScheduler.message(Event.Message.newBuilder().setExecutorId(MesosProtosUtils.toExecutorId(task.getMesosTask().getExecutor().getExecutorId())).setAgentId(MesosProtosUtils.toAgentId(task.getMesosTask().getAgentId())).setData(ByteString.copyFrom(updateTranscoder.toBytes(new SingularityTaskShellCommandUpdate(new SingularityTaskShellCommandRequestId(new SingularityTaskId("makingitup", "did", System.currentTimeMillis(), 1, "host", "rack"), "wat", System.currentTimeMillis()), System.currentTimeMillis(), Optional.<String>of("hi"), Optional.<String>absent(), UpdateType.STARTED)))).build());
assertEquals(true, taskManager.getTaskHistory(task.getTaskId()).get().getShellCommandHistory().get(1).getShellUpdates().get(0).getUpdateType() == UpdateType.STARTED);
assertEquals(1, taskManager.getTaskShellCommandUpdates(firstShellRequest.getId()).size());
assertEquals(0, taskManager.getTaskShellCommandUpdates(secondShellRequest.getId()).size());
}
use of com.hubspot.singularity.SingularityTaskId 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());
}
Aggregations