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..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,4 +99,7 @@ public class ConversationalIndexConstants { + " }\n" + "}"; + /** 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/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 75% 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 4aee788879..f6856b7c66 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,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; @@ -39,27 +42,45 @@ public class CreateConversationTransportAction extends HandledTransportAction featureIsEnabled = it); } @Override protected void doExecute(Task task, CreateConversationRequest request, ActionListener actionListener) { + if (!featureIsEnabled) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + ) + ); + 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 75% 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 eb3b75de35..2273cc32e8 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,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; @@ -39,27 +42,45 @@ public class CreateInteractionTransportAction extends HandledTransportAction featureIsEnabled = it); } @Override protected void doExecute(Task task, CreateInteractionRequest request, ActionListener actionListener) { + if (!featureIsEnabled) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + ) + ); + 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 74% 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 94039e4202..3b9a23a49b 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,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; @@ -39,27 +42,45 @@ public class DeleteConversationTransportAction extends HandledTransportAction featureIsEnabled = it); } @Override public void doExecute(Task task, DeleteConversationRequest request, ActionListener listener) { + if (!featureIsEnabled) { + listener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + ) + ); + 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 76% 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 ccb4bf97e4..f515f0f50b 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,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; @@ -42,27 +45,45 @@ public class GetConversationsTransportAction extends HandledTransportAction featureIsEnabled = it); } @Override public void doExecute(Task task, GetConversationsRequest request, ActionListener actionListener) { + if (!featureIsEnabled) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + ) + ); + 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 75% 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 01cc94b546..ee857a4174 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,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; @@ -42,27 +45,45 @@ public class GetInteractionsTransportAction extends HandledTransportAction featureIsEnabled = it); } @Override public void doExecute(Task task, GetInteractionsRequest request, ActionListener actionListener) { + if (!featureIsEnabled) { + actionListener + .onFailure( + new OpenSearchException( + "The experimental Conversation Memory feature is not enabled. To enable, please update the setting " + + ConversationalIndexConstants.ML_COMMONS_MEMORY_FEATURE_ENABLED.getKey() + ) + ); + 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 80% 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 1f7a0f59a3..313071dc45 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 @@ -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,10 +34,12 @@ 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; 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 +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)); - Settings settings = Settings.builder().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() { @@ -144,4 +151,15 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + 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()); + 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 79% 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 499dda8354..8321a0b65e 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 @@ -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,10 +34,12 @@ 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; 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 +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)); - Settings settings = Settings.builder().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() { @@ -134,4 +142,15 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + 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()); + 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 78% 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 bf39567516..984b9a2fbf 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 @@ -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,10 +34,12 @@ 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; 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 +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)); - Settings settings = Settings.builder().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() { @@ -130,4 +137,15 @@ public void testdoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Test doExecute Error")); } + 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()); + 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 85% 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 c648cd2581..41c99bdc74 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 @@ -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,11 +37,13 @@ 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; 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 +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)); - Settings settings = Settings.builder().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() { @@ -184,4 +191,15 @@ 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); + 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()); + 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 83% 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 95b087cd1d..a7a245b680 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 @@ -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,10 +37,12 @@ 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; 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 +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)); - Settings settings = Settings.builder().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() { @@ -176,4 +183,14 @@ public void testDoExecuteFails_thenFail() { assert (argCaptor.getValue().getMessage().equals("Failure in doExecute")); } + 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()); + 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 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..dc9c209535 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,6 @@ private MLCommonsSettings() {} 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..26f1486f3f 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,33 @@ 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 { + 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..63f7093b6e 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,33 @@ 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 { + 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..3bdb7ed213 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,33 @@ 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 { + 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..4c95296b08 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,33 @@ 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 { + 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..3272d4a991 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,33 @@ 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 { + 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( 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"