WIP : Add data type, Add Migration to add data type to existing data adapter
This commit is contained in:
parent
2abda2fd7d
commit
1908a40a1c
@ -26,6 +26,7 @@ import org.graylog2.plugin.PluginModule;
|
|||||||
|
|
||||||
import in.nosd.redis.dataadapters.RedisLookupDataAdapter;
|
import in.nosd.redis.dataadapters.RedisLookupDataAdapter;
|
||||||
import in.nosd.redis.functions.RedisLookupPluginFunction;
|
import in.nosd.redis.functions.RedisLookupPluginFunction;
|
||||||
|
import in.nosd.redis.migrations.V104_MigrateRedisType;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -65,7 +66,9 @@ public class RedisLookupPluginModule extends PluginModule {
|
|||||||
* addConfigBeans();
|
* addConfigBeans();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addMessageProcessorFunction(RedisLookupPluginFunction.NAME, RedisLookupPluginFunction.class);
|
addMigration(V104_MigrateRedisType.class);
|
||||||
|
|
||||||
|
addMessageProcessorFunction(RedisLookupPluginFunction.NAME, RedisLookupPluginFunction.class);
|
||||||
|
|
||||||
installLookupDataAdapter2(RedisLookupDataAdapter.NAME, RedisLookupDataAdapter.class,
|
installLookupDataAdapter2(RedisLookupDataAdapter.NAME, RedisLookupDataAdapter.class,
|
||||||
RedisLookupDataAdapter.Factory.class, RedisLookupDataAdapter.Config.class);
|
RedisLookupDataAdapter.Factory.class, RedisLookupDataAdapter.Config.class);
|
||||||
|
@ -69,7 +69,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
private final RedisClient client;
|
private final RedisClient client;
|
||||||
private RedisCommands<String, String> commands;
|
private RedisCommands<String, String> commands;
|
||||||
private StatefulRedisConnection<String, String> connection;
|
private StatefulRedisConnection<String, String> connection;
|
||||||
|
|
||||||
private final Timer redisGetRequestTimer;
|
private final Timer redisGetRequestTimer;
|
||||||
private final Meter redisGetRequestErrors;
|
private final Meter redisGetRequestErrors;
|
||||||
private final Timer redisSetRequestTimer;
|
private final Timer redisSetRequestTimer;
|
||||||
@ -124,9 +123,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
this.redisRemoveStringListRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisRemoveStringListRequestErrors"));
|
this.redisRemoveStringListRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisRemoveStringListRequestErrors"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* LookupDataAdapter functions
|
|
||||||
**************************************************************************/
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws Exception {
|
protected void doStart() throws Exception {
|
||||||
connection = this.client.connect();
|
connection = this.client.connect();
|
||||||
@ -151,6 +147,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
cachePurge.purgeAll();
|
cachePurge.purgeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getSingleValue(String key) {
|
||||||
|
final String value = this.commands.get(key);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LookupResult doGet(Object key) {
|
protected LookupResult doGet(Object key) {
|
||||||
final Timer.Context time = redisGetRequestTimer.time();
|
final Timer.Context time = redisGetRequestTimer.time();
|
||||||
@ -239,11 +240,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSingleValue(String key) {
|
|
||||||
final String value = this.commands.get(key);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LookupResult setExpire(String key, Long ttl) {
|
private LookupResult setExpire(String key, Long ttl) {
|
||||||
try {
|
try {
|
||||||
if (!this.commands.expire(key, ttl)) {
|
if (!this.commands.expire(key, ttl)) {
|
||||||
@ -312,10 +308,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
if (!keepDuplicates) {
|
if (!keepDuplicates) {
|
||||||
removeStringList(trimmedKey, listValue);
|
removeStringList(trimmedKey, listValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("Redis addStringList: List is <{}> items", listValue.size());
|
|
||||||
LOG.info("Redis addStringList: List is <{}>", listValue);
|
|
||||||
|
|
||||||
final Long len = this.commands.rpush(trimmedKey, listValue.toArray(new String[0]));
|
final Long len = this.commands.rpush(trimmedKey, listValue.toArray(new String[0]));
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
return LookupResult.withoutTTL().stringListValue(this.commands.lrange(trimmedKey, 0, -1)).build();
|
return LookupResult.withoutTTL().stringListValue(this.commands.lrange(trimmedKey, 0, -1)).build();
|
||||||
@ -452,7 +444,10 @@ public class RedisLookupDataAdapter extends LookupDataAdapter {
|
|||||||
public abstract int redisDB();
|
public abstract int redisDB();
|
||||||
|
|
||||||
@JsonProperty("redis_type")
|
@JsonProperty("redis_type")
|
||||||
@NotEmpty
|
/* FIXME: This should be notEmpty, but migration crash when dbDataAdapterService.findAll() with error
|
||||||
|
* "Missing required properties: redisType"
|
||||||
|
* so dont flag NoteEmpty and put Nullable. */
|
||||||
|
@Nullable
|
||||||
public abstract String redisType();
|
public abstract String redisType();
|
||||||
|
|
||||||
@JsonProperty("redis_ttl")
|
@JsonProperty("redis_ttl")
|
||||||
|
Loading…
Reference in New Issue
Block a user