diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java index 9ae7d065dd949..be757a02c3982 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/close/TransportVerifyShardBeforeCloseAction.java @@ -158,7 +158,7 @@ public String toString() { @Override public void readFrom(final StreamInput in) throws IOException { super.readFrom(in); - clusterBlock = ClusterBlock.readClusterBlock(in); + clusterBlock = new ClusterBlock(in); } @Override diff --git a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java index 497e296d9eeb6..ec5d7b178e8de 100644 --- a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java +++ b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlock.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.RestStatus; @@ -34,7 +35,7 @@ import java.util.Locale; import java.util.Objects; -public class ClusterBlock implements Streamable, ToXContentFragment { +public class ClusterBlock implements Streamable, Writeable, ToXContentFragment { private int id; private @Nullable String uuid; @@ -45,7 +46,24 @@ public class ClusterBlock implements Streamable, ToXContentFragment { private boolean allowReleaseResources; private RestStatus status; - private ClusterBlock() { + public ClusterBlock(StreamInput in) throws IOException { + id = in.readVInt(); + if (in.getVersion().onOrAfter(Version.V_6_7_0)) { + uuid = in.readOptionalString(); + } else { + uuid = null; + } + description = in.readString(); + final int len = in.readVInt(); + ArrayList levels = new ArrayList<>(len); + for (int i = 0; i < len; i++) { + levels.add(in.readEnum(ClusterBlockLevel.class)); + } + this.levels = EnumSet.copyOf(levels); + retryable = in.readBoolean(); + disableStatePersistence = in.readBoolean(); + status = RestStatus.readFrom(in); + allowReleaseResources = in.readBoolean(); } public ClusterBlock(int id, String description, boolean retryable, boolean disableStatePersistence, @@ -129,31 +147,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - public static ClusterBlock readClusterBlock(StreamInput in) throws IOException { - ClusterBlock block = new ClusterBlock(); - block.readFrom(in); - return block; - } - @Override public void readFrom(StreamInput in) throws IOException { - id = in.readVInt(); - if (in.getVersion().onOrAfter(Version.V_6_7_0)) { - uuid = in.readOptionalString(); - } else { - uuid = null; - } - description = in.readString(); - final int len = in.readVInt(); - ArrayList levels = new ArrayList<>(len); - for (int i = 0; i < len; i++) { - levels.add(in.readEnum(ClusterBlockLevel.class)); - } - this.levels = EnumSet.copyOf(levels); - retryable = in.readBoolean(); - disableStatePersistence = in.readBoolean(); - status = RestStatus.readFrom(in); - allowReleaseResources = in.readBoolean(); + throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable"); } @Override diff --git a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java index 9ebb2286895fd..b24ec795bc474 100644 --- a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java +++ b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlockException.java @@ -43,7 +43,7 @@ public ClusterBlockException(StreamInput in) throws IOException { int totalBlocks = in.readVInt(); Set blocks = new HashSet<>(totalBlocks); for (int i = 0; i < totalBlocks;i++) { - blocks.add(ClusterBlock.readClusterBlock(in)); + blocks.add(new ClusterBlock(in)); } this.blocks = unmodifiableSet(blocks); } diff --git a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java index 0de7bce115943..c46bc291e7397 100644 --- a/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java +++ b/server/src/main/java/org/elasticsearch/cluster/block/ClusterBlocks.java @@ -305,7 +305,7 @@ private static Set readBlockSet(StreamInput in) throws IOException int totalBlocks = in.readVInt(); Set blocks = new HashSet<>(totalBlocks); for (int i = 0; i < totalBlocks;i++) { - blocks.add(ClusterBlock.readClusterBlock(in)); + blocks.add(new ClusterBlock(in)); } return unmodifiableSet(blocks); } diff --git a/server/src/test/java/org/elasticsearch/cluster/block/ClusterBlockTests.java b/server/src/test/java/org/elasticsearch/cluster/block/ClusterBlockTests.java index 3fdb97b8c3558..4bd6c15853aa0 100644 --- a/server/src/test/java/org/elasticsearch/cluster/block/ClusterBlockTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/block/ClusterBlockTests.java @@ -56,7 +56,7 @@ public void testSerialization() throws Exception { StreamInput in = out.bytes().streamInput(); in.setVersion(version); - ClusterBlock result = ClusterBlock.readClusterBlock(in); + ClusterBlock result = new ClusterBlock(in); assertClusterBlockEquals(clusterBlock, result); } @@ -74,7 +74,7 @@ public void testBwcSerialization() throws Exception { expected.writeTo(out); // Deserialize and check the cluster block - final ClusterBlock actual = ClusterBlock.readClusterBlock(out.bytes().streamInput()); + final ClusterBlock actual = new ClusterBlock(out.bytes().streamInput()); assertClusterBlockEquals(expected, actual); } @@ -90,7 +90,7 @@ public void testBwcSerialization() throws Exception { // Deserialize and check the cluster block final StreamInput in = out.bytes().streamInput(); in.setVersion(out.getVersion()); - final ClusterBlock actual = ClusterBlock.readClusterBlock(in); + final ClusterBlock actual = new ClusterBlock(in); assertThat(actual.id(), equalTo(expected.id())); assertThat(actual.status(), equalTo(expected.status()));