Search in sources :

Example 26 with SpoutSpec

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

the class TestTopologyAnonymizerUtils method readAndAnonymizeTopology.

private StormTopology readAndAnonymizeTopology(String resource, List<String> errors) {
    StormTopology stormTopology;
    try {
        stormTopology = Utils.deserialize(getResourceAsBytes(resource), StormTopology.class);
    } catch (Exception ex) {
        String err = String.format("Cannot read topology from resource %s", resource);
        errors.add(err);
        LOG.error(err, ex);
        return null;
    }
    Map<String, String> renameMap = new HashMap<>();
    if (stormTopology.get_spouts() != null) {
        for (String name : stormTopology.get_spouts().keySet()) {
            String newName = String.format("Spout-%d", renameMap.size());
            renameMap.putIfAbsent(name, newName);
        }
    }
    int spoutCnt = renameMap.size();
    if (stormTopology.get_bolts() != null) {
        for (String name : stormTopology.get_bolts().keySet()) {
            String newName = String.format("Bolt-%d", renameMap.size() - spoutCnt);
            renameMap.putIfAbsent(name, newName);
        }
    }
    int boltCnt = renameMap.size() - spoutCnt;
    // rename components
    StormTopology retVal = stormTopology.deepCopy();
    if (spoutCnt > 0) {
        Map<String, SpoutSpec> spouts = retVal.get_spouts();
        for (String name : renameMap.keySet()) {
            if (spouts.containsKey(name)) {
                spouts.put(renameMap.get(name), spouts.remove(name));
            }
        }
        retVal.get_spouts().values().forEach(spec -> {
            for (GlobalStreamId globalId : spec.get_common().get_inputs().keySet()) {
                if (renameMap.containsKey(globalId.get_componentId())) {
                    globalId.set_componentId(renameMap.get(globalId.get_componentId()));
                }
            }
        });
    }
    if (boltCnt > 0) {
        Map<String, Bolt> bolts = retVal.get_bolts();
        for (String name : renameMap.keySet()) {
            if (bolts.containsKey(name)) {
                bolts.put(renameMap.get(name), bolts.remove(name));
            }
        }
        retVal.get_bolts().values().forEach(spec -> {
            for (GlobalStreamId globalId : spec.get_common().get_inputs().keySet()) {
                if (renameMap.containsKey(globalId.get_componentId())) {
                    globalId.set_componentId(renameMap.get(globalId.get_componentId()));
                }
            }
        });
    }
    return retVal;
}
Also used : SpoutSpec(org.apache.storm.generated.SpoutSpec) HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Bolt(org.apache.storm.generated.Bolt) IOException(java.io.IOException)

Example 27 with SpoutSpec

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

the class TestUtilsForResourceAwareScheduler method genExecsAndComps.

public static Map<ExecutorDetails, String> genExecsAndComps(StormTopology topology) {
    Map<ExecutorDetails, String> retMap = new HashMap<>();
    int startTask = 0;
    int endTask = 0;
    for (Map.Entry<String, SpoutSpec> entry : topology.get_spouts().entrySet()) {
        SpoutSpec spout = entry.getValue();
        String spoutId = entry.getKey();
        int spoutParallelism = spout.get_common().get_parallelism_hint();
        for (int i = 0; i < spoutParallelism; i++) {
            retMap.put(new ExecutorDetails(startTask, endTask), spoutId);
            startTask++;
            endTask++;
        }
    }
    for (Map.Entry<String, Bolt> entry : topology.get_bolts().entrySet()) {
        String boltId = entry.getKey();
        Bolt bolt = entry.getValue();
        int boltParallelism = bolt.get_common().get_parallelism_hint();
        for (int i = 0; i < boltParallelism; i++) {
            retMap.put(new ExecutorDetails(startTask, endTask), boltId);
            startTask++;
            endTask++;
        }
    }
    return retMap;
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) SpoutSpec(org.apache.storm.generated.SpoutSpec) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BaseRichBolt(org.apache.storm.topology.base.BaseRichBolt) Bolt(org.apache.storm.generated.Bolt) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 28 with SpoutSpec

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

the class StormCommon method addAcker.

@SuppressWarnings("unchecked")
public static void addAcker(Map<String, Object> conf, StormTopology topology) {
    Map<String, StreamInfo> outputStreams = new HashMap<String, StreamInfo>();
    outputStreams.put(Acker.ACKER_ACK_STREAM_ID, Thrift.directOutputFields(Arrays.asList("id", "time-delta-ms")));
    outputStreams.put(Acker.ACKER_FAIL_STREAM_ID, Thrift.directOutputFields(Arrays.asList("id", "time-delta-ms")));
    outputStreams.put(Acker.ACKER_RESET_TIMEOUT_STREAM_ID, Thrift.directOutputFields(Arrays.asList("id", "time-delta-ms")));
    Map<String, Object> ackerConf = new HashMap<>();
    int ackerNum = ObjectReader.getInt(conf.get(Config.TOPOLOGY_ACKER_EXECUTORS), ObjectReader.getInt(conf.get(Config.TOPOLOGY_WORKERS)));
    ackerConf.put(Config.TOPOLOGY_TASKS, ackerNum);
    ackerConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, ObjectReader.getInt(conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)));
    Map<GlobalStreamId, Grouping> inputs = ackerInputs(topology);
    Bolt acker = Thrift.prepareSerializedBoltDetails(inputs, makeAckerBolt(), outputStreams, ackerNum, ackerConf);
    for (Bolt bolt : topology.get_bolts().values()) {
        ComponentCommon common = bolt.get_common();
        common.put_to_streams(Acker.ACKER_ACK_STREAM_ID, Thrift.outputFields(Arrays.asList("id", "ack-val")));
        common.put_to_streams(Acker.ACKER_FAIL_STREAM_ID, Thrift.outputFields(Arrays.asList("id")));
        common.put_to_streams(Acker.ACKER_RESET_TIMEOUT_STREAM_ID, Thrift.outputFields(Arrays.asList("id")));
    }
    for (SpoutSpec spout : topology.get_spouts().values()) {
        ComponentCommon common = spout.get_common();
        Map<String, Object> spoutConf = componentConf(spout);
        spoutConf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, ObjectReader.getInt(conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS)));
        common.set_json_conf(JSONValue.toJSONString(spoutConf));
        common.put_to_streams(Acker.ACKER_INIT_STREAM_ID, Thrift.outputFields(Arrays.asList("id", "init-val", "spout-task")));
        common.put_to_inputs(Utils.getGlobalStreamId(Acker.ACKER_COMPONENT_ID, Acker.ACKER_ACK_STREAM_ID), Thrift.prepareDirectGrouping());
        common.put_to_inputs(Utils.getGlobalStreamId(Acker.ACKER_COMPONENT_ID, Acker.ACKER_FAIL_STREAM_ID), Thrift.prepareDirectGrouping());
        common.put_to_inputs(Utils.getGlobalStreamId(Acker.ACKER_COMPONENT_ID, Acker.ACKER_RESET_TIMEOUT_STREAM_ID), Thrift.prepareDirectGrouping());
    }
    topology.put_to_bolts(Acker.ACKER_COMPONENT_ID, acker);
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) HashMap(java.util.HashMap) Grouping(org.apache.storm.generated.Grouping) Bolt(org.apache.storm.generated.Bolt) MetricsConsumerBolt(org.apache.storm.metric.MetricsConsumerBolt) IBolt(org.apache.storm.task.IBolt) EventLoggerBolt(org.apache.storm.metric.EventLoggerBolt) SystemBolt(org.apache.storm.metric.SystemBolt) StateSpoutSpec(org.apache.storm.generated.StateSpoutSpec) SpoutSpec(org.apache.storm.generated.SpoutSpec) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) StreamInfo(org.apache.storm.generated.StreamInfo)

Example 29 with SpoutSpec

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

the class Executor method getExecutorType.

private static String getExecutorType(WorkerTopologyContext workerTopologyContext, String componentId) {
    StormTopology topology = workerTopologyContext.getRawTopology();
    Map<String, SpoutSpec> spouts = topology.get_spouts();
    Map<String, Bolt> bolts = topology.get_bolts();
    if (spouts.containsKey(componentId)) {
        return ClientStatsUtil.SPOUT;
    } else if (bolts.containsKey(componentId)) {
        return ClientStatsUtil.BOLT;
    } else {
        throw new RuntimeException("Could not find " + componentId + " in " + topology);
    }
}
Also used : SpoutSpec(org.apache.storm.generated.SpoutSpec) StormTopology(org.apache.storm.generated.StormTopology) Bolt(org.apache.storm.generated.Bolt)

Example 30 with SpoutSpec

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

the class StrictTopologyValidator method validate.

@Override
public void validate(String topologyName, Map topologyConf, StormTopology topology) throws InvalidTopologyException {
    if (topologyName.contains(".")) {
        throw new WrappedInvalidTopologyException(String.format("Topology name '%s' contains illegal character '.'", topologyName));
    }
    Map<String, SpoutSpec> spouts = topology.get_spouts();
    for (String spoutName : spouts.keySet()) {
        if (spoutName.contains(".")) {
            throw new WrappedInvalidTopologyException(String.format("Spout name '%s' contains illegal character '.'", spoutName));
        }
        SpoutSpec spoutSpec = spouts.get(spoutName);
        for (String streamName : spoutSpec.get_common().get_streams().keySet()) {
            if (streamName.contains(".")) {
                throw new WrappedInvalidTopologyException(String.format("Stream name '%s' contains illegal character '.'", streamName));
            }
        }
    }
    Map<String, Bolt> bolts = topology.get_bolts();
    for (String boltName : bolts.keySet()) {
        if (boltName.contains(".")) {
            throw new WrappedInvalidTopologyException(String.format("Bolt name '%s' contains illegal character '.'", boltName));
        }
        Bolt bolt = bolts.get(boltName);
        for (String streamName : bolt.get_common().get_streams().keySet()) {
            if (streamName.contains(".")) {
                throw new WrappedInvalidTopologyException(String.format("Stream name '%s' contains illegal character '.'", streamName));
            }
        }
    }
}
Also used : WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) SpoutSpec(org.apache.storm.generated.SpoutSpec) Bolt(org.apache.storm.generated.Bolt)

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