Search in sources :

Example 1 with ArtifactDownloadRequest

use of com.hubspot.singularity.s3.base.ArtifactDownloadRequest in project Singularity by HubSpot.

the class SingularityS3DownloaderHandler method handle.

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    metrics.getRequestsMeter().mark();
    if (!target.equals(s3Configuration.getLocalDownloadPath())) {
        metrics.getClientErrorsMeter().mark();
        response.sendError(404);
        return;
    }
    if (!request.getMethod().equalsIgnoreCase(HttpMethod.POST.name())) {
        metrics.getClientErrorsMeter().mark();
        response.sendError(405);
        return;
    }
    Optional<ArtifactDownloadRequest> artifactOptional = readDownloadRequest(request);
    if (!artifactOptional.isPresent()) {
        metrics.getClientErrorsMeter().mark();
        response.sendError(400);
        return;
    }
    Continuation continuation = ContinuationSupport.getContinuation(request);
    continuation.suspend(response);
    if (artifactOptional.get().getTimeoutMillis().isPresent()) {
        continuation.setTimeout(artifactOptional.get().getTimeoutMillis().get());
    }
    downloaderCoordinator.register(continuation, artifactOptional.get());
}
Also used : Continuation(org.eclipse.jetty.continuation.Continuation) ArtifactDownloadRequest(com.hubspot.singularity.s3.base.ArtifactDownloadRequest)

Example 2 with ArtifactDownloadRequest

use of com.hubspot.singularity.s3.base.ArtifactDownloadRequest in project Singularity by HubSpot.

the class UnixLocalDownloadServiceFetcher method downloadFiles.

@Override
public void downloadFiles(List<? extends S3Artifact> s3Artifacts, SingularityExecutorTask task) throws InterruptedException {
    final List<CompletableFutureHolder> futures = Lists.newArrayListWithCapacity(s3Artifacts.size());
    for (S3Artifact s3Artifact : s3Artifacts) {
        String destination = task.getArtifactPath(s3Artifact, task.getTaskDefinition().getTaskDirectoryPath()).toString();
        ArtifactDownloadRequest artifactDownloadRequest = new ArtifactDownloadRequest(destination, s3Artifact, Optional.of(executorConfiguration.getLocalDownloadServiceTimeoutMillis()));
        task.getLog().debug("Requesting {} from {}", artifactDownloadRequest, s3Configuration.getLocalDownloadSocket().get());
        try {
            CompletableFuture<ContentResponse> future = new CompletableFuture<>();
            httpClient.newRequest(localDownloadPath).method(HttpMethod.POST).content(new BytesContentProvider(objectMapper.writeValueAsBytes(artifactDownloadRequest)), "application/json").send(new CompletableFutureResponseListener(future));
            futures.add(new CompletableFutureHolder(future, System.currentTimeMillis(), s3Artifact));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
    for (CompletableFutureHolder future : futures) {
        ContentResponse response = future.getResponse();
        task.getLog().debug("Future for {} got status code {} after {}", future.s3Artifact.getName(), response.getStatus(), JavaUtils.duration(future.start));
        if (response.getStatus() != 200) {
            throw new IllegalStateException("Got status code:" + response.getStatus());
        }
    }
}
Also used : ArtifactDownloadRequest(com.hubspot.singularity.s3.base.ArtifactDownloadRequest) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) CompletableFuture(java.util.concurrent.CompletableFuture) S3Artifact(com.hubspot.deploy.S3Artifact) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with ArtifactDownloadRequest

use of com.hubspot.singularity.s3.base.ArtifactDownloadRequest in project Singularity by HubSpot.

the class HttpLocalDownloadServiceFetcher method downloadFiles.

@Override
public void downloadFiles(List<? extends S3Artifact> s3Artifacts, SingularityExecutorTask task) throws InterruptedException {
    final List<FutureHolder> futures = Lists.newArrayListWithCapacity(s3Artifacts.size());
    for (S3Artifact s3Artifact : s3Artifacts) {
        String destination = task.getArtifactPath(s3Artifact, task.getTaskDefinition().getTaskDirectoryPath()).toString();
        ArtifactDownloadRequest artifactDownloadRequest = new ArtifactDownloadRequest(destination, s3Artifact, Optional.of(executorConfiguration.getLocalDownloadServiceTimeoutMillis()));
        task.getLog().debug("Requesting {} from {}", artifactDownloadRequest, localDownloadUri);
        BoundRequestBuilder postRequestBldr = httpClient.preparePost(localDownloadUri);
        try {
            postRequestBldr.setBody(objectMapper.writeValueAsBytes(artifactDownloadRequest));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        try {
            ListenableFuture<Response> future = httpClient.executeRequest(postRequestBldr.build());
            futures.add(new FutureHolder(future, System.currentTimeMillis(), s3Artifact));
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
    for (FutureHolder future : futures) {
        Response response = future.getResponse();
        task.getLog().debug("Future for {} got status code {} after {}", future.s3Artifact.getName(), response.getStatusCode(), JavaUtils.duration(future.start));
        if (response.getStatusCode() != 200) {
            throw new IllegalStateException("Got status code:" + response.getStatusCode());
        }
    }
}
Also used : Response(com.ning.http.client.Response) BoundRequestBuilder(com.ning.http.client.AsyncHttpClient.BoundRequestBuilder) ArtifactDownloadRequest(com.hubspot.singularity.s3.base.ArtifactDownloadRequest) S3Artifact(com.hubspot.deploy.S3Artifact) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ArtifactDownloadRequest (com.hubspot.singularity.s3.base.ArtifactDownloadRequest)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 S3Artifact (com.hubspot.deploy.S3Artifact)2 BoundRequestBuilder (com.ning.http.client.AsyncHttpClient.BoundRequestBuilder)1 Response (com.ning.http.client.Response)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)1 BytesContentProvider (org.eclipse.jetty.client.util.BytesContentProvider)1 Continuation (org.eclipse.jetty.continuation.Continuation)1