/** * check whether the workerheartbeat is allowed in the assignedTasks * * @param whb : WorkerHeartbeat * @param assignedTasks * @return boolean if true, the assignments(LS-LOCAL-ASSIGNMENTS) is match with workerheart if * fasle, is not matched */ public boolean matchesAssignment( WorkerHeartbeat whb, Map<Integer, LocalAssignment> assignedTasks) { boolean isMatch = true; LocalAssignment localAssignment = assignedTasks.get(whb.getPort()); if (localAssignment == null) { isMatch = false; } else if (!whb.getTopologyId().equals(localAssignment.getTopologyId())) { // topology id not equal LOG.info( "topology id not equal whb=" + whb.getTopologyId() + ",localAssignment=" + localAssignment.getTopologyId()); isMatch = false; } else if (!(whb.getTaskIds().equals(localAssignment.getTaskIds()))) { // task-id isn't equal LOG.info( "task-id isn't equal whb=" + whb.getTaskIds() + ",localAssignment=" + localAssignment.getTaskIds()); isMatch = false; } return isMatch; }
/** * get localstat approved workerId's map * * @return Map<workerid [workerheart, state]> [workerheart, state] is also a map, key is * "workheartbeat" and "state" * @param conf * @param localState * @param assignedTasks * @throws IOException * @pdOid 11c9bebb-d082-4c51-b323-dd3d5522a649 */ @SuppressWarnings("unchecked") public Map<String, StateHeartbeat> getLocalWorkerStats( Map conf, LocalState localState, Map<Integer, LocalAssignment> assignedTasks) throws Exception { Map<String, StateHeartbeat> workeridHbstate = new HashMap<String, StateHeartbeat>(); int now = TimeUtils.current_time_secs(); /** Get Map<workerId, WorkerHeartbeat> from local_dir/worker/ids/heartbeat */ Map<String, WorkerHeartbeat> idToHeartbeat = readWorkerHeartbeats(conf); for (Map.Entry<String, WorkerHeartbeat> entry : idToHeartbeat.entrySet()) { String workerid = entry.getKey().toString(); WorkerHeartbeat whb = entry.getValue(); State state = null; if (whb == null) { state = State.notStarted; } else if (matchesAssignment(whb, assignedTasks) == false) { // workerId isn't approved or // isn't assigned task state = State.disallowed; } else if ((now - whb.getTimeSecs()) > JStormUtils.parseInt(conf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS))) { // state = State.timedOut; } else { state = State.valid; } if (state != State.valid) { LOG.info( "Worker:" + workerid + " state:" + state + " WorkerHeartbeat: " + whb + " at supervisor time-secs " + now); } else { LOG.debug( "Worker:" + workerid + " state:" + state + " WorkerHeartbeat: " + whb + " at supervisor time-secs " + now); } workeridHbstate.put(workerid, new StateHeartbeat(state, whb)); } return workeridHbstate; }