|
@@ -9,6 +9,7 @@ package org.elasticsearch.action.admin.cluster.allocation;
|
|
|
|
|
|
import org.elasticsearch.TransportVersion;
|
|
|
import org.elasticsearch.action.ActionResponse;
|
|
|
+import org.elasticsearch.cluster.ClusterInfo;
|
|
|
import org.elasticsearch.cluster.routing.AllocationId;
|
|
|
import org.elasticsearch.cluster.routing.ShardRoutingState;
|
|
|
import org.elasticsearch.cluster.routing.allocation.allocator.ClusterBalanceStats;
|
|
@@ -35,19 +36,23 @@ import static org.elasticsearch.common.xcontent.ChunkedToXContentHelper.singleCh
|
|
|
public class DesiredBalanceResponse extends ActionResponse implements ChunkedToXContentObject {
|
|
|
|
|
|
private static final TransportVersion CLUSTER_BALANCE_STATS_VERSION = TransportVersion.V_8_7_0;
|
|
|
+ private static final TransportVersion CLUSTER_INFO_VERSION = TransportVersion.V_8_8_0;
|
|
|
|
|
|
private final DesiredBalanceStats stats;
|
|
|
private final ClusterBalanceStats clusterBalanceStats;
|
|
|
private final Map<String, Map<Integer, DesiredShards>> routingTable;
|
|
|
+ private final ClusterInfo clusterInfo;
|
|
|
|
|
|
public DesiredBalanceResponse(
|
|
|
DesiredBalanceStats stats,
|
|
|
ClusterBalanceStats clusterBalanceStats,
|
|
|
- Map<String, Map<Integer, DesiredShards>> routingTable
|
|
|
+ Map<String, Map<Integer, DesiredShards>> routingTable,
|
|
|
+ ClusterInfo clusterInfo
|
|
|
) {
|
|
|
this.stats = stats;
|
|
|
this.clusterBalanceStats = clusterBalanceStats;
|
|
|
this.routingTable = routingTable;
|
|
|
+ this.clusterInfo = clusterInfo;
|
|
|
}
|
|
|
|
|
|
public static DesiredBalanceResponse from(StreamInput in) throws IOException {
|
|
@@ -56,7 +61,8 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
in.getTransportVersion().onOrAfter(CLUSTER_BALANCE_STATS_VERSION)
|
|
|
? ClusterBalanceStats.readFrom(in)
|
|
|
: ClusterBalanceStats.EMPTY,
|
|
|
- in.readImmutableMap(StreamInput::readString, v -> v.readImmutableMap(StreamInput::readVInt, DesiredShards::from))
|
|
|
+ in.readImmutableMap(StreamInput::readString, v -> v.readImmutableMap(StreamInput::readVInt, DesiredShards::from)),
|
|
|
+ in.getTransportVersion().onOrAfter(CLUSTER_INFO_VERSION) ? new ClusterInfo(in) : ClusterInfo.EMPTY
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -64,7 +70,7 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
stats.writeTo(out);
|
|
|
if (out.getTransportVersion().onOrAfter(CLUSTER_BALANCE_STATS_VERSION)) {
|
|
|
- clusterBalanceStats.writeTo(out);
|
|
|
+ out.writeWriteable(clusterBalanceStats);
|
|
|
}
|
|
|
out.writeMap(
|
|
|
routingTable,
|
|
@@ -75,6 +81,9 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
(desiredShardsOut, desiredShards) -> desiredShards.writeTo(desiredShardsOut)
|
|
|
)
|
|
|
);
|
|
|
+ if (out.getTransportVersion().onOrAfter(CLUSTER_INFO_VERSION)) {
|
|
|
+ out.writeWriteable(clusterInfo);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -87,7 +96,11 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
(builder, p) -> builder.startObject("routing_table")
|
|
|
),
|
|
|
routingTableToXContentChunked(),
|
|
|
- singleChunk((builder, p) -> builder.endObject(), (builder, p) -> builder.endObject())
|
|
|
+ singleChunk(
|
|
|
+ (builder, p) -> builder.endObject(),
|
|
|
+ (builder, p) -> builder.startObject("cluster_info").value(clusterInfo).endObject(),
|
|
|
+ (builder, p) -> builder.endObject()
|
|
|
+ )
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -114,18 +127,23 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
return routingTable;
|
|
|
}
|
|
|
|
|
|
+ public ClusterInfo getClusterInfo() {
|
|
|
+ return clusterInfo;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean equals(Object o) {
|
|
|
if (this == o) return true;
|
|
|
return o instanceof DesiredBalanceResponse that
|
|
|
&& Objects.equals(stats, that.stats)
|
|
|
&& Objects.equals(clusterBalanceStats, that.clusterBalanceStats)
|
|
|
- && Objects.equals(routingTable, that.routingTable);
|
|
|
+ && Objects.equals(routingTable, that.routingTable)
|
|
|
+ && Objects.equals(clusterInfo, that.clusterInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(stats, clusterBalanceStats, routingTable);
|
|
|
+ return Objects.hash(stats, clusterBalanceStats, routingTable, clusterInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -136,6 +154,8 @@ public class DesiredBalanceResponse extends ActionResponse implements ChunkedToX
|
|
|
+ clusterBalanceStats
|
|
|
+ ", routingTable="
|
|
|
+ routingTable
|
|
|
+ + ", clusterInfo="
|
|
|
+ + clusterInfo
|
|
|
+ "}";
|
|
|
}
|
|
|
|