forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PutSnapshotLifecycleAction.java
130 lines (105 loc) · 4.15 KB
/
PutSnapshotLifecycleAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.core.snapshotlifecycle.action;
import org.elasticsearch.action.Action;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.master.AcknowledgedRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.snapshotlifecycle.SnapshotLifecyclePolicy;
import java.io.IOException;
import java.util.Objects;
public class PutSnapshotLifecycleAction extends Action<PutSnapshotLifecycleAction.Response> {
public static final PutSnapshotLifecycleAction INSTANCE = new PutSnapshotLifecycleAction();
public static final String NAME = "cluster:admin/ilm/snapshot/put";
protected PutSnapshotLifecycleAction() {
super(NAME);
}
@Override
public PutSnapshotLifecycleAction.Response newResponse() {
throw new UnsupportedOperationException();
}
@Override
public Writeable.Reader<PutSnapshotLifecycleAction.Response> getResponseReader() {
return Response::new;
}
public static class Request extends AcknowledgedRequest<Request> implements ToXContentObject {
private String lifecycleId;
private SnapshotLifecyclePolicy lifecycle;
public Request(String lifecycleId, SnapshotLifecyclePolicy lifecycle) {
this.lifecycleId = lifecycleId;
this.lifecycle = lifecycle;
}
public Request() { }
public String getLifecycleId() {
return this.lifecycleId;
}
public SnapshotLifecyclePolicy getLifecycle() {
return this.lifecycle;
}
public static Request parseRequest(String lifecycleId, XContentParser parser) {
return new Request(lifecycleId, SnapshotLifecyclePolicy.parse(parser, lifecycleId));
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
lifecycleId = in.readString();
lifecycle = new SnapshotLifecyclePolicy(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(lifecycleId);
lifecycle.writeTo(out);
}
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(lifecycleId, lifecycle);
builder.endObject();
return builder;
}
@Override
public int hashCode() {
return Objects.hash(lifecycleId, lifecycle);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj.getClass() != getClass()) {
return false;
}
Request other = (Request) obj;
return lifecycleId.equals(other.lifecycleId) &&
lifecycle.equals(other.lifecycle);
}
@Override
public String toString() {
return Strings.toString(this);
}
}
public static class Response extends AcknowledgedResponse implements ToXContentObject {
public Response() { }
public Response(boolean acknowledged) {
super(acknowledged);
}
public Response(StreamInput streamInput) throws IOException {
this(streamInput.readBoolean());
}
}
}