Search in sources :

Example 1 with GetAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project elasticsearch by elastic.

the class RestAliasAction method doCatRequest.

@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final GetAliasesRequest getAliasesRequest = request.hasParam("alias") ? new GetAliasesRequest(request.param("alias")) : new GetAliasesRequest();
    getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));
    return channel -> client.admin().indices().getAliases(getAliasesRequest, new RestResponseListener<GetAliasesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetAliasesResponse response) throws Exception {
            Table tab = buildTable(request, response);
            return RestTable.buildResponse(tab, channel);
        }
    });
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestResponse(org.elasticsearch.rest.RestResponse) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Table(org.elasticsearch.common.Table) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) Table(org.elasticsearch.common.Table) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) RestResponse(org.elasticsearch.rest.RestResponse) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)

Example 2 with GetAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project elasticsearch by elastic.

the class RestGetAliasesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name");
    final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases);
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    getAliasesRequest.indices(indices);
    getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions()));
    getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local()));
    return channel -> client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception {
            if (response.getAliases().isEmpty()) {
                if (indices.length > 0) {
                    return new BytesRestResponse(OK, builder.startObject().endObject());
                } else {
                    final String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases()));
                    builder.startObject();
                    {
                        builder.field("error", message);
                        builder.field("status", RestStatus.NOT_FOUND.getStatus());
                    }
                    builder.endObject();
                    return new BytesRestResponse(RestStatus.NOT_FOUND, builder);
                }
            } else {
                builder.startObject();
                {
                    for (final ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) {
                        builder.startObject(entry.key);
                        {
                            builder.startObject("aliases");
                            {
                                for (final AliasMetaData alias : entry.value) {
                                    AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS);
                                }
                            }
                            builder.endObject();
                        }
                        builder.endObject();
                    }
                }
                builder.endObject();
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) Arrays(java.util.Arrays) GET(org.elasticsearch.rest.RestRequest.Method.GET) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Strings(org.elasticsearch.common.Strings) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) Settings(org.elasticsearch.common.settings.Settings) Locale(java.util.Locale) IndicesOptions(org.elasticsearch.action.support.IndicesOptions) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) RestResponse(org.elasticsearch.rest.RestResponse) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) RestBuilderListener(org.elasticsearch.rest.action.RestBuilderListener) ToXContent(org.elasticsearch.common.xcontent.ToXContent) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Collectors(java.util.stream.Collectors) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) List(java.util.List) RestStatus(org.elasticsearch.rest.RestStatus) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) RestResponse(org.elasticsearch.rest.RestResponse) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) IOException(java.io.IOException) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) List(java.util.List) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 3 with GetAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project graylog2-server by Graylog2.

the class Indices method aliasTarget.

@Nullable
public String aliasTarget(String alias) throws TooManyAliasesException {
    final IndicesAdminClient indicesAdminClient = c.admin().indices();
    final GetAliasesRequest request = indicesAdminClient.prepareGetAliases(alias).request();
    final GetAliasesResponse response = indicesAdminClient.getAliases(request).actionGet();
    // The ES return value of this has an awkward format: The first key of the hash is the target index. Thanks.
    final ImmutableOpenMap<String, List<AliasMetaData>> aliases = response.getAliases();
    if (aliases.size() > 1) {
        throw new TooManyAliasesException(Sets.newHashSet(aliases.keysIt()));
    }
    return aliases.isEmpty() ? null : aliases.keysIt().next();
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Nullable(javax.annotation.Nullable)

Example 4 with GetAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method resolveAlias.

@Override
public Set<String> resolveAlias(String alias) {
    final GetAliasesRequest request = new GetAliasesRequest().aliases(alias);
    final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions));
    return result.getAliases().keySet();
}
Also used : GetAliasesResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse) GetAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)

Example 5 with GetAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest 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)

Aggregations

GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)5 List (java.util.List)4 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)3 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)2 Arrays (java.util.Arrays)2 Locale (java.util.Locale)2 Collectors (java.util.stream.Collectors)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)2 Strings (org.elasticsearch.common.Strings)2 Settings (org.elasticsearch.common.settings.Settings)2 RestController (org.elasticsearch.rest.RestController)2 RestRequest (org.elasticsearch.rest.RestRequest)2 GET (org.elasticsearch.rest.RestRequest.Method.GET)2 RestResponse (org.elasticsearch.rest.RestResponse)2 GetAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)2 GetAliasesResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.GetAliasesResponse)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Duration (com.github.joschi.jadconfig.util.Duration)1 ImmutableList (com.google.common.collect.ImmutableList)1