Skip to content

Commit

Permalink
Merge branch 'main' into geoshape-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Oct 11, 2023
2 parents 3a3d7bc + 8a6df32 commit 521a7c2
Show file tree
Hide file tree
Showing 32 changed files with 953 additions and 361 deletions.
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=bb09982fdf52718e4c7b25023d10df6d35a5fff969860bdf5a5bd27a3ab27a9e
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.3
8.4
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.bootstrap.PluginPolicyInfo;
import org.elasticsearch.bootstrap.PolicyUtil;
import org.elasticsearch.cli.ExitCodes;
Expand Down Expand Up @@ -84,6 +83,8 @@
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -303,7 +304,7 @@ private Path download(InstallablePlugin plugin, Path tmpDir) throws Exception {
// else carry on to regular download
}

final String url = getElasticUrl(getStagingHash(), Version.CURRENT, isSnapshot(), pluginId, Platforms.PLATFORM_NAME);
final String url = getElasticUrl(getStagingHash(), isSnapshot(), pluginId, Platforms.PLATFORM_NAME);
terminal.println(logPrefix + "Downloading " + pluginId + " from elastic");
return downloadAndValidate(url, tmpDir, true);
}
Expand Down Expand Up @@ -341,7 +342,7 @@ private Path getPluginArchivePath(String pluginId, String pluginArchiveDir) thro
if (Files.isDirectory(path) == false) {
throw new UserException(ExitCodes.CONFIG, "Location in ES_PLUGIN_ARCHIVE_DIR is not a directory");
}
return PathUtils.get(pluginArchiveDir, pluginId + "-" + Version.CURRENT + (isSnapshot() ? "-SNAPSHOT" : "") + ".zip");
return PathUtils.get(pluginArchiveDir, pluginId + "-" + Build.current().qualifiedVersion() + ".zip");
}

// pkg private so tests can override
Expand All @@ -356,25 +357,30 @@ boolean isSnapshot() {
/**
* Returns the url for an official elasticsearch plugin.
*/
private String getElasticUrl(
final String stagingHash,
final Version version,
final boolean isSnapshot,
final String pluginId,
final String platform
) throws IOException, UserException {
private String getElasticUrl(final String stagingHash, final boolean isSnapshot, final String pluginId, final String platform)
throws IOException, UserException {
final String baseUrl;
if (isSnapshot && stagingHash == null) {
throw new UserException(
ExitCodes.CONFIG,
"attempted to install release build of official plugin on snapshot build of Elasticsearch"
);
}
// assumption: we will only be publishing plugins to snapshot or staging when they're versioned
String semanticVersion = getSemanticVersion(Build.current().version());
if (semanticVersion == null) {
throw new UserException(
ExitCodes.CONFIG,
"attempted to download a plugin for a non-semantically-versioned build of Elasticsearch: ["
+ Build.current().version()
+ "]"
);
}
if (stagingHash != null) {
if (isSnapshot) {
baseUrl = nonReleaseUrl("snapshots", version, stagingHash, pluginId);
baseUrl = nonReleaseUrl("snapshots", semanticVersion, stagingHash, pluginId);
} else {
baseUrl = nonReleaseUrl("staging", version, stagingHash, pluginId);
baseUrl = nonReleaseUrl("staging", semanticVersion, stagingHash, pluginId);
}
} else {
baseUrl = String.format(Locale.ROOT, "https://artifacts.elastic.co/downloads/elasticsearch-plugins/%s", pluginId);
Expand All @@ -393,7 +399,7 @@ private String getElasticUrl(
return String.format(Locale.ROOT, "%s/%s-%s.zip", baseUrl, pluginId, Build.current().qualifiedVersion());
}

private static String nonReleaseUrl(final String hostname, final Version version, final String stagingHash, final String pluginId) {
private static String nonReleaseUrl(final String hostname, final String version, final String stagingHash, final String pluginId) {
return String.format(
Locale.ROOT,
"https://%s.elastic.co/%s-%s/downloads/elasticsearch-plugins/%s",
Expand Down Expand Up @@ -1088,4 +1094,9 @@ private static void setFileAttributes(final Path path, final Set<PosixFilePermis
public void close() throws IOException {
IOUtils.rm(pathsToDeleteOnShutdown.toArray(new Path[0]));
}

static String getSemanticVersion(String version) {
Matcher matcher = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)\\D?.*").matcher(version);
return matcher.matches() ? matcher.group(1) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import joptsimple.OptionSet;

import org.elasticsearch.Version;
import org.elasticsearch.Build;
import org.elasticsearch.cli.ProcessInfo;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.common.cli.EnvironmentAwareCommand;
Expand All @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

import static org.elasticsearch.plugins.cli.SyncPluginsAction.ELASTICSEARCH_PLUGINS_YML_CACHE;

Expand Down Expand Up @@ -61,14 +62,19 @@ private static void printPlugin(Environment env, Terminal terminal, Path plugin,
terminal.println(Terminal.Verbosity.SILENT, prefix + plugin.getFileName().toString());
PluginDescriptor info = PluginDescriptor.readFromProperties(env.pluginsFile().resolve(plugin));
terminal.println(Terminal.Verbosity.VERBOSE, info.toString(prefix));
if (info.getElasticsearchVersion().equals(Version.CURRENT) == false) {

// When PluginDescriptor#getElasticsearchVersion returns a string, we can revisit the need
// for a semantic version
String semanticVersion = InstallPluginAction.getSemanticVersion(Build.current().version());
String buildVersion = Objects.nonNull(semanticVersion) ? semanticVersion : Build.current().version();
if (info.getElasticsearchVersion().toString().equals(buildVersion) == false) {
terminal.errorPrintln(
"WARNING: plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but version "
+ Version.CURRENT
+ buildVersion
+ " is required"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.elasticsearch.plugins.cli;

import org.elasticsearch.Version;
import org.elasticsearch.Build;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.cli.UserException;
Expand Down Expand Up @@ -241,15 +241,15 @@ private List<InstallablePlugin> getPluginsToUpgrade(
throw new RuntimeException("Couldn't find a PluginInfo for [" + eachPluginId + "], which should be impossible");
});

if (info.getElasticsearchVersion().before(Version.CURRENT)) {
if (info.getElasticsearchVersion().toString().equals(Build.current().version()) == false) {
this.terminal.println(
Terminal.Verbosity.VERBOSE,
String.format(
Locale.ROOT,
"Official plugin [%s] is out-of-date (%s versus %s), upgrading",
"Official plugin [%s] is out-of-sync (%s versus %s), upgrading",
eachPluginId,
info.getElasticsearchVersion(),
Version.CURRENT
Build.current().version()
)
);
return true;
Expand Down Expand Up @@ -278,14 +278,14 @@ private List<PluginDescriptor> getExistingPlugins() throws PluginSyncException {

// Check for a version mismatch, unless it's an official plugin since we can upgrade them.
if (InstallPluginAction.OFFICIAL_PLUGINS.contains(info.getName())
&& info.getElasticsearchVersion().equals(Version.CURRENT) == false) {
&& info.getElasticsearchVersion().toString().equals(Build.current().version()) == false) {
this.terminal.errorPrintln(
String.format(
Locale.ROOT,
"WARNING: plugin [%s] was built for Elasticsearch version %s but version %s is required",
info.getName(),
info.getElasticsearchVersion(),
Version.CURRENT
Build.current().version()
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.elasticsearch.Build;
import org.elasticsearch.Version;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.ProcessInfo;
Expand Down Expand Up @@ -111,6 +110,7 @@
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
Expand Down Expand Up @@ -298,7 +298,7 @@ private static String[] pluginProperties(String name, String[] additionalProps,
"version",
"1.0",
"elasticsearch.version",
Version.CURRENT.toString(),
InstallPluginAction.getSemanticVersion(Build.current().version()),
"java.version",
System.getProperty("java.specification.version")

Expand Down Expand Up @@ -724,7 +724,7 @@ public void testPluginPermissions() throws Exception {
final Path platformBinDir = platformNameDir.resolve("bin");
Files.createDirectories(platformBinDir);

Files.createFile(tempPluginDir.resolve("fake-" + Version.CURRENT.toString() + ".jar"));
Files.createFile(tempPluginDir.resolve("fake-" + Build.current().version() + ".jar"));
Files.createFile(platformBinDir.resolve("fake_executable"));
Files.createDirectory(resourcesDir);
Files.createFile(resourcesDir.resolve("resource"));
Expand All @@ -740,7 +740,7 @@ public void testPluginPermissions() throws Exception {
final Path platformName = platform.resolve("linux-x86_64");
final Path bin = platformName.resolve("bin");
assert755(fake);
assert644(fake.resolve("fake-" + Version.CURRENT + ".jar"));
assert644(fake.resolve("fake-" + Build.current().version() + ".jar"));
assert755(resources);
assert644(resources.resolve("resource"));
assert755(platform);
Expand Down Expand Up @@ -1110,8 +1110,8 @@ public void testOfficialPluginSnapshot() throws Exception {
String url = String.format(
Locale.ROOT,
"https://snapshots.elastic.co/%s-abc123/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-%s.zip",
Version.CURRENT,
Build.current().qualifiedVersion()
InstallPluginAction.getSemanticVersion(Build.current().version()),
Build.current().version()
);
assertInstallPluginFromUrl("analysis-icu", url, "abc123", true);
}
Expand All @@ -1120,8 +1120,8 @@ public void testInstallReleaseBuildOfPluginOnSnapshotBuild() {
String url = String.format(
Locale.ROOT,
"https://snapshots.elastic.co/%s-abc123/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-%s.zip",
Version.CURRENT,
Build.current().qualifiedVersion()
InstallPluginAction.getSemanticVersion(Build.current().version()),
Build.current().version()
);
// attempting to install a release build of a plugin (no staging ID) on a snapshot build should throw a user exception
final UserException e = expectThrows(
Expand All @@ -1137,9 +1137,9 @@ public void testInstallReleaseBuildOfPluginOnSnapshotBuild() {

public void testOfficialPluginStaging() throws Exception {
String url = "https://staging.elastic.co/"
+ Version.CURRENT
+ InstallPluginAction.getSemanticVersion(Build.current().version())
+ "-abc123/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-"
+ Build.current().qualifiedVersion()
+ Build.current().version()
+ ".zip";
assertInstallPluginFromUrl("analysis-icu", url, "abc123", false);
}
Expand All @@ -1148,7 +1148,7 @@ public void testOfficialPlatformPlugin() throws Exception {
String url = "https://artifacts.elastic.co/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-"
+ Platforms.PLATFORM_NAME
+ "-"
+ Build.current().qualifiedVersion()
+ Build.current().version()
+ ".zip";
assertInstallPluginFromUrl("analysis-icu", url, null, false);
}
Expand All @@ -1157,16 +1157,16 @@ public void testOfficialPlatformPluginSnapshot() throws Exception {
String url = String.format(
Locale.ROOT,
"https://snapshots.elastic.co/%s-abc123/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-%s-%s.zip",
Version.CURRENT,
InstallPluginAction.getSemanticVersion(Build.current().version()),
Platforms.PLATFORM_NAME,
Build.current().qualifiedVersion()
Build.current().version()
);
assertInstallPluginFromUrl("analysis-icu", url, "abc123", true);
}

public void testOfficialPlatformPluginStaging() throws Exception {
String url = "https://staging.elastic.co/"
+ Version.CURRENT
+ InstallPluginAction.getSemanticVersion(Build.current().version())
+ "-abc123/downloads/elasticsearch-plugins/analysis-icu/analysis-icu-"
+ Platforms.PLATFORM_NAME
+ "-"
Expand Down Expand Up @@ -1580,6 +1580,17 @@ public void testStablePluginWithoutNamedComponentsFile() throws Exception {
assertNamedComponentFile("stable1", env.v2().pluginsFile(), namedComponentsJSON());
}

public void testGetSemanticVersion() {
assertThat(InstallPluginAction.getSemanticVersion("1.2.3"), equalTo("1.2.3"));
assertThat(InstallPluginAction.getSemanticVersion("123.456.789"), equalTo("123.456.789"));
assertThat(InstallPluginAction.getSemanticVersion("1.2.3-SNAPSHOT"), equalTo("1.2.3"));
assertThat(InstallPluginAction.getSemanticVersion("1.2.3foobar"), equalTo("1.2.3"));
assertThat(InstallPluginAction.getSemanticVersion("1.2.3.4"), equalTo("1.2.3"));
assertThat(InstallPluginAction.getSemanticVersion("1.2"), nullValue());
assertThat(InstallPluginAction.getSemanticVersion("foo"), nullValue());
assertThat(InstallPluginAction.getSemanticVersion("foo-1.2.3"), nullValue());
}

private Map<String, Map<String, String>> namedComponentsMap() {
Map<String, Map<String, String>> result = new LinkedHashMap<>();
Map<String, String> extensibles = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void testExistingIncompatiblePlugin() throws Exception {
"version",
"1.0",
"elasticsearch.version",
Version.fromString("1.0.0").toString(),
"1.0.0",
"java.version",
System.getProperty("java.specification.version"),
"classname",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
package org.elasticsearch.plugins.cli;

import org.apache.lucene.tests.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.Build;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.cli.UserException;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -17,6 +17,7 @@
import org.elasticsearch.plugins.PluginTestUtil;
import org.elasticsearch.plugins.cli.SyncPluginsAction.PluginChanges;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.mockito.InOrder;
Expand All @@ -26,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -129,7 +131,7 @@ public void test_getPluginChanges_withPluginToInstall_returnsPluginToInstall() t
* since we can't automatically upgrade it.
*/
public void test_getPluginChanges_withPluginToUpgrade_returnsNoChanges() throws Exception {
createPlugin("my-plugin", Version.CURRENT.previousMajor());
createPlugin("my-plugin", VersionUtils.getPreviousVersion().toString());
config.setPlugins(List.of(new InstallablePlugin("my-plugin")));

final PluginChanges pluginChanges = action.getPluginChanges(config, Optional.empty());
Expand All @@ -142,7 +144,7 @@ public void test_getPluginChanges_withPluginToUpgrade_returnsNoChanges() throws
* but needs to be upgraded, then we calculate that the plugin needs to be upgraded.
*/
public void test_getPluginChanges_withOfficialPluginToUpgrade_returnsPluginToUpgrade() throws Exception {
createPlugin("analysis-icu", Version.CURRENT.previousMajor());
createPlugin("analysis-icu", VersionUtils.getPreviousVersion().toString());
config.setPlugins(List.of(new InstallablePlugin("analysis-icu")));

final PluginChanges pluginChanges = action.getPluginChanges(config, Optional.empty());
Expand Down Expand Up @@ -329,10 +331,11 @@ public void test_performSync_withPluginsToUpgrade_callsUpgradeAction() throws Ex
}

private void createPlugin(String name) throws IOException {
createPlugin(name, Version.CURRENT);
String semanticVersion = InstallPluginAction.getSemanticVersion(Build.current().version());
createPlugin(name, Objects.nonNull(semanticVersion) ? semanticVersion : Build.current().version());
}

private void createPlugin(String name, Version version) throws IOException {
private void createPlugin(String name, String version) throws IOException {
PluginTestUtil.writePluginProperties(
env.pluginsFile().resolve(name),
"description",
Expand All @@ -342,7 +345,7 @@ private void createPlugin(String name, Version version) throws IOException {
"version",
"1.0",
"elasticsearch.version",
version.toString(),
version,
"java.version",
System.getProperty("java.specification.version"),
"classname",
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/100519.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 100519
summary: Disallow vectors whose magnitudes will not fit in a float
area: Vector Search
type: bug
issues: []
Loading

0 comments on commit 521a7c2

Please sign in to comment.