|
| 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.indexlifecycle; |
| 21 | + |
| 22 | +import org.elasticsearch.client.TimedRequest; |
| 23 | +import org.elasticsearch.common.Strings; |
| 24 | +import org.elasticsearch.common.xcontent.ToXContentObject; |
| 25 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.Objects; |
| 29 | + |
| 30 | +public class PutLifecyclePolicyRequest extends TimedRequest implements ToXContentObject { |
| 31 | + |
| 32 | + private final LifecyclePolicy policy; |
| 33 | + |
| 34 | + public PutLifecyclePolicyRequest(LifecyclePolicy policy) { |
| 35 | + if (policy == null) { |
| 36 | + throw new IllegalArgumentException("policy definition cannot be null"); |
| 37 | + } |
| 38 | + if (Strings.isNullOrEmpty(policy.getName())) { |
| 39 | + throw new IllegalArgumentException("policy name must be present"); |
| 40 | + } |
| 41 | + this.policy = policy; |
| 42 | + } |
| 43 | + |
| 44 | + public String getName() { |
| 45 | + return policy.getName(); |
| 46 | + } |
| 47 | + |
| 48 | + public LifecyclePolicy getLifecyclePolicy() { |
| 49 | + return policy; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
| 54 | + builder.startObject(); |
| 55 | + builder.field("policy", policy); |
| 56 | + builder.endObject(); |
| 57 | + return builder; |
| 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 | + PutLifecyclePolicyRequest that = (PutLifecyclePolicyRequest) o; |
| 65 | + return Objects.equals(getLifecyclePolicy(), that.getLifecyclePolicy()); |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public int hashCode() { |
| 70 | + return Objects.hash(getLifecyclePolicy()); |
| 71 | + } |
| 72 | +} |
0 commit comments