|
@@ -5,6 +5,7 @@
|
|
|
*/
|
|
|
package org.elasticsearch.xpack.core.ml.dataframe;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.common.Nullable;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
@@ -13,6 +14,7 @@ import org.elasticsearch.common.unit.ByteSizeValue;
|
|
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
+import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
@@ -33,22 +35,30 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
DataFrameAnalyticsConfig.MODEL_MEMORY_LIMIT,
|
|
|
VALUE);
|
|
|
PARSER.declareBoolean(Builder::setAllowLazyStart, DataFrameAnalyticsConfig.ALLOW_LAZY_START);
|
|
|
-
|
|
|
+ PARSER.declareInt(Builder::setMaxNumThreads, DataFrameAnalyticsConfig.MAX_NUM_THREADS);
|
|
|
}
|
|
|
|
|
|
private final String id;
|
|
|
private final String description;
|
|
|
private final ByteSizeValue modelMemoryLimit;
|
|
|
private final Boolean allowLazyStart;
|
|
|
+ private final Integer maxNumThreads;
|
|
|
|
|
|
private DataFrameAnalyticsConfigUpdate(String id,
|
|
|
@Nullable String description,
|
|
|
@Nullable ByteSizeValue modelMemoryLimit,
|
|
|
- @Nullable Boolean allowLazyStart) {
|
|
|
+ @Nullable Boolean allowLazyStart,
|
|
|
+ @Nullable Integer maxNumThreads) {
|
|
|
this.id = id;
|
|
|
this.description = description;
|
|
|
this.modelMemoryLimit = modelMemoryLimit;
|
|
|
this.allowLazyStart = allowLazyStart;
|
|
|
+
|
|
|
+ if (maxNumThreads != null && maxNumThreads < 1) {
|
|
|
+ throw ExceptionsHelper.badRequestException("[{}] must be a positive integer",
|
|
|
+ DataFrameAnalyticsConfig.MAX_NUM_THREADS.getPreferredName());
|
|
|
+ }
|
|
|
+ this.maxNumThreads = maxNumThreads;
|
|
|
}
|
|
|
|
|
|
public DataFrameAnalyticsConfigUpdate(StreamInput in) throws IOException {
|
|
@@ -56,6 +66,11 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
this.description = in.readOptionalString();
|
|
|
this.modelMemoryLimit = in.readOptionalWriteable(ByteSizeValue::new);
|
|
|
this.allowLazyStart = in.readOptionalBoolean();
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ this.maxNumThreads = in.readOptionalVInt();
|
|
|
+ } else {
|
|
|
+ this.maxNumThreads = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -64,6 +79,9 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
out.writeOptionalString(description);
|
|
|
out.writeOptionalWriteable(modelMemoryLimit);
|
|
|
out.writeOptionalBoolean(allowLazyStart);
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
|
|
|
+ out.writeOptionalVInt(maxNumThreads);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public String getId() {
|
|
@@ -82,6 +100,10 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
return allowLazyStart;
|
|
|
}
|
|
|
|
|
|
+ public Integer getMaxNumThreads() {
|
|
|
+ return maxNumThreads;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
|
|
builder.startObject();
|
|
@@ -95,6 +117,9 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
if (allowLazyStart != null) {
|
|
|
builder.field(DataFrameAnalyticsConfig.ALLOW_LAZY_START.getPreferredName(), allowLazyStart);
|
|
|
}
|
|
|
+ if (maxNumThreads != null) {
|
|
|
+ builder.field(DataFrameAnalyticsConfig.MAX_NUM_THREADS.getPreferredName(), maxNumThreads);
|
|
|
+ }
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -120,6 +145,9 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
if (allowLazyStart != null) {
|
|
|
builder.setAllowLazyStart(allowLazyStart);
|
|
|
}
|
|
|
+ if (maxNumThreads != null) {
|
|
|
+ builder.setMaxNumThreads(maxNumThreads);
|
|
|
+ }
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
@@ -127,7 +155,8 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
* Whether this update applied to the given source config requires analytics task restart.
|
|
|
*/
|
|
|
public boolean requiresRestart(DataFrameAnalyticsConfig source) {
|
|
|
- return getModelMemoryLimit() != null && getModelMemoryLimit().equals(source.getModelMemoryLimit()) == false;
|
|
|
+ return (getModelMemoryLimit() != null && getModelMemoryLimit().equals(source.getModelMemoryLimit()) == false)
|
|
|
+ || (getMaxNumThreads() != null && getMaxNumThreads().equals(source.getMaxNumThreads()) == false);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -145,12 +174,13 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
return Objects.equals(this.id, that.id)
|
|
|
&& Objects.equals(this.description, that.description)
|
|
|
&& Objects.equals(this.modelMemoryLimit, that.modelMemoryLimit)
|
|
|
- && Objects.equals(this.allowLazyStart, that.allowLazyStart);
|
|
|
+ && Objects.equals(this.allowLazyStart, that.allowLazyStart)
|
|
|
+ && Objects.equals(this.maxNumThreads, that.maxNumThreads);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(id, description, modelMemoryLimit, allowLazyStart);
|
|
|
+ return Objects.hash(id, description, modelMemoryLimit, allowLazyStart, maxNumThreads);
|
|
|
}
|
|
|
|
|
|
public static class Builder {
|
|
@@ -159,6 +189,7 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
private String description;
|
|
|
private ByteSizeValue modelMemoryLimit;
|
|
|
private Boolean allowLazyStart;
|
|
|
+ private Integer maxNumThreads;
|
|
|
|
|
|
public Builder(String id) {
|
|
|
this.id = id;
|
|
@@ -188,8 +219,13 @@ public class DataFrameAnalyticsConfigUpdate implements Writeable, ToXContentObje
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public Builder setMaxNumThreads(Integer maxNumThreads) {
|
|
|
+ this.maxNumThreads = maxNumThreads;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public DataFrameAnalyticsConfigUpdate build() {
|
|
|
- return new DataFrameAnalyticsConfigUpdate(id, description, modelMemoryLimit, allowLazyStart);
|
|
|
+ return new DataFrameAnalyticsConfigUpdate(id, description, modelMemoryLimit, allowLazyStart, maxNumThreads);
|
|
|
}
|
|
|
}
|
|
|
}
|