From a0fa1a625e4d4c13e8aa0b31cf6c54a7a6ac8970 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Thu, 18 Mar 2021 20:37:21 -0500 Subject: [PATCH] [Rename] remaining ES prefixed classes (#406) This commit refactors remaining ES classes to OpenSearch prefix throughout the code base. All references are also refactored. Signed-off-by: Nicholas Walter Knize --- ...ts.java => OpenSearchJsonLayoutTests.java} | 10 +++--- .../custom_logging/CustomLoggingConfigIT.java | 2 +- ...ava => OpenSearchSmokeClientTestCase.java} | 4 +-- .../smoketest/SmokeTestClientIT.java | 2 +- .../common/logging/DeprecatedMessage.java | 2 +- .../common/logging/DeprecationLogger.java | 2 +- .../common/logging/HeaderWarningAppender.java | 8 ++--- ...nLayout.java => OpenSearchJsonLayout.java} | 34 +++++++++---------- ...Message.java => OpenSearchLogMessage.java} | 6 ++-- ...a => OpenSearchMessageFieldConverter.java} | 18 +++++----- .../common/logging/RateLimitingFilter.java | 8 ++--- .../util/concurrent/OpenSearchExecutors.java | 6 ++-- .../test/store/MockFSDirectoryFactory.java | 12 +++---- 13 files changed, 57 insertions(+), 57 deletions(-) rename qa/logging-config/src/test/java/org/opensearch/common/logging/{ESJsonLayoutTests.java => OpenSearchJsonLayoutTests.java} (91%) rename qa/smoke-test-client/src/test/java/org/opensearch/smoketest/{ESSmokeClientTestCase.java => OpenSearchSmokeClientTestCase.java} (98%) rename server/src/main/java/org/opensearch/common/logging/{ESJsonLayout.java => OpenSearchJsonLayout.java} (86%) rename server/src/main/java/org/opensearch/common/logging/{ESLogMessage.java => OpenSearchLogMessage.java} (90%) rename server/src/main/java/org/opensearch/common/logging/{ESMessageFieldConverter.java => OpenSearchMessageFieldConverter.java} (76%) diff --git a/qa/logging-config/src/test/java/org/opensearch/common/logging/ESJsonLayoutTests.java b/qa/logging-config/src/test/java/org/opensearch/common/logging/OpenSearchJsonLayoutTests.java similarity index 91% rename from qa/logging-config/src/test/java/org/opensearch/common/logging/ESJsonLayoutTests.java rename to qa/logging-config/src/test/java/org/opensearch/common/logging/OpenSearchJsonLayoutTests.java index cad8314dcc4..920bf3feaf6 100644 --- a/qa/logging-config/src/test/java/org/opensearch/common/logging/ESJsonLayoutTests.java +++ b/qa/logging-config/src/test/java/org/opensearch/common/logging/OpenSearchJsonLayoutTests.java @@ -24,18 +24,18 @@ import org.hamcrest.Matchers; import org.junit.BeforeClass; -public class ESJsonLayoutTests extends OpenSearchTestCase { +public class OpenSearchJsonLayoutTests extends OpenSearchTestCase { @BeforeClass public static void initNodeName() { JsonLogsTestSetup.init(); } public void testEmptyType() { - expectThrows(IllegalArgumentException.class, () -> ESJsonLayout.newBuilder().build()); + expectThrows(IllegalArgumentException.class, () -> OpenSearchJsonLayout.newBuilder().build()); } public void testLayout() { - ESJsonLayout server = ESJsonLayout.newBuilder() + OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder() .setType("server") .build(); String conversionPattern = server.getPatternLayout().getConversionPattern(); @@ -54,7 +54,7 @@ public class ESJsonLayoutTests extends OpenSearchTestCase { } public void testLayoutWithAdditionalFields() { - ESJsonLayout server = ESJsonLayout.newBuilder() + OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder() .setType("server") .setESMessageFields("x-opaque-id,someOtherField") .build(); @@ -76,7 +76,7 @@ public class ESJsonLayoutTests extends OpenSearchTestCase { } public void testLayoutWithAdditionalFieldOverride() { - ESJsonLayout server = ESJsonLayout.newBuilder() + OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder() .setType("server") .setESMessageFields("message") .build(); diff --git a/qa/logging-config/src/test/java/org/opensearch/qa/custom_logging/CustomLoggingConfigIT.java b/qa/logging-config/src/test/java/org/opensearch/qa/custom_logging/CustomLoggingConfigIT.java index 80499de6ab7..3d150bf62f8 100644 --- a/qa/logging-config/src/test/java/org/opensearch/qa/custom_logging/CustomLoggingConfigIT.java +++ b/qa/logging-config/src/test/java/org/opensearch/qa/custom_logging/CustomLoggingConfigIT.java @@ -36,7 +36,7 @@ import java.util.List; /** * This test verifies that OpenSearch can startup successfully with a custom logging config using variables introduced in - * ESJsonLayout + * OpenSearchJsonLayout * The intention is to confirm that users can still run their OpenSearch instances with previous configurations. */ public class CustomLoggingConfigIT extends OpenSearchRestTestCase { diff --git a/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/ESSmokeClientTestCase.java b/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/OpenSearchSmokeClientTestCase.java similarity index 98% rename from qa/smoke-test-client/src/test/java/org/opensearch/smoketest/ESSmokeClientTestCase.java rename to qa/smoke-test-client/src/test/java/org/opensearch/smoketest/OpenSearchSmokeClientTestCase.java index 7d2d3838267..8fb8c843c41 100644 --- a/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/ESSmokeClientTestCase.java +++ b/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/OpenSearchSmokeClientTestCase.java @@ -61,14 +61,14 @@ import static org.hamcrest.Matchers.notNullValue; * then run JUnit. If you changed the default port, set "-Dtests.cluster=localhost:PORT" when running your test. */ @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose") -public abstract class ESSmokeClientTestCase extends LuceneTestCase { +public abstract class OpenSearchSmokeClientTestCase extends LuceneTestCase { /** * Key used to eventually switch to using an external cluster and provide its transport addresses */ public static final String TESTS_CLUSTER = "tests.cluster"; - protected static final Logger logger = LogManager.getLogger(ESSmokeClientTestCase.class); + protected static final Logger logger = LogManager.getLogger(OpenSearchSmokeClientTestCase.class); private static final AtomicInteger counter = new AtomicInteger(); private static Client client; diff --git a/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/SmokeTestClientIT.java b/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/SmokeTestClientIT.java index 6f59e109c1e..7f5e840ec08 100644 --- a/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/SmokeTestClientIT.java +++ b/qa/smoke-test-client/src/test/java/org/opensearch/smoketest/SmokeTestClientIT.java @@ -26,7 +26,7 @@ import org.opensearch.client.Client; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.greaterThan; -public class SmokeTestClientIT extends ESSmokeClientTestCase { +public class SmokeTestClientIT extends OpenSearchSmokeClientTestCase { /** * Check that we are connected to a cluster named "opensearch". diff --git a/server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java b/server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java index eb54044a5cf..2ff7e358466 100644 --- a/server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java +++ b/server/src/main/java/org/opensearch/common/logging/DeprecatedMessage.java @@ -28,7 +28,7 @@ import org.opensearch.common.collect.MapBuilder; * A logger message used by {@link DeprecationLogger}. * Carries x-opaque-id field if provided in the headers. Will populate the x-opaque-id field in JSON logs. */ -public class DeprecatedMessage extends ESLogMessage { +public class DeprecatedMessage extends OpenSearchLogMessage { public static final String X_OPAQUE_ID_FIELD_NAME = "x-opaque-id"; public DeprecatedMessage(String key, String xOpaqueId, String messagePattern, Object... args) { diff --git a/server/src/main/java/org/opensearch/common/logging/DeprecationLogger.java b/server/src/main/java/org/opensearch/common/logging/DeprecationLogger.java index e4fa98df24b..96de9a25779 100644 --- a/server/src/main/java/org/opensearch/common/logging/DeprecationLogger.java +++ b/server/src/main/java/org/opensearch/common/logging/DeprecationLogger.java @@ -93,7 +93,7 @@ public class DeprecationLogger { public class DeprecationLoggerBuilder { public DeprecationLoggerBuilder withDeprecation(String key, String msg, Object[] params) { - ESLogMessage deprecationMessage = new DeprecatedMessage(key, HeaderWarning.getXOpaqueId(), msg, params); + OpenSearchLogMessage deprecationMessage = new DeprecatedMessage(key, HeaderWarning.getXOpaqueId(), msg, params); logger.log(DEPRECATION, deprecationMessage); diff --git a/server/src/main/java/org/opensearch/common/logging/HeaderWarningAppender.java b/server/src/main/java/org/opensearch/common/logging/HeaderWarningAppender.java index 811ffea5f82..10af7d98141 100644 --- a/server/src/main/java/org/opensearch/common/logging/HeaderWarningAppender.java +++ b/server/src/main/java/org/opensearch/common/logging/HeaderWarningAppender.java @@ -40,11 +40,11 @@ public class HeaderWarningAppender extends AbstractAppender { public void append(LogEvent event) { final Message message = event.getMessage(); - if (message instanceof ESLogMessage) { - final ESLogMessage esLogMessage = (ESLogMessage) message; + if (message instanceof OpenSearchLogMessage) { + final OpenSearchLogMessage opensearchLogMessage = (OpenSearchLogMessage) message; - String messagePattern = esLogMessage.getMessagePattern(); - Object[] arguments = esLogMessage.getArguments(); + String messagePattern = opensearchLogMessage.getMessagePattern(); + Object[] arguments = opensearchLogMessage.getArguments(); HeaderWarning.addWarning(messagePattern, arguments); } else { diff --git a/server/src/main/java/org/opensearch/common/logging/ESJsonLayout.java b/server/src/main/java/org/opensearch/common/logging/OpenSearchJsonLayout.java similarity index 86% rename from server/src/main/java/org/opensearch/common/logging/ESJsonLayout.java rename to server/src/main/java/org/opensearch/common/logging/OpenSearchJsonLayout.java index ddb17297555..893d7d1bf4b 100644 --- a/server/src/main/java/org/opensearch/common/logging/ESJsonLayout.java +++ b/server/src/main/java/org/opensearch/common/logging/OpenSearchJsonLayout.java @@ -62,22 +62,22 @@ import java.util.stream.Stream; *

* It is possible to add more or override them with esmessagefield * appender.logger.layout.esmessagefields=message,took,took_millis,total_hits,types,stats,search_type,total_shards,source,id - * Each of these will be expanded into a json field with a value taken {@link ESLogMessage} field. In the example above + * Each of these will be expanded into a json field with a value taken {@link OpenSearchLogMessage} field. In the example above * ... "message": %ESMessageField{message}, "took": %ESMessageField{took} ... * the message passed to a logger will be overriden with a value from %ESMessageField{message} *

* The value taken from %ESMessageField{message} has to be a simple escaped JSON value and is populated in subclasses of - * ESLogMessage + * OpenSearchLogMessage */ -@Plugin(name = "ESJsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) -public class ESJsonLayout extends AbstractStringLayout { +@Plugin(name = "OpenSearchJsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) +public class OpenSearchJsonLayout extends AbstractStringLayout { private final PatternLayout patternLayout; - protected ESJsonLayout(String typeName, Charset charset, String[] esmessagefields) { + protected OpenSearchJsonLayout(String typeName, Charset charset, String[] opensearchMessageFields) { super(charset); this.patternLayout = PatternLayout.newBuilder() - .withPattern(pattern(typeName, esmessagefields)) + .withPattern(pattern(typeName, opensearchMessageFields)) .withAlwaysWriteExceptions(false) .build(); } @@ -146,18 +146,18 @@ public class ESJsonLayout extends AbstractStringLayout { } @PluginFactory - public static ESJsonLayout createLayout(String type, - Charset charset, - String[] esmessagefields) { - return new ESJsonLayout(type, charset, esmessagefields); + public static OpenSearchJsonLayout createLayout(String type, + Charset charset, + String[] esmessagefields) { + return new OpenSearchJsonLayout(type, charset, esmessagefields); } PatternLayout getPatternLayout() { return patternLayout; } - public static class Builder> extends AbstractStringLayout.Builder - implements org.apache.logging.log4j.core.util.Builder { + public static class Builder> extends AbstractStringLayout.Builder + implements org.apache.logging.log4j.core.util.Builder { @PluginAttribute("type_name") String type; @@ -173,9 +173,9 @@ public class ESJsonLayout extends AbstractStringLayout { } @Override - public ESJsonLayout build() { + public OpenSearchJsonLayout build() { String[] split = Strings.isNullOrEmpty(esMessageFields) ? new String[]{} : esMessageFields.split(","); - return ESJsonLayout.createLayout(type, charset, split); + return OpenSearchJsonLayout.createLayout(type, charset, split); } public Charset getCharset() { @@ -207,8 +207,8 @@ public class ESJsonLayout extends AbstractStringLayout { } @PluginBuilderFactory - public static > B newBuilder() { - return new ESJsonLayout.Builder().asBuilder(); + public static > B newBuilder() { + return new OpenSearchJsonLayout.Builder().asBuilder(); } @Override @@ -228,7 +228,7 @@ public class ESJsonLayout extends AbstractStringLayout { @Override public String toString() { - final StringBuilder sb = new StringBuilder("ESJsonLayout{"); + final StringBuilder sb = new StringBuilder("OpenSearchJsonLayout{"); sb.append("patternLayout=").append(patternLayout); sb.append('}'); return sb.toString(); diff --git a/server/src/main/java/org/opensearch/common/logging/ESLogMessage.java b/server/src/main/java/org/opensearch/common/logging/OpenSearchLogMessage.java similarity index 90% rename from server/src/main/java/org/opensearch/common/logging/ESLogMessage.java rename to server/src/main/java/org/opensearch/common/logging/OpenSearchLogMessage.java index 0f38bf1a3b1..2b3e88450de 100644 --- a/server/src/main/java/org/opensearch/common/logging/ESLogMessage.java +++ b/server/src/main/java/org/opensearch/common/logging/OpenSearchLogMessage.java @@ -30,14 +30,14 @@ import java.util.stream.Stream; * A base class for custom log4j logger messages. Carries additional fields which will populate JSON fields in logs. */ @SuppressLoggerChecks(reason = "Safe as this is abstract class") -public abstract class ESLogMessage extends ParameterizedMessage { +public abstract class OpenSearchLogMessage extends ParameterizedMessage { private final Map fields; /** * This is an abstract class, so this is safe. The check is done on DeprecationMessage. * Other subclasses are not allowing varargs */ - public ESLogMessage(Map fields, String messagePattern, Object... args) { + public OpenSearchLogMessage(Map fields, String messagePattern, Object... args) { super(messagePattern, args); this.fields = fields; } @@ -61,7 +61,7 @@ public abstract class ESLogMessage extends ParameterizedMessage { public static String asJsonArray(Stream stream) { return "[" + stream - .map(ESLogMessage::inQuotes) + .map(OpenSearchLogMessage::inQuotes) .collect(Collectors.joining(", ")) + "]"; } diff --git a/server/src/main/java/org/opensearch/common/logging/ESMessageFieldConverter.java b/server/src/main/java/org/opensearch/common/logging/OpenSearchMessageFieldConverter.java similarity index 76% rename from server/src/main/java/org/opensearch/common/logging/ESMessageFieldConverter.java rename to server/src/main/java/org/opensearch/common/logging/OpenSearchMessageFieldConverter.java index cfd2eed38b1..ec594b5049b 100644 --- a/server/src/main/java/org/opensearch/common/logging/ESMessageFieldConverter.java +++ b/server/src/main/java/org/opensearch/common/logging/OpenSearchMessageFieldConverter.java @@ -30,32 +30,32 @@ import org.opensearch.common.Strings; /** * Pattern converter to populate ESMessageField in a pattern. - * It will only populate these if the event have message of type ESLogMessage. + * It will only populate these if the event have message of type OpenSearchLogMessage. */ -@Plugin(category = PatternConverter.CATEGORY, name = "ESMessageField") -@ConverterKeys({"ESMessageField"}) -public final class ESMessageFieldConverter extends LogEventPatternConverter { +@Plugin(category = PatternConverter.CATEGORY, name = "OpenSearchMessageField") +@ConverterKeys({"OpenSearchMessageField"}) +public final class OpenSearchMessageFieldConverter extends LogEventPatternConverter { private String key; /** * Called by log4j2 to initialize this converter. */ - public static ESMessageFieldConverter newInstance(final Configuration config, final String[] options) { + public static OpenSearchMessageFieldConverter newInstance(final Configuration config, final String[] options) { final String key = options[0]; - return new ESMessageFieldConverter(key); + return new OpenSearchMessageFieldConverter(key); } - public ESMessageFieldConverter(String key) { + public OpenSearchMessageFieldConverter(String key) { super("ESMessageField", "ESMessageField"); this.key = key; } @Override public void format(LogEvent event, StringBuilder toAppendTo) { - if (event.getMessage() instanceof ESLogMessage) { - ESLogMessage logMessage = (ESLogMessage) event.getMessage(); + if (event.getMessage() instanceof OpenSearchLogMessage) { + OpenSearchLogMessage logMessage = (OpenSearchLogMessage) event.getMessage(); final String value = logMessage.getValueFor(key); if (Strings.isNullOrEmpty(value) == false) { StringBuilders.appendValue(toAppendTo, value); diff --git a/server/src/main/java/org/opensearch/common/logging/RateLimitingFilter.java b/server/src/main/java/org/opensearch/common/logging/RateLimitingFilter.java index 866efb92a52..a6351a78fe6 100644 --- a/server/src/main/java/org/opensearch/common/logging/RateLimitingFilter.java +++ b/server/src/main/java/org/opensearch/common/logging/RateLimitingFilter.java @@ -64,11 +64,11 @@ public class RateLimitingFilter extends AbstractFilter { } public Result filter(Message message) { - if (message instanceof ESLogMessage) { - final ESLogMessage esLogMessage = (ESLogMessage) message; + if (message instanceof OpenSearchLogMessage) { + final OpenSearchLogMessage opensearchLogMessage = (OpenSearchLogMessage) message; - String xOpaqueId = esLogMessage.getValueFor(X_OPAQUE_ID_FIELD_NAME); - final String key = esLogMessage.getValueFor("key"); + String xOpaqueId = opensearchLogMessage.getValueFor(X_OPAQUE_ID_FIELD_NAME); + final String key = opensearchLogMessage.getValueFor("key"); return lruKeyCache.add(xOpaqueId + key) ? Result.ACCEPT : Result.DENY; diff --git a/server/src/main/java/org/opensearch/common/util/concurrent/OpenSearchExecutors.java b/server/src/main/java/org/opensearch/common/util/concurrent/OpenSearchExecutors.java index 76f3f5c4f57..4ba91b2cfac 100644 --- a/server/src/main/java/org/opensearch/common/util/concurrent/OpenSearchExecutors.java +++ b/server/src/main/java/org/opensearch/common/util/concurrent/OpenSearchExecutors.java @@ -262,16 +262,16 @@ public class OpenSearchExecutors { } public static ThreadFactory daemonThreadFactory(String namePrefix) { - return new EsThreadFactory(namePrefix); + return new OpenSearchThreadFactory(namePrefix); } - static class EsThreadFactory implements ThreadFactory { + static class OpenSearchThreadFactory implements ThreadFactory { final ThreadGroup group; final AtomicInteger threadNumber = new AtomicInteger(1); final String namePrefix; - EsThreadFactory(String namePrefix) { + OpenSearchThreadFactory(String namePrefix) { this.namePrefix = namePrefix; SecurityManager s = System.getSecurityManager(); group = (s != null) ? s.getThreadGroup() : diff --git a/test/framework/src/main/java/org/opensearch/test/store/MockFSDirectoryFactory.java b/test/framework/src/main/java/org/opensearch/test/store/MockFSDirectoryFactory.java index 8468233e748..6db76882382 100644 --- a/test/framework/src/main/java/org/opensearch/test/store/MockFSDirectoryFactory.java +++ b/test/framework/src/main/java/org/opensearch/test/store/MockFSDirectoryFactory.java @@ -31,9 +31,9 @@ import org.apache.lucene.util.TestRuleMarkFailure; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.lucene.Lucene; -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Setting.Property; -import org.elasticsearch.common.settings.Settings; +import org.opensearch.common.settings.Setting; +import org.opensearch.common.settings.Setting.Property; +import org.opensearch.common.settings.Settings; import org.opensearch.index.IndexModule; import org.opensearch.index.IndexSettings; import org.opensearch.index.shard.ShardId; @@ -114,7 +114,7 @@ public class MockFSDirectoryFactory implements IndexStorePlugin.DirectoryFactory random.nextInt(shardId.getId() + 1); // some randomness per shard MockDirectoryWrapper.Throttling throttle = MockDirectoryWrapper.Throttling.NEVER; boolean crashIndex = CRASH_INDEX_SETTING.get(indexSettings); - final ElasticsearchMockDirectoryWrapper w = new ElasticsearchMockDirectoryWrapper(random, dir, crashIndex); + final OpenSearchMockDirectoryWrapper w = new OpenSearchMockDirectoryWrapper(random, dir, crashIndex); w.setRandomIOExceptionRate(randomIOExceptionRate); w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen); w.setThrottling(throttle); @@ -139,11 +139,11 @@ public class MockFSDirectoryFactory implements IndexStorePlugin.DirectoryFactory return new FsDirectoryFactory().newDirectory(newIndexSettings, path); } - public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper { + public static final class OpenSearchMockDirectoryWrapper extends MockDirectoryWrapper { private final boolean crash; - public ElasticsearchMockDirectoryWrapper(Random random, Directory delegate, boolean crash) { + public OpenSearchMockDirectoryWrapper(Random random, Directory delegate, boolean crash) { super(random, delegate); this.crash = crash; }