Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<artifactId>nifi-record-path</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-ssl-context-service-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.apache.nifi</groupId>
Expand All @@ -96,15 +101,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-ssl-context-service-api</artifactId>
<scope>compile</scope>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.lang.Nullable;
import redis.clients.jedis.JedisPoolConfig;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -134,7 +135,16 @@ public class RedisUtils {
public static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
.name("Password")
.displayName("Password")
.description("The password used to authenticate to the Redis server. See the requirepass property in redis.conf.")
.description("The password used to authenticate to the Redis server. See the 'requirepass' property in redis.conf.")
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.sensitive(true)
.build();

public static final PropertyDescriptor SENTINEL_PASSWORD = new PropertyDescriptor.Builder()
.name("Sentinel Password")
.displayName("Sentinel Password")
.description("The password used to authenticate to the Redis Sentinel server. See the 'requirepass' and 'sentinel sentinel-pass' properties in sentinel.conf.")
.addValidator(StandardValidators.NON_BLANK_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.sensitive(true)
Expand Down Expand Up @@ -275,6 +285,7 @@ public class RedisUtils {
props.add(RedisUtils.CLUSTER_MAX_REDIRECTS);
props.add(RedisUtils.SENTINEL_MASTER);
props.add(RedisUtils.PASSWORD);
props.add(RedisUtils.SENTINEL_PASSWORD);
props.add(RedisUtils.SSL_CONTEXT_SERVICE);
props.add(RedisUtils.POOL_MAX_TOTAL);
props.add(RedisUtils.POOL_MAX_IDLE);
Expand All @@ -297,6 +308,7 @@ public static JedisConnectionFactory createConnectionFactory(final PropertyConte
final String connectionString = context.getProperty(RedisUtils.CONNECTION_STRING).evaluateAttributeExpressions().getValue();
final Integer dbIndex = context.getProperty(RedisUtils.DATABASE).evaluateAttributeExpressions().asInteger();
final String password = context.getProperty(RedisUtils.PASSWORD).evaluateAttributeExpressions().getValue();
final String sentinelPassword = context.getProperty(RedisUtils.SENTINEL_PASSWORD).evaluateAttributeExpressions().getValue();
final Integer timeout = context.getProperty(RedisUtils.COMMUNICATION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
final JedisPoolConfig poolConfig = createJedisPoolConfig(context);

Expand All @@ -323,15 +335,15 @@ public static JedisConnectionFactory createConnectionFactory(final PropertyConte
final String host = hostAndPortSplit[0].trim();
final Integer port = Integer.parseInt(hostAndPortSplit[1].trim());
final RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(host, port);
enrichRedisConfiguration(redisStandaloneConfiguration, dbIndex, password);
enrichRedisConfiguration(redisStandaloneConfiguration, dbIndex, password, sentinelPassword);

connectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration);

} else if (RedisUtils.REDIS_MODE_SENTINEL.getValue().equals(redisMode)) {
final String[] sentinels = connectionString.split("[,]");
final String sentinelMaster = context.getProperty(RedisUtils.SENTINEL_MASTER).evaluateAttributeExpressions().getValue();
final RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration(sentinelMaster, new HashSet<>(getTrimmedValues(sentinels)));
enrichRedisConfiguration(sentinelConfiguration, dbIndex, password);
enrichRedisConfiguration(sentinelConfiguration, dbIndex, password, sentinelPassword);

logger.info("Connecting to Redis in sentinel mode...");
logger.info("Redis master = " + sentinelMaster);
Expand All @@ -347,7 +359,7 @@ public static JedisConnectionFactory createConnectionFactory(final PropertyConte
final Integer maxRedirects = context.getProperty(RedisUtils.CLUSTER_MAX_REDIRECTS).asInteger();

final RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(getTrimmedValues(clusterNodes));
enrichRedisConfiguration(clusterConfiguration, dbIndex, password);
enrichRedisConfiguration(clusterConfiguration, dbIndex, password, sentinelPassword);
clusterConfiguration.setMaxRedirects(maxRedirects);

logger.info("Connecting to Redis in clustered mode...");
Expand All @@ -373,13 +385,17 @@ private static List<String> getTrimmedValues(final String[] values) {

private static void enrichRedisConfiguration(final RedisConfiguration redisConfiguration,
final Integer dbIndex,
final String password) {
@Nullable final String password,
@Nullable final String sentinelPassword) {
if (redisConfiguration instanceof RedisConfiguration.WithDatabaseIndex) {
((RedisConfiguration.WithDatabaseIndex) redisConfiguration).setDatabase(dbIndex);
}
if (redisConfiguration instanceof RedisConfiguration.WithPassword) {
((RedisConfiguration.WithPassword) redisConfiguration).setPassword(RedisPassword.of(password));
}
if (redisConfiguration instanceof RedisConfiguration.SentinelConfiguration) {
((RedisConfiguration.SentinelConfiguration) redisConfiguration).setSentinelPassword(RedisPassword.of(sentinelPassword));
}
}

private static JedisPoolConfig createJedisPoolConfig(final PropertyContext context) {
Expand Down
Loading