use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class RoutingBackwardCompatibilityTests method testBackwardCompatibility.
public void testBackwardCompatibility() throws Exception {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(RoutingBackwardCompatibilityTests.class.getResourceAsStream("/org/elasticsearch/cluster/routing/shard_routes.txt"), "UTF-8"))) {
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
if (line.startsWith("#")) {
// comment
continue;
}
String[] parts = line.split("\t");
assertEquals(Arrays.toString(parts), 7, parts.length);
final String index = parts[0];
final int numberOfShards = Integer.parseInt(parts[1]);
final String type = parts[2];
final String id = parts[3];
final String routing = "null".equals(parts[4]) ? null : parts[4];
// not needed anymore - old hashing is gone
final int pre20ExpectedShardId = Integer.parseInt(parts[5]);
final int currentExpectedShard = Integer.parseInt(parts[6]);
OperationRouting operationRouting = new OperationRouting(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
for (Version version : VersionUtils.allReleasedVersions()) {
if (version.onOrAfter(Version.V_2_0_0) == false) {
// unsupported version, no need to test
continue;
}
final Settings settings = settings(version).build();
IndexMetaData indexMetaData = IndexMetaData.builder(index).settings(settings).numberOfShards(numberOfShards).numberOfReplicas(randomInt(3)).build();
MetaData.Builder metaData = MetaData.builder().put(indexMetaData, false);
RoutingTable routingTable = RoutingTable.builder().addAsNew(indexMetaData).build();
ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
final int shardId = operationRouting.indexShards(clusterState, index, id, routing).shardId().getId();
assertEquals(currentExpectedShard, shardId);
}
}
}
}
use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class CircuitBreakerUnitTests method testRegisterCustomBreaker.
public void testRegisterCustomBreaker() throws Exception {
CircuitBreakerService service = new HierarchyCircuitBreakerService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
String customName = "custom";
BreakerSettings settings = new BreakerSettings(customName, 20, 1.0);
service.registerBreaker(settings);
CircuitBreaker breaker = service.getBreaker(customName);
assertThat(breaker, notNullValue());
assertThat(breaker, instanceOf(CircuitBreaker.class));
assertThat(breaker.getName(), is(customName));
}
use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class RestControllerTests method setup.
@Before
public void setup() {
Settings settings = Settings.EMPTY;
circuitBreakerService = new HierarchyCircuitBreakerService(Settings.builder().put(HierarchyCircuitBreakerService.IN_FLIGHT_REQUESTS_CIRCUIT_BREAKER_LIMIT_SETTING.getKey(), BREAKER_LIMIT).build(), new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
// we can do this here only because we know that we don't adjust breaker settings dynamically in the test
inFlightRequestsBreaker = circuitBreakerService.getBreaker(CircuitBreaker.IN_FLIGHT_REQUESTS);
HttpServerTransport httpServerTransport = new TestHttpServerTransport();
restController = new RestController(settings, Collections.emptySet(), null, null, circuitBreakerService);
restController.registerHandler(RestRequest.Method.GET, "/", (request, channel, client) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)));
restController.registerHandler(RestRequest.Method.GET, "/error", (request, channel, client) -> {
throw new IllegalArgumentException("test error");
});
httpServerTransport.start();
}
use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class ActionModule method initRestHandlers.
public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
List<AbstractCatAction> catActions = new ArrayList<>();
Consumer<RestHandler> registerHandler = a -> {
if (a instanceof AbstractCatAction) {
catActions.add((AbstractCatAction) a);
}
};
registerHandler.accept(new RestMainAction(settings, restController));
registerHandler.accept(new RestNodesInfoAction(settings, restController, settingsFilter));
registerHandler.accept(new RestNodesStatsAction(settings, restController));
registerHandler.accept(new RestNodesHotThreadsAction(settings, restController));
registerHandler.accept(new RestClusterAllocationExplainAction(settings, restController));
registerHandler.accept(new RestClusterStatsAction(settings, restController));
registerHandler.accept(new RestClusterStateAction(settings, restController, settingsFilter));
registerHandler.accept(new RestClusterHealthAction(settings, restController));
registerHandler.accept(new RestClusterUpdateSettingsAction(settings, restController));
registerHandler.accept(new RestClusterGetSettingsAction(settings, restController, clusterSettings, settingsFilter));
registerHandler.accept(new RestClusterRerouteAction(settings, restController, settingsFilter));
registerHandler.accept(new RestClusterSearchShardsAction(settings, restController));
registerHandler.accept(new RestPendingClusterTasksAction(settings, restController));
registerHandler.accept(new RestPutRepositoryAction(settings, restController));
registerHandler.accept(new RestGetRepositoriesAction(settings, restController, settingsFilter));
registerHandler.accept(new RestDeleteRepositoryAction(settings, restController));
registerHandler.accept(new RestVerifyRepositoryAction(settings, restController));
registerHandler.accept(new RestGetSnapshotsAction(settings, restController));
registerHandler.accept(new RestCreateSnapshotAction(settings, restController));
registerHandler.accept(new RestRestoreSnapshotAction(settings, restController));
registerHandler.accept(new RestDeleteSnapshotAction(settings, restController));
registerHandler.accept(new RestSnapshotsStatusAction(settings, restController));
registerHandler.accept(new RestTypesExistsAction(settings, restController));
registerHandler.accept(new RestGetIndicesAction(settings, restController, indexScopedSettings, settingsFilter));
registerHandler.accept(new RestIndicesStatsAction(settings, restController));
registerHandler.accept(new RestIndicesSegmentsAction(settings, restController));
registerHandler.accept(new RestIndicesShardStoresAction(settings, restController));
registerHandler.accept(new RestGetAliasesAction(settings, restController));
registerHandler.accept(new RestIndexDeleteAliasesAction(settings, restController));
registerHandler.accept(new RestIndexPutAliasAction(settings, restController));
registerHandler.accept(new RestIndicesAliasesAction(settings, restController));
registerHandler.accept(new RestCreateIndexAction(settings, restController));
registerHandler.accept(new RestShrinkIndexAction(settings, restController));
registerHandler.accept(new RestRolloverIndexAction(settings, restController));
registerHandler.accept(new RestDeleteIndexAction(settings, restController));
registerHandler.accept(new RestCloseIndexAction(settings, restController));
registerHandler.accept(new RestOpenIndexAction(settings, restController));
registerHandler.accept(new RestUpdateSettingsAction(settings, restController));
registerHandler.accept(new RestGetSettingsAction(settings, restController, indexScopedSettings, settingsFilter));
registerHandler.accept(new RestAnalyzeAction(settings, restController));
registerHandler.accept(new RestGetIndexTemplateAction(settings, restController));
registerHandler.accept(new RestPutIndexTemplateAction(settings, restController));
registerHandler.accept(new RestDeleteIndexTemplateAction(settings, restController));
registerHandler.accept(new RestPutMappingAction(settings, restController));
registerHandler.accept(new RestGetMappingAction(settings, restController));
registerHandler.accept(new RestGetFieldMappingAction(settings, restController));
registerHandler.accept(new RestRefreshAction(settings, restController));
registerHandler.accept(new RestFlushAction(settings, restController));
registerHandler.accept(new RestSyncedFlushAction(settings, restController));
registerHandler.accept(new RestForceMergeAction(settings, restController));
registerHandler.accept(new RestUpgradeAction(settings, restController));
registerHandler.accept(new RestClearIndicesCacheAction(settings, restController));
registerHandler.accept(new RestIndexAction(settings, restController));
registerHandler.accept(new RestGetAction(settings, restController));
registerHandler.accept(new RestGetSourceAction(settings, restController));
registerHandler.accept(new RestMultiGetAction(settings, restController));
registerHandler.accept(new RestDeleteAction(settings, restController));
registerHandler.accept(new org.elasticsearch.rest.action.document.RestCountAction(settings, restController));
registerHandler.accept(new RestTermVectorsAction(settings, restController));
registerHandler.accept(new RestMultiTermVectorsAction(settings, restController));
registerHandler.accept(new RestBulkAction(settings, restController));
registerHandler.accept(new RestUpdateAction(settings, restController));
registerHandler.accept(new RestSearchAction(settings, restController));
registerHandler.accept(new RestSearchScrollAction(settings, restController));
registerHandler.accept(new RestClearScrollAction(settings, restController));
registerHandler.accept(new RestMultiSearchAction(settings, restController));
registerHandler.accept(new RestValidateQueryAction(settings, restController));
registerHandler.accept(new RestExplainAction(settings, restController));
registerHandler.accept(new RestRecoveryAction(settings, restController));
// Scripts API
registerHandler.accept(new RestGetStoredScriptAction(settings, restController));
registerHandler.accept(new RestPutStoredScriptAction(settings, restController));
registerHandler.accept(new RestDeleteStoredScriptAction(settings, restController));
registerHandler.accept(new RestFieldStatsAction(settings, restController));
// Tasks API
registerHandler.accept(new RestListTasksAction(settings, restController, nodesInCluster));
registerHandler.accept(new RestGetTaskAction(settings, restController));
registerHandler.accept(new RestCancelTasksAction(settings, restController, nodesInCluster));
// Ingest API
registerHandler.accept(new RestPutPipelineAction(settings, restController));
registerHandler.accept(new RestGetPipelineAction(settings, restController));
registerHandler.accept(new RestDeletePipelineAction(settings, restController));
registerHandler.accept(new RestSimulatePipelineAction(settings, restController));
// CAT API
registerHandler.accept(new RestAllocationAction(settings, restController));
registerHandler.accept(new RestShardsAction(settings, restController));
registerHandler.accept(new RestMasterAction(settings, restController));
registerHandler.accept(new RestNodesAction(settings, restController));
registerHandler.accept(new RestTasksAction(settings, restController, nodesInCluster));
registerHandler.accept(new RestIndicesAction(settings, restController, indexNameExpressionResolver));
registerHandler.accept(new RestSegmentsAction(settings, restController));
// Fully qualified to prevent interference with rest.action.count.RestCountAction
registerHandler.accept(new org.elasticsearch.rest.action.cat.RestCountAction(settings, restController));
// Fully qualified to prevent interference with rest.action.indices.RestRecoveryAction
registerHandler.accept(new org.elasticsearch.rest.action.cat.RestRecoveryAction(settings, restController));
registerHandler.accept(new RestHealthAction(settings, restController));
registerHandler.accept(new org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction(settings, restController));
registerHandler.accept(new RestAliasAction(settings, restController));
registerHandler.accept(new RestThreadPoolAction(settings, restController));
registerHandler.accept(new RestPluginsAction(settings, restController));
registerHandler.accept(new RestFielddataAction(settings, restController));
registerHandler.accept(new RestNodeAttrsAction(settings, restController));
registerHandler.accept(new RestRepositoriesAction(settings, restController));
registerHandler.accept(new RestSnapshotAction(settings, restController));
registerHandler.accept(new RestTemplatesAction(settings, restController));
for (ActionPlugin plugin : actionPlugins) {
for (RestHandler handler : plugin.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)) {
registerHandler.accept(handler);
}
}
registerHandler.accept(new RestCatAction(settings, restController, catActions));
}
use of org.elasticsearch.common.settings.ClusterSettings in project elasticsearch by elastic.
the class ClusterModule method createAllocationDeciders.
// TODO: this is public so allocation benchmark can access the default deciders...can we do that in another way?
/** Return a new {@link AllocationDecider} instance with builtin deciders as well as those from plugins. */
public static Collection<AllocationDecider> createAllocationDeciders(Settings settings, ClusterSettings clusterSettings, List<ClusterPlugin> clusterPlugins) {
// collect deciders by class so that we can detect duplicates
Map<Class, AllocationDecider> deciders = new LinkedHashMap<>();
addAllocationDecider(deciders, new MaxRetryAllocationDecider(settings));
addAllocationDecider(deciders, new ReplicaAfterPrimaryActiveAllocationDecider(settings));
addAllocationDecider(deciders, new RebalanceOnlyWhenActiveAllocationDecider(settings));
addAllocationDecider(deciders, new ClusterRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ConcurrentRebalanceAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new EnableAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new NodeVersionAllocationDecider(settings));
addAllocationDecider(deciders, new SnapshotInProgressAllocationDecider(settings));
addAllocationDecider(deciders, new FilterAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new SameShardAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new DiskThresholdDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ThrottlingAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new ShardsLimitAllocationDecider(settings, clusterSettings));
addAllocationDecider(deciders, new AwarenessAllocationDecider(settings, clusterSettings));
clusterPlugins.stream().flatMap(p -> p.createAllocationDeciders(settings, clusterSettings).stream()).forEach(d -> addAllocationDecider(deciders, d));
return deciders.values();
}
Aggregations