Search in sources :

Example 1 with SimpleProcessManager

use of com.hubspot.singularity.runner.base.shared.SimpleProcessManager in project Singularity by HubSpot.

the class SingularityExecutorThreadChecker method getNumThreadsFromCommand.

private Optional<Integer> getNumThreadsFromCommand(SingularityExecutorTaskProcessCallable taskProcess, Optional<Integer> dockerPid, String commandFormat) throws InterruptedException, ProcessFailedException {
    SimpleProcessManager checkThreadsProcessManager = new SimpleProcessManager(NOPLogger.NOP_LOGGER);
    List<String> cmd = ImmutableList.of("/bin/sh", "-c", String.format(commandFormat, dockerPid.or(taskProcess.getCurrentPid().get())));
    List<String> output = checkThreadsProcessManager.runCommandWithOutput(cmd);
    if (output.isEmpty()) {
        LOG.warn("Output from ls was empty ({})", cmd);
        return Optional.absent();
    } else {
        return Optional.of(Integer.parseInt(output.get(0)));
    }
}
Also used : SimpleProcessManager(com.hubspot.singularity.runner.base.shared.SimpleProcessManager)

Example 2 with SimpleProcessManager

use of com.hubspot.singularity.runner.base.shared.SimpleProcessManager in project Singularity by HubSpot.

the class SingularityExecutorTaskLogManager method copyLogTail.

private void copyLogTail() {
    if (configuration.getTailLogLinesToSave() <= 0) {
        return;
    }
    final Path tailOfLogPath = taskDefinition.getServiceFinishedTailLogPath();
    if (Files.exists(tailOfLogPath)) {
        log.debug("{} already existed, skipping tail", tailOfLogPath);
        return;
    }
    final List<String> cmd = ImmutableList.of("tail", "-n", Integer.toString(configuration.getTailLogLinesToSave()), taskDefinition.getServiceLogOut());
    try {
        new SimpleProcessManager(log).runCommand(cmd, Redirect.to(tailOfLogPath.toFile()));
    } catch (Throwable t) {
        log.error("Failed saving tail of log {} to {}", taskDefinition.getServiceLogOut(), taskDefinition.getServiceFinishedTailLogPath(), t);
    }
}
Also used : Path(java.nio.file.Path) SimpleProcessManager(com.hubspot.singularity.runner.base.shared.SimpleProcessManager)

Example 3 with SimpleProcessManager

use of com.hubspot.singularity.runner.base.shared.SimpleProcessManager 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);
        }
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SimpleProcessManager(com.hubspot.singularity.runner.base.shared.SimpleProcessManager) ProcessFailedException(com.hubspot.singularity.runner.base.shared.ProcessFailedException) CompressionType(com.hubspot.singularity.runner.base.shared.CompressionType) HashSet(java.util.HashSet)

Example 4 with SimpleProcessManager

use of com.hubspot.singularity.runner.base.shared.SimpleProcessManager in project Singularity by HubSpot.

the class SingularityUploader method isFileOpen.

static boolean isFileOpen(Path path) {
    try {
        SimpleProcessManager lsof = new SimpleProcessManager(LOG);
        List<String> cmd = ImmutableList.of("lsof", path.toAbsolutePath().toString());
        List<String> output = lsof.runCommandWithOutput(cmd, Sets.newHashSet(0, 1));
        for (String line : output) {
            if (line.contains(path.toAbsolutePath().toString())) {
                return true;
            }
        }
    } catch (Exception e) {
        LOG.error("Could not determine if file {} was in use, skipping", path, e);
        return true;
    }
    return false;
}
Also used : SimpleProcessManager(com.hubspot.singularity.runner.base.shared.SimpleProcessManager) RetryException(com.github.rholder.retry.RetryException) IOException(java.io.IOException)

Example 5 with SimpleProcessManager

use of com.hubspot.singularity.runner.base.shared.SimpleProcessManager in project Singularity by HubSpot.

the class SingularityExecutorTaskCleanup method cleanupTaskAppDirectory.

private boolean cleanupTaskAppDirectory() {
    final String pathToDelete = taskDefinition.getTaskAppDirectory();
    log.info("Deleting: {}", pathToDelete);
    try {
        final List<String> cmd = ImmutableList.of("rm", "-rf", pathToDelete);
        new SimpleProcessManager(log).runCommand(cmd);
        return true;
    } catch (Throwable t) {
        log.error("While deleting directory {}", pathToDelete, t);
    }
    return false;
}
Also used : SimpleProcessManager(com.hubspot.singularity.runner.base.shared.SimpleProcessManager)

Aggregations

SimpleProcessManager (com.hubspot.singularity.runner.base.shared.SimpleProcessManager)5 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 RetryException (com.github.rholder.retry.RetryException)1 CompressionType (com.hubspot.singularity.runner.base.shared.CompressionType)1 ProcessFailedException (com.hubspot.singularity.runner.base.shared.ProcessFailedException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1