|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.client.ccr; |
| 21 | + |
| 22 | +import org.elasticsearch.ElasticsearchException; |
| 23 | +import org.elasticsearch.common.ParseField; |
| 24 | +import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
| 25 | + |
| 26 | +import java.util.AbstractMap; |
| 27 | +import java.util.List; |
| 28 | +import java.util.Map; |
| 29 | +import java.util.NavigableMap; |
| 30 | +import java.util.TreeMap; |
| 31 | +import java.util.stream.Collectors; |
| 32 | + |
| 33 | +public final class AutoFollowStats { |
| 34 | + |
| 35 | + static final ParseField NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED = new ParseField("number_of_successful_follow_indices"); |
| 36 | + static final ParseField NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED = new ParseField("number_of_failed_follow_indices"); |
| 37 | + static final ParseField NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS = |
| 38 | + new ParseField("number_of_failed_remote_cluster_state_requests"); |
| 39 | + static final ParseField RECENT_AUTO_FOLLOW_ERRORS = new ParseField("recent_auto_follow_errors"); |
| 40 | + static final ParseField LEADER_INDEX = new ParseField("leader_index"); |
| 41 | + static final ParseField AUTO_FOLLOW_EXCEPTION = new ParseField("auto_follow_exception"); |
| 42 | + |
| 43 | + @SuppressWarnings("unchecked") |
| 44 | + static final ConstructingObjectParser<AutoFollowStats, Void> STATS_PARSER = new ConstructingObjectParser<>("auto_follow_stats", |
| 45 | + args -> new AutoFollowStats( |
| 46 | + (Long) args[0], |
| 47 | + (Long) args[1], |
| 48 | + (Long) args[2], |
| 49 | + new TreeMap<>( |
| 50 | + ((List<Map.Entry<String, ElasticsearchException>>) args[3]) |
| 51 | + .stream() |
| 52 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) |
| 53 | + )); |
| 54 | + |
| 55 | + private static final ConstructingObjectParser<Map.Entry<String, ElasticsearchException>, Void> AUTO_FOLLOW_EXCEPTIONS_PARSER = |
| 56 | + new ConstructingObjectParser<>( |
| 57 | + "auto_follow_stats_errors", |
| 58 | + args -> new AbstractMap.SimpleEntry<>((String) args[0], (ElasticsearchException) args[1])); |
| 59 | + |
| 60 | + static { |
| 61 | + AUTO_FOLLOW_EXCEPTIONS_PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX); |
| 62 | + AUTO_FOLLOW_EXCEPTIONS_PARSER.declareObject( |
| 63 | + ConstructingObjectParser.constructorArg(), |
| 64 | + (p, c) -> ElasticsearchException.fromXContent(p), |
| 65 | + AUTO_FOLLOW_EXCEPTION); |
| 66 | + |
| 67 | + STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_INDICES_AUTO_FOLLOWED); |
| 68 | + STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_FAILED_REMOTE_CLUSTER_STATE_REQUESTS); |
| 69 | + STATS_PARSER.declareLong(ConstructingObjectParser.constructorArg(), NUMBER_OF_SUCCESSFUL_INDICES_AUTO_FOLLOWED); |
| 70 | + STATS_PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), AUTO_FOLLOW_EXCEPTIONS_PARSER, |
| 71 | + RECENT_AUTO_FOLLOW_ERRORS); |
| 72 | + } |
| 73 | + |
| 74 | + private final long numberOfFailedFollowIndices; |
| 75 | + private final long numberOfFailedRemoteClusterStateRequests; |
| 76 | + private final long numberOfSuccessfulFollowIndices; |
| 77 | + private final NavigableMap<String, ElasticsearchException> recentAutoFollowErrors; |
| 78 | + |
| 79 | + AutoFollowStats(long numberOfFailedFollowIndices, |
| 80 | + long numberOfFailedRemoteClusterStateRequests, |
| 81 | + long numberOfSuccessfulFollowIndices, |
| 82 | + NavigableMap<String, ElasticsearchException> recentAutoFollowErrors) { |
| 83 | + this.numberOfFailedFollowIndices = numberOfFailedFollowIndices; |
| 84 | + this.numberOfFailedRemoteClusterStateRequests = numberOfFailedRemoteClusterStateRequests; |
| 85 | + this.numberOfSuccessfulFollowIndices = numberOfSuccessfulFollowIndices; |
| 86 | + this.recentAutoFollowErrors = recentAutoFollowErrors; |
| 87 | + } |
| 88 | + |
| 89 | + public long getNumberOfFailedFollowIndices() { |
| 90 | + return numberOfFailedFollowIndices; |
| 91 | + } |
| 92 | + |
| 93 | + public long getNumberOfFailedRemoteClusterStateRequests() { |
| 94 | + return numberOfFailedRemoteClusterStateRequests; |
| 95 | + } |
| 96 | + |
| 97 | + public long getNumberOfSuccessfulFollowIndices() { |
| 98 | + return numberOfSuccessfulFollowIndices; |
| 99 | + } |
| 100 | + |
| 101 | + public NavigableMap<String, ElasticsearchException> getRecentAutoFollowErrors() { |
| 102 | + return recentAutoFollowErrors; |
| 103 | + } |
| 104 | + |
| 105 | +} |
0 commit comments