Skip to content

Commit

Permalink
XPack/HLRC request/response compatibility tests (#34547)
Browse files Browse the repository at this point in the history
Relates #34451 , #29827
  • Loading branch information
vladimirdolzhenko committed Oct 31, 2018
1 parent 674225a commit 28bb1a3
Show file tree
Hide file tree
Showing 25 changed files with 600 additions and 228 deletions.
Expand Up @@ -44,7 +44,7 @@ public class GraphClient {
public final GraphExploreResponse explore(GraphExploreRequest graphExploreRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(graphExploreRequest, GraphRequestConverters::explore,
options, GraphExploreResponse::fromXContext, emptySet());
options, GraphExploreResponse::fromXContent, emptySet());
}

/**
Expand All @@ -57,7 +57,7 @@ public final void exploreAsync(GraphExploreRequest graphExploreRequest,
RequestOptions options,
ActionListener<GraphExploreResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(graphExploreRequest, GraphRequestConverters::explore,
options, GraphExploreResponse::fromXContext, listener, emptySet());
options, GraphExploreResponse::fromXContent, listener, emptySet());
}

}
Expand Up @@ -47,7 +47,7 @@
*
* @see GraphExploreRequest
*/
public class GraphExploreResponse implements ToXContentObject {
public class GraphExploreResponse implements ToXContentObject {

private long tookInMillis;
private boolean timedOut = false;
Expand Down Expand Up @@ -94,14 +94,30 @@ public Collection<Connection> getConnections() {
return connections.values();
}

public Collection<ConnectionId> getConnectionIds() {
return connections.keySet();
}

public Connection getConnection(ConnectionId connectionId) {
return connections.get(connectionId);
}

public Collection<Vertex> getVertices() {
return vertices.values();
}


public Collection<VertexId> getVertexIds() {
return vertices.keySet();
}

public Vertex getVertex(VertexId id) {
return vertices.get(id);
}

public boolean isReturnDetailedInfo() {
return 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");
Expand Down Expand Up @@ -190,7 +206,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> ShardSearchFailure.fromXContent(p), FAILURES);
}

public static GraphExploreResponse fromXContext(XContentParser parser) throws IOException {
public static GraphExploreResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.apply(parser, null);
}

Expand Down
Expand Up @@ -220,6 +220,14 @@ public VertexId(String field, String term) {
this.term = term;
}

public String getField() {
return field;
}

public String getTerm() {
return term;
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down
Expand Up @@ -84,14 +84,13 @@ public class StartBasicResponse {
}
}
return new Tuple<>(message, acknowledgeMessages);
},
new ParseField("acknowledge"));
}, new ParseField("acknowledge"));
}

private Map<String, String[]> acknowledgeMessages;
private String acknowledgeMessage;

enum Status {
public enum Status {
GENERATED_BASIC(true, null, RestStatus.OK),
ALREADY_USING_BASIC(false, "Operation failed: Current license is basic.", RestStatus.FORBIDDEN),
NEED_ACKNOWLEDGEMENT(false, "Operation failed: Needs acknowledgement.", RestStatus.OK);
Expand Down Expand Up @@ -141,6 +140,10 @@ public StartBasicResponse() {
this.acknowledgeMessage = acknowledgeMessage;
}

public Status getStatus() {
return status;
}

public boolean isAcknowledged() {
return status != StartBasicResponse.Status.NEED_ACKNOWLEDGEMENT;
}
Expand Down
Expand Up @@ -18,17 +18,12 @@
*/
package org.elasticsearch.client.migration;

import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;

import java.io.IOException;
import java.util.Locale;

/**
* Indicates the type of the upgrade required for the index
*/
public enum UpgradeActionRequired implements Writeable {
public enum UpgradeActionRequired {
NOT_APPLICABLE, // Indicates that the check is not applicable to this index type, the next check will be performed
UP_TO_DATE, // Indicates that the check finds this index to be up to date - no additional checks are required
REINDEX, // The index should be reindex
Expand All @@ -38,15 +33,6 @@ public static UpgradeActionRequired fromString(String value) {
return UpgradeActionRequired.valueOf(value.toUpperCase(Locale.ROOT));
}

public static UpgradeActionRequired readFromStream(StreamInput in) throws IOException {
return in.readEnum(UpgradeActionRequired.class);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeEnum(this);
}

@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
Expand Down
Expand Up @@ -21,9 +21,6 @@
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -252,7 +249,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
}

public static class BuildInfo implements ToXContentObject, Writeable {
public static class BuildInfo implements ToXContentObject {
private final String hash;
private final String timestamp;

Expand All @@ -261,16 +258,6 @@ public BuildInfo(String hash, String timestamp) {
this.timestamp = timestamp;
}

public BuildInfo(StreamInput input) throws IOException {
this(input.readString(), input.readString());
}

@Override
public void writeTo(StreamOutput output) throws IOException {
output.writeString(hash);
output.writeString(timestamp);
}

public String getHash() {
return hash;
}
Expand Down Expand Up @@ -309,7 +296,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}
}

public static class FeatureSetsInfo implements ToXContentObject, Writeable {
public static class FeatureSetsInfo implements ToXContentObject {
private final Map<String, FeatureSet> featureSets;

public FeatureSetsInfo(Set<FeatureSet> featureSets) {
Expand All @@ -320,24 +307,6 @@ public FeatureSetsInfo(Set<FeatureSet> featureSets) {
this.featureSets = Collections.unmodifiableMap(map);
}

public FeatureSetsInfo(StreamInput in) throws IOException {
int size = in.readVInt();
Map<String, FeatureSet> featureSets = new HashMap<>(size);
for (int i = 0; i < size; i++) {
FeatureSet featureSet = new FeatureSet(in);
featureSets.put(featureSet.name, featureSet);
}
this.featureSets = Collections.unmodifiableMap(featureSets);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(featureSets.size());
for (FeatureSet featureSet : featureSets.values()) {
featureSet.writeTo(out);
}
}

public Map<String, FeatureSet> getFeatureSets() {
return featureSets;
}
Expand Down Expand Up @@ -365,7 +334,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.endObject();
}

public static class FeatureSet implements ToXContentObject, Writeable {
public static class FeatureSet implements ToXContentObject {
private final String name;
@Nullable private final String description;
private final boolean available;
Expand All @@ -381,19 +350,6 @@ public FeatureSet(String name, @Nullable String description, boolean available,
this.nativeCodeInfo = nativeCodeInfo;
}

public FeatureSet(StreamInput in) throws IOException {
this(in.readString(), in.readOptionalString(), in.readBoolean(), in.readBoolean(), in.readMap());
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
out.writeOptionalString(description);
out.writeBoolean(available);
out.writeBoolean(enabled);
out.writeMap(nativeCodeInfo);
}

public String name() {
return name;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public class XPackUsageResponse {

private final Map<String, Map<String, Object>> usages;

private XPackUsageResponse(Map<String, Map<String, Object>> usages) throws IOException {
private XPackUsageResponse(Map<String, Map<String, Object>> usages) {
this.usages = usages;
}

Expand Down
Expand Up @@ -81,7 +81,7 @@ private static GraphExploreResponse createTestInstanceWithFailures() {

@Override
protected GraphExploreResponse doParseInstance(XContentParser parser) throws IOException {
return GraphExploreResponse.fromXContext(parser);
return GraphExploreResponse.fromXContent(parser);
}

@Override
Expand Down

This file was deleted.

Expand Up @@ -23,8 +23,6 @@

public class IndexUpgradeInfoRequestTests extends ESTestCase {

// 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));
Expand Down

0 comments on commit 28bb1a3

Please sign in to comment.