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);
}
}
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());
}
}
}
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;
}
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;
}
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;
}
Aggregations