From 1908a40a1cb244db84a148b9677e8e4f0ba81143 Mon Sep 17 00:00:00 2001 From: yo000 Date: Sun, 3 Mar 2024 19:28:25 +0100 Subject: [PATCH] WIP : Add data type, Add Migration to add data type to existing data adapter --- .../nosd/redis/RedisLookupPluginModule.java | 5 +++- .../dataadapters/RedisLookupDataAdapter.java | 29 ++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/in/nosd/redis/RedisLookupPluginModule.java b/src/main/java/in/nosd/redis/RedisLookupPluginModule.java index 828f7de..9d1813d 100644 --- a/src/main/java/in/nosd/redis/RedisLookupPluginModule.java +++ b/src/main/java/in/nosd/redis/RedisLookupPluginModule.java @@ -26,6 +26,7 @@ import org.graylog2.plugin.PluginModule; import in.nosd.redis.dataadapters.RedisLookupDataAdapter; import in.nosd.redis.functions.RedisLookupPluginFunction; +import in.nosd.redis.migrations.V104_MigrateRedisType; import java.util.Collections; import java.util.Set; @@ -64,8 +65,10 @@ public class RedisLookupPluginModule extends PluginModule { * * addConfigBeans(); */ + + addMigration(V104_MigrateRedisType.class); - addMessageProcessorFunction(RedisLookupPluginFunction.NAME, RedisLookupPluginFunction.class); + addMessageProcessorFunction(RedisLookupPluginFunction.NAME, RedisLookupPluginFunction.class); installLookupDataAdapter2(RedisLookupDataAdapter.NAME, RedisLookupDataAdapter.class, RedisLookupDataAdapter.Factory.class, RedisLookupDataAdapter.Config.class); diff --git a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java index 77c6037..25221b9 100755 --- a/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java +++ b/src/main/java/in/nosd/redis/dataadapters/RedisLookupDataAdapter.java @@ -60,16 +60,15 @@ import java.util.StringJoiner; public class RedisLookupDataAdapter extends LookupDataAdapter { private static final Logger LOG = LoggerFactory.getLogger(RedisLookupDataAdapter.class); - + public static final String NAME = "RedisLookup"; - + private static final Duration REFRESH_INTERVAL_DURATION = Duration.ZERO; - + private final Config config; private final RedisClient client; private RedisCommands commands; private StatefulRedisConnection connection; - private final Timer redisGetRequestTimer; private final Meter redisGetRequestErrors; private final Timer redisSetRequestTimer; @@ -124,9 +123,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { this.redisRemoveStringListRequestErrors = metricRegistry.meter(MetricRegistry.name(getClass(), "redisRemoveStringListRequestErrors")); } -/************************************************************************** -* LookupDataAdapter functions -**************************************************************************/ @Override protected void doStart() throws Exception { connection = this.client.connect(); @@ -151,6 +147,11 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { cachePurge.purgeAll(); } + private String getSingleValue(String key) { + final String value = this.commands.get(key); + return value; + } + @Override protected LookupResult doGet(Object key) { 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) { try { if (!this.commands.expire(key, ttl)) { @@ -312,10 +308,6 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { if (!keepDuplicates) { 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])); if (len > 0) { return LookupResult.withoutTTL().stringListValue(this.commands.lrange(trimmedKey, 0, -1)).build(); @@ -452,7 +444,10 @@ public class RedisLookupDataAdapter extends LookupDataAdapter { public abstract int redisDB(); @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(); @JsonProperty("redis_ttl")