Skip to content

Commit

Permalink
Convert Autoscaling license object to use LicensedFeature (#78540)
Browse files Browse the repository at this point in the history
This commit moves the autoscaling license check to use the new
LicensedFeature class.
  • Loading branch information
rjernst authored Oct 4, 2021
1 parent 7a7fffc commit 2a02940
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AutoscalingExtension> autoscalingExtensions;
private final SetOnce<ClusterService> clusterService = new SetOnce<>();
private final SetOnce<AllocationDeciders> allocationDeciders = new SetOnce<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2a02940

Please sign in to comment.