Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
HLRC XPack Protocol clean up: Migration; Graph; Watcher (elastic#34639)
Browse files Browse the repository at this point in the history
Move parts related to XPack for packages Migration; Graph; Watcher from protocol to client

Drop protocol module

Relates elastic#34451
  • Loading branch information
vladimirdolzhenko committed Oct 29, 2018
1 parent 8d7889d commit 69fe9a1
Show file tree
Hide file tree
Showing 46 changed files with 216 additions and 982 deletions.
1 change: 0 additions & 1 deletion client/rest-high-level/build.gradle
Expand Up @@ -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}"
Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -20,15 +20,15 @@
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 {

private 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);
Expand Down
Expand Up @@ -28,10 +28,10 @@
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;

Expand Down
Expand Up @@ -30,8 +30,8 @@
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 {

Expand Down Expand Up @@ -59,9 +59,7 @@ static Request stopWatchService(StopWatchServiceRequest stopWatchServiceRequest)

static Request putWatch(PutWatchRequest putWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(putWatchRequest.getId())
.build();

Expand Down Expand Up @@ -89,9 +87,7 @@ static Request deactivateWatch(DeactivateWatchRequest deactivateWatchRequest) {

static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack")
.addPathPartAsIs("watcher")
.addPathPartAsIs("watch")
.addPathPartAsIs("_xpack", "watcher", "watch")
.addPathPart(deleteWatchRequest.getId())
.build();

Expand All @@ -101,9 +97,7 @@ static Request deleteWatch(DeleteWatchRequest deleteWatchRequest) {

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())
Expand All @@ -114,9 +108,7 @@ public static Request ackWatch(AckWatchRequest ackWatchRequest) {

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();
Expand Down
Expand Up @@ -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;
Expand All @@ -55,25 +52,9 @@ public Connection(Vertex from, Vertex to, double weight, long docCount) {
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());
}
Expand Down
Expand Up @@ -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;
Expand All @@ -37,14 +36,14 @@
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";
Expand Down Expand Up @@ -74,15 +73,15 @@ public GraphExploreRequest(String... indices) {
}

@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
Expand Down Expand Up @@ -159,55 +158,6 @@ public GraphExploreRequest timeout(String timeout) {
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) + "]";
Expand Down

0 comments on commit 69fe9a1

Please sign in to comment.