Skip to content

Commit

Permalink
Replace and block usages of org.apache.logging.log4j.util.Strings (op…
Browse files Browse the repository at this point in the history
…ensearch-project#15238)

* Replace and block usages of org.apache.logging.log4j.util.Strings

Signed-off-by: Craig Perkins <[email protected]>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <[email protected]>

---------

Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks authored Aug 14, 2024
1 parent ef1a79f commit d74e276
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed
- Add lower limit for primary and replica batch allocators timeout ([#14979](https://github.com/opensearch-project/OpenSearch/pull/14979))
- Replace and block usages of org.apache.logging.log4j.util.Strings ([#15238](https://github.com/opensearch-project/OpenSearch/pull/15238))

### Deprecated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
java.nio.file.Paths @ Use org.opensearch.common.io.PathUtils.get() instead.
java.nio.file.FileSystems#getDefault() @ use org.opensearch.common.io.PathUtils.getDefaultFileSystem() instead.

joptsimple.internal.Strings @ use org.opensearch.core.common.Strings instead.
org.apache.logging.log4j.util.Strings @ use org.opensearch.core.common.Strings instead.

java.nio.file.Files#getFileStore(java.nio.file.Path) @ Use org.opensearch.env.Environment.getFileStore() instead, impacted by JDK-8034057
java.nio.file.Files#isWritable(java.nio.file.Path) @ Use org.opensearch.env.Environment.isWritable() instead, impacted by JDK-8034057

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.logging.log4j.core.pattern.ExtendedThrowablePatternConverter;
import org.apache.logging.log4j.core.pattern.PatternConverter;
import org.apache.logging.log4j.core.pattern.ThrowablePatternConverter;
import org.apache.logging.log4j.util.Strings;
import org.opensearch.core.common.Strings;

import java.nio.charset.Charset;
import java.util.StringJoiner;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static JsonThrowablePatternConverter newInstance(final Configuration conf
@Override
public void format(final LogEvent event, final StringBuilder toAppendTo) {
String consoleStacktrace = formatStacktrace(event);
if (Strings.isNotEmpty(consoleStacktrace)) {
if (!Strings.isNullOrEmpty(consoleStacktrace)) {
String jsonStacktrace = formatJson(consoleStacktrace);

toAppendTo.append(", ");
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/opensearch/env/NodeEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Strings;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.store.Directory;
Expand All @@ -61,6 +60,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.core.common.Strings;
import org.opensearch.core.common.unit.ByteSizeValue;
import org.opensearch.core.index.Index;
import org.opensearch.core.index.shard.ShardId;
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public static List<Path> collectFileCacheDataPath(NodePath fileCacheNodePath) th
* Resolve the custom path for a index's shard.
*/
public static Path resolveBaseCustomLocation(String customDataPath, Path sharedDataPath, int nodeLockId) {
if (Strings.isNotEmpty(customDataPath)) {
if (!Strings.isNullOrEmpty(customDataPath)) {
// This assert is because this should be caught by MetadataCreateIndexService
assert sharedDataPath != null;
return sharedDataPath.resolve(customDataPath).resolve(Integer.toString(nodeLockId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Strings;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.routing.remote.RemoteRoutingTableService;
import org.opensearch.cluster.service.ClusterApplierService;
Expand All @@ -23,6 +22,7 @@
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.AbstractAsyncTask;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.Strings;
import org.opensearch.index.translog.transfer.BlobStoreTransferService;
import org.opensearch.threadpool.ThreadPool;

Expand Down Expand Up @@ -125,8 +125,8 @@ void cleanUpStaleFiles() {
ClusterState currentAppliedState = clusterApplierService.state();
if (currentAppliedState.nodes().isLocalNodeElectedClusterManager()) {
long cleanUpAttemptStateVersion = currentAppliedState.version();
assert Strings.isNotEmpty(currentAppliedState.getClusterName().value()) : "cluster name is not set";
assert Strings.isNotEmpty(currentAppliedState.metadata().clusterUUID()) : "cluster uuid is not set";
assert !Strings.isNullOrEmpty(currentAppliedState.getClusterName().value()) : "cluster name is not set";
assert !Strings.isNullOrEmpty(currentAppliedState.metadata().clusterUUID()) : "cluster uuid is not set";
if (cleanUpAttemptStateVersion - lastCleanupAttemptStateVersion > SKIP_CLEANUP_STATE_CHANGES) {
logger.info(
"Cleaning up stale remote state files for cluster [{}] with uuid [{}]. Last clean was done before {} updates",
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/java/org/opensearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand All @@ -108,8 +109,6 @@
import java.util.function.Function;
import java.util.function.Supplier;

import static org.apache.logging.log4j.util.Strings.toRootUpperCase;

/**
* IndexModule represents the central extension point for index level custom implementations like:
* <ul>
Expand Down Expand Up @@ -580,7 +579,7 @@ public enum DataLocalityType {

public static DataLocalityType getValueOf(final String localityType) {
Objects.requireNonNull(localityType, "No locality type given.");
final String localityTypeName = toRootUpperCase(localityType.trim());
final String localityTypeName = localityType.trim().toUpperCase(Locale.ROOT);
final DataLocalityType type = LOCALITY_TYPES.get(localityTypeName);
if (type != null) {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
package org.opensearch.index.shard;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.annotation.PublicApi;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.core.common.Strings;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.env.NodeEnvironment;
Expand Down Expand Up @@ -205,7 +205,7 @@ public static ShardPath loadShardPath(
} else {
final Path dataPath;
final Path statePath = loadedPath;
final boolean hasCustomDataPath = Strings.isNotEmpty(customDataPath);
final boolean hasCustomDataPath = !Strings.isNullOrEmpty(customDataPath);
if (hasCustomDataPath) {
dataPath = NodeEnvironment.resolveCustomLocation(customDataPath, shardId, sharedDataPath, nodeLockId);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.client;

import joptsimple.internal.Strings;
import org.apache.hc.core5.http.Header;
import org.opensearch.test.OpenSearchTestCase;

Expand All @@ -55,7 +54,7 @@ public void assertHeaders(RestClient client, Map<String, String> expectedHeaders
assertEquals(expectedValue, header.getValue());
}
if (expectedHeaders.isEmpty() == false) {
fail("Missing expected headers in rest client: " + Strings.join(expectedHeaders.keySet(), ", "));
fail("Missing expected headers in rest client: " + String.join(",", expectedHeaders.keySet()));
}
}
}

0 comments on commit d74e276

Please sign in to comment.