Search in sources :

Example 1 with IBasicBolt

use of org.apache.storm.topology.IBasicBolt in project storm by apache.

the class StreamBuilder method addSink.

private void addSink(TopologyBuilder topologyBuilder, SinkNode sinkNode) {
    IComponent bolt = sinkNode.getBolt();
    BoltDeclarer boltDeclarer;
    if (bolt instanceof IRichBolt) {
        boltDeclarer = topologyBuilder.setBolt(sinkNode.getComponentId(), (IRichBolt) bolt, sinkNode.getParallelism());
    } else if (bolt instanceof IBasicBolt) {
        boltDeclarer = topologyBuilder.setBolt(sinkNode.getComponentId(), (IBasicBolt) bolt, sinkNode.getParallelism());
    } else {
        throw new IllegalArgumentException("Expect IRichBolt or IBasicBolt in addBolt");
    }
    for (Node parent : parentNodes(sinkNode)) {
        for (String stream : sinkNode.getParentStreams(parent)) {
            declareGrouping(boltDeclarer, parent, stream, nodeGroupingInfo.get(parent, stream));
        }
    }
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IComponent(org.apache.storm.topology.IComponent) IBasicBolt(org.apache.storm.topology.IBasicBolt)

Example 2 with IBasicBolt

use of org.apache.storm.topology.IBasicBolt in project storm by apache.

the class FluxBuilder method buildStreamDefinitions.

/**
 * Builds stream definitions.
 * @param context context
 * @param builder builder
 */
private static void buildStreamDefinitions(ExecutionContext context, TopologyBuilder builder) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
    TopologyDef topologyDef = context.getTopologyDef();
    // process stream definitions
    HashMap<String, BoltDeclarer> declarers = new HashMap<String, BoltDeclarer>();
    for (StreamDef stream : topologyDef.getStreams()) {
        Object boltObj = context.getBolt(stream.getTo());
        BoltDeclarer declarer = declarers.get(stream.getTo());
        if (boltObj instanceof IRichBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IRichBolt) boltObj, topologyDef.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IBasicBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IBasicBolt) boltObj, topologyDef.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IWindowedBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IWindowedBolt) boltObj, topologyDef.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IStatefulBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IStatefulBolt) boltObj, topologyDef.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else {
            throw new IllegalArgumentException("Class does not appear to be a bolt: " + boltObj.getClass().getName());
        }
        BoltDef boltDef = topologyDef.getBoltDef(stream.getTo());
        if (boltDef.getOnHeapMemoryLoad() > -1) {
            if (boltDef.getOffHeapMemoryLoad() > -1) {
                declarer.setMemoryLoad(boltDef.getOnHeapMemoryLoad(), boltDef.getOffHeapMemoryLoad());
            } else {
                declarer.setMemoryLoad(boltDef.getOnHeapMemoryLoad());
            }
        }
        if (boltDef.getCpuLoad() > -1) {
            declarer.setCPULoad(boltDef.getCpuLoad());
        }
        if (boltDef.getNumTasks() > -1) {
            declarer.setNumTasks(boltDef.getNumTasks());
        }
        GroupingDef grouping = stream.getGrouping();
        // if the streamId is defined, use it for the grouping, otherwise assume storm's default stream
        String streamId = (grouping.getStreamId() == null ? Utils.DEFAULT_STREAM_ID : grouping.getStreamId());
        switch(grouping.getType()) {
            case SHUFFLE:
                declarer.shuffleGrouping(stream.getFrom(), streamId);
                break;
            case FIELDS:
                // TODO check for null grouping args
                declarer.fieldsGrouping(stream.getFrom(), streamId, new Fields(grouping.getArgs()));
                break;
            case ALL:
                declarer.allGrouping(stream.getFrom(), streamId);
                break;
            case DIRECT:
                declarer.directGrouping(stream.getFrom(), streamId);
                break;
            case GLOBAL:
                declarer.globalGrouping(stream.getFrom(), streamId);
                break;
            case LOCAL_OR_SHUFFLE:
                declarer.localOrShuffleGrouping(stream.getFrom(), streamId);
                break;
            case NONE:
                declarer.noneGrouping(stream.getFrom(), streamId);
                break;
            case CUSTOM:
                declarer.customGrouping(stream.getFrom(), streamId, buildCustomStreamGrouping(stream.getGrouping().getCustomClass(), context));
                break;
            default:
                throw new UnsupportedOperationException("unsupported grouping type: " + grouping);
        }
    }
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) StreamDef(org.apache.storm.flux.model.StreamDef) HashMap(java.util.HashMap) IBasicBolt(org.apache.storm.topology.IBasicBolt) TopologyDef(org.apache.storm.flux.model.TopologyDef) Fields(org.apache.storm.tuple.Fields) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IWindowedBolt(org.apache.storm.topology.IWindowedBolt) BoltDef(org.apache.storm.flux.model.BoltDef) IStatefulBolt(org.apache.storm.topology.IStatefulBolt) GroupingDef(org.apache.storm.flux.model.GroupingDef)

Example 3 with IBasicBolt

use of org.apache.storm.topology.IBasicBolt in project heron by twitter.

the class StreamBuilder method buildStreams.

protected void buildStreams(EcoExecutionContext executionContext, TopologyBuilder builder, ObjectBuilder objectBuilder) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchFieldException, InvocationTargetException {
    EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
    Map<String, ComponentStream> componentStreams = new HashMap<>();
    HashMap<String, BoltDeclarer> declarers = new HashMap<>();
    for (StreamDefinition stream : topologyDefinition.getStreams()) {
        Object boltObj = executionContext.getBolt(stream.getTo());
        BoltDeclarer declarer = declarers.get(stream.getTo());
        if (boltObj instanceof IRichBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IRichBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IBasicBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IBasicBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IWindowedBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IWindowedBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else {
            throw new IllegalArgumentException("Class does not appear to be a bolt: " + boltObj.getClass().getName());
        }
        GroupingDefinition grouping = stream.getGrouping();
        // if the streamId is defined, use it for the grouping,
        // otherwise assume default stream
        String streamId = grouping.getStreamId() == null ? Utils.DEFAULT_STREAM_ID : grouping.getStreamId();
        switch(grouping.getType()) {
            case SHUFFLE:
                declarer.shuffleGrouping(stream.getFrom(), streamId);
                break;
            case FIELDS:
                List<String> groupingArgs = grouping.getArgs();
                if (groupingArgs == null) {
                    throw new IllegalArgumentException("You must supply arguments for Fields grouping");
                }
                declarer.fieldsGrouping(stream.getFrom(), streamId, new Fields(groupingArgs));
                break;
            case ALL:
                declarer.allGrouping(stream.getFrom(), streamId);
                break;
            case GLOBAL:
                declarer.globalGrouping(stream.getFrom(), streamId);
                break;
            case NONE:
                declarer.noneGrouping(stream.getFrom(), streamId);
                break;
            case CUSTOM:
                declarer.customGrouping(stream.getFrom(), streamId, buildCustomStreamGrouping(stream.getGrouping().getCustomClass(), executionContext, objectBuilder));
                break;
            default:
                throw new UnsupportedOperationException("unsupported grouping type: " + grouping);
        }
    }
    executionContext.setStreams(componentStreams);
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) ComponentStream(org.apache.heron.eco.definition.ComponentStream) StreamDefinition(org.apache.heron.eco.definition.StreamDefinition) HashMap(java.util.HashMap) EcoTopologyDefinition(org.apache.heron.eco.definition.EcoTopologyDefinition) GroupingDefinition(org.apache.heron.eco.definition.GroupingDefinition) IBasicBolt(org.apache.storm.topology.IBasicBolt) Fields(org.apache.storm.tuple.Fields) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IWindowedBolt(org.apache.storm.topology.IWindowedBolt)

Example 4 with IBasicBolt

use of org.apache.storm.topology.IBasicBolt in project incubator-heron by apache.

the class StreamBuilder method buildStreams.

protected void buildStreams(EcoExecutionContext executionContext, TopologyBuilder builder, ObjectBuilder objectBuilder) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchFieldException, InvocationTargetException {
    EcoTopologyDefinition topologyDefinition = executionContext.getTopologyDefinition();
    Map<String, ComponentStream> componentStreams = new HashMap<>();
    HashMap<String, BoltDeclarer> declarers = new HashMap<>();
    for (StreamDefinition stream : topologyDefinition.getStreams()) {
        Object boltObj = executionContext.getBolt(stream.getTo());
        BoltDeclarer declarer = declarers.get(stream.getTo());
        if (boltObj instanceof IRichBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IRichBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IBasicBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IBasicBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else if (boltObj instanceof IWindowedBolt) {
            if (declarer == null) {
                declarer = builder.setBolt(stream.getTo(), (IWindowedBolt) boltObj, topologyDefinition.parallelismForBolt(stream.getTo()));
                declarers.put(stream.getTo(), declarer);
            }
        } else {
            throw new IllegalArgumentException("Class does not appear to be a bolt: " + boltObj.getClass().getName());
        }
        GroupingDefinition grouping = stream.getGrouping();
        // if the streamId is defined, use it for the grouping,
        // otherwise assume default stream
        String streamId = grouping.getStreamId() == null ? Utils.DEFAULT_STREAM_ID : grouping.getStreamId();
        switch(grouping.getType()) {
            case SHUFFLE:
                declarer.shuffleGrouping(stream.getFrom(), streamId);
                break;
            case FIELDS:
                List<String> groupingArgs = grouping.getArgs();
                if (groupingArgs == null) {
                    throw new IllegalArgumentException("You must supply arguments for Fields grouping");
                }
                declarer.fieldsGrouping(stream.getFrom(), streamId, new Fields(groupingArgs));
                break;
            case ALL:
                declarer.allGrouping(stream.getFrom(), streamId);
                break;
            case GLOBAL:
                declarer.globalGrouping(stream.getFrom(), streamId);
                break;
            case NONE:
                declarer.noneGrouping(stream.getFrom(), streamId);
                break;
            case CUSTOM:
                declarer.customGrouping(stream.getFrom(), streamId, buildCustomStreamGrouping(stream.getGrouping().getCustomClass(), executionContext, objectBuilder));
                break;
            default:
                throw new UnsupportedOperationException("unsupported grouping type: " + grouping);
        }
    }
    executionContext.setStreams(componentStreams);
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) ComponentStream(com.twitter.heron.eco.definition.ComponentStream) StreamDefinition(com.twitter.heron.eco.definition.StreamDefinition) HashMap(java.util.HashMap) EcoTopologyDefinition(com.twitter.heron.eco.definition.EcoTopologyDefinition) GroupingDefinition(com.twitter.heron.eco.definition.GroupingDefinition) IBasicBolt(org.apache.storm.topology.IBasicBolt) Fields(org.apache.storm.tuple.Fields) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) IWindowedBolt(org.apache.storm.topology.IWindowedBolt)

Example 5 with IBasicBolt

use of org.apache.storm.topology.IBasicBolt in project storm by apache.

the class Thrift method buildTopology.

public static StormTopology buildTopology(Map<String, SpoutDetails> spoutMap, Map<String, BoltDetails> boltMap) {
    TopologyBuilder builder = new TopologyBuilder();
    for (Entry<String, SpoutDetails> entry : spoutMap.entrySet()) {
        String spoutId = entry.getKey();
        SpoutDetails spec = entry.getValue();
        SpoutDeclarer spoutDeclarer = builder.setSpout(spoutId, spec.getSpout(), spec.getParallelism());
        spoutDeclarer.addConfigurations(spec.getConf());
    }
    for (Entry<String, BoltDetails> entry : boltMap.entrySet()) {
        String spoutId = entry.getKey();
        BoltDetails spec = entry.getValue();
        BoltDeclarer boltDeclarer = null;
        if (spec.bolt instanceof IRichBolt) {
            boltDeclarer = builder.setBolt(spoutId, (IRichBolt) spec.getBolt(), spec.getParallelism());
        } else {
            boltDeclarer = builder.setBolt(spoutId, (IBasicBolt) spec.getBolt(), spec.getParallelism());
        }
        boltDeclarer.addConfigurations(spec.getConf());
        addInputs(boltDeclarer, spec.getInputs());
    }
    return builder.createTopology();
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) BoltDeclarer(org.apache.storm.topology.BoltDeclarer) SpoutDeclarer(org.apache.storm.topology.SpoutDeclarer) IBasicBolt(org.apache.storm.topology.IBasicBolt)

Aggregations

BoltDeclarer (org.apache.storm.topology.BoltDeclarer)5 IBasicBolt (org.apache.storm.topology.IBasicBolt)5 IRichBolt (org.apache.storm.topology.IRichBolt)5 HashMap (java.util.HashMap)3 IWindowedBolt (org.apache.storm.topology.IWindowedBolt)3 Fields (org.apache.storm.tuple.Fields)3 ComponentStream (com.twitter.heron.eco.definition.ComponentStream)1 EcoTopologyDefinition (com.twitter.heron.eco.definition.EcoTopologyDefinition)1 GroupingDefinition (com.twitter.heron.eco.definition.GroupingDefinition)1 StreamDefinition (com.twitter.heron.eco.definition.StreamDefinition)1 ComponentStream (org.apache.heron.eco.definition.ComponentStream)1 EcoTopologyDefinition (org.apache.heron.eco.definition.EcoTopologyDefinition)1 GroupingDefinition (org.apache.heron.eco.definition.GroupingDefinition)1 StreamDefinition (org.apache.heron.eco.definition.StreamDefinition)1 BoltDef (org.apache.storm.flux.model.BoltDef)1 GroupingDef (org.apache.storm.flux.model.GroupingDef)1 StreamDef (org.apache.storm.flux.model.StreamDef)1 TopologyDef (org.apache.storm.flux.model.TopologyDef)1 IComponent (org.apache.storm.topology.IComponent)1 IStatefulBolt (org.apache.storm.topology.IStatefulBolt)1