Search in sources :

Example 1 with IndicesAliasesRequest

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

the class RestIndicesAliasesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
    indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
    try (XContentParser parser = request.contentParser()) {
        PARSER.parse(parser, indicesAliasesRequest, null);
    }
    if (indicesAliasesRequest.getAliasActions().isEmpty()) {
        throw new IllegalArgumentException("No action specified");
    }
    return channel -> client.admin().indices().aliases(indicesAliasesRequest, new AcknowledgedRestListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) AliasActions(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) XContentParser(org.elasticsearch.common.xcontent.XContentParser) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) ParseField(org.elasticsearch.common.ParseField) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 2 with IndicesAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest in project crate by crate.

the class SchemasITest method testTableAlias.

@Test
public void testTableAlias() throws Exception {
    execute("create table terminator (model string, good boolean, actor object)");
    IndicesAliasesRequest request = new IndicesAliasesRequest();
    request.addAlias("entsafter", "terminator");
    client().admin().indices().aliases(request).actionGet();
    ensureYellow();
    DocTableInfo terminatorTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "terminator"));
    DocTableInfo entsafterTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "entsafter"));
    assertNotNull(terminatorTable);
    assertFalse(terminatorTable.isAlias());
    assertNotNull(entsafterTable);
    assertTrue(entsafterTable.isAlias());
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 3 with IndicesAliasesRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest in project crate by crate.

the class SchemasITest method testAliasPartitions.

@Test
public void testAliasPartitions() throws Exception {
    execute("create table terminator (model string, good boolean, actor object)");
    execute("create table transformer (model string, good boolean, actor object)");
    IndicesAliasesRequest request = new IndicesAliasesRequest();
    request.addAlias("entsafter", "terminator");
    request.addAlias("entsafter", "transformer");
    client().admin().indices().aliases(request).actionGet();
    ensureYellow();
    DocTableInfo entsafterTable = (DocTableInfo) schemas.getTableInfo(new TableIdent(null, "entsafter"));
    assertNotNull(entsafterTable);
    assertThat(entsafterTable.concreteIndices().length, is(2));
    assertThat(Arrays.asList(entsafterTable.concreteIndices()), containsInAnyOrder("terminator", "transformer"));
}
Also used : DocTableInfo(io.crate.metadata.doc.DocTableInfo) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) Test(org.junit.Test) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest)

Example 4 with IndicesAliasesRequest

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

the class IndicesTest method testAliasTarget.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testAliasTarget() throws Exception {
    assertThat(indices.aliasTarget("graylog_alias")).isNull();
    final IndicesAdminClient adminClient = client.admin().indices();
    final IndicesAliasesRequest request = adminClient.prepareAliases().addAlias(INDEX_NAME, "graylog_alias").request();
    final IndicesAliasesResponse response = adminClient.aliases(request).actionGet(ES_TIMEOUT);
    assertThat(response.isAcknowledged()).isTrue();
    assertThat(indices.aliasTarget("graylog_alias")).isEqualTo(INDEX_NAME);
}
Also used : IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 5 with IndicesAliasesRequest

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

the class ClientES7 method removeAliasMapping.

@Override
public void removeAliasMapping(String indexName, String alias) {
    final IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    final AliasActions aliasAction = new AliasActions(AliasActions.Type.REMOVE).index(indexName).alias(alias);
    indicesAliasesRequest.addAliasAction(aliasAction);
    client.execute((c, requestOptions) -> c.indices().updateAliases(indicesAliasesRequest, requestOptions), "failed to remove alias " + alias + " for index " + indexName);
}
Also used : IndicesAliasesRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) AliasActions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)

Aggregations

IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)8 IndicesAliasesRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)5 IOException (java.io.IOException)3 AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)3 NodeClient (org.elasticsearch.client.node.NodeClient)3 Settings (org.elasticsearch.common.settings.Settings)3 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)3 RestController (org.elasticsearch.rest.RestController)3 RestRequest (org.elasticsearch.rest.RestRequest)3 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)3 Test (org.junit.Test)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)2 Strings (org.elasticsearch.common.Strings)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)1 ClusterSearchShardsRequest (org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsRequest)1