use of com.hubspot.singularity.SingularityShellCommand in project Singularity by HubSpot.
the class SingularitySchedulerTest method testIncrementalBounce.
@Test
public void testIncrementalBounce() {
initRequest();
// set up slaves so scale validate will pass
resourceOffers(2);
SingularityRequest request = requestResource.getRequest(requestId, singularityUser).getRequest();
requestResource.postRequest(request.toBuilder().setSlavePlacement(Optional.of(SlavePlacement.SEPARATE_BY_REQUEST)).setInstances(Optional.of(2)).build(), singularityUser);
initHCDeploy();
SingularityTask taskOne = startSeparatePlacementTask(firstDeploy, 1);
SingularityTask taskTwo = startSeparatePlacementTask(firstDeploy, 2);
requestManager.createCleanupRequest(new SingularityRequestCleanup(user, RequestCleanupType.INCREMENTAL_BOUNCE, System.currentTimeMillis(), Optional.<Boolean>absent(), Optional.absent(), requestId, Optional.of(firstDeployId), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<SingularityShellCommand>absent()));
Assert.assertTrue(requestManager.cleanupRequestExists(requestId));
cleaner.drainCleanupQueue();
Assert.assertTrue(!requestManager.cleanupRequestExists(requestId));
Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
resourceOffers(3);
SingularityTask taskThree = null;
for (SingularityTask task : taskManager.getActiveTasks()) {
if (!task.getTaskId().equals(taskOne.getTaskId()) && !task.getTaskId().equals(taskTwo.getTaskId())) {
taskThree = task;
}
}
statusUpdate(taskThree, TaskState.TASK_RUNNING, Optional.of(1L));
Assert.assertEquals(3, taskManager.getActiveTaskIds().size());
cleaner.drainCleanupQueue();
// No old tasks should be killed before new ones pass healthchecks
Assert.assertEquals(2, taskManager.getCleanupTaskIds().size());
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), taskThree.getTaskId(), Optional.<Boolean>absent()));
cleaner.drainCleanupQueue();
Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
statusUpdate(taskOne, TaskState.TASK_KILLED);
resourceOffers(3);
SingularityTask taskFour = null;
for (SingularityTask task : taskManager.getActiveTasks()) {
if (!task.getTaskId().equals(taskOne.getTaskId()) && !task.getTaskId().equals(taskTwo.getTaskId()) && !task.getTaskId().equals(taskThree.getTaskId())) {
taskFour = task;
}
}
statusUpdate(taskFour, TaskState.TASK_RUNNING, Optional.of(1L));
taskManager.saveHealthcheckResult(new SingularityTaskHealthcheckResult(Optional.of(200), Optional.of(1000L), System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), taskFour.getTaskId(), Optional.<Boolean>absent()));
cleaner.drainCleanupQueue();
Assert.assertTrue(taskManager.getCleanupTaskIds().isEmpty());
}
use of com.hubspot.singularity.SingularityShellCommand in project Singularity by HubSpot.
the class SingularitySchedulerTest method badPauseExpires.
@Test
public void badPauseExpires() {
initRequest();
requestManager.createCleanupRequest(new SingularityRequestCleanup(Optional.<String>absent(), RequestCleanupType.PAUSING, System.currentTimeMillis(), Optional.<Boolean>absent(), Optional.absent(), requestId, Optional.<String>absent(), Optional.<Boolean>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<SingularityShellCommand>absent()));
cleaner.drainCleanupQueue();
Assert.assertTrue(!requestManager.getCleanupRequests().isEmpty());
configuration.setCleanupEverySeconds(0);
sleep(1);
cleaner.drainCleanupQueue();
Assert.assertTrue(requestManager.getCleanupRequests().isEmpty());
}
use of com.hubspot.singularity.SingularityShellCommand 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.SingularityShellCommand in project Singularity by HubSpot.
the class SingularityTaskShellCommandTest method testRunCommandBeforeBounceKill.
@Test
public void testRunCommandBeforeBounceKill() {
setShellCommandsConfiguration();
initRequest();
initFirstDeploy();
launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
requestResource.bounce(requestId, Optional.of(new SingularityBounceRequest(Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.of(new SingularityShellCommand("d1", Optional.of(Arrays.asList("o1", "o2")), user, Optional.absent())))), singularityUser);
cleaner.drainCleanupQueue();
List<SingularityTaskCleanup> taskCleanups = taskManager.getCleanupTasks();
Assert.assertTrue(taskCleanups.get(0).getRunBeforeKillId().isPresent());
SingularityTaskShellCommandRequestId shellCommandRequestId = taskCleanups.get(0).getRunBeforeKillId().get();
cleaner.drainCleanupQueue();
Assert.assertEquals(1, taskManager.getCleanupTaskIds().size());
launchTask(request, firstDeploy, 1, TaskState.TASK_RUNNING);
Assert.assertEquals(2, taskManager.getActiveTaskIdsForRequest(requestId).size());
cleaner.drainCleanupQueue();
Assert.assertEquals(2, taskManager.getActiveTaskIdsForRequest(requestId).size());
taskManager.saveTaskShellCommandUpdate(new SingularityTaskShellCommandUpdate(shellCommandRequestId, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), UpdateType.ACKED));
cleaner.drainCleanupQueue();
Assert.assertEquals(2, taskManager.getActiveTaskIdsForRequest(requestId).size());
taskManager.saveTaskShellCommandUpdate(new SingularityTaskShellCommandUpdate(shellCommandRequestId, System.currentTimeMillis(), Optional.<String>absent(), Optional.<String>absent(), UpdateType.FINISHED));
cleaner.drainCleanupQueue();
Assert.assertEquals(1, taskManager.getKilledTaskIdRecords().size());
}
use of com.hubspot.singularity.SingularityShellCommand in project Singularity by HubSpot.
the class RequestResource method bounce.
public SingularityRequestParent bounce(String requestId, Optional<SingularityBounceRequest> bounceRequest, SingularityUser user) {
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
validator.checkActionEnabled(SingularityAction.BOUNCE_REQUEST);
checkBadRequest(requestWithState.getRequest().isLongRunning(), "Can not bounce a %s request (%s)", requestWithState.getRequest().getRequestType(), requestWithState);
checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to bounce (it must be manually unpaused first)", requestWithState.getRequest().getId());
final boolean isIncrementalBounce = bounceRequest.isPresent() && bounceRequest.get().getIncremental().or(false);
validator.checkResourcesForBounce(requestWithState.getRequest(), isIncrementalBounce);
validator.checkRequestForPriorityFreeze(requestWithState.getRequest());
final Optional<Boolean> skipHealthchecks = bounceRequest.isPresent() ? bounceRequest.get().getSkipHealthchecks() : Optional.<Boolean>absent();
Optional<String> message = Optional.absent();
Optional<String> actionId = Optional.absent();
Optional<SingularityShellCommand> runBeforeKill = Optional.absent();
if (bounceRequest.isPresent()) {
actionId = bounceRequest.get().getActionId();
message = bounceRequest.get().getMessage();
if (bounceRequest.get().getRunShellCommandBeforeKill().isPresent()) {
validator.checkValidShellCommand(bounceRequest.get().getRunShellCommandBeforeKill().get());
runBeforeKill = bounceRequest.get().getRunShellCommandBeforeKill();
}
}
if (!actionId.isPresent()) {
actionId = Optional.of(UUID.randomUUID().toString());
}
final String deployId = getAndCheckDeployId(requestId);
checkConflict(!(requestManager.markAsBouncing(requestId) == SingularityCreateResult.EXISTED), "%s is already bouncing", requestId);
requestManager.createCleanupRequest(new SingularityRequestCleanup(user.getEmail(), isIncrementalBounce ? RequestCleanupType.INCREMENTAL_BOUNCE : RequestCleanupType.BOUNCE, System.currentTimeMillis(), Optional.absent(), Optional.absent(), requestId, Optional.of(deployId), skipHealthchecks, message, actionId, runBeforeKill));
requestManager.bounce(requestWithState.getRequest(), System.currentTimeMillis(), Optional.of(user.getId()), message);
final SingularityBounceRequest validatedBounceRequest = validator.checkBounceRequest(bounceRequest.or(SingularityBounceRequest.defaultRequest()));
requestManager.saveExpiringObject(new SingularityExpiringBounce(requestId, deployId, Optional.of(user.getId()), System.currentTimeMillis(), validatedBounceRequest, actionId.get()));
return fillEntireRequest(requestWithState);
}
Aggregations