migrate rollup/monitoring/graph/watcher actions to Writeable (#44464) (#44538)

this commit migrates leftover actions from a few x-pack plugins
to the new Writeable.Reader infrastructure.

relates #34389.
This commit is contained in:
Tal Levy 2019-07-18 08:42:56 -07:00 committed by GitHub
parent 651b7a001f
commit c8a8915b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 89 additions and 75 deletions

View File

@ -121,6 +121,31 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest
return this; return this;
} }
public GraphExploreRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
types = in.readStringArray();
routing = in.readOptionalString();
timeout = in.readOptionalTimeValue();
sampleSize = in.readInt();
sampleDiversityField = in.readOptionalString();
maxDocsPerDiversityValue = in.readInt();
useSignificance = in.readBoolean();
returnDetailedInfo = in.readBoolean();
int numHops = in.readInt();
Hop parentHop = null;
for (int i = 0; i < numHops; i++) {
Hop hop = new Hop(parentHop);
hop.readFrom(in);
hops.add(hop);
parentHop = hop;
}
}
public String routing() { public String routing() {
return this.routing; return this.routing;
} }
@ -164,29 +189,7 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
types = in.readStringArray();
routing = in.readOptionalString();
timeout = in.readOptionalTimeValue();
sampleSize = in.readInt();
sampleDiversityField = in.readOptionalString();
maxDocsPerDiversityValue = in.readInt();
useSignificance = in.readBoolean();
returnDetailedInfo = in.readBoolean();
int numHops = in.readInt();
Hop parentHop = null;
for (int i = 0; i < numHops; i++) {
Hop hop = new Hop(parentHop);
hop.readFrom(in);
hops.add(hop);
parentHop = hop;
}
} }
@Override @Override

View File

@ -22,14 +22,18 @@ public class DeleteWatchRequest extends ActionRequest {
private String id; private String id;
private long version = Versions.MATCH_ANY; private long version = Versions.MATCH_ANY;
public DeleteWatchRequest() { public DeleteWatchRequest() {}
this(null);
}
public DeleteWatchRequest(String id) { public DeleteWatchRequest(String id) {
this.id = id; this.id = id;
} }
public DeleteWatchRequest(StreamInput in) throws IOException {
super(in);
id = in.readString();
version = in.readLong();
}
/** /**
* @return The name of the watch to be deleted * @return The name of the watch to be deleted
*/ */
@ -57,9 +61,7 @@ public class DeleteWatchRequest extends ActionRequest {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
id = in.readString();
version = in.readLong();
} }
@Override @Override

View File

@ -33,6 +33,12 @@ public class DeleteWatchResponse extends ActionResponse implements ToXContentObj
public DeleteWatchResponse() {} public DeleteWatchResponse() {}
public DeleteWatchResponse(String id, long version, boolean found) {
this.id = id;
this.version = version;
this.found = found;
}
public DeleteWatchResponse(StreamInput in) throws IOException { public DeleteWatchResponse(StreamInput in) throws IOException {
super(in); super(in);
id = in.readString(); id = in.readString();
@ -40,12 +46,6 @@ public class DeleteWatchResponse extends ActionResponse implements ToXContentObj
found = in.readBoolean(); found = in.readBoolean();
} }
public DeleteWatchResponse(String id, long version, boolean found) {
this.id = id;
this.version = version;
this.found = found;
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@ -16,4 +16,4 @@ public class GraphExploreAction extends ActionType<GraphExploreResponse> {
private GraphExploreAction() { private GraphExploreAction() {
super(NAME, GraphExploreResponse::new); super(NAME, GraphExploreResponse::new);
} }
} }

View File

@ -49,34 +49,31 @@ public class MonitoringBulkDoc implements Writeable {
this.xContentType = Objects.requireNonNull(xContentType); this.xContentType = Objects.requireNonNull(xContentType);
} }
/** public MonitoringBulkDoc (StreamInput in) throws IOException {
* Read from a stream. this.system = MonitoredSystem.fromSystem(in.readOptionalString());
*/
public static MonitoringBulkDoc readFrom(StreamInput in) throws IOException {
final MonitoredSystem system = MonitoredSystem.fromSystem(in.readOptionalString());
if (in.getVersion().before(Version.V_6_0_0_rc1)) { if (in.getVersion().before(Version.V_6_0_0_rc1)) {
in.readOptionalString(); // Monitoring version, removed in 6.0 rc1 in.readOptionalString(); // Monitoring version, removed in 6.0 rc1
in.readOptionalString(); // Cluster UUID, removed in 6.0 rc1 in.readOptionalString(); // Cluster UUID, removed in 6.0 rc1
} }
final long timestamp = in.readVLong(); this.timestamp = in.readVLong();
if (in.getVersion().before(Version.V_6_0_0_rc1)) { if (in.getVersion().before(Version.V_6_0_0_rc1)) {
in.readOptionalWriteable(MonitoringDoc.Node::new);// Source node, removed in 6.0 rc1 in.readOptionalWriteable(MonitoringDoc.Node::new);// Source node, removed in 6.0 rc1
MonitoringIndex.readFrom(in);// Monitoring index, removed in 6.0 rc1 MonitoringIndex.readFrom(in);// Monitoring index, removed in 6.0 rc1
} }
final String type = in.readOptionalString(); this.type = in.readOptionalString();
final String id = in.readOptionalString(); this.id = in.readOptionalString();
final BytesReference source = in.readBytesReference(); this.source = in.readBytesReference();
final XContentType xContentType = (source != BytesArray.EMPTY) ? in.readEnum(XContentType.class) : XContentType.JSON; this.xContentType = (source != BytesArray.EMPTY) ? in.readEnum(XContentType.class) : XContentType.JSON;
long interval = 0L; long interval = 0L;
if (in.getVersion().onOrAfter(Version.V_6_0_0_rc1)) { if (in.getVersion().onOrAfter(Version.V_6_0_0_rc1)) {
interval = in.readVLong(); interval = in.readVLong();
} }
return new MonitoringBulkDoc(system, type, id, timestamp, interval, source, xContentType); this.intervalMillis = interval;
} }
@Override @Override

View File

@ -32,6 +32,13 @@ public class MonitoringBulkRequest extends ActionRequest {
private final List<MonitoringBulkDoc> docs = new ArrayList<>(); private final List<MonitoringBulkDoc> docs = new ArrayList<>();
public MonitoringBulkRequest() {}
public MonitoringBulkRequest(StreamInput in) throws IOException {
super(in);
docs.addAll(in.readList(MonitoringBulkDoc::new));
}
/** /**
* @return the list of {@link MonitoringBulkDoc} to be indexed * @return the list of {@link MonitoringBulkDoc} to be indexed
*/ */
@ -97,8 +104,7 @@ public class MonitoringBulkRequest extends ActionRequest {
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
docs.addAll(in.readList(MonitoringBulkDoc::readFrom));
} }
@Override @Override

View File

@ -51,14 +51,18 @@ public class GetRollupCapsAction extends ActionType<GetRollupCapsAction.Response
public Request() {} public Request() {}
public Request(StreamInput in) throws IOException {
super(in);
this.indexPattern = in.readString();
}
public String getIndexPattern() { public String getIndexPattern() {
return indexPattern; return indexPattern;
} }
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.indexPattern = in.readString();
} }
@Override @Override

View File

@ -10,8 +10,8 @@ import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
@ -57,6 +57,12 @@ public class GetRollupIndexCapsAction extends ActionType<GetRollupIndexCapsActio
public Request() {} public Request() {}
public Request(StreamInput in) throws IOException {
super(in);
this.indices = in.readStringArray();
this.options = IndicesOptions.readIndicesOptions(in);
}
@Override @Override
public IndicesOptions indicesOptions() { public IndicesOptions indicesOptions() {
return options; return options;
@ -79,9 +85,7 @@ public class GetRollupIndexCapsAction extends ActionType<GetRollupIndexCapsActio
@Override @Override
public void readFrom(StreamInput in) throws IOException { public void readFrom(StreamInput in) throws IOException {
super.readFrom(in); throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
this.indices = in.readStringArray();
this.options = IndicesOptions.readIndicesOptions(in);
} }
@Override @Override

View File

@ -84,7 +84,7 @@ public class TransportGraphExploreAction extends HandledTransportAction<GraphExp
@Inject @Inject
public TransportGraphExploreAction(ThreadPool threadPool, NodeClient client, TransportService transportService, public TransportGraphExploreAction(ThreadPool threadPool, NodeClient client, TransportService transportService,
ActionFilters actionFilters, XPackLicenseState licenseState) { ActionFilters actionFilters, XPackLicenseState licenseState) {
super(GraphExploreAction.NAME, transportService, GraphExploreRequest::new, actionFilters); super(GraphExploreAction.NAME, transportService, actionFilters, GraphExploreRequest::new);
this.threadPool = threadPool; this.threadPool = threadPool;
this.client = client; this.client = client;
this.licenseState = licenseState; this.licenseState = licenseState;

View File

@ -43,7 +43,7 @@ public class TransportMonitoringBulkAction extends HandledTransportAction<Monito
public TransportMonitoringBulkAction(ThreadPool threadPool, ClusterService clusterService, public TransportMonitoringBulkAction(ThreadPool threadPool, ClusterService clusterService,
TransportService transportService, ActionFilters actionFilters, Exporters exportService, TransportService transportService, ActionFilters actionFilters, Exporters exportService,
MonitoringService monitoringService) { MonitoringService monitoringService) {
super(MonitoringBulkAction.NAME, transportService, MonitoringBulkRequest::new, actionFilters); super(MonitoringBulkAction.NAME, transportService, actionFilters, MonitoringBulkRequest::new);
this.threadPool = threadPool; this.threadPool = threadPool;
this.clusterService = clusterService; this.clusterService = clusterService;
this.exportService = exportService; this.exportService = exportService;

View File

@ -147,7 +147,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
final int iterations = randomIntBetween(5, 50); final int iterations = randomIntBetween(5, 50);
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
final MonitoringBulkDoc original = randomMonitoringBulkDoc(random()); final MonitoringBulkDoc original = randomMonitoringBulkDoc(random());
final MonitoringBulkDoc deserialized = copyWriteable(original, registry, MonitoringBulkDoc::readFrom); final MonitoringBulkDoc deserialized = copyWriteable(original, registry, MonitoringBulkDoc::new);
assertEquals(original, deserialized); assertEquals(original, deserialized);
assertEquals(original.hashCode(), deserialized.hashCode()); assertEquals(original.hashCode(), deserialized.hashCode());

View File

@ -240,8 +240,7 @@ public class MonitoringBulkRequestTests extends ESTestCase {
final StreamInput in = out.bytes().streamInput(); final StreamInput in = out.bytes().streamInput();
in.setVersion(out.getVersion()); in.setVersion(out.getVersion());
final MonitoringBulkRequest deserializedRequest = new MonitoringBulkRequest(); final MonitoringBulkRequest deserializedRequest = new MonitoringBulkRequest(in);
deserializedRequest.readFrom(in);
assertThat(in.available(), equalTo(0)); assertThat(in.available(), equalTo(0));

View File

@ -36,8 +36,7 @@ public class TransportGetRollupCapsAction extends HandledTransportAction<GetRoll
@Inject @Inject
public TransportGetRollupCapsAction(TransportService transportService, ClusterService clusterService, ActionFilters actionFilters) { public TransportGetRollupCapsAction(TransportService transportService, ClusterService clusterService, ActionFilters actionFilters) {
super(GetRollupCapsAction.NAME, transportService, GetRollupCapsAction.Request::new, actionFilters super(GetRollupCapsAction.NAME, transportService, actionFilters, GetRollupCapsAction.Request::new);
);
this.clusterService = clusterService; this.clusterService = clusterService;
} }

View File

@ -35,8 +35,7 @@ public class TransportGetRollupIndexCapsAction extends HandledTransportAction<Ge
@Inject @Inject
public TransportGetRollupIndexCapsAction(TransportService transportService, ClusterService clusterService, public TransportGetRollupIndexCapsAction(TransportService transportService, ClusterService clusterService,
ActionFilters actionFilters) { ActionFilters actionFilters) {
super(GetRollupIndexCapsAction.NAME, transportService, GetRollupIndexCapsAction.Request::new, actionFilters super(GetRollupIndexCapsAction.NAME, transportService, actionFilters, GetRollupIndexCapsAction.Request::new);
);
this.clusterService = clusterService; this.clusterService = clusterService;
} }

View File

@ -10,7 +10,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.RollupField;
import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction;
@ -27,7 +28,7 @@ import java.util.Optional;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase<GetRollupCapsAction.Request> { public class GetRollupCapsActionRequestTests extends AbstractWireSerializingTestCase<GetRollupCapsAction.Request> {
@Override @Override
protected GetRollupCapsAction.Request createTestInstance() { protected GetRollupCapsAction.Request createTestInstance() {
@ -38,8 +39,8 @@ public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase<
} }
@Override @Override
protected GetRollupCapsAction.Request createBlankInstance() { protected Writeable.Reader<GetRollupCapsAction.Request> instanceReader() {
return new GetRollupCapsAction.Request(); return GetRollupCapsAction.Request::new;
} }
public void testNoIndexMetaData() { public void testNoIndexMetaData() {

View File

@ -10,7 +10,8 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers;
import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.RollupField;
import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction;
@ -27,7 +28,7 @@ import static org.elasticsearch.xpack.rollup.action.TransportGetRollupIndexCapsA
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class GetRollupIndexCapsActionRequestTests extends AbstractStreamableTestCase<GetRollupIndexCapsAction.Request> { public class GetRollupIndexCapsActionRequestTests extends AbstractWireSerializingTestCase<GetRollupIndexCapsAction.Request> {
@Override @Override
protected GetRollupIndexCapsAction.Request createTestInstance() { protected GetRollupIndexCapsAction.Request createTestInstance() {
@ -38,11 +39,10 @@ public class GetRollupIndexCapsActionRequestTests extends AbstractStreamableTest
} }
@Override @Override
protected GetRollupIndexCapsAction.Request createBlankInstance() { protected Writeable.Reader<GetRollupIndexCapsAction.Request> instanceReader() {
return new GetRollupIndexCapsAction.Request(); return GetRollupIndexCapsAction.Request::new;
} }
public void testNoIndicesByRollup() { public void testNoIndicesByRollup() {
ImmutableOpenMap<String, IndexMetaData> indices = new ImmutableOpenMap.Builder<String, IndexMetaData>().build(); ImmutableOpenMap<String, IndexMetaData> indices = new ImmutableOpenMap.Builder<String, IndexMetaData>().build();
Map<String, RollableIndexCaps> caps = getCapsByRollupIndex(Collections.singletonList("foo"), indices); Map<String, RollableIndexCaps> caps = getCapsByRollupIndex(Collections.singletonList("foo"), indices);

View File

@ -34,7 +34,7 @@ public class TransportDeleteWatchAction extends HandledTransportAction<DeleteWat
@Inject @Inject
public TransportDeleteWatchAction(TransportService transportService, ActionFilters actionFilters, Client client) { public TransportDeleteWatchAction(TransportService transportService, ActionFilters actionFilters, Client client) {
super(DeleteWatchAction.NAME, transportService, DeleteWatchRequest::new, actionFilters); super(DeleteWatchAction.NAME, transportService, actionFilters, DeleteWatchRequest::new);
this.client = client; this.client = client;
} }

View File

@ -63,7 +63,7 @@ public class WatchRequestValidationTests extends ESTestCase {
} }
public void testDeleteWatchNullId() { public void testDeleteWatchNullId() {
ActionRequestValidationException e = new DeleteWatchRequest(null).validate(); ActionRequestValidationException e = new DeleteWatchRequest().validate();
assertThat(e, is(notNullValue())); assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch id is missing")); assertThat(e.validationErrors(), hasItem("watch id is missing"));
} }