From 3afda22b2145331a3d01e836b792f7f0c46b0376 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Wed, 30 Aug 2023 13:05:25 -0700 Subject: [PATCH 1/9] add feature flag and checks to transport actions Signed-off-by: HenryL27 --- .../conversation/ConversationalIndexConstants.java | 2 ++ .../CreateConversationTransportAction.java | 12 +++++++++++- .../CreateInteractionTransportAction.java | 12 +++++++++++- .../DeleteConversationTransportAction.java | 12 +++++++++++- .../GetConversationsTransportAction.java | 12 +++++++++++- .../conversation/GetInteractionsTransportAction.java | 12 +++++++++++- .../ml/memory/index/ConversationMetaIndex.java | 1 + .../CreateConversationTransportActionTests.java | 6 ++++-- .../CreateInteractionTransportActionTests.java | 6 ++++-- .../DeleteConversationTransportActionTests.java | 6 ++++-- .../GetConversationsTransportActionTests.java | 6 ++++-- .../GetInteractionsTransportActionTests.java | 6 ++++-- .../opensearch/ml/plugin/MachineLearningPlugin.java | 3 ++- .../opensearch/ml/settings/MLCommonsSettings.java | 4 ++++ 14 files changed, 84 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java index b40e2ae477..051992636f 100644 --- a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java +++ b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java @@ -97,4 +97,6 @@ public class ConversationalIndexConstants { + " }\n" + "}"; + /** Name of the feature flag for conversational memory */ + public final static String MEMORY_FEATURE_FLAG_NAME = "plugins.ml_commons.memory_feature_enabled"; } \ No newline at end of file diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index 4aee788879..82901ee920 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class CreateConversationTransportAction extends HandledTransportAction actionListener) { + if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + return; + } String name = request.getName(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(actionListener, () -> context.restore()); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index eb3b75de35..70e74e98d7 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class CreateInteractionTransportAction extends HandledTransportAction actionListener) { + if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + return; + } String cid = request.getConversationId(); String inp = request.getInput(); String rsp = request.getResponse(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index 94039e4202..e6af66cbbd 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class DeleteConversationTransportAction extends HandledTransportAction listener) { + if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + listener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + return; + } String conversationId = request.getId(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(listener, () -> context.restore()); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index ccb4bf97e4..543122b313 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -19,13 +19,16 @@ import java.util.List; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationMeta; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -41,6 +44,7 @@ public class GetConversationsTransportAction extends HandledTransportAction actionListener) { + if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + return; + } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index 01cc94b546..4c9715ba6c 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -19,12 +19,15 @@ import java.util.List; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; @@ -41,6 +44,7 @@ public class GetInteractionsTransportAction extends HandledTransportAction actionListener) { + if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + return; + } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java index d7a4169fe7..f74082865c 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java @@ -40,6 +40,7 @@ import org.opensearch.client.Client; import org.opensearch.client.Requests; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.commons.ConfigConstants; import org.opensearch.commons.authuser.User; diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java index 1f7a0f59a3..d3cd5d87f6 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java @@ -89,12 +89,14 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateConversationRequest("test"); - this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = spy(Settings.builder().build()); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); + when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testCreateConversation() { diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java index 499dda8354..04c2de29da 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java @@ -89,12 +89,14 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateInteractionRequest("test-cid", "input", "pt", "response", "origin", "metadata"); - this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = spy(Settings.builder().build()); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); + when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testCreateInteraction() { diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java index bf39567516..0fcb67091d 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java @@ -89,12 +89,14 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new DeleteConversationRequest("test"); - this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = spy(Settings.builder().build()); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); + when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testDeleteConversation() { diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index c648cd2581..b30529a10a 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -93,12 +93,14 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetConversationsRequest(); - this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = spy(Settings.builder().build()); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); + when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testGetConversations() { diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java index 95b087cd1d..33b4cfd70a 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java @@ -93,12 +93,14 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetInteractionsRequest("test-cid"); - this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = spy(Settings.builder().build()); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); + when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testGetInteractions_noMorePages() { diff --git a/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java b/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java index a72c5486c3..cbaedb45fd 100644 --- a/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java +++ b/plugin/src/main/java/org/opensearch/ml/plugin/MachineLearningPlugin.java @@ -644,7 +644,8 @@ public List> getSettings() { MLCommonsSettings.ML_COMMONS_ALLOW_LOCAL_FILE_UPLOAD, MLCommonsSettings.ML_COMMONS_MODEL_ACCESS_CONTROL_ENABLED, MLCommonsSettings.ML_COMMONS_CONNECTOR_ACCESS_CONTROL_ENABLED, - MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX + MLCommonsSettings.ML_COMMONS_TRUSTED_CONNECTOR_ENDPOINTS_REGEX, + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED ); return settings; } diff --git a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java index 9f1a5308a2..d573439bfa 100644 --- a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java +++ b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java @@ -9,6 +9,7 @@ import java.util.function.Function; import org.opensearch.common.settings.Setting; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import com.google.common.collect.ImmutableList; @@ -127,4 +128,7 @@ private MLCommonsSettings() {} Setting.Property.NodeScope, Setting.Property.Dynamic ); + + public static final Setting ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting + .boolSetting(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false, Setting.Property.NodeScope, Setting.Property.Dynamic); } From e32d939fdac06e793123a2b2b30659112aadd8b7 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Wed, 30 Aug 2023 13:46:32 -0700 Subject: [PATCH 2/9] add feature flag tests Signed-off-by: HenryL27 --- .../CreateConversationTransportActionTests.java | 12 ++++++++++-- .../CreateInteractionTransportActionTests.java | 12 ++++++++++-- .../DeleteConversationTransportActionTests.java | 12 ++++++++++-- .../GetConversationsTransportActionTests.java | 12 ++++++++++-- .../GetInteractionsTransportActionTests.java | 12 ++++++++++-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java index d3cd5d87f6..5c9bcbbc31 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -91,12 +92,11 @@ public void setup() throws IOException { this.request = new CreateConversationRequest("test"); this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = spy(Settings.builder().build()); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); - when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testCreateConversation() { @@ -146,4 +146,12 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); + } + } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java index 04c2de29da..c4bb7ef3d1 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -91,12 +92,11 @@ public void setup() throws IOException { this.request = new CreateInteractionRequest("test-cid", "input", "pt", "response", "origin", "metadata"); this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = spy(Settings.builder().build()); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); - when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testCreateInteraction() { @@ -136,4 +136,12 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); + } + } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java index 0fcb67091d..da7eceb169 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -91,12 +92,11 @@ public void setup() throws IOException { this.request = new DeleteConversationRequest("test"); this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = spy(Settings.builder().build()); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); - when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testDeleteConversation() { @@ -132,4 +132,12 @@ public void testdoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); + } + } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index b30529a10a..7a920b9fc9 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -41,6 +41,7 @@ import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.common.conversation.ConversationMeta; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -95,12 +96,11 @@ public void setup() throws IOException { this.request = new GetConversationsRequest(); this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = spy(Settings.builder().build()); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); - when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testGetConversations() { @@ -186,4 +186,12 @@ public void testdoExecuteFails_thenFail() { verify(actionListener).onFailure(argCaptor.capture()); assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); + } } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java index 33b4cfd70a..b63768b216 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java +++ b/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java @@ -40,6 +40,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; @@ -95,12 +96,11 @@ public void setup() throws IOException { this.request = new GetInteractionsRequest("test-cid"); this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = spy(Settings.builder().build()); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); - when(settings.getAsBoolean(any(), any())).thenReturn(true); } public void testGetInteractions_noMorePages() { @@ -178,4 +178,12 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); + } + } From 540b0b4a10ba78c9fc46708cc06abdd964adc935 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Wed, 30 Aug 2023 13:59:10 -0700 Subject: [PATCH 3/9] fix typos for real with find-and-replace Signed-off-by: HenryL27 --- .../CreateConversationTransportAction.java | 10 ++++++++-- .../conversation/CreateInteractionTransportAction.java | 10 ++++++++-- .../DeleteConversationTransportAction.java | 10 ++++++++-- .../conversation/GetConversationsTransportAction.java | 10 ++++++++-- .../conversation/GetInteractionsTransportAction.java | 10 ++++++++-- .../ml/memory/index/ConversationMetaIndex.java | 1 - 6 files changed, 40 insertions(+), 11 deletions(-) diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index 82901ee920..ebed2da1ae 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -66,8 +66,14 @@ public CreateConversationTransportAction( @Override protected void doExecute(Task task, CreateConversationRequest request, ActionListener actionListener) { - if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, change the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); return; } String name = request.getName(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index 70e74e98d7..1f9fad8177 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -66,8 +66,14 @@ public CreateInteractionTransportAction( @Override protected void doExecute(Task task, CreateInteractionRequest request, ActionListener actionListener) { - if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, change the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); return; } String cid = request.getConversationId(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index e6af66cbbd..9190657b53 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -66,8 +66,14 @@ public DeleteConversationTransportAction( @Override public void doExecute(Task task, DeleteConversationRequest request, ActionListener listener) { - if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - listener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + listener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, change the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); return; } String conversationId = request.getId(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index 543122b313..8d83cf4c03 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -69,8 +69,14 @@ public GetConversationsTransportAction( @Override public void doExecute(Task task, GetConversationsRequest request, ActionListener actionListener) { - if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, change the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); return; } int maxResults = request.getMaxResults(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index 4c9715ba6c..5f0e59dda5 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -69,8 +69,14 @@ public GetInteractionsTransportAction( @Override public void doExecute(Task task, GetInteractionsRequest request, ActionListener actionListener) { - if(! clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener.onFailure(new OpenSearchException("The experimental Conversation Memory feature is not enabled. To enable, change the setting " + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME)); + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, change the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); return; } int maxResults = request.getMaxResults(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java b/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java index f74082865c..d7a4169fe7 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java +++ b/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java @@ -40,7 +40,6 @@ import org.opensearch.client.Client; import org.opensearch.client.Requests; import org.opensearch.cluster.service.ClusterService; -import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.commons.ConfigConstants; import org.opensearch.commons.authuser.User; From 3e4a0f4c77010eea89b45dffd5bb90a51214aa0f Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Wed, 30 Aug 2023 15:49:51 -0700 Subject: [PATCH 4/9] rename conversational-memory directory to memory Signed-off-by: HenryL27 --- {conversational-memory => memory}/build.gradle | 0 .../ml/memory/ConversationalMemoryHandler.java | 0 .../conversation/CreateConversationAction.java | 0 .../CreateConversationRequest.java | 0 .../CreateConversationResponse.java | 0 .../CreateConversationTransportAction.java | 18 +----------------- .../conversation/CreateInteractionAction.java | 0 .../conversation/CreateInteractionRequest.java | 0 .../CreateInteractionResponse.java | 0 .../CreateInteractionTransportAction.java | 18 +----------------- .../conversation/DeleteConversationAction.java | 0 .../DeleteConversationRequest.java | 0 .../DeleteConversationResponse.java | 0 .../DeleteConversationTransportAction.java | 18 +----------------- .../conversation/GetConversationsAction.java | 0 .../conversation/GetConversationsRequest.java | 0 .../conversation/GetConversationsResponse.java | 0 .../GetConversationsTransportAction.java | 18 +----------------- .../conversation/GetInteractionsAction.java | 0 .../conversation/GetInteractionsRequest.java | 0 .../conversation/GetInteractionsResponse.java | 0 .../GetInteractionsTransportAction.java | 18 +----------------- .../ml/memory/index/ConversationMetaIndex.java | 0 .../ml/memory/index/InteractionsIndex.java | 0 .../OpenSearchConversationalMemoryHandler.java | 0 .../ConversationalMemoryHandlerITTests.java | 0 .../ml/memory/ConversationalTests.java | 0 .../conversation/ConversationActionTests.java | 0 .../CreateConversationRequestTests.java | 0 .../CreateConversationResponseTests.java | 0 ...CreateConversationTransportActionTests.java | 14 ++------------ .../CreateInteractionRequestTests.java | 0 .../CreateInteractionResponseTests.java | 0 .../CreateInteractionTransportActionTests.java | 14 ++------------ .../DeleteConversationRequestTests.java | 0 .../DeleteConversationResponseTests.java | 0 ...DeleteConversationTransportActionTests.java | 14 ++------------ .../GetConversationsRequestTests.java | 0 .../GetConversationsResponseTests.java | 0 .../GetConversationsTransportActionTests.java | 14 ++------------ .../GetInteractionsRequestTests.java | 0 .../GetInteractionsResponseTests.java | 0 .../GetInteractionsTransportActionTests.java | 14 ++------------ .../conversation/InteractionActionTests.java | 0 .../index/ConversationMetaIndexITTests.java | 0 .../index/ConversationMetaIndexTests.java | 0 .../memory/index/InteractionsIndexITTests.java | 0 .../memory/index/InteractionsIndexTests.java | 0 ...SearchConversationalMemoryHandlerTests.java | 0 .../ConversationalClientYamlTestSuiteIT.java | 0 ...ins.conversational_create_conversation.json | 0 ...gins.conversational_create_interaction.json | 0 ...ins.conversational_delete_conversation.json | 0 ...ugins.conversational_get_conversations.json | 0 ...lugins.conversational_get_interactions.json | 0 .../resources/rest-api-spec/test/10_basic.yml | 0 .../rest-api-spec/test/20_create_convo.yml | 0 .../rest-api-spec/test/30_list_convos.yml | 0 .../rest-api-spec/test/40_put_interaction.yml | 0 .../rest-api-spec/test/50_get_interactions.yml | 0 .../rest-api-spec/test/60_delete_convo.yml | 0 61 files changed, 15 insertions(+), 145 deletions(-) rename {conversational-memory => memory}/build.gradle (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/ConversationalMemoryHandler.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationAction.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequest.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java (80%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionAction.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequest.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponse.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java (80%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationAction.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequest.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponse.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java (79%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsAction.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequest.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponse.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java (80%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsAction.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequest.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponse.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java (80%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java (100%) rename {conversational-memory => memory}/src/main/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandler.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/ConversationalMemoryHandlerITTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/ConversationalTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/ConversationActionTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequestTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java (87%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequestTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponseTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java (87%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequestTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponseTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java (86%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequestTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java (91%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequestTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponseTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java (89%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/action/conversation/InteractionActionTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexITTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexITTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java (100%) rename {conversational-memory => memory}/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java (100%) rename {conversational-memory => memory}/src/yamlRestTest/java/org/opensearch/ml/conversational/ConversationalClientYamlTestSuiteIT.java (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_conversation.json (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_interaction.json (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_delete_conversation.json (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_conversations.json (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_interactions.json (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/20_create_convo.yml (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/30_list_convos.yml (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/40_put_interaction.yml (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/50_get_interactions.yml (100%) rename {conversational-memory => memory}/src/yamlRestTest/resources/rest-api-spec/test/60_delete_convo.yml (100%) diff --git a/conversational-memory/build.gradle b/memory/build.gradle similarity index 100% rename from conversational-memory/build.gradle rename to memory/build.gradle diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/ConversationalMemoryHandler.java b/memory/src/main/java/org/opensearch/ml/memory/ConversationalMemoryHandler.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/ConversationalMemoryHandler.java rename to memory/src/main/java/org/opensearch/ml/memory/ConversationalMemoryHandler.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationAction.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationAction.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequest.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequest.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequest.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequest.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponse.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java similarity index 80% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index ebed2da1ae..4aee788879 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -17,15 +17,12 @@ */ package org.opensearch.ml.memory.action.conversation; -import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -41,7 +38,6 @@ public class CreateConversationTransportAction extends HandledTransportAction actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener - .onFailure( - new OpenSearchException( - "The experimental Conversation Memory feature is not enabled. To enable, change the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME - ) - ); - return; - } String name = request.getName(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(actionListener, () -> context.restore()); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionAction.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionAction.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequest.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequest.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequest.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequest.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponse.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponse.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponse.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponse.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java similarity index 80% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index 1f9fad8177..eb3b75de35 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -17,15 +17,12 @@ */ package org.opensearch.ml.memory.action.conversation; -import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -41,7 +38,6 @@ public class CreateInteractionTransportAction extends HandledTransportAction actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener - .onFailure( - new OpenSearchException( - "The experimental Conversation Memory feature is not enabled. To enable, change the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME - ) - ); - return; - } String cid = request.getConversationId(); String inp = request.getInput(); String rsp = request.getResponse(); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationAction.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationAction.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequest.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequest.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequest.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequest.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponse.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponse.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponse.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponse.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java similarity index 79% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index 9190657b53..94039e4202 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -17,15 +17,12 @@ */ package org.opensearch.ml.memory.action.conversation; -import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -41,7 +38,6 @@ public class DeleteConversationTransportAction extends HandledTransportAction listener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - listener - .onFailure( - new OpenSearchException( - "The experimental Conversation Memory feature is not enabled. To enable, change the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME - ) - ); - return; - } String conversationId = request.getId(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(listener, () -> context.restore()); diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsAction.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsAction.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequest.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequest.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequest.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequest.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponse.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponse.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponse.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponse.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java similarity index 80% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index 8d83cf4c03..ccb4bf97e4 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -19,16 +19,13 @@ import java.util.List; -import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationMeta; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -44,7 +41,6 @@ public class GetConversationsTransportAction extends HandledTransportAction actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener - .onFailure( - new OpenSearchException( - "The experimental Conversation Memory feature is not enabled. To enable, change the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME - ) - ); - return; - } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsAction.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsAction.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequest.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequest.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequest.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequest.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponse.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponse.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponse.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponse.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java similarity index 80% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java rename to memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index 5f0e59dda5..01cc94b546 100644 --- a/conversational-memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -19,15 +19,12 @@ import java.util.List; -import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; -import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; @@ -44,7 +41,6 @@ public class GetInteractionsTransportAction extends HandledTransportAction actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { - actionListener - .onFailure( - new OpenSearchException( - "The experimental Conversation Memory feature is not enabled. To enable, change the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME - ) - ); - return; - } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java b/memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java rename to memory/src/main/java/org/opensearch/ml/memory/index/ConversationMetaIndex.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java b/memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java rename to memory/src/main/java/org/opensearch/ml/memory/index/InteractionsIndex.java diff --git a/conversational-memory/src/main/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandler.java b/memory/src/main/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandler.java similarity index 100% rename from conversational-memory/src/main/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandler.java rename to memory/src/main/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandler.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/ConversationalMemoryHandlerITTests.java b/memory/src/test/java/org/opensearch/ml/memory/ConversationalMemoryHandlerITTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/ConversationalMemoryHandlerITTests.java rename to memory/src/test/java/org/opensearch/ml/memory/ConversationalMemoryHandlerITTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/ConversationalTests.java b/memory/src/test/java/org/opensearch/ml/memory/ConversationalTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/ConversationalTests.java rename to memory/src/test/java/org/opensearch/ml/memory/ConversationalTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/ConversationActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/ConversationActionTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/ConversationActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/ConversationActionTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequestTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequestTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequestTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationRequestTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationResponseTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java similarity index 87% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java index 5c9bcbbc31..1f7a0f59a3 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -90,13 +89,12 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateConversationRequest("test"); - this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); - when(this.clusterService.getSettings()).thenReturn(settings); } public void testCreateConversation() { @@ -146,12 +144,4 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } - public void testFeatureDisabled_ThenFail() { - when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); - action.doExecute(null, request, actionListener); - ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); - verify(actionListener).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); - } - } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequestTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequestTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequestTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionRequestTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponseTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponseTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionResponseTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java similarity index 87% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java index c4bb7ef3d1..499dda8354 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -90,13 +89,12 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateInteractionRequest("test-cid", "input", "pt", "response", "origin", "metadata"); - this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); - when(this.clusterService.getSettings()).thenReturn(settings); } public void testCreateInteraction() { @@ -136,12 +134,4 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } - public void testFeatureDisabled_ThenFail() { - when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); - action.doExecute(null, request, actionListener); - ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); - verify(actionListener).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); - } - } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequestTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequestTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequestTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationRequestTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponseTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponseTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationResponseTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java similarity index 86% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java index da7eceb169..bf39567516 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java @@ -37,7 +37,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -90,13 +89,12 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new DeleteConversationRequest("test"); - this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); - when(this.clusterService.getSettings()).thenReturn(settings); } public void testDeleteConversation() { @@ -132,12 +130,4 @@ public void testdoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } - public void testFeatureDisabled_ThenFail() { - when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); - action.doExecute(null, request, actionListener); - ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); - verify(actionListener).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); - } - } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequestTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequestTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequestTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsRequestTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsResponseTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java similarity index 91% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index 7a920b9fc9..c648cd2581 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -41,7 +41,6 @@ import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.common.conversation.ConversationMeta; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -94,13 +93,12 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetConversationsRequest(); - this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); - when(this.clusterService.getSettings()).thenReturn(settings); } public void testGetConversations() { @@ -186,12 +184,4 @@ public void testdoExecuteFails_thenFail() { verify(actionListener).onFailure(argCaptor.capture()); assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } - - public void testFeatureDisabled_ThenFail() { - when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); - action.doExecute(null, request, actionListener); - ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); - verify(actionListener).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); - } } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequestTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequestTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequestTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsRequestTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponseTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponseTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponseTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsResponseTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java similarity index 89% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java index b63768b216..95b087cd1d 100644 --- a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java @@ -40,7 +40,6 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; -import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; @@ -94,13 +93,12 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetInteractionsRequest("test-cid"); - this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); - when(this.clusterService.getSettings()).thenReturn(settings); } public void testGetInteractions_noMorePages() { @@ -178,12 +176,4 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } - public void testFeatureDisabled_ThenFail() { - when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); - action.doExecute(null, request, actionListener); - ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); - verify(actionListener).onFailure(argCaptor.capture()); - assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled")); - } - } diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/InteractionActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/InteractionActionTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/action/conversation/InteractionActionTests.java rename to memory/src/test/java/org/opensearch/ml/memory/action/conversation/InteractionActionTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexITTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexITTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexITTests.java rename to memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexITTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexTests.java rename to memory/src/test/java/org/opensearch/ml/memory/index/ConversationMetaIndexTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexITTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexITTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexITTests.java rename to memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexITTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java rename to memory/src/test/java/org/opensearch/ml/memory/index/InteractionsIndexTests.java diff --git a/conversational-memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java b/memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java similarity index 100% rename from conversational-memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java rename to memory/src/test/java/org/opensearch/ml/memory/index/OpenSearchConversationalMemoryHandlerTests.java diff --git a/conversational-memory/src/yamlRestTest/java/org/opensearch/ml/conversational/ConversationalClientYamlTestSuiteIT.java b/memory/src/yamlRestTest/java/org/opensearch/ml/conversational/ConversationalClientYamlTestSuiteIT.java similarity index 100% rename from conversational-memory/src/yamlRestTest/java/org/opensearch/ml/conversational/ConversationalClientYamlTestSuiteIT.java rename to memory/src/yamlRestTest/java/org/opensearch/ml/conversational/ConversationalClientYamlTestSuiteIT.java diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_conversation.json b/memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_conversation.json similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_conversation.json rename to memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_conversation.json diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_interaction.json b/memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_interaction.json similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_interaction.json rename to memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_create_interaction.json diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_delete_conversation.json b/memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_delete_conversation.json similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_delete_conversation.json rename to memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_delete_conversation.json diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_conversations.json b/memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_conversations.json similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_conversations.json rename to memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_conversations.json diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_interactions.json b/memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_interactions.json similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_interactions.json rename to memory/src/yamlRestTest/resources/rest-api-spec/api/_plugins.conversational_get_interactions.json diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/10_basic.yml diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/20_create_convo.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/20_create_convo.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/20_create_convo.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/20_create_convo.yml diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/30_list_convos.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/30_list_convos.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/30_list_convos.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/30_list_convos.yml diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/40_put_interaction.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/40_put_interaction.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/40_put_interaction.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/40_put_interaction.yml diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/50_get_interactions.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/50_get_interactions.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/50_get_interactions.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/50_get_interactions.yml diff --git a/conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/60_delete_convo.yml b/memory/src/yamlRestTest/resources/rest-api-spec/test/60_delete_convo.yml similarity index 100% rename from conversational-memory/src/yamlRestTest/resources/rest-api-spec/test/60_delete_convo.yml rename to memory/src/yamlRestTest/resources/rest-api-spec/test/60_delete_convo.yml From d0b3670f60677775dd59516156830acba70618d8 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Wed, 30 Aug 2023 16:35:28 -0700 Subject: [PATCH 5/9] fix settings.gradle with new dir name Signed-off-by: HenryL27 --- settings.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index 9021ff4fd6..cb60211c8c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -13,5 +13,5 @@ include 'plugin' project(":plugin").name = rootProject.name + "-plugin" include 'ml-algorithms' project(":ml-algorithms").name = rootProject.name + "-algorithms" -include 'conversational-memory' -project(":conversational-memory").name = rootProject.name + "-memory" +include 'memory' +project(":memory").name = rootProject.name + "-memory" From 6927c4537a6f77d753018adfdd0729400d2d53cc Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Thu, 31 Aug 2023 09:30:19 -0700 Subject: [PATCH 6/9] re-add feature flag checks and tests to transport layer Signed-off-by: HenryL27 --- .../CreateConversationTransportAction.java | 18 +++++++++++++++++- .../CreateInteractionTransportAction.java | 18 +++++++++++++++++- .../DeleteConversationTransportAction.java | 18 +++++++++++++++++- .../GetConversationsTransportAction.java | 18 +++++++++++++++++- .../GetInteractionsTransportAction.java | 18 +++++++++++++++++- ...CreateConversationTransportActionTests.java | 14 ++++++++++++-- .../CreateInteractionTransportActionTests.java | 14 ++++++++++++-- ...DeleteConversationTransportActionTests.java | 14 ++++++++++++-- .../GetConversationsTransportActionTests.java | 14 ++++++++++++-- .../GetInteractionsTransportActionTests.java | 13 +++++++++++-- .../ml/settings/MLCommonsSettings.java | 2 +- 11 files changed, 145 insertions(+), 16 deletions(-) diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index 4aee788879..ce92e455da 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class CreateConversationTransportAction extends HandledTransportAction actionListener) { + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); + return; + } String name = request.getName(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(actionListener, () -> context.restore()); diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index eb3b75de35..18057cddf8 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class CreateInteractionTransportAction extends HandledTransportAction actionListener) { + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); + return; + } String cid = request.getConversationId(); String inp = request.getInput(); String rsp = request.getResponse(); diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index 94039e4202..4ba727c222 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -17,12 +17,15 @@ */ package org.opensearch.ml.memory.action.conversation; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -38,6 +41,7 @@ public class DeleteConversationTransportAction extends HandledTransportAction listener) { + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + listener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); + return; + } String conversationId = request.getId(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { ActionListener internalListener = ActionListener.runBefore(listener, () -> context.restore()); diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index ccb4bf97e4..24ea9465a6 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -19,13 +19,16 @@ import java.util.List; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationMeta; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.tasks.Task; @@ -41,6 +44,7 @@ public class GetConversationsTransportAction extends HandledTransportAction actionListener) { + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); + return; + } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index 01cc94b546..af6cf31289 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -19,12 +19,15 @@ import java.util.List; +import org.opensearch.OpenSearchException; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; import org.opensearch.client.Client; +import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.ConversationalMemoryHandler; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; @@ -41,6 +44,7 @@ public class GetInteractionsTransportAction extends HandledTransportAction actionListener) { + if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + ) + ); + return; + } int maxResults = request.getMaxResults(); int from = request.getFrom(); try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().newStoredContext(true)) { diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java index 1f7a0f59a3..42a2d15016 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -89,12 +90,13 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateConversationRequest("test"); - this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); } public void testCreateConversation() { @@ -144,4 +146,12 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled.")); + } + } diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java index 499dda8354..423bd7e91a 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -89,12 +90,13 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateInteractionRequest("test-cid", "input", "pt", "response", "origin", "metadata"); - this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); } public void testCreateInteraction() { @@ -134,4 +136,12 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled.")); + } + } diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java index bf39567516..35af9d1c1d 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java @@ -37,6 +37,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -89,12 +90,13 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new DeleteConversationRequest("test"); - this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); } public void testDeleteConversation() { @@ -130,4 +132,12 @@ public void testdoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled.")); + } + } diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index c648cd2581..bdded0e3f8 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -41,6 +41,7 @@ import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.ml.common.conversation.ConversationMeta; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.threadpool.ThreadPool; @@ -93,12 +94,13 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetConversationsRequest(); - this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); } public void testGetConversations() { @@ -184,4 +186,12 @@ public void testdoExecuteFails_thenFail() { verify(actionListener).onFailure(argCaptor.capture()); assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled.")); + } } diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java index 95b087cd1d..8ee88b2a54 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java @@ -40,6 +40,7 @@ import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.core.xcontent.NamedXContentRegistry; +import org.opensearch.ml.common.conversation.ConversationalIndexConstants; import org.opensearch.ml.common.conversation.Interaction; import org.opensearch.ml.memory.index.OpenSearchConversationalMemoryHandler; import org.opensearch.test.OpenSearchTestCase; @@ -93,12 +94,13 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetInteractionsRequest("test-cid"); - this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client)); + this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); + when(this.clusterService.getSettings()).thenReturn(settings); } public void testGetInteractions_noMorePages() { @@ -176,4 +178,11 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + public void testFeatureDisabled_ThenFail() { + when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + action.doExecute(null, request, actionListener); + ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); + verify(actionListener).onFailure(argCaptor.capture()); + assert (argCaptor.getValue().getMessage().startsWith("The experimental Conversation Memory feature is not enabled.")); + } } diff --git a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java index d573439bfa..88da0cb748 100644 --- a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java +++ b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java @@ -128,7 +128,7 @@ private MLCommonsSettings() {} Setting.Property.NodeScope, Setting.Property.Dynamic ); - + public static final Setting ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting .boolSetting(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false, Setting.Property.NodeScope, Setting.Property.Dynamic); } From 85a29017a5df7dc78e65799662b0afba48216d74 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Thu, 31 Aug 2023 17:34:33 -0700 Subject: [PATCH 7/9] fix feature flag with updateConsumer Signed-off-by: HenryL27 --- .../ConversationalIndexConstants.java | 7 +++++-- .../CreateConversationTransportAction.java | 16 ++++++++++---- .../CreateInteractionTransportAction.java | 16 ++++++++++---- .../DeleteConversationTransportAction.java | 16 ++++++++++---- .../GetConversationsTransportAction.java | 16 ++++++++++---- .../GetInteractionsTransportAction.java | 16 ++++++++++---- ...reateConversationTransportActionTests.java | 12 +++++++++-- ...CreateInteractionTransportActionTests.java | 13 ++++++++++-- ...eleteConversationTransportActionTests.java | 12 +++++++++-- .../GetConversationsTransportActionTests.java | 12 +++++++++-- .../GetInteractionsTransportActionTests.java | 12 +++++++++-- .../ml/settings/MLCommonsSettings.java | 3 +-- .../RestMemoryCreateConversationActionIT.java | 21 +++++++++++++++++++ .../RestMemoryCreateInteractionActionIT.java | 21 +++++++++++++++++++ .../RestMemoryDeleteConversationActionIT.java | 21 +++++++++++++++++++ .../RestMemoryGetConversationsActionIT.java | 21 +++++++++++++++++++ .../RestMemoryGetInteractionsActionIT.java | 21 +++++++++++++++++++ 17 files changed, 222 insertions(+), 34 deletions(-) diff --git a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java index 051992636f..c8e652265b 100644 --- a/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java +++ b/common/src/main/java/org/opensearch/ml/common/conversation/ConversationalIndexConstants.java @@ -17,6 +17,8 @@ */ package org.opensearch.ml.common.conversation; +import org.opensearch.common.settings.Setting; + /** * Class containing a bunch of constant defining how the conversational indices are formatted */ @@ -97,6 +99,7 @@ public class ConversationalIndexConstants { + " }\n" + "}"; - /** Name of the feature flag for conversational memory */ - public final static String MEMORY_FEATURE_FLAG_NAME = "plugins.ml_commons.memory_feature_enabled"; + /** Feature Flag setting for conversational memory */ + public static final Setting ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting + .boolSetting("plugins.ml_commons.memory_feature_enabled", false, Setting.Property.NodeScope, Setting.Property.Dynamic); } \ No newline at end of file diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index ce92e455da..3d3ac5f656 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -23,6 +23,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -41,7 +42,8 @@ public class CreateConversationTransportAction extends HandledTransportAction setting = (Setting) clusterService + .getClusterSettings() + .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); + this.featureIsEnabled = setting.get(clusterService.getSettings()); + clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); } @Override protected void doExecute(Task task, CreateConversationRequest request, ActionListener actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + if (!featureIsEnabled) { actionListener .onFailure( new OpenSearchException( "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() ) ); return; diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index 18057cddf8..d145d1f770 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -23,6 +23,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -41,7 +42,8 @@ public class CreateInteractionTransportAction extends HandledTransportAction setting = (Setting) clusterService + .getClusterSettings() + .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); + this.featureIsEnabled = setting.get(clusterService.getSettings()); + clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); } @Override protected void doExecute(Task task, CreateInteractionRequest request, ActionListener actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + if (!featureIsEnabled) { actionListener .onFailure( new OpenSearchException( "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() ) ); return; diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index 4ba727c222..b9fb725fe6 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -23,6 +23,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -41,7 +42,8 @@ public class DeleteConversationTransportAction extends HandledTransportAction setting = (Setting) clusterService + .getClusterSettings() + .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); + this.featureIsEnabled = setting.get(clusterService.getSettings()); + clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); } @Override public void doExecute(Task task, DeleteConversationRequest request, ActionListener listener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + if (!featureIsEnabled) { listener .onFailure( new OpenSearchException( "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() ) ); return; diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index 24ea9465a6..efd6809e5c 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -25,6 +25,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationMeta; @@ -44,7 +45,8 @@ public class GetConversationsTransportAction extends HandledTransportAction setting = (Setting) clusterService + .getClusterSettings() + .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); + this.featureIsEnabled = setting.get(clusterService.getSettings()); + clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); } @Override public void doExecute(Task task, GetConversationsRequest request, ActionListener actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + if (!featureIsEnabled) { actionListener .onFailure( new OpenSearchException( "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() ) ); return; diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index af6cf31289..50946af78e 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -25,6 +25,7 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; +import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -44,7 +45,8 @@ public class GetInteractionsTransportAction extends HandledTransportAction setting = (Setting) clusterService + .getClusterSettings() + .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); + this.featureIsEnabled = setting.get(clusterService.getSettings()); + clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); } @Override public void doExecute(Task task, GetInteractionsRequest request, ActionListener actionListener) { - if (!clusterService.getSettings().getAsBoolean(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false)) { + if (!featureIsEnabled) { actionListener .onFailure( new OpenSearchException( "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " - + ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() ) ); return; diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java index 42a2d15016..313071dc45 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportActionTests.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.Set; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -33,6 +34,7 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; @@ -90,13 +92,16 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateConversationRequest("test"); - this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); + when(this.clusterService.getClusterSettings()) + .thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + + this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); } public void testCreateConversation() { @@ -148,6 +153,9 @@ public void testDoExecuteFails_thenFail() { public void testFeatureDisabled_ThenFail() { when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + this.action = spy(new CreateConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + action.doExecute(null, request, actionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argCaptor.capture()); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java index 423bd7e91a..8321a0b65e 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportActionTests.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.Set; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -33,6 +34,7 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; @@ -90,13 +92,17 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new CreateInteractionRequest("test-cid", "input", "pt", "response", "origin", "metadata"); - this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); + when(this.clusterService.getClusterSettings()) + .thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + + this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + } public void testCreateInteraction() { @@ -138,6 +144,9 @@ public void testDoExecuteFails_thenFail() { public void testFeatureDisabled_ThenFail() { when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + this.action = spy(new CreateInteractionTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + action.doExecute(null, request, actionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argCaptor.capture()); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java index 35af9d1c1d..984b9a2fbf 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportActionTests.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.Set; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -33,6 +34,7 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; @@ -90,13 +92,16 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new DeleteConversationRequest("test"); - this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); + when(this.clusterService.getClusterSettings()) + .thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + + this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); } public void testDeleteConversation() { @@ -134,6 +139,9 @@ public void testdoExecuteFails_thenFail() { public void testFeatureDisabled_ThenFail() { when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + this.action = spy(new DeleteConversationTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + action.doExecute(null, request, actionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argCaptor.capture()); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java index bdded0e3f8..41c99bdc74 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportActionTests.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.time.Instant; import java.util.List; +import java.util.Set; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -36,6 +37,7 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; @@ -94,13 +96,16 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetConversationsRequest(); - this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); + when(this.clusterService.getClusterSettings()) + .thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + + this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); } public void testGetConversations() { @@ -189,6 +194,9 @@ public void testdoExecuteFails_thenFail() { public void testFeatureDisabled_ThenFail() { when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + this.action = spy(new GetConversationsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + action.doExecute(null, request, actionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argCaptor.capture()); diff --git a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java index 8ee88b2a54..a7a245b680 100644 --- a/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java +++ b/memory/src/test/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportActionTests.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.time.Instant; import java.util.List; +import java.util.Set; import org.junit.Before; import org.mockito.ArgumentCaptor; @@ -36,6 +37,7 @@ import org.opensearch.action.support.ActionFilters; import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; @@ -94,13 +96,16 @@ public void setup() throws IOException { this.cmHandler = Mockito.mock(OpenSearchConversationalMemoryHandler.class); this.request = new GetInteractionsRequest("test-cid"); - this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); - Settings settings = Settings.builder().put(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, true).build(); + Settings settings = Settings.builder().put(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey(), true).build(); this.threadContext = new ThreadContext(settings); when(this.client.threadPool()).thenReturn(this.threadPool); when(this.threadPool.getThreadContext()).thenReturn(this.threadContext); when(this.clusterService.getSettings()).thenReturn(settings); + when(this.clusterService.getClusterSettings()) + .thenReturn(new ClusterSettings(settings, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + + this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); } public void testGetInteractions_noMorePages() { @@ -180,6 +185,9 @@ public void testDoExecuteFails_thenFail() { public void testFeatureDisabled_ThenFail() { when(this.clusterService.getSettings()).thenReturn(Settings.EMPTY); + when(this.clusterService.getClusterSettings()).thenReturn(new ClusterSettings(Settings.EMPTY, Set.of(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED))); + this.action = spy(new GetInteractionsTransportAction(transportService, actionFilters, cmHandler, client, clusterService)); + action.doExecute(null, request, actionListener); ArgumentCaptor argCaptor = ArgumentCaptor.forClass(Exception.class); verify(actionListener).onFailure(argCaptor.capture()); diff --git a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java index 88da0cb748..dc9c209535 100644 --- a/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java +++ b/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java @@ -129,6 +129,5 @@ private MLCommonsSettings() {} Setting.Property.Dynamic ); - public static final Setting ML_COMMONS_MEMORY_FEATURE_ENABLED = Setting - .boolSetting(ConversationalIndexConstants.MEMORY_FEATURE_FLAG_NAME, false, Setting.Property.NodeScope, Setting.Property.Dynamic); + public static final Setting ML_COMMONS_MEMORY_FEATURE_ENABLED = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED; } diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java index b527ef7a32..0d909805b8 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java @@ -21,13 +21,34 @@ import java.util.Map; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.message.BasicHeader; +import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.conversation.ActionConstants; +import org.opensearch.ml.settings.MLCommonsSettings; import org.opensearch.ml.utils.TestHelper; +import com.google.common.collect.ImmutableList; + public class RestMemoryCreateConversationActionIT extends MLCommonsRestTestCase { + @Before + public void setupFeatureSettings() throws IOException { + super.setupSettings(); + Response response = TestHelper + .makeRequest( + client(), + "PUT", + "_cluster/settings", + null, + "{\"persistent\":{\"" + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + "\":true}}", + ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + public void testCreateConversation() throws IOException { Response response = TestHelper.makeRequest(client(), "POST", ActionConstants.CREATE_CONVERSATION_REST_PATH, null, "", null); assert (response != null); diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java index 32f2b484dd..dbef57d81e 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java @@ -21,13 +21,34 @@ import java.util.Map; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.message.BasicHeader; +import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.conversation.ActionConstants; +import org.opensearch.ml.settings.MLCommonsSettings; import org.opensearch.ml.utils.TestHelper; +import com.google.common.collect.ImmutableList; + public class RestMemoryCreateInteractionActionIT extends MLCommonsRestTestCase { + @Before + public void setupFeatureSettings() throws IOException { + super.setupSettings(); + Response response = TestHelper + .makeRequest( + client(), + "PUT", + "_cluster/settings", + null, + "{\"persistent\":{\"" + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + "\":true}}", + ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + public void testCreateInteraction() throws IOException { Response ccresponse = TestHelper.makeRequest(client(), "POST", ActionConstants.CREATE_CONVERSATION_REST_PATH, null, "", null); assert (ccresponse != null); diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java index f33e163b67..7633d30ac9 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java @@ -22,13 +22,34 @@ import java.util.Map; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.message.BasicHeader; +import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.conversation.ActionConstants; +import org.opensearch.ml.settings.MLCommonsSettings; import org.opensearch.ml.utils.TestHelper; +import com.google.common.collect.ImmutableList; + public class RestMemoryDeleteConversationActionIT extends MLCommonsRestTestCase { + @Before + public void setupFeatureSettings() throws IOException { + super.setupSettings(); + Response response = TestHelper + .makeRequest( + client(), + "PUT", + "_cluster/settings", + null, + "{\"persistent\":{\"" + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + "\":true}}", + ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + public void testDeleteConversation_ThatExists() throws IOException { Response ccresponse = TestHelper.makeRequest(client(), "POST", ActionConstants.CREATE_CONVERSATION_REST_PATH, null, "", null); assert (ccresponse != null); diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java index 3ce0eb8ff0..5273f74472 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java @@ -22,13 +22,34 @@ import java.util.Map; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.message.BasicHeader; +import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.conversation.ActionConstants; +import org.opensearch.ml.settings.MLCommonsSettings; import org.opensearch.ml.utils.TestHelper; +import com.google.common.collect.ImmutableList; + public class RestMemoryGetConversationsActionIT extends MLCommonsRestTestCase { + @Before + public void setupFeatureSettings() throws IOException { + super.setupSettings(); + Response response = TestHelper + .makeRequest( + client(), + "PUT", + "_cluster/settings", + null, + "{\"persistent\":{\"" + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + "\":true}}", + ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + public void testNoConversations_EmptyList() throws IOException { Response response = TestHelper.makeRequest(client(), "GET", ActionConstants.GET_CONVERSATIONS_REST_PATH, null, "", null); assert (response != null); diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java index a4ee6118d3..ac269b5e7c 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java @@ -22,13 +22,34 @@ import java.util.Map; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; +import org.apache.http.message.BasicHeader; +import org.junit.Before; import org.opensearch.client.Response; import org.opensearch.core.rest.RestStatus; import org.opensearch.ml.common.conversation.ActionConstants; +import org.opensearch.ml.settings.MLCommonsSettings; import org.opensearch.ml.utils.TestHelper; +import com.google.common.collect.ImmutableList; + public class RestMemoryGetInteractionsActionIT extends MLCommonsRestTestCase { + @Before + public void setupFeatureSettings() throws IOException { + super.setupSettings(); + Response response = TestHelper + .makeRequest( + client(), + "PUT", + "_cluster/settings", + null, + "{\"persistent\":{\"" + MLCommonsSettings.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + "\":true}}", + ImmutableList.of(new BasicHeader(HttpHeaders.USER_AGENT, "")) + ); + assertEquals(200, response.getStatusLine().getStatusCode()); + } + public void testGetInteractions_NoConversation() throws IOException { Response response = TestHelper .makeRequest( From 51b1cbd3720b92c6bdf6d77fdf0ebaafe204d6ec Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Fri, 1 Sep 2023 10:56:33 -0700 Subject: [PATCH 8/9] remove redundant settings update Signed-off-by: HenryL27 --- .../opensearch/ml/rest/RestMemoryCreateConversationActionIT.java | 1 - .../opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java | 1 - .../opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java | 1 - .../opensearch/ml/rest/RestMemoryGetConversationsActionIT.java | 1 - .../opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java | 1 - 5 files changed, 5 deletions(-) diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java index 0d909805b8..26f1486f3f 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateConversationActionIT.java @@ -36,7 +36,6 @@ public class RestMemoryCreateConversationActionIT extends MLCommonsRestTestCase @Before public void setupFeatureSettings() throws IOException { - super.setupSettings(); Response response = TestHelper .makeRequest( client(), diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java index dbef57d81e..63f7093b6e 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryCreateInteractionActionIT.java @@ -36,7 +36,6 @@ public class RestMemoryCreateInteractionActionIT extends MLCommonsRestTestCase { @Before public void setupFeatureSettings() throws IOException { - super.setupSettings(); Response response = TestHelper .makeRequest( client(), diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java index 7633d30ac9..3bdb7ed213 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryDeleteConversationActionIT.java @@ -37,7 +37,6 @@ public class RestMemoryDeleteConversationActionIT extends MLCommonsRestTestCase @Before public void setupFeatureSettings() throws IOException { - super.setupSettings(); Response response = TestHelper .makeRequest( client(), diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java index 5273f74472..4c95296b08 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetConversationsActionIT.java @@ -37,7 +37,6 @@ public class RestMemoryGetConversationsActionIT extends MLCommonsRestTestCase { @Before public void setupFeatureSettings() throws IOException { - super.setupSettings(); Response response = TestHelper .makeRequest( client(), diff --git a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java index ac269b5e7c..3272d4a991 100644 --- a/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java +++ b/plugin/src/test/java/org/opensearch/ml/rest/RestMemoryGetInteractionsActionIT.java @@ -37,7 +37,6 @@ public class RestMemoryGetInteractionsActionIT extends MLCommonsRestTestCase { @Before public void setupFeatureSettings() throws IOException { - super.setupSettings(); Response response = TestHelper .makeRequest( client(), From 1e72742ab98c0103fc172ef9d32dca819f5968c9 Mon Sep 17 00:00:00 2001 From: HenryL27 Date: Fri, 1 Sep 2023 11:31:30 -0700 Subject: [PATCH 9/9] clean up feature var initialization to avoid unchecked conversion warning Signed-off-by: HenryL27 --- .../conversation/CreateConversationTransportAction.java | 9 +++------ .../conversation/CreateInteractionTransportAction.java | 9 +++------ .../conversation/DeleteConversationTransportAction.java | 9 +++------ .../conversation/GetConversationsTransportAction.java | 9 +++------ .../conversation/GetInteractionsTransportAction.java | 9 +++------ 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java index 3d3ac5f656..f6856b7c66 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateConversationTransportAction.java @@ -23,7 +23,6 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; -import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -64,12 +63,10 @@ public CreateConversationTransportAction( super(CreateConversationAction.NAME, transportService, actionFilters, CreateConversationRequest::new); this.cmHandler = cmHandler; this.client = client; - @SuppressWarnings("unchecked") - Setting setting = (Setting) clusterService + this.featureIsEnabled = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.get(clusterService.getSettings()); + clusterService .getClusterSettings() - .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); - this.featureIsEnabled = setting.get(clusterService.getSettings()); - clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); + .addSettingsUpdateConsumer(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED, it -> featureIsEnabled = it); } @Override diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java index d145d1f770..2273cc32e8 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/CreateInteractionTransportAction.java @@ -23,7 +23,6 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; -import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -64,12 +63,10 @@ public CreateInteractionTransportAction( super(CreateInteractionAction.NAME, transportService, actionFilters, CreateInteractionRequest::new); this.client = client; this.cmHandler = cmHandler; - @SuppressWarnings("unchecked") - Setting setting = (Setting) clusterService + this.featureIsEnabled = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.get(clusterService.getSettings()); + clusterService .getClusterSettings() - .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); - this.featureIsEnabled = setting.get(clusterService.getSettings()); - clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); + .addSettingsUpdateConsumer(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED, it -> featureIsEnabled = it); } @Override diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java index b9fb725fe6..3b9a23a49b 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/DeleteConversationTransportAction.java @@ -23,7 +23,6 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; -import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -64,12 +63,10 @@ public DeleteConversationTransportAction( super(DeleteConversationAction.NAME, transportService, actionFilters, DeleteConversationRequest::new); this.client = client; this.cmHandler = cmHandler; - @SuppressWarnings("unchecked") - Setting setting = (Setting) clusterService + this.featureIsEnabled = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.get(clusterService.getSettings()); + clusterService .getClusterSettings() - .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); - this.featureIsEnabled = setting.get(clusterService.getSettings()); - clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); + .addSettingsUpdateConsumer(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED, it -> featureIsEnabled = it); } @Override diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java index efd6809e5c..f515f0f50b 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetConversationsTransportAction.java @@ -25,7 +25,6 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; -import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationMeta; @@ -67,12 +66,10 @@ public GetConversationsTransportAction( super(GetConversationsAction.NAME, transportService, actionFilters, GetConversationsRequest::new); this.client = client; this.cmHandler = cmHandler; - @SuppressWarnings("unchecked") - Setting setting = (Setting) clusterService + this.featureIsEnabled = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.get(clusterService.getSettings()); + clusterService .getClusterSettings() - .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); - this.featureIsEnabled = setting.get(clusterService.getSettings()); - clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); + .addSettingsUpdateConsumer(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED, it -> featureIsEnabled = it); } @Override diff --git a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java index 50946af78e..ee857a4174 100644 --- a/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java +++ b/memory/src/main/java/org/opensearch/ml/memory/action/conversation/GetInteractionsTransportAction.java @@ -25,7 +25,6 @@ import org.opensearch.client.Client; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; -import org.opensearch.common.settings.Setting; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.core.action.ActionListener; import org.opensearch.ml.common.conversation.ConversationalIndexConstants; @@ -67,12 +66,10 @@ public GetInteractionsTransportAction( super(GetInteractionsAction.NAME, transportService, actionFilters, GetInteractionsRequest::new); this.client = client; this.cmHandler = cmHandler; - @SuppressWarnings("unchecked") - Setting setting = (Setting) clusterService + this.featureIsEnabled = ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.get(clusterService.getSettings()); + clusterService .getClusterSettings() - .get(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey()); - this.featureIsEnabled = setting.get(clusterService.getSettings()); - clusterService.getClusterSettings().addSettingsUpdateConsumer(setting, it -> featureIsEnabled = it); + .addSettingsUpdateConsumer(ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED, it -> featureIsEnabled = it); } @Override