Skip to content

Commit 6281982

Browse files
authored
copy more actions to protocol.xpack (#32892)
this PR creates client-side instances of the following actions: - DeleteAction - ForceMergeAction - ReadOnlyAction - RolloverAction - ForceMergeAction AllocateAction was done separately
1 parent c9de707 commit 6281982

File tree

11 files changed

+694
-2
lines changed

11 files changed

+694
-2
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,23 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
456456
// ILM - Client - Lifecycle Actions
457457
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
458458
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction.NAME),
459-
org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction::parse)
460-
);
459+
org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction::parse),
460+
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
461+
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction.NAME),
462+
org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction::parse),
463+
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
464+
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction.NAME),
465+
org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction::parse),
466+
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
467+
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction.NAME),
468+
org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction::parse),
469+
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
470+
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction.NAME),
471+
org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction::parse),
472+
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
473+
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction.NAME),
474+
org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction::parse)
475+
);
461476
}
462477

463478
@Override
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.protocol.xpack.indexlifecycle;
20+
21+
import org.elasticsearch.common.Strings;
22+
import org.elasticsearch.common.xcontent.ObjectParser;
23+
import org.elasticsearch.common.xcontent.ToXContent;
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+
30+
public class DeleteAction extends LifecycleAction implements ToXContentObject {
31+
public static final String NAME = "delete";
32+
33+
private static final ObjectParser<DeleteAction, Void> PARSER = new ObjectParser<>(NAME, DeleteAction::new);
34+
35+
public static DeleteAction parse(XContentParser parser) {
36+
return PARSER.apply(parser, null);
37+
}
38+
39+
public DeleteAction() {
40+
}
41+
42+
@Override
43+
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
44+
builder.startObject();
45+
builder.endObject();
46+
return builder;
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
return 1;
52+
}
53+
54+
@Override
55+
public boolean equals(Object obj) {
56+
if (obj == null) {
57+
return false;
58+
}
59+
if (obj.getClass() != getClass()) {
60+
return false;
61+
}
62+
return true;
63+
}
64+
65+
@Override
66+
public String toString() {
67+
return Strings.toString(this);
68+
}
69+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.protocol.xpack.indexlifecycle;
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 ForceMergeAction extends LifecycleAction implements ToXContentObject {
32+
public static final String NAME = "forcemerge";
33+
private static final ParseField MAX_NUM_SEGMENTS_FIELD = new ParseField("max_num_segments");
34+
35+
private static final ConstructingObjectParser<ForceMergeAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
36+
false, a -> {
37+
int maxNumSegments = (int) a[0];
38+
return new ForceMergeAction(maxNumSegments);
39+
});
40+
41+
static {
42+
PARSER.declareInt(ConstructingObjectParser.constructorArg(), MAX_NUM_SEGMENTS_FIELD);
43+
}
44+
45+
private final int maxNumSegments;
46+
47+
public static ForceMergeAction parse(XContentParser parser) {
48+
return PARSER.apply(parser, null);
49+
}
50+
51+
public ForceMergeAction(int maxNumSegments) {
52+
if (maxNumSegments <= 0) {
53+
throw new IllegalArgumentException("[" + MAX_NUM_SEGMENTS_FIELD.getPreferredName()
54+
+ "] must be a positive integer");
55+
}
56+
this.maxNumSegments = maxNumSegments;
57+
}
58+
59+
public int getMaxNumSegments() {
60+
return maxNumSegments;
61+
}
62+
63+
@Override
64+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
65+
builder.startObject();
66+
builder.field(MAX_NUM_SEGMENTS_FIELD.getPreferredName(), maxNumSegments);
67+
builder.endObject();
68+
return builder;
69+
}
70+
71+
@Override
72+
public int hashCode() {
73+
return Objects.hash(maxNumSegments);
74+
}
75+
76+
@Override
77+
public boolean equals(Object obj) {
78+
if (obj == null) {
79+
return false;
80+
}
81+
if (obj.getClass() != getClass()) {
82+
return false;
83+
}
84+
ForceMergeAction other = (ForceMergeAction) obj;
85+
return Objects.equals(maxNumSegments, other.maxNumSegments);
86+
}
87+
88+
@Override
89+
public String toString() {
90+
return Strings.toString(this);
91+
}
92+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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.protocol.xpack.indexlifecycle;
20+
21+
import org.elasticsearch.common.Strings;
22+
import org.elasticsearch.common.xcontent.ObjectParser;
23+
import org.elasticsearch.common.xcontent.ToXContentObject;
24+
import org.elasticsearch.common.xcontent.XContentBuilder;
25+
import org.elasticsearch.common.xcontent.XContentParser;
26+
27+
import java.io.IOException;
28+
29+
public class ReadOnlyAction extends LifecycleAction implements ToXContentObject {
30+
public static final String NAME = "readonly";
31+
32+
private static final ObjectParser<ReadOnlyAction, Void> PARSER = new ObjectParser<>(NAME, false, ReadOnlyAction::new);
33+
34+
public static ReadOnlyAction parse(XContentParser parser) {
35+
return PARSER.apply(parser, null);
36+
}
37+
38+
public ReadOnlyAction() {
39+
}
40+
41+
@Override
42+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
43+
builder.startObject();
44+
builder.endObject();
45+
return builder;
46+
}
47+
48+
@Override
49+
public int hashCode() {
50+
return ReadOnlyAction.class.hashCode();
51+
}
52+
53+
@Override
54+
public boolean equals(Object obj) {
55+
if (obj == null) {
56+
return false;
57+
}
58+
if (obj.getClass() != getClass()) {
59+
return false;
60+
}
61+
return true;
62+
}
63+
64+
@Override
65+
public String toString() {
66+
return Strings.toString(this);
67+
}
68+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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.protocol.xpack.indexlifecycle;
20+
21+
import org.elasticsearch.common.ParseField;
22+
import org.elasticsearch.common.Strings;
23+
import org.elasticsearch.common.unit.ByteSizeValue;
24+
import org.elasticsearch.common.unit.TimeValue;
25+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
26+
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
27+
import org.elasticsearch.common.xcontent.ToXContentObject;
28+
import org.elasticsearch.common.xcontent.XContentBuilder;
29+
import org.elasticsearch.common.xcontent.XContentParser;
30+
31+
import java.io.IOException;
32+
import java.util.Objects;
33+
34+
35+
public class RolloverAction extends LifecycleAction implements ToXContentObject {
36+
public static final String NAME = "rollover";
37+
private static final ParseField MAX_SIZE_FIELD = new ParseField("max_size");
38+
private static final ParseField MAX_DOCS_FIELD = new ParseField("max_docs");
39+
private static final ParseField MAX_AGE_FIELD = new ParseField("max_age");
40+
41+
private static final ConstructingObjectParser<RolloverAction, Void> PARSER = new ConstructingObjectParser<>(NAME,
42+
a -> new RolloverAction((ByteSizeValue) a[0], (TimeValue) a[1], (Long) a[2]));
43+
static {
44+
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
45+
(p, c) -> ByteSizeValue.parseBytesSizeValue(p.text(), MAX_SIZE_FIELD.getPreferredName()), MAX_SIZE_FIELD, ValueType.VALUE);
46+
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(),
47+
(p, c) -> TimeValue.parseTimeValue(p.text(), MAX_AGE_FIELD.getPreferredName()), MAX_AGE_FIELD, ValueType.VALUE);
48+
PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), MAX_DOCS_FIELD);
49+
}
50+
51+
private final ByteSizeValue maxSize;
52+
private final Long maxDocs;
53+
private final TimeValue maxAge;
54+
55+
public static RolloverAction parse(XContentParser parser) {
56+
return PARSER.apply(parser, null);
57+
}
58+
59+
public RolloverAction(ByteSizeValue maxSize, TimeValue maxAge, Long maxDocs) {
60+
if (maxSize == null && maxAge == null && maxDocs == null) {
61+
throw new IllegalArgumentException("At least one rollover condition must be set.");
62+
}
63+
this.maxSize = maxSize;
64+
this.maxAge = maxAge;
65+
this.maxDocs = maxDocs;
66+
}
67+
public ByteSizeValue getMaxSize() {
68+
return maxSize;
69+
}
70+
71+
public TimeValue getMaxAge() {
72+
return maxAge;
73+
}
74+
75+
public Long getMaxDocs() {
76+
return maxDocs;
77+
}
78+
79+
@Override
80+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
81+
builder.startObject();
82+
if (maxSize != null) {
83+
builder.field(MAX_SIZE_FIELD.getPreferredName(), maxSize.getStringRep());
84+
}
85+
if (maxAge != null) {
86+
builder.field(MAX_AGE_FIELD.getPreferredName(), maxAge.getStringRep());
87+
}
88+
if (maxDocs != null) {
89+
builder.field(MAX_DOCS_FIELD.getPreferredName(), maxDocs);
90+
}
91+
builder.endObject();
92+
return builder;
93+
}
94+
95+
@Override
96+
public int hashCode() {
97+
return Objects.hash(maxSize, maxAge, maxDocs);
98+
}
99+
100+
@Override
101+
public boolean equals(Object obj) {
102+
if (obj == null) {
103+
return false;
104+
}
105+
if (obj.getClass() != getClass()) {
106+
return false;
107+
}
108+
RolloverAction other = (RolloverAction) obj;
109+
return Objects.equals(maxSize, other.maxSize) &&
110+
Objects.equals(maxAge, other.maxAge) &&
111+
Objects.equals(maxDocs, other.maxDocs);
112+
}
113+
114+
@Override
115+
public String toString() {
116+
return Strings.toString(this);
117+
}
118+
}

0 commit comments

Comments
 (0)