public void getJobOutput()

in genie-web/src/main/java/com/netflix/genie/web/apis/rest/v3/controllers/JobRestController.java [705:758]


    public void getJobOutput(
        @PathVariable("id") final String id,
        @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false)
        @Nullable final String forwardedFrom,
        final HttpServletRequest request,
        final HttpServletResponse response
    ) throws GenieException, NotFoundException {

        final String path = ControllerUtils.getRemainingPath(request);
        log.info(
            "[getJobOutput] Called to get output path: \"{}\" for job: \"{}\".{}",
            path,
            id,
            forwardedFrom == null ? EMPTY_STRING : " Requested forwarded from: " + forwardedFrom
        );

        final URL baseUrl;
        try {
            baseUrl = forwardedFrom == null
                ? ControllerUtils.getRequestRoot(request, path)
                : ControllerUtils.getRequestRoot(new URL(forwardedFrom), path);
        } catch (final MalformedURLException e) {
            throw new GenieServerException("Unable to parse base request url", e);
        }

        final ArchiveStatus archiveStatus = this.persistenceService.getJobArchiveStatus(id);

        if (archiveStatus == ArchiveStatus.PENDING) {
            final String jobHostname;
            try {
                jobHostname = this.agentRoutingService
                    .getHostnameForAgentConnection(id)
                    .orElseThrow(() -> new NotFoundException("No hostname found for job - " + id));
            } catch (NotFoundException e) {
                throw new GenieServerException("Failed to route request", e);
            }

            final boolean shouldForward = !this.hostname.equals(jobHostname);
            final boolean canForward = forwardedFrom == null && this.jobsProperties.getForwarding().isEnabled();

            if (shouldForward && canForward) {
                // Forward request to another node
                forwardRequest(id, path, jobHostname, request, response);
                return;
            } else if (!canForward && shouldForward) {
                // Should forward but can't
                throw new GenieServerException("Job files are not local, but forwarding is disabled");
            }
        }

        // In any other case, delegate the request to the service
        log.debug("Fetching requested resource \"{}\" for job \"{}\"", path, id);
        this.jobDirectoryServerService.serveResource(id, baseUrl, path, request, response);
    }