@Override public void cleanUpForRestart() throws IOException { String origWorkerId = _workerId; super.cleanUpForRestart(); synchronized (_localState) { Map<String, Integer> workersToPort = _localState.getApprovedWorkers(); if (workersToPort != null) { workersToPort.remove(origWorkerId); removeWorkersOn(workersToPort, _port); _localState.setApprovedWorkers(workersToPort); LOG.info("Removed Worker ID {}", origWorkerId); } else { LOG.warn("No approved workers exists"); } } }
/** * Create a new worker ID for this process and store in in this object and in the local state. Never call this if a worker is currently * up and running. We will lose track of the process. */ protected void createNewWorkerId() { _type.assertFull(); assert (_workerId == null); synchronized (_localState) { _workerId = Utils.uuid(); Map<String, Integer> workerToPort = _localState.getApprovedWorkers(); if (workerToPort == null) { workerToPort = new HashMap<>(1); } removeWorkersOn(workerToPort, _port); workerToPort.put(_workerId, _port); _localState.setApprovedWorkers(workerToPort); LOG.info("Created Worker ID {}", _workerId); } }
@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); }
@Override public void cleanUpForRestart() throws IOException { String origWorkerId = _workerId; super.cleanUpForRestart(); synchronized (_localState) { Map<String, Integer> workersToPort = _localState.getApprovedWorkers(); workersToPort.remove(origWorkerId); removeWorkersOn(workersToPort, _port); _localState.setApprovedWorkers(workersToPort); LOG.info("Removed Worker ID {}", origWorkerId); } }
/** * Create a new worker ID for this process and store in in this object and * in the local state. Never call this if a worker is currently up and running. * We will lose track of the process. */ protected void createNewWorkerId() { _type.assertFull(); assert(_workerId == null); synchronized (_localState) { _workerId = Utils.uuid(); Map<String, Integer> workerToPort = _localState.getApprovedWorkers(); if (workerToPort == null) { workerToPort = new HashMap<>(1); } removeWorkersOn(workerToPort, _port); workerToPort.put(_workerId, _port); _localState.setApprovedWorkers(workerToPort); LOG.info("Created Worker ID {}", _workerId); } }