Skip to content

Proxy download from Mesos slave over Singularity. #1817

Merged
ssalinas merged 6 commits into
masterfrom
file_download_proxy
Aug 1, 2018
Merged

Proxy download from Mesos slave over Singularity. #1817
ssalinas merged 6 commits into
masterfrom
file_download_proxy

Conversation

@kdorosh

@kdorosh kdorosh commented Jul 11, 2018

Copy link
Copy Markdown
Contributor

Solves problem of being on different network than Mesos slave. Directly proxying through a configurable load balancer can still be looked into.

@Path("/download/{httpPrefix}/{slaveHostname}/port/{port}/path/{path}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Operation(summary = "Proxy a file download from a Mesos Slave through Singularity")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a GET, it shouldn't consume anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-- whoops -- left this there from when I had it as a POST

@Parameter(required = true, description = "Full file path to file on Mesos slave to be downloaded") @PathParam("path") String fileFullPath
) {

Client client = ClientBuilder.newClient();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we want to inject & use the AsyncHttpClient here instead of using a JAX-RS client, similarly to

Response response = asyncHttpClient
.prepareGet(String.format("http://%s:5051/files/browse", slaveHostname))
.setPerRequestConfig(timeoutConfig)
.addQueryParameter("path", fullPath)
.execute()
.get();
.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah neat, will do. We already have one being injected too which is awesome since creating these clients are expensive operations.

file.downloadLink = `${httpPrefix}://${files.slaveHostname}:${httpPort}/files/download.json?path=${file.fullPath}`;
file.fullPath = encodeURIComponent(`${files.fullPathToRoot}/${files.currentDirectory}/${file.name}`);

file.downloadLink = `${config.apiRoot}/tasks/download/${httpPrefix}/${files.slaveHostname}/port/${httpPort}/path/${file.fullPath}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of httpPrefix is based on the Singularity configuration, so we shouldn't need to send this as a parameter to the backend (since the backend also has access to that configuration and knows whether the slave communicates over HTTP or HTTPS and which port it's listening on).

}

@GET
@Path("/download/{httpPrefix}/{slaveHostname}/port/{port}/path/{path}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of a nit, but a better API design here could be something like GET /download?slaveHostname=x&path=y (since the actual resource being retrieved is a download). The rest of our API doesn't stick to these guidelines religiously, though, so probably not a huge deal. I'll let @ssalinas weigh in as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have them both as PathParams instead of QueryParams since both the slave hostname and the path are both required fields? I did change the URL a bit to better match entity class hierarchy standards. See top answer and comments on this StackOverflow post.

@kdorosh

kdorosh commented Jul 13, 2018

Copy link
Copy Markdown
Contributor Author

This was merged into hs_staging and hs_qa yesterday, 7/12/18.

@ssalinas

Copy link
Copy Markdown
Contributor

🚢

@ssalinas ssalinas added this to the 0.21.0 milestone Jul 16, 2018
@ssalinas ssalinas merged commit 4c119da into master Aug 1, 2018
@ssalinas ssalinas deleted the file_download_proxy branch August 1, 2018 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants