Skip to content

Commit

Permalink
refactor: Introduced RedisClientArgs for all Redis client options
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Nov 1, 2024
1 parent bcc8b0d commit 77645f1
Show file tree
Hide file tree
Showing 55 changed files with 350 additions and 525 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.redis.riot.core;

import lombok.ToString;
import picocli.CommandLine.Option;

@ToString
public class ProgressArgs {

public static final long DEFAULT_UPDATE_INTERVAL = 1000;
Expand Down Expand Up @@ -29,9 +31,4 @@ public void setUpdateInterval(long interval) {
this.updateInterval = interval;
}

@Override
public String toString() {
return "ProgressArgs [style=" + style + ", updateInterval=" + updateInterval + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,15 @@ public class RiotVersion {
private static final String RIOT_VERSION = BUNDLE.getString("riot_version");
private static final String SEPARATOR = "------------------------------------------------------------%n";
private static final String RIOT_FORMAT = "riot %s%n";
private static final String RIOT_VERSION_FORMAT = "RIOT%s";

private RiotVersion() {
// noop
}

public static String getPlainVersion() {
public static String getVersion() {
return RIOT_VERSION;
}

public static String riotVersion() {
return String.format(RIOT_VERSION_FORMAT, RIOT_VERSION);
}

public static void banner(PrintStream out) {
banner(out, true);
}
Expand Down
10 changes: 3 additions & 7 deletions core/riot-core/src/main/java/com/redis/riot/core/Step.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import com.redis.spring.batch.step.FlushingChunkProvider;

import lombok.ToString;

@ToString
public class Step<I, O> {

private static final long NO_MAX_ITEM_COUNT = -1;
Expand Down Expand Up @@ -201,11 +204,4 @@ public Collection<Class<? extends Throwable>> getSkip() {
return skip;
}

@Override
public String toString() {
return "Step [name=" + name + ", taskName=" + taskName + ", live=" + live + ", flushInterval=" + flushInterval
+ ", idleTimeout=" + idleTimeout + ", skip=" + skip + ", noSkip=" + noSkip + ", retry=" + retry
+ ", noRetry=" + noRetry + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.springframework.retry.policy.MaxAttemptsRetryPolicy;

import lombok.ToString;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;

@ToString
public class StepArgs {

public static final int DEFAULT_CHUNK_SIZE = 50;
Expand Down Expand Up @@ -112,11 +114,4 @@ public void setRetryPolicy(RetryPolicy retryPolicy) {
this.retryPolicy = retryPolicy;
}

@Override
public String toString() {
return "StepArgs [sleep=" + sleep + ", threads=" + threads + ", chunkSize=" + chunkSize + ", dryRun=" + dryRun
+ ", skipPolicy=" + skipPolicy + ", skipLimit=" + skipLimit + ", retryPolicy=" + retryPolicy
+ ", retryLimit=" + retryLimit + ", progressArgs=" + progressArgs + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.redis.riot.test;

import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.StringTokenizer;
import java.util.Vector;

Expand All @@ -12,7 +12,6 @@
import com.redis.riot.core.MainCommand;
import com.redis.spring.batch.test.AbstractTargetTestBase;

import io.micrometer.core.instrument.util.IOUtils;
import picocli.CommandLine.IExecutionStrategy;
import picocli.CommandLine.ParseResult;

Expand Down Expand Up @@ -53,7 +52,7 @@ private int doExecute(TestInfo info, String filename, IExecutionStrategy... exec

private String[] args(MainCommand mainCommand, String filename) throws Exception {
try (InputStream inputStream = mainCommand.getClass().getResourceAsStream("/" + filename)) {
String command = IOUtils.toString(inputStream, Charset.defaultCharset());
String command = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
String prefix = getMainCommandPrefix();
if (command.startsWith(prefix)) {
command = command.substring(prefix.length());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

public abstract class AbstractRedisCommand extends AbstractJobCommand {

@ArgGroup(exclusive = false)
@ArgGroup(exclusive = false, heading = "Redis options%n")
private RedisArgs redisArgs = new RedisArgs();

private RedisContext redisContext;

@Override
protected void execute() throws Exception {
redisContext = redisArgs.redisContext();
redisContext = RedisContext.of(redisArgs.getUri(), redisArgs);
redisContext.afterPropertiesSet();
try {
super.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@

public abstract class AbstractRedisExportCommand extends AbstractExportCommand {

@ArgGroup(exclusive = false)
@ArgGroup(exclusive = false, heading = "Redis options%n")
private RedisArgs redisArgs = new RedisArgs();

@Option(names = "--key-regex", description = "Regex for key-field extraction, e.g. '\\w+:(?<id>.+)' extracts an id field from the key", paramLabel = "<rex>")
private Pattern keyRegex;

@Override
protected RedisContext sourceRedisContext() {
return redisArgs.redisContext();
return RedisContext.of(redisArgs.getUri(), redisArgs);
}

protected ItemProcessor<KeyValue<String>, Map<String, Object>> mapProcessor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

public abstract class AbstractRedisImportCommand extends AbstractImportCommand {

@ArgGroup(exclusive = false)
@ArgGroup(exclusive = false, heading = "Redis options%n")
private RedisArgs redisArgs = new RedisArgs();

@Override
protected RedisContext targetRedisContext() {
return redisArgs.redisContext();
return RedisContext.of(redisArgs.getUri(), redisArgs);
}

public RedisArgs getRedisArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ protected void execute() throws Exception {
@Override
protected RedisContext sourceRedisContext() {
log.info("Creating source Redis context with {} {} {}", sourceRedisUri, sourceRedisArgs, sslArgs);
RedisContext context = sourceRedisArgs.redisContext(sourceRedisUri);
RedisContext context = RedisContext.of(sourceRedisUri, sourceRedisArgs);
context.sslOptions(sslArgs.sslOptions());
return context;
}

private RedisContext targetRedisContext() {
protected RedisContext targetRedisContext() {
log.info("Creating target Redis context with {} {} {}", targetRedisUri, targetRedisArgs, sslArgs);
RedisContext context = targetRedisArgs.redisContext(targetRedisUri);
RedisContext context = RedisContext.of(targetRedisUri, targetRedisArgs);
context.sslOptions(sslArgs.sslOptions());
return context;
}
Expand Down
7 changes: 2 additions & 5 deletions plugins/riot/src/main/java/com/redis/riot/AwsArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.awspring.cloud.s3.InMemoryBufferingS3OutputStreamProvider;
import io.awspring.cloud.s3.PropertiesS3ObjectContentTypeResolver;
import io.awspring.cloud.s3.S3Resource;
import lombok.ToString;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
Expand All @@ -18,6 +19,7 @@
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3ClientBuilder;

@ToString
public class AwsArgs {

@ArgGroup(exclusive = false)
Expand Down Expand Up @@ -78,9 +80,4 @@ public void setEndpoint(URI endpoint) {
this.endpoint = endpoint;
}

@Override
public String toString() {
return "AwsArgs [credentialsArgs=" + credentialsArgs + ", region=" + region + ", endpoint=" + endpoint + "]";
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.redis.riot;

import com.redis.riot.core.RiotUtils;

import lombok.ToString;
import picocli.CommandLine.Option;

@ToString
public class AwsCredentialsArgs {

@Option(names = "--s3-access", required = true, description = "AWS access key.", paramLabel = "<key>")
Expand All @@ -28,9 +28,4 @@ public void setSecretKey(String secretKey) {
this.secretKey = secretKey;
}

@Override
public String toString() {
return "AwsCredentialsArgs [accessKey=" + accessKey + ", secretKey=" + RiotUtils.mask(secretKey) + "]";
}

}
5 changes: 5 additions & 0 deletions plugins/riot/src/main/java/com/redis/riot/CompareMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.redis.riot;

public enum CompareMode {
FULL, QUICK, NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private String toString(Collection<StatusCount> counts) {
}

public static String toString(StatusCount count) {
return String.format(STATUS_FORMAT, count.getStatus().name().toLowerCase(), count.getCount());
return String.format(STATUS_FORMAT, count.getStatus(), count.getCount());
}

}
36 changes: 15 additions & 21 deletions plugins/riot/src/main/java/com/redis/riot/DataSourceArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@

import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;

import com.redis.riot.core.RiotUtils;

import lombok.ToString;
import picocli.CommandLine.Option;

@ToString(exclude = "password")
public class DataSourceArgs {

@Option(names = "--driver", description = "Fully qualified name of the JDBC driver.", paramLabel = "<class>")
@Option(names = "--jdbc-driver", description = "Fully qualified name of the JDBC driver.", paramLabel = "<class>")
private String driver;

@Option(names = "--url", required = true, description = "JDBC URL to connect to the database.", paramLabel = "<string>")
@Option(names = "--jdbc-url", required = true, description = "JDBC URL to connect to the database.", paramLabel = "<string>")
private String url;

@Option(names = "--username", description = "Login username of the database.", paramLabel = "<string>")
@Option(names = "--jdbc-username", description = "Login username of the database.", paramLabel = "<string>")
private String username;

@Option(names = "--password", arity = "0..1", interactive = true, description = "Login password of the database.", paramLabel = "<pwd>")
@Option(names = "--jdbc-password", arity = "0..1", interactive = true, description = "Login password of the database.", paramLabel = "<pwd>")
private String password;

public DataSource dataSource() {
DataSourceProperties properties = new DataSourceProperties();
properties.setUrl(url);
properties.setDriverClassName(driver);
properties.setUsername(username);
properties.setPassword(password);
return properties.initializeDataSourceBuilder().build();
}

public String getDriver() {
return driver;
}
Expand Down Expand Up @@ -54,19 +63,4 @@ public void setPassword(String password) {
this.password = password;
}

@Override
public String toString() {
return "DataSourceArgs [driver=" + driver + ", url=" + url + ", username=" + username + ", password="
+ RiotUtils.mask(password) + "]";
}

public DataSource dataSource() {
DataSourceProperties properties = new DataSourceProperties();
properties.setUrl(url);
properties.setDriverClassName(driver);
properties.setUsername(username);
properties.setPassword(password);
return properties.initializeDataSourceBuilder().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.batch.item.database.AbstractCursorItemReader;

import lombok.ToString;
import picocli.CommandLine.Option;

@ToString
public class DatabaseReaderArgs {

public static final int DEFAULT_FETCH_SIZE = AbstractCursorItemReader.VALUE_NOT_SET;
Expand Down Expand Up @@ -81,11 +83,4 @@ public void setVerifyCursorPosition(boolean verifyCursorPosition) {
this.verifyCursorPosition = verifyCursorPosition;
}

@Override
public String toString() {
return "DatabaseReaderArgs [maxItemCount=" + maxItemCount + ", fetchSize=" + fetchSize + ", maxRows=" + maxRows
+ ", queryTimeout=" + queryTimeout + ", useSharedExtendedConnection=" + useSharedExtendedConnection
+ ", verifyCursorPosition=" + verifyCursorPosition + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import com.redis.riot.core.Expression;
import com.redis.riot.core.RiotUtils;

import lombok.ToString;
import net.datafaker.Faker;
import picocli.CommandLine.Option;

@ToString
public class EvaluationContextArgs {

public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
Expand Down Expand Up @@ -80,10 +82,4 @@ public void setNumberFormat(String numberFormat) {
this.numberFormat = numberFormat;
}

@Override
public String toString() {
return "EvaluationContextArgs [varExpressions=" + varExpressions + ", dateFormat=" + dateFormat
+ ", numberFormat=" + numberFormat + ", vars=" + vars + "]";
}

}
9 changes: 2 additions & 7 deletions plugins/riot/src/main/java/com/redis/riot/FileArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import com.redis.riot.file.FilenameInputStreamResource;
import com.redis.riot.file.UncustomizedUrlResource;

import lombok.ToString;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;

@ToString
public class FileArgs {

public static final String DEFAULT_ENCODING = StandardCharsets.UTF_8.name();
Expand Down Expand Up @@ -112,11 +114,4 @@ public void setHeader(boolean header) {
this.header = header;
}

@Override
public String toString() {
return "amazonS3Args=" + amazonS3Args + ", googleStorageArgs=" + googleStorageArgs + ", delimiter=" + delimiter
+ ", encoding=" + encoding + ", gzipped=" + gzipped + ", header=" + header + ", quoteCharacter="
+ quoteCharacter;
}

}
Loading

0 comments on commit 77645f1

Please sign in to comment.