From 2a02940cea37622db88155dbf574271827e03de5 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 4 Oct 2021 09:16:35 -0700 Subject: [PATCH] Convert Autoscaling license object to use LicensedFeature (#78540) This commit moves the autoscaling license check to use the new LicensedFeature class. --- .../org/elasticsearch/xpack/autoscaling/Autoscaling.java | 8 ++++++++ .../xpack/autoscaling/AutoscalingLicenseChecker.java | 7 +++---- .../java/org/elasticsearch/license/XPackLicenseState.java | 4 +--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index 7473feb0d6f2c..8e7a66fac6bcf 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -27,6 +27,8 @@ import org.elasticsearch.common.xcontent.ParseField; import org.elasticsearch.env.Environment; import org.elasticsearch.env.NodeEnvironment; +import org.elasticsearch.license.License; +import org.elasticsearch.license.LicensedFeature; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ExtensiblePlugin; import org.elasticsearch.plugins.Plugin; @@ -79,6 +81,12 @@ public class Autoscaling extends Plugin implements ActionPlugin, ExtensiblePlugi } } + static final LicensedFeature.Momentary AUTOSCALING_FEATURE = LicensedFeature.momentary( + null, + "autoscaling", + License.OperationMode.ENTERPRISE + ); + private final List autoscalingExtensions; private final SetOnce clusterService = new SetOnce<>(); private final SetOnce allocationDeciders = new SetOnce<>(); diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseChecker.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseChecker.java index 09d87883fa968..1bc192b6ebb16 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseChecker.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseChecker.java @@ -7,12 +7,11 @@ package org.elasticsearch.xpack.autoscaling; -import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.xpack.core.XPackPlugin; - import java.util.Objects; import java.util.function.BooleanSupplier; +import static org.elasticsearch.xpack.core.XPackPlugin.getSharedLicenseState; + /** * Encapsulates license checking for autoscaling. */ @@ -24,7 +23,7 @@ public class AutoscalingLicenseChecker { * Constructs an autoscaling license checker with the default rule based on the license state for checking if autoscaling is allowed. */ AutoscalingLicenseChecker() { - this(() -> XPackPlugin.getSharedLicenseState().checkFeature(XPackLicenseState.Feature.AUTOSCALING)); + this(() -> Autoscaling.AUTOSCALING_FEATURE.check(getSharedLicenseState())); } /** diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java index 3a27e0cbe8dcc..2375f637f067d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java @@ -74,9 +74,7 @@ public enum Feature { SPATIAL_GEO_LINE(OperationMode.GOLD, true), - OPERATOR_PRIVILEGES(OperationMode.ENTERPRISE, true), - - AUTOSCALING(OperationMode.ENTERPRISE, true); + OPERATOR_PRIVILEGES(OperationMode.ENTERPRISE, true); // NOTE: this is temporary. The Feature enum will go away in favor of LicensedFeature. // Embedding the feature instance here is a stopgap to allow smaller initial PR,