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