Search in sources :

Example 6 with StormMetricsRegistry

use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.

the class LogCleanerTest method testPerWorkerDirectoryCleanup.

/**
 * cleaner deletes oldest files in each worker dir if files are larger than per-dir quota.
 */
@Test
public void testPerWorkerDirectoryCleanup() throws IOException {
    long nowMillis = Time.currentTimeMillis();
    try (TmpPath testDir = new TmpPath()) {
        Files.createDirectories(testDir.getFile().toPath());
        Path rootDir = createDir(testDir.getFile().toPath(), "workers-artifacts");
        Path topo1Dir = createDir(rootDir, "topo1");
        Path topo2Dir = createDir(rootDir, "topo2");
        Path port1Dir = createDir(topo1Dir, "port1");
        Path port2Dir = createDir(topo1Dir, "port2");
        Path port3Dir = createDir(topo2Dir, "port3");
        Seq.range(0, 10).forEach(idx -> createFile(port1Dir, "A" + idx, nowMillis + 100 * idx, 200));
        Seq.range(0, 10).forEach(idx -> createFile(port2Dir, "B" + idx, nowMillis + 100 * idx, 200));
        Seq.range(0, 10).forEach(idx -> createFile(port3Dir, "C" + idx, nowMillis + 100 * idx, 200));
        Map<String, Object> conf = Utils.readStormConfig();
        StormMetricsRegistry metricRegistry = new StormMetricsRegistry();
        WorkerLogs workerLogs = new WorkerLogs(conf, rootDir, metricRegistry);
        LogCleaner logCleaner = new LogCleaner(conf, workerLogs, new DirectoryCleaner(metricRegistry), rootDir, metricRegistry);
        List<Integer> deletedFiles = logCleaner.perWorkerDirCleanup(1200).stream().map(deletionMeta -> deletionMeta.deletedFiles).collect(toList());
        assertEquals(Integer.valueOf(4), deletedFiles.get(0));
        assertEquals(Integer.valueOf(4), deletedFiles.get(1));
        assertEquals(Integer.valueOf(4), deletedFiles.get(deletedFiles.size() - 1));
    }
}
Also used : Path(java.nio.file.Path) TmpPath(org.apache.storm.testing.TmpPath) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) SUPERVISOR_WORKER_TIMEOUT_SECS(org.apache.storm.Config.SUPERVISOR_WORKER_TIMEOUT_SECS) FileTime(java.nio.file.attribute.FileTime) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) SupervisorUtils(org.apache.storm.daemon.supervisor.SupervisorUtils) Seq(org.jooq.lambda.Seq) TreeSet(java.util.TreeSet) Assert.assertThat(org.junit.Assert.assertThat) DirectoryStream(java.nio.file.DirectoryStream) Sets(org.mockito.internal.util.collections.Sets) Map(java.util.Map) LSWorkerHeartbeat(org.apache.storm.generated.LSWorkerHeartbeat) Path(java.nio.file.Path) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Iterator(java.util.Iterator) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) ThreadLocalRandom(org.apache.storm.shade.io.netty.util.internal.ThreadLocalRandom) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Utils(org.apache.storm.utils.Utils) File(java.io.File) LOGVIEWER_CLEANUP_INTERVAL_SECS(org.apache.storm.DaemonConfig.LOGVIEWER_CLEANUP_INTERVAL_SECS) UncheckedIOException(java.io.UncheckedIOException) Time(org.apache.storm.utils.Time) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) TmpPath(org.apache.storm.testing.TmpPath) LOGVIEWER_CLEANUP_AGE_MINS(org.apache.storm.DaemonConfig.LOGVIEWER_CLEANUP_AGE_MINS) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) TmpPath(org.apache.storm.testing.TmpPath) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Test(org.junit.jupiter.api.Test)

Example 7 with StormMetricsRegistry

use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.

the class DRPCServerTest method testFailedThrift.

@Test
public void testFailedThrift() throws Exception {
    Map<String, Object> conf = getConf(0, 0, null);
    try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
        server.start();
        try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort());
            DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
            Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test"));
            DRPCRequest request = getNextAvailableRequest(invoke, "testing");
            assertNotNull(request);
            assertEquals("test", request.get_func_args());
            assertNotNull(request.get_request_id());
            invoke.failRequest(request.get_request_id());
            try {
                found.get(1000, TimeUnit.MILLISECONDS);
                fail("exec did not throw an exception");
            } catch (ExecutionException e) {
                Throwable t = e.getCause();
                assertEquals(t.getClass(), DRPCExecutionException.class);
                // Don't know a better way to validate that it failed.
                assertEquals("Request failed", ((DRPCExecutionException) t).get_msg());
            }
        }
    }
}
Also used : DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) DRPCClient(org.apache.storm.utils.DRPCClient) ExecutionException(java.util.concurrent.ExecutionException) DRPCExecutionException(org.apache.storm.generated.DRPCExecutionException) Test(org.junit.Test)

Example 8 with StormMetricsRegistry

use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.

the class DRPCServerTest method testGoodHttpGet.

@Test
public void testGoodHttpGet() throws Exception {
    LOG.info("STARTING HTTP GET TEST...");
    Map<String, Object> conf = getConf(0, 0, 0);
    try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
        server.start();
        // TODO need a better way to do this
        Thread.sleep(2000);
        try (DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
            final Future<String> found = exec.submit(() -> doGet(server.getHttpServerPort(), "testing", "test"));
            DRPCRequest request = getNextAvailableRequest(invoke, "testing");
            assertNotNull(request);
            assertEquals("test", request.get_func_args());
            assertNotNull(request.get_request_id());
            invoke.result(request.get_request_id(), "tested");
            String result = found.get(1000, TimeUnit.MILLISECONDS);
            assertEquals("tested", result);
        }
    }
}
Also used : DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Test(org.junit.Test)

Example 9 with StormMetricsRegistry

use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.

the class DRPCServerTest method testGoodThrift.

@Test
public void testGoodThrift() throws Exception {
    Map<String, Object> conf = getConf(0, 0, null);
    try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
        server.start();
        try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort());
            DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
            final Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test"));
            DRPCRequest request = getNextAvailableRequest(invoke, "testing");
            assertNotNull(request);
            assertEquals("test", request.get_func_args());
            assertNotNull(request.get_request_id());
            invoke.result(request.get_request_id(), "tested");
            String result = found.get(1000, TimeUnit.MILLISECONDS);
            assertEquals("tested", result);
        }
    }
}
Also used : DRPCInvocationsClient(org.apache.storm.drpc.DRPCInvocationsClient) DRPCRequest(org.apache.storm.generated.DRPCRequest) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) DRPCClient(org.apache.storm.utils.DRPCClient) Test(org.junit.Test)

Example 10 with StormMetricsRegistry

use of org.apache.storm.metric.StormMetricsRegistry 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)

Aggregations

StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)123 Cluster (org.apache.storm.scheduler.Cluster)67 Topologies (org.apache.storm.scheduler.Topologies)66 Config (org.apache.storm.Config)64 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)64 HashMap (java.util.HashMap)63 Test (org.junit.Test)62 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)61 INimbus (org.apache.storm.scheduler.INimbus)60 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)54 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)53 DaemonConfig (org.apache.storm.DaemonConfig)41 Test (org.junit.jupiter.api.Test)40 ResourceAwareScheduler (org.apache.storm.scheduler.resource.ResourceAwareScheduler)34 HashSet (java.util.HashSet)29 Map (java.util.Map)29 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)27 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)27 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)26 StormTopology (org.apache.storm.generated.StormTopology)24