Search in sources :

Example 1 with ResourceAuthorizer

use of org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer in project storm by apache.

the class LogviewerLogDownloadHandlerTest method createHandlerTraversalTests.

private LogviewerLogDownloadHandler createHandlerTraversalTests(Path rootPath) throws IOException {
    Path daemonLogRoot = rootPath.resolve("logs");
    Path fileOutsideDaemonRoot = rootPath.resolve("evil.sh");
    Path workerLogRoot = daemonLogRoot.resolve("workers-artifacts");
    Path daemonFile = daemonLogRoot.resolve("nimbus.log");
    Path topoA = workerLogRoot.resolve("topoA");
    Path file1 = topoA.resolve("1111").resolve("worker.log");
    Path file2 = topoA.resolve("2222").resolve("worker.log");
    Path file3 = workerLogRoot.resolve("topoB").resolve("1111").resolve("worker.log");
    Files.createDirectories(file1.getParent());
    Files.createDirectories(file2.getParent());
    Files.createDirectories(file3.getParent());
    Files.createFile(file1);
    Files.createFile(file2);
    Files.createFile(file3);
    Files.createFile(fileOutsideDaemonRoot);
    Files.createFile(daemonFile);
    Map<String, Object> stormConf = Utils.readStormConfig();
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    return new LogviewerLogDownloadHandler(workerLogRoot.toString(), daemonLogRoot.toString(), new WorkerLogs(stormConf, workerLogRoot, metricsRegistry), new ResourceAuthorizer(stormConf), metricsRegistry);
}
Also used : TmpPath(org.apache.storm.testing.TmpPath) Path(java.nio.file.Path) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WorkerLogs(org.apache.storm.daemon.logviewer.utils.WorkerLogs) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer)

Example 2 with ResourceAuthorizer

use of org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer in project storm by apache.

the class LogviewerLogSearchHandlerTest method getSearchHandlerWithPort.

private static LogviewerLogSearchHandler getSearchHandlerWithPort(int port) {
    Map<String, Object> stormConf = Utils.readStormConfig();
    stormConf.put(DaemonConfig.LOGVIEWER_PORT, port);
    return new LogviewerLogSearchHandler(stormConf, Paths.get(""), Paths.get(""), new ResourceAuthorizer(stormConf), new StormMetricsRegistry());
}
Also used : StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer)

Example 3 with ResourceAuthorizer

use of org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer in project storm by apache.

the class LogviewerLogPageHandlerTest method testListLogFiles.

/**
 * list-log-files filter selects the correct log files to return.
 */
@Test
public void testListLogFiles() throws IOException {
    String rootPath = Files.createTempDirectory("workers-artifacts").toFile().getCanonicalPath();
    File file1 = new File(String.join(File.separator, rootPath, "topoA", "1111"), "worker.log");
    File file2 = new File(String.join(File.separator, rootPath, "topoA", "2222"), "worker.log");
    File file3 = new File(String.join(File.separator, rootPath, "topoB", "1111"), "worker.log");
    file1.getParentFile().mkdirs();
    file2.getParentFile().mkdirs();
    file3.getParentFile().mkdirs();
    file1.createNewFile();
    file2.createNewFile();
    file3.createNewFile();
    String origin = "www.origin.server.net";
    Map<String, Object> stormConf = Utils.readStormConfig();
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    LogviewerLogPageHandler handler = new LogviewerLogPageHandler(rootPath, rootPath, new WorkerLogs(stormConf, Paths.get(rootPath), metricsRegistry), new ResourceAuthorizer(stormConf), metricsRegistry);
    final Response expectedAll = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoA/port1/worker.log", "topoA/port2/worker.log", "topoB/port1/worker.log"), null, origin);
    final Response expectedFilterPort = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoA/port1/worker.log", "topoB/port1/worker.log"), null, origin);
    final Response expectedFilterTopoId = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoB/port1/worker.log"), null, origin);
    final Response returnedAll = handler.listLogFiles("user", null, null, null, origin);
    final Response returnedFilterPort = handler.listLogFiles("user", 1111, null, null, origin);
    final Response returnedFilterTopoId = handler.listLogFiles("user", null, "topoB", null, origin);
    Utils.forceDelete(rootPath);
    assertEqualsJsonResponse(expectedAll, returnedAll, List.class);
    assertEqualsJsonResponse(expectedFilterPort, returnedFilterPort, List.class);
    assertEqualsJsonResponse(expectedFilterTopoId, returnedFilterTopoId, List.class);
}
Also used : Response(javax.ws.rs.core.Response) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) WorkerLogs(org.apache.storm.daemon.logviewer.utils.WorkerLogs) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer) File(java.io.File) Test(org.junit.Test)

Example 4 with ResourceAuthorizer

use of org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer in project storm by apache.

the class LogviewerLogPageHandlerTest method createHandlerForTraversalTests.

private LogviewerLogPageHandler createHandlerForTraversalTests(Path rootPath) throws IOException {
    Path daemonLogRoot = rootPath.resolve("logs");
    Path fileOutsideDaemonRoot = rootPath.resolve("evil.sh");
    Path daemonFile = daemonLogRoot.resolve("nimbus.log");
    Path workerLogRoot = daemonLogRoot.resolve("workers-artifacts");
    Path topoA = workerLogRoot.resolve("topoA");
    Path file1 = topoA.resolve("1111").resolve("worker.log");
    Path file2 = topoA.resolve("2222").resolve("worker.log");
    Path file3 = workerLogRoot.resolve("topoB").resolve("1111").resolve("worker.log");
    Files.createDirectories(file1.getParent());
    Files.createDirectories(file2.getParent());
    Files.createDirectories(file3.getParent());
    Files.createFile(file1);
    Files.createFile(file2);
    Files.createFile(file3);
    Files.createFile(fileOutsideDaemonRoot);
    Files.createFile(daemonFile);
    Map<String, Object> stormConf = Utils.readStormConfig();
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    return new LogviewerLogPageHandler(workerLogRoot.toString(), daemonLogRoot.toString(), new WorkerLogs(stormConf, workerLogRoot, metricsRegistry), new ResourceAuthorizer(stormConf), metricsRegistry);
}
Also used : TmpPath(org.apache.storm.testing.TmpPath) Path(java.nio.file.Path) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) WorkerLogs(org.apache.storm.daemon.logviewer.utils.WorkerLogs) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer)

Example 5 with ResourceAuthorizer

use of org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer in project storm by apache.

the class LogviewerProfileHandlerTest method createHandlerTraversalTests.

private LogviewerProfileHandler createHandlerTraversalTests(Path rootPath) throws IOException {
    Path daemonLogRoot = rootPath.resolve("logs");
    Path fileOutsideDaemonRoot = rootPath.resolve("evil.bin");
    Path workerLogRoot = daemonLogRoot.resolve("workers-artifacts");
    Path daemonFile = daemonLogRoot.resolve("daemon-dump.bin");
    Path topoA = workerLogRoot.resolve("topoA");
    Path file1 = topoA.resolve("1111").resolve("worker.jfr");
    Path file2 = topoA.resolve("2222").resolve("worker.bin");
    Path file3 = workerLogRoot.resolve("topoB").resolve("1111").resolve("worker.txt");
    Files.createDirectories(file1.getParent());
    Files.createDirectories(file2.getParent());
    Files.createDirectories(file3.getParent());
    Files.write(file1, "TopoA jfr".getBytes(StandardCharsets.UTF_8));
    Files.write(file3, "TopoB txt".getBytes(StandardCharsets.UTF_8));
    Files.createFile(file2);
    Files.createFile(fileOutsideDaemonRoot);
    Files.createFile(daemonFile);
    Map<String, Object> stormConf = Utils.readStormConfig();
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    return new LogviewerProfileHandler(workerLogRoot.toString(), new ResourceAuthorizer(stormConf), metricsRegistry);
}
Also used : TmpPath(org.apache.storm.testing.TmpPath) Path(java.nio.file.Path) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ResourceAuthorizer(org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer)

Aggregations

ResourceAuthorizer (org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer)5 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)5 Path (java.nio.file.Path)3 WorkerLogs (org.apache.storm.daemon.logviewer.utils.WorkerLogs)3 TmpPath (org.apache.storm.testing.TmpPath)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 File (java.io.File)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1