Search in sources :

Example 6 with MetaDataUpgrader

use of org.elasticsearch.plugins.MetaDataUpgrader in project elasticsearch by elastic.

the class GatewayMetaStateTests method testUpdateCustomMetaDataOnUpgrade.

public void testUpdateCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        customs.put(CustomMetaData1.TYPE, new CustomMetaData1("modified_data1"));
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNotNull(upgrade.custom(CustomMetaData1.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData1.TYPE)).getData(), equalTo("modified_data1"));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 7 with MetaDataUpgrader

use of org.elasticsearch.plugins.MetaDataUpgrader in project elasticsearch by elastic.

the class GatewayMetaStateTests method testIndexMetaDataUpgrade.

public void testIndexMetaDataUpgrade() throws Exception {
    MetaData metaData = randomMetaData();
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.emptyList());
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(true), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
    for (IndexMetaData indexMetaData : upgrade) {
        assertFalse(metaData.hasIndexMetaData(indexMetaData));
    }
}
Also used : MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 8 with MetaDataUpgrader

use of org.elasticsearch.plugins.MetaDataUpgrader in project elasticsearch by elastic.

the class GatewayMetaStateTests method testCustomMetaDataValidation.

public void testCustomMetaDataValidation() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        throw new IllegalStateException("custom meta data too old");
    }));
    try {
        GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), equalTo("custom meta data too old"));
    }
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 MetaData (org.elasticsearch.cluster.metadata.MetaData)8 MetaDataUpgrader (org.elasticsearch.plugins.MetaDataUpgrader)8 TestCustomMetaData (org.elasticsearch.test.TestCustomMetaData)8 Arrays (java.util.Arrays)5 Collections (java.util.Collections)5 Collections.emptySet (java.util.Collections.emptySet)5 EnumSet (java.util.EnumSet)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 Set (java.util.Set)5 Version (org.elasticsearch.Version)5 ClusterChangedEvent (org.elasticsearch.cluster.ClusterChangedEvent)5 ClusterState (org.elasticsearch.cluster.ClusterState)5 ESAllocationTestCase (org.elasticsearch.cluster.ESAllocationTestCase)5 MetaDataIndexUpgradeService (org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService)5 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)5 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)5 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)5 INITIALIZING (org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING)5