Search in sources :

Example 31 with SpoutSpec

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

use of org.apache.storm.generated.SpoutSpec in project incubator-atlas by apache.

the class StormAtlasHook method addTopologyInputs.

private void addTopologyInputs(Referenceable topologyReferenceable, Map<String, SpoutSpec> spouts, Map stormConf, String topologyOwner, List<Referenceable> dependentEntities) throws IllegalAccessException {
    final ArrayList<Referenceable> inputDataSets = new ArrayList<>();
    for (Map.Entry<String, SpoutSpec> entry : spouts.entrySet()) {
        Serializable instance = Utils.javaDeserialize(entry.getValue().get_spout_object().get_serialized_java(), Serializable.class);
        String simpleName = instance.getClass().getSimpleName();
        final Referenceable datasetRef = createDataSet(simpleName, topologyOwner, instance, stormConf, dependentEntities);
        if (datasetRef != null) {
            inputDataSets.add(datasetRef);
        }
    }
    topologyReferenceable.set("inputs", inputDataSets);
}
Also used : Serializable(java.io.Serializable) Referenceable(org.apache.atlas.typesystem.Referenceable) SpoutSpec(org.apache.storm.generated.SpoutSpec) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SpoutSpec (org.apache.storm.generated.SpoutSpec)32 HashMap (java.util.HashMap)25 Bolt (org.apache.storm.generated.Bolt)24 Map (java.util.Map)20 StormTopology (org.apache.storm.generated.StormTopology)13 GlobalStreamId (org.apache.storm.generated.GlobalStreamId)8 Grouping (org.apache.storm.generated.Grouping)7 StateSpoutSpec (org.apache.storm.generated.StateSpoutSpec)7 ArrayList (java.util.ArrayList)6 ComponentCommon (org.apache.storm.generated.ComponentCommon)6 StreamInfo (org.apache.storm.generated.StreamInfo)5 List (java.util.List)4 IOException (java.io.IOException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 NormalizedResourceRequest (org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest)3 BaseRichBolt (org.apache.storm.topology.base.BaseRichBolt)3 Fields (org.apache.storm.tuple.Fields)3 Serializable (java.io.Serializable)2 TreeMap (java.util.TreeMap)2 Collectors (java.util.stream.Collectors)2