|
| 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.common.ParseField; |
| 23 | +import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
| 24 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 25 | + |
| 26 | +import java.util.List; |
| 27 | +import java.util.Objects; |
| 28 | + |
| 29 | +public final class FollowInfoResponse { |
| 30 | + |
| 31 | + static final ParseField FOLLOWER_INDICES_FIELD = new ParseField("follower_indices"); |
| 32 | + |
| 33 | + private static final ConstructingObjectParser<FollowInfoResponse, Void> PARSER = new ConstructingObjectParser<>( |
| 34 | + "indices", |
| 35 | + true, |
| 36 | + args -> { |
| 37 | + @SuppressWarnings("unchecked") |
| 38 | + List<FollowerInfo> infos = (List<FollowerInfo>) args[0]; |
| 39 | + return new FollowInfoResponse(infos); |
| 40 | + }); |
| 41 | + |
| 42 | + static { |
| 43 | + PARSER.declareObjectArray(ConstructingObjectParser.constructorArg(), FollowerInfo.PARSER, FOLLOWER_INDICES_FIELD); |
| 44 | + } |
| 45 | + |
| 46 | + public static FollowInfoResponse fromXContent(XContentParser parser) { |
| 47 | + return PARSER.apply(parser, null); |
| 48 | + } |
| 49 | + |
| 50 | + private final List<FollowerInfo> infos; |
| 51 | + |
| 52 | + FollowInfoResponse(List<FollowerInfo> infos) { |
| 53 | + this.infos = infos; |
| 54 | + } |
| 55 | + |
| 56 | + public List<FollowerInfo> getInfos() { |
| 57 | + return infos; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public boolean equals(Object o) { |
| 62 | + if (this == o) return true; |
| 63 | + if (o == null || getClass() != o.getClass()) return false; |
| 64 | + FollowInfoResponse that = (FollowInfoResponse) o; |
| 65 | + return infos.equals(that.infos); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public int hashCode() { |
| 70 | + return Objects.hash(infos); |
| 71 | + } |
| 72 | + |
| 73 | + public static final class FollowerInfo { |
| 74 | + |
| 75 | + static final ParseField FOLLOWER_INDEX_FIELD = new ParseField("follower_index"); |
| 76 | + static final ParseField REMOTE_CLUSTER_FIELD = new ParseField("remote_cluster"); |
| 77 | + static final ParseField LEADER_INDEX_FIELD = new ParseField("leader_index"); |
| 78 | + static final ParseField STATUS_FIELD = new ParseField("status"); |
| 79 | + static final ParseField PARAMETERS_FIELD = new ParseField("parameters"); |
| 80 | + |
| 81 | + private static final ConstructingObjectParser<FollowerInfo, Void> PARSER = new ConstructingObjectParser<>( |
| 82 | + "follower_info", |
| 83 | + true, |
| 84 | + args -> { |
| 85 | + return new FollowerInfo((String) args[0], (String) args[1], (String) args[2], |
| 86 | + Status.fromString((String) args[3]), (FollowConfig) args[4]); |
| 87 | + }); |
| 88 | + |
| 89 | + static { |
| 90 | + PARSER.declareString(ConstructingObjectParser.constructorArg(), FOLLOWER_INDEX_FIELD); |
| 91 | + PARSER.declareString(ConstructingObjectParser.constructorArg(), REMOTE_CLUSTER_FIELD); |
| 92 | + PARSER.declareString(ConstructingObjectParser.constructorArg(), LEADER_INDEX_FIELD); |
| 93 | + PARSER.declareString(ConstructingObjectParser.constructorArg(), STATUS_FIELD); |
| 94 | + PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), |
| 95 | + (p, c) -> FollowConfig.fromXContent(p), PARAMETERS_FIELD); |
| 96 | + } |
| 97 | + |
| 98 | + private final String followerIndex; |
| 99 | + private final String remoteCluster; |
| 100 | + private final String leaderIndex; |
| 101 | + private final Status status; |
| 102 | + private final FollowConfig parameters; |
| 103 | + |
| 104 | + FollowerInfo(String followerIndex, String remoteCluster, String leaderIndex, Status status, |
| 105 | + FollowConfig parameters) { |
| 106 | + this.followerIndex = followerIndex; |
| 107 | + this.remoteCluster = remoteCluster; |
| 108 | + this.leaderIndex = leaderIndex; |
| 109 | + this.status = status; |
| 110 | + this.parameters = parameters; |
| 111 | + } |
| 112 | + |
| 113 | + public String getFollowerIndex() { |
| 114 | + return followerIndex; |
| 115 | + } |
| 116 | + |
| 117 | + public String getRemoteCluster() { |
| 118 | + return remoteCluster; |
| 119 | + } |
| 120 | + |
| 121 | + public String getLeaderIndex() { |
| 122 | + return leaderIndex; |
| 123 | + } |
| 124 | + |
| 125 | + public Status getStatus() { |
| 126 | + return status; |
| 127 | + } |
| 128 | + |
| 129 | + public FollowConfig getParameters() { |
| 130 | + return parameters; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public boolean equals(Object o) { |
| 135 | + if (this == o) return true; |
| 136 | + if (o == null || getClass() != o.getClass()) return false; |
| 137 | + FollowerInfo that = (FollowerInfo) o; |
| 138 | + return Objects.equals(followerIndex, that.followerIndex) && |
| 139 | + Objects.equals(remoteCluster, that.remoteCluster) && |
| 140 | + Objects.equals(leaderIndex, that.leaderIndex) && |
| 141 | + status == that.status && |
| 142 | + Objects.equals(parameters, that.parameters); |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public int hashCode() { |
| 147 | + return Objects.hash(followerIndex, remoteCluster, leaderIndex, status, parameters); |
| 148 | + } |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + public enum Status { |
| 153 | + |
| 154 | + ACTIVE("active"), |
| 155 | + PAUSED("paused"); |
| 156 | + |
| 157 | + private final String name; |
| 158 | + |
| 159 | + Status(String name) { |
| 160 | + this.name = name; |
| 161 | + } |
| 162 | + |
| 163 | + public String getName() { |
| 164 | + return name; |
| 165 | + } |
| 166 | + |
| 167 | + public static Status fromString(String value) { |
| 168 | + switch (value) { |
| 169 | + case "active": |
| 170 | + return Status.ACTIVE; |
| 171 | + case "paused": |
| 172 | + return Status.PAUSED; |
| 173 | + default: |
| 174 | + throw new IllegalArgumentException("unexpected status value [" + value + "]"); |
| 175 | + } |
| 176 | + } |
| 177 | + } |
| 178 | +} |
0 commit comments