[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;
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();

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
* <code>ESJsonLayout</code>
* <code>OpenSearchJsonLayout</code>
* The intention is to confirm that users can still run their OpenSearch instances with previous configurations.
*/
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.
*/
@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;

View File

@ -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".

View File

@ -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) {

View File

@ -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);

View File

@ -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 {

View File

@ -62,22 +62,22 @@ import java.util.stream.Stream;
* <p>
* 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>
* 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>
* the message passed to a logger will be overriden with a value from %ESMessageField{message}
* <p>
* 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)
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,
public static OpenSearchJsonLayout createLayout(String type,
Charset charset,
String[] esmessagefields) {
return new ESJsonLayout(type, charset, esmessagefields);
return new OpenSearchJsonLayout(type, charset, esmessagefields);
}
PatternLayout getPatternLayout() {
return patternLayout;
}
public static class Builder<B extends ESJsonLayout.Builder<B>> extends AbstractStringLayout.Builder<B>
implements org.apache.logging.log4j.core.util.Builder<ESJsonLayout> {
public static class Builder<B extends OpenSearchJsonLayout.Builder<B>> extends AbstractStringLayout.Builder<B>
implements org.apache.logging.log4j.core.util.Builder<OpenSearchJsonLayout> {
@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 extends ESJsonLayout.Builder<B>> B newBuilder() {
return new ESJsonLayout.Builder<B>().asBuilder();
public static <B extends OpenSearchJsonLayout.Builder<B>> B newBuilder() {
return new OpenSearchJsonLayout.Builder<B>().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();

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.
*/
@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;
/**
* This is an abstract class, so this is safe. The check is done on DeprecationMessage.
* 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);
this.fields = fields;
}
@ -61,7 +61,7 @@ public abstract class ESLogMessage extends ParameterizedMessage {
public static String asJsonArray(Stream<String> stream) {
return "[" + stream
.map(ESLogMessage::inQuotes)
.map(OpenSearchLogMessage::inQuotes)
.collect(Collectors.joining(", ")) + "]";
}

View File

@ -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 <code>ESLogMessage</code>.
* It will only populate these if the event have message of type <code>OpenSearchLogMessage</code>.
*/
@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);

View File

@ -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;

View File

@ -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() :

View File

@ -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;
}