Search in sources :

Example 26 with ComponentCommon

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

the class TopologyBuilder method createTopology.

public StormTopology createTopology() {
    Map<String, Bolt> boltSpecs = new HashMap<>();
    Map<String, SpoutSpec> spoutSpecs = new HashMap<>();
    maybeAddCheckpointSpout();
    for (String boltId : bolts.keySet()) {
        IRichBolt bolt = bolts.get(boltId);
        bolt = maybeAddCheckpointTupleForwarder(bolt);
        ComponentCommon common = getComponentCommon(boltId, bolt);
        try {
            maybeAddCheckpointInputs(common);
            boltSpecs.put(boltId, new Bolt(ComponentObject.serialized_java(Utils.javaSerialize(bolt)), common));
        } catch (RuntimeException wrapperCause) {
            if (wrapperCause.getCause() != null && NotSerializableException.class.equals(wrapperCause.getCause().getClass())) {
                throw new IllegalStateException("Bolt '" + boltId + "' contains a non-serializable field of type " + wrapperCause.getCause().getMessage() + ", " + "which was instantiated prior to topology creation. " + wrapperCause.getCause().getMessage() + " " + "should be instantiated within the prepare method of '" + boltId + " at the earliest.", wrapperCause);
            }
            throw wrapperCause;
        }
    }
    for (String spoutId : spouts.keySet()) {
        IRichSpout spout = spouts.get(spoutId);
        ComponentCommon common = getComponentCommon(spoutId, spout);
        try {
            spoutSpecs.put(spoutId, new SpoutSpec(ComponentObject.serialized_java(Utils.javaSerialize(spout)), common));
        } catch (RuntimeException wrapperCause) {
            if (wrapperCause.getCause() != null && NotSerializableException.class.equals(wrapperCause.getCause().getClass())) {
                throw new IllegalStateException("Spout '" + spoutId + "' contains a non-serializable field of type " + wrapperCause.getCause().getMessage() + ", which was instantiated prior to topology creation. " + wrapperCause.getCause().getMessage() + " should be instantiated within the open method of '" + spoutId + " at the earliest.", wrapperCause);
            }
            throw wrapperCause;
        }
    }
    StormTopology stormTopology = new StormTopology(spoutSpecs, boltSpecs, new HashMap<>());
    stormTopology.set_worker_hooks(workerHooks);
    if (!componentToSharedMemory.isEmpty()) {
        stormTopology.set_component_to_shared_memory(componentToSharedMemory);
        stormTopology.set_shared_memory(sharedMemory);
    }
    return Utils.addVersions(stormTopology);
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Bolt(org.apache.storm.generated.Bolt) LambdaBiConsumerBolt(org.apache.storm.lambda.LambdaBiConsumerBolt) LambdaConsumerBolt(org.apache.storm.lambda.LambdaConsumerBolt) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) SpoutSpec(org.apache.storm.generated.SpoutSpec)

Example 27 with ComponentCommon

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

the class TopologyBuilder method initCommon.

private void initCommon(String id, IComponent component, Number parallelism) throws IllegalArgumentException {
    ComponentCommon common = new ComponentCommon();
    common.set_inputs(new HashMap<GlobalStreamId, Grouping>());
    if (parallelism != null) {
        int dop = parallelism.intValue();
        if (dop < 1) {
            throw new IllegalArgumentException("Parallelism must be positive.");
        }
        common.set_parallelism_hint(dop);
    }
    Map<String, Object> conf = component.getComponentConfiguration();
    if (conf != null) {
        common.set_json_conf(JSONValue.toJSONString(conf));
    }
    commons.put(id, common);
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) CustomStreamGrouping(org.apache.storm.grouping.CustomStreamGrouping) Grouping(org.apache.storm.generated.Grouping) PartialKeyGrouping(org.apache.storm.grouping.PartialKeyGrouping) ComponentObject(org.apache.storm.generated.ComponentObject)

Aggregations

ComponentCommon (org.apache.storm.generated.ComponentCommon)27 HashMap (java.util.HashMap)18 Bolt (org.apache.storm.generated.Bolt)10 Map (java.util.Map)8 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)8 Grouping (org.apache.storm.generated.Grouping)8 StormTopology (org.apache.storm.generated.StormTopology)8 StreamInfo (org.apache.storm.generated.StreamInfo)8 ArrayList (java.util.ArrayList)6 SpoutSpec (org.apache.storm.generated.SpoutSpec)6 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 StateSpoutSpec (org.apache.storm.generated.StateSpoutSpec)4 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 WrappedInvalidTopologyException (org.apache.storm.utils.WrappedInvalidTopologyException)4 ParseException (org.json.simple.parser.ParseException)3 File (java.io.File)2