Search in sources :

Example 6 with FileInfo

use of org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo in project crate by crate.

the class BlobStoreIndexShardSnapshots method toXContent.

/**
 * Writes index file for the shard in the following format.
 * <pre>
 * <code>
 * {
 *     "files": [{
 *         "name": "__3",
 *         "physical_name": "_0.si",
 *         "length": 310,
 *         "checksum": "1tpsg3p",
 *         "written_by": "5.1.0",
 *         "meta_hash": "P9dsFxNMdWNlb......"
 *     }, {
 *         "name": "__2",
 *         "physical_name": "segments_2",
 *         "length": 150,
 *         "checksum": "11qjpz6",
 *         "written_by": "5.1.0",
 *         "meta_hash": "P9dsFwhzZWdtZ......."
 *     }, {
 *         "name": "__1",
 *         "physical_name": "_0.cfe",
 *         "length": 363,
 *         "checksum": "er9r9g",
 *         "written_by": "5.1.0"
 *     }, {
 *         "name": "__0",
 *         "physical_name": "_0.cfs",
 *         "length": 3354,
 *         "checksum": "491liz",
 *         "written_by": "5.1.0"
 *     }, {
 *         "name": "__4",
 *         "physical_name": "segments_3",
 *         "length": 150,
 *         "checksum": "134567",
 *         "written_by": "5.1.0",
 *         "meta_hash": "P9dsFwhzZWdtZ......."
 *     }],
 *     "snapshots": {
 *         "snapshot_1": {
 *             "files": ["__0", "__1", "__2", "__3"]
 *         },
 *         "snapshot_2": {
 *             "files": ["__0", "__1", "__2", "__4"]
 *         }
 *     }
 * }
 * }
 * </code>
 * </pre>
 */
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    // First we list all blobs with their file infos:
    builder.startArray(Fields.FILES);
    for (Map.Entry<String, FileInfo> entry : files.entrySet()) {
        FileInfo.toXContent(entry.getValue(), builder);
    }
    builder.endArray();
    // Then we list all snapshots with list of all blobs that are used by the snapshot
    builder.startObject(Fields.SNAPSHOTS);
    for (SnapshotFiles snapshot : shardSnapshots) {
        builder.startObject(snapshot.snapshot());
        builder.startArray(Fields.FILES);
        for (FileInfo fileInfo : snapshot.indexFiles()) {
            builder.value(fileInfo.name());
        }
        builder.endArray();
        builder.endObject();
    }
    builder.endObject();
    return builder;
}
Also used : FileInfo(org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo) HashMap(java.util.HashMap) Map(java.util.Map) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Aggregations

HashMap (java.util.HashMap)6 FileInfo (org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo)6 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)2