Search in sources :

Example 1 with SupervisorInfo

use of com.alibaba.jstorm.daemon.supervisor.SupervisorInfo in project jstorm by alibaba.

the class Cluster method get_all_SupervisorInfo.

/**
     * get all SupervisorInfo of storm cluster
     *
     * @param stormClusterState
     * @param callback
     * @return Map<String, SupervisorInfo> String: supervisorId SupervisorInfo: [time-secs hostname worker-ports uptime-secs]
     * @throws Exception
     */
public static Map<String, SupervisorInfo> get_all_SupervisorInfo(StormClusterState stormClusterState, RunnableCallback callback) throws Exception {
    Map<String, SupervisorInfo> rtn = new TreeMap<String, SupervisorInfo>();
    // get /ZK/supervisors
    List<String> supervisorIds = stormClusterState.supervisors(callback);
    // ignore any supervisors in blacklist
    List<String> blacklist = stormClusterState.get_blacklist();
    if (supervisorIds != null) {
        for (Iterator<String> iter = supervisorIds.iterator(); iter.hasNext(); ) {
            String supervisorId = iter.next();
            // get /supervisors/supervisorid
            SupervisorInfo supervisorInfo = stormClusterState.supervisor_info(supervisorId);
            if (supervisorInfo == null) {
                LOG.warn("Failed to get SupervisorInfo of " + supervisorId);
            } else if (blacklist.contains(supervisorInfo.getHostName())) {
                LOG.warn(" hostname:" + supervisorInfo.getHostName() + " is in blacklist");
            } else {
                rtn.put(supervisorId, supervisorInfo);
            }
        }
    } else {
        LOG.info("No alive supervisor");
    }
    return rtn;
}
Also used : TreeMap(java.util.TreeMap) SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)

Example 2 with SupervisorInfo

use of com.alibaba.jstorm.daemon.supervisor.SupervisorInfo in project jstorm by alibaba.

the class ServiceHandler method getSupervisorConf.

@Override
public String getSupervisorConf(String id) throws TException {
    Map<Object, Object> ret = new HashMap<>();
    ret.putAll(data.getConf());
    try {
        SupervisorInfo supervisorInfo = (SupervisorInfo) (((StormZkClusterState) this.data.getStormClusterState()).getObject(Cluster.supervisor_path(id), false));
        if (supervisorInfo != null && supervisorInfo.getSupervisorConf() != null) {
            ret.putAll(supervisorInfo.getSupervisorConf());
        } else {
            LOG.warn("supervisor conf not found in nimbus cache, supervisor id:{}, so fall back to nimbus conf", id);
        }
    } catch (Exception ex) {
        LOG.error("Error:", ex);
    }
    return JStormUtils.to_json(ret);
}
Also used : StormZkClusterState(com.alibaba.jstorm.cluster.StormZkClusterState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo) InvalidParameterException(java.security.InvalidParameterException) FailedAssignTopologyException(com.alibaba.jstorm.utils.FailedAssignTopologyException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) TopologyAssignException(backtype.storm.generated.TopologyAssignException) FileNotFoundException(java.io.FileNotFoundException) NotAliveException(backtype.storm.generated.NotAliveException) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException)

Example 3 with SupervisorInfo

use of com.alibaba.jstorm.daemon.supervisor.SupervisorInfo in project jstorm by alibaba.

the class ServiceHandler method getSupervisorWorkersByHostOrId.

/**
     * gets supervisor workers by host or supervisor id, note that id priors to host.
     *
     * @param host host
     * @param id   supervisor id
     * @return supervisor workers
     */
private SupervisorWorkers getSupervisorWorkersByHostOrId(String host, String id) throws TException {
    long start = System.nanoTime();
    if (StringUtils.isBlank(id) && StringUtils.isBlank(host)) {
        throw new TException("Must specify host or supervisor id!");
    }
    try {
        StormClusterState stormClusterState = data.getStormClusterState();
        // all supervisors
        Map<String, SupervisorInfo> supervisorInfos = Cluster.get_all_SupervisorInfo(stormClusterState, null);
        SupervisorInfo supervisorInfo = null;
        String ip;
        if (!StringUtils.isBlank(id)) {
            supervisorInfo = supervisorInfos.get(id);
            host = supervisorInfo.getHostName();
            ip = NetWorkUtils.host2Ip(host);
        } else {
            ip = NetWorkUtils.host2Ip(host);
            for (Entry<String, SupervisorInfo> entry : supervisorInfos.entrySet()) {
                SupervisorInfo info = entry.getValue();
                if (info.getHostName().equals(host) || info.getHostName().equals(ip)) {
                    id = entry.getKey();
                    supervisorInfo = info;
                    break;
                }
            }
        }
        if (supervisorInfo == null) {
            throw new TException("unknown supervisor id:" + id);
        }
        Map<String, Assignment> assignments = Cluster.get_all_assignment(stormClusterState, null);
        Map<Integer, WorkerSummary> portWorkerSummarys = new TreeMap<Integer, WorkerSummary>();
        int usedSlotNumber = 0;
        Map<String, Map<Integer, String>> topologyTaskToComponent = new HashMap<String, Map<Integer, String>>();
        Map<String, MetricInfo> metricInfoMap = new HashMap<String, MetricInfo>();
        for (Entry<String, Assignment> entry : assignments.entrySet()) {
            String topologyId = entry.getKey();
            Assignment assignment = entry.getValue();
            Set<ResourceWorkerSlot> workers = assignment.getWorkers();
            for (ResourceWorkerSlot worker : workers) {
                if (!id.equals(worker.getNodeId())) {
                    continue;
                }
                usedSlotNumber++;
                Integer port = worker.getPort();
                WorkerSummary workerSummary = portWorkerSummarys.get(port);
                if (workerSummary == null) {
                    workerSummary = new WorkerSummary();
                    workerSummary.set_port(port);
                    workerSummary.set_topology(topologyId);
                    workerSummary.set_tasks(new ArrayList<TaskComponent>());
                    portWorkerSummarys.put(port, workerSummary);
                }
                Map<Integer, String> taskToComponent = topologyTaskToComponent.get(topologyId);
                if (taskToComponent == null) {
                    taskToComponent = Cluster.get_all_task_component(stormClusterState, topologyId, null);
                    topologyTaskToComponent.put(topologyId, taskToComponent);
                }
                int earliest = TimeUtils.current_time_secs();
                for (Integer taskId : worker.getTasks()) {
                    TaskComponent taskComponent = new TaskComponent();
                    taskComponent.set_component(taskToComponent.get(taskId));
                    taskComponent.set_taskId(taskId);
                    Integer startTime = assignment.getTaskStartTimeSecs().get(taskId);
                    if (startTime != null && startTime < earliest) {
                        earliest = startTime;
                    }
                    workerSummary.add_to_tasks(taskComponent);
                }
                workerSummary.set_uptime(TimeUtils.time_delta(earliest));
                String workerSlotName = getWorkerSlotName(ip, port);
                List<MetricInfo> workerMetricInfoList = this.data.getMetricCache().getMetricData(topologyId, MetaType.WORKER);
                if (workerMetricInfoList.size() > 0) {
                    MetricInfo workerMetricInfo = workerMetricInfoList.get(0);
                    // remove metrics that don't belong to current worker
                    for (Iterator<String> itr = workerMetricInfo.get_metrics().keySet().iterator(); itr.hasNext(); ) {
                        String metricName = itr.next();
                        if (!metricName.contains(ip)) {
                            itr.remove();
                        }
                    }
                    metricInfoMap.put(workerSlotName, workerMetricInfo);
                }
            }
        }
        List<WorkerSummary> workerList = new ArrayList<WorkerSummary>();
        workerList.addAll(portWorkerSummarys.values());
        Map<String, Integer> supervisorToUsedSlotNum = new HashMap<String, Integer>();
        supervisorToUsedSlotNum.put(id, usedSlotNumber);
        SupervisorSummary supervisorSummary = NimbusUtils.mkSupervisorSummary(supervisorInfo, id, supervisorToUsedSlotNum);
        return new SupervisorWorkers(supervisorSummary, workerList, metricInfoMap);
    } catch (TException e) {
        LOG.info("Failed to get ClusterSummary ", e);
        throw e;
    } catch (Exception e) {
        LOG.info("Failed to get ClusterSummary ", e);
        throw new TException(e);
    } finally {
        long end = System.nanoTime();
        SimpleJStormMetric.updateNimbusHistogram("getSupervisorWorkers", (end - start) / TimeUtils.NS_PER_US);
    }
}
Also used : TException(org.apache.thrift.TException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) 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) SupervisorWorkers(backtype.storm.generated.SupervisorWorkers) ResourceWorkerSlot(com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot) TaskComponent(backtype.storm.generated.TaskComponent) TreeMap(java.util.TreeMap) InvalidParameterException(java.security.InvalidParameterException) FailedAssignTopologyException(com.alibaba.jstorm.utils.FailedAssignTopologyException) KeyNotFoundException(backtype.storm.generated.KeyNotFoundException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(backtype.storm.generated.AlreadyAliveException) TopologyAssignException(backtype.storm.generated.TopologyAssignException) FileNotFoundException(java.io.FileNotFoundException) NotAliveException(backtype.storm.generated.NotAliveException) InvalidTopologyException(backtype.storm.generated.InvalidTopologyException) KeyAlreadyExistsException(backtype.storm.generated.KeyAlreadyExistsException) StormClusterState(com.alibaba.jstorm.cluster.StormClusterState) WorkerSummary(backtype.storm.generated.WorkerSummary) MetricInfo(backtype.storm.generated.MetricInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) TimeCacheMap(com.alibaba.jstorm.utils.TimeCacheMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 4 with SupervisorInfo

use of com.alibaba.jstorm.daemon.supervisor.SupervisorInfo in project jstorm by alibaba.

the class TopologyAssign method getAliveSupervsByHb.

private void getAliveSupervsByHb(Map<String, SupervisorInfo> supervisorInfos, Map conf) {
    int currentTime = TimeUtils.current_time_secs();
    int hbTimeout = JStormUtils.parseInt(conf.get(Config.NIMBUS_SUPERVISOR_TIMEOUT_SECS), (JStormUtils.MIN_1 * 3));
    Set<String> supervisorTobeRemoved = new HashSet<String>();
    for (Entry<String, SupervisorInfo> entry : supervisorInfos.entrySet()) {
        SupervisorInfo supInfo = entry.getValue();
        int lastReportTime = supInfo.getTimeSecs();
        if ((currentTime - lastReportTime) > hbTimeout) {
            LOG.warn("Supervisor-" + supInfo.getHostName() + " is dead. lastReportTime=" + lastReportTime);
            supervisorTobeRemoved.add(entry.getKey());
        }
    }
    for (String name : supervisorTobeRemoved) {
        supervisorInfos.remove(name);
    }
}
Also used : SupervisorInfo(com.alibaba.jstorm.daemon.supervisor.SupervisorInfo) HashSet(java.util.HashSet)

Example 5 with SupervisorInfo

use of com.alibaba.jstorm.daemon.supervisor.SupervisorInfo 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)

Aggregations

SupervisorInfo (com.alibaba.jstorm.daemon.supervisor.SupervisorInfo)16 Assignment (com.alibaba.jstorm.schedule.Assignment)6 FailedAssignTopologyException (com.alibaba.jstorm.utils.FailedAssignTopologyException)6 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)5 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 AlreadyAliveException (backtype.storm.generated.AlreadyAliveException)3 InvalidTopologyException (backtype.storm.generated.InvalidTopologyException)3 KeyAlreadyExistsException (backtype.storm.generated.KeyAlreadyExistsException)3 KeyNotFoundException (backtype.storm.generated.KeyNotFoundException)3 NotAliveException (backtype.storm.generated.NotAliveException)3 SupervisorSummary (backtype.storm.generated.SupervisorSummary)3 TopologyAssignException (backtype.storm.generated.TopologyAssignException)3 StormClusterState (com.alibaba.jstorm.cluster.StormClusterState)3 FileNotFoundException (java.io.FileNotFoundException)3 InvalidParameterException (java.security.InvalidParameterException)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 TException (org.apache.thrift.TException)3