Search in sources :

Example 1 with IndicesAliasesResponse

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse 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 2 with IndicesAliasesResponse

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project bw-calendar-engine by Bedework.

the class BwIndexEsImpl method setAlias.

@Override
public int setAlias(final String index, final String alias) throws CalFacadeException {
    // IndicesAliasesResponse resp = null;
    try {
        /* Other is the alias name - index is the index we were just indexing into
       */
        final IndicesAdminClient idx = getAdminIdx();
        final GetAliasesRequestBuilder igarb = idx.prepareGetAliases(alias);
        final ActionFuture<GetAliasesResponse> getAliasesAf = idx.getAliases(igarb.request());
        final GetAliasesResponse garesp = getAliasesAf.actionGet();
        final ImmutableOpenMap<String, List<AliasMetaData>> aliasesmeta = garesp.getAliases();
        final IndicesAliasesRequestBuilder iarb = idx.prepareAliases();
        final Iterator<String> it = aliasesmeta.keysIt();
        while (it.hasNext()) {
            final String indexName = it.next();
            for (final AliasMetaData amd : aliasesmeta.get(indexName)) {
                if (amd.getAlias().equals(alias)) {
                    iarb.removeAlias(indexName, alias);
                }
            }
        }
        iarb.addAlias(index, alias);
        final ActionFuture<IndicesAliasesResponse> af = idx.aliases(iarb.request());
        /*resp = */
        af.actionGet();
        return 0;
    } catch (final ElasticsearchException ese) {
        // Failed somehow
        error(ese);
        return -1;
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) GetAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ElasticsearchException(org.elasticsearch.ElasticsearchException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) ArrayList(java.util.ArrayList) List(java.util.List) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) IndicesAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)

Example 3 with IndicesAliasesResponse

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project elasticsearch by elastic.

the class AckIT method testIndicesAliasesNoAcknowledgement.

public void testIndicesAliasesNoAcknowledgement() {
    createIndex("test");
    IndicesAliasesResponse indicesAliasesResponse = client().admin().indices().prepareAliases().addAlias("test", "alias").setTimeout("0s").get();
    assertThat(indicesAliasesResponse.isAcknowledged(), equalTo(false));
}
Also used : IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)

Example 4 with IndicesAliasesResponse

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testCloseOpenAliasMultipleIndices.

public void testCloseOpenAliasMultipleIndices() {
    Client client = client();
    createIndex("test1", "test2");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    IndicesAliasesResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
    assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
    IndicesAliasesResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
    assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)

Example 5 with IndicesAliasesResponse

use of org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse in project elasticsearch by elastic.

the class OpenCloseIndexIT method testSimpleCloseOpenAlias.

public void testSimpleCloseOpenAlias() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    IndicesAliasesResponse aliasesResponse = client.admin().indices().prepareAliases().addAlias("test1", "test1-alias").execute().actionGet();
    assertThat(aliasesResponse.isAcknowledged(), equalTo(true));
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CloseIndexResponse(org.elasticsearch.action.admin.indices.close.CloseIndexResponse) OpenIndexResponse(org.elasticsearch.action.admin.indices.open.OpenIndexResponse) Client(org.elasticsearch.client.Client) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)

Aggregations

IndicesAliasesResponse (org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse)8 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)3 IndicesAliasesRequestBuilder (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)3 Client (org.elasticsearch.client.Client)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 CloseIndexResponse (org.elasticsearch.action.admin.indices.close.CloseIndexResponse)2 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)2 OpenIndexResponse (org.elasticsearch.action.admin.indices.open.OpenIndexResponse)2 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseEncoding (com.google.common.io.BaseEncoding)1 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 StandardCharsets (java.nio.charset.StandardCharsets)1