|
| 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.ilm; |
| 20 | + |
| 21 | +import org.elasticsearch.common.ParseField; |
| 22 | +import org.elasticsearch.common.Strings; |
| 23 | +import org.elasticsearch.common.xcontent.ConstructingObjectParser; |
| 24 | +import org.elasticsearch.common.xcontent.ToXContentObject; |
| 25 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 26 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 27 | + |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.Objects; |
| 30 | + |
| 31 | +public class MigrateAction implements LifecycleAction, ToXContentObject { |
| 32 | + public static final String NAME = "migrate"; |
| 33 | + |
| 34 | + public static final ParseField ENABLED_FIELD = new ParseField("enabled"); |
| 35 | + |
| 36 | + private static final ConstructingObjectParser<MigrateAction, Void> PARSER = new ConstructingObjectParser<>(NAME, |
| 37 | + a -> new MigrateAction(a[0] == null ? true : (boolean) a[0])); |
| 38 | + |
| 39 | + static { |
| 40 | + PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), ENABLED_FIELD); |
| 41 | + } |
| 42 | + |
| 43 | + public static MigrateAction parse(XContentParser parser) { |
| 44 | + return PARSER.apply(parser, null); |
| 45 | + } |
| 46 | + |
| 47 | + private final boolean enabled; |
| 48 | + |
| 49 | + public MigrateAction() { |
| 50 | + this(true); |
| 51 | + } |
| 52 | + |
| 53 | + public MigrateAction(boolean enabled) { |
| 54 | + this.enabled = enabled; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
| 59 | + builder.startObject(); |
| 60 | + builder.field(ENABLED_FIELD.getPreferredName(), enabled); |
| 61 | + builder.endObject(); |
| 62 | + return builder; |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public String getName() { |
| 67 | + return NAME; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public int hashCode() { |
| 72 | + return Objects.hashCode(enabled); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public boolean equals(Object obj) { |
| 77 | + if (obj == null) { |
| 78 | + return false; |
| 79 | + } |
| 80 | + if (obj.getClass() != getClass()) { |
| 81 | + return false; |
| 82 | + } |
| 83 | + return true; |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public String toString() { |
| 88 | + return Strings.toString(this); |
| 89 | + } |
| 90 | +} |
0 commit comments