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

chore(recordings): replace subdirectory with jvmId in fromPathHandler #1692

Merged
merged 8 commits into from
Oct 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivePathException;
Expand All @@ -40,17 +41,20 @@

public class RecordingDeleteFromPathHandler extends AbstractV2RequestHandler<Void> {

static final String PATH = "fs/recordings/:subdirectoryName/:recordingName";
static final String PATH = "fs/recordings/:jvmId/:recordingName";

private final RecordingArchiveHelper recordingArchiveHelper;
private final JvmIdHelper jvmIdHelper;

@Inject
RecordingDeleteFromPathHandler(
AuthManager auth,
CredentialsManager credentialsManager,
Gson gson,
JvmIdHelper jvmIdHelper,
RecordingArchiveHelper recordingArchiveHelper) {
super(auth, credentialsManager, gson);
this.jvmIdHelper = jvmIdHelper;
this.recordingArchiveHelper = recordingArchiveHelper;
}

Expand Down Expand Up @@ -91,9 +95,10 @@ public boolean isAsync() {

@Override
public IntermediateResponse<Void> handle(RequestParameters params) throws Exception {
String subdirectoryName = params.getPathParams().get("subdirectoryName");
String recordingName = params.getPathParams().get("recordingName");
String jvmId = params.getPathParams().get("jvmId");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
recordingArchiveHelper.deleteRecordingFromPath(subdirectoryName, recordingName).get();
return new IntermediateResponse<Void>().body(null);
} catch (ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.cryostat.net.web.http.api.ApiVersion;
import io.cryostat.net.web.http.api.v2.AbstractAssetJwtConsumingHandler;
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivePathException;
Expand All @@ -44,8 +45,9 @@

public class RecordingGetFromPathWithJwtHandler extends AbstractAssetJwtConsumingHandler {

static final String PATH = "fs/recordings/:subdirectoryName/:recordingName/jwt";
static final String PATH = "fs/recordings/:jvmId/:recordingName/jwt";

private final JvmIdHelper jvmIdHelper;
private final RecordingArchiveHelper recordingArchiveHelper;

@Inject
Expand All @@ -54,9 +56,11 @@ public class RecordingGetFromPathWithJwtHandler extends AbstractAssetJwtConsumin
CredentialsManager credentialsManager,
AssetJwtHelper jwtFactory,
Lazy<WebServer> webServer,
JvmIdHelper jvmIdHelper,
RecordingArchiveHelper recordingArchiveHelper,
Logger logger) {
super(auth, credentialsManager, jwtFactory, webServer, logger);
this.jvmIdHelper = jvmIdHelper;
this.recordingArchiveHelper = recordingArchiveHelper;
}

Expand Down Expand Up @@ -87,9 +91,10 @@ public boolean isAsync() {

@Override
public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception {
String subdirectoryName = ctx.pathParam("subdirectoryName");
String jvmId = ctx.pathParam("jvmId");
String recordingName = ctx.pathParam("recordingName");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
Path archivedRecording =
recordingArchiveHelper
.getRecordingPathFromPath(subdirectoryName, recordingName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingMetadataManager;
import io.cryostat.recordings.RecordingMetadataManager.Metadata;
Expand All @@ -41,21 +42,24 @@

public class RecordingMetadataLabelsPostFromPathHandler extends AbstractV2RequestHandler<Metadata> {

static final String PATH = "fs/recordings/:subdirectoryName/:recordingName/metadata/labels";
static final String PATH = "fs/recordings/:jvmId/:recordingName/metadata/labels";

private final RecordingArchiveHelper recordingArchiveHelper;
private final RecordingMetadataManager recordingMetadataManager;
private final JvmIdHelper jvmIdHelper;

@Inject
RecordingMetadataLabelsPostFromPathHandler(
AuthManager auth,
CredentialsManager credentialsManager,
Gson gson,
JvmIdHelper jvmIdHelper,
RecordingArchiveHelper recordingArchiveHelper,
RecordingMetadataManager recordingMetadataManager) {
super(auth, credentialsManager, gson);
this.recordingArchiveHelper = recordingArchiveHelper;
this.recordingMetadataManager = recordingMetadataManager;
this.jvmIdHelper = jvmIdHelper;
}

@Override
Expand Down Expand Up @@ -96,9 +100,9 @@ public boolean requiresAuthentication() {
@Override
public IntermediateResponse<Metadata> handle(RequestParameters params) throws Exception {
String recordingName = params.getPathParams().get("recordingName");
String subdirectoryName = params.getPathParams().get("subdirectoryName");

String jvmId = params.getPathParams().get("jvmId");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
Metadata metadata =
new Metadata(recordingMetadataManager.parseRecordingLabels(params.getBody()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivePathException;
Expand All @@ -56,11 +57,12 @@

class RecordingUploadPostFromPathHandler extends AbstractV2RequestHandler<String> {

static final String PATH = "fs/recordings/:subdirectoryName/:recordingName/upload";
static final String PATH = "fs/recordings/:jvmId/:recordingName/upload";

private final Environment env;
private final long httpTimeoutSeconds;
private final WebClient webClient;
private final JvmIdHelper jvmIdHelper;
private final RecordingArchiveHelper recordingArchiveHelper;

@Inject
Expand All @@ -70,12 +72,14 @@ class RecordingUploadPostFromPathHandler extends AbstractV2RequestHandler<String
Environment env,
@Named(HttpModule.HTTP_REQUEST_TIMEOUT_SECONDS) long httpTimeoutSeconds,
WebClient webClient,
JvmIdHelper jvmIdHelper,
RecordingArchiveHelper recordingArchiveHelper,
Gson gson) {
super(auth, credentialsManager, gson);
this.env = env;
this.httpTimeoutSeconds = httpTimeoutSeconds;
this.webClient = webClient;
this.jvmIdHelper = jvmIdHelper;
this.recordingArchiveHelper = recordingArchiveHelper;
}

Expand Down Expand Up @@ -116,9 +120,10 @@ public boolean isAsync() {

@Override
public IntermediateResponse<String> handle(RequestParameters params) throws Exception {
String subdirectoryName = params.getPathParams().get("subdirectoryName");
String recordingName = params.getPathParams().get("recordingName");
String jvmId = params.getPathParams().get("jvmId");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
URL uploadUrl = new URL(env.getEnv(Variables.GRAFANA_DATASOURCE_ENV));
boolean isValidUploadUrl =
new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS).isValid(uploadUrl.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivePathException;

Expand All @@ -47,8 +48,9 @@

public class ReportGetFromPathHandler extends AbstractV2RequestHandler<Path> {

static final String PATH = "fs/reports/:subdirectoryName/:recordingName";
static final String PATH = "fs/reports/:jvmId/:recordingName";

private final JvmIdHelper jvmIdHelper;
private final ReportService reportService;
private final long reportGenerationTimeoutSeconds;

Expand All @@ -57,10 +59,12 @@ public class ReportGetFromPathHandler extends AbstractV2RequestHandler<Path> {
AuthManager auth,
CredentialsManager credentialsManager,
Gson gson,
JvmIdHelper jvmIdHelper,
ReportService reportService,
@Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS)
long reportGenerationTimeoutSeconds) {
super(auth, credentialsManager, gson);
this.jvmIdHelper = jvmIdHelper;
this.reportService = reportService;
this.reportGenerationTimeoutSeconds = reportGenerationTimeoutSeconds;
}
Expand Down Expand Up @@ -105,9 +109,10 @@ public boolean isAsync() {

@Override
public IntermediateResponse<Path> handle(RequestParameters params) throws Exception {
String subdirectoryName = params.getPathParams().get("subdirectoryName");
String jvmId = params.getPathParams().get("jvmId");
String recordingName = params.getPathParams().get("recordingName");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
List<String> queriedFilter = params.getQueryParams().getAll("filter");
String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0);
Path report =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import io.cryostat.net.web.http.api.ApiVersion;
import io.cryostat.net.web.http.api.v2.AbstractAssetJwtConsumingHandler;
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivePathException;
Expand All @@ -51,22 +52,25 @@

class ReportGetFromPathWithJwtHandler extends AbstractAssetJwtConsumingHandler {

static final String PATH = "fs/reports/:subdirectoryName/:recordingName/jwt";
static final String PATH = "fs/reports/:jvmId/:recordingName/jwt";

private final ReportService reportService;
private final long generationTimeoutSeconds;
private final JvmIdHelper jvmIdHelper;

@Inject
ReportGetFromPathWithJwtHandler(
AuthManager auth,
CredentialsManager credentialsManager,
AssetJwtHelper jwtFactory,
Lazy<WebServer> webServer,
JvmIdHelper jvmIdHelper,
ReportService reportService,
RecordingArchiveHelper recordingArchiveHelper,
@Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds,
Logger logger) {
super(auth, credentialsManager, jwtFactory, webServer, logger);
this.jvmIdHelper = jvmIdHelper;
this.reportService = reportService;
this.generationTimeoutSeconds = generationTimeoutSeconds;
}
Expand Down Expand Up @@ -111,9 +115,10 @@ public boolean isOrdered() {

@Override
public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception {
String subdirectoryName = ctx.pathParam("subdirectoryName");
String jvmId = ctx.pathParam("jvmId");
String recordingName = ctx.pathParam("recordingName");
try {
String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId);
List<String> queriedFilter = ctx.queryParam("filter");
String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0);
Path report =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,7 @@ public Future<List<ArchiveDirectory>> getRecordingsAndDirectories() {
"beta/recordings",
"beta/fs/recordings"),
webServer
.getArchivedReportURL(
subdirectoryName, file)
.getArchivedReportURL(jvmId, file)
.replace(
"beta/reports",
"beta/fs/reports"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.cryostat.net.web.http.api.v2.ApiException;
import io.cryostat.net.web.http.api.v2.IntermediateResponse;
import io.cryostat.net.web.http.api.v2.RequestParameters;
import io.cryostat.recordings.JvmIdHelper;
import io.cryostat.recordings.RecordingArchiveHelper;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.rules.ArchivedRecordingInfo;
Expand All @@ -56,13 +57,14 @@ class RecordingDeleteFromPathHandlerTest {
@Mock AuthManager auth;
@Mock CredentialsManager credentialsManager;
@Mock Gson gson;
@Mock JvmIdHelper jvmIdHelper;
@Mock RecordingArchiveHelper recordingArchiveHelper;

@BeforeEach
void setup() {
this.handler =
new RecordingDeleteFromPathHandler(
auth, credentialsManager, gson, recordingArchiveHelper);
auth, credentialsManager, gson, jvmIdHelper, recordingArchiveHelper);
}

@Nested
Expand Down Expand Up @@ -94,7 +96,7 @@ void shouldHaveExpectedRequiredPermissions() {
void shouldHandleCorrectPath() {
MatcherAssert.assertThat(
handler.path(),
Matchers.equalTo("/api/beta/fs/recordings/:subdirectoryName/:recordingName"));
Matchers.equalTo("/api/beta/fs/recordings/:jvmId/:recordingName"));
}

@Test
Expand All @@ -117,14 +119,12 @@ class Behaviour {
@Test
void shouldThrow404IfNoMatchingRecordingFound() throws Exception {
String recordingName = "someRecording";
String jvmId = "id";
String subdirectoryName = "someSubdirectory";

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"subdirectoryName",
subdirectoryName,
"recordingName",
recordingName));
.thenReturn(Map.of("jvmId", jvmId, "recordingName", recordingName));

Future<ArchivedRecordingInfo> future =
CompletableFuture.failedFuture(
Expand All @@ -141,14 +141,12 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception {
@Test
void shouldHandleSuccessfulDELETERequest() throws Exception {
String recordingName = "someRecording";
String jvmId = "id";
String subdirectoryName = "someSubdirectory";

when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName);
when(params.getPathParams())
.thenReturn(
Map.of(
"recordingName",
recordingName,
"subdirectoryName",
subdirectoryName));
.thenReturn(Map.of("recordingName", recordingName, "jvmId", jvmId));

CompletableFuture<ArchivedRecordingInfo> future = Mockito.mock(CompletableFuture.class);
when(recordingArchiveHelper.deleteRecordingFromPath(
Expand Down
Loading
Loading