Search in sources :

Example 16 with LocalAssignment

use of org.apache.storm.generated.LocalAssignment in project storm by apache.

the class AsyncLocalizerTest method testRequestDownloadBaseTopologyBlobs.

@Test
public void testRequestDownloadBaseTopologyBlobs() throws Exception {
    final String topoId = "TOPO";
    LocalAssignment la = new LocalAssignment();
    la.set_topology_id(topoId);
    ExecutorInfo ei = new ExecutorInfo();
    ei.set_task_start(1);
    ei.set_task_end(1);
    la.add_to_executors(ei);
    final int port = 8080;
    final String jarKey = topoId + "-stormjar.jar";
    final String codeKey = topoId + "-stormcode.ser";
    final String confKey = topoId + "-stormconf.ser";
    final String stormLocal = "/tmp/storm-local/";
    final String stormRoot = stormLocal + topoId + "/";
    final File fStormRoot = new File(stormRoot);
    ClientBlobStore blobStore = mock(ClientBlobStore.class);
    Map<String, Object> conf = new HashMap<>();
    conf.put(Config.SUPERVISOR_BLOBSTORE, ClientBlobStore.class.getName());
    conf.put(Config.STORM_PRINCIPAL_TO_LOCAL_PLUGIN, DefaultPrincipalToLocal.class.getName());
    conf.put(Config.STORM_CLUSTER_MODE, "distributed");
    conf.put(Config.STORM_LOCAL_DIR, stormLocal);
    Localizer localizer = mock(Localizer.class);
    AdvancedFSOps ops = mock(AdvancedFSOps.class);
    ConfigUtils mockedCU = mock(ConfigUtils.class);
    Utils mockedU = mock(Utils.class);
    Map<String, Object> topoConf = new HashMap<>(conf);
    AsyncLocalizer al = new AsyncLocalizer(conf, localizer, ops);
    ConfigUtils orig = ConfigUtils.setInstance(mockedCU);
    Utils origUtils = Utils.setInstance(mockedU);
    try {
        when(mockedCU.supervisorStormDistRootImpl(conf, topoId)).thenReturn(stormRoot);
        when(mockedCU.supervisorLocalDirImpl(conf)).thenReturn(stormLocal);
        when(mockedU.newInstanceImpl(ClientBlobStore.class)).thenReturn(blobStore);
        when(mockedCU.readSupervisorStormConfImpl(conf, topoId)).thenReturn(topoConf);
        Future<Void> f = al.requestDownloadBaseTopologyBlobs(la, port);
        f.get(20, TimeUnit.SECONDS);
        // We should be done now...
        verify(blobStore).prepare(conf);
        verify(mockedU).downloadResourcesAsSupervisorImpl(eq(jarKey), startsWith(stormLocal), eq(blobStore));
        verify(mockedU).downloadResourcesAsSupervisorImpl(eq(codeKey), startsWith(stormLocal), eq(blobStore));
        verify(mockedU).downloadResourcesAsSupervisorImpl(eq(confKey), startsWith(stormLocal), eq(blobStore));
        verify(blobStore).shutdown();
        //Extracting the dir from the jar
        verify(mockedU).extractDirFromJarImpl(endsWith("stormjar.jar"), eq("resources"), any(File.class));
        verify(ops).moveDirectoryPreferAtomic(any(File.class), eq(fStormRoot));
        verify(ops).setupStormCodeDir(topoConf, fStormRoot);
        verify(ops, never()).deleteIfExists(any(File.class));
    } finally {
        al.shutdown();
        ConfigUtils.setInstance(orig);
        Utils.setInstance(origUtils);
    }
}
Also used : ClientBlobStore(org.apache.storm.blobstore.ClientBlobStore) HashMap(java.util.HashMap) ConfigUtils(org.apache.storm.utils.ConfigUtils) Localizer(org.apache.storm.localizer.Localizer) DefaultPrincipalToLocal(org.apache.storm.security.auth.DefaultPrincipalToLocal) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) Utils(org.apache.storm.utils.Utils) ConfigUtils(org.apache.storm.utils.ConfigUtils) LocalAssignment(org.apache.storm.generated.LocalAssignment) File(java.io.File) AdvancedFSOps(org.apache.storm.daemon.supervisor.AdvancedFSOps) Test(org.junit.Test)

Example 17 with LocalAssignment

use of org.apache.storm.generated.LocalAssignment 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 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);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, workerId, new HashMap<>(), ops, "profile");
    //HEAP DUMP
    ProfileRequest req = new ProfileRequest();
    req.set_action(ProfileAction.JMAP_DUMP);
    mc.runProfiling(req, false);
    assertEquals(1, mc.profileCmds.size());
    CommandRun cmd = mc.profileCmds.get(0);
    mc.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, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.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, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.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, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.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, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.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, mc.profileCmds.size());
    cmd = mc.profileCmds.get(0);
    mc.profileCmds.clear();
    assertEquals(Arrays.asList("profile", String.valueOf(pid), "stop", topoRoot), cmd.cmd);
    assertEquals(new File(topoRoot), cmd.pwd);
}
Also used : HashMap(java.util.HashMap) 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)

Example 18 with LocalAssignment

use of org.apache.storm.generated.LocalAssignment in project storm by apache.

the class BasicContainerTest method testCleanUp.

@Test
public void testCleanUp() throws Exception {
    final String topoId = "test_topology";
    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));
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, workerId, 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) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 19 with LocalAssignment

use of org.apache.storm.generated.LocalAssignment 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 port = 9999;
    int memOnheap = 512;
    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);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, workerId, new HashMap<>(), ops, "profile");
    assertListEquals(Arrays.asList("-Xloggc:/tmp/storm/logs/gc.worker-9999-s-01-w-01-9999.log", "-Xms256m", "-Xmx512m"), mc.substituteChildopts("-Xloggc:/tmp/storm/logs/gc.worker-%ID%-%TOPOLOGY-ID%-%WORKER-ID%-%WORKER-PORT%.log -Xms256m -Xmx%HEAP-MEM%m", memOnheap));
    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));
    assertListEquals(Collections.emptyList(), mc.substituteChildopts(null));
}
Also used : HashMap(java.util.HashMap) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Example 20 with LocalAssignment

use of org.apache.storm.generated.LocalAssignment in project storm by apache.

the class BasicContainerTest method testCreateNewWorkerId.

@Test
public void testCreateNewWorkerId() throws Exception {
    final String topoId = "test_topology";
    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);
    MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", port, la, null, ls, null, 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) LocalAssignment(org.apache.storm.generated.LocalAssignment) LocalState(org.apache.storm.utils.LocalState) Test(org.junit.Test)

Aggregations

LocalAssignment (org.apache.storm.generated.LocalAssignment)23 Test (org.junit.Test)18 HashMap (java.util.HashMap)15 LocalState (org.apache.storm.utils.LocalState)12 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)8 File (java.io.File)6 Map (java.util.Map)5 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)5 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)5 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)5 ILocalizer (org.apache.storm.localizer.ILocalizer)5 ISupervisor (org.apache.storm.scheduler.ISupervisor)5 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 List (java.util.List)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 NodeInfo (org.apache.storm.generated.NodeInfo)3 ProfileRequest (org.apache.storm.generated.ProfileRequest)3 StringWriter (java.io.StringWriter)2