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