Search in sources :

Example 1 with StreamDef

use of org.apache.storm.flux.model.StreamDef 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 2 with StreamDef

use of org.apache.storm.flux.model.StreamDef in project storm by apache.

the class Flux method printTopologyInfo.

static void printTopologyInfo(ExecutionContext ctx) {
    TopologyDef t = ctx.getTopologyDef();
    if (t.isDslTopology()) {
        print("---------- TOPOLOGY DETAILS ----------");
        printf("Topology Name: %s", t.getName());
        print("--------------- SPOUTS ---------------");
        for (SpoutDef s : t.getSpouts()) {
            printf("%s [%d] (%s)", s.getId(), s.getParallelism(), s.getClassName());
        }
        print("---------------- BOLTS ---------------");
        for (BoltDef b : t.getBolts()) {
            printf("%s [%d] (%s)", b.getId(), b.getParallelism(), b.getClassName());
        }
        print("--------------- STREAMS ---------------");
        for (StreamDef sd : t.getStreams()) {
            printf("%s --%s--> %s", sd.getFrom(), sd.getGrouping().getType(), sd.getTo());
        }
        print("--------------------------------------");
    }
}
Also used : TopologyDef(org.apache.storm.flux.model.TopologyDef) StreamDef(org.apache.storm.flux.model.StreamDef) BoltDef(org.apache.storm.flux.model.BoltDef) SpoutDef(org.apache.storm.flux.model.SpoutDef)

Aggregations

BoltDef (org.apache.storm.flux.model.BoltDef)2 StreamDef (org.apache.storm.flux.model.StreamDef)2 TopologyDef (org.apache.storm.flux.model.TopologyDef)2 HashMap (java.util.HashMap)1 GroupingDef (org.apache.storm.flux.model.GroupingDef)1 SpoutDef (org.apache.storm.flux.model.SpoutDef)1 BoltDeclarer (org.apache.storm.topology.BoltDeclarer)1 IBasicBolt (org.apache.storm.topology.IBasicBolt)1 IRichBolt (org.apache.storm.topology.IRichBolt)1 IStatefulBolt (org.apache.storm.topology.IStatefulBolt)1 IWindowedBolt (org.apache.storm.topology.IWindowedBolt)1 Fields (org.apache.storm.tuple.Fields)1