Search in sources :

Example 1 with MetadataUpgrader

use of org.opensearch.plugins.MetadataUpgrader in project OpenSearch by opensearch-project.

the class GatewayMetaStateTests method testUpdateTemplateMetadataOnUpgrade.

public void testUpdateTemplateMetadataOnUpgrade() {
    Metadata metadata = randomMetadata();
    MetadataUpgrader metadataUpgrader = new MetadataUpgrader(Collections.singletonList(templates -> {
        templates.put("added_test_template", IndexTemplateMetadata.builder("added_test_template").patterns(randomIndexPatterns()).build());
        return templates;
    }));
    Metadata upgrade = GatewayMetaState.upgradeMetadata(metadata, new MockMetadataIndexUpgradeService(false), metadataUpgrader);
    assertNotSame(upgrade, metadata);
    assertFalse(Metadata.isGlobalStateEquals(upgrade, metadata));
    assertTrue(upgrade.templates().containsKey("added_test_template"));
}
Also used : MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) Arrays(java.util.Arrays) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings) HashMap(java.util.HashMap) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataIndexUpgradeService(org.opensearch.cluster.metadata.MetadataIndexUpgradeService) Objects(java.util.Objects) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) EnumSet(java.util.EnumSet) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader)

Example 2 with MetadataUpgrader

use of org.opensearch.plugins.MetadataUpgrader in project OpenSearch by opensearch-project.

the class GatewayMetaStateTests method testIndexMetadataUpgrade.

public void testIndexMetadataUpgrade() {
    Metadata metadata = randomMetadata();
    MetadataUpgrader metadataUpgrader = new MetadataUpgrader(Collections.emptyList());
    Metadata upgrade = GatewayMetaState.upgradeMetadata(metadata, new MockMetadataIndexUpgradeService(true), metadataUpgrader);
    assertNotSame(upgrade, metadata);
    assertTrue(Metadata.isGlobalStateEquals(upgrade, metadata));
    for (IndexMetadata indexMetadata : upgrade) {
        assertFalse(metadata.hasIndexMetadata(indexMetadata));
    }
}
Also used : IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 3 with MetadataUpgrader

use of org.opensearch.plugins.MetadataUpgrader in project OpenSearch by opensearch-project.

the class GatewayMetaStateTests method testNoMetadataUpgrade.

public void testNoMetadataUpgrade() {
    Metadata metadata = randomMetadata(new CustomMetadata1("data"));
    MetadataUpgrader metadataUpgrader = new MetadataUpgrader(Collections.emptyList());
    Metadata upgrade = GatewayMetaState.upgradeMetadata(metadata, new MockMetadataIndexUpgradeService(false), metadataUpgrader);
    assertSame(upgrade, metadata);
    assertTrue(Metadata.isGlobalStateEquals(upgrade, metadata));
    for (IndexMetadata indexMetadata : upgrade) {
        assertTrue(metadata.hasIndexMetadata(indexMetadata));
    }
}
Also used : IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 4 with MetadataUpgrader

use of org.opensearch.plugins.MetadataUpgrader in project OpenSearch by opensearch-project.

the class GatewayMetaStateTests method testCustomMetadataNoChange.

public void testCustomMetadataNoChange() {
    Metadata metadata = randomMetadata(new CustomMetadata1("data"));
    MetadataUpgrader metadataUpgrader = new MetadataUpgrader(Collections.singletonList(HashMap::new));
    Metadata upgrade = GatewayMetaState.upgradeMetadata(metadata, new MockMetadataIndexUpgradeService(false), metadataUpgrader);
    assertSame(upgrade, metadata);
    assertTrue(Metadata.isGlobalStateEquals(upgrade, metadata));
    for (IndexMetadata indexMetadata : upgrade) {
        assertTrue(metadata.hasIndexMetadata(indexMetadata));
    }
}
Also used : IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 5 with MetadataUpgrader

use of org.opensearch.plugins.MetadataUpgrader in project OpenSearch by opensearch-project.

the class GatewayMetaStateTests method testMultipleIndexTemplateUpgrade.

public void testMultipleIndexTemplateUpgrade() {
    final Metadata metadata;
    switch(randomIntBetween(0, 2)) {
        case 0:
            metadata = randomMetadataWithIndexTemplates("template1", "template2");
            break;
        case 1:
            metadata = randomMetadataWithIndexTemplates(randomBoolean() ? "template1" : "template2");
            break;
        case 2:
            metadata = randomMetadata();
            break;
        default:
            throw new IllegalStateException("should never happen");
    }
    MetadataUpgrader metadataUpgrader = new MetadataUpgrader(Arrays.asList(indexTemplateMetadatas -> {
        indexTemplateMetadatas.put("template1", IndexTemplateMetadata.builder("template1").patterns(randomIndexPatterns()).settings(Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 20).build()).build());
        return indexTemplateMetadatas;
    }, indexTemplateMetadatas -> {
        indexTemplateMetadatas.put("template2", IndexTemplateMetadata.builder("template2").patterns(randomIndexPatterns()).settings(Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), 10).build()).build());
        return indexTemplateMetadatas;
    }));
    Metadata upgrade = GatewayMetaState.upgradeMetadata(metadata, new MockMetadataIndexUpgradeService(false), metadataUpgrader);
    assertNotSame(upgrade, metadata);
    assertFalse(Metadata.isGlobalStateEquals(upgrade, metadata));
    assertNotNull(upgrade.templates().get("template1"));
    assertThat(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.get(upgrade.templates().get("template1").settings()), equalTo(20));
    assertNotNull(upgrade.templates().get("template2"));
    assertThat(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(upgrade.templates().get("template2").settings()), equalTo(10));
    for (IndexMetadata indexMetadata : upgrade) {
        assertTrue(metadata.hasIndexMetadata(indexMetadata));
    }
}
Also used : MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) Arrays(java.util.Arrays) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Version(org.opensearch.Version) Settings(org.opensearch.common.settings.Settings) HashMap(java.util.HashMap) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataIndexUpgradeService(org.opensearch.cluster.metadata.MetadataIndexUpgradeService) Objects(java.util.Objects) List(java.util.List) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) EnumSet(java.util.EnumSet) IndexTemplateMetadata(org.opensearch.cluster.metadata.IndexTemplateMetadata) Metadata(org.opensearch.cluster.metadata.Metadata) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) TestCustomMetadata(org.opensearch.test.TestCustomMetadata) MetadataUpgrader(org.opensearch.plugins.MetadataUpgrader) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Aggregations

IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)7 IndexTemplateMetadata (org.opensearch.cluster.metadata.IndexTemplateMetadata)7 Metadata (org.opensearch.cluster.metadata.Metadata)7 MetadataUpgrader (org.opensearch.plugins.MetadataUpgrader)7 TestCustomMetadata (org.opensearch.test.TestCustomMetadata)7 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Objects (java.util.Objects)3 Matchers.equalTo (org.hamcrest.Matchers.equalTo)3 Version (org.opensearch.Version)3 MetadataIndexUpgradeService (org.opensearch.cluster.metadata.MetadataIndexUpgradeService)3 Settings (org.opensearch.common.settings.Settings)3 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)3