[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 <nknize@apache.org>
This commit is contained in:
Nick Knize 2021-03-18 20:37:21 -05:00 committed by Nick Knize
parent 127243b83b
commit a0fa1a625e
13 changed files with 57 additions and 57 deletions

View File

@ -24,18 +24,18 @@ import org.hamcrest.Matchers;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public class ESJsonLayoutTests extends OpenSearchTestCase { public class OpenSearchJsonLayoutTests extends OpenSearchTestCase {
@BeforeClass @BeforeClass
public static void initNodeName() { public static void initNodeName() {
JsonLogsTestSetup.init(); JsonLogsTestSetup.init();
} }
public void testEmptyType() { public void testEmptyType() {
expectThrows(IllegalArgumentException.class, () -> ESJsonLayout.newBuilder().build()); expectThrows(IllegalArgumentException.class, () -> OpenSearchJsonLayout.newBuilder().build());
} }
public void testLayout() { public void testLayout() {
ESJsonLayout server = ESJsonLayout.newBuilder() OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder()
.setType("server") .setType("server")
.build(); .build();
String conversionPattern = server.getPatternLayout().getConversionPattern(); String conversionPattern = server.getPatternLayout().getConversionPattern();
@ -54,7 +54,7 @@ public class ESJsonLayoutTests extends OpenSearchTestCase {
} }
public void testLayoutWithAdditionalFields() { public void testLayoutWithAdditionalFields() {
ESJsonLayout server = ESJsonLayout.newBuilder() OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder()
.setType("server") .setType("server")
.setESMessageFields("x-opaque-id,someOtherField") .setESMessageFields("x-opaque-id,someOtherField")
.build(); .build();
@ -76,7 +76,7 @@ public class ESJsonLayoutTests extends OpenSearchTestCase {
} }
public void testLayoutWithAdditionalFieldOverride() { public void testLayoutWithAdditionalFieldOverride() {
ESJsonLayout server = ESJsonLayout.newBuilder() OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder()
.setType("server") .setType("server")
.setESMessageFields("message") .setESMessageFields("message")
.build(); .build();

View File

@ -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 * This test verifies that OpenSearch can startup successfully with a custom logging config using variables introduced in
* <code>ESJsonLayout</code> * <code>OpenSearchJsonLayout</code>
* The intention is to confirm that users can still run their OpenSearch instances with previous configurations. * The intention is to confirm that users can still run their OpenSearch instances with previous configurations.
*/ */
public class CustomLoggingConfigIT extends OpenSearchRestTestCase { public class CustomLoggingConfigIT extends OpenSearchRestTestCase {

View File

@ -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. * 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") @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 * Key used to eventually switch to using an external cluster and provide its transport addresses
*/ */
public static final String TESTS_CLUSTER = "tests.cluster"; 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 final AtomicInteger counter = new AtomicInteger();
private static Client client; private static Client client;

View File

@ -26,7 +26,7 @@ import org.opensearch.client.Client;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan; 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". * Check that we are connected to a cluster named "opensearch".

View File

@ -28,7 +28,7 @@ import org.opensearch.common.collect.MapBuilder;
* A logger message used by {@link DeprecationLogger}. * 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. * 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 static final String X_OPAQUE_ID_FIELD_NAME = "x-opaque-id";
public DeprecatedMessage(String key, String xOpaqueId, String messagePattern, Object... args) { public DeprecatedMessage(String key, String xOpaqueId, String messagePattern, Object... args) {

View File

@ -93,7 +93,7 @@ public class DeprecationLogger {
public class DeprecationLoggerBuilder { public class DeprecationLoggerBuilder {
public DeprecationLoggerBuilder withDeprecation(String key, String msg, Object[] params) { 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); logger.log(DEPRECATION, deprecationMessage);

View File

@ -40,11 +40,11 @@ public class HeaderWarningAppender extends AbstractAppender {
public void append(LogEvent event) { public void append(LogEvent event) {
final Message message = event.getMessage(); final Message message = event.getMessage();
if (message instanceof ESLogMessage) { if (message instanceof OpenSearchLogMessage) {
final ESLogMessage esLogMessage = (ESLogMessage) message; final OpenSearchLogMessage opensearchLogMessage = (OpenSearchLogMessage) message;
String messagePattern = esLogMessage.getMessagePattern(); String messagePattern = opensearchLogMessage.getMessagePattern();
Object[] arguments = esLogMessage.getArguments(); Object[] arguments = opensearchLogMessage.getArguments();
HeaderWarning.addWarning(messagePattern, arguments); HeaderWarning.addWarning(messagePattern, arguments);
} else { } else {

View File

@ -62,22 +62,22 @@ import java.util.stream.Stream;
* <p> * <p>
* It is possible to add more or override them with <code>esmessagefield</code> * It is possible to add more or override them with <code>esmessagefield</code>
* <code>appender.logger.layout.esmessagefields=message,took,took_millis,total_hits,types,stats,search_type,total_shards,source,id</code> * <code>appender.logger.layout.esmessagefields=message,took,took_millis,total_hits,types,stats,search_type,total_shards,source,id</code>
* 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
* <code>... "message": %ESMessageField{message}, "took": %ESMessageField{took} ...</code> * <code>... "message": %ESMessageField{message}, "took": %ESMessageField{took} ...</code>
* the message passed to a logger will be overriden with a value from %ESMessageField{message} * the message passed to a logger will be overriden with a value from %ESMessageField{message}
* <p> * <p>
* The value taken from %ESMessageField{message} has to be a simple escaped JSON value and is populated in subclasses of * The value taken from %ESMessageField{message} has to be a simple escaped JSON value and is populated in subclasses of
* <code>ESLogMessage</code> * <code>OpenSearchLogMessage</code>
*/ */
@Plugin(name = "ESJsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) @Plugin(name = "OpenSearchJsonLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true)
public class ESJsonLayout extends AbstractStringLayout { public class OpenSearchJsonLayout extends AbstractStringLayout {
private final PatternLayout patternLayout; private final PatternLayout patternLayout;
protected ESJsonLayout(String typeName, Charset charset, String[] esmessagefields) { protected OpenSearchJsonLayout(String typeName, Charset charset, String[] opensearchMessageFields) {
super(charset); super(charset);
this.patternLayout = PatternLayout.newBuilder() this.patternLayout = PatternLayout.newBuilder()
.withPattern(pattern(typeName, esmessagefields)) .withPattern(pattern(typeName, opensearchMessageFields))
.withAlwaysWriteExceptions(false) .withAlwaysWriteExceptions(false)
.build(); .build();
} }
@ -146,18 +146,18 @@ public class ESJsonLayout extends AbstractStringLayout {
} }
@PluginFactory @PluginFactory
public static ESJsonLayout createLayout(String type, public static OpenSearchJsonLayout createLayout(String type,
Charset charset, Charset charset,
String[] esmessagefields) { String[] esmessagefields) {
return new ESJsonLayout(type, charset, esmessagefields); return new OpenSearchJsonLayout(type, charset, esmessagefields);
} }
PatternLayout getPatternLayout() { PatternLayout getPatternLayout() {
return patternLayout; return patternLayout;
} }
public static class Builder<B extends ESJsonLayout.Builder<B>> extends AbstractStringLayout.Builder<B> public static class Builder<B extends OpenSearchJsonLayout.Builder<B>> extends AbstractStringLayout.Builder<B>
implements org.apache.logging.log4j.core.util.Builder<ESJsonLayout> { implements org.apache.logging.log4j.core.util.Builder<OpenSearchJsonLayout> {
@PluginAttribute("type_name") @PluginAttribute("type_name")
String type; String type;
@ -173,9 +173,9 @@ public class ESJsonLayout extends AbstractStringLayout {
} }
@Override @Override
public ESJsonLayout build() { public OpenSearchJsonLayout build() {
String[] split = Strings.isNullOrEmpty(esMessageFields) ? new String[]{} : esMessageFields.split(","); String[] split = Strings.isNullOrEmpty(esMessageFields) ? new String[]{} : esMessageFields.split(",");
return ESJsonLayout.createLayout(type, charset, split); return OpenSearchJsonLayout.createLayout(type, charset, split);
} }
public Charset getCharset() { public Charset getCharset() {
@ -207,8 +207,8 @@ public class ESJsonLayout extends AbstractStringLayout {
} }
@PluginBuilderFactory @PluginBuilderFactory
public static <B extends ESJsonLayout.Builder<B>> B newBuilder() { public static <B extends OpenSearchJsonLayout.Builder<B>> B newBuilder() {
return new ESJsonLayout.Builder<B>().asBuilder(); return new OpenSearchJsonLayout.Builder<B>().asBuilder();
} }
@Override @Override
@ -228,7 +228,7 @@ public class ESJsonLayout extends AbstractStringLayout {
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("ESJsonLayout{"); final StringBuilder sb = new StringBuilder("OpenSearchJsonLayout{");
sb.append("patternLayout=").append(patternLayout); sb.append("patternLayout=").append(patternLayout);
sb.append('}'); sb.append('}');
return sb.toString(); return sb.toString();

View File

@ -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. * 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") @SuppressLoggerChecks(reason = "Safe as this is abstract class")
public abstract class ESLogMessage extends ParameterizedMessage { public abstract class OpenSearchLogMessage extends ParameterizedMessage {
private final Map<String, Object> fields; private final Map<String, Object> fields;
/** /**
* This is an abstract class, so this is safe. The check is done on DeprecationMessage. * This is an abstract class, so this is safe. The check is done on DeprecationMessage.
* Other subclasses are not allowing varargs * Other subclasses are not allowing varargs
*/ */
public ESLogMessage(Map<String, Object> fields, String messagePattern, Object... args) { public OpenSearchLogMessage(Map<String, Object> fields, String messagePattern, Object... args) {
super(messagePattern, args); super(messagePattern, args);
this.fields = fields; this.fields = fields;
} }
@ -61,7 +61,7 @@ public abstract class ESLogMessage extends ParameterizedMessage {
public static String asJsonArray(Stream<String> stream) { public static String asJsonArray(Stream<String> stream) {
return "[" + stream return "[" + stream
.map(ESLogMessage::inQuotes) .map(OpenSearchLogMessage::inQuotes)
.collect(Collectors.joining(", ")) + "]"; .collect(Collectors.joining(", ")) + "]";
} }

View File

@ -30,32 +30,32 @@ import org.opensearch.common.Strings;
/** /**
* Pattern converter to populate ESMessageField in a pattern. * Pattern converter to populate ESMessageField in a pattern.
* It will only populate these if the event have message of type <code>ESLogMessage</code>. * It will only populate these if the event have message of type <code>OpenSearchLogMessage</code>.
*/ */
@Plugin(category = PatternConverter.CATEGORY, name = "ESMessageField") @Plugin(category = PatternConverter.CATEGORY, name = "OpenSearchMessageField")
@ConverterKeys({"ESMessageField"}) @ConverterKeys({"OpenSearchMessageField"})
public final class ESMessageFieldConverter extends LogEventPatternConverter { public final class OpenSearchMessageFieldConverter extends LogEventPatternConverter {
private String key; private String key;
/** /**
* Called by log4j2 to initialize this converter. * 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]; final String key = options[0];
return new ESMessageFieldConverter(key); return new OpenSearchMessageFieldConverter(key);
} }
public ESMessageFieldConverter(String key) { public OpenSearchMessageFieldConverter(String key) {
super("ESMessageField", "ESMessageField"); super("ESMessageField", "ESMessageField");
this.key = key; this.key = key;
} }
@Override @Override
public void format(LogEvent event, StringBuilder toAppendTo) { public void format(LogEvent event, StringBuilder toAppendTo) {
if (event.getMessage() instanceof ESLogMessage) { if (event.getMessage() instanceof OpenSearchLogMessage) {
ESLogMessage logMessage = (ESLogMessage) event.getMessage(); OpenSearchLogMessage logMessage = (OpenSearchLogMessage) event.getMessage();
final String value = logMessage.getValueFor(key); final String value = logMessage.getValueFor(key);
if (Strings.isNullOrEmpty(value) == false) { if (Strings.isNullOrEmpty(value) == false) {
StringBuilders.appendValue(toAppendTo, value); StringBuilders.appendValue(toAppendTo, value);

View File

@ -64,11 +64,11 @@ public class RateLimitingFilter extends AbstractFilter {
} }
public Result filter(Message message) { public Result filter(Message message) {
if (message instanceof ESLogMessage) { if (message instanceof OpenSearchLogMessage) {
final ESLogMessage esLogMessage = (ESLogMessage) message; final OpenSearchLogMessage opensearchLogMessage = (OpenSearchLogMessage) message;
String xOpaqueId = esLogMessage.getValueFor(X_OPAQUE_ID_FIELD_NAME); String xOpaqueId = opensearchLogMessage.getValueFor(X_OPAQUE_ID_FIELD_NAME);
final String key = esLogMessage.getValueFor("key"); final String key = opensearchLogMessage.getValueFor("key");
return lruKeyCache.add(xOpaqueId + key) ? Result.ACCEPT : Result.DENY; return lruKeyCache.add(xOpaqueId + key) ? Result.ACCEPT : Result.DENY;

View File

@ -262,16 +262,16 @@ public class OpenSearchExecutors {
} }
public static ThreadFactory daemonThreadFactory(String namePrefix) { 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 ThreadGroup group;
final AtomicInteger threadNumber = new AtomicInteger(1); final AtomicInteger threadNumber = new AtomicInteger(1);
final String namePrefix; final String namePrefix;
EsThreadFactory(String namePrefix) { OpenSearchThreadFactory(String namePrefix) {
this.namePrefix = namePrefix; this.namePrefix = namePrefix;
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : group = (s != null) ? s.getThreadGroup() :

View File

@ -31,9 +31,9 @@ import org.apache.lucene.util.TestRuleMarkFailure;
import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.common.lucene.Lucene; import org.opensearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Setting; import org.opensearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property; import org.opensearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.opensearch.common.settings.Settings;
import org.opensearch.index.IndexModule; import org.opensearch.index.IndexModule;
import org.opensearch.index.IndexSettings; import org.opensearch.index.IndexSettings;
import org.opensearch.index.shard.ShardId; 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 random.nextInt(shardId.getId() + 1); // some randomness per shard
MockDirectoryWrapper.Throttling throttle = MockDirectoryWrapper.Throttling.NEVER; MockDirectoryWrapper.Throttling throttle = MockDirectoryWrapper.Throttling.NEVER;
boolean crashIndex = CRASH_INDEX_SETTING.get(indexSettings); 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.setRandomIOExceptionRate(randomIOExceptionRate);
w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen); w.setRandomIOExceptionRateOnOpen(randomIOExceptionRateOnOpen);
w.setThrottling(throttle); w.setThrottling(throttle);
@ -139,11 +139,11 @@ public class MockFSDirectoryFactory implements IndexStorePlugin.DirectoryFactory
return new FsDirectoryFactory().newDirectory(newIndexSettings, path); return new FsDirectoryFactory().newDirectory(newIndexSettings, path);
} }
public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper { public static final class OpenSearchMockDirectoryWrapper extends MockDirectoryWrapper {
private final boolean crash; private final boolean crash;
public ElasticsearchMockDirectoryWrapper(Random random, Directory delegate, boolean crash) { public OpenSearchMockDirectoryWrapper(Random random, Directory delegate, boolean crash) {
super(random, delegate); super(random, delegate);
this.crash = crash; this.crash = crash;
} }