Skip to content

Commit

Permalink
Move back InferenceServiceRegistry and ModelRegistry to inference plu…
Browse files Browse the repository at this point in the history
…gin, reverting elastic#105012
  • Loading branch information
carlosdelest committed Apr 5, 2024
1 parent ddb1b74 commit fa967cf
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 326 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,49 @@

import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class InferenceServiceRegistry implements Closeable {

private final Map<String, InferenceService> services;
private final List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();

public InferenceServiceRegistry(
List<InferenceServiceExtension> inferenceServicePlugins,
InferenceServiceExtension.InferenceServiceFactoryContext factoryContext
) {
// TODO check names are unique
services = inferenceServicePlugins.stream()
.flatMap(r -> r.getInferenceServiceFactories().stream())
.map(factory -> factory.create(factoryContext))
.collect(Collectors.toMap(InferenceService::name, Function.identity()));
}

public interface InferenceServiceRegistry extends Closeable {
void init(Client client);

Map<String, InferenceService> getServices();

Optional<InferenceService> getService(String serviceName);

List<NamedWriteableRegistry.Entry> getNamedWriteables();

class NoopInferenceServiceRegistry implements InferenceServiceRegistry {
public NoopInferenceServiceRegistry() {}
public void init(Client client) {
services.values().forEach(s -> s.init(client));
}

@Override
public void init(Client client) {}
public Map<String, InferenceService> getServices() {
return services;
}

@Override
public Map<String, InferenceService> getServices() {
return Map.of();
}
public Optional<InferenceService> getService(String serviceName) {
return Optional.ofNullable(services.get(serviceName));
}

@Override
public Optional<InferenceService> getService(String serviceName) {
return Optional.empty();
}
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
return namedWriteables;
}

@Override
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
return List.of();
@Override
public void close() throws IOException {
for (var service : services.values()) {
service.close();
}

@Override
public void close() throws IOException {}
}
}

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions server/src/main/java/org/elasticsearch/node/NodeConstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@
import org.elasticsearch.indices.recovery.plan.PeerOnlyRecoveryPlannerService;
import org.elasticsearch.indices.recovery.plan.RecoveryPlannerService;
import org.elasticsearch.indices.recovery.plan.ShardSnapshotsService;
import org.elasticsearch.inference.InferenceServiceRegistry;
import org.elasticsearch.inference.ModelRegistry;
import org.elasticsearch.ingest.IngestService;
import org.elasticsearch.monitor.MonitorService;
import org.elasticsearch.monitor.fs.FsHealthService;
Expand All @@ -147,7 +145,6 @@
import org.elasticsearch.plugins.ClusterPlugin;
import org.elasticsearch.plugins.DiscoveryPlugin;
import org.elasticsearch.plugins.HealthPlugin;
import org.elasticsearch.plugins.InferenceRegistryPlugin;
import org.elasticsearch.plugins.IngestPlugin;
import org.elasticsearch.plugins.MapperPlugin;
import org.elasticsearch.plugins.MetadataUpgrader;
Expand Down Expand Up @@ -1114,18 +1111,6 @@ record PluginServiceInstances(
);
}

// Register noop versions of inference services if Inference plugin is not available
Optional<InferenceRegistryPlugin> inferenceRegistryPlugin = getSinglePlugin(InferenceRegistryPlugin.class);
modules.bindToInstance(
InferenceServiceRegistry.class,
inferenceRegistryPlugin.map(InferenceRegistryPlugin::getInferenceServiceRegistry)
.orElse(new InferenceServiceRegistry.NoopInferenceServiceRegistry())
);
modules.bindToInstance(
ModelRegistry.class,
inferenceRegistryPlugin.map(InferenceRegistryPlugin::getModelRegistry).orElse(new ModelRegistry.NoopModelRegistry())
);

injector = modules.createInjector();

postInjection(clusterModule, actionModule, clusterService, transportService, featureService);
Expand Down

This file was deleted.

Loading

0 comments on commit fa967cf

Please sign in to comment.