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);
}
}
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));
}
}
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;
}
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);
}
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);
}
Aggregations