Search in sources :

Example 1 with MetaDataStateFormat

use of org.elasticsearch.gateway.MetaDataStateFormat 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

Path (java.nio.file.Path)1 Version (org.elasticsearch.Version)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 MetaDataStateFormat (org.elasticsearch.gateway.MetaDataStateFormat)1