use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class NimbusUtils method getTopologySummary.
public static List<TopologySummary> getTopologySummary(StormClusterState stormClusterState, Map<String, Assignment> assignments) throws Exception {
List<TopologySummary> topologySummaries = new ArrayList<TopologySummary>();
// get all active topology's StormBase
Map<String, StormBase> bases = Cluster.get_all_StormBase(stormClusterState);
for (Entry<String, StormBase> entry : bases.entrySet()) {
String topologyId = entry.getKey();
StormBase base = entry.getValue();
Assignment assignment = stormClusterState.assignment_info(topologyId, null);
if (assignment == null) {
LOG.error("Failed to get assignment of " + topologyId);
continue;
}
assignments.put(topologyId, assignment);
int num_workers = assignment.getWorkers().size();
int num_tasks = getTopologyTaskNum(assignment);
String errorString = null;
if (Cluster.is_topology_exist_error(stormClusterState, topologyId)) {
errorString = "Y";
} else {
errorString = "";
}
TopologySummary topology = new TopologySummary();
topology.set_id(topologyId);
topology.set_name(base.getStormName());
topology.set_status(base.getStatusString());
topology.set_uptimeSecs(TimeUtils.time_delta(base.getLanchTimeSecs()));
topology.set_numWorkers(num_workers);
topology.set_numTasks(num_tasks);
topology.set_errorInfo(errorString);
topologySummaries.add(topology);
}
return topologySummaries;
}
use of com.alibaba.jstorm.schedule.Assignment 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<String, Integer>();
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<SupervisorSummary>();
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.Assignment in project jstorm by alibaba.
the class TaskStartEvent method run.
@Override
public void run() {
Assignment assignment = newAssignment;
TopologyMetricContext metricContext = context.getTopologyMetricContexts().get(topologyId);
if (metricContext != null) {
metricContext.setWorkerSet(assignment.getWorkers());
} else {
metricContext = new TopologyMetricContext();
metricContext.setWorkerSet(assignment.getWorkers());
context.getTopologyMetricContexts().put(topologyId, metricContext);
}
context.getMetricUploader().sendEvent(context.getClusterName(), this);
}
use of com.alibaba.jstorm.schedule.Assignment in project jstorm by alibaba.
the class WorkerSetUpdater method process.
@Override
public void process(Object event) throws Exception {
// TODO Auto-generated method stub
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) == false) {
LOG.info("Find worker slots has been changed, old:{}, \n\n new:{}", 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.Assignment in project jstorm by alibaba.
the class DefaultTopologyScheduler method getKeepAssign.
/**
* Get the task Map which the task is alive and will be kept Only when type is ASSIGN_TYPE_MONITOR, it is valid
*
* @param defaultContext
* @param needAssigns
* @return
*/
public Set<ResourceWorkerSlot> getKeepAssign(DefaultTopologyAssignContext defaultContext, Set<Integer> needAssigns) {
Set<Integer> keepAssignIds = new HashSet<Integer>();
keepAssignIds.addAll(defaultContext.getAllTaskIds());
keepAssignIds.removeAll(defaultContext.getUnstoppedTaskIds());
keepAssignIds.removeAll(needAssigns);
Set<ResourceWorkerSlot> keeps = new HashSet<ResourceWorkerSlot>();
if (keepAssignIds.isEmpty()) {
return keeps;
}
Assignment oldAssignment = defaultContext.getOldAssignment();
if (oldAssignment == null) {
return keeps;
}
keeps.addAll(defaultContext.getOldWorkers());
for (ResourceWorkerSlot worker : defaultContext.getOldWorkers()) {
for (Integer task : worker.getTasks()) {
if (!keepAssignIds.contains(task)) {
keeps.remove(worker);
break;
}
}
}
return keeps;
}
Aggregations