Skip to content

Commit a2bdc21

Browse files
authored
Merge branch 'main' into distribution-cc-fixes
2 parents 25dd73d + 270ec53 commit a2bdc21

File tree

58 files changed

+1701
-780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1701
-780
lines changed

docs/changelog/121106.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 121106
2+
summary: Add `ModelRegistryMetadata` to Cluster State
3+
area: Machine Learning
4+
type: enhancement
5+
issues: []

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,34 @@ public record PluginData(Path pluginPath, boolean isModular, boolean isExternalP
4949

5050
private static final String POLICY_FILE_NAME = "entitlement-policy.yaml";
5151

52-
public static Map<String, Policy> createPluginPolicies(Collection<PluginData> pluginData, Map<String, String> overrides, String version)
53-
throws IOException {
52+
public static Map<String, Policy> createPluginPolicies(
53+
Collection<PluginData> pluginData,
54+
Map<String, String> pluginPolicyPatches,
55+
String version
56+
) throws IOException {
5457
Map<String, Policy> pluginPolicies = new HashMap<>(pluginData.size());
5558
for (var entry : pluginData) {
5659
Path pluginRoot = entry.pluginPath();
60+
Path policyFile = pluginRoot.resolve(POLICY_FILE_NAME);
5761
String pluginName = pluginRoot.getFileName().toString();
5862
final Set<String> moduleNames = getModuleNames(pluginRoot, entry.isModular());
5963

60-
var overriddenPolicy = parseEncodedPolicyIfExists(
61-
overrides.get(pluginName),
64+
var pluginPolicyPatch = parseEncodedPolicyIfExists(
65+
pluginPolicyPatches.get(pluginName),
6266
version,
6367
entry.isExternalPlugin(),
6468
pluginName,
6569
moduleNames
6670
);
67-
if (overriddenPolicy != null) {
68-
pluginPolicies.put(pluginName, overriddenPolicy);
69-
} else {
70-
Path policyFile = pluginRoot.resolve(POLICY_FILE_NAME);
71-
var policy = parsePolicyIfExists(pluginName, policyFile, entry.isExternalPlugin());
72-
validatePolicyScopes(pluginName, policy, moduleNames, policyFile.toString());
73-
pluginPolicies.put(pluginName, policy);
74-
}
71+
var pluginPolicy = parsePolicyIfExists(pluginName, policyFile, entry.isExternalPlugin());
72+
validatePolicyScopes(pluginName, pluginPolicy, moduleNames, policyFile.toString());
73+
74+
pluginPolicies.put(
75+
pluginName,
76+
pluginPolicyPatch == null
77+
? pluginPolicy
78+
: new Policy(pluginPolicy.name(), PolicyUtils.mergeScopes(pluginPolicy.scopes(), pluginPolicyPatch.scopes()))
79+
);
7580
}
7681
return pluginPolicies;
7782
}

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static TransportVersion def(int id) {
187187
public static final TransportVersion ML_INFERENCE_DEEPSEEK = def(9_029_00_0);
188188
public static final TransportVersion ESQL_FAILURE_FROM_REMOTE = def(9_030_00_0);
189189
public static final TransportVersion INDEX_RESHARDING_METADATA = def(9_031_0_00);
190+
public static final TransportVersion INFERENCE_MODEL_REGISTRY_METADATA = def(9_032_0_00);
190191

191192
/*
192193
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
*/
8787
class Elasticsearch {
8888

89-
private static final String PLUGIN_POLICY_OVERRIDE_PREFIX = "es.entitlements.policy.";
90-
private static final String SERVER_POLICY_OVERRIDE = "es.entitlements.server_policy";
89+
private static final String POLICY_PATCH_PREFIX = "es.entitlements.policy.";
90+
private static final String SERVER_POLICY_PATCH_NAME = POLICY_PATCH_PREFIX + "server";
9191

9292
/**
9393
* Main entry point for starting elasticsearch.
@@ -253,10 +253,10 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
253253
.map(bundle -> new PolicyUtils.PluginData(bundle.getDir(), bundle.pluginDescriptor().isModular(), true))
254254
).toList();
255255

256-
var pluginPolicyOverrides = collectPluginPolicyOverrides(modulesBundles, pluginsBundles, logger);
257-
var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyOverrides, Build.current().version());
256+
var pluginPolicyPatches = collectPluginPolicyPatches(modulesBundles, pluginsBundles, logger);
257+
var pluginPolicies = PolicyUtils.createPluginPolicies(pluginData, pluginPolicyPatches, Build.current().version());
258258
var serverPolicyPatch = PolicyUtils.parseEncodedPolicyIfExists(
259-
System.getProperty(SERVER_POLICY_OVERRIDE),
259+
System.getProperty(SERVER_POLICY_PATCH_NAME),
260260
Build.current().version(),
261261
false,
262262
"server",
@@ -331,33 +331,36 @@ private static void logSystemInfo() {
331331
}
332332
}
333333

334-
private static Map<String, String> collectPluginPolicyOverrides(
334+
private static Map<String, String> collectPluginPolicyPatches(
335335
Set<PluginBundle> modulesBundles,
336336
Set<PluginBundle> pluginsBundles,
337337
Logger logger
338338
) {
339-
var policyOverrides = new HashMap<String, String>();
339+
var policyPatches = new HashMap<String, String>();
340340
var systemProperties = BootstrapInfo.getSystemProperties();
341341
systemProperties.keys().asIterator().forEachRemaining(key -> {
342342
var value = systemProperties.get(key);
343-
if (key instanceof String k && k.startsWith(PLUGIN_POLICY_OVERRIDE_PREFIX) && value instanceof String v) {
344-
policyOverrides.put(k.substring(PLUGIN_POLICY_OVERRIDE_PREFIX.length()), v);
343+
if (key instanceof String k
344+
&& value instanceof String v
345+
&& k.startsWith(POLICY_PATCH_PREFIX)
346+
&& k.equals(SERVER_POLICY_PATCH_NAME) == false) {
347+
policyPatches.put(k.substring(POLICY_PATCH_PREFIX.length()), v);
345348
}
346349
});
347350
var pluginNames = Stream.concat(modulesBundles.stream(), pluginsBundles.stream())
348351
.map(bundle -> bundle.pluginDescriptor().getName())
349352
.collect(Collectors.toUnmodifiableSet());
350353

351-
for (var overriddenPluginName : policyOverrides.keySet()) {
352-
if (pluginNames.contains(overriddenPluginName) == false) {
354+
for (var patchedPluginName : policyPatches.keySet()) {
355+
if (pluginNames.contains(patchedPluginName) == false) {
353356
logger.warn(
354-
"Found command-line override for unknown plugin [{}] (available plugins: [{}])",
355-
overriddenPluginName,
357+
"Found command-line policy patch for unknown plugin [{}] (available plugins: [{}])",
358+
patchedPluginName,
356359
String.join(", ", pluginNames)
357360
);
358361
}
359362
}
360-
return policyOverrides;
363+
return policyPatches;
361364
}
362365

363366
private static class EntitlementSelfTester {

server/src/main/java/org/elasticsearch/common/ReferenceDocs.java

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import org.elasticsearch.Build;
1313
import org.elasticsearch.core.SuppressForbidden;
14-
import org.elasticsearch.core.UpdateForV9;
1514

1615
import java.io.BufferedReader;
1716
import java.io.FileNotFoundException;
@@ -28,7 +27,6 @@
2827
* {@link #toString()} yields (a string representation of) a URL for the relevant docs. Links are defined in the resource file
2928
* {@code reference-docs-links.txt} which must include definitions for exactly the set of values of this enum.
3029
*/
31-
@UpdateForV9(owner = UpdateForV9.Owner.DOCS) // the docs are completely different in v9 so these links all need fixing
3230
public enum ReferenceDocs {
3331
/*
3432
* Note that the docs subsystem parses {@code reference-docs-links.txt} differently. See {@code sub check_elasticsearch_links} in
@@ -89,7 +87,22 @@ public enum ReferenceDocs {
8987
// this comment keeps the ';' on the next line so every entry above has a trailing ',' which makes the diff for adding new links cleaner
9088
;
9189

92-
private static final Map<String, String> linksBySymbol;
90+
private static final Map<String, LinkComponents> linksBySymbol;
91+
92+
record LinkComponents(String path, String fragment) {
93+
static LinkComponents ofLink(String link) {
94+
if (link.indexOf('?') != -1) {
95+
throw new IllegalStateException("ReferenceDocs does not support links containing pre-existing query parameters: " + link);
96+
}
97+
98+
final var fragmentIndex = link.indexOf('#');
99+
if (fragmentIndex == -1) {
100+
return new LinkComponents(link, "");
101+
} else {
102+
return new LinkComponents(link.substring(0, fragmentIndex), link.substring(fragmentIndex));
103+
}
104+
}
105+
}
93106

94107
static {
95108
try (var resourceStream = readFromJarResourceUrl(ReferenceDocs.class.getResource("reference-docs-links.txt"))) {
@@ -106,30 +119,17 @@ public enum ReferenceDocs {
106119

107120
static final int SYMBOL_COLUMN_WIDTH = 64; // increase as needed to accommodate yet longer symbols
108121

109-
static Map<String, String> readLinksBySymbol(InputStream inputStream) throws IOException {
110-
final var padding = " ".repeat(SYMBOL_COLUMN_WIDTH);
111-
112-
record LinksBySymbolEntry(String symbol, String link) implements Map.Entry<String, String> {
113-
@Override
114-
public String getKey() {
115-
return symbol;
116-
}
117-
118-
@Override
119-
public String getValue() {
120-
return link;
121-
}
122-
123-
@Override
124-
public String setValue(String value) {
125-
assert false;
126-
throw new UnsupportedOperationException();
127-
}
128-
}
129-
130-
final var symbolCount = values().length;
131-
final var linksBySymbolEntries = new LinksBySymbolEntry[symbolCount];
122+
// exposed for tests
123+
@SuppressWarnings({ "unchecked", "rawtypes" })
124+
static Map<String, LinkComponents> readLinksBySymbol(InputStream inputStream) throws IOException {
125+
final var linksBySymbolEntries = new Map.Entry[values().length];
126+
createLinkComponentEntries(inputStream, linksBySymbolEntries);
127+
return Map.ofEntries(linksBySymbolEntries);
128+
}
132129

130+
private static void createLinkComponentEntries(InputStream inputStream, Map.Entry<?, ?>[] linksBySymbolEntries) throws IOException {
131+
final var padding = " ".repeat(SYMBOL_COLUMN_WIDTH);
132+
final var symbolCount = linksBySymbolEntries.length;
133133
try (var reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
134134
for (int i = 0; i < symbolCount; i++) {
135135
final var currentLine = reader.readLine();
@@ -158,15 +158,13 @@ public String setValue(String value) {
158158
"found auto-generated fragment ID in link [" + link + "] for [" + symbol + "] at line " + (i + 1)
159159
);
160160
}
161-
linksBySymbolEntries[i] = new LinksBySymbolEntry(symbol, link);
161+
linksBySymbolEntries[i] = Map.entry(symbol, LinkComponents.ofLink(link));
162162
}
163163

164164
if (reader.readLine() != null) {
165165
throw new IllegalStateException("unexpected trailing content at line " + (symbolCount + 1));
166166
}
167167
}
168-
169-
return Map.ofEntries(linksBySymbolEntries);
170168
}
171169

172170
/**
@@ -196,13 +194,14 @@ static String getVersionComponent(String version, boolean isSnapshot) {
196194
return UNRELEASED_VERSION_COMPONENT;
197195
}
198196
// Non-semantic, released version -> point to latest information (current release documentation, e.g.
199-
// https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-plugins.html)
197+
// https://www.elastic.co/docs/modules-plugins?version=current)
200198
return CURRENT_VERSION_COMPONENT;
201199
}
202200

203201
@Override
204202
public String toString() {
205-
return "https://www.elastic.co/guide/en/elasticsearch/reference/" + VERSION_COMPONENT + "/" + linksBySymbol.get(name());
203+
final var linkComponents = linksBySymbol.get(name());
204+
return "https://www.elastic.co/docs/" + linkComponents.path() + "?version=" + VERSION_COMPONENT + linkComponents.fragment();
206205
}
207206

208207
@SuppressForbidden(reason = "reads resource from jar")

0 commit comments

Comments
 (0)