This commit is contained in:
parent
88641a08af
commit
80dd0a0948
|
@ -39,7 +39,6 @@ import org.elasticsearch.client.ml.DeleteFilterRequest;
|
|||
import org.elasticsearch.client.ml.DeleteForecastRequest;
|
||||
import org.elasticsearch.client.ml.DeleteJobRequest;
|
||||
import org.elasticsearch.client.ml.DeleteModelSnapshotRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageRequest;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameRequest;
|
||||
import org.elasticsearch.client.ml.FindFileStructureRequest;
|
||||
import org.elasticsearch.client.ml.FlushJobRequest;
|
||||
|
@ -701,7 +700,7 @@ final class MLRequestConverters {
|
|||
return request;
|
||||
}
|
||||
|
||||
static Request estimateMemoryUsage(EstimateMemoryUsageRequest estimateRequest) throws IOException {
|
||||
static Request estimateMemoryUsage(PutDataFrameAnalyticsRequest estimateRequest) throws IOException {
|
||||
String endpoint = new EndpointBuilder()
|
||||
.addPathPartAsIs("_ml", "data_frame", "analytics", "_estimate_memory_usage")
|
||||
.build();
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.client.ml.DeleteForecastRequest;
|
|||
import org.elasticsearch.client.ml.DeleteJobRequest;
|
||||
import org.elasticsearch.client.ml.DeleteJobResponse;
|
||||
import org.elasticsearch.client.ml.DeleteModelSnapshotRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageResponse;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameRequest;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameResponse;
|
||||
|
@ -2195,14 +2194,15 @@ public final class MachineLearningClient {
|
|||
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/estimate-memory-usage-dfanalytics.html">
|
||||
* Estimate Memory Usage for Data Frame Analytics documentation</a>
|
||||
*
|
||||
* @param request The {@link EstimateMemoryUsageRequest}
|
||||
* @param request The {@link PutDataFrameAnalyticsRequest}
|
||||
* @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
|
||||
* @return {@link EstimateMemoryUsageResponse} response object
|
||||
* @throws IOException when there is a serialization issue sending the request or receiving the response
|
||||
*/
|
||||
public EstimateMemoryUsageResponse estimateMemoryUsage(EstimateMemoryUsageRequest request,
|
||||
public EstimateMemoryUsageResponse estimateMemoryUsage(PutDataFrameAnalyticsRequest request,
|
||||
RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request,
|
||||
return restHighLevelClient.performRequestAndParseEntity(
|
||||
request,
|
||||
MLRequestConverters::estimateMemoryUsage,
|
||||
options,
|
||||
EstimateMemoryUsageResponse::fromXContent,
|
||||
|
@ -2216,13 +2216,14 @@ public final class MachineLearningClient {
|
|||
* see <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/estimate-memory-usage-dfanalytics.html">
|
||||
* Estimate Memory Usage for Data Frame Analytics documentation</a>
|
||||
*
|
||||
* @param request The {@link EstimateMemoryUsageRequest}
|
||||
* @param request The {@link PutDataFrameAnalyticsRequest}
|
||||
* @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 estimateMemoryUsageAsync(EstimateMemoryUsageRequest request, RequestOptions options,
|
||||
public void estimateMemoryUsageAsync(PutDataFrameAnalyticsRequest request, RequestOptions options,
|
||||
ActionListener<EstimateMemoryUsageResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request,
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(
|
||||
request,
|
||||
MLRequestConverters::estimateMemoryUsage,
|
||||
options,
|
||||
EstimateMemoryUsageResponse::fromXContent,
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* 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.Validatable;
|
||||
import org.elasticsearch.client.ml.dataframe.DataFrameAnalyticsConfig;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
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;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
|
||||
public class EstimateMemoryUsageRequest implements ToXContentObject, Validatable {
|
||||
|
||||
private static final ParseField DATA_FRAME_ANALYTICS_CONFIG = new ParseField("data_frame_analytics_config");
|
||||
|
||||
private static final ConstructingObjectParser<EstimateMemoryUsageRequest, Void> PARSER =
|
||||
new ConstructingObjectParser<>(
|
||||
"estimate_memory_usage_request",
|
||||
true,
|
||||
args -> {
|
||||
DataFrameAnalyticsConfig config = (DataFrameAnalyticsConfig) args[0];
|
||||
return new EstimateMemoryUsageRequest(config);
|
||||
});
|
||||
|
||||
static {
|
||||
PARSER.declareObject(constructorArg(), (p, c) -> DataFrameAnalyticsConfig.fromXContent(p), DATA_FRAME_ANALYTICS_CONFIG);
|
||||
}
|
||||
|
||||
public static EstimateMemoryUsageRequest fromXContent(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
private final DataFrameAnalyticsConfig config;
|
||||
|
||||
public EstimateMemoryUsageRequest(DataFrameAnalyticsConfig config) {
|
||||
this.config = Objects.requireNonNull(config);
|
||||
}
|
||||
|
||||
public DataFrameAnalyticsConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(DATA_FRAME_ANALYTICS_CONFIG.getPreferredName(), config);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EstimateMemoryUsageRequest that = (EstimateMemoryUsageRequest) other;
|
||||
return Objects.equals(config, that.config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(config);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,6 @@ import org.elasticsearch.client.ml.DeleteFilterRequest;
|
|||
import org.elasticsearch.client.ml.DeleteForecastRequest;
|
||||
import org.elasticsearch.client.ml.DeleteJobRequest;
|
||||
import org.elasticsearch.client.ml.DeleteModelSnapshotRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageRequest;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameRequest;
|
||||
import org.elasticsearch.client.ml.FindFileStructureRequest;
|
||||
import org.elasticsearch.client.ml.FindFileStructureRequestTests;
|
||||
|
@ -797,13 +796,13 @@ public class MLRequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testEstimateMemoryUsage() throws IOException {
|
||||
EstimateMemoryUsageRequest estimateRequest = new EstimateMemoryUsageRequest(randomDataFrameAnalyticsConfig());
|
||||
PutDataFrameAnalyticsRequest estimateRequest = new PutDataFrameAnalyticsRequest(randomDataFrameAnalyticsConfig());
|
||||
Request request = MLRequestConverters.estimateMemoryUsage(estimateRequest);
|
||||
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/_ml/data_frame/analytics/_estimate_memory_usage", request.getEndpoint());
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, request.getEntity().getContent())) {
|
||||
EstimateMemoryUsageRequest parsedRequest = EstimateMemoryUsageRequest.fromXContent(parser);
|
||||
assertThat(parsedRequest, equalTo(estimateRequest));
|
||||
DataFrameAnalyticsConfig parsedConfig = DataFrameAnalyticsConfig.fromXContent(parser);
|
||||
assertThat(parsedConfig, equalTo(estimateRequest.getConfig()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.elasticsearch.client.ml.DeleteForecastRequest;
|
|||
import org.elasticsearch.client.ml.DeleteJobRequest;
|
||||
import org.elasticsearch.client.ml.DeleteJobResponse;
|
||||
import org.elasticsearch.client.ml.DeleteModelSnapshotRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageRequest;
|
||||
import org.elasticsearch.client.ml.EstimateMemoryUsageResponse;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameRequest;
|
||||
import org.elasticsearch.client.ml.EvaluateDataFrameResponse;
|
||||
|
@ -1731,8 +1730,8 @@ public class MachineLearningIT extends ESRestHighLevelClientTestCase {
|
|||
highLevelClient().bulk(bulk1, RequestOptions.DEFAULT);
|
||||
|
||||
MachineLearningClient machineLearningClient = highLevelClient().machineLearning();
|
||||
EstimateMemoryUsageRequest estimateMemoryUsageRequest =
|
||||
new EstimateMemoryUsageRequest(
|
||||
PutDataFrameAnalyticsRequest estimateMemoryUsageRequest =
|
||||
new PutDataFrameAnalyticsRequest(
|
||||
DataFrameAnalyticsConfig.builder()
|
||||
.setSource(DataFrameAnalyticsSource.builder().setIndex(indexName).build())
|
||||
.setAnalysis(OutlierDetection.createDefault())
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.dataframe.DataFrameAnalyticsConfigTests;
|
||||
import org.elasticsearch.client.ml.dataframe.MlDataFrameAnalysisNamedXContentProvider;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class EstimateMemoryUsageRequestTests extends AbstractXContentTestCase<EstimateMemoryUsageRequest> {
|
||||
|
||||
public static EstimateMemoryUsageRequest randomRequest() {
|
||||
return new EstimateMemoryUsageRequest(DataFrameAnalyticsConfigTests.randomDataFrameAnalyticsConfig());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EstimateMemoryUsageRequest createTestInstance() {
|
||||
return randomRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EstimateMemoryUsageRequest doParseInstance(XContentParser parser) throws IOException {
|
||||
return EstimateMemoryUsageRequest.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Predicate<String> getRandomFieldsExcludeFilter() {
|
||||
return field -> field.contains(".");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> namedXContent = new ArrayList<>();
|
||||
namedXContent.addAll(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedXContents());
|
||||
namedXContent.addAll(new MlDataFrameAnalysisNamedXContentProvider().getNamedXContentParsers());
|
||||
return new NamedXContentRegistry(namedXContent);
|
||||
}
|
||||
}
|
|
@ -5,8 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.core.ml.action;
|
||||
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.ActionType;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -18,14 +16,10 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|||
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
|
||||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
||||
|
||||
public class EstimateMemoryUsageAction extends ActionType<EstimateMemoryUsageAction.Response> {
|
||||
|
@ -37,80 +31,6 @@ public class EstimateMemoryUsageAction extends ActionType<EstimateMemoryUsageAct
|
|||
super(NAME, EstimateMemoryUsageAction.Response::new);
|
||||
}
|
||||
|
||||
public static class Request extends ActionRequest implements ToXContentObject {
|
||||
|
||||
private static final ParseField DATA_FRAME_ANALYTICS_CONFIG = new ParseField("data_frame_analytics_config");
|
||||
|
||||
private static final ConstructingObjectParser<EstimateMemoryUsageAction.Request, Void> PARSER =
|
||||
new ConstructingObjectParser<>(
|
||||
NAME,
|
||||
args -> {
|
||||
DataFrameAnalyticsConfig.Builder configBuilder = (DataFrameAnalyticsConfig.Builder) args[0];
|
||||
DataFrameAnalyticsConfig config = configBuilder.buildForMemoryEstimation();
|
||||
return new EstimateMemoryUsageAction.Request(config);
|
||||
});
|
||||
|
||||
static {
|
||||
PARSER.declareObject(constructorArg(), DataFrameAnalyticsConfig.STRICT_PARSER, DATA_FRAME_ANALYTICS_CONFIG);
|
||||
}
|
||||
|
||||
public static EstimateMemoryUsageAction.Request parseRequest(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
private final DataFrameAnalyticsConfig config;
|
||||
|
||||
public Request(DataFrameAnalyticsConfig config) {
|
||||
this.config = ExceptionsHelper.requireNonNull(config, DATA_FRAME_ANALYTICS_CONFIG);
|
||||
}
|
||||
|
||||
public Request(StreamInput in) throws IOException {
|
||||
super(in);
|
||||
this.config = new DataFrameAnalyticsConfig(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionRequestValidationException validate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public DataFrameAnalyticsConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
config.writeTo(out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(DATA_FRAME_ANALYTICS_CONFIG.getPreferredName(), config);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Request that = (Request) other;
|
||||
return Objects.equals(config, that.config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(config);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Response extends ActionResponse implements ToXContentObject {
|
||||
|
||||
public static final ParseField TYPE = new ParseField("memory_usage_estimation_result");
|
||||
|
|
|
@ -34,6 +34,9 @@ public class PutDataFrameAnalyticsAction extends ActionType<PutDataFrameAnalytic
|
|||
|
||||
public static class Request extends AcknowledgedRequest<Request> implements ToXContentObject {
|
||||
|
||||
/**
|
||||
* Parses request.
|
||||
*/
|
||||
public static Request parseRequest(String id, XContentParser parser) {
|
||||
DataFrameAnalyticsConfig.Builder config = DataFrameAnalyticsConfig.STRICT_PARSER.apply(parser, null);
|
||||
if (config.getId() == null) {
|
||||
|
@ -47,6 +50,17 @@ public class PutDataFrameAnalyticsAction extends ActionType<PutDataFrameAnalytic
|
|||
return new PutDataFrameAnalyticsAction.Request(config.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses request for memory estimation.
|
||||
* {@link Request} is reused across {@link PutDataFrameAnalyticsAction} and {@link EstimateMemoryUsageAction} but parsing differs
|
||||
* between these two usages.
|
||||
*/
|
||||
public static Request parseRequestForMemoryEstimation(XContentParser parser) {
|
||||
DataFrameAnalyticsConfig.Builder configBuilder = DataFrameAnalyticsConfig.STRICT_PARSER.apply(parser, null);
|
||||
DataFrameAnalyticsConfig config = configBuilder.buildForMemoryEstimation();
|
||||
return new PutDataFrameAnalyticsAction.Request(config);
|
||||
}
|
||||
|
||||
private DataFrameAnalyticsConfig config;
|
||||
|
||||
public Request() {}
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.core.ml.action;
|
||||
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.search.SearchModule;
|
||||
import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||
import org.elasticsearch.xpack.core.ml.action.EstimateMemoryUsageAction.Request;
|
||||
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfigTests;
|
||||
import org.elasticsearch.xpack.core.ml.dataframe.analyses.MlDataFrameAnalysisNamedXContentProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class EstimateMemoryUsageActionRequestTests extends AbstractSerializingTestCase<Request> {
|
||||
|
||||
@Override
|
||||
protected NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||
List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
|
||||
namedWriteables.addAll(new MlDataFrameAnalysisNamedXContentProvider().getNamedWriteables());
|
||||
namedWriteables.addAll(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedWriteables());
|
||||
return new NamedWriteableRegistry(namedWriteables);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NamedXContentRegistry xContentRegistry() {
|
||||
List<NamedXContentRegistry.Entry> namedXContent = new ArrayList<>();
|
||||
namedXContent.addAll(new MlDataFrameAnalysisNamedXContentProvider().getNamedXContentParsers());
|
||||
namedXContent.addAll(new SearchModule(Settings.EMPTY, false, Collections.emptyList()).getNamedXContents());
|
||||
return new NamedXContentRegistry(namedXContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Request createTestInstance() {
|
||||
return new Request(DataFrameAnalyticsConfigTests.createRandom("dummy"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Writeable.Reader<Request> instanceReader() {
|
||||
return Request::new;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Request doParseInstance(XContentParser parser) {
|
||||
return Request.parseRequest(parser);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.common.inject.Inject;
|
|||
import org.elasticsearch.tasks.Task;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.xpack.core.ml.action.EstimateMemoryUsageAction;
|
||||
import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction;
|
||||
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
||||
import org.elasticsearch.xpack.ml.MachineLearning;
|
||||
import org.elasticsearch.xpack.ml.dataframe.extractor.DataFrameDataExtractorFactory;
|
||||
|
@ -30,7 +31,7 @@ import java.util.Optional;
|
|||
* Redirects to a different node if the current node is *not* an ML node.
|
||||
*/
|
||||
public class TransportEstimateMemoryUsageAction
|
||||
extends HandledTransportAction<EstimateMemoryUsageAction.Request, EstimateMemoryUsageAction.Response> {
|
||||
extends HandledTransportAction<PutDataFrameAnalyticsAction.Request, EstimateMemoryUsageAction.Response> {
|
||||
|
||||
private final TransportService transportService;
|
||||
private final ClusterService clusterService;
|
||||
|
@ -43,7 +44,7 @@ public class TransportEstimateMemoryUsageAction
|
|||
ClusterService clusterService,
|
||||
NodeClient client,
|
||||
MemoryUsageEstimationProcessManager processManager) {
|
||||
super(EstimateMemoryUsageAction.NAME, transportService, actionFilters, EstimateMemoryUsageAction.Request::new);
|
||||
super(EstimateMemoryUsageAction.NAME, transportService, actionFilters, PutDataFrameAnalyticsAction.Request::new);
|
||||
this.transportService = transportService;
|
||||
this.clusterService = Objects.requireNonNull(clusterService);
|
||||
this.client = Objects.requireNonNull(client);
|
||||
|
@ -52,7 +53,7 @@ public class TransportEstimateMemoryUsageAction
|
|||
|
||||
@Override
|
||||
protected void doExecute(Task task,
|
||||
EstimateMemoryUsageAction.Request request,
|
||||
PutDataFrameAnalyticsAction.Request request,
|
||||
ActionListener<EstimateMemoryUsageAction.Response> listener) {
|
||||
DiscoveryNode localNode = clusterService.localNode();
|
||||
if (MachineLearning.isMlNode(localNode)) {
|
||||
|
@ -75,7 +76,7 @@ public class TransportEstimateMemoryUsageAction
|
|||
* the ML node.
|
||||
*/
|
||||
private void doEstimateMemoryUsage(String taskId,
|
||||
EstimateMemoryUsageAction.Request request,
|
||||
PutDataFrameAnalyticsAction.Request request,
|
||||
ActionListener<EstimateMemoryUsageAction.Response> listener) {
|
||||
DataFrameDataExtractorFactory.createForSourceIndices(
|
||||
client,
|
||||
|
@ -103,7 +104,7 @@ public class TransportEstimateMemoryUsageAction
|
|||
/**
|
||||
* Finds the first available ML node in the cluster and redirects the request to this node.
|
||||
*/
|
||||
private void redirectToMlNode(EstimateMemoryUsageAction.Request request,
|
||||
private void redirectToMlNode(PutDataFrameAnalyticsAction.Request request,
|
||||
ActionListener<EstimateMemoryUsageAction.Response> listener) {
|
||||
Optional<DiscoveryNode> node = findMlNode(clusterService.state());
|
||||
if (node.isPresent()) {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.elasticsearch.xpack.core.XPackField;
|
|||
import org.elasticsearch.xpack.core.ml.MlMetadata;
|
||||
import org.elasticsearch.xpack.core.ml.MlTasks;
|
||||
import org.elasticsearch.xpack.core.ml.action.EstimateMemoryUsageAction;
|
||||
import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction;
|
||||
import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction;
|
||||
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
|
||||
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsState;
|
||||
|
@ -192,7 +193,7 @@ public class TransportStartDataFrameAnalyticsAction
|
|||
ActionListener<DataFrameAnalyticsConfig> configListener = ActionListener.wrap(
|
||||
config -> {
|
||||
configHolder.set(config);
|
||||
EstimateMemoryUsageAction.Request estimateMemoryUsageRequest = new EstimateMemoryUsageAction.Request(config);
|
||||
PutDataFrameAnalyticsAction.Request estimateMemoryUsageRequest = new PutDataFrameAnalyticsAction.Request(config);
|
||||
ClientHelper.executeAsyncWithOrigin(
|
||||
client,
|
||||
ClientHelper.ML_ORIGIN,
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.rest.RestController;
|
|||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.RestToXContentListener;
|
||||
import org.elasticsearch.xpack.core.ml.action.EstimateMemoryUsageAction;
|
||||
import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction;
|
||||
import org.elasticsearch.xpack.ml.MachineLearning;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -30,8 +31,8 @@ public class RestEstimateMemoryUsageAction extends BaseRestHandler {
|
|||
|
||||
@Override
|
||||
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
|
||||
EstimateMemoryUsageAction.Request request =
|
||||
EstimateMemoryUsageAction.Request.parseRequest(restRequest.contentOrSourceParamParser());
|
||||
PutDataFrameAnalyticsAction.Request request =
|
||||
PutDataFrameAnalyticsAction.Request.parseRequestForMemoryEstimation(restRequest.contentOrSourceParamParser());
|
||||
return channel -> client.execute(EstimateMemoryUsageAction.INSTANCE, request, new RestToXContentListener<>(channel));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,8 @@ setup:
|
|||
- do:
|
||||
ml.estimate_memory_usage:
|
||||
body:
|
||||
data_frame_analytics_config:
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
- match: { expected_memory_usage_with_one_partition: "0" }
|
||||
- match: { expected_memory_usage_with_max_partitions: "0" }
|
||||
|
||||
|
@ -36,9 +35,8 @@ setup:
|
|||
- do:
|
||||
ml.estimate_memory_usage:
|
||||
body:
|
||||
data_frame_analytics_config:
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
- match: { expected_memory_usage_with_one_partition: "3kb" }
|
||||
- match: { expected_memory_usage_with_max_partitions: "3kb" }
|
||||
|
||||
|
@ -52,9 +50,8 @@ setup:
|
|||
- do:
|
||||
ml.estimate_memory_usage:
|
||||
body:
|
||||
data_frame_analytics_config:
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
- match: { expected_memory_usage_with_one_partition: "4kb" }
|
||||
- match: { expected_memory_usage_with_max_partitions: "4kb" }
|
||||
|
||||
|
@ -68,8 +65,7 @@ setup:
|
|||
- do:
|
||||
ml.estimate_memory_usage:
|
||||
body:
|
||||
data_frame_analytics_config:
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
source: { index: "index-source" }
|
||||
analysis: { outlier_detection: {} }
|
||||
- match: { expected_memory_usage_with_one_partition: "6kb" }
|
||||
- match: { expected_memory_usage_with_max_partitions: "5kb" }
|
||||
|
|
Loading…
Reference in New Issue