Search in sources :

Example 11 with Bolt

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

the class TestTridentTopology method testGenBoltId.

@Test
public void testGenBoltId() {
    Set<String> pre = null;
    for (int i = 0; i < 100; i++) {
        StormTopology topology = buildTopology();
        Map<String, Bolt> cur = topology.get_bolts();
        System.out.println(cur.keySet());
        if (pre != null) {
            Assert.assertTrue("bold id not consistent with group name", pre.equals(cur.keySet()));
        }
        pre = cur.keySet();
    }
}
Also used : StormTopology(org.apache.storm.generated.StormTopology) Bolt(org.apache.storm.generated.Bolt) Test(org.junit.Test)

Example 12 with Bolt

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

the class StormCommon method addSystemComponents.

@SuppressWarnings("unused")
public static void addSystemComponents(Map conf, StormTopology topology) {
    Map<String, StreamInfo> outputStreams = new HashMap<>();
    outputStreams.put(Constants.SYSTEM_TICK_STREAM_ID, Thrift.outputFields(Arrays.asList("rate_secs")));
    outputStreams.put(Constants.METRICS_TICK_STREAM_ID, Thrift.outputFields(Arrays.asList("interval")));
    outputStreams.put(Constants.CREDENTIALS_CHANGED_STREAM_ID, Thrift.outputFields(Arrays.asList("creds")));
    Map<String, Object> boltConf = new HashMap<>();
    boltConf.put(Config.TOPOLOGY_TASKS, 0);
    Bolt systemBoltSpec = Thrift.prepareSerializedBoltDetails(null, new SystemBolt(), outputStreams, 0, boltConf);
    topology.put_to_bolts(Constants.SYSTEM_COMPONENT_ID, systemBoltSpec);
}
Also used : HashMap(java.util.HashMap) StreamInfo(org.apache.storm.generated.StreamInfo) Bolt(org.apache.storm.generated.Bolt) MetricsConsumerBolt(org.apache.storm.metric.MetricsConsumerBolt) IBolt(org.apache.storm.task.IBolt) EventLoggerBolt(org.apache.storm.metric.EventLoggerBolt) SystemBolt(org.apache.storm.metric.SystemBolt) SystemBolt(org.apache.storm.metric.SystemBolt)

Example 13 with Bolt

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

the class StormCommon method addEventLogger.

public static void addEventLogger(Map conf, StormTopology topology) {
    Integer numExecutors = Utils.getInt(conf.get(Config.TOPOLOGY_EVENTLOGGER_EXECUTORS), Utils.getInt(conf.get(Config.TOPOLOGY_WORKERS)));
    HashMap<String, Object> componentConf = new HashMap<>();
    componentConf.put(Config.TOPOLOGY_TASKS, numExecutors);
    componentConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, Utils.getInt(conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)));
    Bolt eventLoggerBolt = Thrift.prepareSerializedBoltDetails(eventLoggerInputs(topology), new EventLoggerBolt(), null, numExecutors, componentConf);
    for (Object component : allComponents(topology).values()) {
        ComponentCommon common = getComponentCommon(component);
        common.put_to_streams(EVENTLOGGER_STREAM_ID, Thrift.outputFields(eventLoggerBoltFields()));
    }
    topology.put_to_bolts(EVENTLOGGER_COMPONENT_ID, eventLoggerBolt);
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) HashMap(java.util.HashMap) EventLoggerBolt(org.apache.storm.metric.EventLoggerBolt) Bolt(org.apache.storm.generated.Bolt) MetricsConsumerBolt(org.apache.storm.metric.MetricsConsumerBolt) IBolt(org.apache.storm.task.IBolt) EventLoggerBolt(org.apache.storm.metric.EventLoggerBolt) SystemBolt(org.apache.storm.metric.SystemBolt)

Example 14 with Bolt

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

the class StormCommon method metricsConsumerBoltSpecs.

@SuppressWarnings("unchecked")
public static Map<String, Bolt> metricsConsumerBoltSpecs(Map conf, StormTopology topology) {
    Map<String, Bolt> metricsConsumerBolts = new HashMap<>();
    Set<String> componentIdsEmitMetrics = new HashSet<>();
    componentIdsEmitMetrics.addAll(allComponents(topology).keySet());
    componentIdsEmitMetrics.add(Constants.SYSTEM_COMPONENT_ID);
    Map<GlobalStreamId, Grouping> inputs = new HashMap<>();
    for (String componentId : componentIdsEmitMetrics) {
        inputs.put(Utils.getGlobalStreamId(componentId, Constants.METRICS_STREAM_ID), Thrift.prepareShuffleGrouping());
    }
    List<Map<String, Object>> registerInfo = (List<Map<String, Object>>) conf.get(Config.TOPOLOGY_METRICS_CONSUMER_REGISTER);
    if (registerInfo != null) {
        Map<String, Integer> classOccurrencesMap = new HashMap<String, Integer>();
        for (Map<String, Object> info : registerInfo) {
            String className = (String) info.get(TOPOLOGY_METRICS_CONSUMER_CLASS);
            Object argument = info.get(TOPOLOGY_METRICS_CONSUMER_ARGUMENT);
            Integer maxRetainMetricTuples = Utils.getInt(info.get(TOPOLOGY_METRICS_CONSUMER_MAX_RETAIN_METRIC_TUPLES), 100);
            Integer phintNum = Utils.getInt(info.get(TOPOLOGY_METRICS_CONSUMER_PARALLELISM_HINT), 1);
            Map<String, Object> metricsConsumerConf = new HashMap<String, Object>();
            metricsConsumerConf.put(Config.TOPOLOGY_TASKS, phintNum);
            List<String> whitelist = (List<String>) info.get(TOPOLOGY_METRICS_CONSUMER_WHITELIST);
            List<String> blacklist = (List<String>) info.get(TOPOLOGY_METRICS_CONSUMER_BLACKLIST);
            FilterByMetricName filterPredicate = new FilterByMetricName(whitelist, blacklist);
            Boolean expandMapType = Utils.getBoolean(info.get(TOPOLOGY_METRICS_CONSUMER_EXPAND_MAP_TYPE), false);
            String metricNameSeparator = Utils.getString(info.get(TOPOLOGY_METRICS_CONSUMER_METRIC_NAME_SEPARATOR), ".");
            DataPointExpander expander = new DataPointExpander(expandMapType, metricNameSeparator);
            MetricsConsumerBolt boltInstance = new MetricsConsumerBolt(className, argument, maxRetainMetricTuples, filterPredicate, expander);
            Bolt metricsConsumerBolt = Thrift.prepareSerializedBoltDetails(inputs, boltInstance, null, phintNum, metricsConsumerConf);
            String id = className;
            if (classOccurrencesMap.containsKey(className)) {
                // e.g. [\"a\", \"b\", \"a\"]) => [\"a\", \"b\", \"a#2\"]"
                int occurrenceNum = classOccurrencesMap.get(className);
                occurrenceNum++;
                classOccurrencesMap.put(className, occurrenceNum);
                id = Constants.METRICS_COMPONENT_ID_PREFIX + className + "#" + occurrenceNum;
            } else {
                classOccurrencesMap.put(className, 1);
            }
            metricsConsumerBolts.put(id, metricsConsumerBolt);
        }
    }
    return metricsConsumerBolts;
}
Also used : FilterByMetricName(org.apache.storm.metric.filter.FilterByMetricName) HashMap(java.util.HashMap) Bolt(org.apache.storm.generated.Bolt) MetricsConsumerBolt(org.apache.storm.metric.MetricsConsumerBolt) IBolt(org.apache.storm.task.IBolt) EventLoggerBolt(org.apache.storm.metric.EventLoggerBolt) SystemBolt(org.apache.storm.metric.SystemBolt) Grouping(org.apache.storm.generated.Grouping) MetricsConsumerBolt(org.apache.storm.metric.MetricsConsumerBolt) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) ArrayList(java.util.ArrayList) List(java.util.List) DataPointExpander(org.apache.storm.metric.util.DataPointExpander) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 15 with Bolt

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

the class TestUtilsForResourceAwareScheduler method genExecsAndComps.

public static Map<ExecutorDetails, String> genExecsAndComps(StormTopology topology) {
    Map<ExecutorDetails, String> retMap = new HashMap<ExecutorDetails, String>();
    int startTask = 0;
    int endTask = 0;
    for (Map.Entry<String, SpoutSpec> entry : topology.get_spouts().entrySet()) {
        SpoutSpec spout = entry.getValue();
        String spoutId = entry.getKey();
        int spoutParallelism = spout.get_common().get_parallelism_hint();
        for (int i = 0; i < spoutParallelism; i++) {
            retMap.put(new ExecutorDetails(startTask, endTask), spoutId);
            startTask++;
            endTask++;
        }
    }
    for (Map.Entry<String, Bolt> entry : topology.get_bolts().entrySet()) {
        String boltId = entry.getKey();
        Bolt bolt = entry.getValue();
        int boltParallelism = bolt.get_common().get_parallelism_hint();
        for (int i = 0; i < boltParallelism; i++) {
            retMap.put(new ExecutorDetails(startTask, endTask), boltId);
            startTask++;
            endTask++;
        }
    }
    return retMap;
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) SpoutSpec(org.apache.storm.generated.SpoutSpec) HashMap(java.util.HashMap) Bolt(org.apache.storm.generated.Bolt) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Bolt (org.apache.storm.generated.Bolt)17 HashMap (java.util.HashMap)12 Map (java.util.Map)9 SpoutSpec (org.apache.storm.generated.SpoutSpec)8 StormTopology (org.apache.storm.generated.StormTopology)8 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)7 Grouping (org.apache.storm.generated.Grouping)6 EventLoggerBolt (org.apache.storm.metric.EventLoggerBolt)4 MetricsConsumerBolt (org.apache.storm.metric.MetricsConsumerBolt)4 SystemBolt (org.apache.storm.metric.SystemBolt)4 IBolt (org.apache.storm.task.IBolt)4 IRichBolt (org.apache.storm.topology.IRichBolt)4 BaseRichBolt (org.apache.storm.topology.base.BaseRichBolt)4 ArrayList (java.util.ArrayList)3 ComponentCommon (org.apache.storm.generated.ComponentCommon)3 NullStruct (org.apache.storm.generated.NullStruct)3 StateSpoutSpec (org.apache.storm.generated.StateSpoutSpec)3 StreamInfo (org.apache.storm.generated.StreamInfo)3 BaseWindowedBolt (org.apache.storm.topology.base.BaseWindowedBolt)3 Test (org.junit.Test)3