Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Pass registry of headers from ActionPlugin.getRestHeaders to ActionPlugin.getRestHandlerWrapper ([#19875](https://github.com/opensearch-project/OpenSearch/pull/19875))
- Refactor the Condition.Stats and DirectoryFileTransferTracker.Stats class to use the Builder pattern instead of constructors ([#19862](https://github.com/opensearch-project/OpenSearch/pull/19862))
- Refactor the RemoteTranslogTransferTracker.Stats and RemoteSegmentTransferTracker.Stats class to use the Builder pattern instead of constructors ([#19837](https://github.com/opensearch-project/OpenSearch/pull/19837))
- Add RangeSemver for `dependencies` in `plugin-descriptor.properties` ([#19939](https://github.com/opensearch-project/OpenSearch/pull/19939))

### Fixed
- Fix Allocation and Rebalance Constraints of WeightFunction are incorrectly reset ([#19012](https://github.com/opensearch-project/OpenSearch/pull/19012))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@PublicApi(since = "2.13.0")
public class SemverRange implements ToXContentFragment {

private static final Pattern RANGE_PATTERN = Pattern.compile("([\\[\\(])([\\d.]+)\\s*,\\s*([\\d.]+)([\\]\\)])");
public static final Pattern RANGE_PATTERN = Pattern.compile("([\\[\\(])([\\d.]+)\\s*,\\s*([\\d.]+)([\\]\\)])");

private final Version rangeVersion;
private final RangeOperator rangeOperator;
Expand Down
14 changes: 10 additions & 4 deletions server/src/main/java/org/opensearch/plugins/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.opensearch.semver.SemverRange.RANGE_PATTERN;

/**
* An in-memory representation of the plugin descriptor.
*
Expand Down Expand Up @@ -322,13 +324,17 @@ public static PluginInfo readFromProperties(final Path path) throws IOException
if (dependenciesMap.keySet().stream().noneMatch(s -> s.equals("opensearch"))) {
throw new IllegalArgumentException("Only opensearch is allowed to be specified as a plugin dependency: " + dependenciesMap);
}
String[] ranges = dependenciesMap.get("opensearch").split(",");
if (ranges.length != 1) {
String opensearchDependencyVersion = dependenciesMap.get("opensearch");
String[] ranges = opensearchDependencyVersion.split(",");
String opensearchVersion = ranges[0];
if (RANGE_PATTERN.matcher(opensearchDependencyVersion).matches()) {
opensearchVersion = opensearchDependencyVersion;
} else if (ranges.length != 1) {
throw new IllegalArgumentException(
"Exactly one range is allowed to be specified in dependencies for the plugin [\" + name + \"]"
"Exactly one range is allowed to be specified in dependencies for the plugin [" + name + "]"
);
}
opensearchVersionRanges.add(SemverRange.fromString(ranges[0].trim()));
opensearchVersionRanges.add(SemverRange.fromString(opensearchVersion.trim()));
}

final String javaVersionString = propsMap.remove("java.version");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,28 @@ public void testMultipleDependencies() throws Exception {
assertThat(e.getMessage(), containsString("Exactly one dependency is allowed to be specified in plugin descriptor properties"));
}

public void testRangeSemverOnDependencies() throws Exception {
String opensearchRange = "[" + Version.V_2_0_0.toString() + "," + Version.V_3_0_0.toString() + ")";
Path pluginDir = createTempDir().resolve("fake-plugin");
PluginTestUtil.writePluginProperties(
pluginDir,
"description",
"fake desc",
"name",
"my_plugin",
"version",
"1.0",
"dependencies",
"{opensearch:\"" + opensearchRange + "\" }",
"java.version",
System.getProperty("java.specification.version"),
"classname",
"FakePlugin"
);
PluginInfo pluginInfo = PluginInfo.readFromProperties(pluginDir);
assertEquals(SemverRange.fromString(opensearchRange).toString(), pluginInfo.getOpenSearchVersionRangesString());
}

public void testNonOpenSearchDependency() throws Exception {
Path pluginDir = createTempDir().resolve("fake-plugin");
PluginTestUtil.writePluginProperties(
Expand Down
Loading