Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datasource): enable overwrite and use hardcoded filename #1354

Merged
merged 3 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/io/cryostat/net/web/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class WebServer extends AbstractVerticle {

// Use X- prefix so as to not trigger web-browser auth dialogs
public static final String AUTH_SCHEME_HEADER = "X-WWW-Authenticate";
public static final String DATASOURCE_FILENAME = "cryostat-analysis.jfr";

private final HttpServer server;
private final NetworkConfiguration netConf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import io.cryostat.core.sys.Environment;
import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.HttpModule;
import io.cryostat.net.web.http.api.ApiVersion;
Expand Down Expand Up @@ -188,13 +189,14 @@ private ResponseMessage doPost(String subdirectoryName, String recordingName, UR
MultipartForm.create()
.binaryFileUpload(
"file",
recordingName,
WebServer.DATASOURCE_FILENAME,
recordingPath.toString(),
HttpMimeType.OCTET_STREAM.toString());

CompletableFuture<ResponseMessage> future = new CompletableFuture<>();
webClient
.postAbs(uploadUrl.toURI().resolve("/load").normalize().toString())
.addQueryParam("overwrite", "true")
.timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds))
.sendMultipartForm(
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import io.cryostat.core.sys.Environment;
import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.HttpModule;
import io.cryostat.net.web.http.api.ApiVersion;
Expand Down Expand Up @@ -188,13 +189,14 @@ private ResponseMessage doPost(String sourceTarget, String recordingName, URL up
MultipartForm.create()
.binaryFileUpload(
"file",
recordingName,
WebServer.DATASOURCE_FILENAME,
recordingPath.toString(),
HttpMimeType.OCTET_STREAM.toString());

CompletableFuture<ResponseMessage> future = new CompletableFuture<>();
webClient
.postAbs(uploadUrl.toURI().resolve("/load").normalize().toString())
.addQueryParam("overwrite", "true")
.timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds))
.sendMultipartForm(
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import io.cryostat.net.AuthManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.DeprecatedApi;
import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.HttpModule;
Expand Down Expand Up @@ -179,13 +180,14 @@ private ResponseMessage doPost(String recordingName, URL uploadUrl) throws Excep
MultipartForm.create()
.binaryFileUpload(
"file",
recordingName,
WebServer.DATASOURCE_FILENAME,
recordingPath.toString(),
HttpMimeType.OCTET_STREAM.toString());

CompletableFuture<ResponseMessage> future = new CompletableFuture<>();
webClient
.postAbs(uploadUrl.toURI().resolve("/load").normalize().toString())
.addQueryParam("overwrite", "true")
.timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds))
.sendMultipartForm(
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import io.cryostat.net.AuthManager;
import io.cryostat.net.TargetConnectionManager;
import io.cryostat.net.security.ResourceAction;
import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.web.http.HttpModule;
Expand Down Expand Up @@ -185,14 +186,15 @@ private ResponseMessage doPost(RoutingContext ctx, URL uploadUrl) throws Excepti
MultipartForm.create()
.binaryFileUpload(
"file",
recordingName,
WebServer.DATASOURCE_FILENAME,
recordingPath.toString(),
HttpMimeType.OCTET_STREAM.toString());

CompletableFuture<ResponseMessage> future = new CompletableFuture<>();
try {
webClient
.postAbs(uploadUrl.toURI().resolve("/load").normalize().toString())
.addQueryParam("overwrite", "true")
.timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds))
.sendMultipartForm(
form,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ void shouldDoUpload() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -275,6 +277,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception {
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
@Override
Expand Down Expand Up @@ -333,6 +337,8 @@ void shouldHandleNullStatusMessage() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -392,6 +398,8 @@ void shouldHandleNullResponseBody() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ void shouldDoUpload() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -264,6 +266,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -320,6 +324,8 @@ void shouldHandleNullStatusMessage() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -376,6 +382,8 @@ void shouldHandleNullResponseBody() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ void shouldDoUpload() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -251,6 +253,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -316,6 +320,8 @@ void shouldHandleNullStatusMessage() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -374,6 +380,8 @@ void shouldHandleNullResponseBody() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ void shouldDoUpload() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -301,6 +303,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -373,6 +377,8 @@ void shouldHandleNullStatusMessage() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down Expand Up @@ -445,6 +451,8 @@ void shouldHandleNullResponseBody() throws Exception {
HttpRequest<Buffer> httpReq = Mockito.mock(HttpRequest.class);
HttpResponse<Buffer> httpResp = Mockito.mock(HttpResponse.class);
Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq);
Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString()))
.thenReturn(httpReq);
Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq);
Mockito.doAnswer(
new Answer<Void>() {
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/itest/UploadRecordingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import io.cryostat.net.web.WebServer;
import io.cryostat.net.web.http.HttpMimeType;

import io.vertx.core.MultiMap;
Expand Down Expand Up @@ -131,7 +132,9 @@ public void shouldLoadRecordingToDatasource() throws Exception {
});

final String expectedUploadResponse =
String.format("Uploaded: %s\nSet: %s", RECORDING_NAME, RECORDING_NAME);
String.format(
"Uploaded: %s\nSet: %s",
WebServer.DATASOURCE_FILENAME, WebServer.DATASOURCE_FILENAME);

MatcherAssert.assertThat(
uploadRespFuture.get().trim(), Matchers.equalTo(expectedUploadResponse));
Expand All @@ -154,7 +157,7 @@ public void shouldLoadRecordingToDatasource() throws Exception {

MatcherAssert.assertThat(
getRespFuture.get().trim(),
Matchers.equalTo(String.format("**%s**", RECORDING_NAME)));
Matchers.equalTo(String.format("**%s**", WebServer.DATASOURCE_FILENAME)));

// Query Data Source for recording metrics
final CompletableFuture<JsonArray> queryRespFuture = new CompletableFuture<>();
Expand Down