Search in sources :

Example 1 with IBolt

use of backtype.storm.task.IBolt in project jstorm by alibaba.

the class Common method addTopologyMaster.

/**
     * Add topology master bolt to topology
     */
public static void addTopologyMaster(Map stormConf, StormTopology ret) {
    // generate outputs
    HashMap<String, StreamInfo> outputs = new HashMap<String, StreamInfo>();
    List<String> list = JStormUtils.mk_list(TopologyMaster.FILED_CTRL_EVENT);
    outputs.put(TOPOLOGY_MASTER_CONTROL_STREAM_ID, Thrift.outputFields(list));
    list = JStormUtils.mk_list(TopologyMaster.FIELD_METRIC_WORKER, TopologyMaster.FIELD_METRIC_METRICS);
    outputs.put(TOPOLOGY_MASTER_METRICS_STREAM_ID, Thrift.outputFields(list));
    list = JStormUtils.mk_list(TopologyMaster.FILED_HEARBEAT_EVENT);
    outputs.put(TOPOLOGY_MASTER_HB_STREAM_ID, Thrift.outputFields(list));
    list = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS);
    outputs.put(TOPOLOGY_MASTER_REGISTER_METRICS_STREAM_ID, Thrift.outputFields(list));
    list = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS_RESP);
    outputs.put(TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID, Thrift.outputFields(list));
    IBolt topologyMaster = new TopologyMaster();
    // generate inputs
    Map<GlobalStreamId, Grouping> inputs = topoMasterInputs(ret);
    // generate topology master which will be stored in topology
    Bolt topologyMasterBolt = Thrift.mkBolt(inputs, topologyMaster, outputs, 1);
    // add output stream to spout/bolt
    for (Entry<String, Bolt> e : ret.get_bolts().entrySet()) {
        Bolt bolt = e.getValue();
        ComponentCommon common = bolt.get_common();
        List<String> fields = JStormUtils.mk_list(TopologyMaster.FIELD_METRIC_WORKER, TopologyMaster.FIELD_METRIC_METRICS);
        common.put_to_streams(TOPOLOGY_MASTER_METRICS_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FILED_HEARBEAT_EVENT);
        common.put_to_streams(TOPOLOGY_MASTER_HB_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FILED_CTRL_EVENT);
        common.put_to_streams(TOPOLOGY_MASTER_CONTROL_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS);
        common.put_to_streams(TOPOLOGY_MASTER_REGISTER_METRICS_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS_RESP);
        common.put_to_streams(TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID, Thrift.directOutputFields(fields));
        GlobalStreamId stream = new GlobalStreamId(TOPOLOGY_MASTER_COMPONENT_ID, TOPOLOGY_MASTER_CONTROL_STREAM_ID);
        common.put_to_inputs(stream, Thrift.mkDirectGrouping());
        bolt.set_common(common);
    }
    for (Entry<String, SpoutSpec> kv : ret.get_spouts().entrySet()) {
        SpoutSpec spout = kv.getValue();
        ComponentCommon common = spout.get_common();
        List<String> fields = JStormUtils.mk_list(TopologyMaster.FIELD_METRIC_WORKER, TopologyMaster.FIELD_METRIC_METRICS);
        common.put_to_streams(TOPOLOGY_MASTER_METRICS_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FILED_HEARBEAT_EVENT);
        common.put_to_streams(TOPOLOGY_MASTER_HB_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FILED_CTRL_EVENT);
        common.put_to_streams(TOPOLOGY_MASTER_CONTROL_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS);
        common.put_to_streams(TOPOLOGY_MASTER_REGISTER_METRICS_STREAM_ID, Thrift.directOutputFields(fields));
        fields = JStormUtils.mk_list(TopologyMaster.FIELD_REGISTER_METRICS_RESP);
        common.put_to_streams(TOPOLOGY_MASTER_REGISTER_METRICS_RESP_STREAM_ID, Thrift.directOutputFields(fields));
        GlobalStreamId stream = new GlobalStreamId(TOPOLOGY_MASTER_COMPONENT_ID, TOPOLOGY_MASTER_CONTROL_STREAM_ID);
        common.put_to_inputs(stream, Thrift.mkDirectGrouping());
        spout.set_common(common);
    }
    ret.put_to_bolts(TOPOLOGY_MASTER_COMPONENT_ID, topologyMasterBolt);
}
Also used : ShellBolt(backtype.storm.task.ShellBolt) IBolt(backtype.storm.task.IBolt) SystemBolt(backtype.storm.metric.SystemBolt) TopologyMaster(com.alibaba.jstorm.task.master.TopologyMaster) IBolt(backtype.storm.task.IBolt)

Example 2 with IBolt

use of backtype.storm.task.IBolt in project jstorm by alibaba.

the class Common method add_acker.

/**
     * Add acker bolt to topology
     */
public static void add_acker(Map stormConf, StormTopology ret) {
    String key = Config.TOPOLOGY_ACKER_EXECUTORS;
    Integer ackerNum = JStormUtils.parseInt(stormConf.get(key), 0);
    // generate outputs
    HashMap<String, StreamInfo> outputs = new HashMap<String, StreamInfo>();
    ArrayList<String> fields = new ArrayList<String>();
    fields.add("id");
    outputs.put(ACKER_ACK_STREAM_ID, Thrift.directOutputFields(fields));
    outputs.put(ACKER_FAIL_STREAM_ID, Thrift.directOutputFields(fields));
    IBolt ackerbolt = new Acker();
    // generate inputs
    Map<GlobalStreamId, Grouping> inputs = acker_inputs(ret);
    // generate acker which will be stored in topology
    Bolt acker_bolt = Thrift.mkBolt(inputs, ackerbolt, outputs, ackerNum);
    // ACKER_ACK_STREAM_ID/ACKER_FAIL_STREAM_ID
    for (Entry<String, Bolt> e : ret.get_bolts().entrySet()) {
        Bolt bolt = e.getValue();
        ComponentCommon common = bolt.get_common();
        List<String> ackList = JStormUtils.mk_list("id", "ack-val");
        common.put_to_streams(ACKER_ACK_STREAM_ID, Thrift.outputFields(ackList));
        List<String> failList = JStormUtils.mk_list("id");
        common.put_to_streams(ACKER_FAIL_STREAM_ID, Thrift.outputFields(failList));
        bolt.set_common(common);
    }
    // ((ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID), directGrouping)
    for (Entry<String, SpoutSpec> kv : ret.get_spouts().entrySet()) {
        SpoutSpec bolt = kv.getValue();
        ComponentCommon common = bolt.get_common();
        List<String> initList = JStormUtils.mk_list("id", "init-val", "spout-task");
        common.put_to_streams(ACKER_INIT_STREAM_ID, Thrift.outputFields(initList));
        GlobalStreamId ack_ack = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_ACK_STREAM_ID);
        common.put_to_inputs(ack_ack, Thrift.mkDirectGrouping());
        GlobalStreamId ack_fail = new GlobalStreamId(ACKER_COMPONENT_ID, ACKER_FAIL_STREAM_ID);
        common.put_to_inputs(ack_fail, Thrift.mkDirectGrouping());
    }
    ret.put_to_bolts(ACKER_COMPONENT_ID, acker_bolt);
}
Also used : ShellBolt(backtype.storm.task.ShellBolt) IBolt(backtype.storm.task.IBolt) SystemBolt(backtype.storm.metric.SystemBolt) Acker(com.alibaba.jstorm.task.acker.Acker) IBolt(backtype.storm.task.IBolt)

Example 3 with IBolt

use of backtype.storm.task.IBolt in project jstorm by alibaba.

the class Common method add_system_components.

public static StormTopology add_system_components(StormTopology topology) {
    // generate inputs
    Map<GlobalStreamId, Grouping> inputs = new HashMap<GlobalStreamId, Grouping>();
    // generate outputs
    HashMap<String, StreamInfo> outputs = new HashMap<String, StreamInfo>();
    //ArrayList<String> fields = new ArrayList<String>();
    outputs.put(Constants.SYSTEM_TICK_STREAM_ID, Thrift.outputFields(JStormUtils.mk_list("rate_secs")));
    outputs.put(Constants.METRICS_TICK_STREAM_ID, Thrift.outputFields(JStormUtils.mk_list("interval")));
    outputs.put(Constants.CREDENTIALS_CHANGED_STREAM_ID, Thrift.outputFields(JStormUtils.mk_list("creds")));
    // ComponentCommon common = new ComponentCommon(inputs, outputs);
    IBolt ackerbolt = new SystemBolt();
    Bolt bolt = Thrift.mkBolt(inputs, ackerbolt, outputs, Integer.valueOf(0));
    topology.put_to_bolts(Constants.SYSTEM_COMPONENT_ID, bolt);
    add_system_streams(topology);
    return topology;
}
Also used : IBolt(backtype.storm.task.IBolt) ShellBolt(backtype.storm.task.ShellBolt) IBolt(backtype.storm.task.IBolt) SystemBolt(backtype.storm.metric.SystemBolt) SystemBolt(backtype.storm.metric.SystemBolt)

Aggregations

SystemBolt (backtype.storm.metric.SystemBolt)3 IBolt (backtype.storm.task.IBolt)3 ShellBolt (backtype.storm.task.ShellBolt)3 Acker (com.alibaba.jstorm.task.acker.Acker)1 TopologyMaster (com.alibaba.jstorm.task.master.TopologyMaster)1