Exemplo n.º 1
0
 private static Set<ResourceWorkerSlot> mkLocalAssignment(TopologyAssignContext context) {
   Set<ResourceWorkerSlot> result = new HashSet<ResourceWorkerSlot>();
   Map<String, SupervisorInfo> cluster = context.getCluster();
   if (cluster.size() != 1) throw new RuntimeException();
   SupervisorInfo localSupervisor = null;
   String supervisorId = null;
   for (Entry<String, SupervisorInfo> entry : cluster.entrySet()) {
     supervisorId = entry.getKey();
     localSupervisor = entry.getValue();
   }
   int port = localSupervisor.getWorkerPorts().iterator().next();
   ResourceWorkerSlot worker = new ResourceWorkerSlot(supervisorId, port);
   worker.setTasks(new HashSet<Integer>(context.getAllTaskIds()));
   worker.setHostname(localSupervisor.getHostName());
   result.add(worker);
   return result;
 }
  /**
   * @@@ Here maybe exist one problem, some dead slots have been free
   *
   * @param context
   */
  protected void freeUsed(TopologyAssignContext context) {
    Set<Integer> canFree = new HashSet<Integer>();
    canFree.addAll(context.getAllTaskIds());
    canFree.removeAll(context.getUnstoppedTaskIds());

    Map<String, SupervisorInfo> cluster = context.getCluster();
    Map<Integer, ResourceAssignment> oldAssigns = context.getOldAssignment().getTaskToResource();
    for (Integer task : canFree) {
      ResourceAssignment oldAssign = oldAssigns.get(task);
      if (oldAssign == null) {
        LOG.warn("When free rebalance resource, no ResourceAssignment of task " + task);
        continue;
      }

      SupervisorInfo supervisorInfo = cluster.get(oldAssign.getSupervisorId());
      if (supervisorInfo == null) {
        continue;
      }
      supervisorInfo.getCpuPool().free(oldAssign.getCpuSlotNum(), context);
      supervisorInfo.getMemPool().free(oldAssign.getMemSlotNum(), context);
      supervisorInfo.getDiskPool().free(oldAssign.getDiskSlot(), context);
      supervisorInfo.getNetPool().free(oldAssign.getPort(), context);
    }
  }