Skip to content

Commit

Permalink
Fix detection of installed components
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Feb 1, 2024
1 parent dfa26ec commit 6539c2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions server/src/main/java/org/elasticsearch/node/NodeConstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1090,10 +1090,12 @@ record PluginServiceInstances(
}

// Register noop versions of inference services if Inference plugin is not available
if (pluginComponents.stream().noneMatch(p -> p instanceof InferenceServiceRegistry)) {
if (isPluginComponentDefined(pluginComponents, InferenceServiceRegistry.class) == false) {
logger.warn("Inference service is not available");
modules.bindToInstance(InferenceServiceRegistry.class, new InferenceServiceRegistry.NoopInferenceServiceRegistry());
}
if (pluginComponents.stream().noneMatch(p -> p instanceof ModelRegistry)) {
if (isPluginComponentDefined(pluginComponents, ModelRegistry.class) == false) {
logger.warn("Model registry is not available");
modules.bindToInstance(ModelRegistry.class, new ModelRegistry.NoopModelRegistry());
}

Expand All @@ -1102,6 +1104,12 @@ record PluginServiceInstances(
postInjection(clusterModule, actionModule, clusterService, transportService, featureService);
}

private static boolean isPluginComponentDefined(Collection<?> pluginComponents, Class<?> clazz) {
return pluginComponents.stream()
.map(p -> p instanceof PluginComponentBinding ? ((PluginComponentBinding) p).impl() : p)
.anyMatch(p -> clazz.isAssignableFrom(clazz));
}

private ClusterService createClusterService(SettingsModule settingsModule, ThreadPool threadPool, TaskManager taskManager) {
ClusterService clusterService = new ClusterService(
settingsModule.getSettings(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ public Collection<?> createComponents(PluginServices services) {
registry.init(services.client());
inferenceServiceRegistry.set(registry);

return List.of(new PluginComponentBinding<>(ModelRegistry.class, modelRegistry), registry);
return List.of(
new PluginComponentBinding<>(ModelRegistry.class, modelRegistry),
new PluginComponentBinding<>(InferenceServiceRegistry.class, registry)
);
}

@Override
public void loadExtensions(ExtensionLoader loader) {
inferenceServiceExtensions = loader.loadExtensions(InferenceServiceExtension.class);
loader.loadExtensions(ModelRegistry.class);
}

public List<InferenceServiceExtension.Factory> getInferenceServiceFactories() {
Expand Down

0 comments on commit 6539c2a

Please sign in to comment.