Skip to content

Commit f308752

Browse files
Support installing plugin SNAPSHOTs with SNASPHOT distribution (#16581) (#16647)
* Support installing plugin SNAPSHOTs with SNASPHOT distribution * Use Build.CURRENT directly for snapshots --------- (cherry picked from commit 3b9ca63) Signed-off-by: Andriy Redko <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 149fa03 commit f308752

File tree

3 files changed

+21
-175
lines changed

3 files changed

+21
-175
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1010
- Switch from `buildSrc/version.properties` to Gradle version catalog (`gradle/libs.versions.toml`) to enable dependabot to perform automated upgrades on common libs ([#16284](https://github.com/opensearch-project/OpenSearch/pull/16284))
1111
- Increase segrep pressure checkpoint default limit to 30 ([#16577](https://github.com/opensearch-project/OpenSearch/pull/16577/files))
1212
- Add dynamic setting allowing size > 0 requests to be cached in the request cache ([#16483](https://github.com/opensearch-project/OpenSearch/pull/16483))
13+
- Support installing plugin SNAPSHOTs with SNASPHOT distribution ([#16581](https://github.com/opensearch-project/OpenSearch/pull/16581))
1314
- Make IndexStoreListener a pluggable interface ([#16583](https://github.com/opensearch-project/OpenSearch/pull/16583))
1415
- Add a flag in QueryShardContext to differentiate inner hit query ([#16600](https://github.com/opensearch-project/OpenSearch/pull/16600))
1516
- Add vertical scaling and SoftReference for snapshot repository data cache ([#16489](https://github.com/opensearch-project/OpenSearch/pull/16489))

distribution/tools/plugin-cli/src/main/java/org/opensearch/plugins/InstallPluginCommand.java

+4-26
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@
137137
*/
138138
class InstallPluginCommand extends EnvironmentAwareCommand {
139139

140-
private static final String PROPERTY_STAGING_ID = "opensearch.plugins.staging";
141-
142140
// exit codes for install
143141
/** A plugin with the same name is already installed. */
144142
static final int PLUGIN_EXISTS = 1;
@@ -307,14 +305,7 @@ void execute(Terminal terminal, List<String> pluginIds, boolean isBatch, Environ
307305
private Path download(Terminal terminal, String pluginId, Path tmpDir, boolean isBatch) throws Exception {
308306

309307
if (OFFICIAL_PLUGINS.contains(pluginId)) {
310-
final String url = getOpenSearchUrl(
311-
terminal,
312-
getStagingHash(),
313-
Version.CURRENT,
314-
isSnapshot(),
315-
pluginId,
316-
Platforms.PLATFORM_NAME
317-
);
308+
final String url = getOpenSearchUrl(terminal, Version.CURRENT, isSnapshot(), pluginId, Platforms.PLATFORM_NAME);
318309
terminal.println("-> Downloading " + pluginId + " from opensearch");
319310
return downloadAndValidate(terminal, url, tmpDir, true, isBatch);
320311
}
@@ -341,38 +332,25 @@ private Path download(Terminal terminal, String pluginId, Path tmpDir, boolean i
341332
return downloadZip(terminal, pluginId, tmpDir, isBatch);
342333
}
343334

344-
// pkg private so tests can override
345-
String getStagingHash() {
346-
return System.getProperty(PROPERTY_STAGING_ID);
347-
}
348-
349335
boolean isSnapshot() {
350336
return Build.CURRENT.isSnapshot();
351337
}
352338

353339
/** Returns the url for an official opensearch plugin. */
354340
private String getOpenSearchUrl(
355341
final Terminal terminal,
356-
final String stagingHash,
357342
final Version version,
358343
final boolean isSnapshot,
359344
final String pluginId,
360345
final String platform
361346
) throws IOException, UserException {
362347
final String baseUrl;
363-
if (isSnapshot && stagingHash == null) {
364-
throw new UserException(
365-
ExitCodes.CONFIG,
366-
"attempted to install release build of official plugin on snapshot build of OpenSearch"
367-
);
368-
}
369-
if (stagingHash != null) {
348+
if (isSnapshot == true) {
370349
baseUrl = String.format(
371350
Locale.ROOT,
372-
"https://artifacts.opensearch.org/snapshots/plugins/%s/%s-%s",
351+
"https://artifacts.opensearch.org/snapshots/plugins/%s/%s",
373352
pluginId,
374-
version,
375-
stagingHash
353+
Build.CURRENT.getQualifiedVersion()
376354
);
377355
} else {
378356
baseUrl = String.format(

distribution/tools/plugin-cli/src/test/java/org/opensearch/plugins/InstallPluginCommandTests.java

+16-149
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,6 @@ void assertInstallPluginFromUrl(
990990
final String pluginId,
991991
final String name,
992992
final String url,
993-
final String stagingHash,
994993
final boolean isSnapshot,
995994
final String shaExtension,
996995
final Function<byte[], String> shaCalculator,
@@ -1065,11 +1064,6 @@ boolean urlExists(Terminal terminal, String urlString) throws IOException {
10651064
return urlString.equals(url);
10661065
}
10671066

1068-
@Override
1069-
String getStagingHash() {
1070-
return stagingHash;
1071-
}
1072-
10731067
@Override
10741068
boolean isSnapshot() {
10751069
return isSnapshot;
@@ -1084,19 +1078,13 @@ void jarHellCheck(PluginInfo candidateInfo, Path candidate, Path pluginsDir, Pat
10841078
assertPlugin(name, pluginDir, env.v2());
10851079
}
10861080

1087-
public void assertInstallPluginFromUrl(
1088-
final String pluginId,
1089-
final String name,
1090-
final String url,
1091-
final String stagingHash,
1092-
boolean isSnapshot
1093-
) throws Exception {
1081+
public void assertInstallPluginFromUrl(final String pluginId, final String name, final String url, boolean isSnapshot)
1082+
throws Exception {
10941083
final MessageDigest digest = MessageDigest.getInstance("SHA-512");
10951084
assertInstallPluginFromUrl(
10961085
pluginId,
10971086
name,
10981087
url,
1099-
stagingHash,
11001088
isSnapshot,
11011089
".sha512",
11021090
checksumAndFilename(digest, url),
@@ -1111,42 +1099,17 @@ public void testOfficialPlugin() throws Exception {
11111099
+ "/analysis-icu-"
11121100
+ Build.CURRENT.getQualifiedVersion()
11131101
+ ".zip";
1114-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, null, false);
1102+
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, false);
11151103
}
11161104

11171105
public void testOfficialPluginSnapshot() throws Exception {
11181106
String url = String.format(
11191107
Locale.ROOT,
1120-
"https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/%s-abc123/analysis-icu-%s.zip",
1121-
Version.CURRENT,
1122-
Build.CURRENT.getQualifiedVersion()
1123-
);
1124-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, "abc123", true);
1125-
}
1126-
1127-
public void testInstallReleaseBuildOfPluginOnSnapshotBuild() {
1128-
String url = String.format(
1129-
Locale.ROOT,
1130-
"https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/%s-abc123/analysis-icu-%s.zip",
1108+
"https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/%s-SNAPSHOT/analysis-icu-%s.zip",
11311109
Version.CURRENT,
11321110
Build.CURRENT.getQualifiedVersion()
11331111
);
1134-
// attemping to install a release build of a plugin (no staging ID) on a snapshot build should throw a user exception
1135-
final UserException e = expectThrows(
1136-
UserException.class,
1137-
() -> assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, null, true)
1138-
);
1139-
assertThat(e.exitCode, equalTo(ExitCodes.CONFIG));
1140-
assertThat(e, hasToString(containsString("attempted to install release build of official plugin on snapshot build of OpenSearch")));
1141-
}
1142-
1143-
public void testOfficialPluginStaging() throws Exception {
1144-
String url = "https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/"
1145-
+ Version.CURRENT
1146-
+ "-abc123/analysis-icu-"
1147-
+ Build.CURRENT.getQualifiedVersion()
1148-
+ ".zip";
1149-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, "abc123", false);
1112+
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, true);
11501113
}
11511114

11521115
public void testOfficialPlatformPlugin() throws Exception {
@@ -1157,62 +1120,30 @@ public void testOfficialPlatformPlugin() throws Exception {
11571120
+ "-"
11581121
+ Build.CURRENT.getQualifiedVersion()
11591122
+ ".zip";
1160-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, null, false);
1161-
}
1162-
1163-
public void testOfficialPlatformPluginSnapshot() throws Exception {
1164-
String url = String.format(
1165-
Locale.ROOT,
1166-
"https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/%s-abc123/analysis-icu-%s-%s.zip",
1167-
Version.CURRENT,
1168-
Platforms.PLATFORM_NAME,
1169-
Build.CURRENT.getQualifiedVersion()
1170-
);
1171-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, "abc123", true);
1172-
}
1173-
1174-
public void testOfficialPlatformPluginStaging() throws Exception {
1175-
String url = "https://artifacts.opensearch.org/snapshots/plugins/analysis-icu/"
1176-
+ Version.CURRENT
1177-
+ "-abc123/analysis-icu-"
1178-
+ Platforms.PLATFORM_NAME
1179-
+ "-"
1180-
+ Build.CURRENT.getQualifiedVersion()
1181-
+ ".zip";
1182-
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, "abc123", false);
1123+
assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, false);
11831124
}
11841125

11851126
public void testMavenPlugin() throws Exception {
11861127
String url = "https://repo1.maven.org/maven2/mygroup/myplugin/1.0.0/myplugin-1.0.0.zip";
1187-
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, null, false);
1128+
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, false);
11881129
}
11891130

11901131
public void testMavenPlatformPlugin() throws Exception {
11911132
String url = "https://repo1.maven.org/maven2/mygroup/myplugin/1.0.0/myplugin-" + Platforms.PLATFORM_NAME + "-1.0.0.zip";
1192-
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, null, false);
1133+
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, false);
11931134
}
11941135

11951136
public void testMavenSha1Backcompat() throws Exception {
11961137
String url = "https://repo1.maven.org/maven2/mygroup/myplugin/1.0.0/myplugin-1.0.0.zip";
11971138
MessageDigest digest = MessageDigest.getInstance("SHA-1");
1198-
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, null, false, ".sha1", checksum(digest), null, (b, p) -> null);
1139+
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, false, ".sha1", checksum(digest), null, (b, p) -> null);
11991140
assertTrue(terminal.getOutput(), terminal.getOutput().contains("sha512 not found, falling back to sha1"));
12001141
}
12011142

12021143
public void testMavenChecksumWithoutFilename() throws Exception {
12031144
String url = "https://repo1.maven.org/maven2/mygroup/myplugin/1.0.0/myplugin-1.0.0.zip";
12041145
MessageDigest digest = MessageDigest.getInstance("SHA-512");
1205-
assertInstallPluginFromUrl(
1206-
"mygroup:myplugin:1.0.0",
1207-
"myplugin",
1208-
url,
1209-
null,
1210-
false,
1211-
".sha512",
1212-
checksum(digest),
1213-
null,
1214-
(b, p) -> null
1215-
);
1146+
assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, false, ".sha512", checksum(digest), null, (b, p) -> null);
12161147
}
12171148

12181149
public void testOfficialChecksumWithoutFilename() throws Exception {
@@ -1224,17 +1155,7 @@ public void testOfficialChecksumWithoutFilename() throws Exception {
12241155
MessageDigest digest = MessageDigest.getInstance("SHA-512");
12251156
UserException e = expectThrows(
12261157
UserException.class,
1227-
() -> assertInstallPluginFromUrl(
1228-
"analysis-icu",
1229-
"analysis-icu",
1230-
url,
1231-
null,
1232-
false,
1233-
".sha512",
1234-
checksum(digest),
1235-
null,
1236-
(b, p) -> null
1237-
)
1158+
() -> assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, false, ".sha512", checksum(digest), null, (b, p) -> null)
12381159
);
12391160
assertEquals(ExitCodes.IO_ERROR, e.exitCode);
12401161
assertThat(e.getMessage(), startsWith("Invalid checksum file"));
@@ -1249,17 +1170,7 @@ public void testOfficialShaMissing() throws Exception {
12491170
MessageDigest digest = MessageDigest.getInstance("SHA-1");
12501171
UserException e = expectThrows(
12511172
UserException.class,
1252-
() -> assertInstallPluginFromUrl(
1253-
"analysis-icu",
1254-
"analysis-icu",
1255-
url,
1256-
null,
1257-
false,
1258-
".sha1",
1259-
checksum(digest),
1260-
null,
1261-
(b, p) -> null
1262-
)
1173+
() -> assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, false, ".sha1", checksum(digest), null, (b, p) -> null)
12631174
);
12641175
assertEquals(ExitCodes.IO_ERROR, e.exitCode);
12651176
assertEquals("Plugin checksum missing: " + url + ".sha512", e.getMessage());
@@ -1269,17 +1180,7 @@ public void testMavenShaMissing() throws Exception {
12691180
String url = "https://repo1.maven.org/maven2/mygroup/myplugin/1.0.0/myplugin-1.0.0.zip";
12701181
UserException e = expectThrows(
12711182
UserException.class,
1272-
() -> assertInstallPluginFromUrl(
1273-
"mygroup:myplugin:1.0.0",
1274-
"myplugin",
1275-
url,
1276-
null,
1277-
false,
1278-
".dne",
1279-
bytes -> null,
1280-
null,
1281-
(b, p) -> null
1282-
)
1183+
() -> assertInstallPluginFromUrl("mygroup:myplugin:1.0.0", "myplugin", url, false, ".dne", bytes -> null, null, (b, p) -> null)
12831184
);
12841185
assertEquals(ExitCodes.IO_ERROR, e.exitCode);
12851186
assertEquals("Plugin checksum missing: " + url + ".sha1", e.getMessage());
@@ -1294,17 +1195,7 @@ public void testInvalidShaFileMissingFilename() throws Exception {
12941195
MessageDigest digest = MessageDigest.getInstance("SHA-512");
12951196
UserException e = expectThrows(
12961197
UserException.class,
1297-
() -> assertInstallPluginFromUrl(
1298-
"analysis-icu",
1299-
"analysis-icu",
1300-
url,
1301-
null,
1302-
false,
1303-
".sha512",
1304-
checksum(digest),
1305-
null,
1306-
(b, p) -> null
1307-
)
1198+
() -> assertInstallPluginFromUrl("analysis-icu", "analysis-icu", url, false, ".sha512", checksum(digest), null, (b, p) -> null)
13081199
);
13091200
assertEquals(ExitCodes.IO_ERROR, e.exitCode);
13101201
assertTrue(e.getMessage(), e.getMessage().startsWith("Invalid checksum file"));
@@ -1323,7 +1214,6 @@ public void testInvalidShaFileMismatchFilename() throws Exception {
13231214
"analysis-icu",
13241215
"analysis-icu",
13251216
url,
1326-
null,
13271217
false,
13281218
".sha512",
13291219
checksumAndString(digest, " repository-s3-" + Build.CURRENT.getQualifiedVersion() + ".zip"),
@@ -1348,7 +1238,6 @@ public void testInvalidShaFileContainingExtraLine() throws Exception {
13481238
"analysis-icu",
13491239
"analysis-icu",
13501240
url,
1351-
null,
13521241
false,
13531242
".sha512",
13541243
checksumAndString(digest, " analysis-icu-" + Build.CURRENT.getQualifiedVersion() + ".zip\nfoobar"),
@@ -1372,7 +1261,6 @@ public void testSha512Mismatch() throws Exception {
13721261
"analysis-icu",
13731262
"analysis-icu",
13741263
url,
1375-
null,
13761264
false,
13771265
".sha512",
13781266
bytes -> "foobar analysis-icu-" + Build.CURRENT.getQualifiedVersion() + ".zip",
@@ -1392,7 +1280,6 @@ public void testSha1Mismatch() throws Exception {
13921280
"mygroup:myplugin:1.0.0",
13931281
"myplugin",
13941282
url,
1395-
null,
13961283
false,
13971284
".sha1",
13981285
bytes -> "foobar",
@@ -1426,17 +1313,7 @@ public void testPublicKeyIdMismatchToExpectedPublicKeyId() throws Exception {
14261313
final String expectedID = Long.toHexString(verifyingKey.getKeyID()).toUpperCase(Locale.ROOT);
14271314
final IllegalStateException e = expectThrows(
14281315
IllegalStateException.class,
1429-
() -> assertInstallPluginFromUrl(
1430-
icu,
1431-
icu,
1432-
url,
1433-
null,
1434-
false,
1435-
".sha512",
1436-
checksumAndFilename(digest, url),
1437-
verifyingKey,
1438-
signature
1439-
)
1316+
() -> assertInstallPluginFromUrl(icu, icu, url, false, ".sha512", checksumAndFilename(digest, url), verifyingKey, signature)
14401317
);
14411318
assertThat(e, hasToString(containsString("key id [" + actualID + "] does not match expected key id [" + expectedID + "]")));
14421319
}
@@ -1463,17 +1340,7 @@ public void testFailedSignatureVerification() throws Exception {
14631340
};
14641341
final IllegalStateException e = expectThrows(
14651342
IllegalStateException.class,
1466-
() -> assertInstallPluginFromUrl(
1467-
icu,
1468-
icu,
1469-
url,
1470-
null,
1471-
false,
1472-
".sha512",
1473-
checksumAndFilename(digest, url),
1474-
newSecretKey(),
1475-
signature
1476-
)
1343+
() -> assertInstallPluginFromUrl(icu, icu, url, false, ".sha512", checksumAndFilename(digest, url), newSecretKey(), signature)
14771344
);
14781345
assertThat(e, hasToString(equalTo("java.lang.IllegalStateException: signature verification for [" + url + "] failed")));
14791346
}

0 commit comments

Comments
 (0)