From 49cbf520a9f45ab5e975dfe0b7c9ff489a57c338 Mon Sep 17 00:00:00 2001 From: Andrey Pleskach Date: Fri, 7 Jul 2023 18:21:23 +0200 Subject: [PATCH] Remove commons-collections 3.2.2 (#2924) Signed-off-by: Andrey Pleskach --- build.gradle | 2 +- .../framework/log/LogCapturingAppender.java | 27 ++++----- .../resolver/IndexResolverReplacer.java | 60 ++++++++++++++++--- 3 files changed, 66 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index 6657f177f1..2339991416 100644 --- a/build.gradle +++ b/build.gradle @@ -533,7 +533,7 @@ dependencies { implementation "org.opensaml:opensaml-storage-api:${open_saml_version}" implementation "com.nulab-inc:zxcvbn:1.7.0" - implementation 'commons-collections:commons-collections:3.2.2' + implementation 'com.jayway.jsonpath:json-path:2.4.0' implementation 'net.minidev:json-smart:2.4.10' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.10.8' diff --git a/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java b/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java index 63765dfd14..5673f1bd3e 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java +++ b/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java @@ -9,18 +9,8 @@ */ package org.opensearch.test.framework.log; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import org.apache.commons.collections.Buffer; -import org.apache.commons.collections.BufferUtils; -import org.apache.commons.collections.buffer.CircularFifoBuffer; +import com.google.common.collect.EvictingQueue; +import com.google.common.collect.Queues; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Filter; @@ -32,6 +22,15 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Queue; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + import static org.opensearch.test.framework.log.LogCapturingAppender.PLUGIN_NAME; /** @@ -56,12 +55,12 @@ public class LogCapturingAppender extends AbstractAppender { /** * Buffer for captured log messages */ - private static final Buffer messages = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(MAX_SIZE)); + private static final Queue messages = Queues.synchronizedQueue(EvictingQueue.create(MAX_SIZE)); /** * Log messages are stored in buffer {@link #messages} only for classes which are added to the {@link #activeLoggers} set. */ - private static final Set activeLoggers = Collections.synchronizedSet(new HashSet<>()); + private static final Set activeLoggers = ConcurrentHashMap.newKeySet(); protected LogCapturingAppender( String name, diff --git a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java index dff4d4fcba..a907bdbe13 100644 --- a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java +++ b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java @@ -35,12 +35,12 @@ import java.util.List; import java.util.ListIterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.regex.PatternSyntaxException; import java.util.stream.Collectors; import com.google.common.collect.ImmutableSet; -import org.apache.commons.collections.keyvalue.MultiKey; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.greenrobot.eventbus.Subscribe; @@ -112,7 +112,7 @@ public IndexResolverReplacer(IndexNameExpressionResolver resolver, ClusterServic this.clusterInfoHolder = clusterInfoHolder; } - private static final boolean isAllWithNoRemote(final String... requestedPatterns) { + private static boolean isAllWithNoRemote(final String... requestedPatterns) { final List patterns = requestedPatterns == null ? null : Arrays.asList(requestedPatterns); @@ -131,11 +131,11 @@ private static final boolean isAllWithNoRemote(final String... requestedPatterns return false; } - private static final boolean isLocalAll(String... requestedPatterns) { + private static boolean isLocalAll(String... requestedPatterns) { return isLocalAll(requestedPatterns == null ? null : Arrays.asList(requestedPatterns)); } - private static final boolean isLocalAll(Collection patterns) { + private static boolean isLocalAll(Collection patterns) { if (IndexNameExpressionResolver.isAllIndices(patterns)) { return true; } @@ -158,9 +158,49 @@ private class ResolvedIndicesProvider implements IndicesProvider { private final ImmutableSet.Builder remoteIndices; // set of previously resolved index requests to avoid resolving // the same index more than once while processing bulk requests - private final Set alreadyResolved; + private final Set alreadyResolved; private final String name; + private final class AlreadyResolvedKey { + + private final IndicesOptions indicesOptions; + + private final boolean enableCrossClusterResolution; + + private final String[] original; + + private AlreadyResolvedKey(final IndicesOptions indicesOptions, final boolean enableCrossClusterResolution) { + this(indicesOptions, enableCrossClusterResolution, null); + } + + private AlreadyResolvedKey( + final IndicesOptions indicesOptions, + final boolean enableCrossClusterResolution, + final String[] original + ) { + this.indicesOptions = indicesOptions; + this.enableCrossClusterResolution = enableCrossClusterResolution; + this.original = original; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AlreadyResolvedKey that = (AlreadyResolvedKey) o; + return enableCrossClusterResolution == that.enableCrossClusterResolution + && Objects.equals(indicesOptions, that.indicesOptions) + && Arrays.equals(original, that.original); + } + + @Override + public int hashCode() { + int result = Objects.hash(indicesOptions, enableCrossClusterResolution); + result = 31 * result + Arrays.hashCode(original); + return result; + } + } + ResolvedIndicesProvider(Object request) { aliases = ImmutableSet.builder(); allIndices = ImmutableSet.builder(); @@ -336,9 +376,13 @@ public String[] provide(String[] original, Object localRequest, boolean supports || localRequest instanceof SearchRequest || localRequest instanceof ResolveIndexAction.Request; // skip the whole thing if we have seen this exact resolveIndexPatterns request - if (alreadyResolved.add( - new MultiKey(indicesOptions, enableCrossClusterResolution, (original != null) ? new MultiKey(original, false) : null) - )) { + final AlreadyResolvedKey alreadyResolvedKey; + if (original != null) { + alreadyResolvedKey = new AlreadyResolvedKey(indicesOptions, enableCrossClusterResolution, original); + } else { + alreadyResolvedKey = new AlreadyResolvedKey(indicesOptions, enableCrossClusterResolution); + } + if (alreadyResolved.add(alreadyResolvedKey)) { resolveIndexPatterns(localRequest.getClass().getSimpleName(), indicesOptions, enableCrossClusterResolution, original); } return IndicesProvider.NOOP;