org.elasticsearch.action.admin.indices.diskusage.AnalyzeIndexDiskUsageResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :distribution:archives:integ-test-zip
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
package org.elasticsearch.action.admin.indices.diskusage;
import org.elasticsearch.action.support.DefaultShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.xcontent.XContentBuilder;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
public final class AnalyzeIndexDiskUsageResponse extends BroadcastResponse {
private final Map stats;
AnalyzeIndexDiskUsageResponse(
int totalShards,
int successfulShards,
int failedShards,
List shardFailures,
Map stats
) {
super(totalShards, successfulShards, failedShards, shardFailures);
this.stats = stats;
}
AnalyzeIndexDiskUsageResponse(StreamInput in) throws IOException {
super(in);
stats = in.readMap(StreamInput::readString, IndexDiskUsageStats::new);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(stats, StreamOutput::writeString, (o, v) -> v.writeTo(o));
}
Map getStats() {
return stats;
}
@Override
protected void addCustomXContentFields(XContentBuilder builder, Params params) throws IOException {
final List> entries = stats.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.collect(Collectors.toList());
for (Map.Entry entry : entries) {
builder.startObject(entry.getKey());
entry.getValue().toXContent(builder, params);
builder.endObject();
}
}
}