From 818a9eefb2338e6193e1d98563d5c35359e9bc6f Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 2 Feb 2016 11:32:44 +0100 Subject: [PATCH] Make settings validation strict This commit enableds strict settings validation on node startup. All settings passed to elasticsearch either through system properties, yaml files or any other way to pass settings must be registered and valid. Settings that are unknown ie. due to typos or due to deprecation or removal will cause the node to NOT start up. Plugins have to declare all their settings on the `SettingsModule#registerSetting` and settings for plugins that are not installed must be removed. This commit also removes the ability to specify the nodes name via `-Des.name` or just `name` in the configuration files. The node name must be prefixed with the node prexif like `node.name: Boom`. Left over usage of `name` will also cause startup to fail. --- .../elasticsearch/bootstrap/Bootstrap.java | 2 +- .../TransportClientNodesService.java | 3 +- .../service/InternalClusterService.java | 2 +- .../common/component/AbstractComponent.java | 2 +- .../common/inject/AbstractModule.java | 1 + .../elasticsearch/common/logging/Loggers.java | 2 +- .../common/network/NetworkModule.java | 5 +- .../common/settings/ClusterSettings.java | 467 +++++++++--------- .../common/settings/SettingsModule.java | 33 +- .../common/util/concurrent/EsExecutors.java | 2 +- .../elasticsearch/index/IndexSettings.java | 2 +- .../java/org/elasticsearch/node/Node.java | 18 +- .../internal/InternalSettingsPreparer.java | 18 +- .../elasticsearch/plugins/PluginsService.java | 7 +- .../rest/action/main/RestMainAction.java | 5 +- .../elasticsearch/script/ScriptModule.java | 27 +- .../elasticsearch/threadpool/ThreadPool.java | 4 +- .../org/elasticsearch/tribe/TribeService.java | 23 +- .../admin/cluster/node/tasks/TasksIT.java | 2 +- .../node/tasks/TransportTasksActionTests.java | 4 +- .../shards/IndicesShardStoreRequestIT.java | 2 +- .../ingest/SimulateExecutionServiceTests.java | 2 +- .../client/AbstractClientHeadersTestCase.java | 2 +- .../transport/TransportClientRetryIT.java | 2 +- .../common/settings/SettingsModuleTests.java | 31 +- .../RecoveryBackwardsCompatibilityIT.java | 1 - .../gateway/RecoveryFromGatewayIT.java | 1 - .../index/query/AbstractQueryTestCase.java | 60 +-- .../InternalSettingsPreparerTests.java | 4 +- .../script/NativeScriptTests.java | 5 +- .../bucket/DateHistogramOffsetIT.java | 8 + .../builder/SearchSourceBuilderTests.java | 2 +- .../AbstractSnapshotIntegTestCase.java | 2 +- .../ThreadPoolSerializationTests.java | 2 +- .../UpdateThreadPoolSettingsTests.java | 18 +- .../NettySizeHeaderFrameDecoderTests.java | 2 +- .../java/org/elasticsearch/tribe/TribeIT.java | 1 - .../expression/IndexedExpressionTests.java | 1 - .../messy/tests/IndexedScriptTests.java | 3 - .../messy/tests/TemplateQueryParserTests.java | 5 +- .../discovery/azure/AzureDiscoveryPlugin.java | 5 + .../azure/AzureRepositoryPlugin.java | 11 + .../EvilInternalSettingsPreparerTests.java | 147 ------ .../elasticsearch/tribe/TribeUnitTests.java | 4 +- .../smoketest/ESSmokeClientTestCase.java | 2 +- .../test/ExternalTestCluster.java | 2 +- .../test/InternalTestCluster.java | 8 +- .../test/tasks/MockTaskManager.java | 3 +- .../transport/AssertingLocalTransport.java | 6 + .../test/transport/MockTransportService.java | 7 +- 50 files changed, 457 insertions(+), 521 deletions(-) delete mode 100644 qa/evil-tests/src/test/java/org/elasticsearch/node/internal/EvilInternalSettingsPreparerTests.java diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 5aa760dc9f6..ed99f9b3894 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -314,7 +314,7 @@ final class Bootstrap { } ESLogger logger = Loggers.getLogger(Bootstrap.class); if (INSTANCE.node != null) { - logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("name")); + logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("node.name")); } // HACK, it sucks to do this, but we will run users out of disk space otherwise if (e instanceof CreationException) { diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java index f9ee988d811..1e605b9de06 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClientNodesService.java @@ -103,6 +103,7 @@ public class TransportClientNodesService extends AbstractComponent { public static final Setting CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL = Setting.positiveTimeSetting("client.transport.nodes_sampler_interval", timeValueSeconds(5), false, Setting.Scope.CLUSTER); public static final Setting CLIENT_TRANSPORT_PING_TIMEOUT = Setting.positiveTimeSetting("client.transport.ping_timeout", timeValueSeconds(5), false, Setting.Scope.CLUSTER); public static final Setting CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME = Setting.boolSetting("client.transport.ignore_cluster_name", false, false, Setting.Scope.CLUSTER); + public static final Setting CLIENT_TRANSPORT_SNIFF = Setting.boolSetting("client.transport.sniff", false, false, Setting.Scope.CLUSTER); @Inject public TransportClientNodesService(Settings settings, ClusterName clusterName, TransportService transportService, @@ -121,7 +122,7 @@ public class TransportClientNodesService extends AbstractComponent { logger.debug("node_sampler_interval[" + nodesSamplerInterval + "]"); } - if (this.settings.getAsBoolean("client.transport.sniff", false)) { + if (CLIENT_TRANSPORT_SNIFF.get(this.settings)) { this.nodesSampler = new SniffNodesSampler(); } else { this.nodesSampler = new SimpleNodeSampler(); diff --git a/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java index b592eeb1469..fa43c520642 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/InternalClusterService.java @@ -196,7 +196,7 @@ public class InternalClusterService extends AbstractLifecycleComponent HTTP_ENABLED = Setting.boolSetting("http.enabled", true, false, Scope.CLUSTER); + public static final Setting TRANSPORT_SERVICE_TYPE_SETTING = Setting.simpleString("transport.service.type", false, Scope.CLUSTER); + public static final Setting TRANSPORT_TYPE_SETTING = Setting.simpleString("transport.type", false, Scope.CLUSTER); + + private static final List> builtinRestHandlers = Arrays.asList( RestMainAction.class, diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index ea16c6aabd6..c0a84ade9e0 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -58,7 +58,6 @@ import org.elasticsearch.env.NodeEnvironment; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.gateway.PrimaryShardAllocator; import org.elasticsearch.http.HttpTransportSettings; -import org.elasticsearch.http.netty.NettyHttpServerTransport; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.store.IndexStoreConfig; import org.elasticsearch.indices.analysis.HunspellService; @@ -76,6 +75,7 @@ import org.elasticsearch.monitor.os.OsService; import org.elasticsearch.monitor.process.ProcessService; import org.elasticsearch.node.Node; import org.elasticsearch.node.internal.InternalSettingsPreparer; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.repositories.fs.FsRepository; import org.elasticsearch.repositories.uri.URLRepository; import org.elasticsearch.rest.BaseRestHandler; @@ -114,9 +114,9 @@ public final class ClusterSettings extends AbstractScopedSettings { @Override public boolean hasChanged(Settings current, Settings previous) { return current.filter(loggerPredicate).getAsMap().equals(previous.filter(loggerPredicate).getAsMap()) == false; - } + } - @Override + @Override public Settings getValue(Settings current, Settings previous) { Settings.Builder builder = Settings.builder(); builder.put(current.filter(loggerPredicate).getAsMap()); @@ -132,7 +132,7 @@ public final class ClusterSettings extends AbstractScopedSettings { return builder.build(); } - @Override + @Override public void apply(Settings value, Settings current, Settings previous) { for (String key : value.getAsMap().keySet()) { assert loggerPredicate.test(key); @@ -143,231 +143,242 @@ public final class ClusterSettings extends AbstractScopedSettings { } else { ESLoggerFactory.getLogger(component).setLevel(value.get(key)); } + } + } } - } - }; + + ; public static Set> BUILT_IN_CLUSTER_SETTINGS = Collections.unmodifiableSet(new HashSet<>( - Arrays.asList(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING, - TransportClientNodesService.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL, // TODO these transport client settings are kind of odd here and should only be valid if we are a transport client - TransportClientNodesService.CLIENT_TRANSPORT_PING_TIMEOUT, - TransportClientNodesService.CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME, - AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING, - BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, - BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, - BalancedShardsAllocator.THRESHOLD_SETTING, - ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING, - ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING, - EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING, - EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING, - ZenDiscovery.REJOIN_ON_MASTER_GONE_SETTING, - FilterAllocationDecider.CLUSTER_ROUTING_INCLUDE_GROUP_SETTING, - FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING, - FilterAllocationDecider.CLUSTER_ROUTING_REQUIRE_GROUP_SETTING, - FsRepository.REPOSITORIES_CHUNK_SIZE_SETTING, - FsRepository.REPOSITORIES_COMPRESS_SETTING, - FsRepository.REPOSITORIES_LOCATION_SETTING, - IndexStoreConfig.INDICES_STORE_THROTTLE_TYPE_SETTING, - IndexStoreConfig.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING, - IndicesQueryCache.INDICES_CACHE_QUERY_SIZE_SETTING, - IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING, - IndicesTTLService.INDICES_TTL_INTERVAL_SETTING, - MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING, - MetaData.SETTING_READ_ONLY_SETTING, - RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING, - RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC_SETTING, - RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING, - RecoverySettings.INDICES_RECOVERY_ACTIVITY_TIMEOUT_SETTING, - RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT_SETTING, - RecoverySettings.INDICES_RECOVERY_INTERNAL_LONG_ACTION_TIMEOUT_SETTING, - ThreadPool.THREADPOOL_GROUP_SETTING, - ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING, - ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING, - ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING, - ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING, - DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING, - DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING, - DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, - DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING, - DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING, - InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, - InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, - SnapshotInProgressAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SNAPSHOT_RELOCATION_ENABLED_SETTING, - DestructiveOperations.REQUIRES_NAME_SETTING, - DiscoverySettings.PUBLISH_TIMEOUT_SETTING, - DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING, - DiscoverySettings.COMMIT_TIMEOUT_SETTING, - DiscoverySettings.NO_MASTER_BLOCK_SETTING, - GatewayService.EXPECTED_DATA_NODES_SETTING, - GatewayService.EXPECTED_MASTER_NODES_SETTING, - GatewayService.EXPECTED_NODES_SETTING, - GatewayService.RECOVER_AFTER_DATA_NODES_SETTING, - GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING, - GatewayService.RECOVER_AFTER_NODES_SETTING, - GatewayService.RECOVER_AFTER_TIME_SETTING, - NetworkModule.HTTP_ENABLED, - HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS, - HttpTransportSettings.SETTING_CORS_ENABLED, - HttpTransportSettings.SETTING_CORS_MAX_AGE, - HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED, - HttpTransportSettings.SETTING_PIPELINING, - HttpTransportSettings.SETTING_CORS_ALLOW_ORIGIN, - HttpTransportSettings.SETTING_HTTP_PORT, - HttpTransportSettings.SETTING_HTTP_PUBLISH_PORT, - HttpTransportSettings.SETTING_PIPELINING_MAX_EVENTS, - HttpTransportSettings.SETTING_HTTP_COMPRESSION, - HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL, - HttpTransportSettings.SETTING_CORS_ALLOW_METHODS, - HttpTransportSettings.SETTING_CORS_ALLOW_HEADERS, - HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED, - HttpTransportSettings.SETTING_HTTP_MAX_CONTENT_LENGTH, - HttpTransportSettings.SETTING_HTTP_MAX_CHUNK_SIZE, - HttpTransportSettings.SETTING_HTTP_MAX_HEADER_SIZE, - HttpTransportSettings.SETTING_HTTP_MAX_INITIAL_LINE_LENGTH, - HttpTransportSettings.SETTING_HTTP_RESET_COOKIES, - HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, - HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, - HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, - HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, - HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, - InternalClusterService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, - SearchService.DEFAULT_SEARCH_TIMEOUT_SETTING, - ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING, - TransportService.TRACE_LOG_EXCLUDE_SETTING, - TransportService.TRACE_LOG_INCLUDE_SETTING, - TransportCloseIndexAction.CLUSTER_INDICES_CLOSE_ENABLE_SETTING, - ShardsLimitAllocationDecider.CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, - InternalClusterService.CLUSTER_SERVICE_RECONNECT_INTERVAL_SETTING, - HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING, - HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING, - Transport.TRANSPORT_TCP_COMPRESS, - TransportSettings.TRANSPORT_PROFILES_SETTING, - TransportSettings.HOST, - TransportSettings.PUBLISH_HOST, - TransportSettings.BIND_HOST, - TransportSettings.PUBLISH_PORT, - TransportSettings.PORT, - NettyTransport.WORKER_COUNT, - NettyTransport.CONNECTIONS_PER_NODE_RECOVERY, - NettyTransport.CONNECTIONS_PER_NODE_BULK, - NettyTransport.CONNECTIONS_PER_NODE_REG, - NettyTransport.CONNECTIONS_PER_NODE_STATE, - NettyTransport.CONNECTIONS_PER_NODE_PING, - NettyTransport.PING_SCHEDULE, - NettyTransport.TCP_BLOCKING_CLIENT, - NettyTransport.TCP_CONNECT_TIMEOUT, - NettyTransport.NETTY_MAX_CUMULATION_BUFFER_CAPACITY, - NettyTransport.NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS, - NettyTransport.NETTY_RECEIVE_PREDICTOR_SIZE, - NettyTransport.NETTY_RECEIVE_PREDICTOR_MIN, - NettyTransport.NETTY_RECEIVE_PREDICTOR_MAX, - NetworkService.NETWORK_SERVER, - NettyTransport.NETTY_BOSS_COUNT, - NettyTransport.TCP_NO_DELAY, - NettyTransport.TCP_KEEP_ALIVE, - NettyTransport.TCP_REUSE_ADDRESS, - NettyTransport.TCP_SEND_BUFFER_SIZE, - NettyTransport.TCP_RECEIVE_BUFFER_SIZE, - NettyTransport.TCP_BLOCKING_SERVER, - NetworkService.GLOBAL_NETWORK_HOST_SETTING, - NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING, - NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING, - NetworkService.TcpSettings.TCP_NO_DELAY, - NetworkService.TcpSettings.TCP_KEEP_ALIVE, - NetworkService.TcpSettings.TCP_REUSE_ADDRESS, - NetworkService.TcpSettings.TCP_SEND_BUFFER_SIZE, - NetworkService.TcpSettings.TCP_RECEIVE_BUFFER_SIZE, - NetworkService.TcpSettings.TCP_BLOCKING, - NetworkService.TcpSettings.TCP_BLOCKING_SERVER, - NetworkService.TcpSettings.TCP_BLOCKING_CLIENT, - NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT, - IndexSettings.QUERY_STRING_ANALYZE_WILDCARD, - IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD, - PrimaryShardAllocator.NODE_INITIAL_SHARDS_SETTING, - ScriptService.SCRIPT_CACHE_SIZE_SETTING, - IndicesFieldDataCache.INDICES_FIELDDATA_CLEAN_INTERVAL_SETTING, - IndicesFieldDataCache.INDICES_FIELDDATA_CACHE_SIZE_KEY, - IndicesRequestCache.INDICES_CACHE_QUERY_SIZE, - IndicesRequestCache.INDICES_CACHE_QUERY_EXPIRE, - IndicesRequestCache.INDICES_CACHE_REQUEST_CLEAN_INTERVAL, - HunspellService.HUNSPELL_LAZY_LOAD, - HunspellService.HUNSPELL_IGNORE_CASE, - HunspellService.HUNSPELL_DICTIONARY_OPTIONS, - IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT, - Environment.PATH_CONF_SETTING, - Environment.PATH_DATA_SETTING, - Environment.PATH_HOME_SETTING, - Environment.PATH_LOGS_SETTING, - Environment.PATH_PLUGINS_SETTING, - Environment.PATH_REPO_SETTING, - Environment.PATH_SCRIPTS_SETTING, - Environment.PATH_SHARED_DATA_SETTING, - Environment.PIDFILE_SETTING, - DiscoveryService.DISCOVERY_SEED_SETTING, - DiscoveryService.INITIAL_STATE_TIMEOUT_SETTING, - DiscoveryModule.DISCOVERY_TYPE_SETTING, - DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING, - FaultDetection.PING_RETRIES_SETTING, - FaultDetection.PING_TIMEOUT_SETTING, - FaultDetection.REGISTER_CONNECTION_LISTENER_SETTING, - FaultDetection.PING_INTERVAL_SETTING, - FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING, - ZenDiscovery.PING_TIMEOUT_SETTING, - ZenDiscovery.JOIN_TIMEOUT_SETTING, - ZenDiscovery.JOIN_RETRY_ATTEMPTS_SETTING, - ZenDiscovery.JOIN_RETRY_DELAY_SETTING, - ZenDiscovery.MAX_PINGS_FROM_ANOTHER_MASTER_SETTING, - ZenDiscovery.SEND_LEAVE_REQUEST_SETTING, - ZenDiscovery.MASTER_ELECTION_FILTER_CLIENT_SETTING, - ZenDiscovery.MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING, - ZenDiscovery.MASTER_ELECTION_FILTER_DATA_SETTING, - UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, - UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING, - SearchService.DEFAULT_KEEPALIVE_SETTING, - SearchService.KEEPALIVE_INTERVAL_SETTING, - Node.WRITE_PORTS_FIELD_SETTING, - Node.NODE_CLIENT_SETTING, - Node.NODE_DATA_SETTING, - Node.NODE_MASTER_SETTING, - Node.NODE_LOCAL_SETTING, - Node.NODE_MODE_SETTING, - Node.NODE_INGEST_SETTING, - URLRepository.ALLOWED_URLS_SETTING, - URLRepository.REPOSITORIES_LIST_DIRECTORIES_SETTING, - URLRepository.REPOSITORIES_URL_SETTING, - URLRepository.SUPPORTED_PROTOCOLS_SETTING, - TransportMasterNodeReadAction.FORCE_LOCAL_SETTING, - AutoCreateIndex.AUTO_CREATE_INDEX_SETTING, - BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX, - ClusterName.CLUSTER_NAME_SETTING, - Client.CLIENT_TYPE_SETTING_S, - InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, - ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING, - EsExecutors.PROCESSORS_SETTING, - ThreadContext.DEFAULT_HEADERS_SETTING, - ESLoggerFactory.LOG_DEFAULT_LEVEL_SETTING, - ESLoggerFactory.LOG_LEVEL_SETTING, - TribeService.BLOCKS_METADATA_SETTING, - TribeService.BLOCKS_WRITE_SETTING, - TribeService.BLOCKS_WRITE_INDICES_SETTING, - TribeService.BLOCKS_READ_INDICES_SETTING, - TribeService.BLOCKS_METADATA_INDICES_SETTING, - TribeService.ON_CONFLICT_SETTING, - NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING, - NodeEnvironment.ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING, - NodeEnvironment.ADD_NODE_ID_TO_CUSTOM_PATH, - OsService.REFRESH_INTERVAL_SETTING, - ProcessService.REFRESH_INTERVAL_SETTING, - JvmService.REFRESH_INTERVAL_SETTING, - FsService.REFRESH_INTERVAL_SETTING, - JvmGcMonitorService.ENABLED_SETTING, - JvmGcMonitorService.REFRESH_INTERVAL_SETTING, - JvmGcMonitorService.GC_SETTING, - PageCacheRecycler.LIMIT_HEAP_SETTING, - PageCacheRecycler.WEIGHT_BYTES_SETTING, - PageCacheRecycler.WEIGHT_INT_SETTING, - PageCacheRecycler.WEIGHT_LONG_SETTING, - PageCacheRecycler.WEIGHT_OBJECTS_SETTING, - PageCacheRecycler.TYPE_SETTING - ))); + Arrays.asList(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING, + TransportClientNodesService.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL, // TODO these transport client settings are kind of odd here and should only be valid if we are a transport client + TransportClientNodesService.CLIENT_TRANSPORT_PING_TIMEOUT, + TransportClientNodesService.CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME, + TransportClientNodesService.CLIENT_TRANSPORT_SNIFF, + AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING, + BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING, + BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING, + BalancedShardsAllocator.THRESHOLD_SETTING, + ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING, + ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING, + EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING, + EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING, + ZenDiscovery.REJOIN_ON_MASTER_GONE_SETTING, + FilterAllocationDecider.CLUSTER_ROUTING_INCLUDE_GROUP_SETTING, + FilterAllocationDecider.CLUSTER_ROUTING_EXCLUDE_GROUP_SETTING, + FilterAllocationDecider.CLUSTER_ROUTING_REQUIRE_GROUP_SETTING, + FsRepository.REPOSITORIES_CHUNK_SIZE_SETTING, + FsRepository.REPOSITORIES_COMPRESS_SETTING, + FsRepository.REPOSITORIES_LOCATION_SETTING, + IndexStoreConfig.INDICES_STORE_THROTTLE_TYPE_SETTING, + IndexStoreConfig.INDICES_STORE_THROTTLE_MAX_BYTES_PER_SEC_SETTING, + IndicesQueryCache.INDICES_CACHE_QUERY_SIZE_SETTING, + IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING, + IndicesTTLService.INDICES_TTL_INTERVAL_SETTING, + MappingUpdatedAction.INDICES_MAPPING_DYNAMIC_TIMEOUT_SETTING, + MetaData.SETTING_READ_ONLY_SETTING, + RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING, + RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_STATE_SYNC_SETTING, + RecoverySettings.INDICES_RECOVERY_RETRY_DELAY_NETWORK_SETTING, + RecoverySettings.INDICES_RECOVERY_ACTIVITY_TIMEOUT_SETTING, + RecoverySettings.INDICES_RECOVERY_INTERNAL_ACTION_TIMEOUT_SETTING, + RecoverySettings.INDICES_RECOVERY_INTERNAL_LONG_ACTION_TIMEOUT_SETTING, + ThreadPool.THREADPOOL_GROUP_SETTING, + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING, + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING, + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_OUTGOING_RECOVERIES_SETTING, + ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_RECOVERIES_SETTING, + DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING, + DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING, + DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING, + DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING, + DiskThresholdDecider.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING, + InternalClusterInfoService.INTERNAL_CLUSTER_INFO_UPDATE_INTERVAL_SETTING, + InternalClusterInfoService.INTERNAL_CLUSTER_INFO_TIMEOUT_SETTING, + SnapshotInProgressAllocationDecider.CLUSTER_ROUTING_ALLOCATION_SNAPSHOT_RELOCATION_ENABLED_SETTING, + DestructiveOperations.REQUIRES_NAME_SETTING, + DiscoverySettings.PUBLISH_TIMEOUT_SETTING, + DiscoverySettings.PUBLISH_DIFF_ENABLE_SETTING, + DiscoverySettings.COMMIT_TIMEOUT_SETTING, + DiscoverySettings.NO_MASTER_BLOCK_SETTING, + GatewayService.EXPECTED_DATA_NODES_SETTING, + GatewayService.EXPECTED_MASTER_NODES_SETTING, + GatewayService.EXPECTED_NODES_SETTING, + GatewayService.RECOVER_AFTER_DATA_NODES_SETTING, + GatewayService.RECOVER_AFTER_MASTER_NODES_SETTING, + GatewayService.RECOVER_AFTER_NODES_SETTING, + GatewayService.RECOVER_AFTER_TIME_SETTING, + NetworkModule.HTTP_ENABLED, + NetworkModule.TRANSPORT_SERVICE_TYPE_SETTING, + NetworkModule.TRANSPORT_TYPE_SETTING, + HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS, + HttpTransportSettings.SETTING_CORS_ENABLED, + HttpTransportSettings.SETTING_CORS_MAX_AGE, + HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED, + HttpTransportSettings.SETTING_PIPELINING, + HttpTransportSettings.SETTING_CORS_ALLOW_ORIGIN, + HttpTransportSettings.SETTING_HTTP_PORT, + HttpTransportSettings.SETTING_HTTP_PUBLISH_PORT, + HttpTransportSettings.SETTING_PIPELINING_MAX_EVENTS, + HttpTransportSettings.SETTING_HTTP_COMPRESSION, + HttpTransportSettings.SETTING_HTTP_COMPRESSION_LEVEL, + HttpTransportSettings.SETTING_CORS_ALLOW_METHODS, + HttpTransportSettings.SETTING_CORS_ALLOW_HEADERS, + HttpTransportSettings.SETTING_HTTP_DETAILED_ERRORS_ENABLED, + HttpTransportSettings.SETTING_HTTP_MAX_CONTENT_LENGTH, + HttpTransportSettings.SETTING_HTTP_MAX_CHUNK_SIZE, + HttpTransportSettings.SETTING_HTTP_MAX_HEADER_SIZE, + HttpTransportSettings.SETTING_HTTP_MAX_INITIAL_LINE_LENGTH, + HttpTransportSettings.SETTING_HTTP_RESET_COOKIES, + HierarchyCircuitBreakerService.TOTAL_CIRCUIT_BREAKER_LIMIT_SETTING, + HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_LIMIT_SETTING, + HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_OVERHEAD_SETTING, + HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_LIMIT_SETTING, + HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_OVERHEAD_SETTING, + InternalClusterService.CLUSTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, + SearchService.DEFAULT_SEARCH_TIMEOUT_SETTING, + ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING, + TransportService.TRACE_LOG_EXCLUDE_SETTING, + TransportService.TRACE_LOG_INCLUDE_SETTING, + TransportCloseIndexAction.CLUSTER_INDICES_CLOSE_ENABLE_SETTING, + ShardsLimitAllocationDecider.CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, + InternalClusterService.CLUSTER_SERVICE_RECONNECT_INTERVAL_SETTING, + HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING, + HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING, + Transport.TRANSPORT_TCP_COMPRESS, + TransportSettings.TRANSPORT_PROFILES_SETTING, + TransportSettings.HOST, + TransportSettings.PUBLISH_HOST, + TransportSettings.BIND_HOST, + TransportSettings.PUBLISH_PORT, + TransportSettings.PORT, + NettyTransport.WORKER_COUNT, + NettyTransport.CONNECTIONS_PER_NODE_RECOVERY, + NettyTransport.CONNECTIONS_PER_NODE_BULK, + NettyTransport.CONNECTIONS_PER_NODE_REG, + NettyTransport.CONNECTIONS_PER_NODE_STATE, + NettyTransport.CONNECTIONS_PER_NODE_PING, + NettyTransport.PING_SCHEDULE, + NettyTransport.TCP_BLOCKING_CLIENT, + NettyTransport.TCP_CONNECT_TIMEOUT, + NettyTransport.NETTY_MAX_CUMULATION_BUFFER_CAPACITY, + NettyTransport.NETTY_MAX_COMPOSITE_BUFFER_COMPONENTS, + NettyTransport.NETTY_RECEIVE_PREDICTOR_SIZE, + NettyTransport.NETTY_RECEIVE_PREDICTOR_MIN, + NettyTransport.NETTY_RECEIVE_PREDICTOR_MAX, + NetworkService.NETWORK_SERVER, + NettyTransport.NETTY_BOSS_COUNT, + NettyTransport.TCP_NO_DELAY, + NettyTransport.TCP_KEEP_ALIVE, + NettyTransport.TCP_REUSE_ADDRESS, + NettyTransport.TCP_SEND_BUFFER_SIZE, + NettyTransport.TCP_RECEIVE_BUFFER_SIZE, + NettyTransport.TCP_BLOCKING_SERVER, + NetworkService.GLOBAL_NETWORK_HOST_SETTING, + NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING, + NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING, + NetworkService.TcpSettings.TCP_NO_DELAY, + NetworkService.TcpSettings.TCP_KEEP_ALIVE, + NetworkService.TcpSettings.TCP_REUSE_ADDRESS, + NetworkService.TcpSettings.TCP_SEND_BUFFER_SIZE, + NetworkService.TcpSettings.TCP_RECEIVE_BUFFER_SIZE, + NetworkService.TcpSettings.TCP_BLOCKING, + NetworkService.TcpSettings.TCP_BLOCKING_SERVER, + NetworkService.TcpSettings.TCP_BLOCKING_CLIENT, + NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT, + IndexSettings.QUERY_STRING_ANALYZE_WILDCARD, + IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD, + PrimaryShardAllocator.NODE_INITIAL_SHARDS_SETTING, + ScriptService.SCRIPT_CACHE_SIZE_SETTING, + ScriptService.SCRIPT_CACHE_EXPIRE_SETTING, + ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING, + IndicesFieldDataCache.INDICES_FIELDDATA_CLEAN_INTERVAL_SETTING, + IndicesFieldDataCache.INDICES_FIELDDATA_CACHE_SIZE_KEY, + IndicesRequestCache.INDICES_CACHE_QUERY_SIZE, + IndicesRequestCache.INDICES_CACHE_QUERY_EXPIRE, + IndicesRequestCache.INDICES_CACHE_REQUEST_CLEAN_INTERVAL, + HunspellService.HUNSPELL_LAZY_LOAD, + HunspellService.HUNSPELL_IGNORE_CASE, + HunspellService.HUNSPELL_DICTIONARY_OPTIONS, + IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT, + Environment.PATH_CONF_SETTING, + Environment.PATH_DATA_SETTING, + Environment.PATH_HOME_SETTING, + Environment.PATH_LOGS_SETTING, + Environment.PATH_PLUGINS_SETTING, + Environment.PATH_REPO_SETTING, + Environment.PATH_SCRIPTS_SETTING, + Environment.PATH_SHARED_DATA_SETTING, + Environment.PIDFILE_SETTING, + DiscoveryService.DISCOVERY_SEED_SETTING, + DiscoveryService.INITIAL_STATE_TIMEOUT_SETTING, + DiscoveryModule.DISCOVERY_TYPE_SETTING, + DiscoveryModule.ZEN_MASTER_SERVICE_TYPE_SETTING, + FaultDetection.PING_RETRIES_SETTING, + FaultDetection.PING_TIMEOUT_SETTING, + FaultDetection.REGISTER_CONNECTION_LISTENER_SETTING, + FaultDetection.PING_INTERVAL_SETTING, + FaultDetection.CONNECT_ON_NETWORK_DISCONNECT_SETTING, + ZenDiscovery.PING_TIMEOUT_SETTING, + ZenDiscovery.JOIN_TIMEOUT_SETTING, + ZenDiscovery.JOIN_RETRY_ATTEMPTS_SETTING, + ZenDiscovery.JOIN_RETRY_DELAY_SETTING, + ZenDiscovery.MAX_PINGS_FROM_ANOTHER_MASTER_SETTING, + ZenDiscovery.SEND_LEAVE_REQUEST_SETTING, + ZenDiscovery.MASTER_ELECTION_FILTER_CLIENT_SETTING, + ZenDiscovery.MASTER_ELECTION_WAIT_FOR_JOINS_TIMEOUT_SETTING, + ZenDiscovery.MASTER_ELECTION_FILTER_DATA_SETTING, + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_HOSTS_SETTING, + UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING, + SearchService.DEFAULT_KEEPALIVE_SETTING, + SearchService.KEEPALIVE_INTERVAL_SETTING, + Node.WRITE_PORTS_FIELD_SETTING, + Node.NODE_NAME_SETTING, + Node.NODE_CLIENT_SETTING, + Node.NODE_DATA_SETTING, + Node.NODE_MASTER_SETTING, + Node.NODE_LOCAL_SETTING, + Node.NODE_MODE_SETTING, + Node.NODE_INGEST_SETTING, + Node.NODE_ATTRIBUTES, + URLRepository.ALLOWED_URLS_SETTING, + URLRepository.REPOSITORIES_LIST_DIRECTORIES_SETTING, + URLRepository.REPOSITORIES_URL_SETTING, + URLRepository.SUPPORTED_PROTOCOLS_SETTING, + TransportMasterNodeReadAction.FORCE_LOCAL_SETTING, + AutoCreateIndex.AUTO_CREATE_INDEX_SETTING, + BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX, + ClusterName.CLUSTER_NAME_SETTING, + Client.CLIENT_TYPE_SETTING_S, + InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, + ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING, + EsExecutors.PROCESSORS_SETTING, + ThreadContext.DEFAULT_HEADERS_SETTING, + ESLoggerFactory.LOG_DEFAULT_LEVEL_SETTING, + ESLoggerFactory.LOG_LEVEL_SETTING, + TribeService.BLOCKS_METADATA_SETTING, + TribeService.BLOCKS_WRITE_SETTING, + TribeService.BLOCKS_WRITE_INDICES_SETTING, + TribeService.BLOCKS_READ_INDICES_SETTING, + TribeService.BLOCKS_METADATA_INDICES_SETTING, + TribeService.ON_CONFLICT_SETTING, + TribeService.TRIBE_NAME_SETTING, + NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING, + NodeEnvironment.ENABLE_LUCENE_SEGMENT_INFOS_TRACE_SETTING, + NodeEnvironment.ADD_NODE_ID_TO_CUSTOM_PATH, + OsService.REFRESH_INTERVAL_SETTING, + ProcessService.REFRESH_INTERVAL_SETTING, + JvmService.REFRESH_INTERVAL_SETTING, + FsService.REFRESH_INTERVAL_SETTING, + JvmGcMonitorService.ENABLED_SETTING, + JvmGcMonitorService.REFRESH_INTERVAL_SETTING, + JvmGcMonitorService.GC_SETTING, + PageCacheRecycler.LIMIT_HEAP_SETTING, + PageCacheRecycler.WEIGHT_BYTES_SETTING, + PageCacheRecycler.WEIGHT_INT_SETTING, + PageCacheRecycler.WEIGHT_LONG_SETTING, + PageCacheRecycler.WEIGHT_OBJECTS_SETTING, + PageCacheRecycler.TYPE_SETTING, + PluginsService.MANDATORY_SETTING + ))); } diff --git a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java index f95cc1f6f6f..2ebeb1b2658 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java +++ b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.settings; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.tribe.TribeService; import java.util.HashMap; import java.util.HashSet; @@ -37,6 +38,8 @@ public class SettingsModule extends AbstractModule { private final SettingsFilter settingsFilter; private final Map> clusterSettings = new HashMap<>(); private final Map> indexSettings = new HashMap<>(); + private static final Predicate NO_TRIBE_PREDICATE = (s) -> s.startsWith("tribe.") == false || TribeService.TRIBE_SETTING_KEYS.contains(s); + public SettingsModule(Settings settings, SettingsFilter settingsFilter) { this.settings = settings; @@ -56,11 +59,7 @@ public class SettingsModule extends AbstractModule { // by now we are fully configured, lets check node level settings for unregistered index settings indexScopedSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE)); Predicate noIndexSettingPredicate = IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE.negate(); - Predicate noTribePredicate = (s) -> s.startsWith("tribe.") == false; - for (Map.Entry entry : settings.filter(noTribePredicate.and(noIndexSettingPredicate)).getAsMap().entrySet()) { - validateClusterSetting(clusterSettings, entry.getKey(), settings); - } - + clusterSettings.validate(settings.filter(NO_TRIBE_PREDICATE.and(noIndexSettingPredicate))); validateTribeSettings(settings, clusterSettings); bind(Settings.class).toInstance(settings); bind(SettingsFilter.class).toInstance(settingsFilter); @@ -87,24 +86,16 @@ public class SettingsModule extends AbstractModule { } public void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) { - Map groups = settings.getGroups("tribe.", true); + Map groups = settings.filter(NO_TRIBE_PREDICATE.negate()).getGroups("tribe.", true); for (Map.Entry tribeSettings : groups.entrySet()) { - for (Map.Entry entry : tribeSettings.getValue().getAsMap().entrySet()) { - validateClusterSetting(clusterSettings, entry.getKey(), tribeSettings.getValue()); + Settings thisTribesSettings = tribeSettings.getValue(); + for (Map.Entry entry : thisTribesSettings.getAsMap().entrySet()) { + try { + clusterSettings.validate(entry.getKey(), thisTribesSettings); + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException("tribe." + tribeSettings.getKey() +" validation failed: "+ ex.getMessage(), ex); + } } } } - - private final void validateClusterSetting(ClusterSettings clusterSettings, String key, Settings settings) { - // we can't call this method yet since we have not all node level settings registered. - // yet we can validate the ones we have registered to not have invalid values. this is better than nothing - // and progress over perfection and we fail as soon as possible. - // clusterSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE.negate())); - if (clusterSettings.get(key) != null) { - clusterSettings.validate(key, settings); - } else if (AbstractScopedSettings.isValidKey(key) == false) { - throw new IllegalArgumentException("illegal settings key: [" + key + "]"); - } - } - } diff --git a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java index 723d7df5114..10b1412425c 100644 --- a/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java +++ b/core/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java @@ -90,7 +90,7 @@ public class EsExecutors { } public static String threadName(Settings settings, String namePrefix) { - String name = settings.get("name"); + String name = settings.get("node.name"); if (name == null) { name = "elasticsearch"; } else { diff --git a/core/src/main/java/org/elasticsearch/index/IndexSettings.java b/core/src/main/java/org/elasticsearch/index/IndexSettings.java index 3919584b780..d6a4e901e55 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexSettings.java +++ b/core/src/main/java/org/elasticsearch/index/IndexSettings.java @@ -182,7 +182,7 @@ public final class IndexSettings { this.index = indexMetaData.getIndex(); version = Version.indexCreated(settings); logger = Loggers.getLogger(getClass(), settings, index); - nodeName = settings.get("name", ""); + nodeName = settings.get("node.name", ""); this.indexMetaData = indexMetaData; numberOfShards = settings.getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, null); isShadowReplicaIndex = IndexMetaData.isIndexUsingShadowReplicas(settings); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 542039fe22f..49952cf609b 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -133,6 +133,11 @@ public class Node implements Closeable { public static final Setting NODE_LOCAL_SETTING = Setting.boolSetting("node.local", false, false, Setting.Scope.CLUSTER); public static final Setting NODE_MODE_SETTING = new Setting<>("node.mode", "network", Function.identity(), false, Setting.Scope.CLUSTER); public static final Setting NODE_INGEST_SETTING = Setting.boolSetting("node.ingest", true, false, Setting.Scope.CLUSTER); + public static final Setting NODE_NAME_SETTING = Setting.simpleString("node.name", false, Setting.Scope.CLUSTER); + // this sucks that folks can mistype client etc and get away with it. + // TODO: we should move this to node.attribute.${name} = ${value} instead. + public static final Setting NODE_ATTRIBUTES = Setting.groupSetting("node.", false, Setting.Scope.CLUSTER); + private static final String CLIENT_TYPE = "node"; private final Lifecycle lifecycle = new Lifecycle(); @@ -156,7 +161,7 @@ public class Node implements Closeable { .put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build(); tmpSettings = TribeService.processSettings(tmpSettings); - ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name")); + ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(tmpSettings)); logger.info("version[{}], pid[{}], build[{}/{}]", version, JvmInfo.jvmInfo().pid(), Build.CURRENT.shortHash(), Build.CURRENT.date()); logger.info("initializing ..."); @@ -197,7 +202,8 @@ public class Node implements Closeable { modules.add(new EnvironmentModule(environment)); modules.add(new NodeModule(this, monitorService)); modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry)); - modules.add(new ScriptModule(settingsModule)); + ScriptModule scriptModule = new ScriptModule(); + modules.add(scriptModule); modules.add(new NodeEnvironmentModule(nodeEnvironment)); modules.add(new ClusterNameModule(this.settings)); modules.add(new ThreadPoolModule(threadPool)); @@ -215,7 +221,7 @@ public class Node implements Closeable { modules.add(new AnalysisModule(environment)); pluginsService.processModules(modules); - + scriptModule.prepareSettings(settingsModule); injector = modules.createInjector(); client = injector.getInstance(Client.class); @@ -262,7 +268,7 @@ public class Node implements Closeable { return this; } - ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); + ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings)); logger.info("starting ..."); // hack around dependency injection problem (for now...) injector.getInstance(Discovery.class).setRoutingService(injector.getInstance(RoutingService.class)); @@ -316,7 +322,7 @@ public class Node implements Closeable { if (!lifecycle.moveToStopped()) { return this; } - ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); + ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings)); logger.info("stopping ..."); injector.getInstance(TribeService.class).stop(); @@ -363,7 +369,7 @@ public class Node implements Closeable { return; } - ESLogger logger = Loggers.getLogger(Node.class, settings.get("name")); + ESLogger logger = Loggers.getLogger(Node.class, NODE_NAME_SETTING.get(settings)); logger.info("closing ..."); List toClose = new ArrayList<>(); StopWatch stopWatch = new StopWatch("node_close"); diff --git a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java index c5dd64a67bb..06fab2dc056 100644 --- a/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java +++ b/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java @@ -154,14 +154,6 @@ public class InternalSettingsPreparer { } output.replacePropertyPlaceholders(); - // check if name is set in settings, if not look for system property and set it - if (output.get("name") == null) { - String name = System.getProperty("name"); - if (name != null) { - output.put("name", name); - } - } - // put the cluster name if (output.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) == null) { output.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)); @@ -170,12 +162,10 @@ public class InternalSettingsPreparer { replacePromptPlaceholders(output, terminal); // all settings placeholders have been resolved. resolve the value for the name setting by checking for name, // then looking for node.name, and finally generate one if needed - if (output.get("name") == null) { - String name = output.get("node.name"); - if (name == null || name.isEmpty()) { - name = randomNodeName(configDir); - } - output.put("name", name); + String name = output.get("node.name"); + if (name == null || name.isEmpty()) { + name = randomNodeName(configDir); + output.put("node.name", name); } } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 4e61185491d..ac3e61689a5 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.io.FileSystemUtils; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexModule; @@ -56,6 +57,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory; @@ -69,6 +71,7 @@ public class PluginsService extends AbstractComponent { */ private final List> plugins; private final PluginsAndModules info; + public static final Setting> MANDATORY_SETTING = Setting.listSetting("plugin.mandatory", Collections.emptyList(), Function.identity(), false, Setting.Scope.CLUSTER); private final Map> onModuleReferences; @@ -143,8 +146,8 @@ public class PluginsService extends AbstractComponent { } // Checking expected plugins - String[] mandatoryPlugins = settings.getAsArray("plugin.mandatory", null); - if (mandatoryPlugins != null) { + List mandatoryPlugins = MANDATORY_SETTING.get(settings); + if (mandatoryPlugins.isEmpty() == false) { Set missingPlugins = new HashSet<>(); for (String mandatoryPlugin : mandatoryPlugins) { if (!pluginsNames.contains(mandatoryPlugin) && !missingPlugins.contains(mandatoryPlugin)) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index aaf0906b0f5..199f5124fa4 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -76,9 +76,8 @@ public class RestMainAction extends BaseRestHandler { } builder.startObject(); - if (settings.get("name") != null) { - builder.field("name", settings.get("name")); - } + assert settings.get("node.name") != null; + builder.field("name", settings.get("node.name")); builder.field("cluster_name", clusterName.value()); builder.startObject("version") .field("number", version.number()) diff --git a/core/src/main/java/org/elasticsearch/script/ScriptModule.java b/core/src/main/java/org/elasticsearch/script/ScriptModule.java index 1ccc7eb956d..11bc2b58a99 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptModule.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptModule.java @@ -37,8 +37,6 @@ import java.util.Objects; */ public class ScriptModule extends AbstractModule { - private final SettingsModule settingsModule; - private final List scriptEngineRegistrations = new ArrayList<>(); { @@ -49,9 +47,6 @@ public class ScriptModule extends AbstractModule { private final List customScriptContexts = new ArrayList<>(); - public ScriptModule(SettingsModule settingsModule) { - this.settingsModule = settingsModule; - } public void addScriptEngine(ScriptEngineRegistry.ScriptEngineRegistration scriptEngineRegistration) { Objects.requireNonNull(scriptEngineRegistration); @@ -70,6 +65,21 @@ public class ScriptModule extends AbstractModule { customScriptContexts.add(scriptContext); } + /** + * This method is called after all modules have been processed but before we actually validate all settings. This allwos the + * script extensions to add all their settings. + */ + public void prepareSettings(SettingsModule settingsModule) { + ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngineRegistrations); + ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); + + scriptSettings.getScriptTypeSettings().forEach(settingsModule::registerSetting); + scriptSettings.getScriptContextSettings().forEach(settingsModule::registerSetting); + scriptSettings.getScriptLanguageSettings().forEach(settingsModule::registerSetting); + settingsModule.registerSetting(scriptSettings.getDefaultScriptLanguageSetting()); + } + @Override protected void configure() { MapBinder scriptsBinder @@ -85,16 +95,11 @@ public class ScriptModule extends AbstractModule { multibinder.addBinding().to(scriptEngineRegistration.getScriptEngineService()).asEagerSingleton(); } + ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customScriptContexts); ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(scriptEngineRegistrations); - ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - scriptSettings.getScriptTypeSettings().forEach(settingsModule::registerSetting); - scriptSettings.getScriptContextSettings().forEach(settingsModule::registerSetting); - scriptSettings.getScriptLanguageSettings().forEach(settingsModule::registerSetting); - settingsModule.registerSetting(scriptSettings.getDefaultScriptLanguageSetting()); - bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); bind(ScriptSettings.class).toInstance(scriptSettings); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 378a849115b..ba5c075abec 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -206,13 +206,13 @@ public class ThreadPool extends AbstractComponent implements Closeable { private final ThreadContext threadContext; public ThreadPool(String name) { - this(Settings.builder().put("name", name).build()); + this(Settings.builder().put("node.name", name).build()); } public ThreadPool(Settings settings) { super(settings); - assert settings.get("name") != null : "ThreadPool's settings should contain a name"; + assert settings.get("node.name") != null : "ThreadPool's settings should contain a name"; threadContext = new ThreadContext(settings); Map groupSettings = THREADPOOL_GROUP_SETTING.get(settings).getAsGroups(); validate(groupSettings); diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java index 88c4dc75222..af2e3fe96f0 100644 --- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java +++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java @@ -46,6 +46,7 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; +import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.env.Environment; @@ -61,6 +62,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Function; +import java.util.function.Predicate; import static java.util.Collections.unmodifiableMap; @@ -119,7 +121,7 @@ public class TribeService extends AbstractLifecycleComponent { } // internal settings only - private static final Setting TRIBE_NAME_SETTING = Setting.simpleString("tribe.name", false, Setting.Scope.CLUSTER); + public static final Setting TRIBE_NAME_SETTING = Setting.simpleString("tribe.name", false, Setting.Scope.CLUSTER); private final ClusterService clusterService; private final String[] blockIndicesWrite; private final String[] blockIndicesRead; @@ -127,11 +129,17 @@ public class TribeService extends AbstractLifecycleComponent { private static final String ON_CONFLICT_ANY = "any", ON_CONFLICT_DROP = "drop", ON_CONFLICT_PREFER = "prefer_"; public static final Setting ON_CONFLICT_SETTING = new Setting<>("tribe.on_conflict", ON_CONFLICT_ANY, (s) -> { - if (ON_CONFLICT_ANY.equals(s) || ON_CONFLICT_DROP.equals(s) || s.startsWith(ON_CONFLICT_PREFER)) { - return s; + switch (s) { + case ON_CONFLICT_ANY: + case ON_CONFLICT_DROP: + return s; + default: + if (s.startsWith(ON_CONFLICT_PREFER) && s.length() > ON_CONFLICT_PREFER.length()) { + return s; + } + throw new IllegalArgumentException( + "Invalid value for [tribe.on_conflict] must be either [any, drop or start with prefer_] but was: [" + s + "]"); } - throw new IllegalArgumentException( - "Invalid value for [tribe.on_conflict] must be either [any, drop or start with prefer_] but was: " + s); }, false, Setting.Scope.CLUSTER); public static final Setting BLOCKS_METADATA_SETTING = Setting.boolSetting("tribe.blocks.metadata", false, false, @@ -145,6 +153,9 @@ public class TribeService extends AbstractLifecycleComponent { public static final Setting> BLOCKS_METADATA_INDICES_SETTING = Setting.listSetting("tribe.blocks.metadata.indices", Collections.emptyList(), Function.identity(), false, Setting.Scope.CLUSTER); + public static final Set TRIBE_SETTING_KEYS = Sets.newHashSet(TRIBE_NAME_SETTING.getKey(), ON_CONFLICT_SETTING.getKey(), + BLOCKS_METADATA_INDICES_SETTING.getKey(), BLOCKS_METADATA_SETTING.getKey(), BLOCKS_READ_INDICES_SETTING.getKey(), BLOCKS_WRITE_INDICES_SETTING.getKey(), BLOCKS_WRITE_SETTING.getKey()); + private final String onConflict; private final Set droppedIndices = ConcurrentCollections.newConcurrentSet(); @@ -159,7 +170,7 @@ public class TribeService extends AbstractLifecycleComponent { nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client for (Map.Entry entry : nodesSettings.entrySet()) { Settings.Builder sb = Settings.builder().put(entry.getValue()); - sb.put("name", settings.get("name") + "/" + entry.getKey()); + sb.put("node.name", settings.get("node.name") + "/" + entry.getKey()); sb.put(Environment.PATH_HOME_SETTING.getKey(), Environment.PATH_HOME_SETTING.get(settings)); // pass through ES home dir if (Environment.PATH_CONF_SETTING.exists(settings)) { sb.put(Environment.PATH_CONF_SETTING.getKey(), Environment.PATH_CONF_SETTING.get(settings)); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java index fbb93202fcf..89fd4046c9c 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java @@ -66,7 +66,7 @@ public class TasksIT extends ESIntegTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put(MockTaskManager.USE_MOCK_TASK_MANAGER, true) + .put(MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.getKey(), true) .build(); } diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java index 4e1c08261a3..fe74b530097 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TransportTasksActionTests.java @@ -118,7 +118,7 @@ public class TransportTasksActionTests extends ESTestCase { threadPool){ @Override protected TaskManager createTaskManager() { - if (settings.getAsBoolean(MockTaskManager.USE_MOCK_TASK_MANAGER, false)) { + if (MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.get(settings)) { return new MockTaskManager(settings); } else { return super.createTaskManager(); @@ -659,7 +659,7 @@ public class TransportTasksActionTests extends ESTestCase { } public void testFailedTasksCount() throws ExecutionException, InterruptedException, IOException { - Settings settings = Settings.builder().put(MockTaskManager.USE_MOCK_TASK_MANAGER, true).build(); + Settings settings = Settings.builder().put(MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.getKey(), true).build(); setupTestNodes(settings); connectNodes(testNodes); TestNodesAction[] actions = new TestNodesAction[nodesCount]; diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java index 118560b7ab6..d5316ea7b5e 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/shards/IndicesShardStoreRequestIT.java @@ -222,7 +222,7 @@ public class IndicesShardStoreRequestIT extends ESIntegTestCase { @Override public boolean test(Settings settings) { - return nodesWithShard.contains(settings.get("name")); + return nodesWithShard.contains(settings.get("node.name")); } private Set findNodesWithShard(String index) { diff --git a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java index d58b9bf850d..cf1cab2416b 100644 --- a/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java +++ b/core/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java @@ -54,7 +54,7 @@ public class SimulateExecutionServiceTests extends ESTestCase { public void setup() { threadPool = new ThreadPool( Settings.builder() - .put("name", getClass().getName()) + .put("node.name", getClass().getName()) .build() ); executionService = new SimulateExecutionService(threadPool); diff --git a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java index 25a1e7005a7..3b18211f00f 100644 --- a/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java +++ b/core/src/test/java/org/elasticsearch/client/AbstractClientHeadersTestCase.java @@ -78,7 +78,7 @@ public abstract class AbstractClientHeadersTestCase extends ESTestCase { Settings settings = Settings.builder() .put(HEADER_SETTINGS) .put("path.home", createTempDir().toString()) - .put("name", "test-" + getTestName()) + .put("node.name", "test-" + getTestName()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .build(); threadPool = new ThreadPool(settings); diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientRetryIT.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientRetryIT.java index dcb5ac46948..9d7598325e3 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientRetryIT.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientRetryIT.java @@ -53,7 +53,7 @@ public class TransportClientRetryIT extends ESIntegTestCase { } Settings.Builder builder = settingsBuilder().put("client.transport.nodes_sampler_interval", "1s") - .put("name", "transport_client_retry_test") + .put("node.name", "transport_client_retry_test") .put(Node.NODE_MODE_SETTING.getKey(), internalCluster().getNodeMode()) .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), internalCluster().getClusterName()) .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) diff --git a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java index 290eec0c0bb..e60e4043a99 100644 --- a/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/settings/SettingsModuleTests.java @@ -74,11 +74,40 @@ public class SettingsModuleTests extends ModuleTestCase { assertInstanceBinding(module, Settings.class, (s) -> s == settings); fail(); } catch (IllegalArgumentException ex) { - assertEquals("Failed to parse value [[2.0]] for setting [cluster.routing.allocation.balance.shard]", ex.getMessage()); + assertEquals("tribe.t1 validation failed: Failed to parse value [[2.0]] for setting [cluster.routing.allocation.balance.shard]", ex.getMessage()); } } } + public void testSpecialTribeSetting() { + { + Settings settings = Settings.builder().put("tribe.blocks.write", "false").build(); + SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + assertInstanceBinding(module, Settings.class, (s) -> s == settings); + } + { + Settings settings = Settings.builder().put("tribe.blocks.write", "BOOM").build(); + SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + try { + assertInstanceBinding(module, Settings.class, (s) -> s == settings); + fail(); + } catch (IllegalArgumentException ex) { + assertEquals("Failed to parse value [BOOM] cannot be parsed to boolean [ true/1/on/yes OR false/0/off/no ]", ex.getMessage()); + } + } + { + Settings settings = Settings.builder().put("tribe.blocks.wtf", "BOOM").build(); + SettingsModule module = new SettingsModule(settings, new SettingsFilter(Settings.EMPTY)); + try { + assertInstanceBinding(module, Settings.class, (s) -> s == settings); + fail(); + } catch (IllegalArgumentException ex) { + assertEquals("tribe.blocks validation failed: unknown setting [wtf]", ex.getMessage()); + } + } + } + + public void testLoggerSettings() { { Settings settings = Settings.builder().put("logger._root", "TRACE").put("logger.transport", "INFO").build(); diff --git a/core/src/test/java/org/elasticsearch/gateway/RecoveryBackwardsCompatibilityIT.java b/core/src/test/java/org/elasticsearch/gateway/RecoveryBackwardsCompatibilityIT.java index 2fce6e44c1c..5146c7dc917 100644 --- a/core/src/test/java/org/elasticsearch/gateway/RecoveryBackwardsCompatibilityIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/RecoveryBackwardsCompatibilityIT.java @@ -43,7 +43,6 @@ public class RecoveryBackwardsCompatibilityIT extends ESBackcompatTestCase { protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) - .put("action.admin.cluster.node.shutdown.delay", "10ms") .put("gateway.recover_after_nodes", 2).build(); } diff --git a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java index a08a0722a88..dd398bd48cd 100644 --- a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java @@ -331,7 +331,6 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase { public void testReusePeerRecovery() throws Exception { final Settings settings = settingsBuilder() - .put("action.admin.cluster.node.shutdown.delay", "10ms") .put(MockFSIndexStore.INDEX_CHECK_INDEX_ON_CLOSE_SETTING.getKey(), false) .put("gateway.recover_after_nodes", 4) .put(ThrottlingAllocationDecider.CLUSTER_ROUTING_ALLOCATION_NODE_CONCURRENT_INCOMING_RECOVERIES_SETTING.getKey(), 4) diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index 9f2b33b96b9..ac272171ede 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -186,7 +186,7 @@ public abstract class AbstractQueryTestCase> // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually. Version version = randomBoolean() ? Version.CURRENT : VersionUtils.randomVersionBetween(random(), Version.V_2_0_0_beta1, Version.CURRENT); Settings settings = Settings.settingsBuilder() - .put("name", AbstractQueryTestCase.class.toString()) + .put("node.name", AbstractQueryTestCase.class.toString()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) .build(); @@ -204,6 +204,35 @@ public abstract class AbstractQueryTestCase> new Class[]{Client.class}, clientInvocationHandler); namedWriteableRegistry = new NamedWriteableRegistry(); + ScriptModule scriptModule = new ScriptModule() { + @Override + protected void configure() { + Settings settings = Settings.builder() + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) + // no file watching, so we don't need a ResourceWatcherService + .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) + .build(); + MockScriptEngine mockScriptEngine = new MockScriptEngine(); + Multibinder multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class); + multibinder.addBinding().toInstance(mockScriptEngine); + Set engines = new HashSet<>(); + engines.add(mockScriptEngine); + List customContexts = new ArrayList<>(); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES))); + bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); + ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); + bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); + ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); + bind(ScriptSettings.class).toInstance(scriptSettings); + try { + ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); + bind(ScriptService.class).toInstance(scriptService); + } catch(IOException e) { + throw new IllegalStateException("error while binding ScriptService", e); + } + } + }; + scriptModule.prepareSettings(settingsModule); injector = new ModulesBuilder().add( new EnvironmentModule(new Environment(settings)), settingsModule, @@ -215,34 +244,7 @@ public abstract class AbstractQueryTestCase> bindMapperExtension(); } }, - new ScriptModule(settingsModule) { - @Override - protected void configure() { - Settings settings = Settings.builder() - .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) - // no file watching, so we don't need a ResourceWatcherService - .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) - .build(); - MockScriptEngine mockScriptEngine = new MockScriptEngine(); - Multibinder multibinder = Multibinder.newSetBinder(binder(), ScriptEngineService.class); - multibinder.addBinding().toInstance(mockScriptEngine); - Set engines = new HashSet<>(); - engines.add(mockScriptEngine); - List customContexts = new ArrayList<>(); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES))); - bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); - ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); - bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); - ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); - bind(ScriptSettings.class).toInstance(scriptSettings); - try { - ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); - bind(ScriptService.class).toInstance(scriptService); - } catch(IOException e) { - throw new IllegalStateException("error while binding ScriptService", e); - } - } - }, + scriptModule, new IndexSettingsModule(index, indexSettings), new SearchModule(settings, namedWriteableRegistry) { @Override diff --git a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java index 204dcefea7d..0f8ee84d576 100644 --- a/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java +++ b/core/src/test/java/org/elasticsearch/node/internal/InternalSettingsPreparerTests.java @@ -59,13 +59,13 @@ public class InternalSettingsPreparerTests extends ESTestCase { public void testEmptySettings() { Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY); - assertNotNull(settings.get("name")); // a name was set + assertNotNull(settings.get("node.name")); // a name was set assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey())); // a cluster name was set int size = settings.names().size(); Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null); settings = env.settings(); - assertNotNull(settings.get("name")); // a name was set + assertNotNull(settings.get("node.name")); // a name was set assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey())); // a cluster name was set assertEquals(settings.toString(), size + 1 /* path.home is in the base settings */, settings.names().size()); String home = Environment.PATH_HOME_SETTING.get(baseEnvSettings); diff --git a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java index 144aedb7fd2..7561b9b2b12 100644 --- a/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java +++ b/core/src/test/java/org/elasticsearch/script/NativeScriptTests.java @@ -47,11 +47,12 @@ import static org.hamcrest.Matchers.notNullValue; public class NativeScriptTests extends ESTestCase { public void testNativeScript() throws InterruptedException { Settings settings = Settings.settingsBuilder() - .put("name", "testNativeScript") + .put("node.name", "testNativeScript") .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); - ScriptModule scriptModule = new ScriptModule(settingsModule); + ScriptModule scriptModule = new ScriptModule(); + scriptModule.prepareSettings(settingsModule); scriptModule.registerScript("my", MyNativeScriptFactory.class); Injector injector = new ModulesBuilder().add( new EnvironmentModule(new Environment(settings)), diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java index b729692e408..f240960c408 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DateHistogramOffsetIT.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.mapper.core.DateFieldMapper; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; import org.elasticsearch.test.ESIntegTestCase; @@ -33,6 +34,8 @@ import org.junit.After; import org.junit.Before; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; @@ -57,6 +60,11 @@ public class DateHistogramOffsetIT extends ESIntegTestCase { return DateFieldMapper.Defaults.DATE_TIME_FORMATTER.parser().parseDateTime(date); } + @Override + protected Collection> nodePlugins() { + return Collections.singleton(AssertingLocalTransport.TestPlugin.class); + } + @Override protected Settings nodeSettings(int nodeOrdinal) { return Settings.builder() diff --git a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java index bb969b90de6..b214a1710ba 100644 --- a/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/builder/SearchSourceBuilderTests.java @@ -83,7 +83,7 @@ public class SearchSourceBuilderTests extends ESTestCase { @BeforeClass public static void init() throws IOException { Settings settings = Settings.settingsBuilder() - .put("name", SearchSourceBuilderTests.class.toString()) + .put("node.name", SearchSourceBuilderTests.class.toString()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); namedWriteableRegistry = new NamedWriteableRegistry(); diff --git a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java index c6e93204b66..7e9bd14f9f3 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/snapshots/AbstractSnapshotIntegTestCase.java @@ -92,7 +92,7 @@ public abstract class AbstractSnapshotIntegTestCase extends ESIntegTestCase { } public static void stopNode(final String node) throws IOException { - internalCluster().stopRandomNode(settings -> settings.get("name").equals(node)); + internalCluster().stopRandomNode(settings -> settings.get("node.name").equals(node)); } public void waitForBlock(String node, String repository, TimeValue timeout) throws InterruptedException { diff --git a/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java b/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java index c30954f7312..30dd0bd5477 100644 --- a/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java +++ b/core/src/test/java/org/elasticsearch/threadpool/ThreadPoolSerializationTests.java @@ -97,7 +97,7 @@ public class ThreadPoolSerializationTests extends ESTestCase { } public void testThatNegativeSettingAllowsToStart() throws InterruptedException { - Settings settings = settingsBuilder().put("name", "index").put("threadpool.index.queue_size", "-1").build(); + Settings settings = settingsBuilder().put("node.name", "index").put("threadpool.index.queue_size", "-1").build(); ThreadPool threadPool = new ThreadPool(settings); assertThat(threadPool.info("index").getQueueSize(), is(nullValue())); terminate(threadPool); diff --git a/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java b/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java index 01fae3036dd..67a3f6fd4cf 100644 --- a/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java +++ b/core/src/test/java/org/elasticsearch/threadpool/UpdateThreadPoolSettingsTests.java @@ -55,7 +55,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { ThreadPool threadPool = null; try { threadPool = new ThreadPool(settingsBuilder() - .put("name", "testCorrectThreadPoolTypePermittedInSettings") + .put("node.name", "testCorrectThreadPoolTypePermittedInSettings") .put("threadpool." + threadPoolName + ".type", correctThreadPoolType.getType()) .build()); ThreadPool.Info info = info(threadPool, threadPoolName); @@ -78,7 +78,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { try { threadPool = new ThreadPool( settingsBuilder() - .put("name", "testThreadPoolCanNotOverrideThreadPoolType") + .put("node.name", "testThreadPoolCanNotOverrideThreadPoolType") .put("threadpool." + threadPoolName + ".type", incorrectThreadPoolType.getType()) .build()); terminate(threadPool); @@ -102,7 +102,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { // try to create a too-big (maxSize+1) thread pool threadPool = new ThreadPool(settingsBuilder() - .put("name", "testIndexingThreadPoolsMaxSize") + .put("node.name", "testIndexingThreadPoolsMaxSize") .put("threadpool." + name + ".size", maxSize+1) .build()); @@ -143,7 +143,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { ThreadPool.ThreadPoolType validThreadPoolType = ThreadPool.THREAD_POOL_TYPES.get(threadPoolName); ThreadPool threadPool = null; try { - threadPool = new ThreadPool(settingsBuilder().put("name", "testUpdateSettingsCanNotChangeThreadPoolType").build()); + threadPool = new ThreadPool(settingsBuilder().put("node.name", "testUpdateSettingsCanNotChangeThreadPoolType").build()); ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); @@ -168,7 +168,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { ThreadPool threadPool = null; try { Settings nodeSettings = Settings.settingsBuilder() - .put("name", "testCachedExecutorType").build(); + .put("node.name", "testCachedExecutorType").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); @@ -227,7 +227,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { try { Settings nodeSettings = Settings.settingsBuilder() - .put("name", "testFixedExecutorType").build(); + .put("node.name", "testFixedExecutorType").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); @@ -287,7 +287,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { try { Settings nodeSettings = settingsBuilder() .put("threadpool." + threadPoolName + ".size", 10) - .put("name", "testScalingExecutorType").build(); + .put("node.name", "testScalingExecutorType").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); @@ -325,7 +325,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { try { Settings nodeSettings = Settings.settingsBuilder() .put("threadpool." + threadPoolName + ".queue_size", 1000) - .put("name", "testShutdownNowInterrupts").build(); + .put("node.name", "testShutdownNowInterrupts").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); @@ -362,7 +362,7 @@ public class UpdateThreadPoolSettingsTests extends ESTestCase { .put("threadpool.my_pool2.type", "fixed") .put("threadpool.my_pool2.size", "1") .put("threadpool.my_pool2.queue_size", "1") - .put("name", "testCustomThreadPool").build(); + .put("node.name", "testCustomThreadPool").build(); threadPool = new ThreadPool(nodeSettings); ClusterSettings clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS); threadPool.setClusterSettings(clusterSettings); diff --git a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java index def9a119ac4..9de8de67ce0 100644 --- a/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java +++ b/core/src/test/java/org/elasticsearch/transport/NettySizeHeaderFrameDecoderTests.java @@ -51,7 +51,7 @@ import static org.hamcrest.Matchers.is; public class NettySizeHeaderFrameDecoderTests extends ESTestCase { private final Settings settings = settingsBuilder() - .put("name", "foo") + .put("node.name", "NettySizeHeaderFrameDecoderTests") .put(TransportSettings.BIND_HOST.getKey(), "127.0.0.1") .put(TransportSettings.PORT.getKey(), "0") .build(); diff --git a/core/src/test/java/org/elasticsearch/tribe/TribeIT.java b/core/src/test/java/org/elasticsearch/tribe/TribeIT.java index ae4555b891c..55a79ffddfc 100644 --- a/core/src/test/java/org/elasticsearch/tribe/TribeIT.java +++ b/core/src/test/java/org/elasticsearch/tribe/TribeIT.java @@ -143,7 +143,6 @@ public class TribeIT extends ESIntegTestCase { .put("tribe.t1.cluster.name", internalCluster().getClusterName()) .put("tribe.t2.cluster.name", cluster2.getClusterName()) .put("tribe.blocks.write", false) - .put("tribe.blocks.read", false) .put(settings) .put(tribe1Defaults.build()) .put(tribe2Defaults.build()) diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java index 4246d34e3f5..06e04f41a44 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/IndexedExpressionTests.java @@ -41,7 +41,6 @@ public class IndexedExpressionTests extends ESIntegTestCase { Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal)); builder.put("script.engine.expression.indexed.update", "false"); builder.put("script.engine.expression.indexed.search", "false"); - builder.put("script.engine.expression.indexed.mapping", "false"); return builder.build(); } diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndexedScriptTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndexedScriptTests.java index 65b83a9be3c..c4445a97277 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndexedScriptTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/IndexedScriptTests.java @@ -64,9 +64,6 @@ public class IndexedScriptTests extends ESIntegTestCase { builder.put("script.engine.groovy.indexed.search", "true"); builder.put("script.engine.groovy.indexed.aggs", "true"); builder.put("script.engine.groovy.inline.aggs", "false"); - builder.put("script.engine.expression.indexed.update", "false"); - builder.put("script.engine.expression.indexed.search", "false"); - builder.put("script.engine.expression.indexed.mapping", "false"); return builder.build(); } diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java index 661187286d7..a9c75b31a74 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java @@ -91,7 +91,7 @@ public class TemplateQueryParserTests extends ESTestCase { Settings settings = Settings.settingsBuilder() .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .put(Environment.PATH_CONF_SETTING.getKey(), this.getDataPath("config")) - .put("name", getClass().getName()) + .put("node.name", getClass().getName()) .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .build(); final Client proxy = (Client) Proxy.newProxyInstance( @@ -102,7 +102,8 @@ public class TemplateQueryParserTests extends ESTestCase { IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", settings); Index index = idxSettings.getIndex(); SettingsModule settingsModule = new SettingsModule(settings, new SettingsFilter(settings)); - ScriptModule scriptModule = new ScriptModule(settingsModule); + ScriptModule scriptModule = new ScriptModule(); + scriptModule.prepareSettings(settingsModule); // TODO: make this use a mock engine instead of mustache and it will no longer be messy! scriptModule.addScriptEngine(new ScriptEngineRegistry.ScriptEngineRegistration(MustacheScriptEngineService.class, MustacheScriptEngineService.TYPES)); settingsModule.registerSetting(InternalSettingsPlugin.VERSION_CREATED); diff --git a/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java b/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java index 418bd1291ed..9bee3b81ff3 100644 --- a/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java +++ b/plugins/discovery-azure/src/main/java/org/elasticsearch/plugin/discovery/azure/AzureDiscoveryPlugin.java @@ -71,6 +71,11 @@ public class AzureDiscoveryPlugin extends Plugin { public void onModule(SettingsModule settingsModule) { settingsModule.registerSetting(AzureComputeService.Discovery.REFRESH_SETTING); + settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_PASSWORD_SETTING); + settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_PATH_SETTING); + settingsModule.registerSetting(AzureComputeService.Management.KEYSTORE_TYPE_SETTING); + settingsModule.registerSetting(AzureComputeService.Management.SUBSCRIPTION_ID_SETTING); + settingsModule.registerSetting(AzureComputeService.Management.SERVICE_NAME_SETTING); settingsModule.registerSetting(AzureComputeService.Discovery.HOST_TYPE_SETTING); } } diff --git a/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java b/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java index e32c10562c7..0c593e24ebf 100644 --- a/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java +++ b/plugins/repository-azure/src/main/java/org/elasticsearch/plugin/repository/azure/AzureRepositoryPlugin.java @@ -20,10 +20,12 @@ package org.elasticsearch.plugin.repository.azure; import org.elasticsearch.cloud.azure.AzureRepositoryModule; +import org.elasticsearch.cloud.azure.storage.AzureStorageService; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoriesModule; @@ -64,4 +66,13 @@ public class AzureRepositoryPlugin extends Plugin { logger.debug("registering repository type [{}]", AzureRepository.TYPE); module.registerRepository(AzureRepository.TYPE, AzureRepository.class, BlobStoreIndexShardRepository.class); } + + public void onModule(SettingsModule module) { + module.registerSetting(AzureStorageService.Storage.ACCOUNT_SETTING); + module.registerSetting(AzureStorageService.Storage.COMPRESS_SETTING); + module.registerSetting(AzureStorageService.Storage.CONTAINER_SETTING); + module.registerSetting(AzureStorageService.Storage.BASE_PATH_SETTING); + module.registerSetting(AzureStorageService.Storage.CHUNK_SIZE_SETTING); + module.registerSetting(AzureStorageService.Storage.LOCATION_MODE_SETTING); + } } diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/node/internal/EvilInternalSettingsPreparerTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/node/internal/EvilInternalSettingsPreparerTests.java deleted file mode 100644 index 61410c612ab..00000000000 --- a/qa/evil-tests/src/test/java/org/elasticsearch/node/internal/EvilInternalSettingsPreparerTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.node.internal; - -import org.elasticsearch.common.SuppressForbidden; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.test.ESTestCase; -import org.junit.After; -import org.junit.Before; - -import java.util.HashMap; -import java.util.Map; - -import static org.elasticsearch.common.settings.Settings.settingsBuilder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.notNullValue; - -@SuppressForbidden(reason = "modifies system properties intentionally") -public class EvilInternalSettingsPreparerTests extends ESTestCase { - - Map savedProperties = new HashMap<>(); - Settings baseEnvSettings; - - @Before - public void saveSettingsSystemProperties() { - // clear out any properties the settings preparer may look for - savedProperties.clear(); - for (Object propObj : System.getProperties().keySet()) { - String property = (String)propObj; - // NOTE: these prefixes are prefixes of the defaults, so both are handled here - for (String prefix : InternalSettingsPreparer.PROPERTY_PREFIXES) { - if (property.startsWith(prefix)) { - savedProperties.put(property, System.getProperty(property)); - } - } - } - String name = System.getProperty("name"); - if (name != null) { - savedProperties.put("name", name); - } - for (String property : savedProperties.keySet()) { - System.clearProperty(property); - } - } - - @After - public void restoreSettingsSystemProperties() { - for (Map.Entry property : savedProperties.entrySet()) { - System.setProperty(property.getKey(), property.getValue()); - } - } - - @Before - public void createBaseEnvSettings() { - baseEnvSettings = settingsBuilder() - .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) - .build(); - } - - @After - public void clearBaseEnvSettings() { - baseEnvSettings = null; - } - - public void testIgnoreSystemProperties() { - try { - System.setProperty("es.node.zone", "foo"); - Settings settings = settingsBuilder() - .put("node.zone", "bar") - .put(baseEnvSettings) - .build(); - Environment env = InternalSettingsPreparer.prepareEnvironment(settings, null); - // Should use setting from the system property - assertThat(env.settings().get("node.zone"), equalTo("foo")); - - settings = settingsBuilder() - .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) - .put("node.zone", "bar") - .put(baseEnvSettings) - .build(); - env = InternalSettingsPreparer.prepareEnvironment(settings, null); - // Should use setting from the system property - assertThat(env.settings().get("node.zone"), equalTo("bar")); - } finally { - System.clearProperty("es.node.zone"); - } - } - - public void testNameSettingsPreference() { - try { - System.setProperty("name", "sys-prop-name"); - // Test system property overrides node.name - Settings settings = settingsBuilder() - .put("node.name", "node-name") - .put(baseEnvSettings) - .build(); - Environment env = InternalSettingsPreparer.prepareEnvironment(settings, null); - assertThat(env.settings().get("name"), equalTo("sys-prop-name")); - - // test name in settings overrides sys prop and node.name - settings = settingsBuilder() - .put("name", "name-in-settings") - .put("node.name", "node-name") - .put(baseEnvSettings) - .build(); - env = InternalSettingsPreparer.prepareEnvironment(settings, null); - assertThat(env.settings().get("name"), equalTo("name-in-settings")); - - // test only node.name in settings - System.clearProperty("name"); - settings = settingsBuilder() - .put("node.name", "node-name") - .put(baseEnvSettings) - .build(); - env = InternalSettingsPreparer.prepareEnvironment(settings, null); - assertThat(env.settings().get("name"), equalTo("node-name")); - - // test no name at all results in name being set - env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null); - assertThat(env.settings().get("name"), not("name-in-settings")); - assertThat(env.settings().get("name"), not("sys-prop-name")); - assertThat(env.settings().get("name"), not("node-name")); - assertThat(env.settings().get("name"), notNullValue()); - } finally { - System.clearProperty("name"); - } - } -} diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java index ca9f5aa96a7..157a7b787cf 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/tribe/TribeUnitTests.java @@ -65,14 +65,14 @@ public class TribeUnitTests extends ESTestCase { Settings.builder() .put(baseSettings) .put("cluster.name", "tribe1") - .put("name", "tribe1_node") + .put("node.name", "tribe1_node") .put(DiscoveryService.DISCOVERY_SEED_SETTING.getKey(), random().nextLong()) .build()).start(); tribe2 = new TribeClientNode( Settings.builder() .put(baseSettings) .put("cluster.name", "tribe2") - .put("name", "tribe2_node") + .put("node.name", "tribe2_node") .put(DiscoveryService.DISCOVERY_SEED_SETTING.getKey(), random().nextLong()) .build()).start(); } diff --git a/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/ESSmokeClientTestCase.java b/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/ESSmokeClientTestCase.java index 97e328fb1aa..e9a6ee0fdd8 100644 --- a/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/ESSmokeClientTestCase.java +++ b/qa/smoke-test-client/src/test/java/org/elasticsearch/smoketest/ESSmokeClientTestCase.java @@ -77,7 +77,7 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase { private static Client startClient(Path tempDir, TransportAddress... transportAddresses) { Settings clientSettings = Settings.settingsBuilder() - .put("name", "qa_smoke_client_" + counter.getAndIncrement()) + .put("node.name", "qa_smoke_client_" + counter.getAndIncrement()) .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) // prevents any settings to be replaced by system properties. .put("client.transport.ignore_cluster_name", true) .put(Environment.PATH_HOME_SETTING.getKey(), tempDir) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java index 21cf79f6075..cbd2669c92c 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -73,7 +73,7 @@ public final class ExternalTestCluster extends TestCluster { super(0); Settings clientSettings = Settings.settingsBuilder() .put(additionalSettings) - .put("name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement()) + .put("node. name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement()) .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) // prevents any settings to be replaced by system properties. .put("client.transport.ignore_cluster_name", true) .put(Environment.PATH_HOME_SETTING.getKey(), tempDir) diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index d9f634d503e..61a58c59b1e 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -588,7 +588,7 @@ public final class InternalTestCluster extends TestCluster { Settings finalSettings = settingsBuilder() .put(Environment.PATH_HOME_SETTING.getKey(), baseDir) // allow overriding path.home .put(settings) - .put("name", name) + .put("node.name", name) .put(DiscoveryService.DISCOVERY_SEED_SETTING.getKey(), seed) .build(); MockNode node = new MockNode(finalSettings, version, plugins); @@ -768,7 +768,7 @@ public final class InternalTestCluster extends TestCluster { double nextDouble = random.nextDouble(); if (nextDouble < transportClientRatio) { if (logger.isTraceEnabled()) { - logger.trace("Using transport client for node [{}] sniff: [{}]", node.settings().get("name"), false); + logger.trace("Using transport client for node [{}] sniff: [{}]", node.settings().get("node.name"), false); } return getOrBuildTransportClient(); } else { @@ -883,7 +883,7 @@ public final class InternalTestCluster extends TestCluster { Builder builder = settingsBuilder() .put("client.transport.nodes_sampler_interval", "1s") .put(Environment.PATH_HOME_SETTING.getKey(), baseDir) - .put("name", TRANSPORT_CLIENT_PREFIX + node.settings().get("name")) + .put("node.name", TRANSPORT_CLIENT_PREFIX + node.settings().get("node.name")) .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName).put("client.transport.sniff", sniff) .put(Node.NODE_MODE_SETTING.getKey(), Node.NODE_MODE_SETTING.exists(nodeSettings) ? Node.NODE_MODE_SETTING.get(nodeSettings) : nodeMode) .put("logger.prefix", nodeSettings.get("logger.prefix", "")) @@ -1763,7 +1763,7 @@ public final class InternalTestCluster extends TestCluster { @Override public boolean test(Settings settings) { - return nodeNames.contains(settings.get("name")); + return nodeNames.contains(settings.get("node.name")); } } diff --git a/test/framework/src/main/java/org/elasticsearch/test/tasks/MockTaskManager.java b/test/framework/src/main/java/org/elasticsearch/test/tasks/MockTaskManager.java index 9b6bc72162c..4c48f990d6a 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/tasks/MockTaskManager.java +++ b/test/framework/src/main/java/org/elasticsearch/test/tasks/MockTaskManager.java @@ -19,6 +19,7 @@ package org.elasticsearch.test.tasks; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.TaskManager; @@ -32,7 +33,7 @@ import java.util.concurrent.CopyOnWriteArrayList; */ public class MockTaskManager extends TaskManager { - public static final String USE_MOCK_TASK_MANAGER = "tests.mock.taskmanager.enabled"; + public static final Setting USE_MOCK_TASK_MANAGER_SETTING = Setting.boolSetting("tests.mock.taskmanager.enabled", false, false, Setting.Scope.CLUSTER); private final Collection listeners = new CopyOnWriteArrayList<>(); diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java b/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java index 9e8d7a4af85..fb310239155 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/AssertingLocalTransport.java @@ -26,6 +26,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.VersionUtils; @@ -59,6 +60,11 @@ public class AssertingLocalTransport extends LocalTransport { public Settings additionalSettings() { return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "mock").build(); } + + public void onModule(SettingsModule module) { + module.registerSetting(ASSERTING_TRANSPORT_MIN_VERSION_KEY); + module.registerSetting(ASSERTING_TRANSPORT_MAX_VERSION_KEY); + } } public static final Setting ASSERTING_TRANSPORT_MIN_VERSION_KEY = new Setting<>("transport.asserting.version.min", diff --git a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java index 84c981d60d5..41a83a0bd06 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/transport/MockTransportService.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; @@ -80,6 +81,10 @@ public class MockTransportService extends TransportService { public void onModule(NetworkModule module) { module.registerTransportService("mock", MockTransportService.class); } + + public void onModule(SettingsModule module) { + module.registerSetting(MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING); + } @Override public Settings additionalSettings() { return Settings.builder().put(NetworkModule.TRANSPORT_SERVICE_TYPE_KEY, "mock").build(); @@ -104,7 +109,7 @@ public class MockTransportService extends TransportService { @Override protected TaskManager createTaskManager() { - if (settings.getAsBoolean(MockTaskManager.USE_MOCK_TASK_MANAGER, false)) { + if (MockTaskManager.USE_MOCK_TASK_MANAGER_SETTING.get(settings)) { return new MockTaskManager(settings); } else { return super.createTaskManager();