From 6934b0bd6d3bbaaeab3795bf2e63dd0ecd85cb83 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Thu, 26 Oct 2023 15:56:01 -0400 Subject: [PATCH] tmp --- .../net/reports/ArchivedRecordingReportCache.java | 7 ++++++- .../cryostat/recordings/RecordingArchiveHelper.java | 13 ++++++++----- .../recordings/RecordingMetadataManager.java | 9 +++++---- ...ordingMetadataLabelsPostFromPathHandlerTest.java | 3 ++- .../java/itest/FileSystemArchivedRequestsIT.java | 5 +++++ 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java b/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java index 8924774155..6462793ee4 100644 --- a/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java +++ b/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java @@ -26,12 +26,14 @@ import io.cryostat.core.log.Logger; import io.cryostat.core.sys.FileSystem; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingArchiveHelper; class ArchivedRecordingReportCache { protected final FileSystem fs; protected final Provider reportGeneratorServiceProvider; + protected final JvmIdHelper jvmIdHelper; protected final RecordingArchiveHelper recordingArchiveHelper; protected final long generationTimeoutSeconds; protected final Logger logger; @@ -39,11 +41,13 @@ class ArchivedRecordingReportCache { ArchivedRecordingReportCache( FileSystem fs, Provider reportGeneratorServiceProvider, + JvmIdHelper jvmIdHelper, RecordingArchiveHelper recordingArchiveHelper, @Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds, Logger logger) { this.fs = fs; this.reportGeneratorServiceProvider = reportGeneratorServiceProvider; + this.jvmIdHelper = jvmIdHelper; this.recordingArchiveHelper = recordingArchiveHelper; this.generationTimeoutSeconds = generationTimeoutSeconds; this.logger = logger; @@ -53,9 +57,10 @@ Future getFromPath(String jvmId, String recordingName, String filter) { CompletableFuture f = new CompletableFuture<>(); Path dest = null; try { + String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); dest = recordingArchiveHelper - .getCachedReportPathFromPath(jvmId, recordingName, filter) + .getCachedReportPathFromPath(subdirectoryName, recordingName, filter) .get(); if (fs.isReadable(dest) && fs.isRegularFile(dest)) { f.complete(dest); diff --git a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java index ce94de1ef7..e598c588b1 100644 --- a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java @@ -432,8 +432,10 @@ public Future saveRecording( public Future deleteRecordingFromPath( String jvmId, String recordingName) { CompletableFuture future = new CompletableFuture<>(); + String subdirectoryName = null; try { - Path subdirectoryPath = archivedRecordingsPath.resolve(jvmId); + subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); + Path subdirectoryPath = archivedRecordingsPath.resolve(subdirectoryName); Path recordingPath = subdirectoryPath.resolve(recordingName); validateSavePath(recordingName, recordingPath); Path filenamePath = recordingPath.getFileName(); @@ -574,10 +576,10 @@ public boolean deleteReports(String jvmId, String recordingName) { } public Future getCachedReportPathFromPath( - String jvmId, String recordingName, String filter) { + String subdirectoryName, String recordingName, String filter) { CompletableFuture future = new CompletableFuture<>(); try { - Path tempSubdirectory = archivedRecordingsReportPath.resolve(jvmId); + Path tempSubdirectory = archivedRecordingsReportPath.resolve(subdirectoryName); if (!fs.exists(tempSubdirectory)) { tempSubdirectory = fs.createDirectory(tempSubdirectory); } @@ -790,8 +792,9 @@ public Future> getRecordings() { public Future getRecordingPathFromPath(String jvmId, String recordingName) { try { - boolean checkConnectUrl = !jvmIdHelper.isSpecialDirectory(jvmId); - Path path = archivedRecordingsPath.resolve(jvmId).resolve(recordingName); + String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); + boolean checkConnectUrl = !jvmIdHelper.isSpecialDirectory(subdirectoryName); + Path path = archivedRecordingsPath.resolve(subdirectoryName).resolve(recordingName); validateRecordingPath(Optional.of(path), recordingName, checkConnectUrl); return CompletableFuture.completedFuture(path); } catch (RecordingNotFoundException | ArchivePathException e) { diff --git a/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java b/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java index a1fd980b0c..4a12f5f72a 100644 --- a/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java +++ b/src/main/java/io/cryostat/recordings/RecordingMetadataManager.java @@ -493,18 +493,19 @@ private void pruneStaleMetadata(Map staleMetadata } public Future setRecordingMetadataFromPath( - String jvmId, String recordingName, Metadata metadata) + String subdirectoryName, String recordingName, Metadata metadata) throws IOException, InterruptedException, ExecutionException { - Objects.requireNonNull(jvmId); + Objects.requireNonNull(subdirectoryName); Objects.requireNonNull(recordingName); Objects.requireNonNull(metadata); String connectUrl = this.archiveHelperProvider .get() - .getConnectUrlFromPath(archivedRecordingsPath.resolve(jvmId)) + .getConnectUrlFromPath(archivedRecordingsPath.resolve(subdirectoryName)) .get(); + String jvmId = jvmIdHelper.subdirectoryNameToJvmId(subdirectoryName); - Path metadataPath = this.getMetadataPath(jvmId, recordingName); + Path metadataPath = this.getMetadataPath(subdirectoryName, recordingName); fs.writeString( metadataPath, gson.toJson(StoredRecordingMetadata.of(connectUrl, jvmId, recordingName, metadata)), diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java index ea4da01a2b..ac1bc9b0d1 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java @@ -140,6 +140,7 @@ class Behaviour { void shouldUpdateLabels() throws Exception { String recordingName = "someRecording"; String jvmId = "id"; + String subdirectoryName = "foo"; Map labels = Map.of("key", "value"); Metadata metadata = new Metadata(labels); String requestLabels = labels.toString(); @@ -156,7 +157,7 @@ void shouldUpdateLabels() throws Exception { when(recordingMetadataManager.parseRecordingLabels(requestLabels)).thenReturn(labels); when(recordingMetadataManager.setRecordingMetadataFromPath( - jvmId, recordingName, metadata)) + subdirectoryName, recordingName, metadata)) .thenReturn(CompletableFuture.completedFuture(metadata)); IntermediateResponse response = handler.handle(requestParameters); diff --git a/src/test/java/itest/FileSystemArchivedRequestsIT.java b/src/test/java/itest/FileSystemArchivedRequestsIT.java index 1dbe7c595f..86e03598fe 100644 --- a/src/test/java/itest/FileSystemArchivedRequestsIT.java +++ b/src/test/java/itest/FileSystemArchivedRequestsIT.java @@ -46,6 +46,7 @@ public class FileSystemArchivedRequestsIT extends JwtAssetsSelfTest { private static final Gson gson = MainModule.provideGson(Logger.INSTANCE); + private static final Logger logger = Logger.INSTANCE; static final String TEST_RECORDING_NAME = "FileSystemArchivedRequestsIT"; @@ -131,6 +132,8 @@ void testGetRecordingsAndDirectories() throws Exception { MatcherAssert.assertThat(updatedDirRecordings.size(), Matchers.equalTo(1)); JsonObject updatedArchivedRecording = updatedDirRecordings.getJsonObject(0); + logger.info("jvmId: {}", updatedArchivedRecording.getString("jvmId")); + logger.info("other jvmId: {}", jvmId); MatcherAssert.assertThat( updatedArchivedRecording.getString("name"), Matchers.equalTo(archivedRecording.getString("name"))); @@ -179,6 +182,8 @@ void testGetRecordingsAndDirectories() throws Exception { .replaceFirst( "/api/v1/recordings", String.format("/api/beta/fs/recordings/%s", jvmId)); + logger.info("oldPath: {}", archivedResource.getPath()); + logger.info("path: {}", updatedArchivedPath); cleanupCreatedResources(updatedArchivedPath); } if (assetDownload != null) {