Search in sources :

Example 6 with InvalidTopologyException

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

the class TridentKafkaClientWordCountNamedTopics method run.

protected void run(String[] args) throws AlreadyAliveException, InvalidTopologyException, AuthorizationException, InterruptedException {
    if (args.length > 0 && Arrays.stream(args).anyMatch(option -> option.equals("-h"))) {
        System.out.printf("Usage: java %s [%s] [%s] [%s] [%s]\n", getClass().getName(), "broker_host:broker_port", "topic1", "topic2", "topology_name");
    } else {
        final String brokerUrl = args.length > 0 ? args[0] : KAFKA_LOCAL_BROKER;
        final String topic1 = args.length > 1 ? args[1] : TOPIC_1;
        final String topic2 = args.length > 2 ? args[2] : TOPIC_2;
        System.out.printf("Running with broker_url: [%s], topics: [%s, %s]\n", brokerUrl, topic1, topic2);
        Config tpConf = LocalSubmitter.defaultConfig(true);
        if (args.length == 4) {
            //Submit Remote
            // Producers
            StormSubmitter.submitTopology(topic1 + "-producer", tpConf, KafkaProducerTopology.newTopology(brokerUrl, topic1));
            StormSubmitter.submitTopology(topic2 + "-producer", tpConf, KafkaProducerTopology.newTopology(brokerUrl, topic2));
            // Consumer
            StormSubmitter.submitTopology("topics-consumer", tpConf, TridentKafkaConsumerTopology.newTopology(newKafkaTridentSpoutOpaque()));
            // Print results to console, which also causes the print filter in the consumer topology to print the results in the worker log
            Thread.sleep(2000);
            DrpcResultsPrinter.remoteClient().printResults(60, 1, TimeUnit.SECONDS);
        } else {
            //Submit Local
            final LocalSubmitter localSubmitter = LocalSubmitter.newInstance();
            final String topic1Tp = "topic1-producer";
            final String topic2Tp = "topic2-producer";
            final String consTpName = "topics-consumer";
            try {
                // Producers
                localSubmitter.submit(topic1Tp, tpConf, KafkaProducerTopology.newTopology(brokerUrl, topic1));
                localSubmitter.submit(topic2Tp, tpConf, KafkaProducerTopology.newTopology(brokerUrl, topic2));
                // Consumer
                try {
                    localSubmitter.submit(consTpName, tpConf, TridentKafkaConsumerTopology.newTopology(localSubmitter.getDrpc(), newKafkaTridentSpoutOpaque()));
                    // print
                    localSubmitter.printResults(15, 1, TimeUnit.SECONDS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } finally {
                // kill
                localSubmitter.kill(topic1Tp);
                localSubmitter.kill(topic2Tp);
                localSubmitter.kill(consTpName);
                // shutdown
                localSubmitter.shutdown();
            }
        }
    }
    // Kill all the non daemon threads
    System.exit(0);
}
Also used : StormSubmitter(org.apache.storm.StormSubmitter) Arrays(java.util.Arrays) KafkaTridentSpoutOpaque(org.apache.storm.kafka.spout.trident.KafkaTridentSpoutOpaque) KafkaSpoutRetryService(org.apache.storm.kafka.spout.KafkaSpoutRetryService) Fields(org.apache.storm.tuple.Fields) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) TimeInterval(org.apache.storm.kafka.spout.KafkaSpoutRetryExponentialBackoff.TimeInterval) Serializable(java.io.Serializable) TimeUnit(java.util.concurrent.TimeUnit) AuthorizationException(org.apache.storm.generated.AuthorizationException) Values(org.apache.storm.tuple.Values) List(java.util.List) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Func(org.apache.storm.kafka.spout.Func) EARLIEST(org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy.EARLIEST) Config(org.apache.storm.Config) KafkaSpoutRetryExponentialBackoff(org.apache.storm.kafka.spout.KafkaSpoutRetryExponentialBackoff) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) KafkaSpoutConfig(org.apache.storm.kafka.spout.KafkaSpoutConfig) Config(org.apache.storm.Config) KafkaSpoutConfig(org.apache.storm.kafka.spout.KafkaSpoutConfig) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) AuthorizationException(org.apache.storm.generated.AuthorizationException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException)

Example 7 with InvalidTopologyException

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

the class BlobStoreAPIWordCountTopology method buildAndLaunchWordCountTopology.

public void buildAndLaunchWordCountTopology(String[] args) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new RandomSentenceSpout(), 5);
    builder.setBolt("split", new SplitSentence(), 8).shuffleGrouping("spout");
    builder.setBolt("filter", new FilterWords(), 6).shuffleGrouping("split");
    Config conf = new Config();
    conf.setDebug(true);
    try {
        conf.setNumWorkers(3);
        StormSubmitter.submitTopologyWithProgressBar(args[0], conf, builder.createTopology());
    } catch (InvalidTopologyException | AuthorizationException | AlreadyAliveException exp) {
        throw new RuntimeException(exp);
    }
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AuthorizationException(org.apache.storm.generated.AuthorizationException) Config(org.apache.storm.Config) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException)

Example 8 with InvalidTopologyException

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

the class StormCommon method validateStructure.

public static void validateStructure(StormTopology topology) throws InvalidTopologyException {
    Map<String, Object> componentMap = allComponents(topology);
    for (Map.Entry<String, Object> entry : componentMap.entrySet()) {
        String componentId = entry.getKey();
        ComponentCommon common = getComponentCommon(entry.getValue());
        Map<GlobalStreamId, Grouping> inputs = common.get_inputs();
        for (Map.Entry<GlobalStreamId, Grouping> input : inputs.entrySet()) {
            String sourceStreamId = input.getKey().get_streamId();
            String sourceComponentId = input.getKey().get_componentId();
            if (!componentMap.keySet().contains(sourceComponentId)) {
                throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from non-existent component [" + sourceComponentId + "]");
            }
            ComponentCommon sourceComponent = getComponentCommon(componentMap.get(sourceComponentId));
            if (!sourceComponent.get_streams().containsKey(sourceStreamId)) {
                throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from non-existent stream: " + "[" + sourceStreamId + "] of component [" + sourceComponentId + "]");
            }
            Grouping grouping = input.getValue();
            if (Thrift.groupingType(grouping) == Grouping._Fields.FIELDS) {
                List<String> fields = new ArrayList<>(grouping.get_fields());
                Map<String, StreamInfo> streams = sourceComponent.get_streams();
                Set<String> sourceOutputFields = getStreamOutputFields(streams);
                fields.removeAll(sourceOutputFields);
                if (fields.size() != 0) {
                    throw new InvalidTopologyException("Component: [" + componentId + "] subscribes from stream: [" + sourceStreamId + "] of component " + "[" + sourceComponentId + "] + with non-existent fields: " + fields);
                }
            }
        }
    }
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) ArrayList(java.util.ArrayList) Grouping(org.apache.storm.generated.Grouping) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) StreamInfo(org.apache.storm.generated.StreamInfo) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 9 with InvalidTopologyException

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

the class StormCommon method validateBasic.

@SuppressWarnings("unchecked")
public static void validateBasic(StormTopology topology) throws InvalidTopologyException {
    validateIds(topology);
    for (StormTopology._Fields field : Thrift.getSpoutFields()) {
        Map<String, Object> spoutComponents = (Map<String, Object>) topology.getFieldValue(field);
        if (spoutComponents != null) {
            for (Object obj : spoutComponents.values()) {
                ComponentCommon common = getComponentCommon(obj);
                if (!isEmptyInputs(common)) {
                    throw new InvalidTopologyException("May not declare inputs for a spout");
                }
            }
        }
    }
    Map<String, Object> componentMap = allComponents(topology);
    for (Object componentObj : componentMap.values()) {
        Map conf = componentConf(componentObj);
        ComponentCommon common = getComponentCommon(componentObj);
        int parallelismHintNum = Thrift.getParallelismHint(common);
        Integer taskNum = Utils.getInt(conf.get(Config.TOPOLOGY_TASKS), 0);
        if (taskNum > 0 && parallelismHintNum <= 0) {
            throw new InvalidTopologyException("Number of executors must be greater than 0 when number of tasks is greater than 0");
        }
    }
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) StormTopology(org.apache.storm.generated.StormTopology) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 10 with InvalidTopologyException

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

the class Nimbus method validateTopologySize.

private static void validateTopologySize(Map<String, Object> topoConf, Map<String, Object> nimbusConf, StormTopology topology) throws InvalidTopologyException {
    int workerCount = Utils.getInt(topoConf.get(Config.TOPOLOGY_WORKERS), 1);
    Integer allowedWorkers = Utils.getInt(nimbusConf.get(Config.NIMBUS_SLOTS_PER_TOPOLOGY), null);
    int executorsCount = 0;
    for (Object comp : StormCommon.allComponents(topology).values()) {
        executorsCount += StormCommon.numStartExecutors(comp);
    }
    Integer allowedExecutors = Utils.getInt(nimbusConf.get(Config.NIMBUS_EXECUTORS_PER_TOPOLOGY), null);
    if (allowedExecutors != null && executorsCount > allowedExecutors) {
        throw new InvalidTopologyException("Failed to submit topology. Topology requests more than " + allowedExecutors + " executors.");
    }
    if (allowedWorkers != null && workerCount > allowedWorkers) {
        throw new InvalidTopologyException("Failed to submit topology. Topology requests more than " + allowedWorkers + " workers.");
    }
}
Also used : InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) DataPoint(org.apache.storm.metric.api.DataPoint)

Aggregations

InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)10 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 AuthorizationException (org.apache.storm.generated.AuthorizationException)4 IOException (java.io.IOException)3 TreeMap (java.util.TreeMap)3 ComponentCommon (org.apache.storm.generated.ComponentCommon)3 File (java.io.File)2 InterruptedIOException (java.io.InterruptedIOException)2 BindException (java.net.BindException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Configuration (org.apache.flink.configuration.Configuration)2 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)2 Config (org.apache.storm.Config)2 IStormClusterState (org.apache.storm.cluster.IStormClusterState)2 Credentials (org.apache.storm.generated.Credentials)2 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)2 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)2