Search in sources :

Example 1 with MetadataUpgrader

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

the class GatewayMetaStateTests method testRemoveCustomMetaDataOnUpgrade.

public void testRemoveCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        customs.remove(CustomMetaData1.TYPE);
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNull(upgrade.custom(CustomMetaData1.TYPE));
}
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 2 with MetadataUpgrader

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

the class GatewayMetaStateTests method testAddCustomMetaDataOnUpgrade.

public void testAddCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData();
    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 3 with MetadataUpgrader

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

the class GatewayMetaStateTests method testNoMetaDataUpgrade.

public void testNoMetaDataUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.emptyList());
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade == metaData);
    assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
    for (IndexMetaData indexMetaData : upgrade) {
        assertTrue(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 4 with MetadataUpgrader

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

the class GatewayMetaStateTests method testCustomMetaDataNoChange.

public void testCustomMetaDataNoChange() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(HashMap::new));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade == metaData);
    assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
    for (IndexMetaData indexMetaData : upgrade) {
        assertTrue(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 5 with MetadataUpgrader

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

the class GatewayMetaStateTests method testMultipleCustomMetaDataUpgrade.

public void testMultipleCustomMetaDataUpgrade() throws Exception {
    final MetaData metaData;
    switch(randomIntBetween(0, 2)) {
        case 0:
            metaData = randomMetaData(new CustomMetaData1("data1"), new CustomMetaData2("data2"));
            break;
        case 1:
            metaData = randomMetaData(randomBoolean() ? new CustomMetaData1("data1") : new CustomMetaData2("data2"));
            break;
        case 2:
            metaData = randomMetaData();
            break;
        default:
            throw new IllegalStateException("should never happen");
    }
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Arrays.asList(customs -> {
        customs.put(CustomMetaData1.TYPE, new CustomMetaData1("modified_data1"));
        return customs;
    }, customs -> {
        customs.put(CustomMetaData2.TYPE, new CustomMetaData1("modified_data2"));
        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"));
    assertNotNull(upgrade.custom(CustomMetaData2.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData2.TYPE)).getData(), equalTo("modified_data2"));
    for (IndexMetaData indexMetaData : upgrade) {
        assertTrue(metaData.hasIndexMetaData(indexMetaData));
    }
}
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) 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