HLRC XPack Protocol clean up: Migration; Graph; Watcher (#34639)

Move parts related to XPack for packages Migration; Graph; Watcher from protocol to client

Drop protocol module

Relates #34451
This commit is contained in:
Vladimir Dolzhenko 2018-10-29 13:38:56 +01:00 committed by GitHub
parent 8d7889d20c
commit 69fe9a1bf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 217 additions and 983 deletions

View File

@ -51,7 +51,6 @@ dependencies {
compile "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}"
compile "org.elasticsearch.plugin:rank-eval-client:${version}"
compile "org.elasticsearch.plugin:lang-mustache-client:${version}"
bundle project(':x-pack:protocol')
testCompile "org.elasticsearch.client:test:${version}"
testCompile "org.elasticsearch.test:framework:${version}"

View File

@ -20,8 +20,8 @@
package org.elasticsearch.client;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
import org.elasticsearch.protocol.xpack.graph.GraphExploreResponse;
import org.elasticsearch.client.graph.GraphExploreRequest;
import org.elasticsearch.client.graph.GraphExploreResponse;
import java.io.IOException;

View File

@ -20,7 +20,7 @@
package org.elasticsearch.client;
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
import org.elasticsearch.client.graph.GraphExploreRequest;
import java.io.IOException;

View File

@ -19,8 +19,8 @@
package org.elasticsearch.client;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.client.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.client.migration.IndexUpgradeInfoResponse;
import java.io.IOException;
import java.util.Collections;

View File

@ -20,7 +20,7 @@
package org.elasticsearch.client;
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.client.migration.IndexUpgradeInfoRequest;
final class MigrationRequestConverters {
@ -28,7 +28,7 @@ final class MigrationRequestConverters {
static Request getMigrationAssistance(IndexUpgradeInfoRequest indexUpgradeInfoRequest) {
RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack/migration/assistance")
.addPathPartAsIs("_xpack", "migration", "assistance")
.addCommaSeparatedPathParts(indexUpgradeInfoRequest.indices());
String endpoint = endpointBuilder.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

View File

@ -28,10 +28,10 @@ import org.elasticsearch.client.watcher.AckWatchRequest;
import org.elasticsearch.client.watcher.AckWatchResponse;
import org.elasticsearch.client.watcher.StartWatchServiceRequest;
import org.elasticsearch.client.watcher.StopWatchServiceRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchResponse;
import org.elasticsearch.client.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.PutWatchResponse;
import java.io.IOException;

View File

@ -30,8 +30,8 @@ import org.elasticsearch.client.watcher.AckWatchRequest;
import org.elasticsearch.client.watcher.StartWatchServiceRequest;
import org.elasticsearch.client.watcher.StopWatchServiceRequest;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
import org.elasticsearch.client.watcher.PutWatchRequest;
final class WatcherRequestConverters {
@ -59,9 +59,7 @@ final class WatcherRequestConverters {
static Request putWatch(PutWatchRequest putWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(putWatchRequest.getId())
.build();
@ -89,9 +87,7 @@ final class WatcherRequestConverters {
static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(deleteWatchRequest.getId())
.build();
@ -101,9 +97,7 @@ final class WatcherRequestConverters {
public static Request ackWatch(AckWatchRequest ackWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(ackWatchRequest.getWatchId())
.addPathPartAsIs("_ack")
.addCommaSeparatedPathParts(ackWatchRequest.getActionIds())
@ -114,9 +108,7 @@ final class WatcherRequestConverters {
static Request activateWatch(ActivateWatchRequest activateWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(activateWatchRequest.getWatchId())
.addPathPartAsIs("_activate")
.build();

View File

@ -16,22 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import com.carrotsearch.hppc.ObjectIntHashMap;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContent.Params;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.xpack.graph.Vertex.VertexId;
import org.elasticsearch.client.graph.Vertex.VertexId;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
@ -55,25 +52,9 @@ public class Connection {
this.docCount = docCount;
}
public Connection(StreamInput in, Map<VertexId, Vertex> vertices) throws IOException {
from = vertices.get(new VertexId(in.readString(), in.readString()));
to = vertices.get(new VertexId(in.readString(), in.readString()));
weight = in.readDouble();
docCount = in.readVLong();
}
Connection() {
}
void writeTo(StreamOutput out) throws IOException {
out.writeString(from.getField());
out.writeString(from.getTerm());
out.writeString(to.getField());
out.writeString(to.getTerm());
out.writeDouble(weight);
out.writeVLong(docCount);
}
public ConnectionId getId() {
return new ConnectionId(from.getId(), to.getId());
}

View File

@ -16,13 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -37,14 +36,14 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
/**
* Holds the criteria required to guide the exploration of connected terms which
* can be returned as a graph.
*/
public class GraphExploreRequest extends ActionRequest implements IndicesRequest.Replaceable, ToXContentObject {
public class GraphExploreRequest implements IndicesRequest.Replaceable, ToXContentObject, Validatable {
public static final String NO_HOPS_ERROR_MESSAGE = "Graph explore request must have at least one hop";
public static final String NO_VERTICES_ERROR_MESSAGE = "Graph explore hop must have at least one VertexRequest";
@ -74,15 +73,15 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest
}
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
public Optional<ValidationException> validate() {
ValidationException validationException = new ValidationException();
if (hops.size() == 0) {
validationException = ValidateActions.addValidationError(NO_HOPS_ERROR_MESSAGE, validationException);
validationException.addValidationError(NO_HOPS_ERROR_MESSAGE);
}
for (Hop hop : hops) {
validationException = hop.validate(validationException);
hop.validate(validationException);
}
return validationException;
return validationException.validationErrors().isEmpty() ? Optional.empty() : Optional.of(validationException);
}
@Override
@ -159,55 +158,6 @@ public class GraphExploreRequest extends ActionRequest implements IndicesRequest
return this;
}
@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;
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
out.writeStringArray(types);
out.writeOptionalString(routing);
out.writeOptionalTimeValue(timeout);
out.writeInt(sampleSize);
out.writeOptionalString(sampleDiversityField);
out.writeInt(maxDocsPerDiversityValue);
out.writeBoolean(useSignificance);
out.writeBoolean(returnDetailedInfo);
out.writeInt(hops.size());
for (Iterator<Hop> iterator = hops.iterator(); iterator.hasNext();) {
Hop hop = iterator.next();
hop.writeTo(out);
}
}
@Override
public String toString() {
return "graph explore [" + Arrays.toString(indices) + "][" + Arrays.toString(types) + "]";

View File

@ -16,24 +16,21 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import com.carrotsearch.hppc.ObjectIntHashMap;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.search.ShardSearchFailure;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.protocol.xpack.graph.Connection.ConnectionId;
import org.elasticsearch.protocol.xpack.graph.Connection.UnresolvedConnection;
import org.elasticsearch.protocol.xpack.graph.Vertex.VertexId;
import org.elasticsearch.client.graph.Connection.ConnectionId;
import org.elasticsearch.client.graph.Connection.UnresolvedConnection;
import org.elasticsearch.client.graph.Vertex.VertexId;
import java.io.IOException;
import java.util.Collection;
@ -41,7 +38,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.action.search.ShardSearchFailure.readShardSearchFailure;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
@ -51,7 +47,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optiona
*
* @see GraphExploreRequest
*/
public class GraphExploreResponse extends ActionResponse implements ToXContentObject {
public class GraphExploreResponse implements ToXContentObject {
private long tookInMillis;
private boolean timedOut = false;
@ -94,41 +90,6 @@ public class GraphExploreResponse extends ActionResponse implements ToXContentOb
return shardFailures;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
tookInMillis = in.readVLong();
timedOut = in.readBoolean();
int size = in.readVInt();
if (size == 0) {
shardFailures = ShardSearchFailure.EMPTY_ARRAY;
} else {
shardFailures = new ShardSearchFailure[size];
for (int i = 0; i < shardFailures.length; i++) {
shardFailures[i] = readShardSearchFailure(in);
}
}
// read vertices
size = in.readVInt();
vertices = new HashMap<>();
for (int i = 0; i < size; i++) {
Vertex n = Vertex.readFrom(in);
vertices.put(n.getId(), n);
}
size = in.readVInt();
connections = new HashMap<>();
for (int i = 0; i < size; i++) {
Connection e = new Connection(in, vertices);
connections.put(e.getId(), e);
}
returnDetailedInfo = in.readBoolean();
}
public Collection<Connection> getConnections() {
return connections.values();
}
@ -141,31 +102,6 @@ public class GraphExploreResponse extends ActionResponse implements ToXContentOb
return vertices.get(id);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeVLong(tookInMillis);
out.writeBoolean(timedOut);
out.writeVInt(shardFailures.length);
for (ShardOperationFailedException shardSearchFailure : shardFailures) {
shardSearchFailure.writeTo(out);
}
out.writeVInt(vertices.size());
for (Vertex vertex : vertices.values()) {
vertex.writeTo(out);
}
out.writeVInt(connections.size());
for (Connection connection : connections.values()) {
connection.writeTo(out);
}
out.writeBoolean(returnDetailedInfo);
}
private static final ParseField TOOK = new ParseField("took");
private static final ParseField TIMED_OUT = new ParseField("timed_out");
private static final ParseField VERTICES = new ParseField("vertices");

View File

@ -16,12 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryBuilder;
@ -56,7 +53,7 @@ import java.util.List;
* </p>
*
*/
public class Hop implements ToXContentFragment{
public class Hop implements ToXContentFragment {
final Hop parentHop;
List<VertexRequest> vertices = null;
QueryBuilder guidingQuery = null;
@ -65,44 +62,16 @@ public class Hop implements ToXContentFragment{
this.parentHop = parent;
}
public ActionRequestValidationException validate(ActionRequestValidationException validationException) {
public void validate(ValidationException validationException) {
if (getEffectiveVertexRequests().size() == 0) {
validationException = ValidateActions.addValidationError(GraphExploreRequest.NO_VERTICES_ERROR_MESSAGE, validationException);
validationException.addValidationError(GraphExploreRequest.NO_VERTICES_ERROR_MESSAGE);
}
return validationException;
}
public Hop getParentHop() {
return parentHop;
}
void writeTo(StreamOutput out) throws IOException {
out.writeOptionalNamedWriteable(guidingQuery);
if (vertices == null) {
out.writeVInt(0);
} else {
out.writeVInt(vertices.size());
for (VertexRequest vr : vertices) {
vr.writeTo(out);
}
}
}
void readFrom(StreamInput in) throws IOException {
guidingQuery = in.readOptionalNamedWriteable(QueryBuilder.class);
int size = in.readVInt();
if (size > 0) {
vertices = new ArrayList<>();
for (int i = 0; i < size; i++) {
VertexRequest vr = new VertexRequest();
vr.readFrom(in);
vertices.add(vr);
}
}
}
public QueryBuilder guidingQuery() {
if (guidingQuery != null) {
return guidingQuery;

View File

@ -16,11 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -65,19 +63,6 @@ public class Vertex implements ToXContentFragment {
this.fg = fg;
}
static Vertex readFrom(StreamInput in) throws IOException {
return new Vertex(in.readString(), in.readString(), in.readDouble(), in.readVInt(), in.readVLong(), in.readVLong());
}
void writeTo(StreamOutput out) throws IOException {
out.writeString(field);
out.writeString(term);
out.writeDouble(weight);
out.writeVInt(depth);
out.writeVLong(bg);
out.writeVLong(fg);
}
@Override
public int hashCode() {
return Objects.hash(field, term, weight, depth, bg, fg);

View File

@ -16,13 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest.TermBoost;
import org.elasticsearch.client.graph.GraphExploreRequest.TermBoost;
import java.io.IOException;
import java.util.HashMap;
@ -52,57 +50,6 @@ public class VertexRequest implements ToXContentObject {
}
void readFrom(StreamInput in) throws IOException {
fieldName = in.readString();
size = in.readVInt();
minDocCount = in.readVInt();
shardMinDocCount = in.readVInt();
int numIncludes = in.readVInt();
if (numIncludes > 0) {
includes = new HashMap<>();
for (int i = 0; i < numIncludes; i++) {
TermBoost tb = new TermBoost();
tb.readFrom(in);
includes.put(tb.term, tb);
}
}
int numExcludes = in.readVInt();
if (numExcludes > 0) {
excludes = new HashSet<>();
for (int i = 0; i < numExcludes; i++) {
excludes.add(in.readString());
}
}
}
void writeTo(StreamOutput out) throws IOException {
out.writeString(fieldName);
out.writeVInt(size);
out.writeVInt(minDocCount);
out.writeVInt(shardMinDocCount);
if (includes != null) {
out.writeVInt(includes.size());
for (TermBoost tb : includes.values()) {
tb.writeTo(out);
}
} else {
out.writeVInt(0);
}
if (excludes != null) {
out.writeVInt(excludes.size());
for (String term : excludes) {
out.writeString(term);
}
} else {
out.writeVInt(0);
}
}
public String fieldName() {
return fieldName;
}
@ -224,7 +171,7 @@ public class VertexRequest implements ToXContentObject {
if (shardMinDocCount != DEFAULT_SHARD_MIN_DOC_COUNT) {
builder.field("shard_min_doc_count", shardMinDocCount);
}
if(includes!=null) {
if (includes != null) {
builder.startArray("include");
for (TermBoost tb : includes.values()) {
builder.startObject();
@ -234,7 +181,7 @@ public class VertexRequest implements ToXContentObject {
}
builder.endArray();
}
if(excludes!=null) {
if (excludes != null) {
builder.startArray("exclude");
for (String value : excludes) {
builder.value(value);

View File

@ -21,4 +21,4 @@
* Request and Response objects for the default distribution's Graph
* APIs.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;

View File

@ -16,21 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.migration;
package org.elasticsearch.client.migration;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
import org.elasticsearch.client.TimedRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.Arrays;
import java.util.Objects;
public class IndexUpgradeInfoRequest extends MasterNodeReadRequest<IndexUpgradeInfoRequest> implements IndicesRequest.Replaceable {
public class IndexUpgradeInfoRequest extends TimedRequest implements IndicesRequest.Replaceable {
private String[] indices = Strings.EMPTY_ARRAY;
private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, true, true, true);
@ -39,19 +35,6 @@ public class IndexUpgradeInfoRequest extends MasterNodeReadRequest<IndexUpgradeI
indices(indices);
}
public IndexUpgradeInfoRequest(StreamInput in) throws IOException {
super(in);
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
}
@Override
public String[] indices() {
return indices;
@ -72,16 +55,6 @@ public class IndexUpgradeInfoRequest extends MasterNodeReadRequest<IndexUpgradeI
this.indicesOptions = indicesOptions;
}
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void readFrom(StreamInput in) throws IOException {
throw new UnsupportedOperationException("usage of Streamable is to be replaced by Writeable");
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -16,25 +16,19 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.migration;
package org.elasticsearch.client.migration;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
public class IndexUpgradeInfoResponse extends ActionResponse implements ToXContentObject {
public class IndexUpgradeInfoResponse {
private static final ParseField INDICES = new ParseField("indices");
private static final ParseField ACTION_REQUIRED = new ParseField("action_required");
@ -70,50 +64,16 @@ public class IndexUpgradeInfoResponse extends ActionResponse implements ToXConte
}
private Map<String, UpgradeActionRequired> actions;
public IndexUpgradeInfoResponse() {
}
private final Map<String, UpgradeActionRequired> actions;
public IndexUpgradeInfoResponse(Map<String, UpgradeActionRequired> actions) {
this.actions = actions;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
actions = in.readMap(StreamInput::readString, UpgradeActionRequired::readFromStream);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(actions, StreamOutput::writeString, (out1, value) -> value.writeTo(out1));
}
public Map<String, UpgradeActionRequired> getActions() {
return actions;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
{
builder.startObject(INDICES.getPreferredName());
for (Map.Entry<String, UpgradeActionRequired> entry : actions.entrySet()) {
builder.startObject(entry.getKey());
{
builder.field(ACTION_REQUIRED.getPreferredName(), entry.getValue().toString());
}
builder.endObject();
}
builder.endObject();
}
builder.endObject();
return builder;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.migration;
package org.elasticsearch.client.migration;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;

View File

@ -21,4 +21,4 @@
* Request and Response objects for the default distribution's Migration
* APIs.
*/
package org.elasticsearch.protocol.xpack.migration;
package org.elasticsearch.client.migration;

View File

@ -21,7 +21,6 @@ package org.elasticsearch.client.watcher;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import java.util.Locale;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.client.watcher;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import java.util.Objects;

View File

@ -19,7 +19,7 @@
package org.elasticsearch.client.watcher;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.PutWatchRequest;
import java.util.Objects;
@ -27,7 +27,6 @@ public class DeactivateWatchRequest implements Validatable {
private final String watchId;
public DeactivateWatchRequest(String watchId) {
Objects.requireNonNull(watchId, "watch id is missing");
if (PutWatchRequest.isValidId(watchId) == false) {
throw new IllegalArgumentException("watch id contains whitespace");

View File

@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.client.watcher;
import org.elasticsearch.client.Validatable;
import java.util.Objects;
/**
* A delete watch request to delete an watch by name (id)
*/
public class DeleteWatchRequest implements Validatable {
private final String id;
public DeleteWatchRequest(String id) {
Objects.requireNonNull(id, "watch id is missing");
if (PutWatchRequest.isValidId(id) == false) {
throw new IllegalArgumentException("watch id contains whitespace");
}
this.id = id;
}
/**
* @return The name of the watch to be deleted
*/
public String getId() {
return id;
}
@Override
public String toString() {
return "delete [" + id + "]";
}
}

View File

@ -16,12 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -30,7 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
public class DeleteWatchResponse extends ActionResponse implements ToXContentObject {
public class DeleteWatchResponse implements ToXContentObject {
private static final ObjectParser<DeleteWatchResponse, Void> PARSER
= new ObjectParser<>("x_pack_delete_watch_response", DeleteWatchResponse::new);
@ -92,22 +89,6 @@ public class DeleteWatchResponse extends ActionResponse implements ToXContentObj
return Objects.hash(id, version, found);
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
version = in.readVLong();
found = in.readBoolean();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeVLong(version);
out.writeBoolean(found);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()

View File

@ -16,67 +16,43 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.client.Validatable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.Objects;
import java.util.regex.Pattern;
/**
* This request class contains the data needed to create a watch along with the name of the watch.
* The name of the watch will become the ID of the indexed document.
*/
public final class PutWatchRequest extends ActionRequest {
public final class PutWatchRequest implements Validatable {
private static final Pattern NO_WS_PATTERN = Pattern.compile("\\S+");
private String id;
private BytesReference source;
private XContentType xContentType = XContentType.JSON;
private final String id;
private final BytesReference source;
private final XContentType xContentType;
private boolean active = true;
private long version = Versions.MATCH_ANY;
public PutWatchRequest() {}
public PutWatchRequest(StreamInput in) throws IOException {
readFrom(in);
}
public PutWatchRequest(String id, BytesReference source, XContentType xContentType) {
Objects.requireNonNull(id, "watch id is missing");
if (isValidId(id) == false) {
throw new IllegalArgumentException("watch id contains whitespace");
}
Objects.requireNonNull(source, "watch source is missing");
Objects.requireNonNull(xContentType, "request body is missing");
this.id = id;
this.source = source;
this.xContentType = xContentType;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
source = in.readBytesReference();
active = in.readBoolean();
xContentType = in.readEnum(XContentType.class);
version = in.readZLong();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeBytesReference(source);
out.writeBoolean(active);
out.writeEnum(xContentType);
out.writeZLong(version);
}
/**
* @return The name that will be the ID of the indexed document
*/
@ -84,13 +60,6 @@ public final class PutWatchRequest extends ActionRequest {
return id;
}
/**
* Set the watch name
*/
public void setId(String id) {
this.id = id;
}
/**
* @return The source of the watch
*/
@ -98,14 +67,6 @@ public final class PutWatchRequest extends ActionRequest {
return source;
}
/**
* Set the source of the watch
*/
public void setSource(BytesReference source, XContentType xContentType) {
this.source = source;
this.xContentType = xContentType;
}
/**
* @return The initial active state of the watch (defaults to {@code true}, e.g. "active")
*/
@ -135,23 +96,6 @@ public final class PutWatchRequest extends ActionRequest {
this.version = version;
}
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (id == null) {
validationException = ValidateActions.addValidationError("watch id is missing", validationException);
} else if (isValidId(id) == false) {
validationException = ValidateActions.addValidationError("watch id contains whitespace", validationException);
}
if (source == null) {
validationException = ValidateActions.addValidationError("watch source is missing", validationException);
}
if (xContentType == null) {
validationException = ValidateActions.addValidationError("request body is missing", validationException);
}
return validationException;
}
public static boolean isValidId(String id) {
return Strings.isEmpty(id) == false && NO_WS_PATTERN.matcher(id).matches();
}

View File

@ -16,12 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -30,10 +27,11 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Objects;
public class PutWatchResponse extends ActionResponse implements ToXContentObject {
public class PutWatchResponse implements ToXContentObject {
private static final ObjectParser<PutWatchResponse, Void> PARSER
= new ObjectParser<>("x_pack_put_watch_response", PutWatchResponse::new);
static {
PARSER.declareString(PutWatchResponse::setId, new ParseField("_id"));
PARSER.declareLong(PutWatchResponse::setVersion, new ParseField("_version"));
@ -92,22 +90,6 @@ public class PutWatchResponse extends ActionResponse implements ToXContentObject
return Objects.hash(id, version, created);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeVLong(version);
out.writeBoolean(created);
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
version = in.readVLong();
created = in.readBoolean();
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()

View File

@ -21,4 +21,4 @@
* Request and Response objects for the default distribution's Watcher
* APIs.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;

View File

@ -24,17 +24,16 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
import org.elasticsearch.protocol.xpack.graph.Hop;
import org.elasticsearch.client.graph.GraphExploreRequest;
import org.elasticsearch.client.graph.Hop;
import org.elasticsearch.test.ESTestCase;
import org.junit.Assert;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.Matchers.is;
public class GrapRequestConvertersTests extends ESTestCase{
public class GrapRequestConvertersTests extends ESTestCase {
public void testGraphExplore() throws Exception {
Map<String, String> expectedParams = new HashMap<>();
@ -43,14 +42,14 @@ public class GrapRequestConvertersTests extends ESTestCase{
graphExploreRequest.sampleDiversityField("diversity");
graphExploreRequest.indices("index1", "index2");
graphExploreRequest.types("type1", "type2");
int timeout = ESTestCase.randomIntBetween(10000, 20000);
int timeout = randomIntBetween(10000, 20000);
graphExploreRequest.timeout(TimeValue.timeValueMillis(timeout));
graphExploreRequest.useSignificance(ESTestCase.randomBoolean());
int numHops = ESTestCase.randomIntBetween(1, 5);
graphExploreRequest.useSignificance(randomBoolean());
int numHops = randomIntBetween(1, 5);
for (int i = 0; i < numHops; i++) {
int hopNumber = i + 1;
QueryBuilder guidingQuery = null;
if (ESTestCase.randomBoolean()) {
if (randomBoolean()) {
guidingQuery = new TermQueryBuilder("field" + hopNumber, "value" + hopNumber);
}
Hop hop = graphExploreRequest.createNextHop(guidingQuery);
@ -58,10 +57,10 @@ public class GrapRequestConvertersTests extends ESTestCase{
hop.getVertexRequest(0).addInclude("value" + hopNumber, hopNumber);
}
Request request = GraphRequestConverters.explore(graphExploreRequest);
Assert.assertEquals(HttpGet.METHOD_NAME, request.getMethod());
Assert.assertEquals("/index1,index2/type1,type2/_xpack/graph/_explore", request.getEndpoint());
Assert.assertEquals(expectedParams, request.getParameters());
Assert.assertThat(request.getEntity().getContentType().getValue(), is(XContentType.JSON.mediaTypeWithoutParameters()));
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("/index1,index2/type1,type2/_xpack/graph/_explore", request.getEndpoint());
assertEquals(expectedParams, request.getParameters());
assertThat(request.getEntity().getContentType().getValue(), is(XContentType.JSON.mediaTypeWithoutParameters()));
RequestConvertersTests.assertToXContentBody(graphExploreRequest, request.getEntity());
}
}

View File

@ -23,11 +23,11 @@ import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
import org.elasticsearch.protocol.xpack.graph.GraphExploreResponse;
import org.elasticsearch.protocol.xpack.graph.Hop;
import org.elasticsearch.protocol.xpack.graph.Vertex;
import org.elasticsearch.protocol.xpack.graph.VertexRequest;
import org.elasticsearch.client.graph.GraphExploreRequest;
import org.elasticsearch.client.graph.GraphExploreResponse;
import org.elasticsearch.client.graph.Hop;
import org.elasticsearch.client.graph.Vertex;
import org.elasticsearch.client.graph.VertexRequest;
import org.hamcrest.Matchers;
import org.junit.Before;

View File

@ -20,8 +20,8 @@
package org.elasticsearch.client;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.client.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.client.migration.IndexUpgradeInfoResponse;
import java.io.IOException;

View File

@ -20,7 +20,7 @@
package org.elasticsearch.client;
import org.apache.http.client.methods.HttpGet;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.client.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.test.ESTestCase;
import java.util.HashMap;
@ -28,7 +28,7 @@ import java.util.Map;
public class MigrationRequestConvertersTests extends ESTestCase {
public static void testGetMigrationAssistance() {
public void testGetMigrationAssistance() {
IndexUpgradeInfoRequest upgradeInfoRequest = new IndexUpgradeInfoRequest();
String expectedEndpoint = "/_xpack/migration/assistance";
if (randomBoolean()) {

View File

@ -35,10 +35,10 @@ import org.elasticsearch.client.watcher.StopWatchServiceRequest;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchResponse;
import org.elasticsearch.client.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.PutWatchResponse;
import org.elasticsearch.rest.RestStatus;
import static org.hamcrest.Matchers.is;

View File

@ -29,8 +29,8 @@ import org.elasticsearch.client.watcher.StartWatchServiceRequest;
import org.elasticsearch.client.watcher.StopWatchServiceRequest;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
import org.elasticsearch.client.watcher.PutWatchRequest;
import org.elasticsearch.test.ESTestCase;
import java.io.ByteArrayOutputStream;
@ -56,11 +56,9 @@ public class WatcherRequestConvertersTests extends ESTestCase {
}
public void testPutWatch() throws Exception {
PutWatchRequest putWatchRequest = new PutWatchRequest();
String watchId = randomAlphaOfLength(10);
putWatchRequest.setId(watchId);
String body = randomAlphaOfLength(20);
putWatchRequest.setSource(new BytesArray(body), XContentType.JSON);
PutWatchRequest putWatchRequest = new PutWatchRequest(watchId, new BytesArray(body), XContentType.JSON);
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
@ -94,9 +92,8 @@ public class WatcherRequestConvertersTests extends ESTestCase {
}
public void testDeleteWatch() {
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest();
String watchId = randomAlphaOfLength(10);
deleteWatchRequest.setId(watchId);
DeleteWatchRequest deleteWatchRequest = new DeleteWatchRequest(watchId);
Request request = WatcherRequestConverters.deleteWatch(deleteWatchRequest);
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());

View File

@ -26,12 +26,12 @@ import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.protocol.xpack.graph.Connection;
import org.elasticsearch.protocol.xpack.graph.GraphExploreRequest;
import org.elasticsearch.protocol.xpack.graph.GraphExploreResponse;
import org.elasticsearch.protocol.xpack.graph.Hop;
import org.elasticsearch.protocol.xpack.graph.Vertex;
import org.elasticsearch.protocol.xpack.graph.VertexRequest;
import org.elasticsearch.client.graph.Connection;
import org.elasticsearch.client.graph.GraphExploreRequest;
import org.elasticsearch.client.graph.GraphExploreResponse;
import org.elasticsearch.client.graph.Hop;
import org.elasticsearch.client.graph.Vertex;
import org.elasticsearch.client.graph.VertexRequest;
import org.junit.Before;
import java.io.IOException;

View File

@ -24,9 +24,9 @@ import org.elasticsearch.client.ESRestHighLevelClientTestCase;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.protocol.xpack.migration.UpgradeActionRequired;
import org.elasticsearch.client.migration.IndexUpgradeInfoRequest;
import org.elasticsearch.client.migration.IndexUpgradeInfoResponse;
import org.elasticsearch.client.migration.UpgradeActionRequired;
import java.io.IOException;
import java.util.Map;

View File

@ -40,10 +40,10 @@ import org.elasticsearch.client.watcher.WatchStatus;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse;
import org.elasticsearch.client.watcher.DeleteWatchRequest;
import org.elasticsearch.client.watcher.DeleteWatchResponse;
import org.elasticsearch.client.watcher.PutWatchRequest;
import org.elasticsearch.client.watcher.PutWatchResponse;
import org.elasticsearch.rest.RestStatus;
import java.util.concurrent.CountDownLatch;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.graph;
package org.elasticsearch.client.graph;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ShardOperationFailedException;
@ -35,7 +35,7 @@ import java.util.function.Supplier;
import static org.hamcrest.Matchers.equalTo;
public class GraphExploreResponseTests extends AbstractXContentTestCase< GraphExploreResponse> {
public class GraphExploreResponseTests extends AbstractXContentTestCase<GraphExploreResponse> {
@Override
protected GraphExploreResponse createTestInstance() {

View File

@ -17,13 +17,16 @@
* under the License.
*/
apply plugin: 'elasticsearch.build'
package org.elasticsearch.client.migration;
description = 'Request and Response objects for x-pack that are used by the' +
' high level rest client and x-pack itself'
import org.elasticsearch.test.ESTestCase;
dependencies {
compileOnly "org.elasticsearch:elasticsearch:${version}"
public class IndexUpgradeInfoRequestTests extends ESTestCase {
testCompile "org.elasticsearch.test:framework:${version}"
// TODO: add to cross XPack-HLRC serialization test
public void testNullIndices() {
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest((String[])null));
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest().indices((String[])null));
}
}

View File

@ -17,7 +17,10 @@
* under the License.
*/
/**
* Request and Response objects for miscellaneous X-Pack APIs.
*/
package org.elasticsearch.protocol.xpack;
package org.elasticsearch.client.migration;
import org.elasticsearch.test.ESTestCase;
public class IndexUpgradeInfoResponseTests extends ESTestCase {
// TODO: add to cross XPack-HLRC serialization test
}

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractXContentTestCase;

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
package org.elasticsearch.client.watcher;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractXContentTestCase;

View File

@ -19,19 +19,15 @@
package org.elasticsearch.client.watcher;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.client.ValidationException;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest;
import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest;
import org.elasticsearch.test.ESTestCase;
import java.util.Optional;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
public class WatchRequestValidationTests extends ESTestCase {
@ -61,38 +57,38 @@ public class WatchRequestValidationTests extends ESTestCase {
}
public void testDeleteWatchInvalidWatchId() {
ActionRequestValidationException e = new DeleteWatchRequest("id with whitespaces").validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch id contains whitespace"));
final IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
() -> new DeleteWatchRequest("id with whitespaces"));
assertThat(exception.getMessage(), is("watch id contains whitespace"));
}
public void testDeleteWatchNullId() {
ActionRequestValidationException e = new DeleteWatchRequest(null).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch id is missing"));
final NullPointerException exception = expectThrows(NullPointerException.class,
() -> new DeleteWatchRequest(null));
assertThat(exception.getMessage(), is("watch id is missing"));
}
public void testPutWatchInvalidWatchId() {
ActionRequestValidationException e = new PutWatchRequest("id with whitespaces", BytesArray.EMPTY, XContentType.JSON).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch id contains whitespace"));
final IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
() -> new PutWatchRequest("id with whitespaces", BytesArray.EMPTY, XContentType.JSON));
assertThat(exception.getMessage(), is("watch id contains whitespace"));
}
public void testPutWatchNullId() {
ActionRequestValidationException e = new PutWatchRequest(null, BytesArray.EMPTY, XContentType.JSON).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch id is missing"));
final NullPointerException exception = expectThrows(NullPointerException.class,
() -> new PutWatchRequest(null, BytesArray.EMPTY, XContentType.JSON));
assertThat(exception.getMessage(), is("watch id is missing"));
}
public void testPutWatchSourceNull() {
ActionRequestValidationException e = new PutWatchRequest("foo", null, XContentType.JSON).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("watch source is missing"));
final NullPointerException exception = expectThrows(NullPointerException.class,
() -> new PutWatchRequest("foo", null, XContentType.JSON));
assertThat(exception.getMessage(), is("watch source is missing"));
}
public void testPutWatchContentNull() {
ActionRequestValidationException e = new PutWatchRequest("foo", BytesArray.EMPTY, null).validate();
assertThat(e, is(notNullValue()));
assertThat(e.validationErrors(), hasItem("request body is missing"));
final NullPointerException exception = expectThrows(NullPointerException.class,
() -> new PutWatchRequest("foo", BytesArray.EMPTY, null));
assertThat(exception.getMessage(), is("request body is missing"));
}
}

View File

@ -17,7 +17,6 @@ subprojects {
project.esplugin.noticeFile = xpackRootProject.file('NOTICE.txt')
}
if (project.name != 'protocol') {
tasks.withType(LicenseHeadersTask.class) {
approvedLicenses = ['Elastic License', 'Generated']
additionalLicense 'ELAST', 'Elastic License', 'Licensed under the Elastic License'
@ -28,7 +27,6 @@ subprojects {
project.ext.licenseFile = rootProject.file('licenses/ELASTIC-LICENSE.txt')
project.ext.noticeFile = xpackRootProject.file('NOTICE.txt')
}
}
subprojects {

View File

@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,89 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.watcher;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ValidateActions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import java.io.IOException;
/**
* A delete watch request to delete an watch by name (id)
*/
public class DeleteWatchRequest extends ActionRequest {
private String id;
private long version = Versions.MATCH_ANY;
public DeleteWatchRequest() {
this(null);
}
public DeleteWatchRequest(String id) {
this.id = id;
}
/**
* @return The name of the watch to be deleted
*/
public String getId() {
return id;
}
/**
* Sets the name of the watch to be deleted
*/
public void setId(String id) {
this.id = id;
}
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (id == null){
validationException = ValidateActions.addValidationError("watch id is missing", validationException);
} else if (PutWatchRequest.isValidId(id) == false) {
validationException = ValidateActions.addValidationError("watch id contains whitespace", validationException);
}
return validationException;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
id = in.readString();
version = in.readLong();
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(id);
out.writeLong(version);
}
@Override
public String toString() {
return "delete [" + id + "]";
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.migration;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
public class IndexUpgradeInfoRequestTests extends AbstractWireSerializingTestCase<IndexUpgradeInfoRequest> {
@Override
protected IndexUpgradeInfoRequest createTestInstance() {
int indexCount = randomInt(4);
String[] indices = new String[indexCount];
for (int i = 0; i < indexCount; i++) {
indices[i] = randomAlphaOfLength(10);
}
IndexUpgradeInfoRequest request = new IndexUpgradeInfoRequest(indices);
if (randomBoolean()) {
request.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
}
return request;
}
@Override
protected Writeable.Reader<IndexUpgradeInfoRequest> instanceReader() {
return IndexUpgradeInfoRequest::new;
}
public void testNullIndices() {
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest((String[])null));
expectThrows(NullPointerException.class, () -> new IndexUpgradeInfoRequest().indices((String[])null));
}
}

View File

@ -1,68 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.protocol.xpack.migration;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractStreamableXContentTestCase;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class IndexUpgradeInfoResponseTests extends AbstractStreamableXContentTestCase<IndexUpgradeInfoResponse> {
@Override
protected IndexUpgradeInfoResponse doParseInstance(XContentParser parser) {
return IndexUpgradeInfoResponse.fromXContent(parser);
}
@Override
protected IndexUpgradeInfoResponse createBlankInstance() {
return new IndexUpgradeInfoResponse();
}
@Override
protected IndexUpgradeInfoResponse createTestInstance() {
return randomIndexUpgradeInfoResponse(randomIntBetween(0, 10));
}
private static IndexUpgradeInfoResponse randomIndexUpgradeInfoResponse(int numIndices) {
Map<String, UpgradeActionRequired> actions = new HashMap<>();
for (int i = 0; i < numIndices; i++) {
actions.put(randomAlphaOfLength(5), randomFrom(UpgradeActionRequired.values()));
}
return new IndexUpgradeInfoResponse(actions);
}
@Override
protected IndexUpgradeInfoResponse mutateInstance(IndexUpgradeInfoResponse instance) {
if (instance.getActions().size() == 0) {
return randomIndexUpgradeInfoResponse(1);
}
Map<String, UpgradeActionRequired> actions = new HashMap<>(instance.getActions());
if (randomBoolean()) {
Iterator<Map.Entry<String, UpgradeActionRequired>> iterator = actions.entrySet().iterator();
iterator.next();
iterator.remove();
} else {
actions.put(randomAlphaOfLength(5), randomFrom(UpgradeActionRequired.values()));
}
return new IndexUpgradeInfoResponse(actions);
}
}