Search in sources :

Example 21 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.

the class TransportRenameTableAction method masterOperation.

@Override
protected void masterOperation(RenameTableRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) throws Exception {
    AtomicReference<String[]> newIndexNames = new AtomicReference<>(null);
    ActionListener<AcknowledgedResponse> waitForShardsListener = ActionListeners.waitForShards(listener, activeShardsObserver, request.timeout(), () -> logger.info("Renamed a relation, but the operation timed out waiting for enough shards to become available"), newIndexNames::get);
    clusterService.submitStateUpdateTask("rename-table", new AckedClusterStateUpdateTask<AcknowledgedResponse>(Priority.HIGH, request, waitForShardsListener) {

        @Override
        public ClusterState execute(ClusterState currentState) throws Exception {
            ClusterState updatedState = executor.execute(currentState, request);
            IndicesOptions openIndices = IndicesOptions.fromOptions(true, true, true, false, true, true, false);
            newIndexNames.set(indexNameExpressionResolver.concreteIndexNames(updatedState, openIndices, request.targetTableIdent().indexNameOrAlias()));
            return updatedState;
        }

        @Override
        protected AcknowledgedResponse newResponse(boolean acknowledged) {
            return new AcknowledgedResponse(acknowledged);
        }
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) IOException(java.io.IOException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 22 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project crate by crate.

the class IndexNameExpressionResolver method concreteIndices.

Index[] concreteIndices(Context context, String... indexExpressions) {
    if (indexExpressions == null || indexExpressions.length == 0) {
        indexExpressions = new String[] { Metadata.ALL };
    }
    Metadata metadata = context.getState().metadata();
    IndicesOptions options = context.getOptions();
    final boolean failClosed = options.forbidClosedIndices() && options.ignoreUnavailable() == false;
    // If only one index is specified then whether we fail a request if an index is missing depends on the allow_no_indices
    // option. At some point we should change this, because there shouldn't be a reason why whether a single index
    // or multiple indices are specified yield different behaviour.
    final boolean failNoIndices = indexExpressions.length == 1 ? !options.allowNoIndices() : !options.ignoreUnavailable();
    List<String> expressions = expressionResolver.resolve(context, Arrays.asList(indexExpressions));
    if (expressions.isEmpty()) {
        if (!options.allowNoIndices()) {
            IndexNotFoundException infe = new IndexNotFoundException((String) null);
            infe.setResources("index_expression", indexExpressions);
            throw infe;
        } else {
            return Index.EMPTY_ARRAY;
        }
    }
    final Set<Index> concreteIndices = new HashSet<>(expressions.size());
    for (String expression : expressions) {
        AliasOrIndex aliasOrIndex = metadata.getAliasAndIndexLookup().get(expression);
        if (aliasOrIndex == null) {
            if (failNoIndices) {
                IndexNotFoundException infe = new IndexNotFoundException(expression);
                infe.setResources("index_expression", expression);
                throw infe;
            } else {
                continue;
            }
        } else if (aliasOrIndex.isAlias() && context.getOptions().ignoreAliases()) {
            if (failNoIndices) {
                throw aliasesNotSupportedException(expression);
            } else {
                continue;
            }
        }
        if (aliasOrIndex.isAlias() && context.isResolveToWriteIndex()) {
            AliasOrIndex.Alias alias = (AliasOrIndex.Alias) aliasOrIndex;
            IndexMetadata writeIndex = alias.getWriteIndex();
            if (writeIndex == null) {
                throw new IllegalArgumentException("no write index is defined for alias [" + alias.getAliasName() + "]." + " The write index may be explicitly disabled using is_write_index=false or the alias points to multiple" + " indices without one being designated as a write index");
            }
            concreteIndices.add(writeIndex.getIndex());
        } else {
            if (aliasOrIndex.getIndices().size() > 1 && !options.allowAliasesToMultipleIndices()) {
                String[] indexNames = new String[aliasOrIndex.getIndices().size()];
                int i = 0;
                for (IndexMetadata indexMetadata : aliasOrIndex.getIndices()) {
                    indexNames[i++] = indexMetadata.getIndex().getName();
                }
                throw new IllegalArgumentException("Alias [" + expression + "] has more than one indices associated with it [" + Arrays.toString(indexNames) + "], can't execute a single index op");
            }
            for (IndexMetadata index : aliasOrIndex.getIndices()) {
                if (index.getState() == IndexMetadata.State.CLOSE) {
                    if (failClosed) {
                        throw new IndexClosedException(index.getIndex());
                    } else {
                        if (options.forbidClosedIndices() == false) {
                            concreteIndices.add(index.getIndex());
                        }
                    }
                } else if (index.getState() == IndexMetadata.State.OPEN) {
                    concreteIndices.add(index.getIndex());
                } else {
                    throw new IllegalStateException("index state [" + index.getState() + "] not supported");
                }
            }
        }
    }
    if (options.allowNoIndices() == false && concreteIndices.isEmpty()) {
        IndexNotFoundException infe = new IndexNotFoundException((String) null);
        infe.setResources("index_expression", indexExpressions);
        throw infe;
    }
    return concreteIndices.toArray(new Index[concreteIndices.size()]);
}
Also used : Index(org.elasticsearch.index.Index) IndexClosedException(org.elasticsearch.indices.IndexClosedException) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) HashSet(java.util.HashSet)

Example 23 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method indexCreationDate.

@Override
public Optional<DateTime> indexCreationDate(String index) {
    final GetSettingsRequest request = new GetSettingsRequest().indices(index).indicesOptions(IndicesOptions.fromOptions(true, true, true, false));
    final GetSettingsResponse result = client.execute((c, requestOptions) -> c.indices().getSettings(request, requestOptions), "Couldn't read settings of index " + index);
    final Optional<String> creationDate = Optional.ofNullable(result.getIndexToSettings().get(index)).map(indexSettings -> indexSettings.get("index.creation_date"));
    return creationDate.map(Long::valueOf).map(instant -> new DateTime(instant, DateTimeZone.UTC));
}
Also used : GetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) DateTime(org.joda.time.DateTime)

Example 24 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method aliases.

@Override
public Map<String, Set<String>> aliases(String indexPattern) {
    final GetAliasesRequest request = new GetAliasesRequest().indices(indexPattern).indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
    final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions), "Couldn't collect aliases for index pattern " + indexPattern);
    return result.getAliases().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(AliasMetadata::alias).collect(Collectors.toSet())));
}
Also used : Terms(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.Terms) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) MultiBucketsAggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) LoggerFactory(org.slf4j.LoggerFactory) OpenIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.open.OpenIndexRequest) IndicesAdapter(org.graylog2.indexer.indices.IndicesAdapter) HealthStatus(org.graylog2.indexer.indices.HealthStatus) TimeValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue) Indices(org.graylog2.indexer.indices.Indices) Locale(java.util.Locale) Map(java.util.Map) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) JsonNode(com.fasterxml.jackson.databind.JsonNode) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) SearchType(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchType) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) StatsApi(org.graylog.storage.elasticsearch7.stats.StatsApi) Collection(java.util.Collection) DeleteIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Set(java.util.Set) Max(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Max) IndexTemplatesExistRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.IndexTemplatesExistRequest) ClusterStateApi(org.graylog.storage.elasticsearch7.cluster.ClusterStateApi) Collectors(java.util.stream.Collectors) UpdateSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest) List(java.util.List) AliasMetadata(org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata) GetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) IndexMoveResult(org.graylog2.indexer.indices.IndexMoveResult) GetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Optional(java.util.Optional) BulkByScrollResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.reindex.BulkByScrollResponse) Min(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Min) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse) ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) FlushRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.flush.FlushRequest) HashMap(java.util.HashMap) CloseIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CloseIndexRequest) AggregationBuilders(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilders) Inject(javax.inject.Inject) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest) PutMappingRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutMappingRequest) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Duration(com.github.joschi.jadconfig.util.Duration) Filter(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.Filter) Nonnull(javax.annotation.Nonnull) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FilterAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) IndexSettings(org.graylog2.indexer.indices.IndexSettings) ElasticsearchClient.withTimeout(org.graylog.storage.elasticsearch7.ElasticsearchClient.withTimeout) CatApi(org.graylog.storage.elasticsearch7.cat.CatApi) IndexNotFoundException(org.graylog2.indexer.IndexNotFoundException) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) DateTime(org.joda.time.DateTime) AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) ReindexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.reindex.ReindexRequest) ForceMergeRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) DeleteIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest) Consumer(java.util.function.Consumer) DeleteAliasRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.DeleteAliasRequest) Collectors.toList(java.util.stream.Collectors.toList) IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) QueryBuilders(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilders) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 25 with IndicesOptions

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions in project graylog2-server by Graylog2.

the class IndexToolsAdapterES7 method count.

@Override
public long count(Set<String> indices, Optional<Set<String>> includedStreams) {
    final CountRequest request = new CountRequest(indices.toArray(new String[0]), buildStreamIdFilter(includedStreams)).indicesOptions(IndicesOptions.fromOptions(true, false, true, false));
    final CountResponse result = client.execute((c, requestOptions) -> c.count(request, requestOptions), "Unable to count documents of index.");
    return result.getCount();
}
Also used : CountRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountRequest) CountResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.core.CountResponse)

Aggregations

IndicesOptions (org.elasticsearch.action.support.IndicesOptions)39 ClusterState (org.elasticsearch.cluster.ClusterState)11 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)11 ClusterName (org.elasticsearch.cluster.ClusterName)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Arrays (java.util.Arrays)5 List (java.util.List)5 ArrayList (java.util.ArrayList)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)4 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)4 Row (io.crate.data.Row)3 Row1 (io.crate.data.Row1)3 RowConsumer (io.crate.data.RowConsumer)3 OneRowActionListener (io.crate.execution.support.OneRowActionListener)3 DependencyCarrier (io.crate.planner.DependencyCarrier)3 Plan (io.crate.planner.Plan)3 PlannerContext (io.crate.planner.PlannerContext)3