Search in sources :

Example 1 with SupervisorInfo

use of org.apache.storm.generated.SupervisorInfo in project storm by apache.

the class Nimbus method readAllSupervisorDetails.

/**
     * @param superToDeadPorts dead ports on the supervisor
     * @param topologies all of the topologies
     * @param missingAssignmentTopologies topologies that need assignments
     * @return a map: {supervisor-id SupervisorDetails}
     */
private Map<String, SupervisorDetails> readAllSupervisorDetails(Map<String, Set<Long>> superToDeadPorts, Topologies topologies, Collection<String> missingAssignmentTopologies) {
    Map<String, SupervisorDetails> ret = new HashMap<>();
    IStormClusterState state = stormClusterState;
    Map<String, SupervisorInfo> superInfos = state.allSupervisorInfo();
    List<SupervisorDetails> superDetails = new ArrayList<>();
    for (Entry<String, SupervisorInfo> entry : superInfos.entrySet()) {
        SupervisorInfo info = entry.getValue();
        superDetails.add(new SupervisorDetails(entry.getKey(), info.get_meta(), info.get_resources_map()));
    }
    // Note that allSlotsAvailableForScheduling
    // only uses the supervisor-details. The rest of the arguments
    // are there to satisfy the INimbus interface.
    Map<String, Set<Long>> superToPorts = new HashMap<>();
    for (WorkerSlot slot : inimbus.allSlotsAvailableForScheduling(superDetails, topologies, new HashSet<>(missingAssignmentTopologies))) {
        String superId = slot.getNodeId();
        Set<Long> ports = superToPorts.get(superId);
        if (ports == null) {
            ports = new HashSet<>();
            superToPorts.put(superId, ports);
        }
        ports.add((long) slot.getPort());
    }
    for (Entry<String, SupervisorInfo> entry : superInfos.entrySet()) {
        String superId = entry.getKey();
        SupervisorInfo info = entry.getValue();
        String hostname = info.get_hostname();
        // Hide the dead-ports from the all-ports
        // these dead-ports can be reused in next round of assignments
        Set<Long> deadPorts = superToDeadPorts.get(superId);
        Set<Long> allPorts = superToPorts.get(superId);
        if (allPorts == null) {
            allPorts = new HashSet<>();
        } else {
            allPorts = new HashSet<>(allPorts);
        }
        if (deadPorts != null) {
            allPorts.removeAll(deadPorts);
        }
        ret.put(superId, new SupervisorDetails(superId, hostname, info.get_scheduler_meta(), allPorts, info.get_resources_map()));
    }
    return ret;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SupervisorInfo(org.apache.storm.generated.SupervisorInfo) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) AtomicLong(java.util.concurrent.atomic.AtomicLong) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) IStormClusterState(org.apache.storm.cluster.IStormClusterState)

Example 2 with SupervisorInfo

use of org.apache.storm.generated.SupervisorInfo in project storm by apache.

the class Nimbus method getClusterInfoImpl.

private ClusterSummary getClusterInfoImpl() throws Exception {
    IStormClusterState state = stormClusterState;
    Map<String, SupervisorInfo> infos = state.allSupervisorInfo();
    List<SupervisorSummary> summaries = new ArrayList<>(infos.size());
    for (Entry<String, SupervisorInfo> entry : infos.entrySet()) {
        summaries.add(makeSupervisorSummary(entry.getKey(), entry.getValue()));
    }
    int uptime = this.uptime.upTime();
    Map<String, StormBase> bases = state.topologyBases();
    List<NimbusSummary> nimbuses = state.nimbuses();
    //update the isLeader field for each nimbus summary
    NimbusInfo leader = leaderElector.getLeader();
    for (NimbusSummary nimbusSummary : nimbuses) {
        nimbusSummary.set_uptime_secs(Time.deltaSecs(nimbusSummary.get_uptime_secs()));
        nimbusSummary.set_isLeader(leader.getHost().equals(nimbusSummary.get_host()) && leader.getPort() == nimbusSummary.get_port());
    }
    List<TopologySummary> topologySummaries = new ArrayList<>();
    for (Entry<String, StormBase> entry : bases.entrySet()) {
        StormBase base = entry.getValue();
        if (base == null) {
            continue;
        }
        String topoId = entry.getKey();
        Assignment assignment = state.assignmentInfo(topoId, null);
        int numTasks = 0;
        int numExecutors = 0;
        int numWorkers = 0;
        if (assignment != null && assignment.is_set_executor_node_port()) {
            for (List<Long> ids : assignment.get_executor_node_port().keySet()) {
                numTasks += StormCommon.executorIdToTasks(ids).size();
            }
            numExecutors = assignment.get_executor_node_port_size();
            numWorkers = new HashSet<>(assignment.get_executor_node_port().values()).size();
        }
        TopologySummary summary = new TopologySummary(topoId, base.get_name(), numTasks, numExecutors, numWorkers, Time.deltaSecs(base.get_launch_time_secs()), extractStatusStr(base));
        if (base.is_set_owner()) {
            summary.set_owner(base.get_owner());
        }
        String status = idToSchedStatus.get().get(topoId);
        if (status != null) {
            summary.set_sched_status(status);
        }
        TopologyResources resources = getResourcesForTopology(topoId, base);
        if (resources != null) {
            summary.set_requested_memonheap(resources.getRequestedMemOnHeap());
            summary.set_requested_memoffheap(resources.getRequestedMemOffHeap());
            summary.set_requested_cpu(resources.getRequestedCpu());
            summary.set_assigned_memonheap(resources.getAssignedMemOnHeap());
            summary.set_assigned_memoffheap(resources.getAssignedMemOffHeap());
            summary.set_assigned_cpu(resources.getAssignedCpu());
        }
        summary.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)));
        topologySummaries.add(summary);
    }
    ClusterSummary ret = new ClusterSummary(summaries, topologySummaries, nimbuses);
    ret.set_nimbus_uptime_secs(uptime);
    return ret;
}
Also used : ClusterSummary(org.apache.storm.generated.ClusterSummary) ArrayList(java.util.ArrayList) StormBase(org.apache.storm.generated.StormBase) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) NimbusSummary(org.apache.storm.generated.NimbusSummary) SupervisorInfo(org.apache.storm.generated.SupervisorInfo) DataPoint(org.apache.storm.metric.api.DataPoint) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) AtomicLong(java.util.concurrent.atomic.AtomicLong) TopologySummary(org.apache.storm.generated.TopologySummary) IStormClusterState(org.apache.storm.cluster.IStormClusterState) HashSet(java.util.HashSet)

Example 3 with SupervisorInfo

use of org.apache.storm.generated.SupervisorInfo in project storm by apache.

the class Nimbus method getSupervisorPageInfo.

@Override
public SupervisorPageInfo getSupervisorPageInfo(String superId, String host, boolean includeSys) throws NotAliveException, AuthorizationException, TException {
    try {
        getSupervisorPageInfoCalls.mark();
        IStormClusterState state = stormClusterState;
        Map<String, SupervisorInfo> superInfos = state.allSupervisorInfo();
        Map<String, List<String>> hostToSuperId = new HashMap<>();
        for (Entry<String, SupervisorInfo> entry : superInfos.entrySet()) {
            String h = entry.getValue().get_hostname();
            List<String> superIds = hostToSuperId.get(h);
            if (superIds == null) {
                superIds = new ArrayList<>();
                hostToSuperId.put(h, superIds);
            }
            superIds.add(entry.getKey());
        }
        List<String> supervisorIds = null;
        if (superId == null) {
            supervisorIds = hostToSuperId.get(host);
        } else {
            supervisorIds = Arrays.asList(superId);
        }
        SupervisorPageInfo pageInfo = new SupervisorPageInfo();
        Map<String, Assignment> topoToAssignment = state.topologyAssignments();
        for (String sid : supervisorIds) {
            SupervisorInfo info = superInfos.get(sid);
            LOG.info("SIDL {} SI: {} ALL: {}", sid, info, superInfos);
            SupervisorSummary supSum = makeSupervisorSummary(sid, info);
            pageInfo.add_to_supervisor_summaries(supSum);
            List<String> superTopologies = topologiesOnSupervisor(topoToAssignment, sid);
            Set<String> userTopologies = filterAuthorized("getTopology", superTopologies);
            for (String topoId : superTopologies) {
                CommonTopoInfo common = getCommonTopoInfo(topoId, "getSupervisorPageInfo");
                String topoName = common.topoName;
                Assignment assignment = common.assignment;
                Map<List<Integer>, Map<String, Object>> beats = common.beats;
                Map<Integer, String> taskToComp = common.taskToComponent;
                Map<List<Long>, List<Object>> exec2NodePort = new HashMap<>();
                Map<String, String> nodeToHost;
                if (assignment != null) {
                    Map<List<Long>, NodeInfo> execToNodeInfo = assignment.get_executor_node_port();
                    for (Entry<List<Long>, NodeInfo> entry : execToNodeInfo.entrySet()) {
                        NodeInfo ni = entry.getValue();
                        List<Object> nodePort = Arrays.asList(ni.get_node(), ni.get_port_iterator().next());
                        exec2NodePort.put(entry.getKey(), nodePort);
                    }
                    nodeToHost = assignment.get_node_host();
                } else {
                    nodeToHost = Collections.emptyMap();
                }
                Map<WorkerSlot, WorkerResources> workerResources = getWorkerResourcesForTopology(topoId);
                boolean isAllowed = userTopologies.contains(topoId);
                for (WorkerSummary workerSummary : StatsUtil.aggWorkerStats(topoId, topoName, taskToComp, beats, exec2NodePort, nodeToHost, workerResources, includeSys, isAllowed, sid)) {
                    pageInfo.add_to_worker_summaries(workerSummary);
                }
            }
        }
        return pageInfo;
    } catch (Exception e) {
        LOG.warn("Get super page info exception. (super id='{}')", superId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HashMap(java.util.HashMap) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) SupervisorInfo(org.apache.storm.generated.SupervisorInfo) Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) ArrayList(java.util.ArrayList) List(java.util.List) IStormClusterState(org.apache.storm.cluster.IStormClusterState) WorkerResources(org.apache.storm.generated.WorkerResources) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException) WorkerSummary(org.apache.storm.generated.WorkerSummary) SupervisorPageInfo(org.apache.storm.generated.SupervisorPageInfo) NodeInfo(org.apache.storm.generated.NodeInfo) Map(java.util.Map) TimeCacheMap(org.apache.storm.utils.TimeCacheMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 4 with SupervisorInfo

use of org.apache.storm.generated.SupervisorInfo in project storm by apache.

the class SupervisorHeartbeat method run.

@Override
public void run() {
    SupervisorInfo supervisorInfo = buildSupervisorInfo(conf, supervisor);
    stormClusterState.supervisorHeartbeat(supervisorId, supervisorInfo);
}
Also used : SupervisorInfo(org.apache.storm.generated.SupervisorInfo)

Example 5 with SupervisorInfo

use of org.apache.storm.generated.SupervisorInfo in project storm by apache.

the class SupervisorHeartbeat method buildSupervisorInfo.

private SupervisorInfo buildSupervisorInfo(Map<String, Object> conf, Supervisor supervisor) {
    SupervisorInfo supervisorInfo = new SupervisorInfo();
    supervisorInfo.set_time_secs(Time.currentTimeSecs());
    supervisorInfo.set_hostname(supervisor.getHostName());
    supervisorInfo.set_assignment_id(supervisor.getAssignmentId());
    List<Long> usedPorts = new ArrayList<>();
    usedPorts.addAll(supervisor.getCurrAssignment().get().keySet());
    supervisorInfo.set_used_ports(usedPorts);
    List metaDatas = (List) supervisor.getiSupervisor().getMetadata();
    List<Long> portList = new ArrayList<>();
    if (metaDatas != null) {
        for (Object data : metaDatas) {
            Integer port = Utils.getInt(data);
            if (port != null)
                portList.add(port.longValue());
        }
    }
    supervisorInfo.set_meta(portList);
    supervisorInfo.set_scheduler_meta((Map<String, String>) conf.get(Config.SUPERVISOR_SCHEDULER_META));
    supervisorInfo.set_uptime_secs(supervisor.getUpTime().upTime());
    supervisorInfo.set_version(supervisor.getStormVersion());
    supervisorInfo.set_resources_map(mkSupervisorCapacities(conf));
    return supervisorInfo;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) SupervisorInfo(org.apache.storm.generated.SupervisorInfo)

Aggregations

SupervisorInfo (org.apache.storm.generated.SupervisorInfo)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 IStormClusterState (org.apache.storm.cluster.IStormClusterState)3 HashSet (java.util.HashSet)2 List (java.util.List)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Assignment (org.apache.storm.generated.Assignment)2 SupervisorSummary (org.apache.storm.generated.SupervisorSummary)2 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)2 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)2 WorkerSlot (org.apache.storm.scheduler.WorkerSlot)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 BindException (java.net.BindException)1 Map (java.util.Map)1 Set (java.util.Set)1 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)1 AuthorizationException (org.apache.storm.generated.AuthorizationException)1