From 29ddfc27738fe5ecc5a9a479f45453ba502211b6 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 28 Sep 2023 09:30:29 -0400 Subject: [PATCH] chore(reports): remove HTML report generation (#1685) * remove HTML-based rules report generation * remove JFR event --- pom.xml | 2 +- .../io/cryostat/configuration/Variables.java | 1 - .../AbstractReportGeneratorService.java | 5 +- .../reports/ActiveRecordingReportCache.java | 80 +++------ .../reports/ArchivedRecordingReportCache.java | 18 +- .../net/reports/RemoteReportGenerator.java | 5 +- .../net/reports/ReportGeneratorService.java | 6 +- .../cryostat/net/reports/ReportService.java | 26 ++- .../net/reports/ReportTransformerModule.java | 34 ---- .../cryostat/net/reports/ReportsModule.java | 13 +- .../reports/SubprocessReportGenerator.java | 156 ++---------------- .../api/beta/ReportGetFromPathHandler.java | 9 +- .../beta/ReportGetFromPathWithJwtHandler.java | 11 +- .../web/http/api/beta/ReportGetHandler.java | 9 +- .../api/beta/ReportGetWithJwtHandler.java | 11 +- .../net/web/http/api/v1/ReportGetHandler.java | 2 +- .../http/api/v1/TargetReportGetHandler.java | 12 +- .../net/web/http/api/v2/ReportGetHandler.java | 2 +- .../http/api/v2/TargetReportGetHandler.java | 12 +- .../recordings/RecordingArchiveHelper.java | 11 +- .../recordings/RecordingTargetHelper.java | 4 +- .../ActiveRecordingReportCacheTest.java | 61 +++---- .../ArchivedRecordingReportCacheTest.java | 67 +++----- .../SubprocessReportGeneratorTest.java | 115 ++----------- .../beta/ReportGetFromPathHandlerTest.java | 37 ++--- .../ReportGetFromPathWithJwtHandlerTest.java | 44 ++--- .../http/api/beta/ReportGetHandlerTest.java | 41 ++--- .../api/beta/ReportGetWithJwtHandlerTest.java | 44 ++--- .../web/http/api/v1/ReportGetHandlerTest.java | 16 +- .../api/v1/TargetReportGetHandlerTest.java | 43 ++--- .../web/http/api/v2/ReportGetHandlerTest.java | 19 +-- .../api/v2/TargetReportGetHandlerTest.java | 36 ++-- .../recordings/RecordingTargetHelperTest.java | 10 +- .../itest/ArchivedReportJwtDownloadIT.java | 4 +- .../itest/FileSystemArchivedRequestsIT.java | 6 +- src/test/java/itest/RecordingWorkflowIT.java | 25 +-- src/test/java/itest/ReportIT.java | 80 +++------ src/test/java/itest/ReportJwtDownloadIT.java | 4 +- src/test/java/itest/TargetReportIT.java | 86 +++------- 39 files changed, 312 insertions(+), 855 deletions(-) delete mode 100644 src/main/java/io/cryostat/net/reports/ReportTransformerModule.java diff --git a/pom.xml b/pom.xml index 11c5d6d7f7..57815d0142 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ 2.47 ${com.google.dagger.version} - 2.22.0 + 2.23.0 15.4 3.12.0 diff --git a/src/main/java/io/cryostat/configuration/Variables.java b/src/main/java/io/cryostat/configuration/Variables.java index b743da95e8..49c056642c 100644 --- a/src/main/java/io/cryostat/configuration/Variables.java +++ b/src/main/java/io/cryostat/configuration/Variables.java @@ -26,7 +26,6 @@ private Variables() {} // report generation public static final String REPORT_GENERATOR_ENV = "CRYOSTAT_REPORT_GENERATOR"; public static final String SUBPROCESS_MAX_HEAP_ENV = "CRYOSTAT_REPORT_GENERATION_MAX_HEAP"; - public static final String REPORT_STATS_PATH = "CRYOSTAT_REPORT_STATS_PATH"; public static final String ACTIVE_REPORTS_CACHE_EXPIRY_ENV = "CRYOSTAT_ACTIVE_REPORTS_CACHE_EXPIRY_SECONDS"; public static final String ACTIVE_REPORTS_CACHE_REFRESH_ENV = diff --git a/src/main/java/io/cryostat/net/reports/AbstractReportGeneratorService.java b/src/main/java/io/cryostat/net/reports/AbstractReportGeneratorService.java index a29eff0596..f0d19a52f7 100644 --- a/src/main/java/io/cryostat/net/reports/AbstractReportGeneratorService.java +++ b/src/main/java/io/cryostat/net/reports/AbstractReportGeneratorService.java @@ -50,15 +50,14 @@ protected AbstractReportGeneratorService( @Override public final CompletableFuture exec( - RecordingDescriptor recordingDescriptor, String filter, boolean formatted) - throws Exception { + RecordingDescriptor recordingDescriptor, String filter) throws Exception { Path recording = getRecordingFromLiveTarget( recordingDescriptor.recordingName, recordingDescriptor.connectionDescriptor); Path saveFile = fs.createTempFile(null, null); - CompletableFuture cf = exec(recording, saveFile, filter, formatted); + CompletableFuture cf = exec(recording, saveFile, filter); return cf.whenComplete( (p, t) -> { try { diff --git a/src/main/java/io/cryostat/net/reports/ActiveRecordingReportCache.java b/src/main/java/io/cryostat/net/reports/ActiveRecordingReportCache.java index f1ffb120dd..b75a2abba5 100644 --- a/src/main/java/io/cryostat/net/reports/ActiveRecordingReportCache.java +++ b/src/main/java/io/cryostat/net/reports/ActiveRecordingReportCache.java @@ -45,8 +45,7 @@ class ActiveRecordingReportCache implements NotificationListener> { protected final Provider reportGeneratorServiceProvider; protected final FileSystem fs; - protected final LoadingCache htmlCache; - protected final LoadingCache jsonCache; + protected final LoadingCache cache; protected final TargetConnectionManager targetConnectionManager; protected final long generationTimeoutSeconds; protected final long cacheExpirySeconds; @@ -71,105 +70,66 @@ class ActiveRecordingReportCache implements NotificationListener getReport(k, true)); - this.jsonCache = + this.cache = Caffeine.newBuilder() .scheduler(Scheduler.systemScheduler()) .expireAfterWrite(cacheExpirySeconds, TimeUnit.SECONDS) .refreshAfterWrite(cacheRefreshSeconds, TimeUnit.SECONDS) .softValues() - .build((k) -> getReport(k, false)); + .build(this::getReport); } Future get( - ConnectionDescriptor connectionDescriptor, - String recordingName, - String filter, - boolean formatted) { + ConnectionDescriptor connectionDescriptor, String recordingName, String filter) { CompletableFuture f = new CompletableFuture<>(); try { - if (formatted) { - if (filter.isBlank()) { - f.complete( - htmlCache.get( - new RecordingDescriptor(connectionDescriptor, recordingName))); - } else { - f.complete( - getReport( - new RecordingDescriptor(connectionDescriptor, recordingName), - filter, - true)); - } + if (filter.isBlank()) { + f.complete(cache.get(new RecordingDescriptor(connectionDescriptor, recordingName))); } else { - if (filter.isBlank()) { - f.complete( - jsonCache.get( - new RecordingDescriptor(connectionDescriptor, recordingName))); - } else { - f.complete( - getReport( - new RecordingDescriptor(connectionDescriptor, recordingName), - filter, - false)); - } + f.complete( + getReport( + new RecordingDescriptor(connectionDescriptor, recordingName), + filter)); } - } catch (Exception e) { f.completeExceptionally(e); } return f; } - boolean delete( - ConnectionDescriptor connectionDescriptor, String recordingName, boolean formatted) { + boolean delete(ConnectionDescriptor connectionDescriptor, String recordingName) { RecordingDescriptor key = new RecordingDescriptor(connectionDescriptor, recordingName); - boolean hasKey = - formatted ? htmlCache.asMap().containsKey(key) : jsonCache.asMap().containsKey(key); + boolean hasKey = cache.asMap().containsKey(key); if (hasKey) { logger.trace("Invalidated active report cache for {}", recordingName); - if (formatted) { - htmlCache.invalidate(key); - } else { - jsonCache.invalidate(key); - } + cache.invalidate(key); } else { logger.trace("No cache entry for {} to invalidate", recordingName); } return hasKey; } - protected String getReport(RecordingDescriptor recordingDescriptor, boolean formatted) - throws Exception { - return getReport(recordingDescriptor, EMPTY_FILTERS, formatted); + protected String getReport(RecordingDescriptor recordingDescriptor) throws Exception { + return getReport(recordingDescriptor, EMPTY_FILTERS); } - protected String getReport( - RecordingDescriptor recordingDescriptor, String filter, boolean formatted) + protected String getReport(RecordingDescriptor recordingDescriptor, String filter) throws Exception { Path saveFile = null; try { - /* NOTE: Not always a cache miss since if a filter is specified or we want a JSON response, we do not even check the cache */ + /* NOTE: Not always a cache miss since if a filter is specified we do not even check the cache */ logger.trace("Active report cache miss for {}", recordingDescriptor.recordingName); try { saveFile = reportGeneratorServiceProvider .get() - .exec(recordingDescriptor, filter, formatted) + .exec(recordingDescriptor, filter) .get(generationTimeoutSeconds, TimeUnit.SECONDS); return fs.readString(saveFile); } catch (ExecutionException | CompletionException e) { logger.error(e); - delete( - recordingDescriptor.connectionDescriptor, - recordingDescriptor.recordingName, - formatted); + delete(recordingDescriptor.connectionDescriptor, recordingDescriptor.recordingName); if (e.getCause() instanceof SubprocessReportGenerator.SubprocessReportGenerationException) { @@ -217,7 +177,7 @@ public void onNotification(Notification> notification) { ((HyperlinkedSerializableRecordingDescriptor) notification.getMessage().get("recording")) .getName(); - delete(new ConnectionDescriptor(targetId), recordingName, true); + delete(new ConnectionDescriptor(targetId), recordingName); break; default: break; diff --git a/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java b/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java index 3a657711cc..0c492297a2 100644 --- a/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java +++ b/src/main/java/io/cryostat/net/reports/ArchivedRecordingReportCache.java @@ -49,15 +49,13 @@ class ArchivedRecordingReportCache { this.logger = logger; } - Future getFromPath( - String subdirectoryName, String recordingName, String filter, boolean formatted) { + Future getFromPath(String subdirectoryName, String recordingName, String filter) { CompletableFuture f = new CompletableFuture<>(); Path dest = null; try { dest = recordingArchiveHelper - .getCachedReportPathFromPath( - subdirectoryName, recordingName, filter, formatted) + .getCachedReportPathFromPath(subdirectoryName, recordingName, filter) .get(); if (fs.isReadable(dest) && fs.isRegularFile(dest)) { f.complete(dest); @@ -73,7 +71,7 @@ Future getFromPath( Path saveFile = reportGeneratorServiceProvider .get() - .exec(archivedRecording, dest, filter, formatted) + .exec(archivedRecording, dest, filter) .get(generationTimeoutSeconds, TimeUnit.SECONDS); f.complete(saveFile); } catch (Exception e) { @@ -88,17 +86,17 @@ Future getFromPath( return f; } - Future get(String recordingName, String filter, boolean formatted) { - return this.get(null, recordingName, filter, formatted); + Future get(String recordingName, String filter) { + return this.get(null, recordingName, filter); } - Future get(String sourceTarget, String recordingName, String filter, boolean formatted) { + Future get(String sourceTarget, String recordingName, String filter) { CompletableFuture f = new CompletableFuture<>(); Path dest = null; try { dest = recordingArchiveHelper - .getCachedReportPath(sourceTarget, recordingName, filter, formatted) + .getCachedReportPath(sourceTarget, recordingName, filter) .get(); if (fs.isReadable(dest) && fs.isRegularFile(dest)) { f.complete(dest); @@ -111,7 +109,7 @@ Future get(String sourceTarget, String recordingName, String filter, boole Path saveFile = reportGeneratorServiceProvider .get() - .exec(archivedRecording, dest, filter, formatted) + .exec(archivedRecording, dest, filter) .get(generationTimeoutSeconds, TimeUnit.SECONDS); f.complete(saveFile); } catch (Exception e) { diff --git a/src/main/java/io/cryostat/net/reports/RemoteReportGenerator.java b/src/main/java/io/cryostat/net/reports/RemoteReportGenerator.java index 8474608349..ae3426073a 100644 --- a/src/main/java/io/cryostat/net/reports/RemoteReportGenerator.java +++ b/src/main/java/io/cryostat/net/reports/RemoteReportGenerator.java @@ -59,8 +59,7 @@ class RemoteReportGenerator extends AbstractReportGeneratorService { @Override @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") - public CompletableFuture exec( - Path recording, Path destination, String filter, boolean formatted) { + public CompletableFuture exec(Path recording, Path destination, String filter) { String reportGenerator = env.getEnv(Variables.REPORT_GENERATOR_ENV); logger.trace("POSTing {} to {}", recording, reportGenerator); var form = @@ -73,7 +72,7 @@ public CompletableFuture exec( HttpMimeType.OCTET_STREAM.mime()); var f = new CompletableFuture(); - String acceptHeader = formatted ? HttpMimeType.HTML.mime() : HttpMimeType.JSON.mime(); + String acceptHeader = HttpMimeType.JSON.mime(); this.http .postAbs(String.format("%s/report", reportGenerator)) .putHeader(HttpHeaders.ACCEPT.toString(), acceptHeader) diff --git a/src/main/java/io/cryostat/net/reports/ReportGeneratorService.java b/src/main/java/io/cryostat/net/reports/ReportGeneratorService.java index 3fb6b1de4b..422d174241 100644 --- a/src/main/java/io/cryostat/net/reports/ReportGeneratorService.java +++ b/src/main/java/io/cryostat/net/reports/ReportGeneratorService.java @@ -19,9 +19,7 @@ import java.util.concurrent.CompletableFuture; interface ReportGeneratorService { - CompletableFuture exec(Path in, Path out, String filter, boolean formatted) - throws Exception; + CompletableFuture exec(Path in, Path out, String filter) throws Exception; - CompletableFuture exec(RecordingDescriptor rd, String filter, boolean formatted) - throws Exception; + CompletableFuture exec(RecordingDescriptor rd, String filter) throws Exception; } diff --git a/src/main/java/io/cryostat/net/reports/ReportService.java b/src/main/java/io/cryostat/net/reports/ReportService.java index 9199a6f71d..2257e454e5 100644 --- a/src/main/java/io/cryostat/net/reports/ReportService.java +++ b/src/main/java/io/cryostat/net/reports/ReportService.java @@ -31,30 +31,24 @@ public class ReportService { this.archivedCache = archivedCache; } - public Future getFromPath( - String subdirectoryName, String recordingName, String filter, boolean formatted) { - return archivedCache.getFromPath(subdirectoryName, recordingName, filter, formatted); + public Future getFromPath(String subdirectoryName, String recordingName, String filter) { + return archivedCache.getFromPath(subdirectoryName, recordingName, filter); } - public Future get(String recordingName, String filter, boolean formatted) { - return archivedCache.get(recordingName, filter, formatted); + public Future get(String recordingName, String filter) { + return archivedCache.get(recordingName, filter); } - public Future get( - String sourceTarget, String recordingName, String filter, boolean formatted) { - return archivedCache.get(sourceTarget, recordingName, filter, formatted); + public Future get(String sourceTarget, String recordingName, String filter) { + return archivedCache.get(sourceTarget, recordingName, filter); } public Future get( - ConnectionDescriptor connectionDescriptor, - String recordingName, - String filter, - boolean formatted) { - return activeCache.get(connectionDescriptor, recordingName, filter, formatted); + ConnectionDescriptor connectionDescriptor, String recordingName, String filter) { + return activeCache.get(connectionDescriptor, recordingName, filter); } - public boolean delete( - ConnectionDescriptor connectionDescriptor, String recordingName, boolean formatted) { - return activeCache.delete(connectionDescriptor, recordingName, formatted); + public boolean delete(ConnectionDescriptor connectionDescriptor, String recordingName) { + return activeCache.delete(connectionDescriptor, recordingName); } } diff --git a/src/main/java/io/cryostat/net/reports/ReportTransformerModule.java b/src/main/java/io/cryostat/net/reports/ReportTransformerModule.java deleted file mode 100644 index d141f99543..0000000000 --- a/src/main/java/io/cryostat/net/reports/ReportTransformerModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.cryostat.net.reports; - -import java.util.Set; - -import io.cryostat.core.reports.ReportTransformer; - -import dagger.Module; -import dagger.Provides; -import dagger.multibindings.ElementsIntoSet; - -@Module -public abstract class ReportTransformerModule { - - @Provides - @ElementsIntoSet - static Set provideReportTransformers() { - return Set.of(); - } -} diff --git a/src/main/java/io/cryostat/net/reports/ReportsModule.java b/src/main/java/io/cryostat/net/reports/ReportsModule.java index 4eca24dd37..c6980e4e9d 100644 --- a/src/main/java/io/cryostat/net/reports/ReportsModule.java +++ b/src/main/java/io/cryostat/net/reports/ReportsModule.java @@ -15,15 +15,12 @@ */ package io.cryostat.net.reports; -import java.util.Set; - import javax.inject.Named; import javax.inject.Provider; import javax.inject.Singleton; import io.cryostat.configuration.Variables; import io.cryostat.core.log.Logger; -import io.cryostat.core.reports.ReportTransformer; import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem; import io.cryostat.messaging.notifications.NotificationListener; @@ -32,7 +29,6 @@ import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.util.JavaProcess; -import com.google.gson.Gson; import dagger.Binds; import dagger.Module; import dagger.Provides; @@ -40,10 +36,7 @@ import io.vertx.core.Vertx; import io.vertx.ext.web.client.WebClient; -@Module( - includes = { - ReportTransformerModule.class, - }) +@Module public abstract class ReportsModule { public static final String REPORT_GENERATION_TIMEOUT_SECONDS = @@ -144,19 +137,15 @@ static RemoteReportGenerator provideRemoteReportGenerator( @Provides static SubprocessReportGenerator provideSubprocessReportGenerator( Environment env, - Gson gson, FileSystem fs, TargetConnectionManager targetConnectionManager, - Set reportTransformers, Provider javaProcessBuilder, @Named(REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds, Logger logger) { return new SubprocessReportGenerator( env, - gson, fs, targetConnectionManager, - reportTransformers, javaProcessBuilder, generationTimeoutSeconds, logger); diff --git a/src/main/java/io/cryostat/net/reports/SubprocessReportGenerator.java b/src/main/java/io/cryostat/net/reports/SubprocessReportGenerator.java index 5714a82ebf..97f8630d8b 100644 --- a/src/main/java/io/cryostat/net/reports/SubprocessReportGenerator.java +++ b/src/main/java/io/cryostat/net/reports/SubprocessReportGenerator.java @@ -15,7 +15,6 @@ */ package io.cryostat.net.reports; -import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; @@ -24,12 +23,8 @@ import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ForkJoinPool; @@ -46,11 +41,7 @@ import io.cryostat.core.CryostatCore; import io.cryostat.core.log.Logger; import io.cryostat.core.reports.InterruptibleReportGenerator; -import io.cryostat.core.reports.InterruptibleReportGenerator.ReportGenerationEvent; -import io.cryostat.core.reports.InterruptibleReportGenerator.ReportResult; -import io.cryostat.core.reports.InterruptibleReportGenerator.ReportStats; -import io.cryostat.core.reports.InterruptibleReportGenerator.RuleEvaluation; -import io.cryostat.core.reports.ReportTransformer; +import io.cryostat.core.reports.InterruptibleReportGenerator.AnalysisResult; import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem; import io.cryostat.core.util.RuleFilterParser; @@ -64,31 +55,24 @@ public class SubprocessReportGenerator extends AbstractReportGeneratorService { private final Environment env; - private final Gson gson; - private final Set reportTransformers; private final Provider javaProcessBuilderProvider; private final long generationTimeoutSeconds; SubprocessReportGenerator( Environment env, - Gson gson, FileSystem fs, TargetConnectionManager targetConnectionManager, - Set reportTransformers, Provider javaProcessBuilderProvider, @Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds, Logger logger) { super(targetConnectionManager, fs, logger); this.env = env; - this.gson = gson; - this.reportTransformers = reportTransformers; this.javaProcessBuilderProvider = javaProcessBuilderProvider; this.generationTimeoutSeconds = generationTimeoutSeconds; } @Override - public synchronized CompletableFuture exec( - Path recording, Path saveFile, String filter, boolean formatted) + public synchronized CompletableFuture exec(Path recording, Path saveFile, String filter) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, InterruptedException, ReportGenerationException { @@ -101,13 +85,6 @@ public synchronized CompletableFuture exec( if (filter == null) { throw new IllegalArgumentException("Filter may not be null"); } - fs.writeString( - saveFile, - serializeTransformersSet(), - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, - StandardOpenOption.DSYNC, - StandardOpenOption.WRITE); JavaProcess.Builder procBuilder = javaProcessBuilderProvider .get() @@ -117,14 +94,10 @@ public synchronized CompletableFuture exec( Integer.parseInt( env.getEnv( Variables.SUBPROCESS_MAX_HEAP_ENV, "0")))) - .processArgs(createProcessArgs(recording, saveFile, filter, formatted)); + .processArgs(createProcessArgs(recording, saveFile, filter)); return CompletableFuture.supplyAsync( () -> { Process proc = null; - ReportGenerationEvent evt = new ReportGenerationEvent(recording.toString()); - evt.begin(); - Path reportStatsPath = Paths.get(Variables.REPORT_STATS_PATH); - try { proc = procBuilder.exec(); proc.waitFor(generationTimeoutSeconds - 1, TimeUnit.SECONDS); @@ -134,15 +107,6 @@ public synchronized CompletableFuture exec( ? ExitStatus.TIMED_OUT : ExitStatus.byExitCode(proc.exitValue()); - if (fs.exists(reportStatsPath)) { - try (BufferedReader br = fs.readFile(reportStatsPath)) { - ReportStats stats = gson.fromJson(br, ReportStats.class); - evt.setRecordingSizeBytes(stats.getRecordingSizeBytes()); - evt.setRulesEvaluated(stats.getRulesEvaluated()); - evt.setRulesApplicable(stats.getRulesApplicable()); - } - } - switch (status) { case OK: return saveFile; @@ -166,18 +130,6 @@ public synchronized CompletableFuture exec( if (proc != null) { proc.destroyForcibly(); } - - try { - fs.deleteIfExists(reportStatsPath); - } catch (IOException e) { - logger.error(e); - throw new CompletionException(e); - } - - evt.end(); - if (evt.shouldCommit()) { - evt.commit(); - } } }); } @@ -197,38 +149,11 @@ private List createJvmArgs(int maxHeapMegabytes) throws IOException { return args; } - private List createProcessArgs( - Path recording, Path saveFile, String filter, boolean formatted) { + private List createProcessArgs(Path recording, Path saveFile, String filter) { return List.of( recording.toAbsolutePath().toString(), saveFile.toAbsolutePath().toString(), - filter, - String.valueOf(formatted)); - } - - private String serializeTransformersSet() { - var sb = new StringBuilder(); - for (var rt : reportTransformers) { - sb.append(rt.getClass().getCanonicalName()); - sb.append(System.lineSeparator()); - } - return sb.toString().trim(); - } - - static Set deserializeTransformers(String serial) - throws InstantiationException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchMethodException, SecurityException, - ClassNotFoundException { - var st = new StringTokenizer(serial); - var res = new HashSet(); - while (st.hasMoreTokens()) { - // TODO does it ever make sense that a ReportTransformer would have constructor - // arguments, or otherwise require state? How would we handle that here if so? - res.add( - (ReportTransformer) - Class.forName(st.nextToken()).getDeclaredConstructor().newInstance()); - } - return res; + filter); } public static void main(String[] args) { @@ -269,55 +194,23 @@ public static void main(String[] args) { System.exit(ExitStatus.OTHER.code); } - if (args.length != 4) { + if (args.length != 3) { throw new IllegalArgumentException(Arrays.asList(args).toString()); } var recording = Paths.get(args[0]); - Set transformers = Collections.emptySet(); var saveFile = Paths.get(args[1]); String filter = args[2]; - String formatted = args[3]; - try { - transformers = deserializeTransformers(fs.readString(saveFile)); - } catch (Exception e) { - Logger.INSTANCE.error(e); - System.exit(ExitStatus.OTHER.code); - } try { Logger.INSTANCE.info(SubprocessReportGenerator.class.getName() + " processing report"); - if (Boolean.parseBoolean(formatted)) { - ReportResult reportResult = generateReportFromFile(recording, transformers, filter); - Logger.INSTANCE.info( - SubprocessReportGenerator.class.getName() + " writing report to file"); - fs.writeString( - saveFile, - reportResult.getHtml(), - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, - StandardOpenOption.DSYNC, - StandardOpenOption.WRITE); - - Path reportStats = Paths.get(Variables.REPORT_STATS_PATH); - fs.writeString( - reportStats, - gson.toJson(reportResult.getReportStats()), - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, - StandardOpenOption.DSYNC, - StandardOpenOption.WRITE); - - } else { - Map evalMapResult = - generateEvalMapFromFile(recording, transformers, filter); - fs.writeString( - saveFile, - gson.toJson(evalMapResult), - StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, - StandardOpenOption.DSYNC, - StandardOpenOption.WRITE); - } + Map evalMapResult = generateEvalMapFromFile(recording, filter); + fs.writeString( + saveFile, + gson.toJson(evalMapResult), + StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, + StandardOpenOption.DSYNC, + StandardOpenOption.WRITE); System.exit(ExitStatus.OK.code); } catch (ConnectionException e) { @@ -332,26 +225,11 @@ public static void main(String[] args) { } } - static ReportResult generateReportFromFile( - Path recording, Set transformers, String filter) throws Exception { - Pair, FileSystem> hPair = generateHelper(recording, filter); - try (InputStream stream = hPair.getRight().newInputStream(recording)) { - return new InterruptibleReportGenerator( - Logger.INSTANCE, transformers, ForkJoinPool.commonPool()) - .generateReportInterruptibly(stream, hPair.getLeft()) - .get(); - } catch (IOException ioe) { - ioe.printStackTrace(); - throw new SubprocessReportGenerationException(ExitStatus.IO_EXCEPTION); - } - } - - static Map generateEvalMapFromFile( - Path recording, Set transformers, String filter) throws Exception { + static Map generateEvalMapFromFile(Path recording, String filter) + throws Exception { Pair, FileSystem> hPair = generateHelper(recording, filter); try (InputStream stream = hPair.getRight().newInputStream(recording)) { - return new InterruptibleReportGenerator( - Logger.INSTANCE, transformers, ForkJoinPool.commonPool()) + return new InterruptibleReportGenerator(ForkJoinPool.commonPool(), Logger.INSTANCE) .generateEvalMapInterruptibly(stream, hPair.getLeft()) .get(); } catch (IOException ioe) { diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java index 069445ec59..95b6e26204 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java @@ -95,7 +95,7 @@ public String path() { @Override public List produces() { - return List.of(HttpMimeType.HTML, HttpMimeType.JSON_RAW); + return List.of(HttpMimeType.JSON_RAW); } @Override @@ -110,14 +110,9 @@ public IntermediateResponse handle(RequestParameters params) throws Except try { List queriedFilter = params.getQueryParams().getAll("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (params.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : params.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); Path report = reportService - .getFromPath(subdirectoryName, recordingName, rawFilter, formatted) + .getFromPath(subdirectoryName, recordingName, rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS); return new IntermediateResponse().body(report); } catch (ExecutionException | CompletionException e) { diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java index b04ce5d281..f13bd3b513 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java @@ -96,7 +96,7 @@ public String path() { @Override public List produces() { - return List.of(HttpMimeType.HTML, HttpMimeType.JSON); + return List.of(HttpMimeType.JSON); } @Override @@ -116,17 +116,12 @@ public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { try { List queriedFilter = ctx.queryParam("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (ctx.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : ctx.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); Path report = reportService - .getFromPath(subdirectoryName, recordingName, rawFilter, formatted) + .getFromPath(subdirectoryName, recordingName, rawFilter) .get(generationTimeoutSeconds, TimeUnit.SECONDS); ctx.response().putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, contentType); + ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, ctx.getAcceptableContentType()); ctx.response().sendFile(report.toAbsolutePath().toString()); } catch (ExecutionException | CompletionException e) { if (ExceptionUtils.getRootCause(e) instanceof RecordingNotFoundException diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetHandler.java index 0542174424..c3b9bb1af7 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetHandler.java @@ -99,7 +99,7 @@ public String path() { @Override public List produces() { - return List.of(HttpMimeType.HTML, HttpMimeType.JSON_RAW); + return List.of(HttpMimeType.JSON_RAW); } @Override @@ -115,14 +115,9 @@ public IntermediateResponse handle(RequestParameters params) throws Except recordingArchiveHelper.validateSourceTarget(sourceTarget); List queriedFilter = params.getQueryParams().getAll("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (params.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : params.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); Path report = reportService - .get(sourceTarget, recordingName, rawFilter, formatted) + .get(sourceTarget, recordingName, rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS); return new IntermediateResponse().body(report); } catch (RecordingSourceTargetNotFoundException e) { diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandler.java index 4dedc79b2e..526f9067f6 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandler.java @@ -98,7 +98,7 @@ public String path() { @Override public List produces() { - return List.of(HttpMimeType.HTML, HttpMimeType.JSON); + return List.of(HttpMimeType.JSON); } @Override @@ -119,17 +119,12 @@ public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { recordingArchiveHelper.validateSourceTarget(sourceTarget); List queriedFilter = ctx.queryParam("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (ctx.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : ctx.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); Path report = reportService - .get(sourceTarget, recordingName, rawFilter, formatted) + .get(sourceTarget, recordingName, rawFilter) .get(generationTimeoutSeconds, TimeUnit.SECONDS); ctx.response().putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, contentType); + ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, ctx.getAcceptableContentType()); ctx.response().sendFile(report.toAbsolutePath().toString()); } catch (RecordingSourceTargetNotFoundException e) { throw new ApiException(404, e.getMessage(), e); diff --git a/src/main/java/io/cryostat/net/web/http/api/v1/ReportGetHandler.java b/src/main/java/io/cryostat/net/web/http/api/v1/ReportGetHandler.java index 7cb1bb6f61..272dbe8682 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v1/ReportGetHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v1/ReportGetHandler.java @@ -113,7 +113,7 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception { Path report = reportService - .get(recordingName, rawFilter, true) + .get(recordingName, rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS); ctx.response().putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); ctx.response() diff --git a/src/main/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandler.java b/src/main/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandler.java index d80ec79000..cb37b3784d 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandler.java @@ -89,7 +89,7 @@ public Set resourceActions() { @Override public List produces() { - return List.of(HttpMimeType.HTML, HttpMimeType.JSON); + return List.of(HttpMimeType.JSON); } @Override @@ -107,21 +107,15 @@ public void handleAuthenticated(RoutingContext ctx) throws Exception { String recordingName = ctx.pathParam("recordingName"); List queriedFilter = ctx.queryParam("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (ctx.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : ctx.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); try { ctx.response() - .putHeader(HttpHeaders.CONTENT_TYPE, contentType) + .putHeader(HttpHeaders.CONTENT_TYPE, ctx.getAcceptableContentType()) .end( reportService .get( getConnectionDescriptorFromContext(ctx), recordingName, - rawFilter, - formatted) + rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS)); } catch (CompletionException | ExecutionException ee) { diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/ReportGetHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/ReportGetHandler.java index f412e299c0..211deb2b10 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/ReportGetHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/ReportGetHandler.java @@ -109,7 +109,7 @@ public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { try { Path report = reportService - .get(recordingName, rawFilter, true) + .get(recordingName, rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS); ctx.response().putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); ctx.response() diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandler.java index cae5dbc5d7..be7498dc8e 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandler.java @@ -91,7 +91,7 @@ public Set resourceActions() { @Override public List produces() { - return List.of(HttpMimeType.JSON, HttpMimeType.HTML); + return List.of(HttpMimeType.JSON); } @Override @@ -109,22 +109,16 @@ public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { String recordingName = ctx.pathParam("recordingName"); List queriedFilter = ctx.queryParam("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); - String contentType = - (ctx.getAcceptableContentType() == null) - ? HttpMimeType.HTML.mime() - : ctx.getAcceptableContentType(); - boolean formatted = contentType.equals(HttpMimeType.HTML.mime()); try { ctx.response() - .putHeader(HttpHeaders.CONTENT_TYPE, contentType) + .putHeader(HttpHeaders.CONTENT_TYPE, ctx.getAcceptableContentType()) .putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline") .end( reportService .get( getConnectionDescriptorFromJwt(ctx, jwt), recordingName, - rawFilter, - formatted) + rawFilter) .get(reportGenerationTimeoutSeconds, TimeUnit.SECONDS)); } catch (CompletionException | ExecutionException ee) { diff --git a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java index c5d45fab29..606b3dc676 100644 --- a/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingArchiveHelper.java @@ -576,17 +576,14 @@ public boolean deleteReports(String subdirectoryName, String recordingName) { } public Future getCachedReportPathFromPath( - String subdirectoryName, String recordingName, String filter, boolean formatted) { + String subdirectoryName, String recordingName, String filter) { CompletableFuture future = new CompletableFuture<>(); try { Path tempSubdirectory = archivedRecordingsReportPath.resolve(subdirectoryName); if (!fs.exists(tempSubdirectory)) { tempSubdirectory = fs.createDirectory(tempSubdirectory); } - String fileName = - String.format( - "%s-%s.report%s", - recordingName, filter.hashCode(), formatted ? ".html" : ".json"); + String fileName = String.format("%s-%s.report.json", recordingName, filter.hashCode()); future.complete(tempSubdirectory.resolve(fileName).toAbsolutePath()); } catch (IOException e) { future.completeExceptionally(e); @@ -595,7 +592,7 @@ public Future getCachedReportPathFromPath( } public Future getCachedReportPath( - String sourceTarget, String recordingName, String filter, boolean formatted) { + String sourceTarget, String recordingName, String filter) { try { String jvmId = jvmIdHelper.getJvmId(sourceTarget); String subdirectory = @@ -604,7 +601,7 @@ public Future getCachedReportPath( : sourceTarget.equals(UPLOADED_RECORDINGS_SUBDIRECTORY) ? UPLOADED_RECORDINGS_SUBDIRECTORY : base32.encodeAsString(jvmId.getBytes(StandardCharsets.UTF_8)); - return getCachedReportPathFromPath(subdirectory, recordingName, filter, formatted); + return getCachedReportPathFromPath(subdirectory, recordingName, filter); } catch (JvmIdGetException e) { return CompletableFuture.failedFuture(e); } diff --git a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java index 1b01c98ef1..949f75e728 100644 --- a/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java +++ b/src/main/java/io/cryostat/recordings/RecordingTargetHelper.java @@ -425,9 +425,7 @@ private Future deleteRecording( if (descriptor.isPresent()) { IRecordingDescriptor d = descriptor.get(); connection.getService().close(d); - reportService.delete(connectionDescriptor, recordingName, true); - reportService.delete( - connectionDescriptor, recordingName, false); + reportService.delete(connectionDescriptor, recordingName); this.cancelScheduledTasksIfExists(targetId, recordingName); HyperlinkedSerializableRecordingDescriptor linkedDesc = new HyperlinkedSerializableRecordingDescriptor( diff --git a/src/test/java/io/cryostat/net/reports/ActiveRecordingReportCacheTest.java b/src/test/java/io/cryostat/net/reports/ActiveRecordingReportCacheTest.java index 112fe04dd7..a793c8fd6c 100644 --- a/src/test/java/io/cryostat/net/reports/ActiveRecordingReportCacheTest.java +++ b/src/test/java/io/cryostat/net/reports/ActiveRecordingReportCacheTest.java @@ -15,7 +15,6 @@ */ package io.cryostat.net.reports; -import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import java.nio.file.Path; @@ -79,7 +78,7 @@ void setup() { @Test void shouldReturnFalseWhenDeletingNonExistentReport() { - Assertions.assertFalse(cache.delete(new ConnectionDescriptor("foo"), "bar", false)); + Assertions.assertFalse(cache.delete(new ConnectionDescriptor("foo"), "bar")); } @Test @@ -87,9 +86,7 @@ void shouldReturnTrueWhenDeletingReport() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), - anyString(), - Mockito.anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_DOC); @@ -97,8 +94,8 @@ void shouldReturnTrueWhenDeletingReport() throws Exception { String recordingName = "bar"; ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - cache.get(connectionDescriptor, recordingName, "", true); - Assertions.assertTrue(cache.delete(connectionDescriptor, recordingName, true)); + cache.get(connectionDescriptor, recordingName, ""); + Assertions.assertTrue(cache.delete(connectionDescriptor, recordingName)); } @Test @@ -106,18 +103,18 @@ void shouldReturnGeneratedReportResult() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_DOC); String targetId = "foo"; ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - Future report = cache.get(connectionDescriptor, "foo", "", true); + Future report = cache.get(connectionDescriptor, "foo", ""); MatcherAssert.assertThat(report.get(), Matchers.equalTo(REPORT_DOC)); Mockito.verify(subprocessReportGenerator) - .exec(Mockito.any(RecordingDescriptor.class), Mockito.eq(""), Mockito.eq(true)); + .exec(Mockito.any(RecordingDescriptor.class), Mockito.eq("")); Mockito.verify(fs).readString(destinationFile); } @@ -126,21 +123,18 @@ void shouldReturnGeneratedReportResultFiltered() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_DOC); String targetId = "foo"; ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - Future report = cache.get(connectionDescriptor, "foo", "non-null", true); + Future report = cache.get(connectionDescriptor, "foo", "non-null"); MatcherAssert.assertThat(report.get(), Matchers.equalTo(REPORT_DOC)); Mockito.verify(subprocessReportGenerator) - .exec( - Mockito.any(RecordingDescriptor.class), - Mockito.eq("non-null"), - Mockito.eq(true)); + .exec(Mockito.any(RecordingDescriptor.class), Mockito.eq("non-null")); Mockito.verify(fs).readString(destinationFile); } @@ -149,21 +143,18 @@ void shouldReturnGeneratedReportResultUnformatted() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_JSON); String targetId = "foo"; ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - Future report = cache.get(connectionDescriptor, "foo", "non-null", false); + Future report = cache.get(connectionDescriptor, "foo", "non-null"); MatcherAssert.assertThat(report.get(), Matchers.equalTo(REPORT_JSON)); Mockito.verify(subprocessReportGenerator) - .exec( - Mockito.any(RecordingDescriptor.class), - Mockito.eq("non-null"), - Mockito.eq(false)); + .exec(Mockito.any(RecordingDescriptor.class), Mockito.eq("non-null")); Mockito.verify(fs).readString(destinationFile); } @@ -172,7 +163,7 @@ void shouldReturnCachedReportResultOnSecondRequest() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_DOC); @@ -180,13 +171,13 @@ void shouldReturnCachedReportResultOnSecondRequest() throws Exception { String recordingName = "bar"; ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - String report1 = cache.get(connectionDescriptor, recordingName, "", true).get(); + String report1 = cache.get(connectionDescriptor, recordingName, "").get(); MatcherAssert.assertThat(report1, Matchers.equalTo(REPORT_DOC)); - String report2 = cache.get(connectionDescriptor, recordingName, "", true).get(); + String report2 = cache.get(connectionDescriptor, recordingName, "").get(); MatcherAssert.assertThat(report2, Matchers.equalTo(report1)); Mockito.verify(subprocessReportGenerator, Mockito.times(1)) - .exec(Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean()); + .exec(Mockito.any(RecordingDescriptor.class), anyString()); } @SuppressWarnings("rawtypes") @@ -195,7 +186,7 @@ void shouldReturnUncachedReportWhenRecordingStopped() throws Exception { Mockito.when(pathFuture.get(Mockito.anyLong(), Mockito.any())).thenReturn(destinationFile); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenReturn(pathFuture); Mockito.when(fs.readString(destinationFile)).thenReturn(REPORT_DOC); @@ -212,14 +203,14 @@ void shouldReturnUncachedReportWhenRecordingStopped() throws Exception { .thenReturn(Map.of("target", targetId, "recording", hsrd)); ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor(targetId); - String report1 = cache.get(connectionDescriptor, recordingName, "", true).get(); + String report1 = cache.get(connectionDescriptor, recordingName, "").get(); MatcherAssert.assertThat(report1, Matchers.equalTo(REPORT_DOC)); cache.onNotification(notification); - String report2 = cache.get(connectionDescriptor, recordingName, "", true).get(); + String report2 = cache.get(connectionDescriptor, recordingName, "").get(); MatcherAssert.assertThat(report2, Matchers.equalTo(report1)); Mockito.verify(subprocessReportGenerator, Mockito.times(2)) - .exec(Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean()); + .exec(Mockito.any(RecordingDescriptor.class), anyString()); } @Test @@ -227,11 +218,10 @@ void shouldThrowExceptionIfRecordingNotFound() throws Exception { ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor("foo"); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenThrow(new CompletionException(new RecordingNotFoundException("", ""))); Assertions.assertThrows( - ExecutionException.class, - () -> cache.get(connectionDescriptor, "bar", "", true).get()); + ExecutionException.class, () -> cache.get(connectionDescriptor, "bar", "").get()); } @Test @@ -239,13 +229,12 @@ void shouldThrowExceptionIfSubprocessExitsNonCleanly() throws Exception { ConnectionDescriptor connectionDescriptor = new ConnectionDescriptor("foo"); Mockito.when( subprocessReportGenerator.exec( - Mockito.any(RecordingDescriptor.class), anyString(), anyBoolean())) + Mockito.any(RecordingDescriptor.class), anyString())) .thenThrow( new CompletionException( new SubprocessReportGenerator.SubprocessReportGenerationException( SubprocessReportGenerator.ExitStatus.OTHER))); Assertions.assertThrows( - ExecutionException.class, - () -> cache.get(connectionDescriptor, "bar", "", true).get()); + ExecutionException.class, () -> cache.get(connectionDescriptor, "bar", "").get()); } } diff --git a/src/test/java/io/cryostat/net/reports/ArchivedRecordingReportCacheTest.java b/src/test/java/io/cryostat/net/reports/ArchivedRecordingReportCacheTest.java index 8ee592a3e0..c510ed5cd3 100644 --- a/src/test/java/io/cryostat/net/reports/ArchivedRecordingReportCacheTest.java +++ b/src/test/java/io/cryostat/net/reports/ArchivedRecordingReportCacheTest.java @@ -67,9 +67,7 @@ void getShouldThrowIfNoCacheAndNoRecording() throws Exception { CompletableFuture future1 = Mockito.mock(CompletableFuture.class); Mockito.when(future1.get()).thenReturn(destinationFile); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future1); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(false); @@ -90,7 +88,7 @@ void getShouldThrowIfNoCacheAndNoRecording() throws Exception { ExecutionException ee = Assertions.assertThrows( ExecutionException.class, - () -> cache.get(sourceTarget, recordingName, "", true).get()); + () -> cache.get(sourceTarget, recordingName, "").get()); MatcherAssert.assertThat( ExceptionUtils.getRootCause(ee), @@ -104,9 +102,7 @@ void getShouldGenerateAndCacheReport() throws Exception { CompletableFuture future1 = Mockito.mock(CompletableFuture.class); Mockito.when(future1.get()).thenReturn(destinationFile); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future1); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(false); @@ -126,14 +122,13 @@ void getShouldGenerateAndCacheReport() throws Exception { subprocessReportGenerator.exec( Mockito.any(Path.class), Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(pathFuture); - Future res = cache.get(sourceTarget, recordingName, "", true); + Future res = cache.get(sourceTarget, recordingName, ""); MatcherAssert.assertThat(res.get(), Matchers.sameInstance(destinationFile)); - Mockito.verify(subprocessReportGenerator).exec(recording, destinationFile, "", true); + Mockito.verify(subprocessReportGenerator).exec(recording, destinationFile, ""); Mockito.verify(fs, Mockito.atLeastOnce()).isReadable(destinationFile); } @@ -144,7 +139,7 @@ void getShouldGenerateAndCacheReportFiltered() throws Exception { Mockito.when( recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "someFilter", true)) + sourceTarget, recordingName, "someFilter")) .thenReturn(future1); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(false); @@ -164,15 +159,13 @@ void getShouldGenerateAndCacheReportFiltered() throws Exception { subprocessReportGenerator.exec( Mockito.any(Path.class), Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(pathFuture); - Future res = cache.get(sourceTarget, recordingName, "someFilter", true); + Future res = cache.get(sourceTarget, recordingName, "someFilter"); MatcherAssert.assertThat(res.get(), Matchers.sameInstance(destinationFile)); - Mockito.verify(subprocessReportGenerator) - .exec(recording, destinationFile, "someFilter", true); + Mockito.verify(subprocessReportGenerator).exec(recording, destinationFile, "someFilter"); Mockito.verify(fs, Mockito.atLeastOnce()).isReadable(destinationFile); } @@ -183,7 +176,7 @@ void getShouldGenerateReportUnformatted() throws Exception { Mockito.when( recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "someFilter", false)) + sourceTarget, recordingName, "someFilter")) .thenReturn(future1); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(false); @@ -203,15 +196,13 @@ void getShouldGenerateReportUnformatted() throws Exception { subprocessReportGenerator.exec( Mockito.any(Path.class), Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(pathFuture); - Future res = cache.get(sourceTarget, recordingName, "someFilter", false); + Future res = cache.get(sourceTarget, recordingName, "someFilter"); MatcherAssert.assertThat(res.get(), Matchers.sameInstance(destinationFile)); - Mockito.verify(subprocessReportGenerator) - .exec(recording, destinationFile, "someFilter", false); + Mockito.verify(subprocessReportGenerator).exec(recording, destinationFile, "someFilter"); Mockito.verify(fs, Mockito.atLeastOnce()).isReadable(destinationFile); } @@ -220,15 +211,13 @@ void getShouldReturnCachedFileIfAvailable() throws Exception { CompletableFuture future = Mockito.mock(CompletableFuture.class); Mockito.when(future.get()).thenReturn(destinationFile); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(true); Mockito.when(fs.isRegularFile(Mockito.any(Path.class))).thenReturn(true); - Future res = cache.get(sourceTarget, recordingName, "", true); + Future res = cache.get(sourceTarget, recordingName, ""); MatcherAssert.assertThat(res.get(), Matchers.sameInstance(destinationFile)); Mockito.verifyNoInteractions(subprocessReportGenerator); @@ -241,9 +230,7 @@ void shouldThrowErrorIfReportGenerationFails() throws Exception { CompletableFuture future1 = Mockito.mock(CompletableFuture.class); Mockito.when(future1.get()).thenReturn(destinationFile); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future1); Mockito.when(fs.isReadable(Mockito.any(Path.class))).thenReturn(false); @@ -261,8 +248,7 @@ void shouldThrowErrorIfReportGenerationFails() throws Exception { subprocessReportGenerator.exec( Mockito.any(Path.class), Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenThrow( new CompletionException( new SubprocessReportGenerator.SubprocessReportGenerationException( @@ -270,8 +256,7 @@ void shouldThrowErrorIfReportGenerationFails() throws Exception { ExecutionException ee = Assertions.assertThrows( - ExecutionException.class, - () -> cache.get(sourceTarget, "foo", "", true).get()); + ExecutionException.class, () -> cache.get(sourceTarget, "foo", "").get()); MatcherAssert.assertThat( ExceptionUtils.getRootCause(ee), @@ -285,17 +270,14 @@ void shouldThrowIfCachedPathResolutionFails() throws Exception { CompletableFuture future1 = Mockito.mock(CompletableFuture.class); Mockito.when(future1.get()).thenThrow(new CompletionException(new IOException())); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future1); Mockito.when(fs.deleteIfExists(Mockito.nullable(Path.class))).thenReturn(false); ExecutionException ee = Assertions.assertThrows( - ExecutionException.class, - () -> cache.get(sourceTarget, "foo", "", true).get()); + ExecutionException.class, () -> cache.get(sourceTarget, "foo", "").get()); MatcherAssert.assertThat( ExceptionUtils.getRootCause(ee), Matchers.instanceOf(IOException.class)); @@ -307,9 +289,7 @@ void shouldThrowIfRecordingPathResolutionFails() throws Exception { CompletableFuture future1 = Mockito.mock(CompletableFuture.class); Mockito.when(future1.get()).thenReturn(destinationFile); - Mockito.when( - recordingArchiveHelper.getCachedReportPath( - sourceTarget, recordingName, "", true)) + Mockito.when(recordingArchiveHelper.getCachedReportPath(sourceTarget, recordingName, "")) .thenReturn(future1); CompletableFuture future2 = Mockito.mock(CompletableFuture.class); @@ -326,8 +306,7 @@ void shouldThrowIfRecordingPathResolutionFails() throws Exception { ExecutionException ee = Assertions.assertThrows( - ExecutionException.class, - () -> cache.get(sourceTarget, "foo", "", true).get()); + ExecutionException.class, () -> cache.get(sourceTarget, "foo", "").get()); MatcherAssert.assertThat( ExceptionUtils.getRootCause(ee), Matchers.instanceOf(ArchivePathException.class)); diff --git a/src/test/java/io/cryostat/net/reports/SubprocessReportGeneratorTest.java b/src/test/java/io/cryostat/net/reports/SubprocessReportGeneratorTest.java index 822b5a154a..6a9a02295a 100644 --- a/src/test/java/io/cryostat/net/reports/SubprocessReportGeneratorTest.java +++ b/src/test/java/io/cryostat/net/reports/SubprocessReportGeneratorTest.java @@ -16,33 +16,26 @@ package io.cryostat.net.reports; import java.nio.file.Path; -import java.nio.file.StandardOpenOption; import java.time.Duration; import java.util.List; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import io.cryostat.configuration.Variables; import io.cryostat.core.log.Logger; import io.cryostat.core.net.Credentials; -import io.cryostat.core.reports.ReportTransformer; import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.TargetConnectionManager; import io.cryostat.util.JavaProcess; -import com.google.gson.Gson; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; @@ -54,7 +47,6 @@ class SubprocessReportGeneratorTest { @Mock Environment env; - @Mock Gson gson; @Mock FileSystem fs; @Mock TargetConnectionManager targetConnectionManager; @Mock JavaProcess.Builder javaProcessBuilder; @@ -105,57 +97,27 @@ void setup() throws Exception { .thenReturn("200"); this.generator = new SubprocessReportGenerator( - env, - gson, - fs, - targetConnectionManager, - Set.of(new TestReportTransformer()), - () -> javaProcessBuilder, - 30, - logger); + env, fs, targetConnectionManager, () -> javaProcessBuilder, 30, logger); } @Test void shouldThrowIfRecordingPathIsNull() { Assertions.assertThrows( IllegalArgumentException.class, - () -> generator.exec(null, Mockito.mock(Path.class), "", true)); + () -> generator.exec(null, Mockito.mock(Path.class), "")); } @Test void shouldThrowIfDestinationFileIsNull() { Assertions.assertThrows( - IllegalArgumentException.class, - () -> generator.exec(recordingFile, null, "", true)); + IllegalArgumentException.class, () -> generator.exec(recordingFile, null, "")); } @Test void shouldThrowIfFilterIsNull() { Assertions.assertThrows( IllegalArgumentException.class, - () -> generator.exec(recordingFile, Mockito.mock(Path.class), null, true)); - } - - @Test - void shouldWriteSerializedTransformersToFile() throws Exception { - Path dest = Mockito.mock(Path.class); - Mockito.when(dest.toAbsolutePath()).thenReturn(dest); - Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); - - generator.exec(recordingFile, dest, "", true); - - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - Mockito.verify(fs) - .writeString( - Mockito.same(dest), - captor.capture(), - Mockito.same(StandardOpenOption.CREATE), - Mockito.same(StandardOpenOption.TRUNCATE_EXISTING), - Mockito.same(StandardOpenOption.DSYNC), - Mockito.same(StandardOpenOption.WRITE)); - String serialized = captor.getValue(); - MatcherAssert.assertThat( - serialized, Matchers.equalTo(TestReportTransformer.class.getCanonicalName())); + () -> generator.exec(recordingFile, Mockito.mock(Path.class), null)); } @Test @@ -164,7 +126,7 @@ void shouldUseSelfAsForkedProcess() throws Exception { Mockito.when(dest.toAbsolutePath()).thenReturn(dest); Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); - generator.exec(recordingFile, dest, "", true); + generator.exec(recordingFile, dest, ""); Mockito.verify(javaProcessBuilder).klazz(SubprocessReportGenerator.class); } @@ -175,7 +137,7 @@ void shouldSetJvmArgs() throws Exception { Mockito.when(dest.toAbsolutePath()).thenReturn(dest); Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); - generator.exec(recordingFile, dest, "", true); + generator.exec(recordingFile, dest, ""); ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); Mockito.verify(javaProcessBuilder).jvmArgs(captor.capture()); @@ -196,7 +158,7 @@ void shouldSetJvmArgsWithoutReportMaxHeapEnvVar() throws Exception { Mockito.anyString())) .thenReturn("0"); - generator.exec(recordingFile, dest, "", true); + generator.exec(recordingFile, dest, ""); ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); Mockito.verify(javaProcessBuilder).jvmArgs(captor.capture()); @@ -211,12 +173,12 @@ void shouldSetProcessArgs() throws Exception { Mockito.when(dest.toAbsolutePath()).thenReturn(dest); Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); - generator.exec(recordingFile, dest, "", true); + generator.exec(recordingFile, dest, ""); ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); Mockito.verify(javaProcessBuilder).processArgs(captor.capture()); - List expected = List.of("/dest/recording.tmp", "/dest/somefile.tmp", "", "true"); + List expected = List.of("/dest/recording.tmp", "/dest/somefile.tmp", ""); MatcherAssert.assertThat(captor.getValue(), Matchers.equalTo(expected)); } @@ -226,19 +188,17 @@ void shouldSetProcessArgsFilteredUnformatted() throws Exception { Mockito.when(dest.toAbsolutePath()).thenReturn(dest); Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); - generator.exec(recordingFile, dest, "someFilter", false); + generator.exec(recordingFile, dest, "someFilter"); ArgumentCaptor> captor = ArgumentCaptor.forClass(List.class); Mockito.verify(javaProcessBuilder).processArgs(captor.capture()); - List expected = - List.of("/dest/recording.tmp", "/dest/somefile.tmp", "someFilter", "false"); + List expected = List.of("/dest/recording.tmp", "/dest/somefile.tmp", "someFilter"); MatcherAssert.assertThat(captor.getValue(), Matchers.equalTo(expected)); } - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void shouldExecuteProcessAndReturnPathOnOkExit(boolean formatted) throws Exception { + @Test + void shouldExecuteProcessAndReturnPathOnOkExit() throws Exception { Path dest = Mockito.mock(Path.class); Mockito.when(dest.toAbsolutePath()).thenReturn(dest); Mockito.when(dest.toString()).thenReturn("/dest/somefile.tmp"); @@ -247,7 +207,7 @@ void shouldExecuteProcessAndReturnPathOnOkExit(boolean formatted) throws Excepti Assertions.assertTimeoutPreemptively( Duration.ofSeconds(2), () -> { - Future path = generator.exec(recordingFile, dest, "", formatted); + Future path = generator.exec(recordingFile, dest, ""); MatcherAssert.assertThat(path.get(), Matchers.sameInstance(dest)); }); } @@ -266,7 +226,7 @@ void shouldExecuteProcessAndThrowExceptionOnNonOkExit() throws Exception { ExecutionException ex = Assertions.assertThrows( ExecutionException.class, - () -> generator.exec(recordingFile, dest, "", true).get()); + () -> generator.exec(recordingFile, dest, "").get()); MatcherAssert.assertThat( ex.getMessage(), Matchers.containsString( @@ -289,7 +249,7 @@ public Path answer(InvocationOnMock invocation) throws Throwable { } }); - Path result = generator.exec(recordingDescriptor, "", true).get(); + Path result = generator.exec(recordingDescriptor, "").get(); MatcherAssert.assertThat(result, Matchers.sameInstance(tempFile2)); Mockito.verify(fs).deleteIfExists(tempFile1); @@ -313,50 +273,9 @@ public Path answer(InvocationOnMock invocation) throws Throwable { Assertions.assertThrows( ExecutionException.class, () -> { - generator.exec(recordingDescriptor, "", true).get(); + generator.exec(recordingDescriptor, "").get(); }); Mockito.verify(fs).deleteIfExists(tempFile1); } - - @Test - void shouldExecuteProcessAndDeleteTempReportStatsFileOnFailure() throws Exception { - Mockito.when(proc.waitFor(29, TimeUnit.SECONDS)).thenReturn(true); - Mockito.when(proc.exitValue()) - .thenReturn(SubprocessReportGenerator.ExitStatus.NO_SUCH_RECORDING.code); - - Mockito.when(targetConnectionManager.executeConnectedTask(Mockito.any(), Mockito.any())) - .then( - new Answer() { - @Override - public Path answer(InvocationOnMock invocation) throws Throwable { - return fs.createTempFile(null, null); - } - }); - - Assertions.assertThrows( - ExecutionException.class, - () -> { - generator.exec(recordingDescriptor, "", true).get(); - }); - - Mockito.verify(fs).deleteIfExists(Path.of(Variables.REPORT_STATS_PATH)); - } - - static class TestReportTransformer implements ReportTransformer { - @Override - public int priority() { - return 0; - } - - @Override - public String selector() { - return ".test"; - } - - @Override - public String innerHtml(String innerHtml) { - return "Hello World " + innerHtml; - } - } } diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java index ae793138a3..1741942fb4 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java @@ -102,10 +102,9 @@ void shouldHandleCorrectPath() { } @Test - void shouldProduceHtmlAndRawJson() { + void shouldProduceRawJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON_RAW)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON_RAW)); } @Test @@ -132,23 +131,19 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception { "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Future future = CompletableFuture.failedFuture( new RecordingNotFoundException(subdirectoryName, recordingName)); when(reportService.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); ApiException ex = Assertions.assertThrows(ApiException.class, () -> handler.handle(params)); MatcherAssert.assertThat(ex.getStatusCode(), Matchers.equalTo(404)); - verify(reportService).getFromPath(subdirectoryName, recordingName, "", true); + verify(reportService).getFromPath(subdirectoryName, recordingName, ""); } @Test @@ -164,15 +159,11 @@ void shouldRespondBySendingFile() throws Exception { "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Path fakePath = Mockito.mock(Path.class); when(reportService.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -180,7 +171,7 @@ void shouldRespondBySendingFile() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).getFromPath(subdirectoryName, recordingName, "", true); + verify(reportService).getFromPath(subdirectoryName, recordingName, ""); } @Test @@ -197,15 +188,11 @@ void shouldRespondBySendingFileFiltered() throws Exception { "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Path fakePath = Mockito.mock(Path.class); when(reportService.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -213,7 +200,7 @@ void shouldRespondBySendingFileFiltered() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).getFromPath(subdirectoryName, recordingName, "someFilter", true); + verify(reportService).getFromPath(subdirectoryName, recordingName, "someFilter"); } @Test @@ -230,15 +217,11 @@ void shouldRespondBySendingFileUnformatted() throws Exception { "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); Path fakePath = Mockito.mock(Path.class); when(reportService.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -246,7 +229,7 @@ void shouldRespondBySendingFileUnformatted() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).getFromPath(subdirectoryName, recordingName, "someFilter", false); + verify(reportService).getFromPath(subdirectoryName, recordingName, "someFilter"); } } } diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java index 7bfe5ee9df..394b40e6f6 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java @@ -112,10 +112,9 @@ void shouldUseExpectedPath() { } @Test - void shouldProduceHtmlAndJson() { + void shouldProduceJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON)); } @Test @@ -138,18 +137,13 @@ class Behaviour { @Test void shouldRespond404IfNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); Future future = CompletableFuture.failedFuture( new RecordingNotFoundException("mytarget", "myrecording")); - when(reports.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.getFromPath(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); ApiException ex = Assertions.assertThrows( @@ -159,7 +153,7 @@ void shouldRespond404IfNotFound() throws Exception { @Test void shouldSendFileIfFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); @@ -167,25 +161,21 @@ void shouldSendFileIfFound() throws Exception { when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr"); Future future = CompletableFuture.completedFuture(path); - when(reports.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.getFromPath(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).getFromPath("mydirectory", "myrecording", "", true); + verify(reports).getFromPath("mydirectory", "myrecording", ""); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); inOrder.verify(resp).sendFile("foo.jfr"); } @Test void shouldSendFileIfFoundFiltered() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); @@ -194,19 +184,15 @@ void shouldSendFileIfFoundFiltered() throws Exception { when(path.toString()).thenReturn("foo.jfr"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); Future future = CompletableFuture.completedFuture(path); - when(reports.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.getFromPath(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).getFromPath("mydirectory", "myrecording", "someFilter", true); + verify(reports).getFromPath("mydirectory", "myrecording", "someFilter"); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); inOrder.verify(resp).sendFile("foo.jfr"); } @@ -221,16 +207,12 @@ void shouldSendFileIfFoundUnformatted() throws Exception { when(path.toString()).thenReturn("foo.jfr"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); Future future = CompletableFuture.completedFuture(path); - when(reports.getFromPath( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.getFromPath(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).getFromPath("mydirectory", "myrecording", "someFilter", false); + verify(reports).getFromPath("mydirectory", "myrecording", "someFilter"); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetHandlerTest.java index 76b12c8870..c9738cf1ac 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetHandlerTest.java @@ -104,10 +104,9 @@ void shouldHandleCorrectPath() { } @Test - void shouldProduceHtmlAndRawJson() { + void shouldProduceRawJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON_RAW)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON_RAW)); } @Test @@ -130,23 +129,18 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception { .thenReturn( Map.of("sourceTarget", sourceTarget, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Future future = CompletableFuture.failedFuture( new RecordingNotFoundException(sourceTarget, recordingName)); - when(reportService.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); ApiException ex = Assertions.assertThrows(ApiException.class, () -> handler.handle(params)); MatcherAssert.assertThat(ex.getStatusCode(), Matchers.equalTo(404)); - verify(reportService).get(sourceTarget, recordingName, "", true); + verify(reportService).get(sourceTarget, recordingName, ""); } @Test @@ -158,15 +152,10 @@ void shouldRespondBySendingFile() throws Exception { .thenReturn( Map.of("sourceTarget", sourceTarget, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Path fakePath = Mockito.mock(Path.class); - when(reportService.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -174,7 +163,7 @@ void shouldRespondBySendingFile() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).get(sourceTarget, recordingName, "", true); + verify(reportService).get(sourceTarget, recordingName, ""); } @Test @@ -187,15 +176,10 @@ void shouldRespondBySendingFileFiltered() throws Exception { .thenReturn( Map.of("sourceTarget", sourceTarget, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); Path fakePath = Mockito.mock(Path.class); - when(reportService.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -203,7 +187,7 @@ void shouldRespondBySendingFileFiltered() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).get(sourceTarget, recordingName, "someFilter", true); + verify(reportService).get(sourceTarget, recordingName, "someFilter"); } @Test @@ -216,15 +200,10 @@ void shouldRespondBySendingFileUnformatted() throws Exception { .thenReturn( Map.of("sourceTarget", sourceTarget, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); - when(params.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); Path fakePath = Mockito.mock(Path.class); - when(reportService.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); IntermediateResponse response = handler.handle(params); @@ -232,7 +211,7 @@ void shouldRespondBySendingFileUnformatted() throws Exception { MatcherAssert.assertThat(response.getStatusCode(), Matchers.equalTo(200)); MatcherAssert.assertThat(response.getBody(), Matchers.equalTo(fakePath)); - verify(reportService).get(sourceTarget, recordingName, "someFilter", false); + verify(reportService).get(sourceTarget, recordingName, "someFilter"); } } } diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandlerTest.java index df26bc60f2..5c8ebcb106 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetWithJwtHandlerTest.java @@ -112,10 +112,9 @@ void shouldUseExpectedPath() { } @Test - void shouldProduceHtmlAndJson() { + void shouldProduceJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON)); } @Test @@ -138,18 +137,13 @@ class Behaviour { @Test void shouldRespond404IfNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); when(ctx.pathParam("sourceTarget")).thenReturn("mytarget"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); Future future = CompletableFuture.failedFuture( new RecordingNotFoundException("mytarget", "myrecording")); - when(reports.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); ApiException ex = Assertions.assertThrows( @@ -159,7 +153,7 @@ void shouldRespond404IfNotFound() throws Exception { @Test void shouldSendFileIfFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); when(ctx.pathParam("sourceTarget")).thenReturn("mytarget"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); @@ -167,25 +161,21 @@ void shouldSendFileIfFound() throws Exception { when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr"); Future future = CompletableFuture.completedFuture(path); - when(reports.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).get("mytarget", "myrecording", "", true); + verify(reports).get("mytarget", "myrecording", ""); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); inOrder.verify(resp).sendFile("foo.jfr"); } @Test void shouldSendFileIfFoundFiltered() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); when(ctx.pathParam("sourceTarget")).thenReturn("mytarget"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); @@ -194,19 +184,15 @@ void shouldSendFileIfFoundFiltered() throws Exception { when(path.toString()).thenReturn("foo.jfr"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); Future future = CompletableFuture.completedFuture(path); - when(reports.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).get("mytarget", "myrecording", "someFilter", true); + verify(reports).get("mytarget", "myrecording", "someFilter"); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); - inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); inOrder.verify(resp).sendFile("foo.jfr"); } @@ -221,16 +207,12 @@ void shouldSendFileIfFoundUnformatted() throws Exception { when(path.toString()).thenReturn("foo.jfr"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); Future future = CompletableFuture.completedFuture(path); - when(reports.get( - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + when(reports.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(reports).get("mytarget", "myrecording", "someFilter", false); + verify(reports).get("mytarget", "myrecording", "someFilter"); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_DISPOSITION, "inline"); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/ReportGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/ReportGetHandlerTest.java index da3814f3f3..39e776117e 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/ReportGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/ReportGetHandlerTest.java @@ -132,14 +132,14 @@ void shouldRespondBySendingFile() throws Exception { when(ctx.pathParam("recordingName")).thenReturn("someRecording"); when(ctx.queryParam("filter")).thenReturn(List.of()); - when(reportService.get(Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(fakePath)); handler.handle(ctx); when(ctx.pathParam("recordingName")).thenReturn("someRecording"); when(ctx.queryParam("filter")).thenReturn(List.of()); - when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); } @@ -166,14 +166,14 @@ void shouldRespondBySendingFileFiltered() throws Exception { when(ctx.pathParam("recordingName")).thenReturn("someRecording"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); - when(reportService.get(Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(fakePath)); handler.handle(ctx); when(ctx.pathParam("recordingName")).thenReturn("someRecording"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); - when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString())) .thenReturn(CompletableFuture.completedFuture(fakePath)); } @@ -200,16 +200,16 @@ void shouldRespondBySendingFileUnformatted() throws Exception { when(ctx.pathParam("recordingName")).thenReturn("someRecording"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); - when(reportService.get(Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(fakePath)); when(ctx.pathParam("recordingName")).thenReturn("someRecording"); - when(reportService.get(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.anyString())) .thenReturn( CompletableFuture.failedFuture( new RecordingNotFoundException(null, "someRecording"))); - Mockito.verify(reportService).get("someRecording", "someFilter", false); + Mockito.verify(reportService).get("someRecording", "someFilter"); Mockito.verify(resp).sendFile(fakePath.toString()); Mockito.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, "application/json"); Mockito.verify(resp).putHeader(HttpHeaders.CONTENT_LENGTH, "12345"); @@ -230,7 +230,7 @@ void shouldRespond404IfRecordingNameNotFound() throws Exception { .thenReturn(resp); when(ctx.pathParam("recordingName")).thenReturn("someRecording"); - when(reportService.get(Mockito.anyString(), Mockito.any(), Mockito.anyBoolean())) + when(reportService.get(Mockito.anyString(), Mockito.any())) .thenReturn( CompletableFuture.failedFuture( new RecordingNotFoundException(null, "someRecording"))); diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandlerTest.java index 6972d0058e..5ea83a9bd3 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/TargetReportGetHandlerTest.java @@ -96,10 +96,9 @@ void shouldHaveExpectedRequiredPermissions() { } @Test - void shouldProduceHtmlAndJson() { + void shouldProduceJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON)); } } @@ -122,7 +121,7 @@ void setup() { @Test void shouldHandleRecordingDownloadRequest() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); String targetId = "fooHost:0"; String recordingName = "foo"; @@ -130,8 +129,7 @@ void shouldHandleRecordingDownloadRequest() throws Exception { when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(content); Mockito.when(ctx.pathParam("targetId")).thenReturn(targetId); @@ -141,14 +139,14 @@ void shouldHandleRecordingDownloadRequest() throws Exception { handler.handle(ctx); - verify(reportService).get(cd, recordingName, "", true); - verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + verify(reportService).get(cd, recordingName, ""); + verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); verify(resp).end("foobar"); } @Test void shouldHandleRecordingDownloadRequestFiltered() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); String targetId = "fooHost:0"; String recordingName = "foo"; @@ -156,8 +154,7 @@ void shouldHandleRecordingDownloadRequestFiltered() throws Exception { when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(content); Mockito.when(ctx.pathParam("targetId")).thenReturn(targetId); @@ -167,8 +164,8 @@ void shouldHandleRecordingDownloadRequestFiltered() throws Exception { handler.handle(ctx); - verify(reportService).get(cd, recordingName, "someFilter", true); - verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + verify(reportService).get(cd, recordingName, "someFilter"); + verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); verify(resp).end("foobar"); } @@ -182,8 +179,7 @@ void shouldHandleRecordingDownloadRequestUnformatted() throws Exception { when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(content); Mockito.when(ctx.pathParam("targetId")).thenReturn(targetId); @@ -193,20 +189,19 @@ void shouldHandleRecordingDownloadRequestUnformatted() throws Exception { handler.handle(ctx); - verify(reportService).get(cd, recordingName, "someFilter", false); + verify(reportService).get(cd, recordingName, "someFilter"); verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); verify(resp).end("foobar"); } @Test void shouldRespond404IfRecordingNameNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenThrow( new CompletionException( new RecordingNotFoundException("fooHost:0", "someRecording"))); @@ -222,7 +217,7 @@ void shouldRespond404IfRecordingNameNotFound() throws Exception { @Test void shouldRespond404IfTargetNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); String targetId = "fooHost:0"; String recordingName = "foo"; @@ -236,8 +231,7 @@ void shouldRespond404IfTargetNotFound() throws Exception { when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(content); Mockito.when(ctx.pathParam("targetId")).thenReturn(targetId); @@ -250,7 +244,7 @@ void shouldRespond404IfTargetNotFound() throws Exception { @Test void shouldRespond404IfRecordingNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); String targetId = "fooHost:0"; String recordingName = "foo"; @@ -264,8 +258,7 @@ void shouldRespond404IfRecordingNotFound() throws Exception { when(reportService.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(content); when(ctx.pathParam("targetId")).thenReturn(targetId); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/ReportGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/ReportGetHandlerTest.java index e68f28341e..7a8793ceb2 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/ReportGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/ReportGetHandlerTest.java @@ -122,10 +122,7 @@ void shouldRespond404IfNotFound() throws Exception { Future future = CompletableFuture.failedFuture( new RecordingNotFoundException("archive", "myrecording")); - Mockito.when( - reports.get( - Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) - .thenReturn(future); + Mockito.when(reports.get(Mockito.anyString(), Mockito.anyString())).thenReturn(future); ApiException ex = Assertions.assertThrows( ApiException.class, () -> handler.handleWithValidJwt(ctx, token)); @@ -144,14 +141,11 @@ void shouldSendFileIfFound() throws Exception { Mockito.when(path.toFile()).thenReturn(file); Mockito.when(file.length()).thenReturn(1234L); Future future = CompletableFuture.completedFuture(path); - Mockito.when( - reports.get( - Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) - .thenReturn(future); + Mockito.when(reports.get(Mockito.anyString(), Mockito.anyString())).thenReturn(future); handler.handleWithValidJwt(ctx, token); - Mockito.verify(reports).get("myrecording", "", true); + Mockito.verify(reports).get("myrecording", ""); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, "text/html"); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_LENGTH, "1234"); @@ -171,14 +165,11 @@ void shouldSendFileIfFoundFiltered() throws Exception { Mockito.when(file.length()).thenReturn(1234L); Mockito.when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); Future future = CompletableFuture.completedFuture(path); - Mockito.when( - reports.get( - Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) - .thenReturn(future); + Mockito.when(reports.get(Mockito.anyString(), Mockito.anyString())).thenReturn(future); handler.handleWithValidJwt(ctx, token); - Mockito.verify(reports).get("myrecording", "someFilter", true); + Mockito.verify(reports).get("myrecording", "someFilter"); InOrder inOrder = Mockito.inOrder(resp); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, "text/html"); inOrder.verify(resp).putHeader(HttpHeaders.CONTENT_LENGTH, "1234"); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandlerTest.java index c8a1ec6489..af3ece187d 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/TargetReportGetHandlerTest.java @@ -104,10 +104,9 @@ void shouldRequireResourceActions() { } @Test - void shouldProduceHtmlAndJson() { + void shouldProduceJson() { MatcherAssert.assertThat( - handler.produces(), - Matchers.containsInAnyOrder(HttpMimeType.HTML, HttpMimeType.JSON)); + handler.produces(), Matchers.containsInAnyOrder(HttpMimeType.JSON)); } @Test @@ -139,7 +138,7 @@ void setup() throws ParseException { @Test void shouldRespond404IfNotFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); Future future = @@ -148,8 +147,7 @@ void shouldRespond404IfNotFound() throws Exception { when(reports.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(future); ApiException ex = Assertions.assertThrows( @@ -159,7 +157,7 @@ void shouldRespond404IfNotFound() throws Exception { @Test void shouldSendFileIfFound() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); when(ctx.queryParam("filter")).thenReturn(List.of()); @@ -167,25 +165,23 @@ void shouldSendFileIfFound() throws Exception { when(reports.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); verify(resp).end("report text"); verify(reports) .get( Mockito.any(ConnectionDescriptor.class), Mockito.eq("myrecording"), - Mockito.eq(""), - Mockito.eq(true)); + Mockito.eq("")); } @Test void shouldSendFileIfFoundFiltered() throws Exception { - when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.HTML.mime()); + when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); when(ctx.queryParam("filter")).thenReturn(List.of("someFilter")); @@ -193,20 +189,18 @@ void shouldSendFileIfFoundFiltered() throws Exception { when(reports.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); - verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.HTML.mime()); + verify(resp).putHeader(HttpHeaders.CONTENT_TYPE, HttpMimeType.JSON.mime()); verify(resp).end("report text"); verify(reports) .get( Mockito.any(ConnectionDescriptor.class), Mockito.eq("myrecording"), - Mockito.eq("someFilter"), - Mockito.eq(true)); + Mockito.eq("someFilter")); } @Test @@ -219,8 +213,7 @@ void shouldSendFileIfFoundUnformatted() throws Exception { when(reports.get( Mockito.any(ConnectionDescriptor.class), Mockito.anyString(), - Mockito.anyString(), - Mockito.anyBoolean())) + Mockito.anyString())) .thenReturn(future); handler.handleWithValidJwt(ctx, token); @@ -231,8 +224,7 @@ void shouldSendFileIfFoundUnformatted() throws Exception { .get( Mockito.any(ConnectionDescriptor.class), Mockito.eq("myrecording"), - Mockito.eq("someFilter"), - Mockito.eq(false)); + Mockito.eq("someFilter")); } } } diff --git a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java index 411a2c8c41..ee6c77f426 100644 --- a/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java +++ b/src/test/java/io/cryostat/recordings/RecordingTargetHelperTest.java @@ -211,10 +211,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ArgumentCaptor connectionDescriptorCaptor = ArgumentCaptor.forClass(ConnectionDescriptor.class); Mockito.verify(reportService) - .delete( - connectionDescriptorCaptor.capture(), - Mockito.eq(recordingName), - Mockito.eq(true)); + .delete(connectionDescriptorCaptor.capture(), Mockito.eq(recordingName)); MatcherAssert.assertThat( connectionDescriptorCaptor.getValue().getTargetId(), Matchers.equalTo(connectionDescriptor.getTargetId())); @@ -264,10 +261,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable { ArgumentCaptor connectionDescriptorCaptor = ArgumentCaptor.forClass(ConnectionDescriptor.class); Mockito.verify(reportService) - .delete( - connectionDescriptorCaptor.capture(), - Mockito.eq(recordingName), - Mockito.eq(true)); + .delete(connectionDescriptorCaptor.capture(), Mockito.eq(recordingName)); MatcherAssert.assertThat( connectionDescriptorCaptor.getValue().getTargetId(), Matchers.equalTo(connectionDescriptor.getTargetId())); diff --git a/src/test/java/itest/ArchivedReportJwtDownloadIT.java b/src/test/java/itest/ArchivedReportJwtDownloadIT.java index 1906fba814..ffe39fd6bb 100644 --- a/src/test/java/itest/ArchivedReportJwtDownloadIT.java +++ b/src/test/java/itest/ArchivedReportJwtDownloadIT.java @@ -55,9 +55,9 @@ void testDownloadRecordingUsingJwt() throws Exception { getTokenDownloadUrl( new URL(reportUrl.toString().replace("/api/v1/", "/api/v2.1/"))); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); - headers.add(HttpHeaders.ACCEPT.toString(), HttpMimeType.HTML.mime()); + headers.add(HttpHeaders.ACCEPT.toString(), HttpMimeType.JSON.mime()); assetDownload = - downloadFileAbs(downloadUrl, TEST_RECORDING_NAME, ".html", headers) + downloadFileAbs(downloadUrl, TEST_RECORDING_NAME, ".json", headers) .get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); Assertions.assertTrue(Files.isReadable(assetDownload)); Assertions.assertTrue(Files.isRegularFile(assetDownload)); diff --git a/src/test/java/itest/FileSystemArchivedRequestsIT.java b/src/test/java/itest/FileSystemArchivedRequestsIT.java index 59e5e740fd..cfd01bbfc9 100644 --- a/src/test/java/itest/FileSystemArchivedRequestsIT.java +++ b/src/test/java/itest/FileSystemArchivedRequestsIT.java @@ -157,16 +157,16 @@ void testGetRecordingsAndDirectories() throws Exception { downloadFileAbs( getTokenDownloadUrl(badReportUrl), TEST_RECORDING_NAME, - ".html") + ".json") .get()); // get recording report fromPath MultiMap headers = MultiMap.caseInsensitiveMultiMap(); - headers.add(HttpHeaders.ACCEPT, HttpMimeType.HTML.mime()); + headers.add(HttpHeaders.ACCEPT, HttpMimeType.JSON.mime()); URL reportUrl = new URL(updatedArchivedRecording.getString("reportUrl")); String downloadUrl = getTokenDownloadUrl(new URL(reportUrl.toString())); assetDownload = - downloadFileAbs(downloadUrl, TEST_RECORDING_NAME, ".html", headers) + downloadFileAbs(downloadUrl, TEST_RECORDING_NAME, ".json", headers) .get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); Assertions.assertTrue(Files.isReadable(assetDownload)); Assertions.assertTrue(Files.isRegularFile(assetDownload)); diff --git a/src/test/java/itest/RecordingWorkflowIT.java b/src/test/java/itest/RecordingWorkflowIT.java index e1e6a0bb02..af1df95f82 100644 --- a/src/test/java/itest/RecordingWorkflowIT.java +++ b/src/test/java/itest/RecordingWorkflowIT.java @@ -18,6 +18,7 @@ import java.io.File; import java.nio.file.Path; import java.util.List; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -25,6 +26,7 @@ import io.cryostat.net.web.http.HttpMimeType; +import com.fasterxml.jackson.databind.ObjectMapper; import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpHeaders; @@ -36,9 +38,6 @@ import jdk.jfr.consumer.RecordingFile; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.select.Elements; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -209,26 +208,18 @@ public void testWorkflow() throws Exception { String reportUrl = recordingInfo.getString("reportUrl"); MultiMap headers = MultiMap.caseInsensitiveMultiMap(); - headers.add(HttpHeaders.ACCEPT.toString(), HttpMimeType.HTML.mime()); + headers.add(HttpHeaders.ACCEPT.toString(), HttpMimeType.JSON.mime()); Path reportPath = - downloadFileAbs(reportUrl, TEST_RECORDING_NAME + "_report", ".html", headers) + downloadFileAbs(reportUrl, TEST_RECORDING_NAME + "_report", ".json", headers) .get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); File reportFile = reportPath.toFile(); MatcherAssert.assertThat(reportFile.length(), Matchers.greaterThan(0L)); - Document doc = Jsoup.parse(reportFile, "UTF-8"); - Elements head = doc.getElementsByTag("head"); - Elements titles = head.first().getElementsByTag("title"); - Elements body = doc.getElementsByTag("body"); - Elements script = head.first().getElementsByTag("script"); - - MatcherAssert.assertThat("Expected one ", head.size(), Matchers.equalTo(1)); - MatcherAssert.assertThat(titles.size(), Matchers.equalTo(1)); - MatcherAssert.assertThat("Expected one ", body.size(), Matchers.equalTo(1)); + ObjectMapper mapper = new ObjectMapper(); + Map response = mapper.readValue(reportFile, Map.class); + MatcherAssert.assertThat(response, Matchers.notNullValue()); MatcherAssert.assertThat( - "Expected at least one