forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLRC][ML] Add ML put datafeed API to HLRC (elastic#33603)
This also changes both `DatafeedConfig` and `DatafeedUpdate` to store the query and aggs as a bytes reference. This allows the client to remove its dependency to the named objects registry of the search module. Relates elastic#29827
- Loading branch information
1 parent
7e195c2
commit 2eb2313
Showing
16 changed files
with
793 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/PutDatafeedRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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.ml; | ||
|
||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.client.ml.datafeed.DatafeedConfig; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Request to create a new Machine Learning Datafeed given a {@link DatafeedConfig} configuration | ||
*/ | ||
public class PutDatafeedRequest extends ActionRequest implements ToXContentObject { | ||
|
||
private final DatafeedConfig datafeed; | ||
|
||
/** | ||
* Construct a new PutDatafeedRequest | ||
* | ||
* @param datafeed a {@link DatafeedConfig} configuration to create | ||
*/ | ||
public PutDatafeedRequest(DatafeedConfig datafeed) { | ||
this.datafeed = datafeed; | ||
} | ||
|
||
public DatafeedConfig getDatafeed() { | ||
return datafeed; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return datafeed.toXContent(builder, params); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
|
||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
|
||
PutDatafeedRequest request = (PutDatafeedRequest) object; | ||
return Objects.equals(datafeed, request.datafeed); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(datafeed); | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return Strings.toString(this); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
client/rest-high-level/src/main/java/org/elasticsearch/client/ml/PutDatafeedResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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.ml; | ||
|
||
import org.elasticsearch.client.ml.datafeed.DatafeedConfig; | ||
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.Objects; | ||
|
||
/** | ||
* Response containing the newly created {@link DatafeedConfig} | ||
*/ | ||
public class PutDatafeedResponse implements ToXContentObject { | ||
|
||
private DatafeedConfig datafeed; | ||
|
||
public static PutDatafeedResponse fromXContent(XContentParser parser) throws IOException { | ||
return new PutDatafeedResponse(DatafeedConfig.PARSER.parse(parser, null).build()); | ||
} | ||
|
||
PutDatafeedResponse(DatafeedConfig datafeed) { | ||
this.datafeed = datafeed; | ||
} | ||
|
||
public DatafeedConfig getResponse() { | ||
return datafeed; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
datafeed.toXContent(builder, params); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (object == null || getClass() != object.getClass()) { | ||
return false; | ||
} | ||
PutDatafeedResponse response = (PutDatafeedResponse) object; | ||
return Objects.equals(datafeed, response.datafeed); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(datafeed); | ||
} | ||
} |
Oops, something went wrong.