Search in sources :

Example 11 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class StandaloneSupervisor method prepare.

@Override
public void prepare(Map stormConf, String schedulerLocalDir) {
    try {
        LocalState localState = new LocalState(schedulerLocalDir);
        String supervisorId = localState.getSupervisorId();
        if (supervisorId == null) {
            supervisorId = generateSupervisorId();
            localState.setSupervisorId(supervisorId);
        }
        this.conf = stormConf;
        this.supervisorId = supervisorId;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LocalState(org.apache.storm.utils.LocalState) IOException(java.io.IOException)

Example 12 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class Nimbus method addTopoToHistoryLog.

private void addTopoToHistoryLog(String topoId, Map<String, Object> topoConf) {
    LOG.info("Adding topo to history log: {}", topoId);
    LocalState state = topologyHistoryState;
    List<String> users = ConfigUtils.getTopoLogsUsers(topoConf);
    List<String> groups = ConfigUtils.getTopoLogsGroups(topoConf);
    synchronized (topologyHistoryLock) {
        state.addTopologyHistory(new LSTopoHistory(topoId, Time.currentTimeSecs(), users, groups));
    }
}
Also used : LocalState(org.apache.storm.utils.LocalState) LSTopoHistory(org.apache.storm.generated.LSTopoHistory)

Example 13 with LocalState

use of org.apache.storm.utils.LocalState in project storm by apache.

the class Nimbus method readTopologyHistory.

private List<String> readTopologyHistory(String user, Collection<String> adminUsers) throws IOException {
    LocalState state = topologyHistoryState;
    List<String> ret = new ArrayList<>();
    for (LSTopoHistory history : state.getTopoHistoryList()) {
        if (//Security off
        user == null || //is admin
        adminUsers.contains(user) || //is in allowed group
        isUserPartOf(user, history.get_groups()) || history.get_users().contains(user)) {
            //is an allowed user
            ret.add(history.get_topology_id());
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) LocalState(org.apache.storm.utils.LocalState) LSTopoHistory(org.apache.storm.generated.LSTopoHistory)

Example 14 with LocalState

use of org.apache.storm.utils.LocalState 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 15 with LocalState

use of org.apache.storm.utils.LocalState 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)

Aggregations

LocalState (org.apache.storm.utils.LocalState)19 Test (org.junit.Test)13 LocalAssignment (org.apache.storm.generated.LocalAssignment)12 HashMap (java.util.HashMap)8 LSWorkerHeartbeat (org.apache.storm.generated.LSWorkerHeartbeat)7 DynamicState (org.apache.storm.daemon.supervisor.Slot.DynamicState)6 StaticState (org.apache.storm.daemon.supervisor.Slot.StaticState)6 ExecutorInfo (org.apache.storm.generated.ExecutorInfo)6 ILocalizer (org.apache.storm.localizer.ILocalizer)5 ISupervisor (org.apache.storm.scheduler.ISupervisor)5 SimulatedTime (org.apache.storm.utils.Time.SimulatedTime)5 File (java.io.File)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LSTopoHistory (org.apache.storm.generated.LSTopoHistory)2 Preconditions (com.google.common.base.Preconditions)1 EventHandler (com.lmax.disruptor.EventHandler)1 Charset (java.nio.charset.Charset)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Collection (java.util.Collection)1