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);
}
});
}
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);
}
}
});
}
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();
}
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();
}
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())));
}
Aggregations