Search in sources :

Example 26 with IndexTemplateMetaData

use of org.elasticsearch.cluster.metadata.IndexTemplateMetaData in project crate by crate.

the class DefaultTemplateService method addDefaultTemplate.

@VisibleForTesting
static ClusterState addDefaultTemplate(ClusterState currentState) throws IOException {
    MetaData currentMetaData = currentState.getMetaData();
    ImmutableOpenMap<String, IndexTemplateMetaData> currentTemplates = currentMetaData.getTemplates();
    ImmutableOpenMap<String, IndexTemplateMetaData> newTemplates = createCopyWithDefaultTemplateAdded(currentTemplates);
    MetaData.Builder mdBuilder = MetaData.builder(currentMetaData).templates(newTemplates);
    return ClusterState.builder(currentState).metaData(mdBuilder).build();
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 27 with IndexTemplateMetaData

use of org.elasticsearch.cluster.metadata.IndexTemplateMetaData in project elasticsearch by elastic.

the class GetIndexTemplatesResponse method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(indexTemplates.size());
    for (IndexTemplateMetaData indexTemplate : indexTemplates) {
        indexTemplate.writeTo(out);
    }
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData)

Example 28 with IndexTemplateMetaData

use of org.elasticsearch.cluster.metadata.IndexTemplateMetaData in project elasticsearch by elastic.

the class ElasticsearchAssertions method assertIndexTemplateMissing.

/**
     * Assert that an index template is missing
     */
public static void assertIndexTemplateMissing(GetIndexTemplatesResponse templatesResponse, String name) {
    List<String> templateNames = new ArrayList<>();
    for (IndexTemplateMetaData indexTemplateMetaData : templatesResponse.getIndexTemplates()) {
        templateNames.add(indexTemplateMetaData.name());
    }
    assertThat(templateNames, not(hasItem(name)));
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ArrayList(java.util.ArrayList)

Example 29 with IndexTemplateMetaData

use of org.elasticsearch.cluster.metadata.IndexTemplateMetaData in project elasticsearch by elastic.

the class ElasticsearchAssertions method assertIndexTemplateExists.

/**
     * Assert that an index template exists
     */
public static void assertIndexTemplateExists(GetIndexTemplatesResponse templatesResponse, String name) {
    List<String> templateNames = new ArrayList<>();
    for (IndexTemplateMetaData indexTemplateMetaData : templatesResponse.getIndexTemplates()) {
        templateNames.add(indexTemplateMetaData.name());
    }
    assertThat(templateNames, hasItem(name));
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ArrayList(java.util.ArrayList)

Example 30 with IndexTemplateMetaData

use of org.elasticsearch.cluster.metadata.IndexTemplateMetaData in project crate by crate.

the class TableAliasIntegrationTest method testPartitionedTableKeepsAliasAfterSchemaUpdate.

@Test
public void testPartitionedTableKeepsAliasAfterSchemaUpdate() throws Exception {
    execute("create table t (name string, p string) partitioned by (p) " + "clustered into 2 shards with (number_of_replicas = 0)");
    ensureYellow();
    execute("insert into t (name, p) values ('Arthur', 'a')");
    execute("insert into t (name, p) values ('Trillian', 'a')");
    execute("alter table t add column age integer");
    execute("insert into t (name, p) values ('Marvin', 'b')");
    waitNoPendingTasksOnAll();
    refresh();
    execute("select count(*) from t");
    assertThat(response.rowCount(), is(1L));
    assertThat((Long) response.rows()[0][0], is(3L));
    GetIndexTemplatesResponse indexTemplatesResponse = client().admin().indices().prepareGetTemplates(".partitioned.t.").execute().actionGet();
    IndexTemplateMetaData indexTemplateMetaData = indexTemplatesResponse.getIndexTemplates().get(0);
    AliasMetaData t = indexTemplateMetaData.aliases().get("t");
    assertThat(t.alias(), is("t"));
    execute("select partitioned_by from information_schema.tables where table_name = 't'");
    assertThat((String) ((Object[]) response.rows()[0][0])[0], is("p"));
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) Test(org.junit.Test)

Aggregations

IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)36 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)18 Test (org.junit.Test)16 Settings (org.elasticsearch.common.settings.Settings)14 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)13 Map (java.util.Map)12 Metadata (org.elasticsearch.cluster.metadata.Metadata)11 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)11 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)10 ClusterState (org.elasticsearch.cluster.ClusterState)10 PartitionName (io.crate.metadata.PartitionName)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 Index (org.elasticsearch.index.Index)9 RelationName (io.crate.metadata.RelationName)8 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)7 AliasMetadata (org.elasticsearch.cluster.metadata.AliasMetadata)6 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)6 IOException (java.io.IOException)5 Set (java.util.Set)5