Convert PutModelDescription response from SingleDoc to simple, inlined model (elastic/elasticsearch#424)
Original commit: elastic/x-pack-elasticsearch@1d28285e77
This commit is contained in:
parent
211d787f33
commit
7c9f65231a
|
@ -16,6 +16,7 @@ import org.elasticsearch.action.support.ActionFilters;
|
||||||
import org.elasticsearch.action.support.HandledTransportAction;
|
import org.elasticsearch.action.support.HandledTransportAction;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -162,45 +163,51 @@ PutModelSnapshotDescriptionAction.RequestBuilder> {
|
||||||
|
|
||||||
public static class Response extends ActionResponse implements StatusToXContent {
|
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) {
|
public Response(ModelSnapshot modelSnapshot) {
|
||||||
response = new SingleDocument<>(ModelSnapshot.TYPE.getPreferredName(), modelSnapshot);
|
model = modelSnapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingleDocument<ModelSnapshot> getResponse() {
|
public ModelSnapshot getModel() {
|
||||||
return response;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFrom(StreamInput in) throws IOException {
|
public void readFrom(StreamInput in) throws IOException {
|
||||||
super.readFrom(in);
|
super.readFrom(in);
|
||||||
response = new SingleDocument<>(in, ModelSnapshot::new);
|
model = new ModelSnapshot(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
super.writeTo(out);
|
super.writeTo(out);
|
||||||
response.writeTo(out);
|
model.writeTo(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RestStatus status() {
|
public RestStatus status() {
|
||||||
return response.status();
|
return RestStatus.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(response);
|
return Objects.hash(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,7 +219,7 @@ PutModelSnapshotDescriptionAction.RequestBuilder> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Response other = (Response) obj;
|
Response other = (Response) obj;
|
||||||
return Objects.equals(response, other.response);
|
return Objects.equals(model, other.model);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
|
|
@ -72,6 +72,9 @@ setup:
|
||||||
"description": "new_description"
|
"description": "new_description"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- match: { acknowledged: true }
|
||||||
|
- match: { model.description: "new_description" }
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
indices.refresh:
|
indices.refresh:
|
||||||
index: prelertresults-foo
|
index: prelertresults-foo
|
||||||
|
|
Loading…
Reference in New Issue