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;
}
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() {
return this.routing;
}
@ -164,29 +189,7 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(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;
}
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
@Override

View File

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

View File

@ -33,6 +33,12 @@ public class DeleteWatchResponse extends ActionResponse implements ToXContentObj
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 {
super(in);
id = in.readString();
@ -40,12 +46,6 @@ public class DeleteWatchResponse extends ActionResponse implements ToXContentObj
found = in.readBoolean();
}
public DeleteWatchResponse(String id, long version, boolean found) {
this.id = id;
this.version = version;
this.found = found;
}
public String getId() {
return id;
}

View File

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

View File

@ -32,6 +32,13 @@ public class MonitoringBulkRequest extends ActionRequest {
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
*/
@ -97,8 +104,7 @@ public class MonitoringBulkRequest extends ActionRequest {
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
docs.addAll(in.readList(MonitoringBulkDoc::readFrom));
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
@Override

View File

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

View File

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

View File

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

View File

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

View File

@ -147,7 +147,7 @@ public class MonitoringBulkDocTests extends ESTestCase {
final int iterations = randomIntBetween(5, 50);
for (int i = 0; i < iterations; i++) {
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.hashCode(), deserialized.hashCode());

View File

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

View File

@ -36,8 +36,7 @@ public class TransportGetRollupCapsAction extends HandledTransportAction<GetRoll
@Inject
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;
}

View File

@ -35,8 +35,7 @@ public class TransportGetRollupIndexCapsAction extends HandledTransportAction<Ge
@Inject
public TransportGetRollupIndexCapsAction(TransportService transportService, ClusterService clusterService,
ActionFilters actionFilters) {
super(GetRollupIndexCapsAction.NAME, transportService, GetRollupIndexCapsAction.Request::new, actionFilters
);
super(GetRollupIndexCapsAction.NAME, transportService, actionFilters, GetRollupIndexCapsAction.Request::new);
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.MetaData;
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.RollupField;
import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction;
@ -27,7 +28,7 @@ import java.util.Optional;
import static org.hamcrest.Matchers.equalTo;
public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase<GetRollupCapsAction.Request> {
public class GetRollupCapsActionRequestTests extends AbstractWireSerializingTestCase<GetRollupCapsAction.Request> {
@Override
protected GetRollupCapsAction.Request createTestInstance() {
@ -38,8 +39,8 @@ public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase<
}
@Override
protected GetRollupCapsAction.Request createBlankInstance() {
return new GetRollupCapsAction.Request();
protected Writeable.Reader<GetRollupCapsAction.Request> instanceReader() {
return GetRollupCapsAction.Request::new;
}
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.MetaData;
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.RollupField;
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;
public class GetRollupIndexCapsActionRequestTests extends AbstractStreamableTestCase<GetRollupIndexCapsAction.Request> {
public class GetRollupIndexCapsActionRequestTests extends AbstractWireSerializingTestCase<GetRollupIndexCapsAction.Request> {
@Override
protected GetRollupIndexCapsAction.Request createTestInstance() {
@ -38,11 +39,10 @@ public class GetRollupIndexCapsActionRequestTests extends AbstractStreamableTest
}
@Override
protected GetRollupIndexCapsAction.Request createBlankInstance() {
return new GetRollupIndexCapsAction.Request();
protected Writeable.Reader<GetRollupIndexCapsAction.Request> instanceReader() {
return GetRollupIndexCapsAction.Request::new;
}
public void testNoIndicesByRollup() {
ImmutableOpenMap<String, IndexMetaData> indices = new ImmutableOpenMap.Builder<String, IndexMetaData>().build();
Map<String, RollableIndexCaps> caps = getCapsByRollupIndex(Collections.singletonList("foo"), indices);

View File

@ -34,7 +34,7 @@ public class TransportDeleteWatchAction extends HandledTransportAction<DeleteWat
@Inject
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;
}

View File

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