From e3b5f985fda007e1f78c5f4f71eca2efcd4ca2c3 Mon Sep 17 00:00:00 2001 From: Andrey Pleskach Date: Sun, 2 Jul 2023 11:42:40 +0200 Subject: [PATCH] Remove commons-collections 3.2.2 Signed-off-by: Andrey Pleskach --- build.gradle | 1 - .../framework/log/LogCapturingAppender.java | 45 +++++++---------- .../resolver/IndexResolverReplacer.java | 48 ++++++++----------- 3 files changed, 36 insertions(+), 58 deletions(-) diff --git a/build.gradle b/build.gradle index c1302656c4..ef17087151 100644 --- a/build.gradle +++ b/build.gradle @@ -526,7 +526,6 @@ dependencies { runtimeOnly 'org.opensaml:opensaml-soap-impl:3.4.5' implementation 'org.opensaml:opensaml-storage-api:3.4.5' implementation 'commons-lang:commons-lang:2.4' - 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..2f7f4f2638 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java +++ b/src/integrationTest/java/org/opensearch/test/framework/log/LogCapturingAppender.java @@ -9,22 +9,10 @@ */ 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; -import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.Property; @@ -32,6 +20,14 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; +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,21 +52,15 @@ 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, - Filter filter, - Layout layout, - boolean ignoreExceptions, - Property[] properties - ) { - super(name, filter, layout, ignoreExceptions, properties); + protected LogCapturingAppender(String name) { + super(name, null, null, true, Property.EMPTY_ARRAY); } /** @@ -82,7 +72,7 @@ protected LogCapturingAppender( public static LogCapturingAppender createAppender( @PluginAttribute(value = "name", defaultString = "logCapturingAppender") String name ) { - return new LogCapturingAppender(name, null, null, true, Property.EMPTY_ARRAY); + return new LogCapturingAppender(name); } /** @@ -91,10 +81,7 @@ public static LogCapturingAppender createAppender( */ @Override public void append(LogEvent event) { - String loggerName = event.getLoggerName(); - boolean loggable = activeLoggers.contains(loggerName); - if (loggable) { - event.getThrown(); + if (activeLoggers.contains(event.getLoggerName())) { messages.add(new LogMessage(event.getMessage().getFormattedMessage(), event.getThrown())); } } diff --git a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java index dff4d4fcba..bb12055ca5 100644 --- a/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java +++ b/src/main/java/org/opensearch/security/resolver/IndexResolverReplacer.java @@ -40,7 +40,6 @@ 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; @@ -156,9 +155,7 @@ private class ResolvedIndicesProvider implements IndicesProvider { private final ImmutableSet.Builder allIndices; private final ImmutableSet.Builder originalRequested; 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 String name; ResolvedIndicesProvider(Object request) { @@ -166,7 +163,6 @@ private class ResolvedIndicesProvider implements IndicesProvider { allIndices = ImmutableSet.builder(); originalRequested = ImmutableSet.builder(); remoteIndices = ImmutableSet.builder(); - alreadyResolved = new HashSet<>(); name = request.getClass().getSimpleName(); } @@ -336,18 +332,18 @@ 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) - )) { - resolveIndexPatterns(localRequest.getClass().getSimpleName(), indicesOptions, enableCrossClusterResolution, original); - } + resolveIndexPatterns(localRequest.getClass().getSimpleName(), indicesOptions, enableCrossClusterResolution, original); return IndicesProvider.NOOP; } Resolved resolved(IndicesOptions indicesOptions) { - final Resolved resolved = alreadyResolved.isEmpty() - ? Resolved._LOCAL_ALL - : new Resolved(aliases.build(), allIndices.build(), originalRequested.build(), remoteIndices.build(), indicesOptions); + final Resolved resolved = new Resolved( + aliases.build(), + allIndices.build(), + originalRequested.build(), + remoteIndices.build(), + indicesOptions + ); if (log.isTraceEnabled()) { log.trace("Finally resolved for {}: {}", name, resolved); @@ -359,22 +355,18 @@ Resolved resolved(IndicesOptions indicesOptions) { // dnfof public boolean replace(final TransportRequest request, boolean retainMode, String... replacements) { - return getOrReplaceAllIndices(request, new IndicesProvider() { - - @Override - public String[] provide(String[] original, Object request, boolean supportsReplace) { - if (supportsReplace) { - if (retainMode && !isAllWithNoRemote(original)) { - final Resolved resolved = resolveRequest(request); - final List retained = WildcardMatcher.from(resolved.getAllIndices()) - .getMatchAny(replacements, Collectors.toList()); - retained.addAll(resolved.getRemoteIndices()); - return retained.toArray(new String[0]); - } - return replacements; - } else { - return NOOP; + return getOrReplaceAllIndices(request, (original, request1, supportsReplace) -> { + if (supportsReplace) { + if (retainMode && !isAllWithNoRemote(original)) { + final Resolved resolved = resolveRequest(request1); + final List retained = WildcardMatcher.from(resolved.getAllIndices()) + .getMatchAny(replacements, Collectors.toList()); + retained.addAll(resolved.getRemoteIndices()); + return retained.toArray(new String[0]); } + return replacements; + } else { + return IndicesProvider.NOOP; } }, false); }