Skip to content

Commit 7a19e26

Browse files
committed
add phase execution info to ILM Explain API (#33488)
adds a section for phase execution to the Explain API. This contains - phase definition - policy name - policy version - modified date
1 parent 86e6c71 commit 7a19e26

File tree

21 files changed

+760
-301
lines changed

21 files changed

+760
-301
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/ExplainLifecycleResponse.java

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@
1919

2020
package org.elasticsearch.client.indexlifecycle;
2121

22-
import org.elasticsearch.action.ActionResponse;
2322
import org.elasticsearch.common.ParseField;
2423
import org.elasticsearch.common.Strings;
25-
import org.elasticsearch.common.io.stream.StreamInput;
26-
import org.elasticsearch.common.io.stream.StreamOutput;
2724
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
2825
import org.elasticsearch.common.xcontent.ToXContentObject;
2926
import org.elasticsearch.common.xcontent.XContentBuilder;
3027
import org.elasticsearch.common.xcontent.XContentParser;
3128

3229
import java.io.IOException;
33-
import java.util.HashMap;
3430
import java.util.List;
3531
import java.util.Map;
3632
import java.util.Objects;
@@ -43,9 +39,9 @@
4339
* Since the API can be run over multiple indices the response provides a map of
4440
* index to the explanation of the lifecycle status for that index.
4541
*/
46-
public class ExplainLifecycleResponse extends ActionResponse implements ToXContentObject {
42+
public class ExplainLifecycleResponse implements ToXContentObject {
4743

48-
public static final ParseField INDICES_FIELD = new ParseField("indices");
44+
private static final ParseField INDICES_FIELD = new ParseField("indices");
4945

5046
private Map<String, IndexLifecycleExplainResponse> indexResponses;
5147

@@ -62,9 +58,6 @@ public static ExplainLifecycleResponse fromXContent(XContentParser parser) {
6258
return PARSER.apply(parser, null);
6359
}
6460

65-
public ExplainLifecycleResponse() {
66-
}
67-
6861
public ExplainLifecycleResponse(Map<String, IndexLifecycleExplainResponse> indexResponses) {
6962
this.indexResponses = indexResponses;
7063
}
@@ -91,25 +84,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
9184
return builder;
9285
}
9386

94-
@Override
95-
public void readFrom(StreamInput in) throws IOException {
96-
int size = in.readVInt();
97-
Map<String, IndexLifecycleExplainResponse> indexResponses = new HashMap<>(size);
98-
for (int i = 0; i < size; i++) {
99-
IndexLifecycleExplainResponse indexResponse = new IndexLifecycleExplainResponse(in);
100-
indexResponses.put(indexResponse.getIndex(), indexResponse);
101-
}
102-
this.indexResponses = indexResponses;
103-
}
104-
105-
@Override
106-
public void writeTo(StreamOutput out) throws IOException {
107-
out.writeVInt(indexResponses.size());
108-
for (IndexLifecycleExplainResponse e : indexResponses.values()) {
109-
e.writeTo(out);
110-
}
111-
}
112-
11387
@Override
11488
public int hashCode() {
11589
return Objects.hash(indexResponses);

client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/IndexLifecycleExplainResponse.java

Lines changed: 53 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
import org.elasticsearch.common.Strings;
2424
import org.elasticsearch.common.bytes.BytesArray;
2525
import org.elasticsearch.common.bytes.BytesReference;
26-
import org.elasticsearch.common.io.stream.StreamInput;
27-
import org.elasticsearch.common.io.stream.StreamOutput;
28-
import org.elasticsearch.common.io.stream.Writeable;
2926
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
3027
import org.elasticsearch.common.xcontent.ToXContentObject;
3128
import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -37,7 +34,7 @@
3734
import java.io.IOException;
3835
import java.util.Objects;
3936

40-
public class IndexLifecycleExplainResponse implements ToXContentObject, Writeable {
37+
public class IndexLifecycleExplainResponse implements ToXContentObject {
4138

4239
private static final ParseField INDEX_FIELD = new ParseField("index");
4340
private static final ParseField MANAGED_BY_ILM_FIELD = new ParseField("managed");
@@ -52,23 +49,25 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
5249
private static final ParseField ACTION_TIME_FIELD = new ParseField("action_time");
5350
private static final ParseField STEP_TIME_FIELD = new ParseField("step_time");
5451
private static final ParseField STEP_INFO_FIELD = new ParseField("step_info");
52+
private static final ParseField PHASE_EXECUTION_INFO = new ParseField("phase_execution");
5553

5654
public static final ConstructingObjectParser<IndexLifecycleExplainResponse, Void> PARSER = new ConstructingObjectParser<>(
57-
"index_lifecycle_explain_response",
58-
a -> new IndexLifecycleExplainResponse(
59-
(String) a[0],
60-
(boolean) a[1],
61-
(String) a[2],
62-
(boolean) (a[3] == null ? false: a[3]),
63-
(long) (a[4] == null ? -1L: a[4]),
64-
(String) a[5],
65-
(String) a[6],
66-
(String) a[7],
67-
(String) a[8],
68-
(long) (a[9] == null ? -1L: a[9]),
69-
(long) (a[10] == null ? -1L: a[10]),
70-
(long) (a[11] == null ? -1L: a[11]),
71-
(BytesReference) a[12]));
55+
"index_lifecycle_explain_response",
56+
a -> new IndexLifecycleExplainResponse(
57+
(String) a[0],
58+
(boolean) a[1],
59+
(String) a[2],
60+
(boolean) (a[3] == null ? false: a[3]),
61+
(long) (a[4] == null ? -1L: a[4]),
62+
(String) a[5],
63+
(String) a[6],
64+
(String) a[7],
65+
(String) a[8],
66+
(long) (a[9] == null ? -1L: a[9]),
67+
(long) (a[10] == null ? -1L: a[10]),
68+
(long) (a[11] == null ? -1L: a[11]),
69+
(BytesReference) a[12],
70+
(PhaseExecutionInfo) a[13]));
7271
static {
7372
PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_FIELD);
7473
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), MANAGED_BY_ILM_FIELD);
@@ -87,6 +86,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
8786
builder.copyCurrentStructure(p);
8887
return BytesArray.bytes(builder);
8988
}, STEP_INFO_FIELD);
89+
PARSER.declareObject(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> PhaseExecutionInfo.parse(p, ""),
90+
PHASE_EXECUTION_INFO);
9091
}
9192

9293
private final String index;
@@ -102,30 +103,32 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
102103
private final boolean skip;
103104
private final boolean managedByILM;
104105
private final BytesReference stepInfo;
106+
private final PhaseExecutionInfo phaseExecutionInfo;
105107

106108
public static IndexLifecycleExplainResponse newManagedIndexResponse(String index, String policyName, boolean skip, long lifecycleDate,
107-
String phase, String action, String step, String failedStep, long phaseTime, long actionTime, long stepTime,
108-
BytesReference stepInfo) {
109+
String phase, String action, String step, String failedStep,
110+
long phaseTime, long actionTime, long stepTime,
111+
BytesReference stepInfo, PhaseExecutionInfo phaseExecutionInfo) {
109112
return new IndexLifecycleExplainResponse(index, true, policyName, skip, lifecycleDate, phase, action, step, failedStep, phaseTime,
110-
actionTime, stepTime, stepInfo);
113+
actionTime, stepTime, stepInfo, phaseExecutionInfo);
111114
}
112115

113116
public static IndexLifecycleExplainResponse newUnmanagedIndexResponse(String index) {
114-
return new IndexLifecycleExplainResponse(index, false, null, false, -1L, null, null, null, null, -1L, -1L, -1L, null);
117+
return new IndexLifecycleExplainResponse(index, false, null, false, -1L, null, null, null, null, -1L, -1L, -1L, null, null);
115118
}
116119

117120
private IndexLifecycleExplainResponse(String index, boolean managedByILM, String policyName, boolean skip, long lifecycleDate,
118-
String phase, String action, String step, String failedStep, long phaseTime, long actionTime, long stepTime,
119-
BytesReference stepInfo) {
121+
String phase, String action, String step, String failedStep, long phaseTime, long actionTime,
122+
long stepTime, BytesReference stepInfo, PhaseExecutionInfo phaseExecutionInfo) {
120123
if (managedByILM) {
121124
if (policyName == null) {
122125
throw new IllegalArgumentException("[" + POLICY_NAME_FIELD.getPreferredName() + "] cannot be null for managed index");
123126
}
124127
} else {
125128
if (policyName != null || lifecycleDate >= 0 || phase != null || action != null || step != null || failedStep != null
126-
|| phaseTime >= 0 || actionTime >= 0 || stepTime >= 0 || stepInfo != null) {
129+
|| phaseTime >= 0 || actionTime >= 0 || stepTime >= 0 || stepInfo != null || phaseExecutionInfo != null) {
127130
throw new IllegalArgumentException(
128-
"Unmanaged index response must only contain fields: [" + MANAGED_BY_ILM_FIELD + ", " + INDEX_FIELD + "]");
131+
"Unmanaged index response must only contain fields: [" + MANAGED_BY_ILM_FIELD + ", " + INDEX_FIELD + "]");
129132
}
130133
}
131134
this.index = index;
@@ -141,56 +144,7 @@ private IndexLifecycleExplainResponse(String index, boolean managedByILM, String
141144
this.stepTime = stepTime;
142145
this.failedStep = failedStep;
143146
this.stepInfo = stepInfo;
144-
}
145-
146-
public IndexLifecycleExplainResponse(StreamInput in) throws IOException {
147-
index = in.readString();
148-
managedByILM = in.readBoolean();
149-
if (managedByILM) {
150-
policyName = in.readString();
151-
skip = in.readBoolean();
152-
lifecycleDate = in.readZLong();
153-
phase = in.readString();
154-
action = in.readString();
155-
step = in.readString();
156-
failedStep = in.readOptionalString();
157-
phaseTime = in.readZLong();
158-
actionTime = in.readZLong();
159-
stepTime = in.readZLong();
160-
stepInfo = in.readOptionalBytesReference();
161-
162-
} else {
163-
policyName = null;
164-
skip = false;
165-
lifecycleDate = -1L;
166-
phase = null;
167-
action = null;
168-
step = null;
169-
failedStep = null;
170-
phaseTime = -1L;
171-
actionTime = -1L;
172-
stepTime = -1L;
173-
stepInfo = null;
174-
}
175-
}
176-
177-
@Override
178-
public void writeTo(StreamOutput out) throws IOException {
179-
out.writeString(index);
180-
out.writeBoolean(managedByILM);
181-
if (managedByILM) {
182-
out.writeString(policyName);
183-
out.writeBoolean(skip);
184-
out.writeZLong(lifecycleDate);
185-
out.writeString(phase);
186-
out.writeString(action);
187-
out.writeString(step);
188-
out.writeOptionalString(failedStep);
189-
out.writeZLong(phaseTime);
190-
out.writeZLong(actionTime);
191-
out.writeZLong(stepTime);
192-
out.writeOptionalBytesReference(stepInfo);
193-
}
147+
this.phaseExecutionInfo = phaseExecutionInfo;
194148
}
195149

196150
public String getIndex() {
@@ -245,6 +199,10 @@ public BytesReference getStepInfo() {
245199
return stepInfo;
246200
}
247201

202+
public PhaseExecutionInfo getPhaseExecutionInfo() {
203+
return phaseExecutionInfo;
204+
}
205+
248206
@Override
249207
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
250208
builder.startObject();
@@ -282,6 +240,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
282240
if (stepInfo != null && stepInfo.length() > 0) {
283241
builder.rawField(STEP_INFO_FIELD.getPreferredName(), stepInfo.streamInput(), XContentType.JSON);
284242
}
243+
if (phaseExecutionInfo != null) {
244+
builder.field(PHASE_EXECUTION_INFO.getPreferredName(), phaseExecutionInfo);
245+
}
285246
}
286247
builder.endObject();
287248
return builder;
@@ -290,7 +251,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
290251
@Override
291252
public int hashCode() {
292253
return Objects.hash(index, managedByILM, policyName, skip, lifecycleDate, phase, action, step, failedStep, phaseTime, actionTime,
293-
stepTime, stepInfo);
254+
stepTime, stepInfo, phaseExecutionInfo);
294255
}
295256

296257
@Override
@@ -303,18 +264,19 @@ public boolean equals(Object obj) {
303264
}
304265
IndexLifecycleExplainResponse other = (IndexLifecycleExplainResponse) obj;
305266
return Objects.equals(index, other.index) &&
306-
Objects.equals(managedByILM, other.managedByILM) &&
307-
Objects.equals(policyName, other.policyName) &&
308-
Objects.equals(skip, other.skip) &&
309-
Objects.equals(lifecycleDate, other.lifecycleDate) &&
310-
Objects.equals(phase, other.phase) &&
311-
Objects.equals(action, other.action) &&
312-
Objects.equals(step, other.step) &&
313-
Objects.equals(failedStep, other.failedStep) &&
314-
Objects.equals(phaseTime, other.phaseTime) &&
315-
Objects.equals(actionTime, other.actionTime) &&
316-
Objects.equals(stepTime, other.stepTime) &&
317-
Objects.equals(stepInfo, other.stepInfo);
267+
Objects.equals(managedByILM, other.managedByILM) &&
268+
Objects.equals(policyName, other.policyName) &&
269+
Objects.equals(skip, other.skip) &&
270+
Objects.equals(lifecycleDate, other.lifecycleDate) &&
271+
Objects.equals(phase, other.phase) &&
272+
Objects.equals(action, other.action) &&
273+
Objects.equals(step, other.step) &&
274+
Objects.equals(failedStep, other.failedStep) &&
275+
Objects.equals(phaseTime, other.phaseTime) &&
276+
Objects.equals(actionTime, other.actionTime) &&
277+
Objects.equals(stepTime, other.stepTime) &&
278+
Objects.equals(stepInfo, other.stepInfo) &&
279+
Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo);
318280
}
319281

320282
@Override
@@ -323,3 +285,4 @@ public String toString() {
323285
}
324286

325287
}
288+

0 commit comments

Comments
 (0)