-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Move tribe to a module #25778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move tribe to a module #25778
Changes from 6 commits
92b07cd
36454ec
462a600
e6064ea
fdcc93a
f290c59
e86a5cf
2025150
996d7d7
5b81192
e9c4519
be55c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.cluster; | ||
|
||
import org.elasticsearch.cluster.metadata.MetaData; | ||
|
||
/** | ||
* Interface to allow merging {@link org.elasticsearch.cluster.metadata.MetaData.Custom}. | ||
* When multiple Mergable Custom metadata of the same type are found (from underlying clusters), the | ||
* Custom metadata can be merged using {@link #merge(MetaData.Custom)}. | ||
* | ||
* @param <T> type of custom meta data | ||
*/ | ||
public interface MergableCustomMetaData<T extends MetaData.Custom> { | ||
|
||
/** | ||
* Merges this custom metadata with other, returning either this or <code>other</code> custom metadata. | ||
* This method should not mutate either <code>this</code> or the <code>other</code> custom metadata. | ||
* | ||
* @param other custom meta data | ||
* @return the same instance or <code>other</code> custom metadata based on implementation | ||
* if both the instances are considered equal, implementations should return this | ||
* instance to avoid redundant cluster state changes. | ||
*/ | ||
T merge(T other); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,6 @@ | |
import org.elasticsearch.transport.Transport; | ||
import org.elasticsearch.transport.TransportInterceptor; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.tribe.TribeService; | ||
import org.elasticsearch.usage.UsageService; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
|
||
|
@@ -153,6 +152,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
|
@@ -229,6 +229,7 @@ public static final Settings addNodeNameIfNeeded(Settings settings, final String | |
private final Collection<LifecycleComponent> pluginLifecycleComponents; | ||
private final LocalNodeFactory localNodeFactory; | ||
private final NodeService nodeService; | ||
private final List<Runnable> onStartedListeners = new CopyOnWriteArrayList<>(); | ||
|
||
/** | ||
* Constructs a node with the given settings. | ||
|
@@ -256,8 +257,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin> | |
Settings tmpSettings = Settings.builder().put(environment.settings()) | ||
.put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build(); | ||
|
||
tmpSettings = TribeService.processSettings(tmpSettings); | ||
|
||
// create the node environment as soon as possible, to recover the node id and enable logging | ||
try { | ||
nodeEnvironment = new NodeEnvironment(tmpSettings, environment); | ||
|
@@ -385,15 +384,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin> | |
.flatMap(p -> p.getNamedXContent().stream()), | ||
ClusterModule.getNamedXWriteables().stream()) | ||
.flatMap(Function.identity()).collect(toList())); | ||
final TribeService tribeService = | ||
new TribeService( | ||
settings, | ||
environment.configFile(), | ||
clusterService, | ||
nodeId, | ||
namedWriteableRegistry, | ||
(s, p) -> newTribeClientNode(s, classpathPlugins, p)); | ||
resourcesToClose.add(tribeService); | ||
modules.add(new RepositoriesModule(this.environment, pluginsService.filterPlugins(RepositoryPlugin.class), xContentRegistry)); | ||
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment, xContentRegistry); | ||
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry, | ||
|
@@ -449,6 +439,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin> | |
transportService, indicesService, pluginsService, circuitBreakerService, scriptModule.getScriptService(), | ||
httpServerTransport, ingestService, clusterService, settingsModule.getSettingsFilter()); | ||
modules.add(b -> { | ||
b.bind(NodeBuilder.class).toInstance(new NodeBuilder(this, classpathPlugins)); | ||
b.bind(Node.class).toInstance(this); | ||
b.bind(NodeService.class).toInstance(nodeService); | ||
b.bind(NamedXContentRegistry.class).toInstance(xContentRegistry); | ||
|
@@ -458,7 +449,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin> | |
b.bind(Environment.class).toInstance(this.environment); | ||
b.bind(ThreadPool.class).toInstance(threadPool); | ||
b.bind(NodeEnvironment.class).toInstance(nodeEnvironment); | ||
b.bind(TribeService.class).toInstance(tribeService); | ||
b.bind(ResourceWatcherService.class).toInstance(resourceWatcherService); | ||
b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService); | ||
b.bind(BigArrays.class).toInstance(bigArrays); | ||
|
@@ -527,6 +517,10 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin> | |
} | ||
} | ||
|
||
public void addOnStartedListener(Runnable runnable) { | ||
onStartedListeners.add(runnable); | ||
} | ||
|
||
// visible for testing | ||
static void warnIfPreRelease(final Version version, final boolean isSnapshot, final Logger logger) { | ||
if (!version.isRelease() || isSnapshot) { | ||
|
@@ -612,10 +606,6 @@ public Node start() throws NodeValidationException { | |
Discovery discovery = injector.getInstance(Discovery.class); | ||
clusterService.getMasterService().setClusterStatePublisher(discovery::publish); | ||
|
||
// start before the cluster service since it adds/removes initial Cluster state blocks | ||
final TribeService tribeService = injector.getInstance(TribeService.class); | ||
tribeService.start(); | ||
|
||
// Start the transport service now so the publish address will be added to the local disco node in ClusterService | ||
TransportService transportService = injector.getInstance(TransportService.class); | ||
transportService.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class)); | ||
|
@@ -682,10 +672,10 @@ public void onTimeout(TimeValue timeout) { | |
writePortsFile("transport", transport.boundAddress()); | ||
} | ||
|
||
// start nodes now, after the http server, because it may take some time | ||
tribeService.startNodes(); | ||
logger.info("started"); | ||
|
||
onStartedListeners.forEach(Runnable::run); | ||
|
||
return this; | ||
} | ||
|
||
|
@@ -696,7 +686,6 @@ private Node stop() { | |
Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings)); | ||
logger.info("stopping ..."); | ||
|
||
injector.getInstance(TribeService.class).stop(); | ||
injector.getInstance(ResourceWatcherService.class).stop(); | ||
if (NetworkModule.HTTP_ENABLED.get(settings)) { | ||
injector.getInstance(HttpServerTransport.class).stop(); | ||
|
@@ -744,7 +733,6 @@ public synchronized void close() throws IOException { | |
List<Closeable> toClose = new ArrayList<>(); | ||
StopWatch stopWatch = new StopWatch("node_close"); | ||
toClose.add(() -> stopWatch.start("tribe")); | ||
toClose.add(injector.getInstance(TribeService.class)); | ||
toClose.add(() -> stopWatch.stop().start("node_service")); | ||
toClose.add(nodeService); | ||
toClose.add(() -> stopWatch.stop().start("http")); | ||
|
@@ -920,8 +908,23 @@ private List<NetworkService.CustomNameResolver> getCustomNameResolvers(List<Disc | |
return customNameResolvers; | ||
} | ||
|
||
/** Constructs an internal node used as a client into a cluster fronted by this tribe node. */ | ||
protected Node newTribeClientNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins, Path configPath) { | ||
public static class NodeBuilder { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need this additional class? it's seem like users can provide all the stuff at once to the newNode method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this entire construct we can just subclass Node.java in the plugin / module and create a node via this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To play nicely with the |
||
|
||
private final Node node; | ||
private final Collection<Class<? extends Plugin>> classpathPlugins; | ||
|
||
public NodeBuilder(Node node, Collection<Class<? extends Plugin>> classpathPlugins) { | ||
this.node = node; | ||
this.classpathPlugins = classpathPlugins; | ||
} | ||
|
||
public Node newNode(Settings settings, Path configPath) { | ||
return node.newNode(settings, classpathPlugins, configPath); | ||
} | ||
} | ||
|
||
/** Constructs a new node based on the following settings. Overridden by tests */ | ||
protected Node newNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins, Path configPath) { | ||
return new Node(new Environment(settings, configPath), classpathPlugins); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our plugin API on the node level is pull based not push. Can we add a method to pull these from
ClusterPlugin.java
that way we are consistent and we fully control who calls this method.