@Inject public SingularityExecutorArtifactFetcher(@Named(SingularityExecutorModule.LOCAL_DOWNLOAD_HTTP_CLIENT) AsyncHttpClient localDownloadHttpClient, SingularityS3Configuration s3Configuration, SingularityExecutorConfiguration executorConfiguration, ObjectMapper objectMapper, SingularityRunnerExceptionNotifier exceptionNotifier, SingularityRunnerBaseConfiguration runnerBaseConfiguration) { this.localDownloadHttpClient = localDownloadHttpClient; this.executorConfiguration = executorConfiguration; this.s3Configuration = s3Configuration; this.objectMapper = objectMapper; this.exceptionNotifier = exceptionNotifier; this.runnerBaseConfiguration = runnerBaseConfiguration; this.localDownloadUri = String.format(LOCAL_DOWNLOAD_STRING_FORMAT, s3Configuration.getLocalDownloadHttpPort(), s3Configuration.getLocalDownloadPath()); }
@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()); }