Search in sources :

Example 1 with ComponentObject

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

the class Task method mkTaskObject.

private Object mkTaskObject() {
    StormTopology topology = systemTopologyContext.getRawTopology();
    Map<String, SpoutSpec> spouts = topology.get_spouts();
    Map<String, Bolt> bolts = topology.get_bolts();
    Map<String, StateSpoutSpec> stateSpouts = topology.get_state_spouts();
    Object result;
    ComponentObject componentObject;
    if (spouts.containsKey(componentId)) {
        componentObject = spouts.get(componentId).get_spout_object();
    } else if (bolts.containsKey(componentId)) {
        componentObject = bolts.get(componentId).get_bolt_object();
    } else if (stateSpouts.containsKey(componentId)) {
        componentObject = stateSpouts.get(componentId).get_state_spout_object();
    } else {
        throw new RuntimeException("Could not find " + componentId + " in " + topology);
    }
    result = Utils.getSetComponentObject(componentObject);
    if (result instanceof ShellComponent) {
        if (spouts.containsKey(componentId)) {
            result = new ShellSpout((ShellComponent) result);
        } else {
            result = new ShellBolt((ShellComponent) result);
        }
    }
    if (result instanceof JavaObject) {
        result = Thrift.instantiateJavaObject((JavaObject) result);
    }
    return result;
}
Also used : StormTopology(org.apache.storm.generated.StormTopology) ShellSpout(org.apache.storm.spout.ShellSpout) Bolt(org.apache.storm.generated.Bolt) ShellBolt(org.apache.storm.task.ShellBolt) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) SpoutSpec(org.apache.storm.generated.SpoutSpec) JavaObject(org.apache.storm.generated.JavaObject) ComponentObject(org.apache.storm.generated.ComponentObject) ShellBolt(org.apache.storm.task.ShellBolt) JavaObject(org.apache.storm.generated.JavaObject) ComponentObject(org.apache.storm.generated.ComponentObject) ShellComponent(org.apache.storm.generated.ShellComponent)

Example 2 with ComponentObject

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

the class TopologySpoutLag method lag.

public static Map<String, Map<String, Object>> lag(StormTopology stormTopology, Map topologyConf) {
    Map<String, Map<String, Object>> result = new HashMap<>();
    Map<String, SpoutSpec> spouts = stormTopology.get_spouts();
    String className = null;
    for (Map.Entry<String, SpoutSpec> spout : spouts.entrySet()) {
        try {
            SpoutSpec spoutSpec = spout.getValue();
            ComponentObject componentObject = spoutSpec.get_spout_object();
            // FIXME: yes it's a trick so we might be better to find alternative way...
            className = getClassNameFromComponentObject(componentObject);
            logger.debug("spout classname: {}", className);
            if (className.endsWith("storm.kafka.spout.KafkaSpout")) {
                result.put(spout.getKey(), getLagResultForNewKafkaSpout(spout.getKey(), spoutSpec, topologyConf));
            } else if (className.endsWith("storm.kafka.KafkaSpout")) {
                result.put(spout.getKey(), getLagResultForOldKafkaSpout(spout.getKey(), spoutSpec, topologyConf));
            }
        } catch (Exception e) {
            logger.warn("Exception thrown while getting lag for spout id: " + spout.getKey() + " and spout class: " + className);
            logger.warn("Exception message:" + e.getMessage(), e);
        }
    }
    return result;
}
Also used : SpoutSpec(org.apache.storm.generated.SpoutSpec) HashMap(java.util.HashMap) ComponentObject(org.apache.storm.generated.ComponentObject) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) ParseException(org.json.simple.parser.ParseException)

Aggregations

ComponentObject (org.apache.storm.generated.ComponentObject)2 SpoutSpec (org.apache.storm.generated.SpoutSpec)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Bolt (org.apache.storm.generated.Bolt)1 JavaObject (org.apache.storm.generated.JavaObject)1 ShellComponent (org.apache.storm.generated.ShellComponent)1 StateSpoutSpec (org.apache.storm.generated.StateSpoutSpec)1 StormTopology (org.apache.storm.generated.StormTopology)1 ShellSpout (org.apache.storm.spout.ShellSpout)1 ShellBolt (org.apache.storm.task.ShellBolt)1 ParseException (org.json.simple.parser.ParseException)1