diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index c9af8083d5d3c..eaf4d085c6946 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -105,7 +105,7 @@ jobs: echo Adding bwc version $NEXT_VERSION after $CURRENT_VERSION sed -i "s/- \"$CURRENT_VERSION\"/\0\n - \"$NEXT_VERSION\"/g" .ci/bwcVersions echo Adding $NEXT_VERSION_UNDERSCORE after $CURRENT_VERSION_UNDERSCORE - sed -i "s/public static final Version $CURRENT_VERSION_UNDERSCORE = new Version(\([[:digit:]]\+\)\(.*\));/\0\n public static final Version $NEXT_VERSION_UNDERSCORE = new Version($NEXT_VERSION_ID\2);/g" server/src/main/java/org/opensearch/Version.java + sed -i "s/public static final Version $CURRENT_VERSION_UNDERSCORE = new Version(\([[:digit:]]\+\)\(.*\));/\0\n public static final Version $NEXT_VERSION_UNDERSCORE = new Version($NEXT_VERSION_ID\2);/g" libs/core/src/main/java/org/opensearch/Version.java - name: Create Pull Request uses: peter-evans/create-pull-request@v3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 435167f534bd0..7598a634e1d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Add self-organizing hash table to improve the performance of bucket aggregations ([#7652](https://github.com/opensearch-project/OpenSearch/pull/7652)) - Check UTF16 string size before converting to String to avoid OOME ([#7963](https://github.com/opensearch-project/OpenSearch/pull/7963)) - [Refactor] remaining ImmutableOpenMap usage to j.u.Map and remove class ([#7309](https://github.com/opensearch-project/OpenSearch/pull/7309)) +- [Refactor] Version and LegacyESVersion from server module to core lib ([#7328](https://github.com/opensearch-project/OpenSearch/pull/7328)) - Move ZSTD compression codecs out of the sandbox ([#7908](https://github.com/opensearch-project/OpenSearch/pull/7908)) ### Deprecated diff --git a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java index 7708e4583ed7a..bde7e916013cd 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java @@ -74,8 +74,8 @@ public class GlobalBuildInfoPlugin implements Plugin { private static final Logger LOGGER = Logging.getLogger(GlobalBuildInfoPlugin.class); - private static final String DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/LegacyESVersion.java"; - private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/Version.java"; + private static final String DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH = "libs/core/src/main/java/org/opensearch/LegacyESVersion.java"; + private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "libs/core/src/main/java/org/opensearch/Version.java"; private static Integer _defaultParallel = null; private final JvmMetadataDetector jvmMetadataDetector; @@ -152,7 +152,7 @@ private static BwcVersions resolveBwcVersions(File root) { versionLines.addAll(IOUtils.readLines(fis2, "UTF-8")); return new BwcVersions(versionLines); } catch (IOException e) { - throw new IllegalStateException("Unable to resolve to resolve bwc versions from versionsFile.", e); + throw new IllegalStateException("Unable to resolve bwc versions from versionsFile.", e); } } diff --git a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java b/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java index a5afe85152cc6..02d9809d6906e 100644 --- a/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java +++ b/distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java @@ -63,7 +63,7 @@ import org.opensearch.common.SuppressForbidden; import org.opensearch.common.collect.Tuple; import org.opensearch.common.hash.MessageDigests; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.PathUtils; import org.opensearch.common.io.PathUtilsForTesting; import org.opensearch.common.settings.Settings; diff --git a/libs/core/build.gradle b/libs/core/build.gradle index 63f268d769273..e2e2c6f0bb345 100644 --- a/libs/core/build.gradle +++ b/libs/core/build.gradle @@ -81,6 +81,9 @@ dependencies { // lucene api "org.apache.lucene:lucene-core:${versions.lucene}" + // logging + api "org.apache.logging.log4j:log4j-api:${versions.log4j}" + testImplementation "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}" testImplementation "junit:junit:${versions.junit}" testImplementation "org.hamcrest:hamcrest:${versions.hamcrest}" @@ -96,6 +99,19 @@ tasks.named('forbiddenApisMain').configure { replaceSignatureFiles 'jdk-signatures' } +tasks.named("thirdPartyAudit").configure { + ignoreMissingClasses( + // from log4j + 'org.osgi.framework.Bundle', + 'org.osgi.framework.BundleActivator', + 'org.osgi.framework.BundleContext', + 'org.osgi.framework.BundleEvent', + 'org.osgi.framework.SynchronousBundleListener', + 'org.osgi.framework.wiring.BundleWire', + 'org.osgi.framework.wiring.BundleWiring' + ) +} + tasks.named("dependencyLicenses").configure { mapping from: /jackson-.*/, to: 'jackson' mapping from: /lucene-.*/, to: 'lucene' diff --git a/libs/core/licenses/log4j-api-2.17.1.jar.sha1 b/libs/core/licenses/log4j-api-2.17.1.jar.sha1 new file mode 100644 index 0000000000000..9d0e5dc631ed5 --- /dev/null +++ b/libs/core/licenses/log4j-api-2.17.1.jar.sha1 @@ -0,0 +1 @@ +d771af8e336e372fb5399c99edabe0919aeaf5b2 \ No newline at end of file diff --git a/libs/core/licenses/log4j-api-LICENSE.txt b/libs/core/licenses/log4j-api-LICENSE.txt new file mode 100644 index 0000000000000..6279e5206de13 --- /dev/null +++ b/libs/core/licenses/log4j-api-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 1999-2005 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/libs/core/licenses/log4j-api-NOTICE.txt b/libs/core/licenses/log4j-api-NOTICE.txt new file mode 100644 index 0000000000000..0375732360047 --- /dev/null +++ b/libs/core/licenses/log4j-api-NOTICE.txt @@ -0,0 +1,5 @@ +Apache log4j +Copyright 2007 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file diff --git a/server/src/main/java/org/opensearch/Build.java b/libs/core/src/main/java/org/opensearch/Build.java similarity index 77% rename from server/src/main/java/org/opensearch/Build.java rename to libs/core/src/main/java/org/opensearch/Build.java index 364b17ad4aa33..8c9d2424c72de 100644 --- a/server/src/main/java/org/opensearch/Build.java +++ b/libs/core/src/main/java/org/opensearch/Build.java @@ -33,9 +33,7 @@ package org.opensearch; import org.opensearch.common.Booleans; -import org.opensearch.common.io.FileSystemUtils; -import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.core.util.FileSystemUtils; import java.io.IOException; import java.net.URL; @@ -206,61 +204,6 @@ public String date() { return date; } - public static Build readBuild(StreamInput in) throws IOException { - final String distribution; - final Type type; - // the following is new for opensearch: we write the distribution to support any "forks" - if (in.getVersion().onOrAfter(Version.V_1_0_0)) { - distribution = in.readString(); - } else { - distribution = "other"; - } - - // The following block is kept for existing BWS tests to pass. - // TODO - clean up this code when we remove all v6 bwc tests. - // TODO - clean this up when OSS flavor is removed in all of the code base - // (Integ test zip still write OSS as distribution) - // See issue: https://github.com/opendistro-for-elasticsearch/search/issues/159 - if (in.getVersion().before(Version.V_1_3_0)) { - String flavor = in.readString(); - } - // be lenient when reading on the wire, the enumeration values from other versions might be different than what we know - type = Type.fromDisplayName(in.readString(), false); - String hash = in.readString(); - String date = in.readString(); - boolean snapshot = in.readBoolean(); - - final String version; - if (in.getVersion().onOrAfter(LegacyESVersion.V_7_0_0)) { - version = in.readString(); - } else { - version = in.getVersion().toString(); - } - return new Build(type, hash, date, snapshot, version, distribution); - } - - public static void writeBuild(Build build, StreamOutput out) throws IOException { - // the following is new for opensearch: we write the distribution name to support any "forks" of the code - if (out.getVersion().onOrAfter(Version.V_1_0_0)) { - out.writeString(build.distribution); - } - - // The following block is kept for existing BWS tests to pass. - // TODO - clean up this code when we remove all v6 bwc tests. - // TODO - clean this up when OSS flavor is removed in all of the code base - if (out.getVersion().before(Version.V_1_3_0)) { - out.writeString("oss"); - } - final Type buildType = build.type(); - out.writeString(buildType.displayName()); - out.writeString(build.hash()); - out.writeString(build.date()); - out.writeBoolean(build.isSnapshot()); - if (out.getVersion().onOrAfter(LegacyESVersion.V_7_0_0)) { - out.writeString(build.getQualifiedVersion()); - } - } - /** * Get the distribution name (expected to be OpenSearch; empty if legacy; something else if forked) * @return distribution name as a string diff --git a/server/src/main/java/org/opensearch/LegacyESVersion.java b/libs/core/src/main/java/org/opensearch/LegacyESVersion.java similarity index 99% rename from server/src/main/java/org/opensearch/LegacyESVersion.java rename to libs/core/src/main/java/org/opensearch/LegacyESVersion.java index e74eaeae234d4..dafd071ef935a 100644 --- a/server/src/main/java/org/opensearch/LegacyESVersion.java +++ b/libs/core/src/main/java/org/opensearch/LegacyESVersion.java @@ -32,7 +32,6 @@ package org.opensearch; -import org.opensearch.common.Strings; import org.opensearch.core.Assertions; import java.lang.reflect.Field; @@ -176,7 +175,7 @@ public boolean isAlpha() { * Returns the version given its string representation, current version if the argument is null or empty */ public static Version fromString(String version) { - if (!Strings.hasLength(version)) { + if (stringHasLength(version) == false) { return Version.CURRENT; } final Version cached = stringToVersion.get(version); diff --git a/server/src/main/java/org/opensearch/Version.java b/libs/core/src/main/java/org/opensearch/Version.java similarity index 94% rename from server/src/main/java/org/opensearch/Version.java rename to libs/core/src/main/java/org/opensearch/Version.java index cd120237eda61..7dbd30c567b95 100644 --- a/server/src/main/java/org/opensearch/Version.java +++ b/libs/core/src/main/java/org/opensearch/Version.java @@ -32,15 +32,9 @@ package org.opensearch; -import org.opensearch.cluster.metadata.IndexMetadata; -import org.opensearch.common.Strings; import org.opensearch.common.SuppressForbidden; -import org.opensearch.common.io.stream.StreamInput; -import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.settings.Settings; import org.opensearch.core.xcontent.ToXContentFragment; import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.monitor.jvm.JvmInfo; import java.io.IOException; import java.lang.reflect.Field; @@ -120,10 +114,6 @@ public class Version implements Comparable, ToXContentFragment { public static final Version V_2_9_0 = new Version(2090099, org.apache.lucene.util.Version.LUCENE_9_7_0); public static final Version CURRENT = V_2_9_0; - public static Version readVersion(StreamInput in) throws IOException { - return fromId(in.readVInt()); - } - public static Version fromId(int id) { final Version known = LegacyESVersion.idToVersion.get(id); if (known != null) { @@ -160,30 +150,6 @@ private static Version fromIdSlow(int id) { return id < MASK ? new LegacyESVersion(id, luceneVersion) : new Version(id ^ MASK, luceneVersion); } - /** - * Return the {@link Version} of OpenSearch that has been used to create an index given its settings. - * - * @throws IllegalStateException if the given index settings doesn't contain a value for the key - * {@value IndexMetadata#SETTING_VERSION_CREATED} - */ - public static Version indexCreated(Settings indexSettings) { - final Version indexVersion = IndexMetadata.SETTING_INDEX_VERSION_CREATED.get(indexSettings); - if (indexVersion.equals(V_EMPTY)) { - final String message = String.format( - Locale.ROOT, - "[%s] is not present in the index settings for index with UUID [%s]", - IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), - indexSettings.get(IndexMetadata.SETTING_INDEX_UUID) - ); - throw new IllegalStateException(message); - } - return indexVersion; - } - - public static void writeVersion(Version version, StreamOutput out) throws IOException { - out.writeVInt(version.id); - } - public static int computeLegacyID(int major, int minor, int revision, int build) { return major * 1000000 + minor * 10000 + revision * 100 + build; } @@ -210,7 +176,7 @@ public static Version max(Version version1, Version version2) { * Returns the version given its string representation, current version if the argument is null or empty */ public static Version fromString(String version) { - if (!Strings.hasLength(version)) { + if (stringHasLength(version) == false) { // TODO replace with Strings.hasLength after refactoring Strings to core lib return Version.CURRENT; } final Version cached = LegacyESVersion.stringToVersion.get(version); @@ -473,7 +439,7 @@ public static void main(String[] args) { Build.CURRENT.type().displayName(), Build.CURRENT.hash(), Build.CURRENT.date(), - JvmInfo.jvmInfo().version() + System.getProperty("java.version") // TODO switch back to JvmInfo.jvmInfo().version() after refactoring to core lib ); System.out.println(versionOutput); } @@ -570,4 +536,12 @@ public static List getDeclaredVersions(final Class versionClass) { Collections.sort(versions); return versions; } + + /** + * Check that the given String is neither null nor of length 0. + * Note: Will return true for a String that purely consists of whitespace. + */ + public static boolean stringHasLength(String str) { + return (str != null && str.length() > 0); + } } diff --git a/server/src/main/java/org/opensearch/common/io/FileSystemUtils.java b/libs/core/src/main/java/org/opensearch/core/util/FileSystemUtils.java similarity index 98% rename from server/src/main/java/org/opensearch/common/io/FileSystemUtils.java rename to libs/core/src/main/java/org/opensearch/core/util/FileSystemUtils.java index 383393d15b7de..d742e8584fa8b 100644 --- a/server/src/main/java/org/opensearch/common/io/FileSystemUtils.java +++ b/libs/core/src/main/java/org/opensearch/core/util/FileSystemUtils.java @@ -30,12 +30,11 @@ * GitHub history for details. */ -package org.opensearch.common.io; +package org.opensearch.core.util; import org.apache.logging.log4j.Logger; import org.apache.lucene.util.Constants; import org.opensearch.common.util.io.IOUtils; -import org.opensearch.common.Strings; import org.opensearch.common.SuppressForbidden; import java.io.IOException; @@ -151,7 +150,7 @@ public static InputStream openFileURLStream(URL url) throws IOException { if ("file".equals(protocol) == false && "jar".equals(protocol) == false) { throw new IllegalArgumentException("Invalid protocol [" + protocol + "], must be [file] or [jar]"); } - if (Strings.isEmpty(url.getHost()) == false) { + if (url.getHost().isEmpty() == false) { throw new IllegalArgumentException("URL cannot have host. Found: [" + url.getHost() + ']'); } if (url.getPort() != -1) { diff --git a/server/src/test/java/org/opensearch/common/io/FileSystemUtilsTests.java b/libs/core/src/test/java/org/opensearch/core/util/FileSystemUtilsTests.java similarity index 98% rename from server/src/test/java/org/opensearch/common/io/FileSystemUtilsTests.java rename to libs/core/src/test/java/org/opensearch/core/util/FileSystemUtilsTests.java index bb0a1c486a30c..a26ce634187f5 100644 --- a/server/src/test/java/org/opensearch/common/io/FileSystemUtilsTests.java +++ b/libs/core/src/test/java/org/opensearch/core/util/FileSystemUtilsTests.java @@ -30,10 +30,11 @@ * GitHub history for details. */ -package org.opensearch.common.io; +package org.opensearch.core.util; import org.apache.lucene.util.Constants; import org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems; +import org.opensearch.common.io.PathUtils; import org.opensearch.test.OpenSearchTestCase; import org.junit.Before; diff --git a/modules/reindex/src/test/java/org/opensearch/index/reindex/remote/RemoteScrollableHitSourceTests.java b/modules/reindex/src/test/java/org/opensearch/index/reindex/remote/RemoteScrollableHitSourceTests.java index 96b350c377e87..a330208da1686 100644 --- a/modules/reindex/src/test/java/org/opensearch/index/reindex/remote/RemoteScrollableHitSourceTests.java +++ b/modules/reindex/src/test/java/org/opensearch/index/reindex/remote/RemoteScrollableHitSourceTests.java @@ -59,7 +59,7 @@ import org.opensearch.client.RestClient; import org.opensearch.common.ParsingException; import org.opensearch.common.bytes.BytesArray; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.Streams; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.common.unit.ByteSizeValue; diff --git a/plugins/discovery-azure-classic/src/internalClusterTest/java/org/opensearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java b/plugins/discovery-azure-classic/src/internalClusterTest/java/org/opensearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java index 570aa98cd9f55..2615460c53602 100644 --- a/plugins/discovery-azure-classic/src/internalClusterTest/java/org/opensearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java +++ b/plugins/discovery-azure-classic/src/internalClusterTest/java/org/opensearch/discovery/azure/classic/AzureDiscoveryClusterFormationTests.java @@ -40,7 +40,7 @@ import org.apache.logging.log4j.LogManager; import org.opensearch.cloud.azure.classic.management.AzureComputeService; import org.opensearch.common.SuppressForbidden; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.discovery.DiscoveryModule; diff --git a/plugins/discovery-gce/src/test/java/org/opensearch/discovery/gce/GceMockUtils.java b/plugins/discovery-gce/src/test/java/org/opensearch/discovery/gce/GceMockUtils.java index 5109600be7488..24790aa4a900d 100644 --- a/plugins/discovery-gce/src/test/java/org/opensearch/discovery/gce/GceMockUtils.java +++ b/plugins/discovery-gce/src/test/java/org/opensearch/discovery/gce/GceMockUtils.java @@ -42,7 +42,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.common.Strings; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.Streams; import java.io.IOException; diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java index b0aeb786b0268..e9260e36e50d3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java @@ -58,7 +58,7 @@ import org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.Allocation; import org.opensearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; import org.opensearch.common.Priority; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.io.IOUtils; diff --git a/server/src/internalClusterTest/java/org/opensearch/remotestore/AbstractRemoteStoreMockRepositoryIntegTestCase.java b/server/src/internalClusterTest/java/org/opensearch/remotestore/AbstractRemoteStoreMockRepositoryIntegTestCase.java index b2dc728d27889..f57c312aa2cd0 100644 --- a/server/src/internalClusterTest/java/org/opensearch/remotestore/AbstractRemoteStoreMockRepositoryIntegTestCase.java +++ b/server/src/internalClusterTest/java/org/opensearch/remotestore/AbstractRemoteStoreMockRepositoryIntegTestCase.java @@ -12,9 +12,9 @@ import org.opensearch.action.index.IndexResponse; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.UUIDs; -import org.opensearch.common.io.FileSystemUtils; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.FeatureFlags; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.index.IndexModule; import org.opensearch.index.IndexSettings; import org.opensearch.index.store.RemoteSegmentStoreDirectory; diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/RepositoriesIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/RepositoriesIT.java index 47fd106ff5a8f..f6df7cccf96f7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/RepositoriesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/RepositoriesIT.java @@ -42,7 +42,7 @@ import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.metadata.RepositoriesMetadata; import org.opensearch.cluster.metadata.RepositoryMetadata; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; import org.opensearch.repositories.RepositoriesService; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/node/info/NodeInfo.java b/server/src/main/java/org/opensearch/action/admin/cluster/node/info/NodeInfo.java index 4e93b5d784558..3d5aa58e1ab79 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/node/info/NodeInfo.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/node/info/NodeInfo.java @@ -82,8 +82,8 @@ public class NodeInfo extends BaseNodeResponse { public NodeInfo(StreamInput in) throws IOException { super(in); - version = Version.readVersion(in); - build = Build.readBuild(in); + version = in.readVersion(); + build = in.readBuild(); if (in.readBoolean()) { totalIndexingBuffer = new ByteSizeValue(in.readLong()); } else { @@ -209,7 +209,7 @@ public void writeTo(StreamOutput out) throws IOException { } else { out.writeVInt(version.id); } - Build.writeBuild(build, out); + out.writeBuild(build); if (totalIndexingBuffer == null) { out.writeBoolean(false); } else { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/ShardUpgradeResult.java b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/ShardUpgradeResult.java index 4eea1f01742bd..1f251f2d8cda4 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/ShardUpgradeResult.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/ShardUpgradeResult.java @@ -66,7 +66,7 @@ class ShardUpgradeResult implements Writeable { ShardUpgradeResult(StreamInput in) throws IOException { shardId = new ShardId(in); primary = in.readBoolean(); - upgradeVersion = Version.readVersion(in); + upgradeVersion = in.readVersion(); try { oldestLuceneSegment = org.apache.lucene.util.Version.parse(in.readString()); } catch (ParseException ex) { @@ -94,7 +94,7 @@ public boolean primary() { public void writeTo(StreamOutput out) throws IOException { shardId.writeTo(out); out.writeBoolean(primary); - Version.writeVersion(upgradeVersion, out); + out.writeVersion(upgradeVersion); out.writeString(oldestLuceneSegment.toString()); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeResponse.java b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeResponse.java index 68f8552ed9e5e..b763c893f9bdf 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeResponse.java @@ -55,7 +55,7 @@ public class UpgradeResponse extends BroadcastResponse { UpgradeResponse(StreamInput in) throws IOException { super(in); - versions = in.readMap(StreamInput::readString, i -> Tuple.tuple(Version.readVersion(i), i.readString())); + versions = in.readMap(StreamInput::readString, i -> Tuple.tuple(i.readVersion(), i.readString())); } UpgradeResponse( @@ -73,7 +73,7 @@ public class UpgradeResponse extends BroadcastResponse { public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeMap(versions, StreamOutput::writeString, (o, v) -> { - Version.writeVersion(v.v1(), o); + o.writeVersion(v.v1()); o.writeString(v.v2()); }); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeSettingsRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeSettingsRequest.java index d6b784e44befb..618c2114babc3 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeSettingsRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/upgrade/post/UpgradeSettingsRequest.java @@ -55,7 +55,7 @@ public class UpgradeSettingsRequest extends AcknowledgedRequest new Tuple<>(Version.readVersion(i), i.readString())); + versions = in.readMap(StreamInput::readString, i -> new Tuple<>(i.readVersion(), i.readString())); } public UpgradeSettingsRequest() {} @@ -94,7 +94,7 @@ public UpgradeSettingsRequest versions(Map> versi public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeMap(versions, StreamOutput::writeString, (o, v) -> { - Version.writeVersion(v.v1(), out); + out.writeVersion(v.v1()); out.writeString(v.v2()); }); } diff --git a/server/src/main/java/org/opensearch/action/main/MainResponse.java b/server/src/main/java/org/opensearch/action/main/MainResponse.java index 9871d0db8ebfa..9e6a374ee0658 100644 --- a/server/src/main/java/org/opensearch/action/main/MainResponse.java +++ b/server/src/main/java/org/opensearch/action/main/MainResponse.java @@ -68,10 +68,10 @@ public class MainResponse extends ActionResponse implements ToXContentObject { MainResponse(StreamInput in) throws IOException { super(in); nodeName = in.readString(); - version = Version.readVersion(in); + version = in.readVersion(); clusterName = new ClusterName(in); clusterUuid = in.readString(); - build = Build.readBuild(in); + build = in.readBuild(); if (in.getVersion().before(LegacyESVersion.V_7_0_0)) { in.readBoolean(); } @@ -124,13 +124,13 @@ public String getVersionNumber() { public void writeTo(StreamOutput out) throws IOException { out.writeString(nodeName); if (out.getVersion().before(Version.V_1_0_0)) { - Version.writeVersion(LegacyESVersion.V_7_10_2, out); + out.writeVersion(LegacyESVersion.V_7_10_2); } else { - Version.writeVersion(version, out); + out.writeVersion(version); } clusterName.writeTo(out); out.writeString(clusterUuid); - Build.writeBuild(build, out); + out.writeBuild(build); if (out.getVersion().before(LegacyESVersion.V_7_0_0)) { out.writeBoolean(true); } diff --git a/server/src/main/java/org/opensearch/action/search/SearchContextId.java b/server/src/main/java/org/opensearch/action/search/SearchContextId.java index 8a9cf1dc9772d..d54f3039395fe 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchContextId.java +++ b/server/src/main/java/org/opensearch/action/search/SearchContextId.java @@ -90,7 +90,7 @@ public static String encode(List searchPhaseResults, Map k.writeTo(o), (o, v) -> v.writeTo(o)); out.writeMap(aliasFilter, StreamOutput::writeString, (o, v) -> v.writeTo(o)); return Base64.getUrlEncoder().encodeToString(BytesReference.toBytes(out.bytes())); @@ -107,7 +107,7 @@ public static SearchContextId decode(NamedWriteableRegistry namedWriteableRegist throw new IllegalArgumentException("invalid id: [" + id + "]", e); } try (StreamInput in = new NamedWriteableAwareStreamInput(new ByteBufferStreamInput(byteBuffer), namedWriteableRegistry)) { - final Version version = Version.readVersion(in); + final Version version = in.readVersion(); in.setVersion(version); final Map shards = in.readMap(ShardId::new, SearchContextIdForNode::new); final Map aliasFilters = in.readMap(StreamInput::readString, AliasFilter::new); diff --git a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java index f7ddf0f943441..87287359b6e4c 100644 --- a/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/opensearch/cluster/SnapshotsInProgress.java @@ -308,7 +308,7 @@ private Entry(StreamInput in) throws IOException { userMetadata = null; } if (in.getVersion().onOrAfter(VERSION_IN_SNAPSHOT_VERSION)) { - version = Version.readVersion(in); + version = in.readVersion(); } else if (in.getVersion().onOrAfter(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) { // If an older cluster-manager informs us that shard generations are supported // we use the minimum shard generation compatible version. @@ -764,7 +764,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeMap(userMetadata); } if (out.getVersion().onOrAfter(VERSION_IN_SNAPSHOT_VERSION)) { - Version.writeVersion(version, out); + out.writeVersion(version); } else if (out.getVersion().onOrAfter(SnapshotsService.SHARD_GEN_IN_REPO_DATA_VERSION)) { out.writeBoolean(SnapshotsService.useShardGenerations(version)); } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index 6ce30eeae4fcc..45228b6644c7c 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -1561,7 +1561,7 @@ public IndexMetadata build() { } else { initialRecoveryFilters = DiscoveryNodeFilters.buildOrUpdateFromKeyValue(null, OR, initialRecoveryMap); } - Version indexCreatedVersion = Version.indexCreated(settings); + Version indexCreatedVersion = indexCreated(settings); Version indexUpgradedVersion = settings.getAsVersion(IndexMetadata.SETTING_VERSION_UPGRADED, indexCreatedVersion); if (primaryTerms == null) { @@ -1859,11 +1859,11 @@ public static IndexMetadata fromXContent(XContentParser parser) throws IOExcepti // Reference: // https://github.com/opensearch-project/OpenSearch/blob/4dde0f2a3b445b2fc61dab29c5a2178967f4a3e3/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java#L1620-L1628 Version legacyVersion = LegacyESVersion.fromId(6050099); - if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(legacyVersion)) { + if (Assertions.ENABLED && indexCreated(builder.settings).onOrAfter(legacyVersion)) { assert mappingVersion : "mapping version should be present for indices"; assert settingsVersion : "settings version should be present for indices"; } - if (Assertions.ENABLED && Version.indexCreated(builder.settings).onOrAfter(LegacyESVersion.V_7_2_0)) { + if (Assertions.ENABLED && indexCreated(builder.settings).onOrAfter(LegacyESVersion.V_7_2_0)) { assert aliasesVersion : "aliases version should be present for indices created on or after 7.2.0"; } return builder.build(); @@ -1900,10 +1900,29 @@ public static Settings addHumanReadableSettings(Settings settings) { FORMAT_PARAMS = new MapParams(params); } + /** + * Return the version the index was created from the provided index settings + * + * This looks for the presence of the {@link Version} object with key {@link IndexMetadata#SETTING_VERSION_CREATED} + */ + public static Version indexCreated(final Settings indexSettings) { + final Version indexVersion = SETTING_INDEX_VERSION_CREATED.get(indexSettings); + if (indexVersion.equals(Version.V_EMPTY)) { + final String message = String.format( + Locale.ROOT, + "[%s] is not present in the index settings for index with UUID [%s]", + SETTING_INDEX_VERSION_CREATED.getKey(), + indexSettings.get(IndexMetadata.SETTING_INDEX_UUID) + ); + throw new IllegalStateException(message); + } + return indexVersion; + } + /** * State format for {@link IndexMetadata} to write to and load from disk */ - public static final MetadataStateFormat FORMAT = new MetadataStateFormat(INDEX_STATE_FILE_PREFIX) { + public static final MetadataStateFormat FORMAT = new MetadataStateFormat<>(INDEX_STATE_FILE_PREFIX) { @Override public void toXContent(XContentBuilder builder, IndexMetadata state) throws IOException { diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java index 7e1c072c352af..50b91fc45458e 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java @@ -371,7 +371,7 @@ public DiscoveryNode(StreamInput in) throws IOException { } } this.roles = Collections.unmodifiableSortedSet(new TreeSet<>(roles)); - this.version = Version.readVersion(in); + this.version = in.readVersion(); } @Override @@ -414,9 +414,9 @@ public void writeTo(StreamOutput out) throws IOException { } } if (out.getVersion().before(Version.V_1_0_0) && version.onOrAfter(Version.V_1_0_0)) { - Version.writeVersion(LegacyESVersion.V_7_10_2, out); + out.writeVersion(LegacyESVersion.V_7_10_2); } else { - Version.writeVersion(version, out); + out.writeVersion(version); } } diff --git a/server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java b/server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java index f3682c7c5a9b6..3940485b40713 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java +++ b/server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java @@ -287,7 +287,7 @@ public SnapshotRecoverySource( SnapshotRecoverySource(StreamInput in) throws IOException { restoreUUID = in.readString(); snapshot = new Snapshot(in); - version = Version.readVersion(in); + version = in.readVersion(); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { index = new IndexId(in); } else { @@ -345,7 +345,7 @@ public boolean remoteStoreIndexShallowCopy() { protected void writeAdditionalFields(StreamOutput out) throws IOException { out.writeString(restoreUUID); snapshot.writeTo(out); - Version.writeVersion(version, out); + out.writeVersion(version); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { index.writeTo(out); } else { @@ -437,7 +437,7 @@ public RemoteStoreRecoverySource(String restoreUUID, Version version, IndexId in RemoteStoreRecoverySource(StreamInput in) throws IOException { restoreUUID = in.readString(); - version = Version.readVersion(in); + version = in.readVersion(); if (in.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { index = new IndexId(in); } else { @@ -466,7 +466,7 @@ public Version version() { @Override protected void writeAdditionalFields(StreamOutput out) throws IOException { out.writeString(restoreUUID); - Version.writeVersion(version, out); + out.writeVersion(version); if (out.getVersion().onOrAfter(LegacyESVersion.V_7_7_0)) { index.writeTo(out); } else { diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java b/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java index 62844929f12e4..f1b4ffe2219aa 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/StreamInput.java @@ -42,6 +42,7 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.CharsRef; import org.joda.time.DateTimeZone; +import org.opensearch.Build; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.common.CharArrays; @@ -1107,6 +1108,24 @@ public T readException() throws IOException { return null; } + /** Reads the OpenSearch Version from the input stream */ + public Version readVersion() throws IOException { + return Version.fromId(readVInt()); + } + + /** Reads the {@link Version} from the input stream */ + public Build readBuild() throws IOException { + // the following is new for opensearch: we write the distribution to support any "forks" + final String distribution = readString(); + // be lenient when reading on the wire, the enumeration values from other versions might be different than what we know + final Build.Type type = Build.Type.fromDisplayName(readString(), false); + String hash = readString(); + String date = readString(); + boolean snapshot = readBoolean(); + final String version = readString(); + return new Build(type, hash, date, snapshot, version, distribution); + } + /** * Get the registry of named writeables if this stream has one, * {@code null} otherwise. diff --git a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java b/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java index 814b8a9a86bd7..da17cddfcf97b 100644 --- a/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java +++ b/server/src/main/java/org/opensearch/common/io/stream/StreamOutput.java @@ -42,6 +42,7 @@ import org.apache.lucene.util.BytesRefBuilder; import org.joda.time.DateTimeZone; import org.joda.time.ReadableInstant; +import org.opensearch.Build; import org.opensearch.OpenSearchException; import org.opensearch.Version; import org.opensearch.cluster.ClusterState; @@ -1102,6 +1103,24 @@ private void writeException(Throwable rootException, Throwable throwable, int ne } } + /** Writes the OpenSearch {@link Version} to the output stream */ + public void writeVersion(final Version version) throws IOException { + writeVInt(version.id); + } + + /** Writes the OpenSearch {@link Build} informn to the output stream */ + public void writeBuild(final Build build) throws IOException { + // the following is new for opensearch: we write the distribution name to support any "forks" of the code + writeString(build.getDistribution()); + + final Build.Type buildType = build.type(); + writeString(buildType.displayName()); + writeString(build.hash()); + writeString(build.date()); + writeBoolean(build.isSnapshot()); + writeString(build.getQualifiedVersion()); + } + boolean failOnTooManyNestedExceptions(Throwable throwable) { throw new AssertionError("too many nested exceptions", throwable); } diff --git a/server/src/main/java/org/opensearch/common/settings/WriteableSetting.java b/server/src/main/java/org/opensearch/common/settings/WriteableSetting.java index 1225202612129..4b34e614f181c 100644 --- a/server/src/main/java/org/opensearch/common/settings/WriteableSetting.java +++ b/server/src/main/java/org/opensearch/common/settings/WriteableSetting.java @@ -368,7 +368,7 @@ private void writeDefaultValue(StreamOutput out, Object defaultValue) throws IOE ((ByteSizeValue) defaultValue).writeTo(out); break; case Version: - Version.writeVersion((Version) defaultValue, out); + out.writeVersion((Version) defaultValue); break; default: // This Should Never Happen (TM) @@ -428,7 +428,7 @@ private Object readDefaultValue(StreamInput in) throws IOException { case ByteSizeValue: return new ByteSizeValue(in); case Version: - return Version.readVersion(in); + return in.readVersion(); default: // This Should Never Happen (TM) throw new IllegalArgumentException("A SettingType has been added to the enum and not handled here."); diff --git a/server/src/main/java/org/opensearch/env/NodeEnvironment.java b/server/src/main/java/org/opensearch/env/NodeEnvironment.java index 51f829023ebf3..80054992c3888 100644 --- a/server/src/main/java/org/opensearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/opensearch/env/NodeEnvironment.java @@ -54,7 +54,7 @@ import org.opensearch.common.SuppressForbidden; import org.opensearch.common.UUIDs; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.lease.Releasable; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Setting.Property; diff --git a/server/src/main/java/org/opensearch/extensions/DiscoveryExtensionNode.java b/server/src/main/java/org/opensearch/extensions/DiscoveryExtensionNode.java index 60387366770cd..c71eb896b9221 100644 --- a/server/src/main/java/org/opensearch/extensions/DiscoveryExtensionNode.java +++ b/server/src/main/java/org/opensearch/extensions/DiscoveryExtensionNode.java @@ -54,7 +54,7 @@ public DiscoveryExtensionNode( @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - Version.writeVersion(minimumCompatibleVersion, out); + out.writeVersion(minimumCompatibleVersion); out.writeVInt(dependencies.size()); for (ExtensionDependency dependency : dependencies) { dependency.writeTo(out); @@ -69,7 +69,7 @@ public void writeTo(StreamOutput out) throws IOException { */ public DiscoveryExtensionNode(final StreamInput in) throws IOException { super(in); - minimumCompatibleVersion = Version.readVersion(in); + minimumCompatibleVersion = in.readVersion(); int size = in.readVInt(); dependencies = new ArrayList<>(size); for (int i = 0; i < size; i++) { diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionDependency.java b/server/src/main/java/org/opensearch/extensions/ExtensionDependency.java index f70ea12017e14..5e6c4dd76abd3 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionDependency.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionDependency.java @@ -51,13 +51,13 @@ private ExtensionDependency() {} */ public ExtensionDependency(StreamInput in) throws IOException { uniqueId = in.readString(); - version = Version.readVersion(in); + version = in.readVersion(); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(uniqueId); - Version.writeVersion(version, out); + out.writeVersion(version); } public static ExtensionDependency parse(XContentParser parser) throws IOException { diff --git a/server/src/main/java/org/opensearch/index/IndexSettings.java b/server/src/main/java/org/opensearch/index/IndexSettings.java index 28907b5d2531a..58a87e6bb93e1 100644 --- a/server/src/main/java/org/opensearch/index/IndexSettings.java +++ b/server/src/main/java/org/opensearch/index/IndexSettings.java @@ -1007,7 +1007,7 @@ public String customDataPath() { /** * Returns the version the index was created on. - * @see Version#indexCreated(Settings) + * @see IndexMetadata#indexCreated(Settings) */ public Version getIndexVersionCreated() { return version; @@ -1121,9 +1121,9 @@ public boolean getSearchSegmentOrderReversed() { */ public synchronized boolean updateIndexMetadata(IndexMetadata indexMetadata) { final Settings newSettings = indexMetadata.getSettings(); - if (version.equals(Version.indexCreated(newSettings)) == false) { + if (version.equals(IndexMetadata.indexCreated(newSettings)) == false) { throw new IllegalArgumentException( - "version mismatch on settings update expected: " + version + " but was: " + Version.indexCreated(newSettings) + "version mismatch on settings update expected: " + version + " but was: " + IndexMetadata.indexCreated(newSettings) ); } final String newUUID = newSettings.get(IndexMetadata.SETTING_INDEX_UUID, IndexMetadata.INDEX_UUID_NA_VALUE); diff --git a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java index 1dafd4c5f6ca6..a65e1898bea0d 100644 --- a/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java +++ b/server/src/main/java/org/opensearch/index/analysis/PreBuiltAnalyzerProviderFactory.java @@ -34,6 +34,7 @@ import org.apache.lucene.analysis.Analyzer; import org.opensearch.Version; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.io.IOUtils; import org.opensearch.env.Environment; @@ -77,7 +78,7 @@ public PreBuiltAnalyzerProviderFactory(String name, PreBuiltCacheFactory.Caching @Override public AnalyzerProvider get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException { - Version versionCreated = Version.indexCreated(settings); + Version versionCreated = IndexMetadata.indexCreated(settings); if (Version.CURRENT.equals(versionCreated) == false) { return super.get(indexSettings, environment, name, settings); } else { diff --git a/server/src/main/java/org/opensearch/index/analysis/PreConfiguredAnalysisComponent.java b/server/src/main/java/org/opensearch/index/analysis/PreConfiguredAnalysisComponent.java index a9c3c95c7bb77..e6d607de3a0fb 100644 --- a/server/src/main/java/org/opensearch/index/analysis/PreConfiguredAnalysisComponent.java +++ b/server/src/main/java/org/opensearch/index/analysis/PreConfiguredAnalysisComponent.java @@ -33,6 +33,7 @@ package org.opensearch.index.analysis; import org.opensearch.Version; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.settings.Settings; import org.opensearch.env.Environment; import org.opensearch.index.IndexSettings; @@ -62,7 +63,7 @@ protected PreConfiguredAnalysisComponent(String name, PreBuiltCacheFactory.PreBu @Override public T get(IndexSettings indexSettings, Environment environment, String name, Settings settings) throws IOException { - Version versionCreated = Version.indexCreated(settings); + Version versionCreated = IndexMetadata.indexCreated(settings); synchronized (this) { T factory = cache.get(versionCreated); if (factory == null) { diff --git a/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java b/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java index 7fff632d22da1..2acffdee49a3a 100644 --- a/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java +++ b/server/src/main/java/org/opensearch/index/mapper/DocumentParser.java @@ -36,6 +36,7 @@ import org.apache.lucene.index.IndexableField; import org.opensearch.OpenSearchParseException; import org.opensearch.Version; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Strings; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; @@ -762,7 +763,7 @@ private static Mapper.Builder createBuilderFromDynamicValue( DateFieldMapper.Resolution.MILLISECONDS, dateTimeFormatter, ignoreMalformed, - Version.indexCreated(context.indexSettings().getSettings()) + IndexMetadata.indexCreated(context.indexSettings().getSettings()) ); } return builder; diff --git a/server/src/main/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapper.java b/server/src/main/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapper.java index b707abdac2b75..9d2b6f2b39dd5 100644 --- a/server/src/main/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/LegacyGeoShapeFieldMapper.java @@ -44,6 +44,7 @@ import org.opensearch.LegacyESVersion; import org.opensearch.OpenSearchParseException; import org.opensearch.Version; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Explicit; import org.opensearch.core.ParseField; import org.opensearch.common.geo.GeoUtils; @@ -520,7 +521,7 @@ public LegacyGeoShapeFieldMapper( CopyTo copyTo ) { super(simpleName, fieldType, mappedFieldType, ignoreMalformed, coerce, ignoreZValue, orientation, multiFields, copyTo); - this.indexCreatedVersion = Version.indexCreated(indexSettings); + this.indexCreatedVersion = IndexMetadata.indexCreated(indexSettings); } @Override diff --git a/server/src/main/java/org/opensearch/index/mapper/Mapper.java b/server/src/main/java/org/opensearch/index/mapper/Mapper.java index 36175e0386107..59c647d38f0de 100644 --- a/server/src/main/java/org/opensearch/index/mapper/Mapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/Mapper.java @@ -79,7 +79,7 @@ public Settings indexSettings() { } public Version indexCreatedVersion() { - return Version.indexCreated(indexSettings); + return IndexMetadata.indexCreated(indexSettings); } public Version indexCreatedVersionOrDefault(@Nullable Version defaultValue) { diff --git a/server/src/main/java/org/opensearch/index/mapper/ObjectMapper.java b/server/src/main/java/org/opensearch/index/mapper/ObjectMapper.java index f3f7559dab149..b4dcd35a5cd47 100644 --- a/server/src/main/java/org/opensearch/index/mapper/ObjectMapper.java +++ b/server/src/main/java/org/opensearch/index/mapper/ObjectMapper.java @@ -35,6 +35,7 @@ import org.apache.lucene.search.Query; import org.opensearch.OpenSearchParseException; import org.opensearch.Version; +import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.common.Explicit; import org.opensearch.common.Nullable; import org.opensearch.common.collect.CopyOnWriteHashMap; @@ -451,7 +452,7 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map LegacyESVersion.indexCreated(Settings.builder().build())); + Exception e = expectThrows(IllegalStateException.class, () -> IndexMetadata.indexCreated(Settings.builder().build())); assertThat(e.getMessage(), containsString("[index.version.created] is not present")); } @@ -123,7 +123,7 @@ public void testIndexCreatedVersion() { final LegacyESVersion version = (LegacyESVersion) LegacyESVersion.fromId(6000026); assertEquals( version, - LegacyESVersion.indexCreated( + IndexMetadata.indexCreated( Settings.builder().put(IndexMetadata.SETTING_INDEX_UUID, "foo").put(IndexMetadata.SETTING_VERSION_CREATED, version).build() ) ); diff --git a/server/src/test/java/org/opensearch/VersionTests.java b/server/src/test/java/org/opensearch/VersionTests.java index c2566e83dd9b6..185c56b23cd60 100644 --- a/server/src/test/java/org/opensearch/VersionTests.java +++ b/server/src/test/java/org/opensearch/VersionTests.java @@ -175,7 +175,7 @@ public void testWrongVersionFromString() { } public void testVersionNoPresentInSettings() { - Exception e = expectThrows(IllegalStateException.class, () -> Version.indexCreated(Settings.builder().build())); + Exception e = expectThrows(IllegalStateException.class, () -> IndexMetadata.indexCreated(Settings.builder().build())); assertThat(e.getMessage(), containsString("[index.version.created] is not present")); } @@ -184,7 +184,7 @@ public void testIndexCreatedVersion() { final Version version = Version.V_1_0_0; assertEquals( version, - Version.indexCreated( + IndexMetadata.indexCreated( Settings.builder().put(IndexMetadata.SETTING_INDEX_UUID, "foo").put(IndexMetadata.SETTING_VERSION_CREATED, version).build() ) ); diff --git a/server/src/test/java/org/opensearch/common/io/stream/DelayableWriteableTests.java b/server/src/test/java/org/opensearch/common/io/stream/DelayableWriteableTests.java index 930aaafaad33e..b0aeb6a86ae2d 100644 --- a/server/src/test/java/org/opensearch/common/io/stream/DelayableWriteableTests.java +++ b/server/src/test/java/org/opensearch/common/io/stream/DelayableWriteableTests.java @@ -118,12 +118,12 @@ private static class SneakOtherSideVersionOnWire implements Writeable { } SneakOtherSideVersionOnWire(StreamInput in) throws IOException { - version = Version.readVersion(in); + version = in.readVersion(); } @Override public void writeTo(StreamOutput out) throws IOException { - Version.writeVersion(out.getVersion(), out); + out.writeVersion(out.getVersion()); } } diff --git a/server/src/test/java/org/opensearch/index/translog/LocalTranslogTests.java b/server/src/test/java/org/opensearch/index/translog/LocalTranslogTests.java index a7fc4bd6329d4..f7c90273a094d 100644 --- a/server/src/test/java/org/opensearch/index/translog/LocalTranslogTests.java +++ b/server/src/test/java/org/opensearch/index/translog/LocalTranslogTests.java @@ -59,7 +59,7 @@ import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.bytes.ReleasableBytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.settings.Settings; diff --git a/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java b/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java index 3e51ca02b5170..a33512c81fdad 100644 --- a/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java +++ b/server/src/test/java/org/opensearch/index/translog/RemoteFSTranslogTests.java @@ -28,7 +28,7 @@ import org.opensearch.common.blobstore.fs.FsBlobStore; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.ReleasableBytesReference; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.ByteSizeUnit; diff --git a/server/src/test/java/org/opensearch/indices/IndicesServiceTests.java b/server/src/test/java/org/opensearch/indices/IndicesServiceTests.java index e481384c3d6f3..8d884debfb95c 100644 --- a/server/src/test/java/org/opensearch/indices/IndicesServiceTests.java +++ b/server/src/test/java/org/opensearch/indices/IndicesServiceTests.java @@ -45,7 +45,7 @@ import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.UUIDs; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; diff --git a/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java b/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java index ae59798d0695f..39df2950d2552 100644 --- a/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java +++ b/server/src/test/java/org/opensearch/indices/recovery/LocalStorePeerRecoverySourceHandlerTests.java @@ -62,7 +62,7 @@ import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.concurrent.GatedCloseable; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.lease.Releasable; import org.opensearch.common.lucene.store.IndexOutputOutputStream; import org.opensearch.common.lucene.uid.Versions; diff --git a/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java b/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java index ad0df6c7a99cc..1d276c6a1c64e 100644 --- a/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java +++ b/server/src/test/java/org/opensearch/persistent/TestPersistentTasksPlugin.java @@ -178,7 +178,7 @@ public TestParams(StreamInput in) throws IOException { executorNodeAttr = in.readOptionalString(); responseNode = in.readOptionalString(); testParam = in.readOptionalString(); - minVersion = Version.readVersion(in); + minVersion = in.readVersion(); feature = Optional.ofNullable(in.readOptionalString()); } @@ -208,7 +208,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeOptionalString(executorNodeAttr); out.writeOptionalString(responseNode); out.writeOptionalString(testParam); - Version.writeVersion(minVersion, out); + out.writeVersion(minVersion); out.writeOptionalString(feature.orElse(null)); } diff --git a/server/src/test/java/org/opensearch/transport/TransportHandshakerTests.java b/server/src/test/java/org/opensearch/transport/TransportHandshakerTests.java index 9dbfec7bfe106..32ccb148f8e11 100644 --- a/server/src/test/java/org/opensearch/transport/TransportHandshakerTests.java +++ b/server/src/test/java/org/opensearch/transport/TransportHandshakerTests.java @@ -124,7 +124,7 @@ public void testHandshakeRequestFutureVersionsCompatibility() throws IOException TaskId.EMPTY_TASK_ID.writeTo(lengthCheckingHandshake); TaskId.EMPTY_TASK_ID.writeTo(futureHandshake); try (BytesStreamOutput internalMessage = new BytesStreamOutput()) { - Version.writeVersion(Version.CURRENT, internalMessage); + internalMessage.writeVersion(Version.CURRENT); lengthCheckingHandshake.writeBytesReference(internalMessage.bytes()); internalMessage.write(new byte[1024]); futureHandshake.writeBytesReference(internalMessage.bytes()); diff --git a/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java b/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java index 524362524bbde..428b0988d4cce 100644 --- a/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java +++ b/test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java @@ -39,7 +39,7 @@ import org.opensearch.common.Booleans; import org.opensearch.common.Strings; import org.opensearch.common.SuppressForbidden; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.PathUtils; import org.opensearch.common.network.IfConfig; import org.opensearch.common.network.NetworkAddress; diff --git a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java index 135ddcc39f60c..6bc4ecacbd980 100644 --- a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java @@ -71,7 +71,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.breaker.CircuitBreaker; import org.opensearch.common.component.LifecycleListener; -import org.opensearch.common.io.FileSystemUtils; +import org.opensearch.core.util.FileSystemUtils; import org.opensearch.common.io.stream.NamedWriteableRegistry; import org.opensearch.common.lease.Releasables; import org.opensearch.common.settings.MockSecureSettings;