/
RedisOptions.java
191 lines (154 loc) · 5.67 KB
/
RedisOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
* Copyright (c) 2013-2022 Contributors to the Eclipse Foundation
*
* <p> See the NOTICE file distributed with this work for additional information regarding copyright
* ownership. All rights reserved. This program and the accompanying materials are made available
* under the terms of the Apache License, Version 2.0 which accompanies this distribution and is
* available at http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package org.locationtech.geowave.datastore.redis.config;
import java.util.function.Function;
import java.util.function.Supplier;
import org.locationtech.geowave.core.cli.converters.OptionalPasswordConverter;
import org.locationtech.geowave.core.cli.converters.PasswordConverter;
import org.locationtech.geowave.core.store.BaseDataStoreOptions;
import org.locationtech.geowave.core.store.DataStoreOptions;
import org.locationtech.geowave.core.store.StoreFactoryFamilySpi;
import org.locationtech.geowave.core.store.StoreFactoryOptions;
import org.locationtech.geowave.datastore.redis.RedisStoreFactoryFamily;
import org.locationtech.geowave.datastore.redis.util.RedisUtils;
import org.redisson.client.codec.Codec;
import org.redisson.codec.FstCodec;
import org.redisson.codec.LZ4Codec;
import org.redisson.codec.SerializationCodec;
import org.redisson.codec.SnappyCodec;
import com.beust.jcommander.IStringConverter;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParametersDelegate;
public class RedisOptions extends StoreFactoryOptions {
public static final String USER_CONFIG_KEY = "username";
// HP Fortify "Hardcoded Password - Password Management: Hardcoded Password"
// false positive
// This is a password label, not a password
public static final String PASSWORD_CONFIG_KEY = "password";
@Parameter(
names = {"-u", "--" + USER_CONFIG_KEY},
description = "A Redis username to be used with Redis AUTH.")
private String username;
@Parameter(
names = {"-p", "--" + PASSWORD_CONFIG_KEY},
description = "The password for the user. " + PasswordConverter.DEFAULT_PASSWORD_DESCRIPTION,
descriptionKey = "redis.pass.label",
converter = OptionalPasswordConverter.class)
private String password;
@Parameter(
names = {"--address", "-a"},
required = true,
description = "The address to connect to, such as redis://127.0.0.1:6379")
private String address;
@Parameter(
names = "--compression",
description = "Can be \"snappy\",\"lz4\", or \"none\". Defaults to snappy.",
converter = CompressionConverter.class)
private Compression compression = Compression.SNAPPY;
@Parameter(
names = "--serialization",
description = "Can be \"fst\" or \"jdk\". Defaults to fst. Note that this serialization codec is only used for the data index when secondary indexing.",
converter = SerializationConverter.class)
private Serialization serialization = Serialization.FST;
@ParametersDelegate
protected BaseDataStoreOptions baseOptions = new BaseDataStoreOptions() {
@Override
public boolean isServerSideLibraryEnabled() {
return false;
}
@Override
protected int defaultMaxRangeDecomposition() {
return RedisUtils.REDIS_DEFAULT_MAX_RANGE_DECOMPOSITION;
}
@Override
protected int defaultAggregationMaxRangeDecomposition() {
return RedisUtils.REDIS_DEFAULT_AGGREGATION_MAX_RANGE_DECOMPOSITION;
}
@Override
protected boolean defaultEnableVisibility() {
return false;
}
};
public RedisOptions() {
super();
}
public RedisOptions(final String geowaveNamespace) {
super(geowaveNamespace);
}
@Override
public StoreFactoryFamilySpi getStoreFactory() {
return new RedisStoreFactoryFamily();
}
@Override
public DataStoreOptions getStoreOptions() {
return baseOptions;
}
public void setAddress(final String address) {
this.address = address;
}
public void setCompression(final Compression compression) {
this.compression = compression;
}
public String getUsername() {
return username;
}
public void setUsername(final String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(final String password) {
this.password = password;
}
public String getAddress() {
return address;
}
public Compression getCompression() {
return compression;
}
public Serialization getSerialization() {
return serialization;
}
public void setSerialization(final Serialization serialization) {
this.serialization = serialization;
}
public static enum Compression {
SNAPPY(c -> new SnappyCodec(c)), L4Z(c -> new LZ4Codec(c)), NONE(c -> c);
private transient Function<Codec, Codec> compressionTransform;
private Compression(final Function<Codec, Codec> compressionTransform) {
this.compressionTransform = compressionTransform;
}
public Codec getCodec(final Codec innerCodec) {
return compressionTransform.apply(innerCodec);
}
};
public static enum Serialization {
FST(FstCodec::new), JDK(SerializationCodec::new);
private transient Supplier<Codec> codec;
private Serialization(final Supplier<Codec> codec) {
this.codec = codec;
}
public Codec getCodec() {
return codec.get();
}
};
public static class SerializationConverter implements IStringConverter<Serialization> {
@Override
public Serialization convert(final String value) {
return Serialization.valueOf(value.toUpperCase());
}
}
public static class CompressionConverter implements IStringConverter<Compression> {
@Override
public Compression convert(final String value) {
return Compression.valueOf(value.toUpperCase());
}
}
}