Skip to content

Commit 9c5f148

Browse files
authored
Convert ML license object to LicensedFeature (#79208)
This commit moves the ML license checks to use the new LicensedFeature class.
1 parent 8c37255 commit 9c5f148

File tree

29 files changed

+77
-50
lines changed

29 files changed

+77
-50
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public enum Feature {
4747
SECURITY_AUTHORIZATION_REALM(OperationMode.PLATINUM, true),
4848
SECURITY_AUTHORIZATION_ENGINE(OperationMode.PLATINUM, true),
4949

50-
MACHINE_LEARNING(OperationMode.PLATINUM, true),
51-
5250
OPERATOR_PRIVILEGES(OperationMode.ENTERPRISE, true);
5351

5452
// NOTE: this is temporary. The Feature enum will go away in favor of LicensedFeature.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/MachineLearningField.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.elasticsearch.common.settings.Setting;
1212
import org.elasticsearch.common.unit.ByteSizeValue;
1313
import org.elasticsearch.core.TimeValue;
14+
import org.elasticsearch.license.License;
15+
import org.elasticsearch.license.LicensedFeature;
1416

1517
import java.math.BigInteger;
1618
import java.nio.charset.StandardCharsets;
@@ -25,6 +27,12 @@ public final class MachineLearningField {
2527
Setting.memorySizeSetting("xpack.ml.max_model_memory_limit", ByteSizeValue.ZERO,
2628
Setting.Property.Dynamic, Setting.Property.NodeScope);
2729
public static final TimeValue STATE_PERSIST_RESTORE_TIMEOUT = TimeValue.timeValueMinutes(30);
30+
public static final String ML_FEATURE_FAMILY = "machine-learning";
31+
public static final LicensedFeature.Momentary ML_API_FEATURE = LicensedFeature.momentary(
32+
ML_FEATURE_FAMILY,
33+
"api",
34+
License.OperationMode.PLATINUM
35+
);
2836

2937
private MachineLearningField() {}
3038

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/license/MachineLearningLicensingIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
3131
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
3232
import org.elasticsearch.xpack.core.XPackField;
33+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
3334
import org.elasticsearch.xpack.core.ml.MlConfigIndex;
3435
import org.elasticsearch.xpack.core.ml.action.CloseJobAction;
3536
import org.elasticsearch.xpack.core.ml.action.DeleteDatafeedAction;
@@ -764,7 +765,7 @@ private static OperationMode randomLicenseType() {
764765

765766
private static void assertMLAllowed(boolean expected) {
766767
for (XPackLicenseState licenseState : internalCluster().getInstances(XPackLicenseState.class)) {
767-
assertEquals(licenseState.checkFeature(XPackLicenseState.Feature.MACHINE_LEARNING), expected);
768+
assertEquals(MachineLearningField.ML_API_FEATURE.check(licenseState), expected);
768769
}
769770
}
770771

x-pack/plugin/ml/src/internalClusterTest/java/org/elasticsearch/xpack/ml/integration/TestFeatureLicenseTrackingIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import java.util.Map;
4242
import java.util.Set;
4343

44-
import static org.elasticsearch.xpack.ml.MachineLearning.ML_FEATURE_FAMILY;
44+
import static org.elasticsearch.xpack.core.ml.MachineLearningField.ML_FEATURE_FAMILY;
4545
import static org.elasticsearch.xpack.ml.inference.loadingservice.LocalModelTests.buildClassification;
4646
import static org.elasticsearch.xpack.ml.integration.ModelInferenceActionIT.buildTrainedModelConfigBuilder;
4747
import static org.elasticsearch.xpack.ml.support.BaseMlIntegTestCase.createScheduledJob;

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/InvalidLicenseEnforcer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.license.LicenseStateListener;
1414
import org.elasticsearch.license.XPackLicenseState;
1515
import org.elasticsearch.threadpool.ThreadPool;
16+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
1617
import org.elasticsearch.xpack.ml.datafeed.DatafeedRunner;
1718
import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManager;
1819

@@ -49,7 +50,7 @@ void listenForLicenseStateChanges() {
4950
@Override
5051
public void licenseStateChanged() {
5152
assert licenseStateListenerRegistered;
52-
if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING) == false) {
53+
if (MachineLearningField.ML_API_FEATURE.checkWithoutTracking(licenseState) == false) {
5354
// if the license has expired, close jobs and datafeeds
5455
threadPool.generic().execute(new AbstractRunnable() {
5556
@Override

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,19 @@ public class MachineLearning extends Plugin implements SystemIndexPlugin,
458458
// This is for performance testing. It's not exposed to the end user.
459459
// Recompile if you want to compare performance with C++ tokenization.
460460
public static final boolean CATEGORIZATION_TOKENIZATION_IN_JAVA = true;
461-
public static final String ML_FEATURE_FAMILY = "machine-learning";
462461

463462
public static final LicensedFeature.Persistent ML_ANOMALY_JOBS_FEATURE = LicensedFeature.persistent(
464-
ML_FEATURE_FAMILY,
463+
MachineLearningField.ML_FEATURE_FAMILY,
465464
"anomaly-detection-job",
466465
License.OperationMode.PLATINUM
467466
);
468467
public static final LicensedFeature.Persistent ML_ANALYTICS_JOBS_FEATURE = LicensedFeature.persistent(
469-
ML_FEATURE_FAMILY,
468+
MachineLearningField.ML_FEATURE_FAMILY,
470469
"data-frame-analytics-job",
471470
License.OperationMode.PLATINUM
472471
);
473472
public static final LicensedFeature.Persistent ML_MODEL_INFERENCE_FEATURE = LicensedFeature.persistent(
474-
ML_FEATURE_FAMILY,
473+
MachineLearningField.ML_FEATURE_FAMILY,
475474
"model-inference",
476475
License.OperationMode.PLATINUM
477476
);

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.xpack.core.XPackSettings;
1616
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction;
1717
import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction;
18+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
1819

1920
public class MachineLearningInfoTransportAction extends XPackInfoFeatureTransportAction {
2021

@@ -36,7 +37,7 @@ public String name() {
3637

3738
@Override
3839
public boolean available() {
39-
return licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING);
40+
return MachineLearningField.ML_API_FEATURE.checkWithoutTracking(licenseState);
4041
}
4142

4243
@Override

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.elasticsearch.xpack.core.action.XPackUsageFeatureTransportAction;
3434
import org.elasticsearch.xpack.core.action.util.PageParams;
3535
import org.elasticsearch.xpack.core.ml.MachineLearningFeatureSetUsage;
36+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
3637
import org.elasticsearch.xpack.core.ml.action.GetDataFrameAnalyticsAction;
3738
import org.elasticsearch.xpack.core.ml.action.GetDataFrameAnalyticsStatsAction;
3839
import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction;
@@ -89,7 +90,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat
8990
ActionListener<XPackUsageFeatureResponse> listener) {
9091
if (enabled == false) {
9192
MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(
92-
licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled,
93+
MachineLearningField.ML_API_FEATURE.checkWithoutTracking(licenseState), enabled,
9394
Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), 0);
9495
listener.onResponse(new XPackUsageFeatureResponse(usage));
9596
return;
@@ -106,7 +107,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat
106107
response -> {
107108
addTrainedModelStats(response, inferenceUsage);
108109
MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(
109-
licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING),
110+
MachineLearningField.ML_API_FEATURE.checkWithoutTracking(licenseState),
110111
enabled, jobsUsage, datafeedsUsage, analyticsUsage, inferenceUsage, nodeCount);
111112
listener.onResponse(new XPackUsageFeatureResponse(usage));
112113
},

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.transport.TransportService;
3030
import org.elasticsearch.xpack.core.XPackField;
3131
import org.elasticsearch.xpack.core.XPackSettings;
32+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
3233
import org.elasticsearch.xpack.core.ml.action.ExplainDataFrameAnalyticsAction;
3334
import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction;
3435
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig;
@@ -93,7 +94,7 @@ public TransportExplainDataFrameAnalyticsAction(TransportService transportServic
9394
protected void doExecute(Task task,
9495
PutDataFrameAnalyticsAction.Request request,
9596
ActionListener<ExplainDataFrameAnalyticsAction.Response> listener) {
96-
if (licenseState.checkFeature(XPackLicenseState.Feature.MACHINE_LEARNING) == false) {
97+
if (MachineLearningField.ML_API_FEATURE.check(licenseState) == false) {
9798
listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING));
9899
return;
99100
}

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.threadpool.ThreadPool;
2222
import org.elasticsearch.transport.TransportService;
2323
import org.elasticsearch.xpack.core.XPackField;
24+
import org.elasticsearch.xpack.core.ml.MachineLearningField;
2425
import org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction;
2526
import org.elasticsearch.xpack.core.ml.action.InferTrainedModelDeploymentAction;
2627
import org.elasticsearch.xpack.core.ml.action.InternalInferModelAction;
@@ -71,7 +72,7 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
7172

7273
Response.Builder responseBuilder = Response.builder();
7374

74-
if (licenseState.checkFeature(XPackLicenseState.Feature.MACHINE_LEARNING)) {
75+
if (MachineLearningField.ML_API_FEATURE.check(licenseState)) {
7576
responseBuilder.setLicensed(true);
7677
doInfer(request, responseBuilder, listener);
7778
} else {

0 commit comments

Comments
 (0)