Search in sources :

Example 31 with SupervisorDetails

use of org.apache.storm.scheduler.SupervisorDetails in project storm by apache.

the class Node method getAllNodesFrom.

public static Map<String, Node> getAllNodesFrom(Cluster cluster) {
    Map<String, Node> nodeIdToNode = new HashMap<>();
    for (SupervisorDetails sup : cluster.getSupervisors().values()) {
        //Node ID and supervisor ID are the same.
        String id = sup.getId();
        boolean isAlive = !cluster.isBlackListed(id);
        LOG.debug("Found a {} Node {} {}", isAlive ? "living" : "dead", id, sup.getAllPorts());
        nodeIdToNode.put(id, new Node(id, sup.getAllPorts(), isAlive));
    }
    for (Entry<String, SchedulerAssignment> entry : cluster.getAssignments().entrySet()) {
        String topId = entry.getValue().getTopologyId();
        for (WorkerSlot ws : entry.getValue().getSlots()) {
            String id = ws.getNodeId();
            Node node = nodeIdToNode.get(id);
            if (node == null) {
                LOG.debug("Found an assigned slot on a dead supervisor {}", ws);
                node = new Node(id, null, false);
                nodeIdToNode.put(id, node);
            }
            if (!node.isAlive()) {
                //The supervisor on the node down so add an orphaned slot to hold the unsupervised worker 
                node.addOrphanedSlot(ws);
            }
            if (node.assignInternal(ws, topId, true)) {
                LOG.warn("Bad scheduling state for topology [" + topId + "], the slot " + ws + " assigned to multiple workers, un-assigning everything...");
                node.free(ws, cluster, true);
            }
        }
    }
    return nodeIdToNode;
}
Also used : SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) HashMap(java.util.HashMap) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails)

Example 32 with SupervisorDetails

use of org.apache.storm.scheduler.SupervisorDetails in project storm by apache.

the class RAS_Nodes method getAllNodesFrom.

public static Map<String, RAS_Node> getAllNodesFrom(Cluster cluster, Topologies topologies) {
    //A map of node ids to node objects
    Map<String, RAS_Node> nodeIdToNode = new HashMap<String, RAS_Node>();
    //A map of assignments organized by node with the following format:
    //{nodeId -> {topologyId -> {workerId -> {execs}}}}
    Map<String, Map<String, Map<String, Collection<ExecutorDetails>>>> assignmentRelationshipMap = new HashMap<String, Map<String, Map<String, Collection<ExecutorDetails>>>>();
    Map<String, Map<String, WorkerSlot>> workerIdToWorker = new HashMap<String, Map<String, WorkerSlot>>();
    for (SchedulerAssignment assignment : cluster.getAssignments().values()) {
        String topId = assignment.getTopologyId();
        for (Map.Entry<WorkerSlot, Collection<ExecutorDetails>> entry : assignment.getSlotToExecutors().entrySet()) {
            WorkerSlot slot = entry.getKey();
            String nodeId = slot.getNodeId();
            Collection<ExecutorDetails> execs = entry.getValue();
            if (!assignmentRelationshipMap.containsKey(nodeId)) {
                assignmentRelationshipMap.put(nodeId, new HashMap<String, Map<String, Collection<ExecutorDetails>>>());
                workerIdToWorker.put(nodeId, new HashMap<String, WorkerSlot>());
            }
            workerIdToWorker.get(nodeId).put(slot.getId(), slot);
            if (!assignmentRelationshipMap.get(nodeId).containsKey(topId)) {
                assignmentRelationshipMap.get(nodeId).put(topId, new HashMap<String, Collection<ExecutorDetails>>());
            }
            if (!assignmentRelationshipMap.get(nodeId).get(topId).containsKey(slot.getId())) {
                assignmentRelationshipMap.get(nodeId).get(topId).put(slot.getId(), new LinkedList<ExecutorDetails>());
            }
            assignmentRelationshipMap.get(nodeId).get(topId).get(slot.getId()).addAll(execs);
        }
    }
    for (SupervisorDetails sup : cluster.getSupervisors().values()) {
        //Initialize a worker slot for every port even if there is no assignment to it
        for (int port : sup.getAllPorts()) {
            WorkerSlot worker = new WorkerSlot(sup.getId(), port);
            if (!workerIdToWorker.containsKey(sup.getId())) {
                workerIdToWorker.put(sup.getId(), new HashMap<String, WorkerSlot>());
            }
            if (!workerIdToWorker.get(sup.getId()).containsKey(worker.getId())) {
                workerIdToWorker.get(sup.getId()).put(worker.getId(), worker);
            }
        }
        nodeIdToNode.put(sup.getId(), new RAS_Node(sup.getId(), sup, cluster, topologies, workerIdToWorker.get(sup.getId()), assignmentRelationshipMap.get(sup.getId())));
    }
    //Add in supervisors that might have crashed but workers are still alive
    for (Map.Entry<String, Map<String, Map<String, Collection<ExecutorDetails>>>> entry : assignmentRelationshipMap.entrySet()) {
        String nodeId = entry.getKey();
        Map<String, Map<String, Collection<ExecutorDetails>>> assignments = entry.getValue();
        if (!nodeIdToNode.containsKey(nodeId)) {
            LOG.info("Found an assigned slot(s) on a dead supervisor {} with assignments {}", nodeId, assignments);
            nodeIdToNode.put(nodeId, new RAS_Node(nodeId, null, cluster, topologies, workerIdToWorker.get(nodeId), assignments));
        }
    }
    return nodeIdToNode;
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) HashMap(java.util.HashMap) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Collection(java.util.Collection) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)32 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)32 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)27 Cluster (org.apache.storm.scheduler.Cluster)24 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)24 Topologies (org.apache.storm.scheduler.Topologies)24 INimbus (org.apache.storm.scheduler.INimbus)23 Test (org.junit.Test)23 Config (org.apache.storm.Config)22 Map (java.util.Map)19 WorkerSlot (org.apache.storm.scheduler.WorkerSlot)16 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)14 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)12 ArrayList (java.util.ArrayList)10 StormTopology (org.apache.storm.generated.StormTopology)8 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)8 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7 List (java.util.List)7 ResourceAwareScheduler (org.apache.storm.scheduler.resource.ResourceAwareScheduler)6