Skip to content

Commit

Permalink
[Refactor] Various Utilities, Assertion, and Concurrency Exception fr…
Browse files Browse the repository at this point in the history
…om server to libraries (opensearch-project#6875) (opensearch-project#7612)

To further reduce the surface area of utility methods in :server: this commit refactors the
following:

 * MapBuilder from server module to common library
 * Assertions from server module to core library
 * BytesRef methods from CollectionUtils in server module to
   new BytesRefUtils in core library

It also removes CollectionUtils dependency on hppc in prep for
refactoring CollectionUtils methods to the proper library.

Signed-off-by: Nicholas Walter Knize <[email protected]>
(cherry picked from commit 0a20092)

Signed-off-by: bansvaru <[email protected]>
Co-authored-by: Nicholas Walter Knize  <[email protected]>
  • Loading branch information
linuxpi and nknize authored May 19, 2023
1 parent 151af91 commit 7a6996b
Show file tree
Hide file tree
Showing 275 changed files with 304 additions and 434 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.ingest.Pipeline;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

package org.opensearch.bootstrap;

import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.common.settings.KeyStoreCommandTestCase;
import org.opensearch.common.settings.KeyStoreWrapper;
import org.opensearch.common.settings.SecureSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.opensearch.cli.CommandTestCase;
import org.opensearch.common.io.PathUtilsForTesting;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.NIOFSDirectory;
import org.opensearch.common.Randomness;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.Environment;
import org.opensearch.test.OpenSearchTestCase;
import org.hamcrest.Matchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.hash.MessageDigests;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.Environment;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

package org.opensearch.plugins;

import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.cli.Command;
import org.opensearch.cli.LoggingAwareMultiCommand;
import org.opensearch.cli.Terminal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.opensearch.cli.ExitCodes;
import org.opensearch.cli.Terminal;
import org.opensearch.cli.UserException;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.Environment;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.opensearch.common.io.PathUtilsForTesting;
import org.opensearch.common.settings.KeyStoreWrapper;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.Environment;
import org.opensearch.env.TestEnvironment;

Expand Down
1 change: 0 additions & 1 deletion libs/cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ apply plugin: 'opensearch.publish'
dependencies {
api 'net.sf.jopt-simple:jopt-simple:5.0.4'
api project(':libs:opensearch-common')
api project(':libs:opensearch-core')
}

test.enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import joptsimple.util.KeyValuePair;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;

import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

package org.opensearch.core.internal.io;
package org.opensearch.common.util.io;

import org.opensearch.common.Nullable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

package org.opensearch.core.internal.io;
package org.opensearch.common.util.io;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* compatible open source license.
*/

/** Common internal I/O classes */
package org.opensearch.core.internal.io;
/** Common internal I/O utility classes */
package org.opensearch.common.util.io;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

package org.opensearch.core.internal.net;
package org.opensearch.common.util.net;

import java.io.IOException;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
*/

/** Common Network Utility Classes */
package org.opensearch.core.internal.net;
package org.opensearch.common.util.net;
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
* GitHub history for details.
*/

package org.opensearch;
package org.opensearch.core;

/**
* Provides a static final field that can be used to check if assertions are enabled. Since this field might be used elsewhere to check if
* assertions are enabled, if you are running with assertions enabled for specific packages or classes, you should enable assertions on this
* class too (e.g., {@code -ea org.opensearch.Assertions -ea org.opensearch.cluster.service.ClusterManagerService}).
* class too (e.g., {@code -ea org.opensearch.core.Assertions -ea org.opensearch.cluster.service.ClusterManagerService}).
*
* @opensearch.internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* GitHub history for details.
*/

package org.opensearch.common.util.concurrent;
package org.opensearch.core.concurrency;

import java.util.concurrent.RejectedExecutionException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/** Common internal core classes */
package org.opensearch.core.internal;
/** core concurrency package */
package org.opensearch.core.concurrency;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.lucene.util.Constants;
import org.opensearch.common.CheckedConsumer;
import org.opensearch.common.io.PathUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.test.OpenSearchTestCase;

import java.io.Closeable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.core.internal.io;

import org.opensearch.common.util.io.Streams;
import org.opensearch.test.OpenSearchTestCase;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
package org.opensearch.core.internal.net;

import org.apache.lucene.util.Constants;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.test.OpenSearchTestCase;

import java.lang.Runtime.Version;
Expand Down
1 change: 0 additions & 1 deletion libs/nio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.opensearch.gradle.info.BuildParams
apply plugin: 'opensearch.publish'

dependencies {
api project(':libs:opensearch-core')
api project(':libs:opensearch-common')

testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
package org.opensearch.nio;

import org.opensearch.common.concurrent.CompletableContext;
import org.opensearch.core.internal.net.NetUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.nio.utils.ByteBufferUtils;
import org.opensearch.nio.utils.ExceptionsHelper;

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

package org.opensearch.nio;

import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.test.OpenSearchTestCase;
import org.junit.After;
import org.junit.Before;
Expand Down
1 change: 0 additions & 1 deletion libs/ssl-config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ apply plugin: "opensearch.publish"

dependencies {
api project(':libs:opensearch-common')
api project(':libs:opensearch-core')

testImplementation(project(":test:framework")) {
exclude group: 'org.opensearch', module: 'opensearch-ssl-config'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.filtering.FilterPathBasedFilter;
import org.opensearch.core.internal.io.Streams;
import org.opensearch.common.util.io.Streams;

import java.io.BufferedInputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.opensearch.core.xcontent.XContentLocation;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.AbstractXContentParser;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;

import java.io.IOException;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.common.CheckedSupplier;
import org.opensearch.common.SetOnce;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;

import java.io.Closeable;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.opensearch.common.cache.CacheBuilder;
import org.opensearch.common.io.PathUtils;
import org.opensearch.common.settings.Setting;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.ingest.Processor;
import org.opensearch.plugins.IngestPlugin;
import org.opensearch.plugins.Plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.opensearch.common.io.PathUtils;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.common.xcontent.json.JsonXContent;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.painless.action.PainlessContextClassBindingInfo;
import org.opensearch.painless.action.PainlessContextClassInfo;
import org.opensearch.painless.action.PainlessContextConstructorInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.opensearch.Version;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.index.fielddata.IndexNumericFieldData;
import org.opensearch.index.fielddata.LeafNumericFieldData;
import org.opensearch.index.fielddata.SortedNumericDoubleValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.opensearch.common.ParsingException;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.core.xcontent.ConstructingObjectParser;
import org.opensearch.core.xcontent.ObjectParser;
import org.opensearch.core.xcontent.ObjectParser.ValueType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.AbstractRunnable;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.Index;
import org.opensearch.index.engine.VersionConflictEngineException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.search.SearchHit;
import org.opensearch.search.SearchHits;
import org.opensearch.search.internal.InternalSearchResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.opensearch.common.bytes.BytesArray;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.http.HttpInfo;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.plugins.Plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
package org.opensearch.index.reindex.remote;

import org.opensearch.action.search.ShardSearchFailure;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException;
import org.opensearch.core.concurrency.OpenSearchRejectedExecutionException;
import org.opensearch.index.reindex.RejectAwareActionListener;
import org.opensearch.index.reindex.ScrollableHitSource;
import org.opensearch.index.reindex.ScrollableHitSource.Response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
import org.opensearch.common.util.BigArrays;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.core.internal.net.NetUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.http.AbstractHttpServerTransport;
import org.opensearch.http.HttpChannel;
import org.opensearch.http.HttpHandlingSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import org.opensearch.common.unit.ByteSizeValue;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
import org.opensearch.core.internal.net.NetUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.indices.breaker.CircuitBreakerService;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.Netty4NioSocketChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.common.util.PageCacheRecycler;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.core.internal.net.NetUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.common.util.net.NetUtils;
import org.opensearch.indices.breaker.NoneCircuitBreakerService;
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.test.transport.StubbableTransport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.logging.log4j.Logger;
import org.opensearch.common.SuppressForbidden;
import org.opensearch.common.network.NetworkService.CustomNameResolver;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.opensearch.common.network.NetworkService;
import org.opensearch.common.settings.MockSecureSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.transport.MockTransportService;
import org.opensearch.threadpool.TestThreadPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.opensearch.common.network.NetworkService;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.internal.io.IOUtils;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.discovery.SeedHostsProvider;
import org.opensearch.discovery.gce.GceSeedHostsProvider;
import org.opensearch.plugins.DiscoveryPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private void writeBlobResumable(BlobInfo blobInfo, InputStream inputStream, long
* It is not enough to wrap the call to Streams#copy, we have to wrap the privileged calls too; this is because Streams#copy
* is in the stacktrace and is not granted the permissions needed to close and write the channel.
*/
org.opensearch.core.internal.io.Streams.copy(inputStream, Channels.newOutputStream(new WritableByteChannel() {
org.opensearch.common.util.io.Streams.copy(inputStream, Channels.newOutputStream(new WritableByteChannel() {

@SuppressForbidden(reason = "channel is based on a socket")
@Override
Expand Down
Loading

0 comments on commit 7a6996b

Please sign in to comment.