Search in sources :

Example 6 with Assignment

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;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) ArrayList(java.util.ArrayList) StormBase(com.alibaba.jstorm.cluster.StormBase) TopologySummary(backtype.storm.generated.TopologySummary)

Example 7 with Assignment

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;
}
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 8 with Assignment

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);
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext)

Example 9 with Assignment

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);
    }
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)

Example 10 with Assignment

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;
}
Also used : Assignment(com.alibaba.jstorm.schedule.Assignment) HashSet(java.util.HashSet)

Aggregations

Assignment (com.alibaba.jstorm.schedule.Assignment)24 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)11 HashMap (java.util.HashMap)8 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)7 SupervisorInfo (com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)6 IOException (java.io.IOException)6 LocalAssignment (com.alibaba.jstorm.daemon.worker.LocalAssignment)5 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)5 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 TException (org.apache.thrift.TException)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 InvalidParameterException (java.security.InvalidParameterException)4 SupervisorSummary (backtype.storm.generated.SupervisorSummary)3