use of com.hubspot.singularity.executor.task.SingularityExecutorTaskProcessCallable in project Singularity by HubSpot.
the class SingularityExecutorMesosFrameworkMessageHandler method handleShellRequest.
private void handleShellRequest(SingularityTaskShellCommandRequest shellRequest) {
Optional<SingularityExecutorTask> matchingTask = monitor.getTask(shellRequest.getTaskId().getId());
if (!matchingTask.isPresent()) {
LOG.warn("Missing task for {}, ignoring shell request", shellRequest.getTaskId());
return;
}
matchingTask.get().getLog().info("Received shell request {}", shellRequest);
SingularityExecutorShellCommandUpdater updater = new SingularityExecutorShellCommandUpdater(objectMapper, shellRequest, matchingTask.get());
Optional<SingularityExecutorTaskProcessCallable> taskProcess = monitor.getTaskProcess(shellRequest.getTaskId().getId());
if (!taskProcess.isPresent()) {
updater.sendUpdate(UpdateType.INVALID, Optional.of("No task process found"), Optional.<String>absent());
return;
}
SingularityExecutorShellCommandRunner shellRunner = new SingularityExecutorShellCommandRunner(shellRequest, executorConfiguration, matchingTask.get(), taskProcess.get(), monitor.getShellCommandExecutorServiceForTask(shellRequest.getTaskId().getId()), updater);
shellRunner.start();
}
use of com.hubspot.singularity.executor.task.SingularityExecutorTaskProcessCallable in project Singularity by HubSpot.
the class SingularityExecutorMonitor method requestKill.
public KillState requestKill(String taskId, Optional<String> user, boolean destroy) {
final Optional<SingularityExecutorTask> maybeTask = Optional.fromNullable(tasks.get(taskId));
if (!maybeTask.isPresent()) {
return KillState.DIDNT_EXIST;
}
final SingularityExecutorTask task = maybeTask.get();
if (!destroy && task.wasForceDestroyed()) {
task.getLog().debug("Already force destroyed, will not issue additional kill");
return KillState.DESTROYING_PROCESS;
}
task.getLog().info("Executor asked to kill {}", taskId);
ListenableFuture<ProcessBuilder> processBuilderFuture = null;
SingularityExecutorTaskProcessCallable runningProcess = null;
task.getLock().lock();
boolean wasKilled = task.wasKilled();
try {
if (!wasKilled) {
task.markKilled(user);
}
processBuilderFuture = processBuildingTasks.get(task.getTaskId());
runningProcess = processRunningTasks.get(task.getTaskId());
} finally {
task.getLock().unlock();
}
if (processBuilderFuture != null) {
task.getLog().info("Canceling process builder future for {}", taskId);
CancelThread cancelThread = new CancelThread(processBuilderFuture, task);
cancelThread.start();
return KillState.INTERRUPTING_PRE_PROCESS;
}
if (runningProcess != null) {
if (destroy) {
if (user.isPresent()) {
task.getLog().info("Destroying process with pid {} for task {} by request from user {}", runningProcess.getCurrentPid(), taskId, user.get());
} else {
task.getLog().info("Destroying process with pid {} for task {}", runningProcess.getCurrentPid(), taskId);
}
task.markForceDestroyed(user);
runningProcess.signalKillToProcessIfActive();
return KillState.DESTROYING_PROCESS;
}
if (processKiller.isKillInProgress(taskId)) {
task.getLog().info("Kill already in progress for task {}", taskId);
return KillState.KILLING_PROCESS;
}
if (user.isPresent()) {
task.getLog().info("Killing process for task {} by request from {}", taskId, user.get());
} else {
task.getLog().info("Killing process for task {}", taskId);
}
processKiller.submitKillRequest(runningProcess);
return KillState.KILLING_PROCESS;
}
return KillState.INCONSISTENT_STATE;
}
use of com.hubspot.singularity.executor.task.SingularityExecutorTaskProcessCallable in project Singularity by HubSpot.
the class SingularityExecutorMonitor method submitProcessMonitor.
private SingularityExecutorTaskProcessCallable submitProcessMonitor(final SingularityExecutorTask task, ProcessBuilder processBuilder) {
SingularityExecutorTaskProcessCallable processCallable = buildProcessCallable(task, processBuilder);
final ListenableFuture<Integer> processExitFuture = runningProcessPool.submit(processCallable);
watchProcessExitFuture(task, processExitFuture);
return processCallable;
}
use of com.hubspot.singularity.executor.task.SingularityExecutorTaskProcessCallable in project Singularity by HubSpot.
the class SingularityExecutorThreadChecker method checkThreads.
private void checkThreads() {
for (SingularityExecutorTaskProcessCallable taskProcess : monitor.getRunningTasks()) {
if (!taskProcess.getTask().getExecutorData().getMaxTaskThreads().isPresent()) {
continue;
}
final int maxThreads = taskProcess.getTask().getExecutorData().getMaxTaskThreads().get();
int usedThreads = 0;
try {
usedThreads = getNumUsedThreads(taskProcess);
LOG.trace("{} is using {} threads", taskProcess.getTask().getTaskId(), usedThreads);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
} catch (Throwable t) {
if (!taskProcess.wasKilled()) {
taskProcess.getTask().getLog().error("While fetching used threads for {}", taskProcess.getTask().getTaskId(), t);
}
continue;
}
if (usedThreads > maxThreads) {
taskProcess.getTask().getLog().info("{} using too many threads: {} (max {})", taskProcess.getTask().getTaskId(), usedThreads, maxThreads);
taskProcess.getTask().markKilledDueToThreads(usedThreads);
KillState killState = monitor.requestKill(taskProcess.getTask().getTaskId());
taskProcess.getTask().getLog().info("Killing {} due to thread overage (kill state {})", taskProcess.getTask().getTaskId(), killState);
}
}
}
Aggregations