Core: Drop settings member from AbstractComponent (#35083)

Drops the `Settings` member from `AbstractComponent`, moving it from the
base class on to the classes that use it. For the most part this is a
mechanical change that doesn't drop `Settings` accesses. The one
exception to this is naming threads where it switches from an invocation
that passes `Settings` and extracts the node name to one that explicitly
passes the node name.

This change doesn't drop the `Settings` argument from
`AbstractComponent`'s ctor because this change is big enough as is.
We'll do that in a follow up change.
This commit is contained in:
Nik Everett 2018-10-30 16:10:38 -04:00 committed by GitHub
parent 0f9a7b3344
commit 086ada4c08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 230 additions and 100 deletions

View File

@ -82,21 +82,21 @@ public class URLRepository extends BlobStoreRepository {
NamedXContentRegistry namedXContentRegistry) {
super(metadata, environment.settings(), namedXContentRegistry);
if (URL_SETTING.exists(metadata.settings()) == false && REPOSITORIES_URL_SETTING.exists(settings) == false) {
if (URL_SETTING.exists(metadata.settings()) == false && REPOSITORIES_URL_SETTING.exists(environment.settings()) == false) {
throw new RepositoryException(metadata.name(), "missing url");
}
this.environment = environment;
supportedProtocols = SUPPORTED_PROTOCOLS_SETTING.get(settings);
urlWhiteList = ALLOWED_URLS_SETTING.get(settings).toArray(new URIPattern[]{});
supportedProtocols = SUPPORTED_PROTOCOLS_SETTING.get(environment.settings());
urlWhiteList = ALLOWED_URLS_SETTING.get(environment.settings()).toArray(new URIPattern[]{});
basePath = BlobPath.cleanPath();
url = URL_SETTING.exists(metadata.settings())
? URL_SETTING.get(metadata.settings()) : REPOSITORIES_URL_SETTING.get(settings);
? URL_SETTING.get(metadata.settings()) : REPOSITORIES_URL_SETTING.get(environment.settings());
}
@Override
protected BlobStore createBlobStore() {
URL normalizedURL = checkURL(url);
return new URLBlobStore(settings, normalizedURL);
return new URLBlobStore(environment.settings(), normalizedURL);
}
// only use for testing

View File

@ -93,6 +93,7 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic
}
}
private final Settings settings;
private final AzureComputeService azureComputeService;
private TransportService transportService;
private NetworkService networkService;
@ -108,6 +109,7 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic
public AzureUnicastHostsProvider(Settings settings, AzureComputeService azureComputeService,
TransportService transportService, NetworkService networkService) {
super(settings);
this.settings = settings;
this.azureComputeService = azureComputeService;
this.transportService = transportService;
this.networkService = networkService;

View File

@ -94,6 +94,7 @@ public class GceInstancesServiceImpl extends AbstractComponent implements GceIns
return instances;
}
private final Settings settings;
private Compute client;
private TimeValue refreshInterval = null;
private long lastRefresh;
@ -108,6 +109,7 @@ public class GceInstancesServiceImpl extends AbstractComponent implements GceIns
public GceInstancesServiceImpl(Settings settings) {
super(settings);
this.settings = settings;
this.validateCerts = GCE_VALIDATE_CERTIFICATES.get(settings);
this.project = resolveProject();
this.zones = resolveZones();

View File

@ -44,11 +44,14 @@ public class GceMetadataService extends AbstractLifecycleComponent {
public static final Setting<String> GCE_HOST =
new Setting<>("cloud.gce.host", "http://metadata.google.internal", Function.identity(), Setting.Property.NodeScope);
private final Settings settings;
/** Global instance of the HTTP transport. */
private HttpTransport gceHttpTransport;
public GceMetadataService(Settings settings) {
super(settings);
this.settings = settings;
}
protected synchronized HttpTransport getGceHttpTransport() throws GeneralSecurityException, IOException {

View File

@ -58,6 +58,7 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas
private static final String TERMINATED = "TERMINATED";
}
private final Settings settings;
private final GceInstancesService gceInstancesService;
private TransportService transportService;
private NetworkService networkService;
@ -74,6 +75,7 @@ public class GceUnicastHostsProvider extends AbstractComponent implements Unicas
TransportService transportService,
NetworkService networkService) {
super(settings);
this.settings = settings;
this.gceInstancesService = gceInstancesService;
this.transportService = transportService;
this.networkService = networkService;

View File

@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.RepositoryMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.blobstore.BlobPath;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -55,6 +56,7 @@ class GoogleCloudStorageRepository extends BlobStoreRepository {
byteSizeSetting("chunk_size", MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, MAX_CHUNK_SIZE, Property.NodeScope, Property.Dynamic);
static final Setting<String> CLIENT_NAME = new Setting<>("client", "default", Function.identity());
private final Settings settings;
private final GoogleCloudStorageService storageService;
private final BlobPath basePath;
private final boolean compress;
@ -66,6 +68,7 @@ class GoogleCloudStorageRepository extends BlobStoreRepository {
NamedXContentRegistry namedXContentRegistry,
GoogleCloudStorageService storageService) {
super(metadata, environment.settings(), namedXContentRegistry);
this.settings = environment.settings();
this.storageService = storageService;
String basePath = BASE_PATH.get(metadata.settings());

View File

@ -148,6 +148,8 @@ class S3Repository extends BlobStoreRepository {
*/
static final Setting<String> BASE_PATH_SETTING = Setting.simpleString("base_path");
private final Settings settings;
private final S3Service service;
private final String bucket;
@ -178,6 +180,7 @@ class S3Repository extends BlobStoreRepository {
final NamedXContentRegistry namedXContentRegistry,
final S3Service service) {
super(metadata, settings, namedXContentRegistry);
this.settings = settings;
this.service = service;
// Parse and validate the user's S3 Storage Class setting

View File

@ -58,7 +58,7 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler {
Setting.boolSetting("test.setting.not_deprecated", false,
Setting.Property.NodeScope, Setting.Property.Dynamic);
private static final Map<String, Setting<?>> SETTINGS;
private static final Map<String, Setting<?>> SETTINGS_MAP;
static {
Map<String, Setting<?>> settingsMap = new HashMap<>(3);
@ -67,14 +67,17 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler {
settingsMap.put(TEST_DEPRECATED_SETTING_TRUE2.getKey(), TEST_DEPRECATED_SETTING_TRUE2);
settingsMap.put(TEST_NOT_DEPRECATED_SETTING.getKey(), TEST_NOT_DEPRECATED_SETTING);
SETTINGS = Collections.unmodifiableMap(settingsMap);
SETTINGS_MAP = Collections.unmodifiableMap(settingsMap);
}
public static final String DEPRECATED_ENDPOINT = "[/_test_cluster/deprecated_settings] exists for deprecated tests";
public static final String DEPRECATED_USAGE = "[deprecated_settings] usage is deprecated. use [settings] instead";
private final Settings settings;
public TestDeprecationHeaderRestAction(Settings settings, RestController controller) {
super(settings);
this.settings = settings;
controller.registerAsDeprecatedHandler(RestRequest.Method.GET, "/_test_cluster/deprecated_settings", this,
DEPRECATED_ENDPOINT, deprecationLogger);
@ -107,7 +110,7 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler {
builder.startObject().startArray("settings");
for (String setting : settings) {
builder.startObject().field(setting, SETTINGS.get(setting).getRaw(this.settings)).endObject();
builder.startObject().field(setting, SETTINGS_MAP.get(setting).getRaw(this.settings)).endObject();
}
builder.endArray().endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));

View File

@ -79,6 +79,7 @@ import java.util.function.Function;
*/
public class TransportAnalyzeAction extends TransportSingleShardAction<AnalyzeRequest, AnalyzeResponse> {
private final Settings settings;
private final IndicesService indicesService;
private final Environment environment;
@ -88,6 +89,7 @@ public class TransportAnalyzeAction extends TransportSingleShardAction<AnalyzeRe
IndexNameExpressionResolver indexNameExpressionResolver, Environment environment) {
super(settings, AnalyzeAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
AnalyzeRequest::new, ThreadPool.Names.ANALYZE);
this.settings = settings;
this.indicesService = indicesService;
this.environment = environment;
}

View File

@ -99,7 +99,7 @@ public class TransportShardBulkAction extends TransportWriteAction<BulkShardRequ
}
@Override
protected TransportRequestOptions transportOptions() {
protected TransportRequestOptions transportOptions(Settings settings) {
return BulkAction.INSTANCE.transportOptions(settings);
}

View File

@ -34,21 +34,22 @@ import org.elasticsearch.transport.TransportService;
public class TransportMainAction extends HandledTransportAction<MainRequest, MainResponse> {
private final String nodeName;
private final ClusterService clusterService;
@Inject
public TransportMainAction(Settings settings, TransportService transportService,
ActionFilters actionFilters, ClusterService clusterService) {
super(settings, MainAction.NAME, transportService, actionFilters, MainRequest::new);
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
this.clusterService = clusterService;
}
@Override
protected void doExecute(Task task, MainRequest request, ActionListener<MainResponse> listener) {
ClusterState clusterState = clusterService.state();
assert Node.NODE_NAME_SETTING.exists(settings);
listener.onResponse(
new MainResponse(Node.NODE_NAME_SETTING.get(settings), Version.CURRENT, clusterState.getClusterName(),
new MainResponse(nodeName, Version.CURRENT, clusterState.getClusterName(),
clusterState.metaData().clusterUUID(), Build.CURRENT));
}
}

View File

@ -147,7 +147,7 @@ public abstract class TransportReplicationAction<
this.transportReplicaAction = actionName + "[r]";
registerRequestHandlers(actionName, transportService, request, replicaRequest, executor);
this.transportOptions = transportOptions();
this.transportOptions = transportOptions(settings);
this.syncGlobalCheckpointAfterOperation = syncGlobalCheckpointAfterOperation;
}
@ -231,7 +231,7 @@ public abstract class TransportReplicationAction<
return true;
}
protected TransportRequestOptions transportOptions() {
protected TransportRequestOptions transportOptions(Settings settings) {
return TransportRequestOptions.EMPTY;
}

View File

@ -344,12 +344,14 @@ import java.util.Map;
public abstract class AbstractClient extends AbstractComponent implements Client {
protected final Settings settings;
private final ThreadPool threadPool;
private final Admin admin;
private final ThreadedActionListener.Wrapper threadedWrapper;
public AbstractClient(Settings settings, ThreadPool threadPool) {
super(settings);
this.settings = settings;
this.threadPool = threadPool;
this.admin = new Admin(this);
this.threadedWrapper = new ThreadedActionListener.Wrapper(logger, settings, threadPool);

View File

@ -130,15 +130,15 @@ final class TransportClientNodesService extends AbstractComponent implements Clo
this.threadPool = threadPool;
this.minCompatibilityVersion = Version.CURRENT.minimumCompatibilityVersion();
this.nodesSamplerInterval = TransportClient.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL.get(this.settings);
this.pingTimeout = TransportClient.CLIENT_TRANSPORT_PING_TIMEOUT.get(this.settings).millis();
this.ignoreClusterName = TransportClient.CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME.get(this.settings);
this.nodesSamplerInterval = TransportClient.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL.get(settings);
this.pingTimeout = TransportClient.CLIENT_TRANSPORT_PING_TIMEOUT.get(settings).millis();
this.ignoreClusterName = TransportClient.CLIENT_TRANSPORT_IGNORE_CLUSTER_NAME.get(settings);
if (logger.isDebugEnabled()) {
logger.debug("node_sampler_interval[{}]", nodesSamplerInterval);
}
if (TransportClient.CLIENT_TRANSPORT_SNIFF.get(this.settings)) {
if (TransportClient.CLIENT_TRANSPORT_SNIFF.get(settings)) {
this.nodesSampler = new SniffNodesSampler();
} else {
this.nodesSampler = new SimpleNodeSampler();

View File

@ -106,6 +106,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
public static final int MAX_INDEX_NAME_BYTES = 255;
private final Settings settings;
private final ClusterService clusterService;
private final IndicesService indicesService;
private final AllocationService allocationService;
@ -128,6 +129,7 @@ public class MetaDataCreateIndexService extends AbstractComponent {
final NamedXContentRegistry xContentRegistry,
final boolean forbidPrivateIndexSettings) {
super(settings);
this.settings = settings;
this.clusterService = clusterService;
this.indicesService = indicesService;
this.allocationService = allocationService;

View File

@ -48,7 +48,7 @@ import static java.util.stream.Collectors.toSet;
* Deletes indices.
*/
public class MetaDataDeleteIndexService extends AbstractComponent {
private final Settings settings;
private final ClusterService clusterService;
private final AllocationService allocationService;
@ -56,6 +56,7 @@ public class MetaDataDeleteIndexService extends AbstractComponent {
@Inject
public MetaDataDeleteIndexService(Settings settings, ClusterService clusterService, AllocationService allocationService) {
super(settings);
this.settings = settings;
this.clusterService = clusterService;
this.allocationService = allocationService;
}

View File

@ -53,6 +53,7 @@ import java.util.function.UnaryOperator;
*/
public class MetaDataIndexUpgradeService extends AbstractComponent {
private final Settings settings;
private final NamedXContentRegistry xContentRegistry;
private final MapperRegistry mapperRegistry;
private final IndexScopedSettings indexScopedSettings;
@ -62,6 +63,7 @@ public class MetaDataIndexUpgradeService extends AbstractComponent {
IndexScopedSettings indexScopedSettings,
Collection<UnaryOperator<IndexMetaData>> indexMetaDataUpgraders) {
super(settings);
this.settings = settings;
this.xContentRegistry = xContentRegistry;
this.mapperRegistry = mapperRegistry;
this.indexScopedSettings = indexScopedSettings;

View File

@ -73,8 +73,11 @@ public class ShardsLimitAllocationDecider extends AllocationDecider {
Setting.intSetting("cluster.routing.allocation.total_shards_per_node", -1, -1,
Property.Dynamic, Property.NodeScope);
private final Settings settings;
public ShardsLimitAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
super(settings);
this.settings = settings;
this.clusterShardLimit = CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING.get(settings);
clusterSettings.addSettingsUpdateConsumer(CLUSTER_TOTAL_SHARDS_PER_NODE_SETTING, this::setClusterShardLimit);
}

View File

@ -134,7 +134,7 @@ public class ClusterApplierService extends AbstractLifecycleComponent implements
addListener(localNodeMasterListeners);
threadPoolExecutor = EsExecutors.newSinglePrioritizing(
nodeName + "/" + CLUSTER_UPDATE_THREAD_NAME,
daemonThreadFactory(settings, CLUSTER_UPDATE_THREAD_NAME),
daemonThreadFactory(nodeName, CLUSTER_UPDATE_THREAD_NAME),
threadPool.getThreadContext(),
threadPool.scheduler());
}

View File

@ -55,6 +55,11 @@ public class ClusterService extends AbstractLifecycleComponent {
public static final org.elasticsearch.common.settings.Setting.AffixSetting<String> USER_DEFINED_META_DATA =
Setting.prefixKeySetting("cluster.metadata.", (key) -> Setting.simpleString(key, Property.Dynamic, Property.NodeScope));
/**
* The node's settings.
*/
private final Settings settings;
private final ClusterName clusterName;
private final OperationRouting operationRouting;
@ -65,6 +70,7 @@ public class ClusterService extends AbstractLifecycleComponent {
public ClusterService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) {
super(settings);
this.settings = settings;
this.nodeName = Node.NODE_NAME_SETTING.get(settings);
this.masterService = new MasterService(nodeName, settings, threadPool);
this.operationRouting = new OperationRouting(settings, clusterSettings);
@ -199,6 +205,9 @@ public class ClusterService extends AbstractLifecycleComponent {
return clusterSettings;
}
/**
* The node's settings.
*/
public Settings getSettings() {
return settings;
}

View File

@ -109,7 +109,7 @@ public class MasterService extends AbstractLifecycleComponent {
Objects.requireNonNull(clusterStateSupplier, "please set a cluster state supplier before starting");
threadPoolExecutor = EsExecutors.newSinglePrioritizing(
nodeName + "/" + MASTER_UPDATE_THREAD_NAME,
daemonThreadFactory(settings, MASTER_UPDATE_THREAD_NAME),
daemonThreadFactory(nodeName, MASTER_UPDATE_THREAD_NAME),
threadPool.getThreadContext(),
threadPool.scheduler());
taskBatcher = new Batcher(logger, threadPoolExecutor);

View File

@ -26,10 +26,8 @@ import org.elasticsearch.common.settings.Settings;
public abstract class AbstractComponent {
protected final Logger logger;
protected final Settings settings;
public AbstractComponent(Settings settings) {
this.logger = LogManager.getLogger(getClass());
this.settings = settings;
}
}

View File

@ -49,15 +49,17 @@ import java.util.stream.Collectors;
*/
public abstract class AbstractScopedSettings extends AbstractComponent {
public static final String ARCHIVED_SETTINGS_PREFIX = "archived.";
private Settings lastSettingsApplied = Settings.EMPTY;
private static final Pattern KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])*[-\\w]+$");
private static final Pattern GROUP_KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])+$");
private static final Pattern AFFIX_KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])+[*](?:[.][-\\w]+)+$");
private final Settings settings;
private final List<SettingUpdater<?>> settingUpdaters = new CopyOnWriteArrayList<>();
private final Map<String, Setting<?>> complexMatchers;
private final Map<String, Setting<?>> keySettings;
private final Map<Setting<?>, SettingUpgrader<?>> settingUpgraders;
private final Setting.Property scope;
private static final Pattern KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])*[-\\w]+$");
private static final Pattern GROUP_KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])+$");
private static final Pattern AFFIX_KEY_PATTERN = Pattern.compile("^(?:[-\\w]+[.])+[*](?:[.][-\\w]+)+$");
private Settings lastSettingsApplied;
protected AbstractScopedSettings(
final Settings settings,
@ -65,6 +67,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
final Set<SettingUpgrader<?>> settingUpgraders,
final Setting.Property scope) {
super(settings);
this.settings = settings;
this.lastSettingsApplied = Settings.EMPTY;
this.settingUpgraders =
@ -105,6 +108,7 @@ public abstract class AbstractScopedSettings extends AbstractComponent {
protected AbstractScopedSettings(Settings nodeSettings, Settings scopeSettings, AbstractScopedSettings other) {
super(nodeSettings);
this.settings = nodeSettings;
this.lastSettingsApplied = scopeSettings;
this.scope = other.scope;
complexMatchers = other.complexMatchers;

View File

@ -179,6 +179,11 @@ public class EsExecutors {
return daemonThreadFactory(threadName(settings, namePrefix));
}
public static ThreadFactory daemonThreadFactory(String nodeName, String namePrefix) {
assert nodeName != null && false == nodeName.isEmpty();
return daemonThreadFactory(threadName(nodeName, namePrefix));
}
public static ThreadFactory daemonThreadFactory(Settings settings, String ... names) {
return daemonThreadFactory(threadName(settings, names));
}

View File

@ -47,6 +47,7 @@ import static org.elasticsearch.gateway.GatewayService.STATE_NOT_RECOVERED_BLOCK
*/
public class SingleNodeDiscovery extends AbstractLifecycleComponent implements Discovery {
private final ClusterName clusterName;
protected final TransportService transportService;
private final ClusterApplier clusterApplier;
private volatile ClusterState clusterState;
@ -54,6 +55,7 @@ public class SingleNodeDiscovery extends AbstractLifecycleComponent implements D
public SingleNodeDiscovery(final Settings settings, final TransportService transportService,
final MasterService masterService, final ClusterApplier clusterApplier) {
super(Objects.requireNonNull(settings));
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
this.transportService = Objects.requireNonNull(transportService);
masterService.setClusterStateSupplier(() -> clusterState);
this.clusterApplier = clusterApplier;
@ -114,7 +116,7 @@ public class SingleNodeDiscovery extends AbstractLifecycleComponent implements D
}
protected ClusterState createInitialState(DiscoveryNode localNode) {
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
ClusterState.Builder builder = ClusterState.builder(clusterName);
return builder.nodes(DiscoveryNodes.builder().add(localNode)
.localNodeId(localNode.getId())
.masterNodeId(localNode.getId())

View File

@ -121,6 +121,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
private final NodesFaultDetection nodesFD;
private final PublishClusterStateAction publishClusterState;
private final MembershipAction membership;
private final ClusterName clusterName;
private final ThreadPool threadPool;
private final TimeValue pingTimeout;
@ -172,7 +173,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
this.maxPingsFromAnotherMaster = MAX_PINGS_FROM_ANOTHER_MASTER_SETTING.get(settings);
this.sendLeaveRequest = SEND_LEAVE_REQUEST_SETTING.get(settings);
this.threadPool = threadPool;
ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
this.clusterName = ClusterName.CLUSTER_NAME_SETTING.get(settings);
this.committedState = new AtomicReference<>();
this.masterElectionIgnoreNonMasters = MASTER_ELECTION_IGNORE_NON_MASTER_PINGS_SETTING.get(settings);
@ -252,7 +253,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implements Discover
// set initial state
assert committedState.get() == null;
assert localNode != null;
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
ClusterState.Builder builder = ClusterState.builder(clusterName);
ClusterState initialState = builder
.blocks(ClusterBlocks.builder()
.addGlobalBlock(STATE_NOT_RECOVERED_BLOCK)

View File

@ -23,7 +23,6 @@ import com.carrotsearch.hppc.ObjectFloatHashMap;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.action.FailedNodeException;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
@ -153,7 +152,7 @@ public class Gateway extends AbstractComponent {
clusterSettings.upgradeSettings(metaDataBuilder.transientSettings()),
e -> logUnknownSetting("transient", e),
(e, ex) -> logInvalidSetting("transient", e, ex)));
ClusterState.Builder builder = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.get(settings));
ClusterState.Builder builder = ClusterState.builder(clusterService.getClusterName());
builder.metaData(metaDataBuilder);
return builder;
}

View File

@ -101,22 +101,22 @@ public class GatewayService extends AbstractLifecycleComponent implements Cluste
this.clusterService = clusterService;
this.threadPool = threadPool;
// allow to control a delay of when indices will get created
this.expectedNodes = EXPECTED_NODES_SETTING.get(this.settings);
this.expectedDataNodes = EXPECTED_DATA_NODES_SETTING.get(this.settings);
this.expectedMasterNodes = EXPECTED_MASTER_NODES_SETTING.get(this.settings);
this.expectedNodes = EXPECTED_NODES_SETTING.get(settings);
this.expectedDataNodes = EXPECTED_DATA_NODES_SETTING.get(settings);
this.expectedMasterNodes = EXPECTED_MASTER_NODES_SETTING.get(settings);
if (RECOVER_AFTER_TIME_SETTING.exists(this.settings)) {
recoverAfterTime = RECOVER_AFTER_TIME_SETTING.get(this.settings);
if (RECOVER_AFTER_TIME_SETTING.exists(settings)) {
recoverAfterTime = RECOVER_AFTER_TIME_SETTING.get(settings);
} else if (expectedNodes >= 0 || expectedDataNodes >= 0 || expectedMasterNodes >= 0) {
recoverAfterTime = DEFAULT_RECOVER_AFTER_TIME_IF_EXPECTED_NODES_IS_SET;
} else {
recoverAfterTime = null;
}
this.recoverAfterNodes = RECOVER_AFTER_NODES_SETTING.get(this.settings);
this.recoverAfterDataNodes = RECOVER_AFTER_DATA_NODES_SETTING.get(this.settings);
this.recoverAfterNodes = RECOVER_AFTER_NODES_SETTING.get(settings);
this.recoverAfterDataNodes = RECOVER_AFTER_DATA_NODES_SETTING.get(settings);
// default the recover after master nodes to the minimum master nodes in the discovery
if (RECOVER_AFTER_MASTER_NODES_SETTING.exists(this.settings)) {
recoverAfterMasterNodes = RECOVER_AFTER_MASTER_NODES_SETTING.get(this.settings);
if (RECOVER_AFTER_MASTER_NODES_SETTING.exists(settings)) {
recoverAfterMasterNodes = RECOVER_AFTER_MASTER_NODES_SETTING.get(settings);
} else {
// TODO: change me once the minimum_master_nodes is changed too
recoverAfterMasterNodes = settings.getAsInt("discovery.zen.minimum_master_nodes", -1);

View File

@ -67,6 +67,7 @@ public class TransportNodesListGatewayStartedShards extends
TransportNodesListGatewayStartedShards.NodeGatewayStartedShards> {
public static final String ACTION_NAME = "internal:gateway/local/started_shards";
private final Settings settings;
private final NodeEnvironment nodeEnv;
private final IndicesService indicesService;
private final NamedXContentRegistry namedXContentRegistry;
@ -78,6 +79,7 @@ public class TransportNodesListGatewayStartedShards extends
NamedXContentRegistry namedXContentRegistry) {
super(settings, ACTION_NAME, threadPool, clusterService, transportService, actionFilters,
Request::new, NodeRequest::new, ThreadPool.Names.FETCH_SHARD_STARTED, NodeGatewayStartedShards.class);
this.settings = settings;
this.nodeEnv = env;
this.indicesService = indicesService;
this.namedXContentRegistry = namedXContentRegistry;

View File

@ -63,7 +63,7 @@ import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_PUBLISH_
import static org.elasticsearch.http.HttpTransportSettings.SETTING_HTTP_PUBLISH_PORT;
public abstract class AbstractHttpServerTransport extends AbstractLifecycleComponent implements HttpServerTransport {
protected final Settings settings;
public final HttpHandlingSettings handlingSettings;
protected final NetworkService networkService;
protected final BigArrays bigArrays;
@ -84,6 +84,7 @@ public abstract class AbstractHttpServerTransport extends AbstractLifecycleCompo
protected AbstractHttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, ThreadPool threadPool,
NamedXContentRegistry xContentRegistry, Dispatcher dispatcher) {
super(settings);
this.settings = settings;
this.networkService = networkService;
this.bigArrays = bigArrays;
this.threadPool = threadPool;

View File

@ -103,8 +103,8 @@ public class IndexingMemoryController extends AbstractComponent implements Index
// null means we used the default (10%)
if (indexingBufferSetting == null || indexingBufferSetting.endsWith("%")) {
// We only apply the min/max when % value was used for the index buffer:
ByteSizeValue minIndexingBuffer = MIN_INDEX_BUFFER_SIZE_SETTING.get(this.settings);
ByteSizeValue maxIndexingBuffer = MAX_INDEX_BUFFER_SIZE_SETTING.get(this.settings);
ByteSizeValue minIndexingBuffer = MIN_INDEX_BUFFER_SIZE_SETTING.get(settings);
ByteSizeValue maxIndexingBuffer = MAX_INDEX_BUFFER_SIZE_SETTING.get(settings);
if (indexingBuffer.getBytes() < minIndexingBuffer.getBytes()) {
indexingBuffer = minIndexingBuffer;
}
@ -114,9 +114,9 @@ public class IndexingMemoryController extends AbstractComponent implements Index
}
this.indexingBuffer = indexingBuffer;
this.inactiveTime = SHARD_INACTIVE_TIME_SETTING.get(this.settings);
this.inactiveTime = SHARD_INACTIVE_TIME_SETTING.get(settings);
// we need to have this relatively small to free up heap quickly enough
this.interval = SHARD_MEMORY_INTERVAL_TIME_SETTING.get(this.settings);
this.interval = SHARD_MEMORY_INTERVAL_TIME_SETTING.get(settings);
this.statusChecker = new ShardsIndicesStatusChecker();

View File

@ -173,6 +173,10 @@ public class IndicesService extends AbstractLifecycleComponent
}
}
/**
* The node's settings.
*/
private final Settings settings;
private final PluginsService pluginsService;
private final NodeEnvironment nodeEnv;
private final NamedXContentRegistry xContentRegistry;
@ -215,6 +219,7 @@ public class IndicesService extends AbstractLifecycleComponent
Collection<Function<IndexSettings, Optional<EngineFactory>>> engineFactoryProviders,
Map<String, Function<IndexSettings, IndexStore>> indexStoreFactories) {
super(settings);
this.settings = settings;
this.threadPool = threadPool;
this.pluginsService = pluginsService;
this.nodeEnv = nodeEnv;
@ -483,7 +488,7 @@ public class IndicesService extends AbstractLifecycleComponent
IndicesFieldDataCache indicesFieldDataCache,
List<IndexEventListener> builtInListeners,
IndexingOperationListener... indexingOperationListeners) throws IOException {
final IndexSettings idxSettings = new IndexSettings(indexMetaData, this.settings, indexScopedSettings);
final IndexSettings idxSettings = new IndexSettings(indexMetaData, settings, indexScopedSettings);
// we ignore private settings since they are not registered settings
indexScopedSettings.validate(indexMetaData.getSettings(), true, true, true);
logger.debug("creating Index [{}], shards [{}]/[{}] - reason [{}]",

View File

@ -107,6 +107,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
private static final ShardStateAction.Listener SHARD_STATE_ACTION_LISTENER = new ShardStateAction.Listener() {
};
private final Settings settings;
// a list of shards that failed during recovery
// we keep track of these shards in order to prevent repeated recovery of these shards on each cluster state update
final ConcurrentMap<ShardId, ShardRouting> failedShardsCache = ConcurrentCollections.newConcurrentMap();
@ -156,6 +157,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
PrimaryReplicaSyncer primaryReplicaSyncer,
Consumer<ShardId> globalCheckpointSyncer) {
super(settings);
this.settings = settings;
this.buildInIndexListener =
Arrays.asList(
peerRecoverySourceService,
@ -172,7 +174,7 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent imple
this.repositoriesService = repositoriesService;
this.primaryReplicaSyncer = primaryReplicaSyncer;
this.globalCheckpointSyncer = globalCheckpointSyncer;
this.sendRefreshMapping = this.settings.getAsBoolean("indices.cluster.send_refresh_mapping", true);
this.sendRefreshMapping = settings.getAsBoolean("indices.cluster.send_refresh_mapping", true);
}
@Override

View File

@ -78,6 +78,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
Property.NodeScope);
public static final String ACTION_SHARD_EXISTS = "internal:index/shard/exists";
private static final EnumSet<IndexShardState> ACTIVE_STATES = EnumSet.of(IndexShardState.STARTED);
private final Settings settings;
private final IndicesService indicesService;
private final ClusterService clusterService;
private final TransportService transportService;
@ -92,6 +93,7 @@ public class IndicesStore extends AbstractComponent implements ClusterStateListe
public IndicesStore(Settings settings, IndicesService indicesService,
ClusterService clusterService, TransportService transportService, ThreadPool threadPool) {
super(settings);
this.settings = settings;
this.indicesService = indicesService;
this.clusterService = clusterService;
this.transportService = transportService;

View File

@ -66,6 +66,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
public static final String ACTION_NAME = "internal:cluster/nodes/indices/shard/store";
private final Settings settings;
private final IndicesService indicesService;
private final NodeEnvironment nodeEnv;
private final NamedXContentRegistry namedXContentRegistry;
@ -77,6 +78,7 @@ public class TransportNodesListShardStoreMetaData extends TransportNodesAction<T
ActionFilters actionFilters, NamedXContentRegistry namedXContentRegistry) {
super(settings, ACTION_NAME, threadPool, clusterService, transportService, actionFilters,
Request::new, NodeRequest::new, ThreadPool.Names.FETCH_SHARD_STORE, NodeStoreFilesMetaData.class);
this.settings = settings;
this.indicesService = indicesService;
this.nodeEnv = nodeEnv;
this.namedXContentRegistry = namedXContentRegistry;

View File

@ -46,7 +46,7 @@ import java.io.Closeable;
import java.io.IOException;
public class NodeService extends AbstractComponent implements Closeable {
private final Settings settings;
private final ThreadPool threadPool;
private final MonitorService monitorService;
private final TransportService transportService;
@ -69,6 +69,7 @@ public class NodeService extends AbstractComponent implements Closeable {
SettingsFilter settingsFilter, ResponseCollectorService responseCollectorService,
SearchTransportService searchTransportService) {
super(settings);
this.settings = settings;
this.threadPool = threadPool;
this.monitorService = monitorService;
this.transportService = transportService;

View File

@ -72,6 +72,7 @@ import static org.elasticsearch.common.io.FileSystemUtils.isAccessibleDirectory;
public class PluginsService extends AbstractComponent {
private final Settings settings;
private final Path configPath;
/**
@ -79,6 +80,7 @@ public class PluginsService extends AbstractComponent {
*/
private final List<Tuple<PluginInfo, Plugin>> plugins;
private final PluginsAndModules info;
public static final Setting<List<String>> MANDATORY_SETTING =
Setting.listSetting("plugin.mandatory", Collections.emptyList(), Function.identity(), Property.NodeScope);
@ -99,7 +101,7 @@ public class PluginsService extends AbstractComponent {
*/
public PluginsService(Settings settings, Path configPath, Path modulesDirectory, Path pluginsDirectory, Collection<Class<? extends Plugin>> classpathPlugins) {
super(settings);
this.settings = settings;
this.configPath = configPath;
List<Tuple<PluginInfo, Plugin>> pluginsLoaded = new ArrayList<>();

View File

@ -204,6 +204,8 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
private static final String DATA_BLOB_PREFIX = "__";
private final Settings settings;
private final RateLimiter snapshotRateLimiter;
private final RateLimiter restoreRateLimiter;
@ -234,10 +236,11 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
* Constructs new BlobStoreRepository
*
* @param metadata The metadata for this repository including name and settings
* @param globalSettings Settings for the node this repository object is created on
* @param settings Settings for the node this repository object is created on
*/
protected BlobStoreRepository(RepositoryMetaData metadata, Settings globalSettings, NamedXContentRegistry namedXContentRegistry) {
super(globalSettings);
protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings, NamedXContentRegistry namedXContentRegistry) {
super(settings);
this.settings = settings;
this.metadata = metadata;
this.namedXContentRegistry = namedXContentRegistry;
snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB));

View File

@ -99,10 +99,10 @@ public class FsRepository extends BlobStoreRepository {
if (CHUNK_SIZE_SETTING.exists(metadata.settings())) {
this.chunkSize = CHUNK_SIZE_SETTING.get(metadata.settings());
} else {
this.chunkSize = REPOSITORIES_CHUNK_SIZE_SETTING.get(settings);
this.chunkSize = REPOSITORIES_CHUNK_SIZE_SETTING.get(environment.settings());
}
this.compress = COMPRESS_SETTING.exists(metadata.settings())
? COMPRESS_SETTING.get(metadata.settings()) : REPOSITORIES_COMPRESS_SETTING.get(settings);
? COMPRESS_SETTING.get(metadata.settings()) : REPOSITORIES_COMPRESS_SETTING.get(environment.settings());
this.basePath = BlobPath.cleanPath();
}
@ -110,7 +110,7 @@ public class FsRepository extends BlobStoreRepository {
protected BlobStore createBlobStore() throws Exception {
final String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings());
final Path locationFile = environment.resolveRepoFile(location);
return new FsBlobStore(settings, locationFile);
return new FsBlobStore(environment.settings(), locationFile);
}
@Override

View File

@ -43,12 +43,14 @@ import java.util.Set;
public class RestClusterGetSettingsAction extends BaseRestHandler {
private final Settings settings;
private final ClusterSettings clusterSettings;
private final SettingsFilter settingsFilter;
public RestClusterGetSettingsAction(Settings settings, RestController controller, ClusterSettings clusterSettings,
SettingsFilter settingsFilter) {
super(settings);
this.settings = settings;
this.clusterSettings = clusterSettings;
controller.registerHandler(RestRequest.Method.GET, "/_cluster/settings", this);
this.settingsFilter = settingsFilter;

View File

@ -109,6 +109,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
public static final Setting<List<String>> CONTEXTS_ALLOWED_SETTING =
Setting.listSetting("script.allowed_contexts", Collections.emptyList(), Function.identity(), Setting.Property.NodeScope);
private final Settings settings;
private final Set<String> typesAllowed;
private final Set<String> contextsAllowed;
@ -128,8 +129,7 @@ public class ScriptService extends AbstractComponent implements Closeable, Clust
public ScriptService(Settings settings, Map<String, ScriptEngine> engines, Map<String, ScriptContext<?>> contexts) {
super(settings);
Objects.requireNonNull(settings);
this.settings = Objects.requireNonNull(settings);
this.engines = Objects.requireNonNull(engines);
this.contexts = Objects.requireNonNull(contexts);

View File

@ -34,6 +34,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.BigArrays;
@ -182,13 +183,14 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase,
ResponseCollectorService responseCollectorService) {
super(clusterService.getSettings());
Settings settings = clusterService.getSettings();
this.threadPool = threadPool;
this.clusterService = clusterService;
this.indicesService = indicesService;
this.scriptService = scriptService;
this.responseCollectorService = responseCollectorService;
this.bigArrays = bigArrays;
this.queryPhase = new QueryPhase(settings);
this.queryPhase = new QueryPhase(clusterService.getSettings());
this.fetchPhase = fetchPhase;
this.multiBucketConsumerService = new MultiBucketConsumerService(clusterService, settings);

View File

@ -167,7 +167,7 @@ public abstract class RemoteClusterAware extends AbstractComponent {
Setting.Property.NodeScope),
REMOTE_CLUSTERS_SEEDS);
protected final Settings settings;
protected final ClusterNameExpressionResolver clusterNameResolver;
/**
@ -176,6 +176,7 @@ public abstract class RemoteClusterAware extends AbstractComponent {
*/
protected RemoteClusterAware(Settings settings) {
super(settings);
this.settings = settings;
this.clusterNameResolver = new ClusterNameExpressionResolver(settings);
}

View File

@ -93,6 +93,7 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo
private volatile List<Supplier<DiscoveryNode>> seedNodes;
private volatile boolean skipUnavailable;
private final ConnectHandler connectHandler;
private final TimeValue initialConnectionTimeout;
private SetOnce<ClusterName> remoteClusterName = new SetOnce<>();
/**
@ -112,9 +113,8 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo
}
RemoteClusterConnection(Settings settings, String clusterAlias, List<Supplier<DiscoveryNode>> seedNodes,
TransportService transportService, ConnectionManager connectionManager, int maxNumRemoteConnections, Predicate<DiscoveryNode>
nodePredicate,
String proxyAddress) {
TransportService transportService, ConnectionManager connectionManager, int maxNumRemoteConnections,
Predicate<DiscoveryNode> nodePredicate, String proxyAddress) {
super(settings);
this.transportService = transportService;
this.maxNumRemoteConnections = maxNumRemoteConnections;
@ -140,6 +140,7 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo
// we register the transport service here as a listener to make sure we notify handlers on disconnect etc.
connectionManager.addListener(transportService);
this.proxyAddress = proxyAddress;
initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
}
private static DiscoveryNode maybeAddProxyAddress(String proxyAddress, DiscoveryNode node) {
@ -679,7 +680,6 @@ final class RemoteClusterConnection extends AbstractComponent implements Transpo
public RemoteConnectionInfo getConnectionInfo() {
List<TransportAddress> seedNodeAddresses = seedNodes.stream().map(node -> node.get().getAddress()).collect
(Collectors.toList());
TimeValue initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settings);
return new RemoteConnectionInfo(clusterAlias, seedNodeAddresses, maxNumRemoteConnections, connectedNodes.size(),
initialConnectionTimeout, skipUnavailable);
}

View File

@ -179,6 +179,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
public static final Setting<Settings> DEFAULT_FEATURES_SETTING = Setting.groupSetting(FEATURE_PREFIX + ".", Setting.Property.NodeScope);
private final String[] features;
protected final Settings settings;
private final CircuitBreakerService circuitBreakerService;
protected final ThreadPool threadPool;
private final BigArrays bigArrays;
@ -216,6 +217,7 @@ public abstract class TcpTransport extends AbstractLifecycleComponent implements
CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService) {
super(settings);
this.settings = settings;
this.profileSettings = getProfileSettings(settings);
this.threadPool = threadPool;
this.bigArrays = bigArrays;

View File

@ -106,6 +106,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class ClusterStateChanges extends AbstractComponent {
private static final Settings SETTINGS = Settings.builder()
.put(PATH_HOME_SETTING.getKey(), "dummy")
.build();
private final AllocationService allocationService;
private final ClusterService clusterService;
@ -124,21 +127,21 @@ public class ClusterStateChanges extends AbstractComponent {
private final NodeJoinController.JoinTaskExecutor joinTaskExecutor;
public ClusterStateChanges(NamedXContentRegistry xContentRegistry, ThreadPool threadPool) {
super(Settings.builder().put(PATH_HOME_SETTING.getKey(), "dummy").build());
super(SETTINGS);
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
allocationService = new AllocationService(settings, new AllocationDeciders(settings,
new HashSet<>(Arrays.asList(new SameShardAllocationDecider(settings, clusterSettings),
new ReplicaAfterPrimaryActiveAllocationDecider(settings),
ClusterSettings clusterSettings = new ClusterSettings(SETTINGS, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
allocationService = new AllocationService(SETTINGS, new AllocationDeciders(SETTINGS,
new HashSet<>(Arrays.asList(new SameShardAllocationDecider(SETTINGS, clusterSettings),
new ReplicaAfterPrimaryActiveAllocationDecider(SETTINGS),
new RandomAllocationDeciderTests.RandomAllocationDecider(getRandom())))),
new TestGatewayAllocator(), new BalancedShardsAllocator(settings),
new TestGatewayAllocator(), new BalancedShardsAllocator(SETTINGS),
EmptyClusterInfoService.INSTANCE);
shardFailedClusterStateTaskExecutor = new ShardStateAction.ShardFailedClusterStateTaskExecutor(allocationService, null, logger);
shardStartedClusterStateTaskExecutor = new ShardStateAction.ShardStartedClusterStateTaskExecutor(allocationService, logger);
ActionFilters actionFilters = new ActionFilters(Collections.emptySet());
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(settings);
DestructiveOperations destructiveOperations = new DestructiveOperations(settings, clusterSettings);
Environment environment = TestEnvironment.newEnvironment(settings);
IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(SETTINGS);
DestructiveOperations destructiveOperations = new DestructiveOperations(SETTINGS, clusterSettings);
Environment environment = TestEnvironment.newEnvironment(SETTINGS);
Transport transport = mock(Transport.class); // it's not used
// mocks
@ -165,11 +168,11 @@ public class ClusterStateChanges extends AbstractComponent {
}
// services
TransportService transportService = new TransportService(settings, transport, threadPool,
TransportService transportService = new TransportService(SETTINGS, transport, threadPool,
TransportService.NOOP_TRANSPORT_INTERCEPTOR,
boundAddress -> DiscoveryNode.createLocal(settings, boundAddress.publishAddress(), UUIDs.randomBase64UUID()), clusterSettings,
boundAddress -> DiscoveryNode.createLocal(SETTINGS, boundAddress.publishAddress(), UUIDs.randomBase64UUID()), clusterSettings,
Collections.emptySet());
MetaDataIndexUpgradeService metaDataIndexUpgradeService = new MetaDataIndexUpgradeService(settings, xContentRegistry, null, null,
MetaDataIndexUpgradeService metaDataIndexUpgradeService = new MetaDataIndexUpgradeService(SETTINGS, xContentRegistry, null, null,
null) {
// metaData upgrader should do nothing
@Override
@ -177,29 +180,29 @@ public class ClusterStateChanges extends AbstractComponent {
return indexMetaData;
}
};
MetaDataIndexStateService indexStateService = new MetaDataIndexStateService(settings, clusterService, allocationService,
MetaDataIndexStateService indexStateService = new MetaDataIndexStateService(SETTINGS, clusterService, allocationService,
metaDataIndexUpgradeService, indicesService, threadPool);
MetaDataDeleteIndexService deleteIndexService = new MetaDataDeleteIndexService(settings, clusterService, allocationService);
MetaDataUpdateSettingsService metaDataUpdateSettingsService = new MetaDataUpdateSettingsService(settings, clusterService,
MetaDataDeleteIndexService deleteIndexService = new MetaDataDeleteIndexService(SETTINGS, clusterService, allocationService);
MetaDataUpdateSettingsService metaDataUpdateSettingsService = new MetaDataUpdateSettingsService(SETTINGS, clusterService,
allocationService, IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, indicesService, threadPool);
MetaDataCreateIndexService createIndexService = new MetaDataCreateIndexService(settings, clusterService, indicesService,
allocationService, new AliasValidator(settings), environment,
MetaDataCreateIndexService createIndexService = new MetaDataCreateIndexService(SETTINGS, clusterService, indicesService,
allocationService, new AliasValidator(SETTINGS), environment,
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS, threadPool, xContentRegistry, true);
transportCloseIndexAction = new TransportCloseIndexAction(settings, transportService, clusterService, threadPool,
transportCloseIndexAction = new TransportCloseIndexAction(SETTINGS, transportService, clusterService, threadPool,
indexStateService, clusterSettings, actionFilters, indexNameExpressionResolver, destructiveOperations);
transportOpenIndexAction = new TransportOpenIndexAction(settings, transportService,
transportOpenIndexAction = new TransportOpenIndexAction(SETTINGS, transportService,
clusterService, threadPool, indexStateService, actionFilters, indexNameExpressionResolver, destructiveOperations);
transportDeleteIndexAction = new TransportDeleteIndexAction(settings, transportService,
transportDeleteIndexAction = new TransportDeleteIndexAction(SETTINGS, transportService,
clusterService, threadPool, deleteIndexService, actionFilters, indexNameExpressionResolver, destructiveOperations);
transportUpdateSettingsAction = new TransportUpdateSettingsAction(settings,
transportUpdateSettingsAction = new TransportUpdateSettingsAction(SETTINGS,
transportService, clusterService, threadPool, metaDataUpdateSettingsService, actionFilters, indexNameExpressionResolver);
transportClusterRerouteAction = new TransportClusterRerouteAction(settings,
transportClusterRerouteAction = new TransportClusterRerouteAction(SETTINGS,
transportService, clusterService, threadPool, allocationService, actionFilters, indexNameExpressionResolver);
transportCreateIndexAction = new TransportCreateIndexAction(settings,
transportCreateIndexAction = new TransportCreateIndexAction(SETTINGS,
transportService, clusterService, threadPool, createIndexService, actionFilters, indexNameExpressionResolver);
ElectMasterService electMasterService = new ElectMasterService(settings);
ElectMasterService electMasterService = new ElectMasterService(SETTINGS);
nodeRemovalExecutor = new ZenDiscovery.NodeRemovalClusterStateTaskExecutor(allocationService, electMasterService,
s -> { throw new AssertionError("rejoin not implemented"); }, logger);
joinTaskExecutor = new NodeJoinController.JoinTaskExecutor(allocationService, electMasterService, logger);

View File

@ -131,8 +131,11 @@ public class ClusterServiceUtils {
}
public static ClusterService createClusterService(ThreadPool threadPool, DiscoveryNode localNode, ClusterSettings clusterSettings) {
ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").build(),
clusterSettings, threadPool);
Settings settings = Settings.builder()
.put("node.name", "test")
.put("cluster.name", "ClusterServiceTests")
.build();
ClusterService clusterService = new ClusterService(settings, clusterSettings, threadPool);
clusterService.setNodeConnectionsService(new NodeConnectionsService(Settings.EMPTY, null, null) {
@Override
public void connectToNodes(DiscoveryNodes discoveryNodes) {

View File

@ -79,6 +79,8 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
public static final long BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS =
XPackInfoResponse.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS;
private final Settings settings;
private final ClusterService clusterService;
/**
@ -118,6 +120,7 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
public LicenseService(Settings settings, ClusterService clusterService, Clock clock, Environment env,
ResourceWatcherService resourceWatcherService, XPackLicenseState licenseState) {
super(settings);
this.settings = settings;
this.clusterService = clusterService;
this.clock = clock;
this.scheduler = new SchedulerEngine(settings, clock);

View File

@ -60,6 +60,8 @@ import java.util.stream.Collectors;
*/
public class SSLService extends AbstractComponent {
private final Settings settings;
/**
* This is a mapping from "context name" (in general use, the name of a setting key)
* to a configuration.
@ -87,6 +89,7 @@ public class SSLService extends AbstractComponent {
*/
public SSLService(Settings settings, Environment environment) {
super(settings);
this.settings = settings;
this.env = environment;
this.globalSSLConfiguration = new SSLConfiguration(settings.getByPrefix(XPackSettings.GLOBAL_SSL_PREFIX));
this.sslConfigurations = new HashMap<>();
@ -96,6 +99,7 @@ public class SSLService extends AbstractComponent {
private SSLService(Settings settings, Environment environment, SSLConfiguration globalSSLConfiguration,
Map<String, SSLConfiguration> sslConfigurations, Map<SSLConfiguration, SSLContextHolder> sslContexts) {
super(settings);
this.settings = settings;
this.env = environment;
this.globalSSLConfiguration = globalSSLConfiguration;
this.sslConfigurations = sslConfigurations;

View File

@ -83,6 +83,7 @@ public class JobManager extends AbstractComponent {
private static final DeprecationLogger deprecationLogger =
new DeprecationLogger(LogManager.getLogger(JobManager.class));
private final Settings settings;
private final Environment environment;
private final JobResultsProvider jobResultsProvider;
private final ClusterService clusterService;
@ -99,6 +100,7 @@ public class JobManager extends AbstractComponent {
ClusterService clusterService, Auditor auditor,
Client client, UpdateJobProcessNotifier updateJobProcessNotifier) {
super(settings);
this.settings = settings;
this.environment = environment;
this.jobResultsProvider = Objects.requireNonNull(jobResultsProvider);
this.clusterService = Objects.requireNonNull(clusterService);

View File

@ -108,6 +108,7 @@ public class AutodetectProcessManager extends AbstractComponent {
public static final Setting<ByteSizeValue> MIN_DISK_SPACE_OFF_HEAP =
Setting.byteSizeSetting("xpack.ml.min_disk_space_off_heap", new ByteSizeValue(5, ByteSizeUnit.GB), Property.NodeScope);
private final Settings settings;
private final Client client;
private final Environment environment;
private final ThreadPool threadPool;
@ -137,6 +138,7 @@ public class AutodetectProcessManager extends AbstractComponent {
AutodetectProcessFactory autodetectProcessFactory, NormalizerFactory normalizerFactory,
NamedXContentRegistry xContentRegistry, Auditor auditor) {
super(settings);
this.settings = settings;
this.environment = environment;
this.client = client;
this.threadPool = threadPool;

View File

@ -36,6 +36,7 @@ public final class StatsCollector extends Collector {
public static final Setting<TimeValue> CCR_STATS_TIMEOUT = collectionTimeoutSetting("ccr.stats.timeout");
private final Settings settings;
private final ThreadContext threadContext;
private final CcrClient ccrClient;
@ -48,12 +49,13 @@ public final class StatsCollector extends Collector {
}
StatsCollector(
final Settings settings,
final ClusterService clusterService,
final XPackLicenseState licenseState,
final CcrClient ccrClient,
final ThreadContext threadContext) {
final Settings settings,
final ClusterService clusterService,
final XPackLicenseState licenseState,
final CcrClient ccrClient,
final ThreadContext threadContext) {
super(settings, TYPE, clusterService, CCR_STATS_TIMEOUT, licenseState);
this.settings = settings;
this.ccrClient = ccrClient;
this.threadContext = threadContext;
}

View File

@ -55,6 +55,7 @@ public class ClusterStatsCollector extends Collector {
*/
public static final Setting<TimeValue> CLUSTER_STATS_TIMEOUT = collectionTimeoutSetting("cluster.stats.timeout");
private final Settings settings;
private final IndexNameExpressionResolver indexNameExpressionResolver;
private final LicenseService licenseService;
private final Client client;
@ -74,7 +75,7 @@ public class ClusterStatsCollector extends Collector {
final LicenseService licenseService,
final IndexNameExpressionResolver indexNameExpressionResolver) {
super(settings, ClusterStatsMonitoringDoc.TYPE, clusterService, CLUSTER_STATS_TIMEOUT, licenseState);
this.settings = settings;
this.client = client;
this.licenseService = licenseService;
this.indexNameExpressionResolver = Objects.requireNonNull(indexNameExpressionResolver);

View File

@ -42,6 +42,7 @@ public class JobStatsCollector extends Collector {
*/
public static final Setting<TimeValue> JOB_STATS_TIMEOUT = collectionTimeoutSetting("ml.job.stats.timeout");
private final Settings settings;
private final ThreadContext threadContext;
private final MachineLearningClient client;
@ -53,6 +54,7 @@ public class JobStatsCollector extends Collector {
JobStatsCollector(final Settings settings, final ClusterService clusterService,
final XPackLicenseState licenseState, final MachineLearningClient client, final ThreadContext threadContext) {
super(settings, JobStatsMonitoringDoc.TYPE, clusterService, JOB_STATS_TIMEOUT, licenseState);
this.settings = settings;
this.client = client;
this.threadContext = threadContext;
}

View File

@ -37,6 +37,7 @@ import static java.util.Collections.emptyMap;
public class Exporters extends AbstractLifecycleComponent implements Iterable<Exporter> {
private final Settings settings;
private final Map<String, Exporter.Factory> factories;
private final AtomicReference<Map<String, Exporter>> exporters;
private final ClusterService clusterService;
@ -47,7 +48,7 @@ public class Exporters extends AbstractLifecycleComponent implements Iterable<Ex
ClusterService clusterService, XPackLicenseState licenseState,
ThreadContext threadContext) {
super(settings);
this.settings = settings;
this.factories = factories;
this.exporters = new AtomicReference<>(emptyMap());
this.threadContext = Objects.requireNonNull(threadContext);

View File

@ -24,12 +24,14 @@ import org.elasticsearch.xpack.security.authc.esnative.NativeUsersStore;
public class TransportChangePasswordAction extends HandledTransportAction<ChangePasswordRequest, ChangePasswordResponse> {
private final Settings settings;
private final NativeUsersStore nativeUsersStore;
@Inject
public TransportChangePasswordAction(Settings settings, TransportService transportService,
ActionFilters actionFilters, NativeUsersStore nativeUsersStore) {
super(settings, ChangePasswordAction.NAME, transportService, actionFilters, ChangePasswordRequest::new);
this.settings = settings;
this.nativeUsersStore = nativeUsersStore;
}

View File

@ -25,6 +25,7 @@ import java.util.function.Supplier;
public class TransportDeleteUserAction extends HandledTransportAction<DeleteUserRequest, DeleteUserResponse> {
private final Settings settings;
private final NativeUsersStore usersStore;
@Inject
@ -32,6 +33,7 @@ public class TransportDeleteUserAction extends HandledTransportAction<DeleteUser
NativeUsersStore usersStore, TransportService transportService) {
super(settings, DeleteUserAction.NAME, transportService, actionFilters,
(Supplier<DeleteUserRequest>) DeleteUserRequest::new);
this.settings = settings;
this.usersStore = usersStore;
}

View File

@ -32,6 +32,7 @@ import java.util.stream.Collectors;
public class TransportGetUsersAction extends HandledTransportAction<GetUsersRequest, GetUsersResponse> {
private final Settings settings;
private final NativeUsersStore usersStore;
private final ReservedRealm reservedRealm;
@ -39,6 +40,7 @@ public class TransportGetUsersAction extends HandledTransportAction<GetUsersRequ
public TransportGetUsersAction(Settings settings, ActionFilters actionFilters,
NativeUsersStore usersStore, TransportService transportService, ReservedRealm reservedRealm) {
super(settings, GetUsersAction.NAME, transportService, actionFilters, GetUsersRequest::new);
this.settings = settings;
this.usersStore = usersStore;
this.reservedRealm = reservedRealm;
}

View File

@ -30,12 +30,14 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
public class TransportPutUserAction extends HandledTransportAction<PutUserRequest, PutUserResponse> {
private final Settings settings;
private final NativeUsersStore usersStore;
@Inject
public TransportPutUserAction(Settings settings, ActionFilters actionFilters,
NativeUsersStore usersStore, TransportService transportService) {
super(settings, PutUserAction.NAME, transportService, actionFilters, PutUserRequest::new);
this.settings = settings;
this.usersStore = usersStore;
}

View File

@ -27,6 +27,7 @@ import org.elasticsearch.xpack.security.authc.esnative.NativeUsersStore;
*/
public class TransportSetEnabledAction extends HandledTransportAction<SetEnabledRequest, SetEnabledResponse> {
private final Settings settings;
private final ThreadPool threadPool;
private final NativeUsersStore usersStore;
@ -34,6 +35,7 @@ public class TransportSetEnabledAction extends HandledTransportAction<SetEnabled
public TransportSetEnabledAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ActionFilters actionFilters, NativeUsersStore usersStore) {
super(settings, SetEnabledAction.NAME, transportService, actionFilters, SetEnabledRequest::new);
this.settings = settings;
this.threadPool = threadPool;
this.usersStore = usersStore;
}

View File

@ -165,6 +165,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
TimeValue.timeValueMillis(1L), Property.NodeScope);
private final AtomicReference<State> state = new AtomicReference<>(State.INITIALIZED);
private final Settings settings;
private final String nodeName;
private final Client client;
private final QueueConsumer queueConsumer;
@ -186,6 +187,7 @@ public class IndexAuditTrail extends AbstractComponent implements AuditTrail, Cl
public IndexAuditTrail(Settings settings, Client client, ThreadPool threadPool, ClusterService clusterService) {
super(settings);
this.settings = settings;
this.threadPool = threadPool;
this.clusterService = clusterService;
this.nodeName = Node.NODE_NAME_SETTING.get(settings);

View File

@ -43,6 +43,7 @@ import org.elasticsearch.xpack.core.security.authc.kerberos.KerberosRealmSetting
*/
public class Realms extends AbstractComponent implements Iterable<Realm> {
private final Settings settings;
private final Environment env;
private final Map<String, Realm.Factory> factories;
private final XPackLicenseState licenseState;
@ -59,6 +60,7 @@ public class Realms extends AbstractComponent implements Iterable<Realm> {
public Realms(Settings settings, Environment env, Map<String, Realm.Factory> factories, XPackLicenseState licenseState,
ThreadContext threadContext, ReservedRealm reservedRealm) throws Exception {
super(settings);
this.settings = settings;
this.env = env;
this.factories = factories;
this.licenseState = licenseState;

View File

@ -162,6 +162,7 @@ public final class TokenService extends AbstractComponent {
private static final int MAX_RETRY_ATTEMPTS = 5;
private final SecureRandom secureRandom = new SecureRandom();
private final Settings settings;
private final ClusterService clusterService;
private final Clock clock;
private final TimeValue expirationDelay;
@ -188,6 +189,7 @@ public final class TokenService extends AbstractComponent {
secureRandom.nextBytes(saltArr);
final SecureString tokenPassphrase = generateTokenKey();
this.settings = settings;
this.clock = clock.withZone(ZoneOffset.UTC);
this.expirationDelay = TOKEN_EXPIRATION.get(settings);
this.client = client;

View File

@ -79,6 +79,8 @@ public class NativeUsersStore extends AbstractComponent {
public static final String INDEX_TYPE = "doc";
static final String USER_DOC_TYPE = "user";
public static final String RESERVED_USER_TYPE = "reserved-user";
private final Settings settings;
private final Client client;
private final ReservedUserInfo disabledDefaultUserInfo;
private final ReservedUserInfo enabledDefaultUserInfo;
@ -87,6 +89,7 @@ public class NativeUsersStore extends AbstractComponent {
public NativeUsersStore(Settings settings, Client client, SecurityIndexManager securityIndex) {
super(settings);
this.settings = settings;
this.client = client;
this.securityIndex = securityIndex;
final char[] emptyPasswordHash = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings)).

View File

@ -95,12 +95,14 @@ public class NativeRoleMappingStore extends AbstractComponent implements UserRol
}
};
private final Settings settings;
private final Client client;
private final SecurityIndexManager securityIndex;
private final List<String> realmsToRefresh = new CopyOnWriteArrayList<>();
public NativeRoleMappingStore(Settings settings, Client client, SecurityIndexManager securityIndex) {
super(settings);
this.settings = settings;
this.client = client;
this.securityIndex = securityIndex;
}

View File

@ -57,6 +57,7 @@ public class FileRolesStore extends AbstractComponent implements BiConsumer<Set<
private static final Pattern IN_SEGMENT_LINE = Pattern.compile("^\\s+.+");
private static final Pattern SKIP_LINE = Pattern.compile("(^#.*|^\\s*)");
private final Settings settings;
private final Path file;
private final XPackLicenseState licenseState;
private final List<Consumer<Set<String>>> listeners = new ArrayList<>();
@ -71,6 +72,7 @@ public class FileRolesStore extends AbstractComponent implements BiConsumer<Set<
FileRolesStore(Settings settings, Environment env, ResourceWatcherService watcherService, Consumer<Set<String>> listener,
XPackLicenseState licenseState) throws IOException {
super(settings);
this.settings = settings;
this.file = resolveFile(env);
if (listener != null) {
listeners.add(listener);

View File

@ -75,12 +75,14 @@ public class NativePrivilegeStore extends AbstractComponent {
return a;
});
private final Settings settings;
private final Client client;
private final SecurityClient securityClient;
private final SecurityIndexManager securityIndexManager;
public NativePrivilegeStore(Settings settings, Client client, SecurityIndexManager securityIndexManager) {
super(settings);
this.settings = settings;
this.client = client;
this.securityClient = new SecurityClient(client);
this.securityIndexManager = securityIndexManager;

View File

@ -89,6 +89,7 @@ public class NativeRolesStore extends AbstractComponent implements BiConsumer<Se
TimeValue.timeValueMinutes(20), Property.NodeScope, Property.Deprecated);
private static final String ROLE_DOC_TYPE = "doc";
private final Settings settings;
private final Client client;
private final XPackLicenseState licenseState;
@ -97,6 +98,7 @@ public class NativeRolesStore extends AbstractComponent implements BiConsumer<Se
public NativeRolesStore(Settings settings, Client client, XPackLicenseState licenseState, SecurityIndexManager securityIndex) {
super(settings);
this.settings = settings;
this.client = client;
this.securityClient = new SecurityClient(client);
this.licenseState = licenseState;

View File

@ -24,6 +24,7 @@ import java.io.IOException;
*/
public abstract class SecurityBaseRestHandler extends BaseRestHandler {
private final Settings settings;
protected final XPackLicenseState licenseState;
/**
@ -32,6 +33,7 @@ public abstract class SecurityBaseRestHandler extends BaseRestHandler {
*/
protected SecurityBaseRestHandler(Settings settings, XPackLicenseState licenseState) {
super(settings);
this.settings = settings;
this.licenseState = licenseState;
}

View File

@ -34,12 +34,13 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
public class RestChangePasswordAction extends SecurityBaseRestHandler implements RestRequestFilter {
private final SecurityContext securityContext;
private final Hasher passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings));
private final Hasher passwordHasher;
public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext,
XPackLicenseState licenseState) {
super(settings, licenseState);
this.securityContext = securityContext;
passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings));
controller.registerHandler(POST, "/_xpack/security/user/{username}/_password", this);
controller.registerHandler(PUT, "/_xpack/security/user/{username}/_password", this);
controller.registerHandler(POST, "/_xpack/security/user/_password", this);

View File

@ -36,10 +36,11 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT;
*/
public class RestPutUserAction extends SecurityBaseRestHandler implements RestRequestFilter {
private final Hasher passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings));
private final Hasher passwordHasher;
public RestPutUserAction(Settings settings, RestController controller, XPackLicenseState licenseState) {
super(settings, licenseState);
passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings));
controller.registerHandler(POST, "/_xpack/security/user/{username}", this);
controller.registerHandler(PUT, "/_xpack/security/user/{username}", this);
}

View File

@ -79,7 +79,7 @@ public class HttpClient extends AbstractComponent implements Closeable {
this.defaultConnectionTimeout = HttpSettings.CONNECTION_TIMEOUT.get(settings);
this.defaultReadTimeout = HttpSettings.READ_TIMEOUT.get(settings);
this.maxResponseSize = HttpSettings.MAX_HTTP_RESPONSE_SIZE.get(settings);
this.settingsProxy = getProxyFromSettings();
this.settingsProxy = getProxyFromSettings(settings);
this.cryptoService = cryptoService;
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
@ -228,7 +228,7 @@ public class HttpClient extends AbstractComponent implements Closeable {
*
* @return An HTTP proxy instance, if no settings are configured this will be an HttpProxy.NO_PROXY instance
*/
private HttpProxy getProxyFromSettings() {
private HttpProxy getProxyFromSettings(Settings settings) {
String proxyHost = HttpSettings.PROXY_HOST.get(settings);
Scheme proxyScheme = HttpSettings.PROXY_SCHEME.exists(settings) ?
Scheme.parse(HttpSettings.PROXY_SCHEME.get(settings)) : Scheme.HTTP;