Skip to content

Commit

Permalink
NIFI-12149 Create nifi-redis-utils and minor improvements to util met…
Browse files Browse the repository at this point in the history
…hods

Signed-off-by: Joe Gresock <jgresock@gmail.com>
This closes #7812.
  • Loading branch information
bbende authored and gresockj committed Oct 6, 2023
1 parent 7ddcb91 commit 551625f
Show file tree
Hide file tree
Showing 9 changed files with 395 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-redis-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public RedisConnection getConnection() {
if (connectionFactory == null) {
synchronized (this) {
if (connectionFactory == null) {
connectionFactory = RedisUtils.createConnectionFactory(context, getLogger(), sslContext);
connectionFactory = RedisUtils.createConnectionFactory(context, sslContext);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void verifyEnabled() throws IOException {
// visible for testing
synchronized RedisConnection getRedis() {
if (connectionFactory == null) {
connectionFactory = RedisUtils.createConnectionFactory(context, logger, sslContext);
connectionFactory = RedisUtils.createConnectionFactory(context, sslContext);
}

return connectionFactory.getConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private JedisConnectionFactory getJedisConnectionFactory() {
final SSLContextService sslContextService = configContext.getProperty(RedisUtils.SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
providedSslContext = sslContextService.createContext();
}
JedisConnectionFactory connectionFactory = RedisUtils.createConnectionFactory(configContext, testRunner.getLogger(), providedSslContext);
JedisConnectionFactory connectionFactory = RedisUtils.createConnectionFactory(configContext, providedSslContext);
return connectionFactory;
}

Expand Down
67 changes: 67 additions & 0 deletions nifi-nar-bundles/nifi-redis-bundle/nifi-redis-utils/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-redis-bundle</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>nifi-redis-utils</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-redis-service-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-ssl-context-service-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.data.redis.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-utils</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.redis.util;

import org.apache.nifi.redis.RedisType;

import java.time.Duration;
import java.util.Objects;

public class RedisConfig {

private final RedisType redisMode;
private final String connectionString;

private String sentinelMaster;
private String sentinelPassword;
private String password;

private int dbIndex = 0;
private int timeout = 10000;
private int clusterMaxRedirects = 5;

private int poolMaxTotal = 8;
private int poolMaxIdle = 8;
private int poolMinIdle = 0;
private boolean blockWhenExhausted = true;
private Duration maxWaitTime = Duration.ofSeconds(10);
private Duration minEvictableIdleTime = Duration.ofSeconds(60);
private Duration timeBetweenEvictionRuns = Duration.ofSeconds(30);
private int numTestsPerEvictionRun = -1;
private boolean testOnCreate = true;
private boolean testOnBorrow = true;
private boolean testOnReturn = false;
private boolean testWhenIdle = true;

public RedisConfig(final RedisType redisMode, final String connectionString) {
this.redisMode = Objects.requireNonNull(redisMode);
this.connectionString = Objects.requireNonNull(connectionString);
}

public RedisType getRedisMode() {
return redisMode;
}

public String getConnectionString() {
return connectionString;
}

public String getSentinelMaster() {
return sentinelMaster;
}

public void setSentinelMaster(String sentinelMaster) {
this.sentinelMaster = sentinelMaster;
}

public String getSentinelPassword() {
return sentinelPassword;
}

public void setSentinelPassword(String sentinelPassword) {
this.sentinelPassword = sentinelPassword;
}

public int getDbIndex() {
return dbIndex;
}

public void setDbIndex(int dbIndex) {
this.dbIndex = dbIndex;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public int getTimeout() {
return timeout;
}

public void setTimeout(int timeout) {
this.timeout = timeout;
}

public int getClusterMaxRedirects() {
return clusterMaxRedirects;
}

public void setClusterMaxRedirects(int clusterMaxRedirects) {
this.clusterMaxRedirects = clusterMaxRedirects;
}

public int getPoolMaxTotal() {
return poolMaxTotal;
}

public void setPoolMaxTotal(int poolMaxTotal) {
this.poolMaxTotal = poolMaxTotal;
}

public int getPoolMaxIdle() {
return poolMaxIdle;
}

public void setPoolMaxIdle(int poolMaxIdle) {
this.poolMaxIdle = poolMaxIdle;
}

public int getPoolMinIdle() {
return poolMinIdle;
}

public void setPoolMinIdle(int poolMinIdle) {
this.poolMinIdle = poolMinIdle;
}

public boolean getBlockWhenExhausted() {
return blockWhenExhausted;
}

public void setBlockWhenExhausted(boolean blockWhenExhausted) {
this.blockWhenExhausted = blockWhenExhausted;
}

public Duration getMaxWaitTime() {
return maxWaitTime;
}

public void setMaxWaitTime(Duration maxWaitTime) {
this.maxWaitTime = maxWaitTime;
}

public Duration getMinEvictableIdleTime() {
return minEvictableIdleTime;
}

public void setMinEvictableIdleTime(Duration minEvictableIdleTime) {
this.minEvictableIdleTime = minEvictableIdleTime;
}

public Duration getTimeBetweenEvictionRuns() {
return timeBetweenEvictionRuns;
}

public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) {
this.timeBetweenEvictionRuns = timeBetweenEvictionRuns;
}

public int getNumTestsPerEvictionRun() {
return numTestsPerEvictionRun;
}

public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {
this.numTestsPerEvictionRun = numTestsPerEvictionRun;
}

public boolean getTestOnCreate() {
return testOnCreate;
}

public void setTestOnCreate(boolean testOnCreate) {
this.testOnCreate = testOnCreate;
}

public boolean getTestOnBorrow() {
return testOnBorrow;
}

public void setTestOnBorrow(boolean testOnBorrow) {
this.testOnBorrow = testOnBorrow;
}

public boolean getTestOnReturn() {
return testOnReturn;
}

public void setTestOnReturn(boolean testOnReturn) {
this.testOnReturn = testOnReturn;
}

public boolean getTestWhenIdle() {
return testWhenIdle;
}

public void setTestWhenIdle(boolean testWhenIdle) {
this.testWhenIdle = testWhenIdle;
}
}
Loading

0 comments on commit 551625f

Please sign in to comment.