|
@@ -6,6 +6,7 @@
|
|
|
package org.elasticsearch.xpack.core.ccr;
|
|
|
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.common.ParseField;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
@@ -17,6 +18,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.AbstractMap;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.NavigableMap;
|
|
@@ -33,6 +35,10 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
private static final ParseField RECENT_AUTO_FOLLOW_ERRORS = new ParseField("recent_auto_follow_errors");
|
|
|
private static final ParseField LEADER_INDEX = new ParseField("leader_index");
|
|
|
private static final ParseField AUTO_FOLLOW_EXCEPTION = new ParseField("auto_follow_exception");
|
|
|
+ private static final ParseField AUTO_FOLLOWED_CLUSTERS = new ParseField("auto_followed_clusters");
|
|
|
+ private static final ParseField CLUSTER_NAME = new ParseField("cluster_name");
|
|
|
+ private static final ParseField TIME_SINCE_LAST_CHECK_MILLIS = new ParseField("time_since_last_check_millis");
|
|
|
+ private static final ParseField LAST_SEEN_METADATA_VERSION = new ParseField("last_seen_metadata_version");
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>("auto_follow_stats",
|
|
@@ -43,26 +49,39 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
new TreeMap<>(
|
|
|
((List<Map.Entry<String, ElasticsearchException>>) args[3])
|
|
|
.stream()
|
|
|
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
|
|
|
- ));
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))),
|
|
|
+ new TreeMap<>(
|
|
|
+ ((List<Map.Entry<String, AutoFollowedCluster>>) args[4])
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))));
|
|
|
|
|
|
private static final ConstructingObjectParser<Map.Entry<String, ElasticsearchException>, Void> AUTO_FOLLOW_EXCEPTIONS_PARSER =
|
|
|
new ConstructingObjectParser<>(
|
|
|
"auto_follow_stats_errors",
|
|
|
args -> new AbstractMap.SimpleEntry<>((String) args[0], (ElasticsearchException) args[1]));
|
|
|
|
|
|
+ private static final ConstructingObjectParser<Map.Entry<String, AutoFollowedCluster>, Void> AUTO_FOLLOWED_CLUSTERS_PARSER =
|
|
|
+ new ConstructingObjectParser<>(
|
|
|
+ "auto_followed_clusters",
|
|
|
+ args -> new AbstractMap.SimpleEntry<>((String) args[0], new AutoFollowedCluster((Long) args[1], (Long) args[2])));
|
|
|
+
|
|
|
static {
|
|
|
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX);
|
|
|
AUTO_FOLLOW_EXCEPTIONS_PARSER.declareObject(
|
|
|
ConstructingObjectParser.constructorArg(),
|
|
|
(p, c) -> ElasticsearchException.fromXContent(p),
|
|
|
AUTO_FOLLOW_EXCEPTION);
|
|
|
+ AUTO_FOLLOWED_CLUSTERS_PARSER.declareString(ConstructingObjectParser.constructorArg(), CLUSTER_NAME);
|
|
|
+ AUTO_FOLLOWED_CLUSTERS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), TIME_SINCE_LAST_CHECK_MILLIS);
|
|
|
+ AUTO_FOLLOWED_CLUSTERS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), LAST_SEEN_METADATA_VERSION);
|
|
|
|
|
|
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED);
|
|
|
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS);
|
|
|
STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED);
|
|
|
STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOW_EXCEPTIONS_PARSER,
|
|
|
RECENT_AUTO_FOLLOW_ERRORS);
|
|
|
+ STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOWED_CLUSTERS_PARSER,
|
|
|
+ AUTO_FOLLOWED_CLUSTERS);
|
|
|
}
|
|
|
|
|
|
public static AutoFollowStats fromXContent(final XContentParser parser) {
|
|
@@ -73,24 +92,32 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
private final long numberOfFailedRemoteClusterStateRequests;
|
|
|
private final long numberOfSuccessfulFollowIndices;
|
|
|
private final NavigableMap<String, ElasticsearchException> recentAutoFollowErrors;
|
|
|
+ private final NavigableMap<String, AutoFollowedCluster> autoFollowedClusters;
|
|
|
|
|
|
public AutoFollowStats(
|
|
|
- long numberOfFailedFollowIndices,
|
|
|
- long numberOfFailedRemoteClusterStateRequests,
|
|
|
- long numberOfSuccessfulFollowIndices,
|
|
|
- NavigableMap<String, ElasticsearchException> recentAutoFollowErrors
|
|
|
+ long numberOfFailedFollowIndices,
|
|
|
+ long numberOfFailedRemoteClusterStateRequests,
|
|
|
+ long numberOfSuccessfulFollowIndices,
|
|
|
+ NavigableMap<String, ElasticsearchException> recentAutoFollowErrors,
|
|
|
+ NavigableMap<String, AutoFollowedCluster> autoFollowedClusters
|
|
|
) {
|
|
|
this.numberOfFailedFollowIndices = numberOfFailedFollowIndices;
|
|
|
this.numberOfFailedRemoteClusterStateRequests = numberOfFailedRemoteClusterStateRequests;
|
|
|
this.numberOfSuccessfulFollowIndices = numberOfSuccessfulFollowIndices;
|
|
|
this.recentAutoFollowErrors = recentAutoFollowErrors;
|
|
|
+ this.autoFollowedClusters = autoFollowedClusters;
|
|
|
}
|
|
|
|
|
|
public AutoFollowStats(StreamInput in) throws IOException {
|
|
|
numberOfFailedFollowIndices = in.readVLong();
|
|
|
numberOfFailedRemoteClusterStateRequests = in.readVLong();
|
|
|
numberOfSuccessfulFollowIndices = in.readVLong();
|
|
|
- recentAutoFollowErrors= new TreeMap<>(in.readMap(StreamInput::readString, StreamInput::readException));
|
|
|
+ recentAutoFollowErrors = new TreeMap<>(in.readMap(StreamInput::readString, StreamInput::readException));
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_6_6_0)) {
|
|
|
+ autoFollowedClusters = new TreeMap<>(in.readMap(StreamInput::readString, AutoFollowedCluster::new));
|
|
|
+ } else {
|
|
|
+ autoFollowedClusters = Collections.emptyNavigableMap();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -99,6 +126,9 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
out.writeVLong(numberOfFailedRemoteClusterStateRequests);
|
|
|
out.writeVLong(numberOfSuccessfulFollowIndices);
|
|
|
out.writeMap(recentAutoFollowErrors, StreamOutput::writeString, StreamOutput::writeException);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_6_6_0)) {
|
|
|
+ out.writeMap(autoFollowedClusters, StreamOutput::writeString, (out1, value) -> value.writeTo(out1));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public long getNumberOfFailedFollowIndices() {
|
|
@@ -117,6 +147,10 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
return recentAutoFollowErrors;
|
|
|
}
|
|
|
|
|
|
+ public NavigableMap<String, AutoFollowedCluster> getAutoFollowedClusters() {
|
|
|
+ return autoFollowedClusters;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.startObject();
|
|
@@ -148,6 +182,19 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
}
|
|
|
}
|
|
|
builder.endArray();
|
|
|
+ builder.startArray(AUTO_FOLLOWED_CLUSTERS.getPreferredName());
|
|
|
+ {
|
|
|
+ for (final Map.Entry<String, AutoFollowedCluster> entry : autoFollowedClusters.entrySet()) {
|
|
|
+ builder.startObject();
|
|
|
+ {
|
|
|
+ builder.field(CLUSTER_NAME.getPreferredName(), entry.getKey());
|
|
|
+ builder.field(TIME_SINCE_LAST_CHECK_MILLIS.getPreferredName(), entry.getValue().getTimeSinceLastCheckMillis());
|
|
|
+ builder.field(LAST_SEEN_METADATA_VERSION.getPreferredName(), entry.getValue().getLastSeenMetadataVersion());
|
|
|
+ }
|
|
|
+ builder.endObject();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ builder.endArray();
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
@@ -165,7 +212,8 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
* keys.
|
|
|
*/
|
|
|
recentAutoFollowErrors.keySet().equals(that.recentAutoFollowErrors.keySet()) &&
|
|
|
- getFetchExceptionMessages(this).equals(getFetchExceptionMessages(that));
|
|
|
+ getFetchExceptionMessages(this).equals(getFetchExceptionMessages(that)) &&
|
|
|
+ Objects.equals(autoFollowedClusters, that.autoFollowedClusters);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -179,7 +227,8 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
* messages. Note that we are relying on the fact that the auto follow exceptions are ordered by keys.
|
|
|
*/
|
|
|
recentAutoFollowErrors.keySet(),
|
|
|
- getFetchExceptionMessages(this)
|
|
|
+ getFetchExceptionMessages(this),
|
|
|
+ autoFollowedClusters
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -194,6 +243,58 @@ public class AutoFollowStats implements Writeable, ToXContentObject {
|
|
|
", numberOfFailedRemoteClusterStateRequests=" + numberOfFailedRemoteClusterStateRequests +
|
|
|
", numberOfSuccessfulFollowIndices=" + numberOfSuccessfulFollowIndices +
|
|
|
", recentAutoFollowErrors=" + recentAutoFollowErrors +
|
|
|
+ ", autoFollowedClusters=" + autoFollowedClusters +
|
|
|
'}';
|
|
|
}
|
|
|
+
|
|
|
+ public static class AutoFollowedCluster implements Writeable {
|
|
|
+
|
|
|
+ private final long timeSinceLastCheckMillis;
|
|
|
+ private final long lastSeenMetadataVersion;
|
|
|
+
|
|
|
+ public AutoFollowedCluster(long timeSinceLastCheckMillis, long lastSeenMetadataVersion) {
|
|
|
+ this.timeSinceLastCheckMillis = timeSinceLastCheckMillis;
|
|
|
+ this.lastSeenMetadataVersion = lastSeenMetadataVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ public AutoFollowedCluster(StreamInput in) throws IOException {
|
|
|
+ this(in.readZLong(), in.readVLong());
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getTimeSinceLastCheckMillis() {
|
|
|
+ return timeSinceLastCheckMillis;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getLastSeenMetadataVersion() {
|
|
|
+ return lastSeenMetadataVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void writeTo(StreamOutput out) throws IOException {
|
|
|
+ out.writeZLong(timeSinceLastCheckMillis);
|
|
|
+ out.writeVLong(lastSeenMetadataVersion);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean equals(Object o) {
|
|
|
+ if (this == o) return true;
|
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
+ AutoFollowedCluster that = (AutoFollowedCluster) o;
|
|
|
+ return timeSinceLastCheckMillis == that.timeSinceLastCheckMillis &&
|
|
|
+ lastSeenMetadataVersion == that.lastSeenMetadataVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int hashCode() {
|
|
|
+ return Objects.hash(timeSinceLastCheckMillis, lastSeenMetadataVersion);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "AutoFollowedCluster{" +
|
|
|
+ "timeSinceLastCheckMillis=" + timeSinceLastCheckMillis +
|
|
|
+ ", lastSeenMetadataVersion=" + lastSeenMetadataVersion +
|
|
|
+ '}';
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|