Skip to content

Commit 650f12a

Browse files
committed
Duplicate Protocol classes into Core
This is needed as with recent changes to master (see #32952), protocol is no longer accessible from core, so these classes need to be duplicated in both places.
1 parent 191bd7c commit 650f12a

39 files changed

+1390
-47
lines changed

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,29 @@ public List<NamedXContentRegistry.Entry> getNamedXContent() {
439439
new NamedXContentRegistry.Entry(Task.Status.class, new ParseField(RollupJobStatus.NAME),
440440
RollupJobStatus::fromXContent),
441441
new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(RollupJobStatus.NAME),
442-
RollupJobStatus::fromXContent),
442+
RollupJobStatus::fromXContent)
443443
// ILM
444-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
445-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction.NAME),
446-
org.elasticsearch.protocol.xpack.indexlifecycle.AllocateAction::parse),
447-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
448-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction.NAME),
449-
org.elasticsearch.protocol.xpack.indexlifecycle.DeleteAction::parse),
450-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
451-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction.NAME),
452-
org.elasticsearch.protocol.xpack.indexlifecycle.ForceMergeAction::parse),
453-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
454-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction.NAME),
455-
org.elasticsearch.protocol.xpack.indexlifecycle.ReadOnlyAction::parse),
456-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
457-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction.NAME),
458-
org.elasticsearch.protocol.xpack.indexlifecycle.RolloverAction::parse),
459-
new NamedXContentRegistry.Entry(org.elasticsearch.protocol.xpack.indexlifecycle.LifecycleAction.class,
460-
new ParseField(org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction.NAME),
461-
org.elasticsearch.protocol.xpack.indexlifecycle.ShrinkAction::parse)
444+
// TODO NORELEASE: These lines may not be necessary, and they cause errors if present
445+
// as they are duplicated in IndexLifecycle.
446+
// Leaving this for now in case they are necessary as we move forward with the HLRC.
447+
// new NamedXContentRegistry.Entry(LifecycleAction.class,
448+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.AllocateAction.NAME),
449+
// org.elasticsearch.xpack.core.indexlifecycle.AllocateAction::parse),
450+
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
451+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.DeleteAction.NAME),
452+
// org.elasticsearch.xpack.core.indexlifecycle.DeleteAction::parse),
453+
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
454+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction.NAME),
455+
// org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction::parse),
456+
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
457+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction.NAME),
458+
// org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction::parse),
459+
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
460+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.RolloverAction.NAME),
461+
// org.elasticsearch.xpack.core.indexlifecycle.RolloverAction::parse),
462+
// new NamedXContentRegistry.Entry(org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction.class,
463+
// new ParseField(org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction.NAME),
464+
// org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction::parse)
462465
);
463466
}
464467

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.core.indexlifecycle;
8+
9+
import org.elasticsearch.action.ActionRequestValidationException;
10+
import org.elasticsearch.action.support.master.info.ClusterInfoRequest;
11+
import org.elasticsearch.common.io.stream.StreamInput;
12+
13+
import java.io.IOException;
14+
import java.util.Arrays;
15+
import java.util.Objects;
16+
17+
/**
18+
* The request object used by the Explain Lifecycle API.
19+
*
20+
* Multiple indices may be queried in the same request using the
21+
* {@link #indices(String...)} method
22+
*/
23+
public class ExplainLifecycleRequest extends ClusterInfoRequest<ExplainLifecycleRequest> {
24+
25+
public ExplainLifecycleRequest() {
26+
super();
27+
}
28+
29+
public ExplainLifecycleRequest(StreamInput in) throws IOException {
30+
super(in);
31+
}
32+
33+
@Override
34+
public ActionRequestValidationException validate() {
35+
return null;
36+
}
37+
38+
@Override
39+
public int hashCode() {
40+
return Objects.hash(Arrays.hashCode(indices()), indicesOptions());
41+
}
42+
43+
@Override
44+
public boolean equals(Object obj) {
45+
if (obj == null) {
46+
return false;
47+
}
48+
if (obj.getClass() != getClass()) {
49+
return false;
50+
}
51+
ExplainLifecycleRequest other = (ExplainLifecycleRequest) obj;
52+
return Objects.deepEquals(indices(), other.indices()) &&
53+
Objects.equals(indicesOptions(), other.indicesOptions());
54+
}
55+
56+
@Override
57+
public String toString() {
58+
return "ExplainLifecycleRequest [indices()=" + Arrays.toString(indices()) + ", indicesOptions()=" + indicesOptions() + "]";
59+
}
60+
61+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.core.indexlifecycle;
8+
9+
import org.elasticsearch.action.ActionResponse;
10+
import org.elasticsearch.common.ParseField;
11+
import org.elasticsearch.common.Strings;
12+
import org.elasticsearch.common.io.stream.StreamInput;
13+
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
15+
import org.elasticsearch.common.xcontent.ToXContentObject;
16+
import org.elasticsearch.common.xcontent.XContentBuilder;
17+
import org.elasticsearch.common.xcontent.XContentParser;
18+
19+
import java.io.IOException;
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
import java.util.Objects;
24+
import java.util.function.Function;
25+
import java.util.stream.Collectors;
26+
27+
/**
28+
* The response object returned by the Explain Lifecycle API.
29+
*
30+
* Since the API can be run over multiple indices the response provides a map of
31+
* index to the explanation of the lifecycle status for that index.
32+
*/
33+
public class ExplainLifecycleResponse extends ActionResponse implements ToXContentObject {
34+
35+
public static final ParseField INDICES_FIELD = new ParseField("indices");
36+
37+
private Map<String, IndexLifecycleExplainResponse> indexResponses;
38+
39+
@SuppressWarnings("unchecked")
40+
private static final ConstructingObjectParser<ExplainLifecycleResponse, Void> PARSER = new ConstructingObjectParser<>(
41+
"explain_lifecycle_response", a -> new ExplainLifecycleResponse(((List<IndexLifecycleExplainResponse>) a[0]).stream()
42+
.collect(Collectors.toMap(IndexLifecycleExplainResponse::getIndex, Function.identity()))));
43+
static {
44+
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> IndexLifecycleExplainResponse.PARSER.apply(p, c),
45+
INDICES_FIELD);
46+
}
47+
48+
public static ExplainLifecycleResponse fromXContent(XContentParser parser) {
49+
return PARSER.apply(parser, null);
50+
}
51+
52+
public ExplainLifecycleResponse() {
53+
}
54+
55+
public ExplainLifecycleResponse(Map<String, IndexLifecycleExplainResponse> indexResponses) {
56+
this.indexResponses = indexResponses;
57+
}
58+
59+
/**
60+
* @return a map of the responses from each requested index. The maps key is
61+
* the index name and the value is the
62+
* {@link IndexLifecycleExplainResponse} describing the current
63+
* lifecycle status of that index
64+
*/
65+
public Map<String, IndexLifecycleExplainResponse> getIndexResponses() {
66+
return indexResponses;
67+
}
68+
69+
@Override
70+
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
71+
builder.startObject();
72+
builder.startObject(INDICES_FIELD.getPreferredName());
73+
for (IndexLifecycleExplainResponse indexResponse : indexResponses.values()) {
74+
builder.field(indexResponse.getIndex(), indexResponse);
75+
}
76+
builder.endObject();
77+
builder.endObject();
78+
return builder;
79+
}
80+
81+
@Override
82+
public void readFrom(StreamInput in) throws IOException {
83+
int size = in.readVInt();
84+
Map<String, IndexLifecycleExplainResponse> indexResponses = new HashMap<>(size);
85+
for (int i = 0; i < size; i++) {
86+
IndexLifecycleExplainResponse indexResponse = new IndexLifecycleExplainResponse(in);
87+
indexResponses.put(indexResponse.getIndex(), indexResponse);
88+
}
89+
this.indexResponses = indexResponses;
90+
}
91+
92+
@Override
93+
public void writeTo(StreamOutput out) throws IOException {
94+
out.writeVInt(indexResponses.size());
95+
for (IndexLifecycleExplainResponse e : indexResponses.values()) {
96+
e.writeTo(out);
97+
}
98+
}
99+
100+
@Override
101+
public int hashCode() {
102+
return Objects.hash(indexResponses);
103+
}
104+
105+
@Override
106+
public boolean equals(Object obj) {
107+
if (obj == null) {
108+
return false;
109+
}
110+
if (obj.getClass() != getClass()) {
111+
return false;
112+
}
113+
ExplainLifecycleResponse other = (ExplainLifecycleResponse) obj;
114+
return Objects.equals(indexResponses, other.indexResponses);
115+
}
116+
117+
@Override
118+
public String toString() {
119+
return Strings.toString(this, true, true);
120+
}
121+
122+
}

0 commit comments

Comments
 (0)