@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); MockBasicContainer mc = new MockBasicContainer(ContainerType.RECOVER_FULL, superConf, "SUPERVISOR", supervisorPort, port, la, null, ls, null, new StormMetricsRegistry(), new HashMap<>(), ops, "profile"); assertEquals(workerId, mc._workerId); }
/** * Setup the container to run. By default this creates the needed directories/links in the local file system PREREQUISITE: All needed * blobs and topology, jars/configs have been downloaded and placed in the appropriate locations * * @throws IOException on any error */ protected void setup() throws IOException { _type.assertFull(); if (!_ops.doRequiredTopoFilesExist(_conf, _topologyId)) { LOG.info("Missing topology storm code, so can't launch worker with assignment {} for this supervisor {} on port {} with id {}", _assignment, _supervisorId, _port, _workerId); throw new IllegalStateException("Not all needed files are here!!!!"); } LOG.info("Setting up {}:{}", _supervisorId, _workerId); _ops.forceMkdir(new File(ConfigUtils.workerPidsRoot(_conf, _workerId))); _ops.forceMkdir(new File(ConfigUtils.workerTmpRoot(_conf, _workerId))); _ops.forceMkdir(new File(ConfigUtils.workerHeartbeatsRoot(_conf, _workerId))); File workerArtifacts = new File(ConfigUtils.workerArtifactsRoot(_conf, _topologyId, _port)); if (!_ops.fileExists(workerArtifacts)) { _ops.forceMkdir(workerArtifacts); _ops.setupWorkerArtifactsDir(_assignment.get_owner(), workerArtifacts); } String user = getWorkerUser(); writeLogMetadata(user); saveWorkerUser(user); createArtifactsLink(); createBlobstoreLinks(); }
@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); MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, null, 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); }
@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)); MockBasicContainer mc = new MockBasicContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", supervisorPort, port, la, null, 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); }
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.fileExists(workerArtifacts)).thenReturn(true); when(ops.fileExists(workerRoot)).thenReturn(true);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.fileExists(workerArtifacts)).thenReturn(true); when(ops.fileExists(workerRoot)).thenReturn(true);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true);
assert (port > 0); _topologyId = assignment.get_topology_id(); if (!_ops.doRequiredTopoFilesExist(_conf, _topologyId)) { LOG.info( "Missing topology storm code, so can't launch worker with assignment {} for this supervisor {} on port {} with id {}",
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.slurpString(workerArtifactsPid)).thenReturn(String.valueOf(pid));
@Test public void testKill() throws Exception { final String topoId = "test_topology"; final Map<String, Object> superConf = new HashMap<>(); AdvancedFSOps ops = mock(AdvancedFSOps.class); when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); LocalAssignment la = new LocalAssignment(); la.set_topology_id(topoId); MockContainer mc = new MockContainer(ContainerType.LAUNCH, superConf, "SUPERVISOR", 6628, 8080, la, null, "worker", new HashMap<>(), ops, new StormMetricsRegistry()); mc.kill(); assertEquals(Collections.EMPTY_LIST, mc.killedPids); assertEquals(Collections.EMPTY_LIST, mc.forceKilledPids); mc.forceKill(); assertEquals(Collections.EMPTY_LIST, mc.killedPids); assertEquals(Collections.EMPTY_LIST, mc.forceKilledPids); long pid = 987654321; mc.allPids.add(pid); mc.kill(); assertEquals(mc.allPids, new HashSet<>(mc.killedPids)); assertEquals(Collections.EMPTY_LIST, mc.forceKilledPids); mc.killedPids.clear(); mc.forceKill(); assertEquals(Collections.EMPTY_LIST, mc.killedPids); assertEquals(mc.allPids, new HashSet<>(mc.forceKilledPids)); }
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.slurp(stormcode)).thenReturn(serializedState);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.slurp(stormcode)).thenReturn(serializedState);
when(ops.doRequiredTopoFilesExist(superConf, topoId)).thenReturn(true); when(ops.slurp(stormcode)).thenReturn(serializedState);
if (!_ops.doRequiredTopoFilesExist(_conf, _topologyId)) { LOG.info("Missing topology storm code, so can't launch worker with assignment {} for this supervisor {} on port {} with id {}", _assignment, _supervisorId, _port, _workerId);
assert(port > 0); _topologyId = assignment.get_topology_id(); if (!_ops.doRequiredTopoFilesExist(_conf, _topologyId)) { LOG.info("Missing topology storm code, so can't launch worker with assignment {} for this supervisor {} on port {} with id {}", _assignment, _supervisorId, _port, _workerId);