Search in sources :

Example 6 with ResourceWorkerSlot

use of com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot in project jstorm by alibaba.

the class WorkerSetUpdater method process.

@Override
public void process(Object event) throws Exception {
    try {
        Assignment assignment = tmContext.getZkCluster().assignment_info(tmContext.getTopologyId(), null);
        if (assignment != null) {
            Set<ResourceWorkerSlot> oldWorkerSet = tmContext.getWorkerSet().get();
            Set<ResourceWorkerSlot> newWorkerSet = assignment.getWorkers();
            if (!oldWorkerSet.equals(newWorkerSet)) {
                LOG.info("Find worker slots has been changed, old:{}, \nnew:{}", oldWorkerSet, newWorkerSet);
                tmContext.getWorkerSet().set(newWorkerSet);
                tmContext.getTopologyMetricContext().setWorkerSet(newWorkerSet);
            }
        }
    } catch (Exception e) {
        String errorInfo = "Failed to get assignment for " + tmContext.getTopologyId();
        LOG.error(errorInfo + e);
        zkCluster.report_task_error(context.getTopologyId(), context.getThisTaskId(), errorInfo, ErrorConstants.WARN, ErrorConstants.CODE_USER);
    }
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 7 with ResourceWorkerSlot

use of com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot in project jstorm by alibaba.

the class GrayUpgradeHandler method setTotalWorkers.

private void setTotalWorkers(TopologyMasterContext tmContext) {
    Set<ResourceWorkerSlot> workerSlots = tmContext.getWorkerSet().get();
    int tmTaskId = tmContext.getTaskId();
    this.totalWorkers.clear();
    for (ResourceWorkerSlot workerSlot : workerSlots) {
        if (!workerSlot.getTasks().contains(tmTaskId)) {
            this.totalWorkers.add(workerSlot.getHostPort());
        }
    }
}
Also used : ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 8 with ResourceWorkerSlot

use of com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot in project jstorm by alibaba.

the class TopologyAssign method getUnstoppedSlots.

/**
 * Get unstopped slots from alive task list
 */
public Set<Integer> getUnstoppedSlots(Set<Integer> aliveTasks, Map<String, SupervisorInfo> supInfos, Assignment existAssignment) {
    Set<Integer> ret = new HashSet<>();
    Set<ResourceWorkerSlot> oldWorkers = existAssignment.getWorkers();
    Set<String> aliveSupervisors = supInfos.keySet();
    for (ResourceWorkerSlot worker : oldWorkers) {
        for (Integer taskId : worker.getTasks()) {
            if (!aliveTasks.contains(taskId)) {
                // task is dead
                continue;
            }
            String oldTaskSupervisorId = worker.getNodeId();
            if (!aliveSupervisors.contains(oldTaskSupervisorId)) {
                // supervisor is dead
                ret.add(taskId);
            }
        }
    }
    return ret;
}
Also used : HashSet(java.util.HashSet) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 9 with ResourceWorkerSlot

use of com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot in project jstorm by alibaba.

the class NimbusUtils method mkSupervisorSummaries.

public static List<SupervisorSummary> mkSupervisorSummaries(Map<String, SupervisorInfo> supervisorInfos, Map<String, Assignment> assignments) {
    Map<String, Integer> supervisorToLeftSlotNum = new HashMap<>();
    for (Entry<String, Assignment> entry : assignments.entrySet()) {
        Set<ResourceWorkerSlot> workers = entry.getValue().getWorkers();
        for (ResourceWorkerSlot worker : workers) {
            String supervisorId = worker.getNodeId();
            SupervisorInfo supervisorInfo = supervisorInfos.get(supervisorId);
            if (supervisorInfo == null) {
                continue;
            }
            Integer slots = supervisorToLeftSlotNum.get(supervisorId);
            if (slots == null) {
                slots = 0;
                supervisorToLeftSlotNum.put(supervisorId, slots);
            }
            supervisorToLeftSlotNum.put(supervisorId, ++slots);
        }
    }
    List<SupervisorSummary> ret = new ArrayList<>();
    for (Entry<String, SupervisorInfo> entry : supervisorInfos.entrySet()) {
        String supervisorId = entry.getKey();
        SupervisorInfo supervisorInfo = entry.getValue();
        SupervisorSummary summary = mkSupervisorSummary(supervisorInfo, supervisorId, supervisorToLeftSlotNum);
        ret.add(summary);
    }
    Collections.sort(ret, new Comparator<SupervisorSummary>() {

        @Override
        public int compare(SupervisorSummary o1, SupervisorSummary o2) {
            return o1.get_host().compareTo(o2.get_host());
        }
    });
    return ret;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SupervisorSummary(backtype.storm.generated.SupervisorSummary) SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo) Assignment(com.alibaba.jstorm.schedule.Assignment) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 10 with ResourceWorkerSlot

use of com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot in project jstorm by alibaba.

the class AbstractSelector method selectWorker.

protected List<ResourceWorkerSlot> selectWorker(List<ResourceWorkerSlot> list, Comparator<ResourceWorkerSlot> c) {
    List<ResourceWorkerSlot> result = new ArrayList<>();
    ResourceWorkerSlot best = null;
    for (ResourceWorkerSlot worker : list) {
        if (best == null) {
            best = worker;
            result.add(worker);
            continue;
        }
        if (c.compare(best, worker) == 0) {
            result.add(worker);
        } else if (c.compare(best, worker) > 0) {
            best = worker;
            result.clear();
            result.add(best);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Aggregations

ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)26 Assignment (com.alibaba.jstorm.schedule.Assignment)13 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)9 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 SupervisorInfo (com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 TreeMap (java.util.TreeMap)5 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)4 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)4 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)4 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)4 NotAliveException (backtype.storm.generated.NotAliveException)4 TopologyAssignException (backtype.storm.generated.TopologyAssignException)4 TException (org.apache.thrift.TException)4