Skip to content

Commit

Permalink
[Rename] remaining ES prefixed classes (#406)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nknize committed Mar 20, 2021
1 parent 88398d8 commit e71b191
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
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();
Expand All @@ -54,7 +54,7 @@ public void testLayout() {
}

public void testLayoutWithAdditionalFields() {
ESJsonLayout server = ESJsonLayout.newBuilder()
OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder()
.setType("server")
.setESMessageFields("x-opaque-id,someOtherField")
.build();
Expand All @@ -76,7 +76,7 @@ public void testLayoutWithAdditionalFields() {
}

public void testLayoutWithAdditionalFieldOverride() {
ESJsonLayout server = ESJsonLayout.newBuilder()
OpenSearchJsonLayout server = OpenSearchJsonLayout.newBuilder()
.setType("server")
.setESMessageFields("message")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/**
* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public DeprecationLoggerBuilder deprecate(final String key, final String msg, fi
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public HeaderWarningAppender(String name, Filter filter) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@
* <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();
}
Expand Down Expand Up @@ -146,18 +146,18 @@ private String inQuotes(String s) {
}

@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<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;
Expand All @@ -173,9 +173,9 @@ public Builder() {
}

@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() {
Expand Down Expand Up @@ -207,8 +207,8 @@ public B setESMessageFields(String esmessagefields) {
}

@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
Expand All @@ -228,7 +228,7 @@ public void encode(final LogEvent event, final ByteBufferDestination destination

@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
* 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;
}
Expand All @@ -61,7 +61,7 @@ public static String inQuotes(Object s) {

public static String asJsonArray(Stream<String> stream) {
return "[" + stream
.map(ESLogMessage::inQuotes)
.map(OpenSearchLogMessage::inQuotes)
.collect(Collectors.joining(", ")) + "]";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@

/**
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public void reset() {
}

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ public static ThreadFactory daemonThreadFactory(String nodeName, String namePref
}

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() :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
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;
Expand Down Expand Up @@ -114,7 +114,7 @@ private Directory wrap(Directory dir, Random random, Settings indexSettings, Sha
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);
Expand All @@ -139,11 +139,11 @@ private Directory randomDirectoryService(Random random, IndexSettings indexSetti
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;
}
Expand Down

0 comments on commit e71b191

Please sign in to comment.