Search in sources :

Example 76 with StormMetricsRegistry

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

the class BasicContainerTest method testCleanUp.

@Test
public void testCleanUp() throws Exception {
    final String topoId = "test_topology";
    final int supervisorPort = 6628;
    final int port = 8080;
    final String workerId = "worker-id";
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    Map<String, Object> superConf = new HashMap<>();
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    Map<String, Integer> workerState = new HashMap<String, Integer>();
    workerState.put(workerId, port);
    LocalState ls = mock(LocalState.class);
    when(ls.getApprovedWorkers()).thenReturn(new HashMap<>(workerState));
    ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
    mc.cleanUp();
    assertNull(mc.workerId);
    verify(ls).getApprovedWorkers();
    Map<String, Integer> expectedNewState = new HashMap<String, Integer>();
    verify(ls).setApprovedWorkers(expectedNewState);
}
Also used : HashMap(java.util.HashMap) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) ResourceIsolationInterface(org.apache.storm.container.ResourceIsolationInterface) Test(org.junit.Test)

Example 77 with StormMetricsRegistry

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

the class BasicContainerTest method testSubstChildOpts.

@Test
public void testSubstChildOpts() throws Exception {
    String workerId = "w-01";
    String topoId = "s-01";
    int supervisorPort = 6628;
    int port = 9999;
    int memOnheap = 512;
    int memOffheap = 256;
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    Map<String, Object> superConf = new HashMap<>();
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    LocalState ls = mock(LocalState.class);
    ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
    assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m", "-XX:MaxDirectMemorySize=256m"), mc.substituteChildopts("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log -Xms256m -Xmx%HEAP-MEM%m -XX:MaxDirectMemorySize=%OFF-HEAP-MEM%m", memOnheap, memOffheap));
    assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m"), mc.substituteChildopts(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log", "-Xms256m", "-Xmx%HEAP-MEM%m"), memOnheap, memOffheap));
    assertListEquals(Collections.emptyList(), mc.substituteChildopts(null));
}
Also used : HashMap(java.util.HashMap) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) ResourceIsolationInterface(org.apache.storm.container.ResourceIsolationInterface) Test(org.junit.Test)

Example 78 with StormMetricsRegistry

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

the class BasicContainerTest method testRecovery.

@Test
public void testRecovery() throws Exception {
    final String topoId = "test_topology";
    final String workerId = "myWorker";
    final int supervisorPort = 6628;
    final int port = 8080;
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    Map<String, Integer> workerState = new HashMap<String, Integer>();
    workerState.put(workerId, port);
    LocalState ls = mock(LocalState.class);
    when(ls.getApprovedWorkers()).thenReturn(workerState);
    Map<String, Object> superConf = new HashMap<>();
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.RECOVER_FULL, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, null, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
    assertEquals(workerId, mc.workerId);
}
Also used : HashMap(java.util.HashMap) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) ResourceIsolationInterface(org.apache.storm.container.ResourceIsolationInterface) Test(org.junit.Test)

Example 79 with StormMetricsRegistry

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

the class BasicContainerTest method testCreateNewWorkerId.

@Test
public void testCreateNewWorkerId() throws Exception {
    final String topoId = "test_topology";
    final int supervisorPort = 6628;
    final int port = 8080;
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    Map<String, Object> superConf = new HashMap<>();
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    LocalState ls = mock(LocalState.class);
    ResourceIsolationInterface iso = mock(ResourceIsolationInterface.class);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, null, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
    // null worker id means generate one...
    assertNotNull(mc.workerId);
    verify(ls).getApprovedWorkers();
    Map<String, Integer> expectedNewState = new HashMap<String, Integer>();
    expectedNewState.put(mc.workerId, port);
    verify(ls).setApprovedWorkers(expectedNewState);
}
Also used : HashMap(java.util.HashMap) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) ResourceIsolationInterface(org.apache.storm.container.ResourceIsolationInterface) Test(org.junit.Test)

Example 80 with StormMetricsRegistry

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

the class BasicContainerTest method testRunProfiling.

@Test
public void testRunProfiling() throws Exception {
    final long pid = 100;
    final String topoId = "test_topology";
    final int supervisorPort = 6628;
    final int port = 8080;
    final String workerId = "worker-id";
    final String stormLocal = ContainerTest.asAbsPath("tmp", "testing");
    final String topoRoot = ContainerTest.asAbsPath(stormLocal, topoId, String.valueOf(port));
    final File workerArtifactsPid = ContainerTest.asAbsFile(topoRoot, "worker.pid");
    final Map<String, Object> superConf = new HashMap<>();
    superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
    superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
    when(ops.slurpString(workerArtifactsPid)).thenReturn(String.valueOf(pid));
    LocalState ls = mock(LocalState.class);
    MockResourceIsolationManager iso = new MockResourceIsolationManager();
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
    // HEAP DUMP
    ProfileRequest req = new ProfileRequest();
    req.set_action(ProfileAction.JMAP_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, iso.profileCmds.size());
    CommandRun cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "jmap", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    // JSTACK DUMP
    req.set_action(ProfileAction.JSTACK_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, iso.profileCmds.size());
    cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "jstack", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    // RESTART
    req.set_action(ProfileAction.JVM_RESTART);
    mc.runProfiling(req, false);
    assertEquals(1, iso.profileCmds.size());
    cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "kill"), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    // JPROFILE DUMP
    req.set_action(ProfileAction.JPROFILE_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, iso.profileCmds.size());
    cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "dump", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    // JPROFILE START
    req.set_action(ProfileAction.JPROFILE_STOP);
    mc.runProfiling(req, false);
    assertEquals(1, iso.profileCmds.size());
    cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "start"), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
    // JPROFILE STOP
    req.set_action(ProfileAction.JPROFILE_STOP);
    mc.runProfiling(req, true);
    assertEquals(1, iso.profileCmds.size());
    cmd = iso.profileCmds.get(0);
    iso.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "stop", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
}
Also used : MockResourceIsolationManager(org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager) HashMap(java.util.HashMap) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ProfileRequest(org.apache.storm.generated.ProfileRequest) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) 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