Skip to content

Commit a1531e8

Browse files
Likejdconrad
Like
authored andcommitted
Migrate Streamable to Writeable for WatchStatus (#37390)
1 parent 7342d5a commit a1531e8

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/ack/AckWatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public WatchStatus getStatus() {
3838
@Override
3939
public void readFrom(StreamInput in) throws IOException {
4040
super.readFrom(in);
41-
status = in.readBoolean() ? WatchStatus.read(in) : null;
41+
status = in.readBoolean() ? new WatchStatus(in) : null;
4242
}
4343

4444
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/activate/ActivateWatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public WatchStatus getStatus() {
3838
@Override
3939
public void readFrom(StreamInput in) throws IOException {
4040
super.readFrom(in);
41-
status = in.readBoolean() ? WatchStatus.read(in) : null;
41+
status = in.readBoolean() ? new WatchStatus(in) : null;
4242
}
4343

4444
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/transport/actions/get/GetWatchResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void readFrom(StreamInput in) throws IOException {
9292
id = in.readString();
9393
found = in.readBoolean();
9494
if (found) {
95-
status = WatchStatus.read(in);
95+
status = new WatchStatus(in);
9696
source = XContentSource.readFrom(in);
9797
version = in.readZLong();
9898
seqNo = in.readZLong();

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/WatchStatus.java

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
1313
import org.elasticsearch.common.io.stream.Streamable;
14+
import org.elasticsearch.common.io.stream.Writeable;
1415
import org.elasticsearch.common.xcontent.ToXContentObject;
1516
import org.elasticsearch.common.xcontent.XContentBuilder;
1617
import org.elasticsearch.common.xcontent.XContentParser;
@@ -36,7 +37,7 @@
3637
import static org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils.writeDate;
3738
import static org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils.writeOptionalDate;
3839

39-
public class WatchStatus implements ToXContentObject, Streamable {
40+
public class WatchStatus implements ToXContentObject, Streamable, Writeable {
4041

4142
public static final String INCLUDE_STATE = "include_state";
4243

@@ -49,8 +50,26 @@ public class WatchStatus implements ToXContentObject, Streamable {
4950
@Nullable private Map<String, String> headers;
5051
private Map<String, ActionStatus> actions;
5152

52-
// for serialization
53-
private WatchStatus() {
53+
public WatchStatus(StreamInput in) throws IOException {
54+
version = in.readLong();
55+
lastChecked = readOptionalDate(in);
56+
lastMetCondition = readOptionalDate(in);
57+
int count = in.readInt();
58+
Map<String, ActionStatus> actions = new HashMap<>(count);
59+
for (int i = 0; i < count; i++) {
60+
actions.put(in.readString(), ActionStatus.readFrom(in));
61+
}
62+
this.actions = unmodifiableMap(actions);
63+
state = new State(in.readBoolean(), Instant.ofEpochMilli(in.readLong()).atZone(ZoneOffset.UTC));
64+
boolean executionStateExists = in.readBoolean();
65+
if (executionStateExists) {
66+
executionState = ExecutionState.resolve(in.readString());
67+
}
68+
if (in.readBoolean()) {
69+
headers = in.readMap(StreamInput::readString, StreamInput::readString);
70+
} else {
71+
headers = Collections.emptyMap();
72+
}
5473
}
5574

5675
public WatchStatus(ZonedDateTime now, Map<String, ActionStatus> actions) {
@@ -222,31 +241,7 @@ public void writeTo(StreamOutput out) throws IOException {
222241

223242
@Override
224243
public void readFrom(StreamInput in) throws IOException {
225-
version = in.readLong();
226-
lastChecked = readOptionalDate(in);
227-
lastMetCondition = readOptionalDate(in);
228-
int count = in.readInt();
229-
Map<String, ActionStatus> actions = new HashMap<>(count);
230-
for (int i = 0; i < count; i++) {
231-
actions.put(in.readString(), ActionStatus.readFrom(in));
232-
}
233-
this.actions = unmodifiableMap(actions);
234-
state = new State(in.readBoolean(), Instant.ofEpochMilli(in.readLong()).atZone(ZoneOffset.UTC));
235-
boolean executionStateExists = in.readBoolean();
236-
if (executionStateExists) {
237-
executionState = ExecutionState.resolve(in.readString());
238-
}
239-
if (in.readBoolean()) {
240-
headers = in.readMap(StreamInput::readString, StreamInput::readString);
241-
} else {
242-
headers = Collections.emptyMap();
243-
}
244-
}
245-
246-
public static WatchStatus read(StreamInput in) throws IOException {
247-
WatchStatus status = new WatchStatus();
248-
status.readFrom(in);
249-
return status;
244+
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
250245
}
251246

252247
@Override

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void testHeadersSerialization() throws IOException {
8888
BytesStreamOutput out = new BytesStreamOutput();
8989
status.writeTo(out);
9090
BytesReference bytesReference = out.bytes();
91-
WatchStatus readStatus = WatchStatus.read(bytesReference.streamInput());
91+
WatchStatus readStatus = new WatchStatus(bytesReference.streamInput());
9292
assertThat(readStatus, is(status));
9393
assertThat(readStatus.getHeaders(), is(headers));
9494

0 commit comments

Comments
 (0)