Search in sources :

Example 46 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class MetaStateService method loadFullState.

/**
     * Loads the full state, which includes both the global state and all the indices
     * meta state.
     */
MetaData loadFullState() throws Exception {
    MetaData globalMetaData = loadGlobalState();
    MetaData.Builder metaDataBuilder;
    if (globalMetaData != null) {
        metaDataBuilder = MetaData.builder(globalMetaData);
    } else {
        metaDataBuilder = MetaData.builder();
    }
    for (String indexFolderName : nodeEnv.availableIndexFolders()) {
        IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, namedXContentRegistry, nodeEnv.resolveIndexFolder(indexFolderName));
        if (indexMetaData != null) {
            metaDataBuilder.put(indexMetaData, false);
        } else {
            logger.debug("[{}] failed to find metadata for existing index location", indexFolderName);
        }
    }
    return metaDataBuilder.build();
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 47 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class RestTemplatesAction method buildTable.

private Table buildTable(RestRequest request, ClusterStateResponse clusterStateResponse, String patternString) {
    Table table = getTableWithHeader(request);
    MetaData metadata = clusterStateResponse.getState().metaData();
    for (ObjectObjectCursor<String, IndexTemplateMetaData> entry : metadata.templates()) {
        IndexTemplateMetaData indexData = entry.value;
        if (patternString == null || Regex.simpleMatch(patternString, indexData.name())) {
            table.startRow();
            table.addCell(indexData.name());
            table.addCell("[" + String.join(", ", indexData.patterns()) + "]");
            table.addCell(indexData.getOrder());
            table.addCell(indexData.getVersion());
            table.endRow();
        }
    }
    return table;
}
Also used : Table(org.elasticsearch.common.Table) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData)

Example 48 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class TransportShrinkActionTests method createClusterState.

private ClusterState createClusterState(String name, int numShards, int numReplicas, Settings settings) {
    MetaData.Builder metaBuilder = MetaData.builder();
    IndexMetaData indexMetaData = IndexMetaData.builder(name).settings(settings(Version.CURRENT).put(settings)).numberOfShards(numShards).numberOfReplicas(numReplicas).build();
    metaBuilder.put(indexMetaData, false);
    MetaData metaData = metaBuilder.build();
    RoutingTable.Builder routingTableBuilder = RoutingTable.builder();
    routingTableBuilder.addAsNew(metaData.index(name));
    RoutingTable routingTable = routingTableBuilder.build();
    ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).blocks(ClusterBlocks.builder().addBlocks(indexMetaData)).build();
    return clusterState;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 49 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class ClusterStateDiffIT method randomMetaDataChanges.

/**
     * Makes random metadata changes
     */
private ClusterState.Builder randomMetaDataChanges(ClusterState clusterState) {
    MetaData metaData = clusterState.metaData();
    int changesCount = randomIntBetween(1, 10);
    for (int i = 0; i < changesCount; i++) {
        switch(randomInt(3)) {
            case 0:
                metaData = randomMetaDataSettings(metaData);
                break;
            case 1:
                metaData = randomIndices(metaData);
                break;
            case 2:
                metaData = randomTemplates(metaData);
                break;
            case 3:
                metaData = randomMetaDataCustoms(metaData);
                break;
            default:
                throw new IllegalArgumentException("Shouldn't be here");
        }
    }
    return ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).version(metaData.version() + 1).build());
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData)

Example 50 with MetaData

use of org.elasticsearch.cluster.metadata.MetaData in project elasticsearch by elastic.

the class OldIndexBackwardsCompatibilityIT method testOldClusterStates.

public void testOldClusterStates() throws Exception {
    // dangling indices do not load the global state, only the per-index states
    // so we make sure we can read them separately
    MetaDataStateFormat<MetaData> globalFormat = new MetaDataStateFormat<MetaData>(XContentType.JSON, "global-") {

        @Override
        public void toXContent(XContentBuilder builder, MetaData state) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public MetaData fromXContent(XContentParser parser) throws IOException {
            return MetaData.Builder.fromXContent(parser);
        }
    };
    MetaDataStateFormat<IndexMetaData> indexFormat = new MetaDataStateFormat<IndexMetaData>(XContentType.JSON, "state-") {

        @Override
        public void toXContent(XContentBuilder builder, IndexMetaData state) throws IOException {
            throw new UnsupportedOperationException();
        }

        @Override
        public IndexMetaData fromXContent(XContentParser parser) throws IOException {
            return IndexMetaData.Builder.fromXContent(parser);
        }
    };
    Collections.shuffle(indexes, random());
    for (String indexFile : indexes) {
        String indexName = indexFile.replace(".zip", "").toLowerCase(Locale.ROOT).replace("unsupported-", "index-");
        Path nodeDir = getNodeDir(indexFile);
        logger.info("Parsing cluster state files from index [{}]", indexName);
        final MetaData metaData = globalFormat.loadLatestState(logger, xContentRegistry(), nodeDir);
        assertNotNull(metaData);
        final Version version = Version.fromString(indexName.substring("index-".length()));
        final Path dataDir;
        if (version.before(Version.V_5_0_0_alpha1)) {
            dataDir = nodeDir.getParent().getParent();
        } else {
            dataDir = nodeDir.getParent();
        }
        final Path indexDir = getIndexDir(logger, indexName, indexFile, dataDir);
        assertNotNull(indexFormat.loadLatestState(logger, xContentRegistry(), indexDir));
    }
}
Also used : MetaDataStateFormat(org.elasticsearch.gateway.MetaDataStateFormat) Path(java.nio.file.Path) Version(org.elasticsearch.Version) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

MetaData (org.elasticsearch.cluster.metadata.MetaData)244 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)223 ClusterState (org.elasticsearch.cluster.ClusterState)179 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)138 RoutingNodes (org.elasticsearch.cluster.routing.RoutingNodes)52 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)48 Settings (org.elasticsearch.common.settings.Settings)43 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)32 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)30 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)27 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)26 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)26 Index (org.elasticsearch.index.Index)25 Matchers.containsString (org.hamcrest.Matchers.containsString)23 IndexRoutingTable (org.elasticsearch.cluster.routing.IndexRoutingTable)21 HashMap (java.util.HashMap)19 HashSet (java.util.HashSet)18 ShardId (org.elasticsearch.index.shard.ShardId)17 TestGatewayAllocator (org.elasticsearch.test.gateway.TestGatewayAllocator)17 ArrayList (java.util.ArrayList)15