use of org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager in project storm by apache.
the class BasicContainerTest method testLaunchStorm0version.
@Test
public void testLaunchStorm0version() throws Exception {
final String topoId = "test_topology_storm_0.x";
final int supervisorPort = 6628;
final int port = 8080;
final String stormHome = ContainerTest.asAbsPath("tmp", "storm-home");
final String stormLogDir = ContainerTest.asFile(".", "target").getCanonicalPath();
final String workerId = "worker-id";
final String stormLocal = ContainerTest.asAbsPath("tmp", "storm-local");
final String distRoot = ContainerTest.asAbsPath(stormLocal, "supervisor", "stormdist", topoId);
final File stormcode = new File(distRoot, "stormcode.ser");
final File stormjar = new File(distRoot, "stormjar.jar");
final String log4jdir = ContainerTest.asAbsPath(stormHome, "conf");
final String workerConf = ContainerTest.asAbsPath(log4jdir, "worker.xml");
final String workerRoot = ContainerTest.asAbsPath(stormLocal, "workers", workerId);
final String workerTmpDir = ContainerTest.asAbsPath(workerRoot, "tmp");
final StormTopology st = new StormTopology();
st.set_spouts(new HashMap<>());
st.set_bolts(new HashMap<>());
st.set_state_spouts(new HashMap<>());
// minimum 0.x version of supporting STORM-2448 would be 0.10.3
st.set_storm_version("0.10.3");
byte[] serializedState = Utils.gzip(Utils.thriftSerialize(st));
final Map<String, Object> superConf = new HashMap<>();
superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
superConf.put(DaemonConfig.STORM_LOG4J2_CONF_DIR, log4jdir);
superConf.put(Config.WORKER_CHILDOPTS, " -Dtesting=true");
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
when(ops.slurp(stormcode)).thenReturn(serializedState);
LocalState ls = mock(LocalState.class);
MockResourceIsolationManager iso = new MockResourceIsolationManager();
checkpoint(() -> {
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
mc.launch();
assertEquals(1, iso.workerCmds.size());
CommandRun cmd = iso.workerCmds.get(0);
iso.workerCmds.clear();
assertListEquals(Arrays.asList("java", "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "backtype.storm.LogWriter", "java", "-server", "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "-Dtesting=true", "-Djava.library.path=JLP", "-Dstorm.conf.file=", "-Dstorm.options=", "-Djava.io.tmpdir=" + workerTmpDir, "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "backtype.storm.daemon.worker", topoId, "SUPERVISOR", String.valueOf(port), workerId), cmd.cmd);
assertEquals(new File(workerRoot), cmd.pwd);
}, ConfigUtils.STORM_HOME, stormHome, "storm.log.dir", stormLogDir);
}
use of org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager in project storm by apache.
the class BasicContainerTest method testLaunch.
@Test
public void testLaunch() throws Exception {
final String topoId = "test_topology_current";
final int supervisorPort = 6628;
final int port = 8080;
final String stormHome = ContainerTest.asAbsPath("tmp", "storm-home");
final String stormLogDir = ContainerTest.asFile(".", "target").getCanonicalPath();
final String workerId = "worker-id";
final String stormLocal = ContainerTest.asAbsPath("tmp", "storm-local");
final String distRoot = ContainerTest.asAbsPath(stormLocal, "supervisor", "stormdist", topoId);
final File stormcode = new File(distRoot, "stormcode.ser");
final File stormjar = new File(distRoot, "stormjar.jar");
final String log4jdir = ContainerTest.asAbsPath(stormHome, "conf");
final String workerConf = ContainerTest.asAbsPath(log4jdir, "worker.xml");
final String workerRoot = ContainerTest.asAbsPath(stormLocal, "workers", workerId);
final String workerTmpDir = ContainerTest.asAbsPath(workerRoot, "tmp");
final StormTopology st = new StormTopology();
st.set_spouts(new HashMap<>());
st.set_bolts(new HashMap<>());
st.set_state_spouts(new HashMap<>());
byte[] serializedState = Utils.gzip(Utils.thriftSerialize(st));
final Map<String, Object> superConf = new HashMap<>();
superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
superConf.put(DaemonConfig.STORM_LOG4J2_CONF_DIR, log4jdir);
superConf.put(Config.WORKER_CHILDOPTS, " -Dtesting=true");
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
when(ops.slurp(stormcode)).thenReturn(serializedState);
LocalState ls = mock(LocalState.class);
MockResourceIsolationManager iso = new MockResourceIsolationManager();
checkpoint(() -> {
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
mc.launch();
assertEquals(1, iso.workerCmds.size());
CommandRun cmd = iso.workerCmds.get(0);
iso.workerCmds.clear();
assertListEquals(Arrays.asList("java", "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "org.apache.storm.LogWriter", "java", "-server", "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "-Dtesting=true", "-Djava.library.path=JLP", "-Dstorm.conf.file=", "-Dstorm.options=", "-Djava.io.tmpdir=" + workerTmpDir, "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "org.apache.storm.daemon.worker.Worker", topoId, "SUPERVISOR", String.valueOf(supervisorPort), String.valueOf(port), workerId), cmd.cmd);
assertEquals(new File(workerRoot), cmd.pwd);
}, ConfigUtils.STORM_HOME, stormHome, "storm.log.dir", stormLogDir);
}
use of org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager in project storm by apache.
the class BasicContainerTest method testLaunchStorm1version.
@Test
public void testLaunchStorm1version() throws Exception {
final String topoId = "test_topology_storm_1.x";
final int supervisorPort = 6628;
final int port = 8080;
final String stormHome = ContainerTest.asAbsPath("tmp", "storm-home");
final String stormLogDir = ContainerTest.asFile(".", "target").getCanonicalPath();
final String workerId = "worker-id";
final String stormLocal = ContainerTest.asAbsPath("tmp", "storm-local");
final String distRoot = ContainerTest.asAbsPath(stormLocal, "supervisor", "stormdist", topoId);
final File stormcode = new File(distRoot, "stormcode.ser");
final File stormjar = new File(distRoot, "stormjar.jar");
final String log4jdir = ContainerTest.asAbsPath(stormHome, "conf");
final String workerConf = ContainerTest.asAbsPath(log4jdir, "worker.xml");
final String workerRoot = ContainerTest.asAbsPath(stormLocal, "workers", workerId);
final String workerTmpDir = ContainerTest.asAbsPath(workerRoot, "tmp");
final StormTopology st = new StormTopology();
st.set_spouts(new HashMap<>());
st.set_bolts(new HashMap<>());
st.set_state_spouts(new HashMap<>());
// minimum 1.x version of supporting STORM-2448 would be 1.0.4
st.set_storm_version("1.0.4");
byte[] serializedState = Utils.gzip(Utils.thriftSerialize(st));
final Map<String, Object> superConf = new HashMap<>();
superConf.put(Config.STORM_LOCAL_DIR, stormLocal);
superConf.put(Config.STORM_WORKERS_ARTIFACTS_DIR, stormLocal);
superConf.put(DaemonConfig.STORM_LOG4J2_CONF_DIR, log4jdir);
superConf.put(Config.WORKER_CHILDOPTS, " -Dtesting=true");
LocalAssignment la = new LocalAssignment();
la.set_topology_id(topoId);
AdvancedFSOps ops = mock(AdvancedFSOps.class);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
when(ops.slurp(stormcode)).thenReturn(serializedState);
LocalState ls = mock(LocalState.class);
MockResourceIsolationManager iso = new MockResourceIsolationManager();
checkpoint(() -> {
MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, iso, ls, workerId, new StormMetricsRegistry(), new HashMap<>(), ops, "profile");
mc.launch();
assertEquals(1, iso.workerCmds.size());
CommandRun cmd = iso.workerCmds.get(0);
iso.workerCmds.clear();
assertListEquals(Arrays.asList("java", "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "org.apache.storm.LogWriter", "java", "-server", "-Dlogging.sensitivity=S3", "-Dlogfile.name=worker.log", "-Dstorm.home=" + stormHome, "-Dworkers.artifacts=" + stormLocal, "-Dstorm.id=" + topoId, "-Dworker.id=" + workerId, "-Dworker.port=" + port, "-Dstorm.log.dir=" + stormLogDir, "-DLog4jContextSelector=org.apache.logging.log4j.core.selector.BasicContextSelector", "-Dstorm.local.dir=" + stormLocal, "-Dworker.memory_limit_mb=768", "-Dlog4j.configurationFile=" + workerConf, "-Dtesting=true", "-Djava.library.path=JLP", "-Dstorm.conf.file=", "-Dstorm.options=", "-Djava.io.tmpdir=" + workerTmpDir, "-cp", "FRAMEWORK_CP:" + stormjar.getAbsolutePath(), "org.apache.storm.daemon.worker", topoId, "SUPERVISOR", String.valueOf(port), workerId), cmd.cmd);
assertEquals(new File(workerRoot), cmd.pwd);
}, ConfigUtils.STORM_HOME, stormHome, "storm.log.dir", stormLogDir);
}
use of org.apache.storm.daemon.supervisor.ContainerTest.MockResourceIsolationManager 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);
}
Aggregations