Search in sources :

Example 16 with AliasMetadata

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class GetAliasesResponse method readFrom.

@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    int size = in.readVInt();
    ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesBuilder = ImmutableOpenMap.builder();
    for (int i = 0; i < size; i++) {
        String key = in.readString();
        int valueSize = in.readVInt();
        List<AliasMetaData> value = new ArrayList<>(valueSize);
        for (int j = 0; j < valueSize; j++) {
            value.add(new AliasMetaData(in));
        }
        aliasesBuilder.put(key, Collections.unmodifiableList(value));
    }
    aliases = aliasesBuilder.build();
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap)

Example 17 with AliasMetadata

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class GetIndexIT method assertAliases.

private void assertAliases(GetIndexResponse response, String indexName) {
    ImmutableOpenMap<String, List<AliasMetaData>> aliases = response.aliases();
    assertThat(aliases, notNullValue());
    assertThat(aliases.size(), equalTo(1));
    List<AliasMetaData> indexAliases = aliases.get(indexName);
    assertThat(indexAliases, notNullValue());
    assertThat(indexAliases.size(), equalTo(1));
    AliasMetaData alias = indexAliases.get(0);
    assertThat(alias, notNullValue());
    assertThat(alias.alias(), equalTo("alias_idx"));
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with AliasMetadata

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class AckIT method testIndicesAliasesAcknowledgement.

public void testIndicesAliasesAcknowledgement() {
    createIndex("test");
    //as the previous operation was acknowledged
    for (int i = 0; i < 2; i++) {
        assertAcked(client().admin().indices().prepareAliases().addAlias("test", "alias"));
        for (Client client : clients()) {
            AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) getLocalClusterState(client).metaData().getAliasAndIndexLookup().get("alias")).getFirstAliasMetaData();
            assertThat(aliasMetaData.alias(), equalTo("alias"));
        }
    }
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Client(org.elasticsearch.client.Client)

Example 19 with AliasMetadata

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class IndexAliasesIT method testSameAlias.

public void testSameAlias() throws Exception {
    logger.info("--> creating index [test]");
    assertAcked(prepareCreate("test").addMapping("type", "name", "type=text"));
    ensureGreen();
    logger.info("--> creating alias1 ");
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1")));
    TimeValue timeout = TimeValue.timeValueSeconds(2);
    logger.info("--> recreating alias1 ");
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1").setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
    logger.info("--> modifying alias1 to have a filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "foo")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
    logger.info("--> recreating alias1 with the same filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "foo")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
    logger.info("--> recreating alias1 with a different filter");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().addAlias("test", "alias1", termQuery("name", "bar")).setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
    logger.info("--> verify that filter was updated");
    AliasMetaData aliasMetaData = ((AliasOrIndex.Alias) internalCluster().clusterService().state().metaData().getAliasAndIndexLookup().get("alias1")).getFirstAliasMetaData();
    assertThat(aliasMetaData.getFilter().toString(), equalTo("{\"term\":{\"name\":{\"value\":\"bar\",\"boost\":1.0}}}"));
    logger.info("--> deleting alias1");
    stopWatch.start();
    assertAcked((admin().indices().prepareAliases().removeAlias("test", "alias1").setTimeout(timeout)));
    assertThat(stopWatch.stop().lastTaskTime().millis(), lessThan(timeout.millis()));
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) Alias(org.elasticsearch.action.admin.indices.alias.Alias) TimeValue(org.elasticsearch.common.unit.TimeValue) StopWatch(org.elasticsearch.common.StopWatch)

Example 20 with AliasMetadata

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.metadata.AliasMetadata in project elasticsearch by elastic.

the class IndexAliasesIT method checkAliases.

private void checkAliases() {
    GetAliasesResponse getAliasesResponse = admin().indices().prepareGetAliases("alias1").get();
    assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
    AliasMetaData aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
    assertThat(aliasMetaData.alias(), equalTo("alias1"));
    assertThat(aliasMetaData.filter(), nullValue());
    assertThat(aliasMetaData.indexRouting(), nullValue());
    assertThat(aliasMetaData.searchRouting(), nullValue());
    getAliasesResponse = admin().indices().prepareGetAliases("alias2").get();
    assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
    aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
    assertThat(aliasMetaData.alias(), equalTo("alias2"));
    assertThat(aliasMetaData.filter(), notNullValue());
    assertThat(aliasMetaData.indexRouting(), nullValue());
    assertThat(aliasMetaData.searchRouting(), nullValue());
    getAliasesResponse = admin().indices().prepareGetAliases("alias3").get();
    assertThat(getAliasesResponse.getAliases().get("test").size(), equalTo(1));
    aliasMetaData = getAliasesResponse.getAliases().get("test").get(0);
    assertThat(aliasMetaData.alias(), equalTo("alias3"));
    assertThat(aliasMetaData.filter(), nullValue());
    assertThat(aliasMetaData.indexRouting(), equalTo("index"));
    assertThat(aliasMetaData.searchRouting(), equalTo("search"));
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)

Aggregations

AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)20 List (java.util.List)13 Settings (org.elasticsearch.common.settings.Settings)10 ArrayList (java.util.ArrayList)9 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)8 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Set (java.util.Set)5 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)4 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)4 Index (org.elasticsearch.index.Index)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 GetAliasesResponse (org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse)3 AliasMetadata (org.elasticsearch.cluster.metadata.AliasMetadata)3 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)3