Skip to content

Commit 92b07cd

Browse files
committed
move tribe to its own module
1 parent ff4a251 commit 92b07cd

File tree

16 files changed

+333
-143
lines changed

16 files changed

+333
-143
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotShardsService.java" checks="LineLength" />
419419
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]snapshots[/\\]SnapshotsService.java" checks="LineLength" />
420420
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]threadpool[/\\]ThreadPool.java" checks="LineLength" />
421-
<suppress files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeService.java" checks="LineLength" />
421+
<suppress files="modules[/\\]tribe[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeService.java" checks="LineLength" />
422422
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]apache[/\\]lucene[/\\]queries[/\\]BlendedTermQueryTests.java" checks="LineLength" />
423423
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]VersionTests.java" checks="LineLength" />
424424
<suppress files="core[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]action[/\\]RejectionActionIT.java" checks="LineLength" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.cluster;
21+
22+
import org.elasticsearch.cluster.metadata.MetaData;
23+
24+
/**
25+
* Interface to allow merging {@link org.elasticsearch.cluster.metadata.MetaData.Custom}.
26+
* When multiple Mergable Custom metadata of the same type are found (from underlying clusters), the
27+
* Custom metadata can be merged using {@link #merge(MetaData.Custom)}.
28+
*
29+
* @param <T> type of custom meta data
30+
*/
31+
public interface MergableCustomMetaData<T extends MetaData.Custom> {
32+
33+
/**
34+
* Merges this custom metadata with other, returning either this or <code>other</code> custom metadata.
35+
* This method should not mutate either <code>this</code> or the <code>other</code> custom metadata.
36+
*
37+
* @param other custom meta data
38+
* @return the same instance or <code>other</code> custom metadata based on implementation
39+
* if both the instances are considered equal, implementations should return this
40+
* instance to avoid redundant cluster state changes.
41+
*/
42+
T merge(T other);
43+
}

core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
7272
import org.elasticsearch.indices.recovery.RecoverySettings;
7373
import org.elasticsearch.indices.store.IndicesStore;
74-
import org.elasticsearch.ingest.IngestService;
7574
import org.elasticsearch.monitor.fs.FsService;
7675
import org.elasticsearch.monitor.jvm.JvmGcMonitorService;
7776
import org.elasticsearch.monitor.jvm.JvmService;
@@ -91,7 +90,6 @@
9190
import org.elasticsearch.transport.TcpTransport;
9291
import org.elasticsearch.transport.Transport;
9392
import org.elasticsearch.transport.TransportService;
94-
import org.elasticsearch.tribe.TribeService;
9593
import org.elasticsearch.watcher.ResourceWatcherService;
9694

9795
import java.util.Arrays;
@@ -369,13 +367,6 @@ public void apply(Settings value, Settings current, Settings previous) {
369367
ThreadContext.DEFAULT_HEADERS_SETTING,
370368
ESLoggerFactory.LOG_DEFAULT_LEVEL_SETTING,
371369
ESLoggerFactory.LOG_LEVEL_SETTING,
372-
TribeService.BLOCKS_METADATA_SETTING,
373-
TribeService.BLOCKS_WRITE_SETTING,
374-
TribeService.BLOCKS_WRITE_INDICES_SETTING,
375-
TribeService.BLOCKS_READ_INDICES_SETTING,
376-
TribeService.BLOCKS_METADATA_INDICES_SETTING,
377-
TribeService.ON_CONFLICT_SETTING,
378-
TribeService.TRIBE_NAME_SETTING,
379370
NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING,
380371
NodeEnvironment.ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING,
381372
OsService.REFRESH_INTERVAL_SETTING,

core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.xcontent.ToXContent;
2727
import org.elasticsearch.common.xcontent.XContentBuilder;
2828
import org.elasticsearch.common.xcontent.XContentType;
29-
import org.elasticsearch.tribe.TribeService;
3029

3130
import java.io.IOException;
3231
import java.util.Arrays;
@@ -49,8 +48,6 @@ public class SettingsModule implements Module {
4948
private final Set<String> settingsFilterPattern = new HashSet<>();
5049
private final Map<String, Setting<?>> nodeSettings = new HashMap<>();
5150
private final Map<String, Setting<?>> indexSettings = new HashMap<>();
52-
private static final Predicate<String> TRIBE_CLIENT_NODE_SETTINGS_PREDICATE = (s) -> s.startsWith("tribe.")
53-
&& TribeService.TRIBE_SETTING_KEYS.contains(s) == false;
5451
private final Logger logger;
5552
private final IndexScopedSettings indexScopedSettings;
5653
private final ClusterSettings clusterSettings;
@@ -135,9 +132,7 @@ public SettingsModule(Settings settings, List<Setting<?>> additionalSettings, Li
135132
}
136133
}
137134
// by now we are fully configured, lets check node level settings for unregistered index settings
138-
final Predicate<String> acceptOnlyClusterSettings = TRIBE_CLIENT_NODE_SETTINGS_PREDICATE.negate();
139-
clusterSettings.validate(settings.filter(acceptOnlyClusterSettings));
140-
validateTribeSettings(settings, clusterSettings);
135+
clusterSettings.validate(settings);
141136
this.settingsFilter = new SettingsFilter(settings, settingsFilterPattern);
142137
}
143138

@@ -195,20 +190,6 @@ private void registerSettingsFilter(String filter) {
195190
settingsFilterPattern.add(filter);
196191
}
197192

198-
private void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) {
199-
Map<String, Settings> groups = settings.filter(TRIBE_CLIENT_NODE_SETTINGS_PREDICATE).getGroups("tribe.", true);
200-
for (Map.Entry<String, Settings> tribeSettings : groups.entrySet()) {
201-
Settings thisTribesSettings = tribeSettings.getValue();
202-
for (Map.Entry<String, String> entry : thisTribesSettings.getAsMap().entrySet()) {
203-
try {
204-
clusterSettings.validate(entry.getKey(), thisTribesSettings);
205-
} catch (IllegalArgumentException ex) {
206-
throw new IllegalArgumentException("tribe." + tribeSettings.getKey() +" validation failed: "+ ex.getMessage(), ex);
207-
}
208-
}
209-
}
210-
}
211-
212193
public Settings getSettings() {
213194
return settings;
214195
}

core/src/main/java/org/elasticsearch/discovery/DiscoveryModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public DiscoveryModule(Settings settings, ThreadPool threadPool, TransportServic
8686
discoveryTypes.put("zen",
8787
() -> new ZenDiscovery(settings, threadPool, transportService, namedWriteableRegistry, masterService, clusterApplier,
8888
clusterSettings, hostsProvider, allocationService));
89-
discoveryTypes.put("tribe", () -> new TribeDiscovery(settings, transportService, masterService, clusterApplier));
9089
discoveryTypes.put("single-node", () -> new SingleNodeDiscovery(settings, transportService, masterService, clusterApplier));
9190
for (DiscoveryPlugin plugin : plugins) {
9291
plugin.getDiscoveryTypes(threadPool, transportService, namedWriteableRegistry,

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@
133133
import org.elasticsearch.transport.Transport;
134134
import org.elasticsearch.transport.TransportInterceptor;
135135
import org.elasticsearch.transport.TransportService;
136-
import org.elasticsearch.tribe.TribeService;
137136
import org.elasticsearch.usage.UsageService;
138137
import org.elasticsearch.watcher.ResourceWatcherService;
139138

@@ -153,6 +152,7 @@
153152
import java.util.Collections;
154153
import java.util.List;
155154
import java.util.Map;
155+
import java.util.concurrent.CopyOnWriteArrayList;
156156
import java.util.concurrent.CountDownLatch;
157157
import java.util.concurrent.TimeUnit;
158158
import java.util.function.Consumer;
@@ -229,6 +229,7 @@ public static final Settings addNodeNameIfNeeded(Settings settings, final String
229229
private final Collection<LifecycleComponent> pluginLifecycleComponents;
230230
private final LocalNodeFactory localNodeFactory;
231231
private final NodeService nodeService;
232+
private final List<Runnable> onStartedListeners = new CopyOnWriteArrayList<>();
232233

233234
/**
234235
* Constructs a node with the given settings.
@@ -256,8 +257,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
256257
Settings tmpSettings = Settings.builder().put(environment.settings())
257258
.put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build();
258259

259-
tmpSettings = TribeService.processSettings(tmpSettings);
260-
261260
// create the node environment as soon as possible, to recover the node id and enable logging
262261
try {
263262
nodeEnvironment = new NodeEnvironment(tmpSettings, environment);
@@ -385,15 +384,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
385384
.flatMap(p -> p.getNamedXContent().stream()),
386385
ClusterModule.getNamedXWriteables().stream())
387386
.flatMap(Function.identity()).collect(toList()));
388-
final TribeService tribeService =
389-
new TribeService(
390-
settings,
391-
environment.configFile(),
392-
clusterService,
393-
nodeId,
394-
namedWriteableRegistry,
395-
(s, p) -> newTribeClientNode(s, classpathPlugins, p));
396-
resourcesToClose.add(tribeService);
397387
modules.add(new RepositoriesModule(this.environment, pluginsService.filterPlugins(RepositoryPlugin.class), xContentRegistry));
398388
final MetaStateService metaStateService = new MetaStateService(settings, nodeEnvironment, xContentRegistry);
399389
final IndicesService indicesService = new IndicesService(settings, pluginsService, nodeEnvironment, xContentRegistry,
@@ -449,6 +439,7 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
449439
transportService, indicesService, pluginsService, circuitBreakerService, scriptModule.getScriptService(),
450440
httpServerTransport, ingestService, clusterService, settingsModule.getSettingsFilter());
451441
modules.add(b -> {
442+
b.bind(NodeBuilder.class).toInstance(new NodeBuilder(this, classpathPlugins));
452443
b.bind(Node.class).toInstance(this);
453444
b.bind(NodeService.class).toInstance(nodeService);
454445
b.bind(NamedXContentRegistry.class).toInstance(xContentRegistry);
@@ -458,7 +449,6 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
458449
b.bind(Environment.class).toInstance(this.environment);
459450
b.bind(ThreadPool.class).toInstance(threadPool);
460451
b.bind(NodeEnvironment.class).toInstance(nodeEnvironment);
461-
b.bind(TribeService.class).toInstance(tribeService);
462452
b.bind(ResourceWatcherService.class).toInstance(resourceWatcherService);
463453
b.bind(CircuitBreakerService.class).toInstance(circuitBreakerService);
464454
b.bind(BigArrays.class).toInstance(bigArrays);
@@ -527,6 +517,10 @@ protected Node(final Environment environment, Collection<Class<? extends Plugin>
527517
}
528518
}
529519

520+
public void addOnStartedListener(Runnable runnable) {
521+
onStartedListeners.add(runnable);
522+
}
523+
530524
// visible for testing
531525
static void warnIfPreRelease(final Version version, final boolean isSnapshot, final Logger logger) {
532526
if (!version.isRelease() || isSnapshot) {
@@ -612,10 +606,6 @@ public Node start() throws NodeValidationException {
612606
Discovery discovery = injector.getInstance(Discovery.class);
613607
clusterService.getMasterService().setClusterStatePublisher(discovery::publish);
614608

615-
// start before the cluster service since it adds/removes initial Cluster state blocks
616-
final TribeService tribeService = injector.getInstance(TribeService.class);
617-
tribeService.start();
618-
619609
// Start the transport service now so the publish address will be added to the local disco node in ClusterService
620610
TransportService transportService = injector.getInstance(TransportService.class);
621611
transportService.getTaskManager().setTaskResultsService(injector.getInstance(TaskResultsService.class));
@@ -682,10 +672,10 @@ public void onTimeout(TimeValue timeout) {
682672
writePortsFile("transport", transport.boundAddress());
683673
}
684674

685-
// start nodes now, after the http server, because it may take some time
686-
tribeService.startNodes();
687675
logger.info("started");
688676

677+
onStartedListeners.forEach(Runnable::run);
678+
689679
return this;
690680
}
691681

@@ -696,7 +686,6 @@ private Node stop() {
696686
Logger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings));
697687
logger.info("stopping ...");
698688

699-
injector.getInstance(TribeService.class).stop();
700689
injector.getInstance(ResourceWatcherService.class).stop();
701690
if (NetworkModule.HTTP_ENABLED.get(settings)) {
702691
injector.getInstance(HttpServerTransport.class).stop();
@@ -744,7 +733,6 @@ public synchronized void close() throws IOException {
744733
List<Closeable> toClose = new ArrayList<>();
745734
StopWatch stopWatch = new StopWatch("node_close");
746735
toClose.add(() -> stopWatch.start("tribe"));
747-
toClose.add(injector.getInstance(TribeService.class));
748736
toClose.add(() -> stopWatch.stop().start("node_service"));
749737
toClose.add(nodeService);
750738
toClose.add(() -> stopWatch.stop().start("http"));
@@ -920,8 +908,23 @@ private List<NetworkService.CustomNameResolver> getCustomNameResolvers(List<Disc
920908
return customNameResolvers;
921909
}
922910

923-
/** Constructs an internal node used as a client into a cluster fronted by this tribe node. */
924-
protected Node newTribeClientNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins, Path configPath) {
911+
public static class NodeBuilder {
912+
913+
private final Node node;
914+
private final Collection<Class<? extends Plugin>> classpathPlugins;
915+
916+
public NodeBuilder(Node node, Collection<Class<? extends Plugin>> classpathPlugins) {
917+
this.node = node;
918+
this.classpathPlugins = classpathPlugins;
919+
}
920+
921+
public Node newNode(Settings settings, Path configPath) {
922+
return node.newNode(settings, classpathPlugins, configPath);
923+
}
924+
}
925+
926+
/** Constructs a new node based on the following settings. Overridden by tests */
927+
protected Node newNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins, Path configPath) {
925928
return new Node(new Environment(settings, configPath), classpathPlugins);
926929
}
927930

modules/tribe/build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
esplugin {
21+
description 'Tribe module'
22+
classname 'org.elasticsearch.tribe.TribePlugin'
23+
}
24+
25+
compileJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"
26+
compileTestJava.options.compilerArgs << "-Xlint:-cast,-deprecation,-rawtypes,-try,-unchecked"

core/src/main/java/org/elasticsearch/discovery/TribeDiscovery.java renamed to modules/tribe/src/main/java/org/elasticsearch/tribe/TribeDiscovery.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.elasticsearch.discovery;
19+
package org.elasticsearch.tribe;
2020

2121
import org.elasticsearch.cluster.ClusterChangedEvent;
2222
import org.elasticsearch.cluster.ClusterName;
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.cluster.service.MasterService;
2929
import org.elasticsearch.common.inject.Inject;
3030
import org.elasticsearch.common.settings.Settings;
31+
import org.elasticsearch.discovery.Discovery;
3132
import org.elasticsearch.discovery.single.SingleNodeDiscovery;
3233
import org.elasticsearch.transport.TransportService;
3334

@@ -37,7 +38,7 @@
3738
import static org.elasticsearch.tribe.TribeService.TRIBE_WRITE_BLOCK;
3839

3940
/**
40-
* A {@link Discovery} implementation that is used by {@link org.elasticsearch.tribe.TribeService}. This implementation
41+
* A {@link Discovery} implementation that is used by {@link TribeService}. This implementation
4142
* doesn't support any clustering features. Most notably {@link #startInitialJoin()} does nothing and
4243
* {@link #publish(ClusterChangedEvent, AckListener)} delegates state updates directly to the
4344
* {@link org.elasticsearch.cluster.service.ClusterApplierService}.

0 commit comments

Comments
 (0)