Search in sources :

Example 1 with JedisClusterConfig

use of org.apache.storm.redis.common.config.JedisClusterConfig in project storm by apache.

the class RedisKeyValueStateProvider method getRedisKeyValueState.

private RedisKeyValueState getRedisKeyValueState(String namespace, Map<String, Object> topoConf, TopologyContext context, StateConfig config) throws Exception {
    JedisPoolConfig jedisPoolConfig = getJedisPoolConfig(config);
    JedisClusterConfig jedisClusterConfig = getJedisClusterConfig(config);
    if (jedisPoolConfig == null && jedisClusterConfig == null) {
        jedisPoolConfig = buildDefaultJedisPoolConfig();
    }
    if (jedisPoolConfig != null) {
        return new RedisKeyValueState(namespace, jedisPoolConfig, getKeySerializer(topoConf, context, config), getValueSerializer(topoConf, context, config));
    } else {
        return new RedisKeyValueState(namespace, jedisClusterConfig, getKeySerializer(topoConf, context, config), getValueSerializer(topoConf, context, config));
    }
}
Also used : JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig)

Example 2 with JedisClusterConfig

use of org.apache.storm.redis.common.config.JedisClusterConfig in project storm by apache.

the class WordCountTridentRedisClusterMap method buildTopology.

public static StormTopology buildTopology(String redisHostPort) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    Set<InetSocketAddress> nodes = new HashSet<InetSocketAddress>();
    for (String hostPort : redisHostPort.split(",")) {
        String[] hostPortSplit = hostPort.split(":");
        nodes.add(new InetSocketAddress(hostPortSplit[0], Integer.valueOf(hostPortSplit[1])));
    }
    JedisClusterConfig clusterConfig = new JedisClusterConfig.Builder().setNodes(nodes).build();
    RedisDataTypeDescription dataTypeDescription = new RedisDataTypeDescription(RedisDataTypeDescription.RedisDataType.HASH, "test");
    StateFactory factory = RedisClusterMapState.transactional(clusterConfig, dataTypeDescription);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    TridentState state = stream.groupBy(new Fields("word")).persistentAggregate(factory, new Fields("count"), new Sum(), new Fields("sum"));
    stream.stateQuery(state, new Fields("word"), new MapGet(), new Fields("sum")).each(new Fields("word", "sum"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisDataTypeDescription(org.apache.storm.redis.common.mapper.RedisDataTypeDescription) TridentState(org.apache.storm.trident.TridentState) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) Values(org.apache.storm.tuple.Values) Sum(org.apache.storm.trident.operation.builtin.Sum) MapGet(org.apache.storm.trident.operation.builtin.MapGet) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) StateFactory(org.apache.storm.trident.state.StateFactory) TridentTopology(org.apache.storm.trident.TridentTopology) Stream(org.apache.storm.trident.Stream) HashSet(java.util.HashSet)

Example 3 with JedisClusterConfig

use of org.apache.storm.redis.common.config.JedisClusterConfig in project storm by apache.

the class RedisDataSourcesProvider method constructTrident.

@Override
public ISqlTridentDataSource constructTrident(URI uri, String inputFormatClass, String outputFormatClass, Properties props, List<FieldInfo> fields) {
    Preconditions.checkArgument(JedisURIHelper.isValid(uri), "URI is not valid for Redis: " + uri);
    String host = uri.getHost();
    int port = uri.getPort() != -1 ? uri.getPort() : DEFAULT_REDIS_PORT;
    int dbIdx = JedisURIHelper.getDBIndex(uri);
    String password = JedisURIHelper.getPassword(uri);
    int timeout = Integer.parseInt(props.getProperty("redis.timeout", String.valueOf(DEFAULT_TIMEOUT)));
    boolean clusterMode = Boolean.valueOf(props.getProperty("use.redis.cluster", "false"));
    List<String> fieldNames = FieldInfoUtils.getFieldNames(fields);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, props, fieldNames);
    if (clusterMode) {
        JedisClusterConfig config = new JedisClusterConfig.Builder().setNodes(Collections.singleton(new InetSocketAddress(host, port))).setTimeout(timeout).build();
        return new RedisClusterTridentDataSource(config, props, fields, serializer);
    } else {
        JedisPoolConfig config = new JedisPoolConfig(host, port, timeout, password, dbIdx);
        return new RedisTridentDataSource(config, props, fields, serializer);
    }
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig)

Example 4 with JedisClusterConfig

use of org.apache.storm.redis.common.config.JedisClusterConfig in project storm by apache.

the class RedisDataSourcesProvider method constructStreams.

@Override
public ISqlStreamsDataSource constructStreams(URI uri, String inputFormatClass, String outputFormatClass, Properties props, List<FieldInfo> fields) {
    Preconditions.checkArgument(JedisURIHelper.isValid(uri), "URI is not valid for Redis: " + uri);
    String host = uri.getHost();
    int port = uri.getPort() != -1 ? uri.getPort() : DEFAULT_REDIS_PORT;
    int dbIdx = JedisURIHelper.getDBIndex(uri);
    String password = JedisURIHelper.getPassword(uri);
    int timeout = Integer.parseInt(props.getProperty(PROPERTY_REDIS_TIMEOUT, String.valueOf(DEFAULT_TIMEOUT)));
    boolean clusterMode = Boolean.valueOf(props.getProperty(PROPERTY_USE_REDIS_CLUSTER, "false"));
    List<String> fieldNames = FieldInfoUtils.getFieldNames(fields);
    IOutputSerializer serializer = SerdeUtils.getSerializer(outputFormatClass, props, fieldNames);
    if (clusterMode) {
        JedisClusterConfig config = new JedisClusterConfig.Builder().setNodes(Collections.singleton(new InetSocketAddress(host, port))).setTimeout(timeout).build();
        return new RedisClusterStreamsDataSource(config, props, fields, serializer);
    } else {
        JedisPoolConfig config = new JedisPoolConfig(host, port, timeout, password, dbIdx);
        return new RedisStreamsDataSource(config, props, fields, serializer);
    }
}
Also used : IOutputSerializer(org.apache.storm.sql.runtime.IOutputSerializer) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) JedisPoolConfig(org.apache.storm.redis.common.config.JedisPoolConfig)

Example 5 with JedisClusterConfig

use of org.apache.storm.redis.common.config.JedisClusterConfig in project storm by apache.

the class WordCountTridentRedisCluster method buildTopology.

public static StormTopology buildTopology(String redisHostPort) {
    Fields fields = new Fields("word", "count");
    FixedBatchSpout spout = new FixedBatchSpout(fields, 4, new Values("storm", 1), new Values("trident", 1), new Values("needs", 1), new Values("javadoc", 1));
    spout.setCycle(true);
    Set<InetSocketAddress> nodes = new HashSet<InetSocketAddress>();
    for (String hostPort : redisHostPort.split(",")) {
        String[] hostPortSplit = hostPort.split(":");
        nodes.add(new InetSocketAddress(hostPortSplit[0], Integer.valueOf(hostPortSplit[1])));
    }
    JedisClusterConfig clusterConfig = new JedisClusterConfig.Builder().setNodes(nodes).build();
    RedisStoreMapper storeMapper = new WordCountStoreMapper();
    RedisLookupMapper lookupMapper = new WordCountLookupMapper();
    RedisClusterState.Factory factory = new RedisClusterState.Factory(clusterConfig);
    TridentTopology topology = new TridentTopology();
    Stream stream = topology.newStream("spout1", spout);
    stream.partitionPersist(factory, fields, new RedisClusterStateUpdater(storeMapper).withExpire(86400000), new Fields());
    TridentState state = topology.newStaticState(factory);
    stream = stream.stateQuery(state, new Fields("word"), new RedisClusterStateQuerier(lookupMapper), new Fields("columnName", "columnValue"));
    stream.each(new Fields("word", "columnValue"), new PrintFunction(), new Fields());
    return topology.build();
}
Also used : RedisClusterStateUpdater(org.apache.storm.redis.trident.state.RedisClusterStateUpdater) TridentState(org.apache.storm.trident.TridentState) InetSocketAddress(java.net.InetSocketAddress) JedisClusterConfig(org.apache.storm.redis.common.config.JedisClusterConfig) RedisClusterState(org.apache.storm.redis.trident.state.RedisClusterState) Values(org.apache.storm.tuple.Values) RedisClusterStateQuerier(org.apache.storm.redis.trident.state.RedisClusterStateQuerier) FixedBatchSpout(org.apache.storm.trident.testing.FixedBatchSpout) Fields(org.apache.storm.tuple.Fields) TridentTopology(org.apache.storm.trident.TridentTopology) RedisStoreMapper(org.apache.storm.redis.common.mapper.RedisStoreMapper) Stream(org.apache.storm.trident.Stream) RedisLookupMapper(org.apache.storm.redis.common.mapper.RedisLookupMapper) HashSet(java.util.HashSet)

Aggregations

JedisClusterConfig (org.apache.storm.redis.common.config.JedisClusterConfig)5 InetSocketAddress (java.net.InetSocketAddress)4 JedisPoolConfig (org.apache.storm.redis.common.config.JedisPoolConfig)3 HashSet (java.util.HashSet)2 IOutputSerializer (org.apache.storm.sql.runtime.IOutputSerializer)2 Stream (org.apache.storm.trident.Stream)2 TridentState (org.apache.storm.trident.TridentState)2 TridentTopology (org.apache.storm.trident.TridentTopology)2 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)2 Fields (org.apache.storm.tuple.Fields)2 Values (org.apache.storm.tuple.Values)2 RedisDataTypeDescription (org.apache.storm.redis.common.mapper.RedisDataTypeDescription)1 RedisLookupMapper (org.apache.storm.redis.common.mapper.RedisLookupMapper)1 RedisStoreMapper (org.apache.storm.redis.common.mapper.RedisStoreMapper)1 RedisClusterState (org.apache.storm.redis.trident.state.RedisClusterState)1 RedisClusterStateQuerier (org.apache.storm.redis.trident.state.RedisClusterStateQuerier)1 RedisClusterStateUpdater (org.apache.storm.redis.trident.state.RedisClusterStateUpdater)1 MapGet (org.apache.storm.trident.operation.builtin.MapGet)1 Sum (org.apache.storm.trident.operation.builtin.Sum)1 StateFactory (org.apache.storm.trident.state.StateFactory)1