use of com.hubspot.singularity.runner.base.shared.ProcessFailedException in project Singularity by HubSpot.
the class SingularityExecutorThreadChecker method getNumUsedThreads.
private int getNumUsedThreads(SingularityExecutorTaskProcessCallable taskProcess) throws InterruptedException, ProcessFailedException {
Optional<Integer> dockerPid = Optional.absent();
if (taskProcess.getTask().getTaskInfo().hasContainer() && taskProcess.getTask().getTaskInfo().getContainer().hasDocker()) {
try {
String containerName = String.format("%s%s", configuration.getDockerPrefix(), taskProcess.getTask().getTaskId());
int possiblePid = dockerUtils.getPid(containerName);
if (possiblePid == 0) {
LOG.warn(String.format("Container %s has pid %s (running: %s). Defaulting to 0 threads running.", containerName, possiblePid, dockerUtils.isContainerRunning(containerName)));
return 0;
} else {
dockerPid = Optional.of(possiblePid);
}
} catch (DockerException e) {
throw new ProcessFailedException("Could not get docker root pid due to error", e);
}
}
try {
Optional<Integer> numThreads = getNumThreads(configuration.getThreadCheckerType(), taskProcess, dockerPid);
if (numThreads.isPresent()) {
return numThreads.get();
} else {
LOG.warn("Could not get num threads using {} thread checker", configuration.getThreadCheckerType());
return 0;
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of com.hubspot.singularity.runner.base.shared.ProcessFailedException in project Singularity by HubSpot.
the class SingularityExecutorTaskProcessBuilder method call.
@Override
public ProcessBuilder call() throws Exception {
if (task.getTaskInfo().hasContainer() && task.getTaskInfo().getContainer().hasDocker()) {
executorUtils.sendStatusUpdate(task.getDriver(), task.getTaskInfo().getTaskId(), TaskState.TASK_STARTING, String.format("Pulling image... (executor pid: %s)", executorPid), task.getLog());
try {
dockerUtils.pull(task.getTaskInfo().getContainer().getDocker().getImage());
} catch (DockerException e) {
throw new ProcessFailedException("Could not pull docker image", e);
}
}
executorUtils.sendStatusUpdate(task.getDriver(), task.getTaskInfo().getTaskId(), TaskState.TASK_STARTING, String.format("Staging files... (executor pid: %s)", executorPid), task.getLog());
taskArtifactFetcher = Optional.of(artifactFetcher.buildTaskFetcher(executorData, task));
taskArtifactFetcher.get().fetchFiles(executorData.getEmbeddedArtifacts(), executorData.getS3Artifacts(), executorData.getS3ArtifactSignaturesOrEmpty(), executorData.getExternalArtifacts());
task.getArtifactVerifier().checkSignatures(executorData.getS3ArtifactSignaturesOrEmpty());
List<ArtifactList> artifactLists = new ArrayList<>();
artifactLists.addAll(checkArtifactsForArtifactLists(executorData.getS3Artifacts()));
artifactLists.addAll(checkArtifactsForArtifactLists(executorData.getS3ArtifactSignaturesOrEmpty()));
artifactLists.addAll(checkArtifactsForArtifactLists(executorData.getExternalArtifacts()));
if (!artifactLists.isEmpty()) {
List<EmbeddedArtifact> embeddedArtifacts = new ArrayList<>();
List<S3Artifact> s3Artifacts = new ArrayList<>();
List<S3ArtifactSignature> s3ArtifactSignatures = new ArrayList<>();
List<ExternalArtifact> externalArtifacts = new ArrayList<>();
for (ArtifactList artifactList : artifactLists) {
embeddedArtifacts.addAll(artifactList.getEmbeddedArtifacts());
s3Artifacts.addAll(artifactList.getS3Artifacts());
s3ArtifactSignatures.addAll(artifactList.getS3ArtifactSignatures());
externalArtifacts.addAll(artifactList.getExternalArtifacts());
}
task.getLog().info("Found {} artifact lists with {} embedded, {} s3, {} external, fetching...", artifactLists.size(), embeddedArtifacts.size(), s3Artifacts.size() + s3ArtifactSignatures.size(), externalArtifacts.size());
taskArtifactFetcher.get().fetchFiles(embeddedArtifacts, s3Artifacts, s3ArtifactSignatures, externalArtifacts);
task.getArtifactVerifier().checkSignatures(s3ArtifactSignatures);
}
ProcessBuilder processBuilder = buildProcessBuilder(task.getTaskInfo(), executorData, task.getTaskDefinition().getServiceLogFileName());
task.getTaskLogManager().setup();
return processBuilder;
}
use of com.hubspot.singularity.runner.base.shared.ProcessFailedException in project Singularity by HubSpot.
the class SingularityExecutorCleanup method checkForUncompressedLogrotatedFile.
private void checkForUncompressedLogrotatedFile(SingularityExecutorTaskDefinition taskDefinition) {
final Iterator<Path> iterator = getUncompressedLogrotatedFileIterator(taskDefinition);
final Set<String> emptyPaths = new HashSet<>();
final List<Path> uncompressedFiles = new ArrayList<>();
while (iterator.hasNext()) {
Path path = iterator.next();
final String fileName = Objects.toString(path.getFileName());
Optional<CompressionType> maybeCompressionType = getFileCompressionType(fileName);
if (maybeCompressionType.isPresent()) {
try {
if (Files.size(path) == 0) {
Files.deleteIfExists(path);
emptyPaths.add(fileName.substring(0, fileName.length() - maybeCompressionType.get().getExtention().length()));
}
} catch (IOException ioe) {
LOG.error("Failed to handle empty {} file {}", maybeCompressionType.get(), path, ioe);
exceptionNotifier.notify(String.format("Error handling empty file (%s)", ioe.getMessage()), ioe, ImmutableMap.of("file", path.toString()));
}
} else {
uncompressedFiles.add(path);
}
}
for (Path path : uncompressedFiles) {
if (emptyPaths.contains(Objects.toString(path.getFileName()))) {
LOG.info("Compressing abandoned file {}", path);
try {
new SimpleProcessManager(LOG).runCommand(ImmutableList.<String>of(cleanupConfiguration.getCompressionType().getCommand(), path.toString()));
} catch (InterruptedException | ProcessFailedException e) {
LOG.error("Failed to {} {}", cleanupConfiguration.getCompressionType(), path, e);
exceptionNotifier.notify(String.format("Failed to gzip (%s)", e.getMessage()), e, ImmutableMap.of("file", path.toString()));
}
} else {
LOG.debug("Didn't find matched empty {} file for {}", cleanupConfiguration.getCompressionType(), path);
}
}
}
Aggregations