Search in sources :

Example 1 with WorkerSummary

use of org.apache.storm.generated.WorkerSummary 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 2 with WorkerSummary

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

the class Nimbus method getTopologyPageInfo.

@Override
public TopologyPageInfo getTopologyPageInfo(String topoId, String window, boolean includeSys) throws NotAliveException, AuthorizationException, TException {
    try {
        getTopologyPageInfoCalls.mark();
        CommonTopoInfo common = getCommonTopoInfo(topoId, "getTopologyPageInfo");
        String topoName = common.topoName;
        IStormClusterState state = stormClusterState;
        int launchTimeSecs = common.launchTimeSecs;
        Assignment assignment = common.assignment;
        Map<List<Integer>, Map<String, Object>> beats = common.beats;
        Map<Integer, String> taskToComp = common.taskToComponent;
        StormTopology topology = common.topology;
        Map<String, Object> topoConf = common.topoConf;
        StormBase base = common.base;
        if (base == null) {
            throw new NotAliveException(topoId);
        }
        Map<WorkerSlot, WorkerResources> workerToResources = getWorkerResourcesForTopology(topoId);
        List<WorkerSummary> workerSummaries = null;
        Map<List<Long>, List<Object>> exec2NodePort = new HashMap<>();
        if (assignment != null) {
            Map<List<Long>, NodeInfo> execToNodeInfo = assignment.get_executor_node_port();
            Map<String, String> nodeToHost = assignment.get_node_host();
            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);
            }
            workerSummaries = StatsUtil.aggWorkerStats(topoId, topoName, taskToComp, beats, exec2NodePort, nodeToHost, workerToResources, includeSys, //this is the topology page, so we know the user is authorized
            true);
        }
        TopologyPageInfo topoPageInfo = StatsUtil.aggTopoExecsStats(topoId, exec2NodePort, taskToComp, beats, topology, window, includeSys, state);
        Map<String, Map<String, Double>> spoutResources = ResourceUtils.getSpoutsResources(topology, topoConf);
        for (Entry<String, ComponentAggregateStats> entry : topoPageInfo.get_id_to_spout_agg_stats().entrySet()) {
            CommonAggregateStats commonStats = entry.getValue().get_common_stats();
            commonStats.set_resources_map(setResourcesDefaultIfNotSet(spoutResources, entry.getKey(), topoConf));
        }
        Map<String, Map<String, Double>> boltResources = ResourceUtils.getBoltsResources(topology, topoConf);
        for (Entry<String, ComponentAggregateStats> entry : topoPageInfo.get_id_to_bolt_agg_stats().entrySet()) {
            CommonAggregateStats commonStats = entry.getValue().get_common_stats();
            commonStats.set_resources_map(setResourcesDefaultIfNotSet(boltResources, entry.getKey(), topoConf));
        }
        if (workerSummaries != null) {
            topoPageInfo.set_workers(workerSummaries);
        }
        if (base.is_set_owner()) {
            topoPageInfo.set_owner(base.get_owner());
        }
        String schedStatus = idToSchedStatus.get().get(topoId);
        if (schedStatus != null) {
            topoPageInfo.set_sched_status(schedStatus);
        }
        TopologyResources resources = getResourcesForTopology(topoId, base);
        if (resources != null) {
            topoPageInfo.set_requested_memonheap(resources.getRequestedMemOnHeap());
            topoPageInfo.set_requested_memoffheap(resources.getRequestedMemOffHeap());
            topoPageInfo.set_requested_cpu(resources.getRequestedCpu());
            topoPageInfo.set_assigned_memonheap(resources.getAssignedMemOnHeap());
            topoPageInfo.set_assigned_memoffheap(resources.getAssignedMemOffHeap());
            topoPageInfo.set_assigned_cpu(resources.getAssignedCpu());
        }
        topoPageInfo.set_name(topoName);
        topoPageInfo.set_status(extractStatusStr(base));
        topoPageInfo.set_uptime_secs(Time.deltaSecs(launchTimeSecs));
        topoPageInfo.set_topology_conf(JSONValue.toJSONString(topoConf));
        topoPageInfo.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)));
        if (base.is_set_component_debug()) {
            DebugOptions debug = base.get_component_debug().get(topoId);
            if (debug != null) {
                topoPageInfo.set_debug_options(debug);
            }
        }
        return topoPageInfo;
    } catch (Exception e) {
        LOG.warn("Get topo page info exception. (topology id='{}')", topoId, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) StormBase(org.apache.storm.generated.StormBase) DebugOptions(org.apache.storm.generated.DebugOptions) Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) NotAliveException(org.apache.storm.generated.NotAliveException) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) ArrayList(java.util.ArrayList) List(java.util.List) IStormClusterState(org.apache.storm.cluster.IStormClusterState) CommonAggregateStats(org.apache.storm.generated.CommonAggregateStats) WorkerResources(org.apache.storm.generated.WorkerResources) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) TopologyPageInfo(org.apache.storm.generated.TopologyPageInfo) DataPoint(org.apache.storm.metric.api.DataPoint) 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) 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 3 with WorkerSummary

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

the class TestStatsUtil method checkWorkerStats.

private List<WorkerSummary> checkWorkerStats(boolean includeSys, boolean userAuthorized, String filterSupervisor) {
    List<WorkerSummary> summaries = StatsUtil.aggWorkerStats("my-storm-id", "my-storm-name", task2Component, beats, exec2NodePort, nodeHost, worker2Resources, includeSys, userAuthorized, filterSupervisor);
    for (WorkerSummary ws : summaries) {
        String host = ws.get_host();
        int port = ws.get_port();
        Assert.assertEquals("my-storm-id", ws.get_topology_id());
        Assert.assertEquals("my-storm-name", ws.get_topology_name());
        boolean includeSupervisor = filterSupervisor == null || filterSupervisor.equals(host);
        switch(port) {
            case 1:
                Assert.assertEquals("host1", ws.get_host());
                Assert.assertEquals("node1", ws.get_supervisor_id());
                Assert.assertEquals(1, ws.get_num_executors());
                Assert.assertEquals(100, ws.get_uptime_secs());
                Assert.assertEquals(1.0, ws.get_assigned_memonheap(), 0.001);
                Assert.assertEquals(2.0, ws.get_assigned_memoffheap(), 0.001);
                Assert.assertEquals(3.0, ws.get_assigned_cpu(), 0.001);
                break;
            case 2:
                Assert.assertEquals("host2", ws.get_host());
                Assert.assertEquals("node2", ws.get_supervisor_id());
                Assert.assertEquals(1, ws.get_num_executors());
                Assert.assertEquals(200, ws.get_uptime_secs());
                Assert.assertEquals(4.0, ws.get_assigned_memonheap(), 0.001);
                Assert.assertEquals(8.0, ws.get_assigned_memoffheap(), 0.001);
                Assert.assertEquals(12.0, ws.get_assigned_cpu(), 0.001);
                break;
            case 3:
                Assert.assertEquals("host3", ws.get_host());
                Assert.assertEquals("node3", ws.get_supervisor_id());
                Assert.assertEquals(1, ws.get_num_executors());
                // no heartbeat for this one, should be 0
                Assert.assertEquals(0, ws.get_uptime_secs());
                Assert.assertEquals(16.0, ws.get_assigned_memonheap(), 0.001);
                Assert.assertEquals(32.0, ws.get_assigned_memoffheap(), 0.001);
                Assert.assertEquals(48.0, ws.get_assigned_cpu(), 0.001);
                break;
        }
    }
    // get the worker count back s.t. we can assert in each test function
    return summaries;
}
Also used : WorkerSummary(org.apache.storm.generated.WorkerSummary)

Example 4 with WorkerSummary

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

the class TestStatsUtil method aggWorkerStatsWithHiddenSystemComponents.

@Test
public void aggWorkerStatsWithHiddenSystemComponents() {
    makeTopoInfoWithSysWorker();
    List<WorkerSummary> summaries = checkWorkerStats(false, /*DON'T include sys*/
    true, /*user authorized*/
    null);
    WorkerSummary ws1 = getWorkerSummaryForPort(summaries, 1);
    WorkerSummary ws2 = getWorkerSummaryForPort(summaries, 2);
    Assert.assertEquals(1, ws1.get_component_to_num_tasks().size());
    // since we made sys components hidden, the component map is empty for this worker
    Assert.assertEquals(0, ws2.get_component_to_num_tasks().size());
    Assert.assertEquals(2, summaries.size());
}
Also used : WorkerSummary(org.apache.storm.generated.WorkerSummary) Test(org.junit.Test)

Example 5 with WorkerSummary

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

the class TestStatsUtil method aggWorkerStatsFilterSupervisor.

@Test
public void aggWorkerStatsFilterSupervisor() {
    makeTopoInfoWithMissingBeats();
    List<WorkerSummary> summaries = checkWorkerStats(true, /*include sys*/
    true, /*user authorized*/
    "node3");
    WorkerSummary ws = getWorkerSummaryForPort(summaries, 3);
    // only host3 should be returned given filter
    Assert.assertEquals(2, ws.get_component_to_num_tasks().size());
    Assert.assertEquals(2, ws.get_component_to_num_tasks().get("__sys4").intValue());
    Assert.assertEquals(1, ws.get_component_to_num_tasks().get("my-component2").intValue());
    Assert.assertEquals(1, summaries.size());
}
Also used : WorkerSummary(org.apache.storm.generated.WorkerSummary) Test(org.junit.Test)

Aggregations

WorkerSummary (org.apache.storm.generated.WorkerSummary)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 WorkerResources (org.apache.storm.generated.WorkerResources)3 WorkerSlot (org.apache.storm.scheduler.WorkerSlot)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 BindException (java.net.BindException)2 IStormClusterState (org.apache.storm.cluster.IStormClusterState)2 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)2 Assignment (org.apache.storm.generated.Assignment)2 AuthorizationException (org.apache.storm.generated.AuthorizationException)2 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)2 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)2 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)2 NodeInfo (org.apache.storm.generated.NodeInfo)2