Search in sources :

Example 1 with Scheme

use of org.apache.storm.spout.Scheme in project storm by apache.

the class KafkaDataSourcesProvider method constructTrident.

@Override
public ISqlTridentDataSource constructTrident(URI uri, String inputFormatClass, String outputFormatClass, Properties properties, List<FieldInfo> fields) {
    int port = uri.getPort() != -1 ? uri.getPort() : DEFAULT_ZK_PORT;
    ZkHosts zk = new ZkHosts(uri.getHost() + ":" + port, uri.getPath());
    Map<String, String> values = parseURIParams(uri.getQuery());
    String topic = values.get("topic");
    Preconditions.checkNotNull(topic, "No topic of the spout is specified");
    TridentKafkaConfig conf = new TridentKafkaConfig(zk, topic);
    List<String> fieldNames = new ArrayList<>();
    int primaryIndex = -1;
    for (int i = 0; i < fields.size(); ++i) {
        FieldInfo f = fields.get(i);
        fieldNames.add(f.name());
        if (f.isPrimary()) {
            primaryIndex = i;
        }
    }
    Preconditions.checkState(primaryIndex != -1, "Kafka stream table must have a primary key");
    Scheme scheme = SerdeUtils.getScheme(inputFormatClass, properties, fieldNames);
    conf.scheme = new SchemeAsMultiScheme(scheme);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, properties, fieldNames);
    return new KafkaTridentDataSource(conf, topic, primaryIndex, properties, serializer);
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) SchemeAsMultiScheme(org.apache.storm.spout.SchemeAsMultiScheme) Scheme(org.apache.storm.spout.Scheme) ZkHosts(org.apache.storm.kafka.ZkHosts) ArrayList(java.util.ArrayList) TridentKafkaConfig(org.apache.storm.kafka.trident.TridentKafkaConfig) SchemeAsMultiScheme(org.apache.storm.spout.SchemeAsMultiScheme) FieldInfo(org.apache.storm.sql.runtime.FieldInfo)

Example 2 with Scheme

use of org.apache.storm.spout.Scheme in project kafka-spout by HolmesNL.

the class KafkaSpoutBufferBehaviourTest method setup.

@Before
public void setup() {
    final Scheme scheme = spy(new RawScheme());
    // main test subject
    _subject = new KafkaSpout(scheme);
    // assign the topic to be used for stream retrieval
    _subject._topic = "test-topic";
    // use a buffer size higher than the expected amount of messages available
    _subject._bufSize = 4;
    // assign the default FailHandler
    _subject._failHandler = ConfigUtils.DEFAULT_FAIL_HANDLER;
    // mocked consumer to avoid actually contacting zookeeper
    _consumer = mock(ConsumerConnector.class);
    // ... but make sure it will return a valid (empty) stream
    when(_consumer.createMessageStreams(any(Map.class))).thenReturn(EMPTY_STREAM);
    // assign the consumer to the test subject
    _subject._consumer = _consumer;
    // provide a mocked collector to be able to check for emitted values
    _subject._collector = mock(SpoutOutputCollector.class);
}
Also used : RawScheme(org.apache.storm.spout.RawScheme) Scheme(org.apache.storm.spout.Scheme) RawScheme(org.apache.storm.spout.RawScheme) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) ConsumerConnector(kafka.javaapi.consumer.ConsumerConnector) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap) Before(org.junit.Before)

Example 3 with Scheme

use of org.apache.storm.spout.Scheme in project storm by apache.

the class SocketDataSourcesProvider method constructTrident.

@Override
public ISqlTridentDataSource constructTrident(URI uri, String inputFormatClass, String outputFormatClass, Properties properties, List<FieldInfo> fields) {
    String host = uri.getHost();
    int port = uri.getPort();
    if (port == -1) {
        throw new RuntimeException("Port information is not available. URI: " + uri);
    }
    List<String> fieldNames = FieldInfoUtils.getFieldNames(fields);
    Scheme scheme = SerdeUtils.getScheme(inputFormatClass, properties, fieldNames);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, properties, fieldNames);
    return new SocketTridentDataSource(scheme, serializer, host, port);
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) Scheme(org.apache.storm.spout.Scheme)

Example 4 with Scheme

use of org.apache.storm.spout.Scheme in project storm by apache.

the class KafkaDataSourcesProvider method constructStreams.

@Override
public ISqlStreamsDataSource constructStreams(URI uri, String inputFormatClass, String outputFormatClass, Properties properties, List<FieldInfo> fields) {
    List<String> fieldNames = new ArrayList<>();
    int primaryIndex = -1;
    for (int i = 0; i < fields.size(); ++i) {
        FieldInfo f = fields.get(i);
        fieldNames.add(f.name());
        if (f.isPrimary()) {
            primaryIndex = i;
        }
    }
    Preconditions.checkState(primaryIndex != -1, "Kafka stream table must have a primary key");
    Scheme scheme = SerdeUtils.getScheme(inputFormatClass, properties, fieldNames);
    Map<String, String> values = parseUriParams(uri.getQuery());
    String bootstrapServers = values.get(URI_PARAMS_BOOTSTRAP_SERVERS);
    Preconditions.checkNotNull(bootstrapServers, "bootstrap-servers must be specified");
    String topic = uri.getHost();
    KafkaSpoutConfig<ByteBuffer, ByteBuffer> kafkaSpoutConfig = new KafkaSpoutConfig.Builder<ByteBuffer, ByteBuffer>(bootstrapServers, topic).setProp(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ByteBufferDeserializer.class).setProp(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ByteBufferDeserializer.class).setProp(ConsumerConfig.GROUP_ID_CONFIG, "storm-sql-kafka-" + UUID.randomUUID().toString()).setRecordTranslator(new RecordTranslatorSchemeAdapter(scheme)).build();
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, properties, fieldNames);
    return new KafkaStreamsDataSource(kafkaSpoutConfig, bootstrapServers, topic, properties, serializer);
}
Also used : Scheme(org.apache.storm.spout.Scheme) ByteBufferDeserializer(org.apache.kafka.common.serialization.ByteBufferDeserializer) ArrayList(java.util.ArrayList) KafkaSpoutConfig(org.apache.storm.kafka.spout.KafkaSpoutConfig) ByteBuffer(java.nio.ByteBuffer) IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) FieldInfo(org.apache.storm.sql.runtime.FieldInfo)

Example 5 with Scheme

use of org.apache.storm.spout.Scheme in project storm by apache.

the class SocketDataSourcesProvider method constructStreams.

@Override
public ISqlStreamsDataSource constructStreams(URI uri, String inputFormatClass, String outputFormatClass, Properties properties, List<FieldInfo> fields) {
    String host = uri.getHost();
    int port = uri.getPort();
    if (port == -1) {
        throw new RuntimeException("Port information is not available. URI: " + uri);
    }
    List<String> fieldNames = FieldInfoUtils.getFieldNames(fields);
    Scheme scheme = SerdeUtils.getScheme(inputFormatClass, properties, fieldNames);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, properties, fieldNames);
    return new SocketDataSourcesProvider.SocketStreamsDataSource(host, port, scheme, serializer);
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) Scheme(org.apache.storm.spout.Scheme)

Aggregations

Scheme (org.apache.storm.spout.Scheme)7 IOutputSerializer (org.apache.storm.sql.runtime.IOutputSerializer)4 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 FieldInfo (org.apache.storm.sql.runtime.FieldInfo)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 ConsumerConnector (kafka.javaapi.consumer.ConsumerConnector)1 ByteBufferDeserializer (org.apache.kafka.common.serialization.ByteBufferDeserializer)1 ZkHosts (org.apache.storm.kafka.ZkHosts)1 KafkaSpoutConfig (org.apache.storm.kafka.spout.KafkaSpoutConfig)1 TridentKafkaConfig (org.apache.storm.kafka.trident.TridentKafkaConfig)1 KeyValueScheme (org.apache.storm.rocketmq.spout.scheme.KeyValueScheme)1 RawScheme (org.apache.storm.spout.RawScheme)1 SchemeAsMultiScheme (org.apache.storm.spout.SchemeAsMultiScheme)1 SpoutOutputCollector (org.apache.storm.spout.SpoutOutputCollector)1 OutputFieldsDeclarer (org.apache.storm.topology.OutputFieldsDeclarer)1 Fields (org.apache.storm.tuple.Fields)1 Before (org.junit.Before)1