|
14 | 14 | import org.elasticsearch.client.Client;
|
15 | 15 | import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
16 | 16 | import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
|
| 17 | +import org.elasticsearch.cluster.node.DiscoveryNode; |
17 | 18 | import org.elasticsearch.cluster.node.DiscoveryNodes;
|
18 | 19 | import org.elasticsearch.cluster.service.ClusterService;
|
19 | 20 | import org.elasticsearch.common.inject.Module;
|
20 | 21 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
21 | 22 | import org.elasticsearch.common.settings.ClusterSettings;
|
22 | 23 | import org.elasticsearch.common.settings.IndexScopedSettings;
|
23 | 24 | import org.elasticsearch.common.settings.Setting;
|
| 25 | +import org.elasticsearch.common.settings.Setting.Property; |
24 | 26 | import org.elasticsearch.common.settings.Settings;
|
25 | 27 | import org.elasticsearch.common.settings.SettingsFilter;
|
26 | 28 | import org.elasticsearch.common.settings.SettingsModule;
|
|
40 | 42 | import org.elasticsearch.threadpool.ExecutorBuilder;
|
41 | 43 | import org.elasticsearch.threadpool.FixedExecutorBuilder;
|
42 | 44 | import org.elasticsearch.threadpool.ThreadPool;
|
| 45 | +import org.elasticsearch.transport.RemoteClusterService; |
43 | 46 | import org.elasticsearch.watcher.ResourceWatcherService;
|
44 | 47 | import org.elasticsearch.xpack.core.XPackPlugin;
|
45 | 48 | import org.elasticsearch.xpack.core.XPackSettings;
|
@@ -138,6 +141,23 @@ public class Transform extends Plugin implements SystemIndexPlugin, PersistentTa
|
138 | 141 | Setting.Property.Dynamic
|
139 | 142 | );
|
140 | 143 |
|
| 144 | + /** |
| 145 | + * Node attributes for transform, automatically created and retrievable via cluster state. |
| 146 | + * These attributes should never be set directly, use the node setting counter parts instead. |
| 147 | + */ |
| 148 | + public static final String TRANSFORM_ENABLED_NODE_ATTR = "transform.node"; |
| 149 | + public static final String TRANSFORM_REMOTE_ENABLED_NODE_ATTR = "transform.remote_connect"; |
| 150 | + |
| 151 | + /** |
| 152 | + * Setting whether transform (the coordinator task) can run on this node and REST API's are available, |
| 153 | + * respects xpack.transform.enabled (for the whole plugin) as fallback |
| 154 | + */ |
| 155 | + public static final Setting<Boolean> TRANSFORM_ENABLED_NODE = Setting.boolSetting( |
| 156 | + "node.transform", |
| 157 | + settings -> Boolean.toString(XPackSettings.TRANSFORM_ENABLED.get(settings) && DiscoveryNode.isDataNode(settings)), |
| 158 | + Property.NodeScope |
| 159 | + ); |
| 160 | + |
141 | 161 | public Transform(Settings settings) {
|
142 | 162 | this.settings = settings;
|
143 | 163 | this.enabled = XPackSettings.TRANSFORM_ENABLED.get(settings);
|
@@ -231,7 +251,13 @@ public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
|
231 | 251 | return emptyList();
|
232 | 252 | }
|
233 | 253 |
|
234 |
| - FixedExecutorBuilder indexing = new FixedExecutorBuilder(settings, TASK_THREAD_POOL_NAME, 4, 4, "transform.task_thread_pool"); |
| 254 | + FixedExecutorBuilder indexing = new FixedExecutorBuilder( |
| 255 | + settings, |
| 256 | + TASK_THREAD_POOL_NAME, |
| 257 | + 4, |
| 258 | + 4, |
| 259 | + "transform.task_thread_pool" |
| 260 | + ); |
235 | 261 |
|
236 | 262 | return Collections.singletonList(indexing);
|
237 | 263 | }
|
@@ -304,13 +330,44 @@ public List<PersistentTasksExecutor<?>> getPersistentTasksExecutor(
|
304 | 330 | // the transform services should have been created
|
305 | 331 | assert transformServices.get() != null;
|
306 | 332 |
|
307 |
| - return Collections.singletonList(new TransformPersistentTasksExecutor(client, transformServices.get(), threadPool, clusterService, |
308 |
| - settingsModule.getSettings(), expressionResolver)); |
| 333 | + return Collections.singletonList( |
| 334 | + new TransformPersistentTasksExecutor( |
| 335 | + client, |
| 336 | + transformServices.get(), |
| 337 | + threadPool, |
| 338 | + clusterService, |
| 339 | + settingsModule.getSettings(), |
| 340 | + expressionResolver |
| 341 | + ) |
| 342 | + ); |
309 | 343 | }
|
310 | 344 |
|
311 | 345 | @Override
|
312 | 346 | public List<Setting<?>> getSettings() {
|
313 |
| - return Collections.singletonList(NUM_FAILURE_RETRIES_SETTING); |
| 347 | + return Collections.unmodifiableList(Arrays.asList(TRANSFORM_ENABLED_NODE, NUM_FAILURE_RETRIES_SETTING)); |
| 348 | + } |
| 349 | + |
| 350 | + @Override |
| 351 | + public Settings additionalSettings() { |
| 352 | + String transformEnabledNodeAttribute = "node.attr." + TRANSFORM_ENABLED_NODE_ATTR; |
| 353 | + String transformRemoteEnabledNodeAttribute = "node.attr." + TRANSFORM_REMOTE_ENABLED_NODE_ATTR; |
| 354 | + |
| 355 | + if (settings.get(transformEnabledNodeAttribute) != null || settings.get(transformRemoteEnabledNodeAttribute) != null) { |
| 356 | + throw new IllegalArgumentException( |
| 357 | + "Directly setting transform node attributes is not permitted, please use the documented node settings instead" |
| 358 | + ); |
| 359 | + } |
| 360 | + |
| 361 | + if (enabled == false) { |
| 362 | + return Settings.EMPTY; |
| 363 | + } |
| 364 | + |
| 365 | + Settings.Builder additionalSettings = Settings.builder(); |
| 366 | + |
| 367 | + additionalSettings.put(transformEnabledNodeAttribute, TRANSFORM_ENABLED_NODE.get(settings)); |
| 368 | + additionalSettings.put(transformRemoteEnabledNodeAttribute, RemoteClusterService.ENABLE_REMOTE_CLUSTERS.get(settings)); |
| 369 | + |
| 370 | + return additionalSettings.build(); |
314 | 371 | }
|
315 | 372 |
|
316 | 373 | @Override
|
|
0 commit comments