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"));
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations