Search in sources :

Example 1 with ProcessFailedException

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);
    }
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) IOException(java.io.IOException) ProcessFailedException(com.hubspot.singularity.runner.base.shared.ProcessFailedException)

Example 2 with ProcessFailedException

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;
}
Also used : DockerException(com.spotify.docker.client.exceptions.DockerException) ArtifactList(com.hubspot.deploy.ArtifactList) ArrayList(java.util.ArrayList) S3ArtifactSignature(com.hubspot.deploy.S3ArtifactSignature) ExternalArtifact(com.hubspot.deploy.ExternalArtifact) ProcessFailedException(com.hubspot.singularity.runner.base.shared.ProcessFailedException) S3Artifact(com.hubspot.deploy.S3Artifact) EmbeddedArtifact(com.hubspot.deploy.EmbeddedArtifact)

Example 3 with ProcessFailedException

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);
        }
    }
}
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)

Aggregations

ProcessFailedException (com.hubspot.singularity.runner.base.shared.ProcessFailedException)3 DockerException (com.spotify.docker.client.exceptions.DockerException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ArtifactList (com.hubspot.deploy.ArtifactList)1 EmbeddedArtifact (com.hubspot.deploy.EmbeddedArtifact)1 ExternalArtifact (com.hubspot.deploy.ExternalArtifact)1 S3Artifact (com.hubspot.deploy.S3Artifact)1 S3ArtifactSignature (com.hubspot.deploy.S3ArtifactSignature)1 CompressionType (com.hubspot.singularity.runner.base.shared.CompressionType)1 SimpleProcessManager (com.hubspot.singularity.runner.base.shared.SimpleProcessManager)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1