-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML-Dataframe] Add Data Frame client to the Java HLRC (#39921)
Adds DataFrameClient to the Java HLRC and implements PUT and DELETE data frame transform.
- Loading branch information
Showing
16 changed files
with
937 additions
and
4 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
client/rest-high-level/src/main/java/org/elasticsearch/client/DataFrameClient.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,118 @@ | ||
/* | ||
* 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; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.client.core.AcknowledgedResponse; | ||
import org.elasticsearch.client.dataframe.DeleteDataFrameTransformRequest; | ||
import org.elasticsearch.client.dataframe.PutDataFrameTransformRequest; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
|
||
public final class DataFrameClient { | ||
|
||
private final RestHighLevelClient restHighLevelClient; | ||
|
||
DataFrameClient(RestHighLevelClient restHighLevelClient) { | ||
this.restHighLevelClient = restHighLevelClient; | ||
} | ||
|
||
/** | ||
* Creates a new Data Frame Transform | ||
* <p> | ||
* For additional info | ||
* see <a href="https://www.TODO.com">Data Frame PUT transform documentation</a> | ||
* | ||
* @param request The PutDataFrameTransformRequest containing the | ||
* {@link org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfig}. | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @return An AcknowledgedResponse object indicating request success | ||
* @throws IOException when there is a serialization issue sending the request or receiving the response | ||
*/ | ||
public AcknowledgedResponse putDataFrameTransform(PutDataFrameTransformRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, | ||
DataFrameRequestConverters::putDataFrameTransform, | ||
options, | ||
AcknowledgedResponse::fromXContent, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Creates a new Data Frame Transform asynchronously and notifies listener on completion | ||
* <p> | ||
* For additional info | ||
* see <a href="https://www.TODO.com">Data Frame PUT transform documentation</a> | ||
* | ||
* @param request The PutDataFrameTransformRequest containing the | ||
* {@link org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfig}. | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @param listener Listener to be notified upon request completion | ||
*/ | ||
public void putDataFrameTransformAsync(PutDataFrameTransformRequest request, RequestOptions options, | ||
ActionListener<AcknowledgedResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, | ||
DataFrameRequestConverters::putDataFrameTransform, | ||
options, | ||
AcknowledgedResponse::fromXContent, | ||
listener, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Delete a data frame transform | ||
* <p> | ||
* For additional info | ||
* see <a href="https://www.TODO.com">Data Frame delete transform documentation</a> | ||
* | ||
* @param request The delete data frame transform request | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @return An AcknowledgedResponse object indicating request success | ||
* @throws IOException when there is a serialization issue sending the request or receiving the response | ||
*/ | ||
public AcknowledgedResponse deleteDataFrameTransform(DeleteDataFrameTransformRequest request, RequestOptions options) | ||
throws IOException { | ||
return restHighLevelClient.performRequestAndParseEntity(request, | ||
DataFrameRequestConverters::deleteDataFrameTransform, | ||
options, | ||
AcknowledgedResponse::fromXContent, | ||
Collections.emptySet()); | ||
} | ||
|
||
/** | ||
* Delete a data frame transform asynchronously and notifies listener on completion | ||
* <p> | ||
* For additional info | ||
* see <a href="https://www.TODO.com">Data Frame delete transform documentation</a> | ||
* | ||
* @param request The delete data frame transform request | ||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized | ||
* @param listener Listener to be notified upon request completion | ||
*/ | ||
public void deleteDataFrameTransformAsync(DeleteDataFrameTransformRequest request, RequestOptions options, | ||
ActionListener<AcknowledgedResponse> listener) { | ||
restHighLevelClient.performRequestAsyncAndParseEntity(request, | ||
DataFrameRequestConverters::deleteDataFrameTransform, | ||
options, | ||
AcknowledgedResponse::fromXContent, | ||
listener, | ||
Collections.emptySet()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...nt/rest-high-level/src/main/java/org/elasticsearch/client/DataFrameRequestConverters.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,53 @@ | ||
/* | ||
* 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; | ||
|
||
import org.apache.http.client.methods.HttpDelete; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.elasticsearch.client.dataframe.DeleteDataFrameTransformRequest; | ||
import org.elasticsearch.client.dataframe.PutDataFrameTransformRequest; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE; | ||
import static org.elasticsearch.client.RequestConverters.createEntity; | ||
|
||
final class DataFrameRequestConverters { | ||
|
||
private DataFrameRequestConverters() {} | ||
|
||
static Request putDataFrameTransform(PutDataFrameTransformRequest putRequest) throws IOException { | ||
String endpoint = new RequestConverters.EndpointBuilder() | ||
.addPathPartAsIs("_data_frame", "transforms") | ||
.addPathPart(putRequest.getConfig().getId()) | ||
.build(); | ||
Request request = new Request(HttpPut.METHOD_NAME, endpoint); | ||
request.setEntity(createEntity(putRequest, REQUEST_BODY_CONTENT_TYPE)); | ||
return request; | ||
} | ||
|
||
static Request deleteDataFrameTransform(DeleteDataFrameTransformRequest request) { | ||
String endpoint = new RequestConverters.EndpointBuilder() | ||
.addPathPartAsIs("_data_frame", "transforms") | ||
.addPathPart(request.getId()) | ||
.build(); | ||
return new Request(HttpDelete.METHOD_NAME, endpoint); | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...vel/src/main/java/org/elasticsearch/client/dataframe/DeleteDataFrameTransformRequest.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,72 @@ | ||
/* | ||
* 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.dataframe; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
|
||
/** | ||
* Request to delete a data frame transform | ||
*/ | ||
public class DeleteDataFrameTransformRequest implements Validatable { | ||
|
||
private final String id; | ||
|
||
public DeleteDataFrameTransformRequest(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
if (id == null) { | ||
ValidationException validationException = new ValidationException(); | ||
validationException.addValidationError("data frame transform id must not be null"); | ||
return Optional.of(validationException); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
DeleteDataFrameTransformRequest other = (DeleteDataFrameTransformRequest) obj; | ||
return Objects.equals(id, other.id); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...-level/src/main/java/org/elasticsearch/client/dataframe/PutDataFrameTransformRequest.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,63 @@ | ||
/* | ||
* 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.dataframe; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfig; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class PutDataFrameTransformRequest implements ToXContentObject, Validatable { | ||
|
||
private final DataFrameTransformConfig config; | ||
|
||
public PutDataFrameTransformRequest(DataFrameTransformConfig config) { | ||
this.config = config; | ||
} | ||
|
||
public DataFrameTransformConfig getConfig() { | ||
return config; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return config.toXContent(builder, params); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(config); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
PutDataFrameTransformRequest other = (PutDataFrameTransformRequest) obj; | ||
return Objects.equals(config, other.config); | ||
} | ||
} |
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
Oops, something went wrong.