Exemplo n.º 1
0
  /** Get unstopped slots from alive task list 获得所有supervisor已经dead,但是还没有dead的任务 */
  public Set<Integer> getUnstoppedSlots(
      Set<Integer> aliveTasks, Map<String, SupervisorInfo> supInfos, Assignment existAssignment) {
    Set<Integer> ret = new HashSet<Integer>();

    Set<ResourceWorkerSlot> oldWorkers = existAssignment.getWorkers();

    Set<String> aliveSupervisors = supInfos.keySet();

    for (ResourceWorkerSlot worker : oldWorkers) {
      for (Integer taskId : worker.getTasks()) {
        if (aliveTasks.contains(taskId) == false) {
          // task is dead
          continue;
        }

        String oldTaskSupervisorId = worker.getNodeId();

        if (aliveSupervisors.contains(oldTaskSupervisorId) == false) {
          // supervisor is dead
          ret.add(taskId);
          continue;
        }
      }
    }

    return ret;
  }
Exemplo n.º 2
0
  /**
   * get all taskids which should be reassigned
   *
   * @param taskToWorkerSlot
   * @param newtaskToWorkerSlot
   * @return Set<Integer> taskid which should reassigned
   */
  public static Set<Integer> getChangeTaskIds(
      Set<ResourceWorkerSlot> oldWorkers, Set<ResourceWorkerSlot> workers) {

    Set<Integer> rtn = new HashSet<Integer>();
    for (ResourceWorkerSlot worker : workers) {
      if (!oldWorkers.contains(worker)) rtn.addAll(worker.getTasks());
    }
    return rtn;
  }
Exemplo n.º 3
0
 private Set<ResourceWorkerSlot> getUnstoppedWorkers(
     Set<Integer> aliveTasks, Assignment existAssignment) {
   Set<ResourceWorkerSlot> ret = new HashSet<ResourceWorkerSlot>();
   for (ResourceWorkerSlot worker : existAssignment.getWorkers()) {
     boolean alive = true;
     for (Integer task : worker.getTasks()) {
       if (!aliveTasks.contains(task)) {
         alive = false;
         break;
       }
     }
     if (alive) {
       ret.add(worker);
     }
   }
   return ret;
 }
Exemplo n.º 4
0
  /**
   * @param existingAssignment
   * @param taskWorkerSlot
   * @return
   * @throws Exception
   */
  public static Map<Integer, Integer> getTaskStartTimes(
      TopologyAssignContext context,
      NimbusData nimbusData,
      String topologyId,
      Assignment existingAssignment,
      Set<ResourceWorkerSlot> workers)
      throws Exception {

    Map<Integer, Integer> startTimes = new TreeMap<Integer, Integer>();

    if (context.getAssignType() == TopologyAssignContext.ASSIGN_TYPE_NEW) {
      int nowSecs = TimeUtils.current_time_secs();
      for (ResourceWorkerSlot worker : workers) {
        for (Integer changedTaskId : worker.getTasks()) {
          startTimes.put(changedTaskId, nowSecs);
        }
      }

      return startTimes;
    }

    Set<ResourceWorkerSlot> oldWorkers = new HashSet<ResourceWorkerSlot>();

    if (existingAssignment != null) {
      Map<Integer, Integer> taskStartTimeSecs = existingAssignment.getTaskStartTimeSecs();
      if (taskStartTimeSecs != null) {
        startTimes.putAll(taskStartTimeSecs);
      }

      if (existingAssignment.getWorkers() != null) {
        oldWorkers = existingAssignment.getWorkers();
      }
    }

    StormClusterState zkClusterState = nimbusData.getStormClusterState();
    Set<Integer> changeTaskIds = getChangeTaskIds(oldWorkers, workers);
    int nowSecs = TimeUtils.current_time_secs();
    for (Integer changedTaskId : changeTaskIds) {
      startTimes.put(changedTaskId, nowSecs);

      zkClusterState.remove_task_heartbeat(topologyId, changedTaskId);
    }

    LOG.info("Task assignment has been changed " + changeTaskIds);
    return startTimes;
  }