From 37207bfbcc515b9885cdbd735a34d23cf45702cd Mon Sep 17 00:00:00 2001 From: jzonthemtn Date: Thu, 15 Feb 2024 11:00:23 -0500 Subject: [PATCH] Making names consistent to ubl for now. Removing dynamic strict. --- Dockerfile | 4 ++-- README.md | 10 ++++++-- build.gradle | 6 ++--- settings.gradle | 2 +- .../{relevance => }/SettingsConstants.java | 2 +- ...in.java => UserBehaviorLoggingPlugin.java} | 24 +++++++++---------- .../UserBehaviorLoggingRestHandler.java} | 18 +++++++------- .../UserBehaviorLoggingSearchFilter.java} | 16 ++++++------- .../{relevance => }/backends/Backend.java | 7 +++--- .../backends/OpenSearchBackend.java | 10 ++++---- .../{relevance => }/events/EventManager.java | 8 +++---- .../events/queues/EventQueue.java | 2 +- .../events/queues/InternalQueue.java | 2 +- .../{relevance => }/model/QueryRequest.java | 2 +- .../{relevance => }/model/QueryResponse.java | 2 +- .../backends/events-mapping.json | 2 +- .../backends/queries-mapping.json | 2 +- ...BehaviorLoggingClientYamlTestSuiteIT.java} | 4 ++-- .../api/_plugins.search_relevance.json | 2 +- .../_plugins.search_relevance/10_basic.yml | 2 +- 20 files changed, 64 insertions(+), 63 deletions(-) rename src/main/java/org/opensearch/{relevance => }/SettingsConstants.java (91%) rename src/main/java/org/opensearch/{relevance/SearchRelevancePlugin.java => UserBehaviorLoggingPlugin.java} (83%) rename src/main/java/org/opensearch/{relevance/action/SearchRelevanceRestHandler.java => action/UserBehaviorLoggingRestHandler.java} (76%) rename src/main/java/org/opensearch/{relevance/action/SearchRelevanceSearchFilter.java => action/UserBehaviorLoggingSearchFilter.java} (87%) rename src/main/java/org/opensearch/{relevance => }/backends/Backend.java (76%) rename src/main/java/org/opensearch/{relevance => }/backends/OpenSearchBackend.java (95%) rename src/main/java/org/opensearch/{relevance => }/events/EventManager.java (88%) rename src/main/java/org/opensearch/{relevance => }/events/queues/EventQueue.java (89%) rename src/main/java/org/opensearch/{relevance => }/events/queues/InternalQueue.java (94%) rename src/main/java/org/opensearch/{relevance => }/model/QueryRequest.java (93%) rename src/main/java/org/opensearch/{relevance => }/model/QueryResponse.java (95%) rename src/main/resources/org/opensearch/{relevance => }/backends/events-mapping.json (99%) rename src/main/resources/org/opensearch/{relevance => }/backends/queries-mapping.json (75%) rename src/yamlRestTest/java/org/opensearch/rest/action/{SearchRelevanceClientYamlTestSuiteIT.java => UserBehaviorLoggingClientYamlTestSuiteIT.java} (77%) diff --git a/Dockerfile b/Dockerfile index 9c8aec4..5c40d67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM opensearchproject/opensearch:2.11.1 -COPY ./build/distributions/opensearch-search-relevance.zip /tmp/ +COPY ./build/distributions/opensearch-ubl.zip /tmp/ -RUN /usr/share/opensearch/bin/opensearch-plugin install file:/tmp/opensearch-search-relevance.zip +RUN /usr/share/opensearch/bin/opensearch-plugin install file:/tmp/opensearch-ubl.zip diff --git a/README.md b/README.md index ec82baf..57a3c6d 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ Start the containers: Initialize the `awesome` search relevance index: ``` -curl -X PUT http://localhost:9200/_plugins/search_relevance/awesome +curl -X PUT http://localhost:9200/_plugins/ubl/awesome ``` Send an event to the `awesome` store: ``` -curl -X POST http://localhost:9200/_plugins/search_relevance/awesome -H "Content-Type: application/json" -d @instant-search.json +curl -X POST http://localhost:9200/_plugins/ubl/awesome -H "Content-Type: application/json" -d @instant-search.json ``` Get events: @@ -37,3 +37,9 @@ Get events: ``` curl http://localhost:9200/.awesome_events/_search ``` + +Delete the store: + +``` +curl -X DELETE http://localhost:9200/_plugins/ubl/awesome +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 48037b6..a2700bd 100644 --- a/build.gradle +++ b/build.gradle @@ -4,9 +4,9 @@ apply plugin: 'opensearch.opensearchplugin' apply plugin: 'opensearch.yaml-rest-test' opensearchplugin { - name 'opensearch-search-relevance' - description 'OpenSearch Search Relevance Plugin' - classname 'org.opensearch.relevance.SearchRelevancePlugin' + name 'opensearch-ubl' + description 'OpenSearch User Behavior Logging Plugin' + classname 'org.opensearch.UserBehaviorLoggingPlugin' licenseFile rootProject.file('LICENSE.txt') noticeFile rootProject.file('NOTICE.txt') } diff --git a/settings.gradle b/settings.gradle index 980ec9b..6919fa6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,4 +7,4 @@ * in the user manual at https://docs.gradle.org/6.5.1/userguide/multi_project_builds.html */ -rootProject.name = 'search-relevance-plugin' +rootProject.name = 'user-behavior-logging-plugin' diff --git a/src/main/java/org/opensearch/relevance/SettingsConstants.java b/src/main/java/org/opensearch/SettingsConstants.java similarity index 91% rename from src/main/java/org/opensearch/relevance/SettingsConstants.java rename to src/main/java/org/opensearch/SettingsConstants.java index f84b130..2ddf200 100644 --- a/src/main/java/org/opensearch/relevance/SettingsConstants.java +++ b/src/main/java/org/opensearch/SettingsConstants.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance; +package org.opensearch; public class SettingsConstants { diff --git a/src/main/java/org/opensearch/relevance/SearchRelevancePlugin.java b/src/main/java/org/opensearch/UserBehaviorLoggingPlugin.java similarity index 83% rename from src/main/java/org/opensearch/relevance/SearchRelevancePlugin.java rename to src/main/java/org/opensearch/UserBehaviorLoggingPlugin.java index 5d0eb24..07d7dfd 100644 --- a/src/main/java/org/opensearch/relevance/SearchRelevancePlugin.java +++ b/src/main/java/org/opensearch/UserBehaviorLoggingPlugin.java @@ -6,11 +6,15 @@ * compatible open source license. */ -package org.opensearch.relevance; +package org.opensearch; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.action.UserBehaviorLoggingRestHandler; +import org.opensearch.action.UserBehaviorLoggingSearchFilter; import org.opensearch.action.support.ActionFilter; +import org.opensearch.backends.Backend; +import org.opensearch.backends.OpenSearchBackend; import org.opensearch.client.Client; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.node.DiscoveryNodes; @@ -20,13 +24,9 @@ import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.env.Environment; import org.opensearch.env.NodeEnvironment; +import org.opensearch.events.EventManager; import org.opensearch.plugins.ActionPlugin; import org.opensearch.plugins.Plugin; -import org.opensearch.relevance.action.SearchRelevanceRestHandler; -import org.opensearch.relevance.action.SearchRelevanceSearchFilter; -import org.opensearch.relevance.backends.Backend; -import org.opensearch.relevance.backends.OpenSearchBackend; -import org.opensearch.relevance.events.EventManager; import org.opensearch.repositories.RepositoriesService; import org.opensearch.rest.RestController; import org.opensearch.rest.RestHandler; @@ -43,12 +43,12 @@ import static java.util.Collections.singletonList; -public class SearchRelevancePlugin extends Plugin implements ActionPlugin { +public class UserBehaviorLoggingPlugin extends Plugin implements ActionPlugin { - private static final Logger LOGGER = LogManager.getLogger(SearchRelevancePlugin.class); + private static final Logger LOGGER = LogManager.getLogger(UserBehaviorLoggingPlugin.class); private Backend backend; - private ActionFilter searchRelevanceFilter; + private ActionFilter userBehaviorLoggingFilter; @Override public List getRestHandlers(final Settings settings, @@ -59,7 +59,7 @@ public List getRestHandlers(final Settings settings, final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier nodesInCluster) { - return singletonList(new SearchRelevanceRestHandler(backend)); + return singletonList(new UserBehaviorLoggingRestHandler(backend)); } @@ -79,7 +79,7 @@ public List> getSettings() { @Override public List getActionFilters() { // LOGGER.info("Index name: {}", settings.get(ConfigConstants.INDEX_NAME)); - return singletonList(searchRelevanceFilter); + return singletonList(userBehaviorLoggingFilter); } @Override @@ -98,7 +98,7 @@ public Collection createComponents( ) { this.backend = new OpenSearchBackend(client); - this.searchRelevanceFilter = new SearchRelevanceSearchFilter(backend, environment.settings()); + this.userBehaviorLoggingFilter = new UserBehaviorLoggingSearchFilter(backend, environment.settings()); LOGGER.info("Creating scheduled task"); diff --git a/src/main/java/org/opensearch/relevance/action/SearchRelevanceRestHandler.java b/src/main/java/org/opensearch/action/UserBehaviorLoggingRestHandler.java similarity index 76% rename from src/main/java/org/opensearch/relevance/action/SearchRelevanceRestHandler.java rename to src/main/java/org/opensearch/action/UserBehaviorLoggingRestHandler.java index f4771f9..0894871 100644 --- a/src/main/java/org/opensearch/relevance/action/SearchRelevanceRestHandler.java +++ b/src/main/java/org/opensearch/action/UserBehaviorLoggingRestHandler.java @@ -6,14 +6,14 @@ * compatible open source license. */ -package org.opensearch.relevance.action; +package org.opensearch.action; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.node.NodeClient; import org.opensearch.core.rest.RestStatus; -import org.opensearch.relevance.backends.Backend; +import org.opensearch.backends.Backend; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestRequest; @@ -22,13 +22,13 @@ import static org.opensearch.rest.RestRequest.Method.*; -public class SearchRelevanceRestHandler extends BaseRestHandler { +public class UserBehaviorLoggingRestHandler extends BaseRestHandler { - private static final Logger LOGGER = LogManager.getLogger(SearchRelevanceRestHandler.class); + private static final Logger LOGGER = LogManager.getLogger(UserBehaviorLoggingRestHandler.class); private final Backend backend; - public SearchRelevanceRestHandler(final Backend backend) { + public UserBehaviorLoggingRestHandler(final Backend backend) { this.backend = backend; } @@ -40,10 +40,10 @@ public String getName() { @Override public List routes() { return List.of( - new Route(PUT, "/_plugins/search_relevance/{store}"), // Initializes the store. - new Route(DELETE, "/_plugins/search_relevance/{store}"), // Deletes a store. - new Route(GET, "/_plugins/search_relevance"), // Lists all stores - new Route(POST, "/_plugins/search_relevance/{store}")); // Indexes events into the store. + new Route(PUT, "/_plugins/ubl/{store}"), // Initializes the store. + new Route(DELETE, "/_plugins/ubl/{store}"), // Deletes a store. + new Route(GET, "/_plugins/ubl"), // Lists all stores + new Route(POST, "/_plugins/ubl/{store}")); // Indexes events into the store. } @Override diff --git a/src/main/java/org/opensearch/relevance/action/SearchRelevanceSearchFilter.java b/src/main/java/org/opensearch/action/UserBehaviorLoggingSearchFilter.java similarity index 87% rename from src/main/java/org/opensearch/relevance/action/SearchRelevanceSearchFilter.java rename to src/main/java/org/opensearch/action/UserBehaviorLoggingSearchFilter.java index 8f243f5..de12a09 100644 --- a/src/main/java/org/opensearch/relevance/action/SearchRelevanceSearchFilter.java +++ b/src/main/java/org/opensearch/action/UserBehaviorLoggingSearchFilter.java @@ -6,11 +6,10 @@ * compatible open source license. */ -package org.opensearch.relevance.action; +package org.opensearch.action; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.opensearch.action.ActionRequest; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; import org.opensearch.action.support.ActionFilter; @@ -18,22 +17,21 @@ import org.opensearch.common.settings.Settings; import org.opensearch.core.action.ActionListener; import org.opensearch.core.action.ActionResponse; -import org.opensearch.relevance.SettingsConstants; -import org.opensearch.relevance.backends.Backend; -import org.opensearch.relevance.model.QueryRequest; -import org.opensearch.relevance.model.QueryResponse; +import org.opensearch.model.QueryResponse; +import org.opensearch.backends.Backend; +import org.opensearch.model.QueryRequest; import org.opensearch.tasks.Task; import java.util.*; -public class SearchRelevanceSearchFilter implements ActionFilter { +public class UserBehaviorLoggingSearchFilter implements ActionFilter { - private static final Logger LOGGER = LogManager.getLogger(SearchRelevanceSearchFilter.class); + private static final Logger LOGGER = LogManager.getLogger(UserBehaviorLoggingSearchFilter.class); private final Backend backend; private final Settings settings; - public SearchRelevanceSearchFilter(final Backend backend, final Settings settings) { + public UserBehaviorLoggingSearchFilter(final Backend backend, final Settings settings) { this.backend = backend; this.settings = settings; } diff --git a/src/main/java/org/opensearch/relevance/backends/Backend.java b/src/main/java/org/opensearch/backends/Backend.java similarity index 76% rename from src/main/java/org/opensearch/relevance/backends/Backend.java rename to src/main/java/org/opensearch/backends/Backend.java index 53e6b25..b9d8ba2 100644 --- a/src/main/java/org/opensearch/relevance/backends/Backend.java +++ b/src/main/java/org/opensearch/backends/Backend.java @@ -6,11 +6,10 @@ * compatible open source license. */ -package org.opensearch.relevance.backends; +package org.opensearch.backends; -import org.opensearch.client.node.NodeClient; -import org.opensearch.relevance.model.QueryRequest; -import org.opensearch.relevance.model.QueryResponse; +import org.opensearch.model.QueryResponse; +import org.opensearch.model.QueryRequest; import org.opensearch.rest.RestChannel; import java.util.List; diff --git a/src/main/java/org/opensearch/relevance/backends/OpenSearchBackend.java b/src/main/java/org/opensearch/backends/OpenSearchBackend.java similarity index 95% rename from src/main/java/org/opensearch/relevance/backends/OpenSearchBackend.java rename to src/main/java/org/opensearch/backends/OpenSearchBackend.java index a752855..a9b11ea 100644 --- a/src/main/java/org/opensearch/relevance/backends/OpenSearchBackend.java +++ b/src/main/java/org/opensearch/backends/OpenSearchBackend.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance.backends; +package org.opensearch.backends; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -18,10 +18,10 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.io.Streams; import org.opensearch.common.xcontent.XContentType; -import org.opensearch.relevance.SettingsConstants; -import org.opensearch.relevance.events.EventManager; -import org.opensearch.relevance.model.QueryRequest; -import org.opensearch.relevance.model.QueryResponse; +import org.opensearch.events.EventManager; +import org.opensearch.model.QueryResponse; +import org.opensearch.SettingsConstants; +import org.opensearch.model.QueryRequest; import org.opensearch.rest.RestChannel; import org.opensearch.rest.action.RestToXContentListener; diff --git a/src/main/java/org/opensearch/relevance/events/EventManager.java b/src/main/java/org/opensearch/events/EventManager.java similarity index 88% rename from src/main/java/org/opensearch/relevance/events/EventManager.java rename to src/main/java/org/opensearch/events/EventManager.java index 5fcc15c..84b0a25 100644 --- a/src/main/java/org/opensearch/relevance/events/EventManager.java +++ b/src/main/java/org/opensearch/events/EventManager.java @@ -6,17 +6,15 @@ * compatible open source license. */ -package org.opensearch.relevance.events; +package org.opensearch.events; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.action.bulk.BulkRequest; import org.opensearch.action.index.IndexRequest; import org.opensearch.client.Client; -import org.opensearch.relevance.events.queues.EventQueue; -import org.opensearch.relevance.events.queues.InternalQueue; - -import java.util.TimerTask; +import org.opensearch.events.queues.EventQueue; +import org.opensearch.events.queues.InternalQueue; public class EventManager { diff --git a/src/main/java/org/opensearch/relevance/events/queues/EventQueue.java b/src/main/java/org/opensearch/events/queues/EventQueue.java similarity index 89% rename from src/main/java/org/opensearch/relevance/events/queues/EventQueue.java rename to src/main/java/org/opensearch/events/queues/EventQueue.java index 2ae1f82..4f0101e 100644 --- a/src/main/java/org/opensearch/relevance/events/queues/EventQueue.java +++ b/src/main/java/org/opensearch/events/queues/EventQueue.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance.events.queues; +package org.opensearch.events.queues; import org.opensearch.action.index.IndexRequest; diff --git a/src/main/java/org/opensearch/relevance/events/queues/InternalQueue.java b/src/main/java/org/opensearch/events/queues/InternalQueue.java similarity index 94% rename from src/main/java/org/opensearch/relevance/events/queues/InternalQueue.java rename to src/main/java/org/opensearch/events/queues/InternalQueue.java index d154ef4..ff9a8b1 100644 --- a/src/main/java/org/opensearch/relevance/events/queues/InternalQueue.java +++ b/src/main/java/org/opensearch/events/queues/InternalQueue.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance.events.queues; +package org.opensearch.events.queues; import org.opensearch.action.index.IndexRequest; diff --git a/src/main/java/org/opensearch/relevance/model/QueryRequest.java b/src/main/java/org/opensearch/model/QueryRequest.java similarity index 93% rename from src/main/java/org/opensearch/relevance/model/QueryRequest.java rename to src/main/java/org/opensearch/model/QueryRequest.java index a5eb03a..0810fff 100644 --- a/src/main/java/org/opensearch/relevance/model/QueryRequest.java +++ b/src/main/java/org/opensearch/model/QueryRequest.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance.model; +package org.opensearch.model; public class QueryRequest { diff --git a/src/main/java/org/opensearch/relevance/model/QueryResponse.java b/src/main/java/org/opensearch/model/QueryResponse.java similarity index 95% rename from src/main/java/org/opensearch/relevance/model/QueryResponse.java rename to src/main/java/org/opensearch/model/QueryResponse.java index f90be4b..cfc9a1e 100644 --- a/src/main/java/org/opensearch/relevance/model/QueryResponse.java +++ b/src/main/java/org/opensearch/model/QueryResponse.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.relevance.model; +package org.opensearch.model; import java.util.List; diff --git a/src/main/resources/org/opensearch/relevance/backends/events-mapping.json b/src/main/resources/org/opensearch/backends/events-mapping.json similarity index 99% rename from src/main/resources/org/opensearch/relevance/backends/events-mapping.json rename to src/main/resources/org/opensearch/backends/events-mapping.json index 6093a67..423f208 100644 --- a/src/main/resources/org/opensearch/relevance/backends/events-mapping.json +++ b/src/main/resources/org/opensearch/backends/events-mapping.json @@ -1,5 +1,5 @@ { - "dynamic": "strict", + "dynamic": false, "properties": { "action_name": { "type" : "keyword" }, "user_id": { "type" : "keyword" }, diff --git a/src/main/resources/org/opensearch/relevance/backends/queries-mapping.json b/src/main/resources/org/opensearch/backends/queries-mapping.json similarity index 75% rename from src/main/resources/org/opensearch/relevance/backends/queries-mapping.json rename to src/main/resources/org/opensearch/backends/queries-mapping.json index 440170b..495f27f 100644 --- a/src/main/resources/org/opensearch/relevance/backends/queries-mapping.json +++ b/src/main/resources/org/opensearch/backends/queries-mapping.json @@ -1,5 +1,5 @@ { - "dynamic": "strict", + "dynamic": false, "properties": { "query": { "type": "keyword" diff --git a/src/yamlRestTest/java/org/opensearch/rest/action/SearchRelevanceClientYamlTestSuiteIT.java b/src/yamlRestTest/java/org/opensearch/rest/action/UserBehaviorLoggingClientYamlTestSuiteIT.java similarity index 77% rename from src/yamlRestTest/java/org/opensearch/rest/action/SearchRelevanceClientYamlTestSuiteIT.java rename to src/yamlRestTest/java/org/opensearch/rest/action/UserBehaviorLoggingClientYamlTestSuiteIT.java index 548cd6a..cd9165f 100644 --- a/src/yamlRestTest/java/org/opensearch/rest/action/SearchRelevanceClientYamlTestSuiteIT.java +++ b/src/yamlRestTest/java/org/opensearch/rest/action/UserBehaviorLoggingClientYamlTestSuiteIT.java @@ -12,9 +12,9 @@ import org.opensearch.test.rest.yaml.ClientYamlTestCandidate; import org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase; -public class SearchRelevanceClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase { +public class UserBehaviorLoggingClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase { - public SearchRelevanceClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { + public UserBehaviorLoggingClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { super(testCandidate); } diff --git a/src/yamlRestTest/resources/rest-api-spec/api/_plugins.search_relevance.json b/src/yamlRestTest/resources/rest-api-spec/api/_plugins.search_relevance.json index 7dcf709..d449fa5 100644 --- a/src/yamlRestTest/resources/rest-api-spec/api/_plugins.search_relevance.json +++ b/src/yamlRestTest/resources/rest-api-spec/api/_plugins.search_relevance.json @@ -4,7 +4,7 @@ "url": { "paths": [ { - "path": "/_plugins/search_relevance", + "path": "/_plugins/ubl", "methods": [ "DELETE", "GET", diff --git a/src/yamlRestTest/resources/rest-api-spec/test/_plugins.search_relevance/10_basic.yml b/src/yamlRestTest/resources/rest-api-spec/test/_plugins.search_relevance/10_basic.yml index 6622524..1a1f6bd 100644 --- a/src/yamlRestTest/resources/rest-api-spec/test/_plugins.search_relevance/10_basic.yml +++ b/src/yamlRestTest/resources/rest-api-spec/test/_plugins.search_relevance/10_basic.yml @@ -5,4 +5,4 @@ h: component - match: - $body: /^opensearch-search-relevance\n$/ + $body: /^opensearch-ubl\n$/