Search in sources :

Example 51 with IndexTemplateMetaData

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

the class IndexTemplateUpgraderTest method testArchivedSettingsAreRemovedOnPartitionedTableTemplates.

@Test
public void testArchivedSettingsAreRemovedOnPartitionedTableTemplates() {
    IndexTemplateUpgrader upgrader = new IndexTemplateUpgrader();
    Settings settings = Settings.builder().put(ARCHIVED_SETTINGS_PREFIX + "some.setting", // archived, must be filtered out
    true).put(SETTING_NUMBER_OF_SHARDS, 4).build();
    HashMap<String, IndexTemplateMetadata> templates = new HashMap<>();
    String partitionTemplateName = PartitionName.templateName("doc", "t1");
    IndexTemplateMetadata oldPartitionTemplate = IndexTemplateMetadata.builder(partitionTemplateName).settings(settings).patterns(Collections.singletonList("*")).build();
    templates.put(partitionTemplateName, oldPartitionTemplate);
    String nonPartitionTemplateName = "non-partition-template";
    IndexTemplateMetadata oldNonPartitionTemplate = IndexTemplateMetadata.builder(nonPartitionTemplateName).settings(settings).patterns(Collections.singletonList("*")).build();
    templates.put(nonPartitionTemplateName, oldNonPartitionTemplate);
    Map<String, IndexTemplateMetadata> upgradedTemplates = upgrader.apply(templates);
    IndexTemplateMetadata upgradedTemplate = upgradedTemplates.get(partitionTemplateName);
    assertThat(upgradedTemplate.settings().keySet(), contains(SETTING_NUMBER_OF_SHARDS));
    // ensure all other attributes remains the same
    assertThat(upgradedTemplate.mappings(), is(oldPartitionTemplate.mappings()));
    assertThat(upgradedTemplate.patterns(), is(oldPartitionTemplate.patterns()));
    assertThat(upgradedTemplate.order(), is(oldPartitionTemplate.order()));
    assertThat(upgradedTemplate.aliases(), is(oldPartitionTemplate.aliases()));
    // ensure non partitioned table templates are untouched
    assertThat(upgradedTemplates.get(nonPartitionTemplateName), is(oldNonPartitionTemplate));
}
Also used : HashMap(java.util.HashMap) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Example 52 with IndexTemplateMetaData

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

the class IndexTemplateUpgraderTest method testDefaultTemplateIsUpgraded.

@Test
public void testDefaultTemplateIsUpgraded() throws IOException {
    IndexTemplateUpgrader upgrader = new IndexTemplateUpgrader();
    HashMap<String, IndexTemplateMetadata> templates = new HashMap<>();
    IndexTemplateMetadata oldTemplate = IndexTemplateMetadata.builder(TEMPLATE_NAME).patterns(Collections.singletonList("*")).build();
    templates.put(TEMPLATE_NAME, oldTemplate);
    Map<String, IndexTemplateMetadata> upgradedTemplates = upgrader.apply(templates);
    assertThat(upgradedTemplates.get(TEMPLATE_NAME), Matchers.nullValue());
}
Also used : HashMap(java.util.HashMap) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Test(org.junit.Test)

Example 53 with IndexTemplateMetaData

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

the class GatewayMetaStateTests method randomMetadataWithIndexTemplates.

private static Metadata randomMetadataWithIndexTemplates(String... templates) {
    Metadata.Builder builder = Metadata.builder();
    for (String template : templates) {
        IndexTemplateMetadata templateMetadata = IndexTemplateMetadata.builder(template).settings(settings(Version.CURRENT).put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), randomIntBetween(0, 3)).put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))).patterns(randomIndexPatterns()).build();
        builder.put(templateMetadata);
    }
    for (int i = 0; i < randomIntBetween(1, 5); i++) {
        builder.put(IndexMetadata.builder(randomAlphaOfLength(10)).settings(settings(Version.CURRENT)).numberOfReplicas(randomIntBetween(0, 3)).numberOfShards(randomIntBetween(1, 5)));
    }
    return builder.build();
}
Also used : IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) IndexTemplateMetadata(org.elasticsearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.elasticsearch.cluster.metadata.Metadata) TestCustomMetadata(org.elasticsearch.test.TestCustomMetadata)

Example 54 with IndexTemplateMetaData

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

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)

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