Convert PutModelDescription response from SingleDoc to simple, inlined model (elastic/elasticsearch#424)

Original commit: elastic/x-pack-elasticsearch@1d28285e77
This commit is contained in:
Zachary Tong 2016-11-30 09:48:49 -05:00 committed by GitHub
parent 211d787f33
commit 7c9f65231a
2 changed files with 22 additions and 12 deletions

View File

@ -16,6 +16,7 @@ import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.stream.StreamInput;
@ -162,45 +163,51 @@ PutModelSnapshotDescriptionAction.RequestBuilder> {
public static class Response extends ActionResponse implements StatusToXContent {
private SingleDocument<ModelSnapshot> response;
private static final ParseField ACKNOWLEDGED = new ParseField("acknowledged");
private static final ParseField MODEL = new ParseField("model");
private ModelSnapshot model;
Response() {
public Response() {
response = SingleDocument.empty(ModelSnapshot.TYPE.getPreferredName());
}
public Response(ModelSnapshot modelSnapshot) {
response = new SingleDocument<>(ModelSnapshot.TYPE.getPreferredName(), modelSnapshot);
model = modelSnapshot;
}
public SingleDocument<ModelSnapshot> getResponse() {
return response;
public ModelSnapshot getModel() {
return model;
}
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
response = new SingleDocument<>(in, ModelSnapshot::new);
model = new ModelSnapshot(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
response.writeTo(out);
model.writeTo(out);
}
@Override
public RestStatus status() {
return response.status();
return RestStatus.OK;
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return response.toXContent(builder, params);
builder.field(ACKNOWLEDGED.getPreferredName(), true);
builder.field(MODEL.getPreferredName());
builder = model.toXContent(builder, params);
return builder;
}
@Override
public int hashCode() {
return Objects.hash(response);
return Objects.hash(model);
}
@Override
@ -212,7 +219,7 @@ PutModelSnapshotDescriptionAction.RequestBuilder> {
return false;
}
Response other = (Response) obj;
return Objects.equals(response, other.response);
return Objects.equals(model, other.model);
}
@SuppressWarnings("deprecation")

View File

@ -72,6 +72,9 @@ setup:
"description": "new_description"
}
- match: { acknowledged: true }
- match: { model.description: "new_description" }
- do:
indices.refresh:
index: prelertresults-foo