Search in sources :

Example 11 with Setting

use of org.elasticsearch.common.settings.Setting in project elasticsearch by elastic.

the class DeprecationHttpIT method doTestDeprecationWarningsAppearInHeaders.

/**
     * Run a request that receives a predictably randomized number of deprecation warnings.
     * <p>
     * Re-running this back-to-back helps to ensure that warnings are not being maintained across requests.
     */
private void doTestDeprecationWarningsAppearInHeaders() throws IOException {
    final boolean useDeprecatedField = randomBoolean();
    final boolean useNonDeprecatedSetting = randomBoolean();
    // deprecated settings should also trigger a deprecation warning
    final List<Setting<Boolean>> settings = new ArrayList<>(3);
    settings.add(TEST_DEPRECATED_SETTING_TRUE1);
    if (randomBoolean()) {
        settings.add(TEST_DEPRECATED_SETTING_TRUE2);
    }
    if (useNonDeprecatedSetting) {
        settings.add(TEST_NOT_DEPRECATED_SETTING);
    }
    Collections.shuffle(settings, random());
    // trigger all deprecations
    Response response = getRestClient().performRequest("GET", "/_test_cluster/deprecated_settings", Collections.emptyMap(), buildSettingsRequest(settings, useDeprecatedField));
    assertThat(response.getStatusLine().getStatusCode(), equalTo(OK.getStatus()));
    final List<String> deprecatedWarnings = getWarningHeaders(response.getHeaders());
    final List<Matcher<String>> headerMatchers = new ArrayList<>(4);
    headerMatchers.add(equalTo(TestDeprecationHeaderRestAction.DEPRECATED_ENDPOINT));
    if (useDeprecatedField) {
        headerMatchers.add(equalTo(TestDeprecationHeaderRestAction.DEPRECATED_USAGE));
    }
    for (Setting<?> setting : settings) {
        if (setting.isDeprecated()) {
            headerMatchers.add(equalTo("[" + setting.getKey() + "] setting was deprecated in Elasticsearch and will be removed in a future release! " + "See the breaking changes documentation for the next major version."));
        }
    }
    assertThat(deprecatedWarnings, hasSize(headerMatchers.size()));
    for (final String deprecatedWarning : deprecatedWarnings) {
        assertThat(deprecatedWarning, matches(WARNING_HEADER_PATTERN.pattern()));
    }
    final List<String> actualWarningValues = deprecatedWarnings.stream().map(DeprecationLogger::extractWarningValueFromWarningHeader).collect(Collectors.toList());
    for (Matcher<String> headerMatcher : headerMatchers) {
        assertThat(actualWarningValues, hasItem(headerMatcher));
    }
}
Also used : Response(org.elasticsearch.client.Response) Matcher(org.hamcrest.Matcher) Setting(org.elasticsearch.common.settings.Setting) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 12 with Setting

use of org.elasticsearch.common.settings.Setting in project crate by crate.

the class AlterTableClusterStateExecutor method updateSettings.

/**
 * The logic is taken over from {@link MetadataUpdateSettingsService#updateSettings(UpdateSettingsClusterStateUpdateRequest, ActionListener)}
 */
private ClusterState updateSettings(final ClusterState currentState, final Settings settings, Index[] concreteIndices) {
    final Settings normalizedSettings = Settings.builder().put(markArchivedSettings(settings)).normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build();
    Settings.Builder settingsForClosedIndices = Settings.builder();
    Settings.Builder settingsForOpenIndices = Settings.builder();
    final Set<String> skippedSettings = new HashSet<>();
    for (String key : normalizedSettings.keySet()) {
        Setting setting = indexScopedSettings.get(key);
        boolean isWildcard = setting == null && Regex.isSimpleMatchPattern(key);
        assert // we already validated the normalized settings
        setting != null || (isWildcard && normalizedSettings.hasValue(key) == false) : "unknown setting: " + key + " isWildcard: " + isWildcard + " hasValue: " + normalizedSettings.hasValue(key);
        settingsForClosedIndices.copy(key, normalizedSettings);
        if (isWildcard || setting.isDynamic()) {
            settingsForOpenIndices.copy(key, normalizedSettings);
        } else {
            skippedSettings.add(key);
        }
    }
    final Settings closedSettings = settingsForClosedIndices.build();
    final Settings openSettings = settingsForOpenIndices.build();
    final RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
    final Metadata.Builder metadataBuilder = Metadata.builder(currentState.metadata());
    // allow to change any settings to a close index, and only allow dynamic settings to be changed
    // on an open index
    Set<Index> openIndices = new HashSet<>();
    Set<Index> closeIndices = new HashSet<>();
    final String[] actualIndices = new String[concreteIndices.length];
    for (int i = 0; i < concreteIndices.length; i++) {
        Index index = concreteIndices[i];
        actualIndices[i] = index.getName();
        final IndexMetadata metadata = currentState.metadata().getIndexSafe(index);
        if (metadata.getState() == IndexMetadata.State.OPEN) {
            openIndices.add(index);
        } else {
            closeIndices.add(index);
        }
    }
    if (!skippedSettings.isEmpty() && !openIndices.isEmpty()) {
        throw new IllegalArgumentException(String.format(Locale.ROOT, "Can't update non dynamic settings [%s] for open indices %s", skippedSettings, openIndices));
    }
    if (IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.exists(openSettings)) {
        final int updatedNumberOfReplicas = IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(openSettings);
        // Verify that this won't take us over the cluster shard limit.
        int totalNewShards = openIndices.stream().mapToInt(i -> MetadataUpdateSettingsService.getTotalNewShards(i, currentState, updatedNumberOfReplicas)).sum();
        Optional<String> error = shardLimitValidator.checkShardLimit(totalNewShards, currentState);
        if (error.isPresent()) {
            ValidationException ex = new ValidationException();
            ex.addValidationError(error.get());
            throw ex;
        }
        /*
             * We do not update the in-sync allocation IDs as they will be removed upon the first index operation which makes
             * these copies stale.
             *
             * TODO: should we update the in-sync allocation IDs once the data is deleted by the node?
             */
        routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
        metadataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
    }
    ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
    maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_ONLY_BLOCK, IndexMetadata.INDEX_READ_ONLY_SETTING, openSettings);
    maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK, IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING, openSettings);
    maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_METADATA_BLOCK, IndexMetadata.INDEX_BLOCKS_METADATA_SETTING, openSettings);
    maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_WRITE_BLOCK, IndexMetadata.INDEX_BLOCKS_WRITE_SETTING, openSettings);
    maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_BLOCK, IndexMetadata.INDEX_BLOCKS_READ_SETTING, openSettings);
    if (!openIndices.isEmpty()) {
        for (Index index : openIndices) {
            IndexMetadata indexMetadata = metadataBuilder.getSafe(index);
            Settings.Builder updates = Settings.builder();
            Settings.Builder indexSettings = Settings.builder().put(indexMetadata.getSettings());
            if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index.getName())) {
                Settings finalSettings = indexSettings.build();
                indexScopedSettings.validate(finalSettings.filter(k -> indexScopedSettings.isPrivateSetting(k) == false), true);
                metadataBuilder.put(IndexMetadata.builder(indexMetadata).settings(finalSettings));
            }
        }
    }
    if (!closeIndices.isEmpty()) {
        for (Index index : closeIndices) {
            IndexMetadata indexMetadata = metadataBuilder.getSafe(index);
            Settings.Builder updates = Settings.builder();
            Settings.Builder indexSettings = Settings.builder().put(indexMetadata.getSettings());
            if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index.getName())) {
                Settings finalSettings = indexSettings.build();
                indexScopedSettings.validate(finalSettings.filter(k -> indexScopedSettings.isPrivateSetting(k) == false), true);
                metadataBuilder.put(IndexMetadata.builder(indexMetadata).settings(finalSettings));
            }
        }
    }
    // increment settings versions
    for (final String index : actualIndices) {
        if (same(currentState.metadata().index(index).getSettings(), metadataBuilder.get(index).getSettings()) == false) {
            final IndexMetadata.Builder builder = IndexMetadata.builder(metadataBuilder.get(index));
            builder.settingsVersion(1 + builder.settingsVersion());
            metadataBuilder.put(builder);
        }
    }
    ClusterState updatedState = ClusterState.builder(currentState).metadata(metadataBuilder).routingTable(routingTableBuilder.build()).blocks(blocks).build();
    // now, reroute in case things change that require it (like number of replicas)
    updatedState = allocationService.reroute(updatedState, "settings update");
    try {
        for (Index index : openIndices) {
            final IndexMetadata currentMetadata = currentState.getMetadata().getIndexSafe(index);
            final IndexMetadata updatedMetadata = updatedState.metadata().getIndexSafe(index);
            indicesService.verifyIndexMetadata(currentMetadata, updatedMetadata);
        }
        for (Index index : closeIndices) {
            final IndexMetadata currentMetadata = currentState.getMetadata().getIndexSafe(index);
            final IndexMetadata updatedMetadata = updatedState.metadata().getIndexSafe(index);
            // Verifies that the current index settings can be updated with the updated dynamic settings.
            indicesService.verifyIndexMetadata(currentMetadata, updatedMetadata);
            // Now check that we can create the index with the updated settings (dynamic and non-dynamic).
            // This step is mandatory since we allow to update non-dynamic settings on closed indices.
            indicesService.verifyIndexMetadata(updatedMetadata, updatedMetadata);
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
    return updatedState;
}
Also used : ShardLimitValidator(org.elasticsearch.indices.ShardLimitValidator) RelationName(io.crate.metadata.RelationName) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) Map(java.util.Map) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) ValidationException(org.elasticsearch.common.ValidationException) MetadataUpdateSettingsService.maybeUpdateClusterBlock(org.elasticsearch.cluster.metadata.MetadataUpdateSettingsService.maybeUpdateClusterBlock) InvalidIndexTemplateException(org.elasticsearch.indices.InvalidIndexTemplateException) NodeContext(io.crate.metadata.NodeContext) IndexSettings.same(org.elasticsearch.index.IndexSettings.same) Setting(org.elasticsearch.common.settings.Setting) Set(java.util.Set) BytesReference(org.elasticsearch.common.bytes.BytesReference) Collectors(java.util.stream.Collectors) TableParameters(io.crate.analyze.TableParameters) UncheckedIOException(java.io.UncheckedIOException) MapperService(org.elasticsearch.index.mapper.MapperService) List(java.util.List) Optional(java.util.Optional) PutMappingClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest) VisibleForTesting(io.crate.common.annotations.VisibleForTesting) DocTableInfoBuilder(io.crate.metadata.doc.DocTableInfoBuilder) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) XContentType(org.elasticsearch.common.xcontent.XContentType) AlterTableRequest(io.crate.execution.ddl.tables.AlterTableRequest) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) MetadataUpdateSettingsService(org.elasticsearch.cluster.metadata.MetadataUpdateSettingsService) PartitionName(io.crate.metadata.PartitionName) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) XContentHelper(org.elasticsearch.common.xcontent.XContentHelper) Metadata(org.elasticsearch.cluster.metadata.Metadata) BiConsumer(java.util.function.BiConsumer) Regex(org.elasticsearch.common.regex.Regex) IndicesService(org.elasticsearch.indices.IndicesService) MetadataMappingService(org.elasticsearch.cluster.metadata.MetadataMappingService) Maps(io.crate.common.collections.Maps) IOException(java.io.IOException) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) MetadataCreateIndexService(org.elasticsearch.cluster.metadata.MetadataCreateIndexService) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) UpdateSettingsClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) ARCHIVED_SETTINGS_PREFIX(org.elasticsearch.common.settings.AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) ValidationException(org.elasticsearch.common.ValidationException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Index(org.elasticsearch.index.Index) UncheckedIOException(java.io.UncheckedIOException) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) Setting(org.elasticsearch.common.settings.Setting) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable)

Example 13 with Setting

use of org.elasticsearch.common.settings.Setting in project crate by crate.

the class MetadataUpdateSettingsService method updateSettings.

public void updateSettings(final UpdateSettingsClusterStateUpdateRequest request, final ActionListener<ClusterStateUpdateResponse> listener) {
    final Settings normalizedSettings = Settings.builder().put(request.settings()).normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX).build();
    Settings.Builder settingsForClosedIndices = Settings.builder();
    Settings.Builder settingsForOpenIndices = Settings.builder();
    final Set<String> skippedSettings = new HashSet<>();
    indexScopedSettings.validate(// don't validate wildcards
    normalizedSettings.filter(s -> Regex.isSimpleMatchPattern(s) == false), // don't validate dependencies here we check it below never allow to change the number of shards
    false, // validate internal or private index settings
    true);
    for (String key : normalizedSettings.keySet()) {
        Setting setting = indexScopedSettings.get(key);
        boolean isWildcard = setting == null && Regex.isSimpleMatchPattern(key);
        assert // we already validated the normalized settings
        setting != null || (isWildcard && normalizedSettings.hasValue(key) == false) : "unknown setting: " + key + " isWildcard: " + isWildcard + " hasValue: " + normalizedSettings.hasValue(key);
        settingsForClosedIndices.copy(key, normalizedSettings);
        if (isWildcard || setting.isDynamic()) {
            settingsForOpenIndices.copy(key, normalizedSettings);
        } else {
            skippedSettings.add(key);
        }
    }
    final Settings closedSettings = settingsForClosedIndices.build();
    final Settings openSettings = settingsForOpenIndices.build();
    final boolean preserveExisting = request.isPreserveExisting();
    clusterService.submitStateUpdateTask("update-settings", new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(Priority.URGENT, request, listener) {

        @Override
        protected ClusterStateUpdateResponse newResponse(boolean acknowledged) {
            return new ClusterStateUpdateResponse(acknowledged);
        }

        @Override
        public ClusterState execute(ClusterState currentState) {
            RoutingTable.Builder routingTableBuilder = RoutingTable.builder(currentState.routingTable());
            Metadata.Builder metadataBuilder = Metadata.builder(currentState.metadata());
            // allow to change any settings to a close index, and only allow dynamic settings to be changed
            // on an open index
            Set<Index> openIndices = new HashSet<>();
            Set<Index> closeIndices = new HashSet<>();
            final String[] actualIndices = new String[request.indices().length];
            for (int i = 0; i < request.indices().length; i++) {
                Index index = request.indices()[i];
                actualIndices[i] = index.getName();
                final IndexMetadata metadata = currentState.metadata().getIndexSafe(index);
                if (metadata.getState() == IndexMetadata.State.OPEN) {
                    openIndices.add(index);
                } else {
                    closeIndices.add(index);
                }
            }
            if (!skippedSettings.isEmpty() && !openIndices.isEmpty()) {
                throw new IllegalArgumentException(String.format(Locale.ROOT, "Can't update non dynamic settings [%s] for open indices %s", skippedSettings, openIndices));
            }
            if (IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.exists(openSettings)) {
                final int updatedNumberOfReplicas = IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(openSettings);
                if (preserveExisting == false) {
                    // Verify that this won't take us over the cluster shard limit.
                    int totalNewShards = Arrays.stream(request.indices()).mapToInt(i -> getTotalNewShards(i, currentState, updatedNumberOfReplicas)).sum();
                    Optional<String> error = shardLimitValidator.checkShardLimit(totalNewShards, currentState);
                    if (error.isPresent()) {
                        ValidationException ex = new ValidationException();
                        ex.addValidationError(error.get());
                        throw ex;
                    }
                    /*
                                 * We do not update the in-sync allocation IDs as they will be removed upon the first index operation which makes
                                 * these copies stale.
                                 *
                                 * TODO: should we update the in-sync allocation IDs once the data is deleted by the node?
                                 */
                    routingTableBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
                    metadataBuilder.updateNumberOfReplicas(updatedNumberOfReplicas, actualIndices);
                    LOGGER.info("updating number_of_replicas to [{}] for indices {}", updatedNumberOfReplicas, actualIndices);
                }
            }
            ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_ONLY_BLOCK, IndexMetadata.INDEX_READ_ONLY_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK, IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_METADATA_BLOCK, IndexMetadata.INDEX_BLOCKS_METADATA_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_WRITE_BLOCK, IndexMetadata.INDEX_BLOCKS_WRITE_SETTING, openSettings);
            maybeUpdateClusterBlock(actualIndices, blocks, IndexMetadata.INDEX_READ_BLOCK, IndexMetadata.INDEX_BLOCKS_READ_SETTING, openSettings);
            if (!openIndices.isEmpty()) {
                for (Index index : openIndices) {
                    IndexMetadata indexMetadata = metadataBuilder.getSafe(index);
                    Settings.Builder updates = Settings.builder();
                    Settings.Builder indexSettings = Settings.builder().put(indexMetadata.getSettings());
                    if (indexScopedSettings.updateDynamicSettings(openSettings, indexSettings, updates, index.getName())) {
                        if (preserveExisting) {
                            indexSettings.put(indexMetadata.getSettings());
                        }
                        Settings finalSettings = indexSettings.build();
                        indexScopedSettings.validate(finalSettings.filter(k -> indexScopedSettings.isPrivateSetting(k) == false), true);
                        metadataBuilder.put(IndexMetadata.builder(indexMetadata).settings(finalSettings));
                    }
                }
            }
            if (!closeIndices.isEmpty()) {
                for (Index index : closeIndices) {
                    IndexMetadata indexMetadata = metadataBuilder.getSafe(index);
                    Settings.Builder updates = Settings.builder();
                    Settings.Builder indexSettings = Settings.builder().put(indexMetadata.getSettings());
                    if (indexScopedSettings.updateSettings(closedSettings, indexSettings, updates, index.getName())) {
                        if (preserveExisting) {
                            indexSettings.put(indexMetadata.getSettings());
                        }
                        Settings finalSettings = indexSettings.build();
                        indexScopedSettings.validate(finalSettings.filter(k -> indexScopedSettings.isPrivateSetting(k) == false), true);
                        metadataBuilder.put(IndexMetadata.builder(indexMetadata).settings(finalSettings));
                    }
                }
            }
            // increment settings versions
            for (final String index : actualIndices) {
                if (same(currentState.metadata().index(index).getSettings(), metadataBuilder.get(index).getSettings()) == false) {
                    final IndexMetadata.Builder builder = IndexMetadata.builder(metadataBuilder.get(index));
                    builder.settingsVersion(1 + builder.settingsVersion());
                    metadataBuilder.put(builder);
                }
            }
            ClusterState updatedState = ClusterState.builder(currentState).metadata(metadataBuilder).routingTable(routingTableBuilder.build()).blocks(blocks).build();
            // now, reroute in case things change that require it (like number of replicas)
            updatedState = allocationService.reroute(updatedState, "settings update");
            try {
                for (Index index : openIndices) {
                    final IndexMetadata currentMetadata = currentState.getMetadata().getIndexSafe(index);
                    final IndexMetadata updatedMetadata = updatedState.metadata().getIndexSafe(index);
                    indicesService.verifyIndexMetadata(currentMetadata, updatedMetadata);
                }
                for (Index index : closeIndices) {
                    final IndexMetadata currentMetadata = currentState.getMetadata().getIndexSafe(index);
                    final IndexMetadata updatedMetadata = updatedState.metadata().getIndexSafe(index);
                    // Verifies that the current index settings can be updated with the updated dynamic settings.
                    indicesService.verifyIndexMetadata(currentMetadata, updatedMetadata);
                    // Now check that we can create the index with the updated settings (dynamic and non-dynamic).
                    // This step is mandatory since we allow to update non-dynamic settings on closed indices.
                    indicesService.verifyIndexMetadata(updatedMetadata, updatedMetadata);
                }
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return updatedState;
        }
    });
}
Also used : Arrays(java.util.Arrays) AckedClusterStateUpdateTask(org.elasticsearch.cluster.AckedClusterStateUpdateTask) Tuple(io.crate.common.collections.Tuple) ShardLimitValidator(org.elasticsearch.indices.ShardLimitValidator) ClusterService(org.elasticsearch.cluster.service.ClusterService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) UpgradeSettingsClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.upgrade.post.UpgradeSettingsClusterStateUpdateRequest) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) Index(org.elasticsearch.index.Index) Inject(org.elasticsearch.common.inject.Inject) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlock(org.elasticsearch.cluster.block.ClusterBlock) Locale(java.util.Locale) Map(java.util.Map) Regex(org.elasticsearch.common.regex.Regex) ValidationException(org.elasticsearch.common.ValidationException) IndicesService(org.elasticsearch.indices.IndicesService) Priority(org.elasticsearch.common.Priority) Setting(org.elasticsearch.common.settings.Setting) IndexSettings.same(org.elasticsearch.index.IndexSettings.same) Set(java.util.Set) IOException(java.io.IOException) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) UncheckedIOException(java.io.UncheckedIOException) Logger(org.apache.logging.log4j.Logger) Version(org.elasticsearch.Version) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Optional(java.util.Optional) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) UpdateSettingsClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsClusterStateUpdateRequest) LogManager(org.apache.logging.log4j.LogManager) ActionListener(org.elasticsearch.action.ActionListener) ClusterState(org.elasticsearch.cluster.ClusterState) HashSet(java.util.HashSet) Set(java.util.Set) ValidationException(org.elasticsearch.common.ValidationException) Optional(java.util.Optional) Setting(org.elasticsearch.common.settings.Setting) Index(org.elasticsearch.index.Index) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClusterStateUpdateResponse(org.elasticsearch.cluster.ack.ClusterStateUpdateResponse) Settings(org.elasticsearch.common.settings.Settings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) HashSet(java.util.HashSet)

Example 14 with Setting

use of org.elasticsearch.common.settings.Setting in project crate by crate.

the class IndexSettingsModule method newIndexSettings.

public static IndexSettings newIndexSettings(Index index, Settings indexSetting, Settings nodeSettings, Setting<?>... setting) {
    Settings build = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(indexSetting).build();
    IndexMetadata metadata = IndexMetadata.builder(index.getName()).settings(build).build();
    Set<Setting<?>> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
    if (setting.length > 0) {
        settingSet.addAll(Arrays.asList(setting));
    }
    return new IndexSettings(metadata, nodeSettings, new IndexScopedSettings(Settings.EMPTY, settingSet));
}
Also used : IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Setting(org.elasticsearch.common.settings.Setting) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) HashSet(java.util.HashSet)

Example 15 with Setting

use of org.elasticsearch.common.settings.Setting in project crate by crate.

the class CrateDummyClusterServiceUnitTest method createClusterService.

protected ClusterService createClusterService(Collection<Setting<?>> additionalClusterSettings, Version version) {
    Set<Setting<?>> clusterSettingsSet = new HashSet<>(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    clusterSettingsSet.addAll(additionalClusterSettings);
    ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, clusterSettingsSet);
    ClusterService clusterService = new ClusterService(Settings.builder().put("cluster.name", "ClusterServiceTests").put(Node.NODE_NAME_SETTING.getKey(), NODE_NAME).build(), clusterSettings, THREAD_POOL);
    clusterService.setNodeConnectionsService(createNoOpNodeConnectionsService());
    DiscoveryNode discoveryNode = new DiscoveryNode(NODE_NAME, NODE_ID, buildNewFakeTransportAddress(), Collections.emptyMap(), DiscoveryNodeRole.BUILT_IN_ROLES, version);
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(discoveryNode).localNodeId(NODE_ID).masterNodeId(NODE_ID).build();
    ClusterState clusterState = ClusterState.builder(new ClusterName(this.getClass().getSimpleName())).nodes(nodes).blocks(ClusterBlocks.EMPTY_CLUSTER_BLOCK).build();
    ClusterApplierService clusterApplierService = clusterService.getClusterApplierService();
    clusterApplierService.setInitialState(clusterState);
    MasterService masterService = clusterService.getMasterService();
    masterService.setClusterStatePublisher(createClusterStatePublisher(clusterApplierService));
    masterService.setClusterStateSupplier(clusterApplierService::state);
    clusterService.start();
    return clusterService;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) ClusterService(org.elasticsearch.cluster.service.ClusterService) Setting(org.elasticsearch.common.settings.Setting) ClusterName(org.elasticsearch.cluster.ClusterName) ClusterApplierService(org.elasticsearch.cluster.service.ClusterApplierService) MasterService(org.elasticsearch.cluster.service.MasterService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) HashSet(java.util.HashSet)

Aggregations

Setting (org.elasticsearch.common.settings.Setting)15 Settings (org.elasticsearch.common.settings.Settings)13 IndexScopedSettings (org.elasticsearch.common.settings.IndexScopedSettings)9 HashSet (java.util.HashSet)8 Set (java.util.Set)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Map (java.util.Map)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Version (org.elasticsearch.Version)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)4 StringContains.containsString (org.hamcrest.core.StringContains.containsString)4 HasToString.hasToString (org.hamcrest.object.HasToString.hasToString)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ActionListener (org.elasticsearch.action.ActionListener)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3