|
| 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 | +package org.elasticsearch.client.indices; |
| 20 | + |
| 21 | +import org.elasticsearch.client.core.BroadcastResponse; |
| 22 | +import org.elasticsearch.common.ParseField; |
| 23 | +import org.elasticsearch.common.collect.Tuple; |
| 24 | +import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
| 25 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 26 | + |
| 27 | +import java.util.HashMap; |
| 28 | +import java.util.HashSet; |
| 29 | +import java.util.List; |
| 30 | +import java.util.Map; |
| 31 | +import java.util.Set; |
| 32 | + |
| 33 | +import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; |
| 34 | + |
| 35 | +/** |
| 36 | + * The response object that will be returned when reloading analyzers |
| 37 | + */ |
| 38 | +public class ReloadAnalyzersResponse extends BroadcastResponse { |
| 39 | + |
| 40 | + private final Map<String, ReloadDetails> reloadDetails; |
| 41 | + |
| 42 | + ReloadAnalyzersResponse(final Shards shards, Map<String, ReloadDetails> reloadDetails) { |
| 43 | + super(shards); |
| 44 | + this.reloadDetails = reloadDetails; |
| 45 | + } |
| 46 | + |
| 47 | + @SuppressWarnings({ "unchecked" }) |
| 48 | + private static final ConstructingObjectParser<ReloadAnalyzersResponse, Void> PARSER = new ConstructingObjectParser<>("reload_analyzer", |
| 49 | + true, arg -> { |
| 50 | + Shards shards = (Shards) arg[0]; |
| 51 | + List<Tuple<String, ReloadDetails>> results = (List<Tuple<String, ReloadDetails>>) arg[1]; |
| 52 | + Map<String, ReloadDetails> reloadDetails = new HashMap<>(); |
| 53 | + for (Tuple<String, ReloadDetails> result : results) { |
| 54 | + reloadDetails.put(result.v1(), result.v2()); |
| 55 | + } |
| 56 | + return new ReloadAnalyzersResponse(shards, reloadDetails); |
| 57 | + }); |
| 58 | + |
| 59 | + @SuppressWarnings({ "unchecked" }) |
| 60 | + private static final ConstructingObjectParser<Tuple<String, ReloadDetails>, Void> ENTRY_PARSER = new ConstructingObjectParser<>( |
| 61 | + "reload_analyzer.entry", true, arg -> { |
| 62 | + String index = (String) arg[0]; |
| 63 | + Set<String> nodeIds = new HashSet<>((List<String>) arg[1]); |
| 64 | + Set<String> analyzers = new HashSet<>((List<String>) arg[2]); |
| 65 | + return new Tuple<>(index, new ReloadDetails(index, nodeIds, analyzers)); |
| 66 | + }); |
| 67 | + |
| 68 | + static { |
| 69 | + declareShardsField(PARSER); |
| 70 | + PARSER.declareObjectArray(constructorArg(), ENTRY_PARSER, new ParseField("reload_details")); |
| 71 | + ENTRY_PARSER.declareString(constructorArg(), new ParseField("index")); |
| 72 | + ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_node_ids")); |
| 73 | + ENTRY_PARSER.declareStringArray(constructorArg(), new ParseField("reloaded_analyzers")); |
| 74 | + } |
| 75 | + |
| 76 | + public static ReloadAnalyzersResponse fromXContent(XContentParser parser) { |
| 77 | + return PARSER.apply(parser, null); |
| 78 | + } |
| 79 | + |
| 80 | + public Map<String, ReloadDetails> getReloadedDetails() { |
| 81 | + return reloadDetails; |
| 82 | + } |
| 83 | + |
| 84 | + public static class ReloadDetails { |
| 85 | + |
| 86 | + private final String indexName; |
| 87 | + private final Set<String> reloadedIndicesNodes; |
| 88 | + private final Set<String> reloadedAnalyzers; |
| 89 | + |
| 90 | + public ReloadDetails(String name, Set<String> reloadedIndicesNodes, Set<String> reloadedAnalyzers) { |
| 91 | + this.indexName = name; |
| 92 | + this.reloadedIndicesNodes = reloadedIndicesNodes; |
| 93 | + this.reloadedAnalyzers = reloadedAnalyzers; |
| 94 | + } |
| 95 | + |
| 96 | + public String getIndexName() { |
| 97 | + return indexName; |
| 98 | + } |
| 99 | + |
| 100 | + public Set<String> getReloadedIndicesNodes() { |
| 101 | + return reloadedIndicesNodes; |
| 102 | + } |
| 103 | + |
| 104 | + public Set<String> getReloadedAnalyzers() { |
| 105 | + return reloadedAnalyzers; |
| 106 | + } |
| 107 | + } |
| 108 | +} |
0 commit comments