Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Oct 26, 2023
1 parent 1f94ac0 commit 6934b0b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@

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<ReportGeneratorService> reportGeneratorServiceProvider;
protected final JvmIdHelper jvmIdHelper;
protected final RecordingArchiveHelper recordingArchiveHelper;
protected final long generationTimeoutSeconds;
protected final Logger logger;

ArchivedRecordingReportCache(
FileSystem fs,
Provider<ReportGeneratorService> 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;
Expand All @@ -53,9 +57,10 @@ Future<Path> getFromPath(String jvmId, String recordingName, String filter) {
CompletableFuture<Path> 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);
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,10 @@ public Future<ArchivedRecordingInfo> saveRecording(
public Future<ArchivedRecordingInfo> deleteRecordingFromPath(
String jvmId, String recordingName) {
CompletableFuture<ArchivedRecordingInfo> 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();
Expand Down Expand Up @@ -574,10 +576,10 @@ public boolean deleteReports(String jvmId, String recordingName) {
}

public Future<Path> getCachedReportPathFromPath(
String jvmId, String recordingName, String filter) {
String subdirectoryName, String recordingName, String filter) {
CompletableFuture<Path> future = new CompletableFuture<>();
try {
Path tempSubdirectory = archivedRecordingsReportPath.resolve(jvmId);
Path tempSubdirectory = archivedRecordingsReportPath.resolve(subdirectoryName);
if (!fs.exists(tempSubdirectory)) {
tempSubdirectory = fs.createDirectory(tempSubdirectory);
}
Expand Down Expand Up @@ -790,8 +792,9 @@ public Future<List<ArchivedRecordingInfo>> getRecordings() {

public Future<Path> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,19 @@ private void pruneStaleMetadata(Map<StoredRecordingMetadata, Path> staleMetadata
}

public Future<Metadata> 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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class Behaviour {
void shouldUpdateLabels() throws Exception {
String recordingName = "someRecording";
String jvmId = "id";
String subdirectoryName = "foo";
Map<String, String> labels = Map.of("key", "value");
Metadata metadata = new Metadata(labels);
String requestLabels = labels.toString();
Expand All @@ -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<Metadata> response = handler.handle(requestParameters);
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/itest/FileSystemArchivedRequestsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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")));
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6934b0b

Please sign in to comment.