From 1e008e65edd3ce866632ee48996e8d88d9e4059d Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 28 Apr 2020 21:08:04 -0700 Subject: [PATCH 1/5] Convert remaining license methods to isAllowed This commit converts the remaining isXXXAllowed methods to instead of use isAllowed with a Feature value. There are a couple other methods that are static, as well as some licensed features that check the license directly, but those will be dealt with in other followups. --- .../xpack/analytics/AnalyticsPlugin.java | 2 +- .../action/AnalyticsInfoTransportAction.java | 2 +- .../action/AnalyticsUsageTransportAction.java | 2 +- .../AnalyticsInfoTransportActionTests.java | 4 +- .../xpack/ccr/CcrLicenseChecker.java | 3 +- .../ccr/CCRInfoTransportActionTests.java | 4 +- .../collector/ccr/StatsCollectorTests.java | 28 +-- .../license/XPackLicenseState.java | 185 +++++------------- .../xpack/ccr/CCRInfoTransportAction.java | 2 +- .../xpack/ccr/CCRUsageTransportAction.java | 2 +- .../actions/throttler/ActionThrottler.java | 2 +- .../license/XPackLicenseStateTests.java | 170 ++++++++-------- .../throttler/WatchThrottlerTests.java | 13 +- .../TransportDeprecationInfoAction.java | 2 +- .../action/EnrichInfoTransportAction.java | 2 +- .../action/EnrichUsageTransportAction.java | 2 +- .../enrich/EnrichStatsCollectorTests.java | 28 +-- .../xpack/eql/EqlInfoTransportAction.java | 6 +- .../xpack/eql/EqlUsageTransportAction.java | 2 +- .../eql/EqlInfoTransportActionTests.java | 8 +- .../xpack/graph/GraphInfoTransportAction.java | 2 +- .../graph/GraphUsageTransportAction.java | 3 +- .../action/TransportGraphExploreAction.java | 2 +- .../graph/GraphInfoTransportActionTests.java | 2 +- .../IndexLifecycleInfoTransportAction.java | 2 +- .../IndexLifecycleUsageTransportAction.java | 2 +- .../xpack/slm/SLMInfoTransportAction.java | 2 +- .../xpack/slm/SLMUsageTransportAction.java | 2 +- ...ndexLifecycleInfoTransportActionTests.java | 4 +- .../logstash/LogstashInfoTransportAction.java | 2 +- .../LogstashUsageTransportAction.java | 2 +- .../LogstashInfoTransportActionTests.java | 4 +- .../xpack/ml/InvalidLicenseEnforcer.java | 2 +- .../MachineLearningInfoTransportAction.java | 2 +- .../MachineLearningUsageTransportAction.java | 4 +- ...nsportExplainDataFrameAnalyticsAction.java | 2 +- .../TransportInternalInferModelAction.java | 2 +- .../ml/action/TransportOpenJobAction.java | 2 +- .../TransportPutDataFrameAnalyticsAction.java | 2 +- .../ml/action/TransportPutDatafeedAction.java | 2 +- .../ml/action/TransportPutJobAction.java | 2 +- .../TransportPutTrainedModelAction.java | 2 +- ...ransportStartDataFrameAnalyticsAction.java | 2 +- .../action/TransportStartDatafeedAction.java | 2 +- .../license/MachineLearningLicensingIT.java | 2 +- ...chineLearningInfoTransportActionTests.java | 10 +- ...sportGetTrainedModelsStatsActionTests.java | 2 +- .../InferenceProcessorFactoryTests.java | 4 +- .../MonitoringInfoTransportAction.java | 2 +- .../MonitoringUsageTransportAction.java | 2 +- .../monitoring/cleaner/CleanerService.java | 9 +- .../xpack/monitoring/collector/Collector.java | 2 +- .../collector/ccr/StatsCollector.java | 2 +- .../enrich/EnrichStatsCollector.java | 2 +- .../collector/ml/JobStatsCollector.java | 2 +- .../http/ClusterAlertHttpResource.java | 2 +- .../exporter/http/HttpExporter.java | 4 +- .../exporter/local/LocalExporter.java | 2 +- .../MonitoringInfoTransportActionTests.java | 2 +- .../cleaner/CleanerServiceTests.java | 23 +-- .../indices/IndexRecoveryCollectorTests.java | 12 +- .../indices/IndexStatsCollectorTests.java | 12 +- .../collector/ml/JobStatsCollectorTests.java | 30 +-- .../node/NodeStatsCollectorTests.java | 14 +- .../shards/ShardsCollectorTests.java | 12 +- .../http/ClusterAlertHttpResourceTests.java | 14 +- .../http/HttpExporterResourceTests.java | 2 +- .../rollup/RollupInfoTransportAction.java | 2 +- .../rollup/RollupUsageTransportAction.java | 2 +- .../action/TransportPutRollupJobAction.java | 2 +- .../action/TransportStartRollupAction.java | 2 +- .../RollupInfoTransportActionTests.java | 2 +- .../security/SecurityInfoTransportAction.java | 2 +- .../SecurityUsageTransportAction.java | 2 +- .../action/filter/SecurityActionFilter.java | 3 +- .../rest/action/SecurityBaseRestHandler.java | 2 +- .../support/SecurityStatusChangeListener.java | 2 +- .../SecurityInfoTransportActionTests.java | 8 +- .../filter/SecurityActionFilterTests.java | 3 +- .../action/SecurityBaseRestHandlerTests.java | 4 +- .../apikey/RestCreateApiKeyActionTests.java | 2 +- .../apikey/RestGetApiKeyActionTests.java | 2 +- .../RestInvalidateApiKeyActionTests.java | 2 +- .../RestGetUserPrivilegesActionTests.java | 2 +- .../user/RestHasPrivilegesActionTests.java | 2 +- .../SecurityStatusChangeListenerTests.java | 2 +- .../spatial/SpatialInfoTransportAction.java | 2 +- .../spatial/SpatialUsageTransportAction.java | 2 +- .../SpatialInfoTransportActionTests.java | 2 +- .../xpack/sql/SqlInfoTransportAction.java | 6 +- .../xpack/sql/SqlUsageTransportAction.java | 2 +- .../xpack/sql/plugin/SqlPlugin.java | 6 +- .../sql/SqlInfoTransportActionTests.java | 2 +- .../TransformInfoTransportAction.java | 2 +- .../TransformUsageTransportAction.java | 2 +- .../TransportPreviewTransformAction.java | 2 +- .../action/TransportPutTransformAction.java | 2 +- .../action/TransportStartTransformAction.java | 2 +- .../TransportUpdateTransformAction.java | 2 +- .../TransformInfoTransportActionTests.java | 4 +- .../vectors/VectorsInfoTransportAction.java | 2 +- .../vectors/VectorsUsageTransportAction.java | 2 +- .../VectorsInfoTransportActionTests.java | 2 +- .../VotingOnlyNodeFeatureSet.java | 7 +- .../watcher/WatcherInfoTransportAction.java | 2 +- .../watcher/WatcherUsageTransportAction.java | 5 +- .../actions/WatcherTransportAction.java | 2 +- .../WatcherInfoTransportActionTests.java | 2 +- .../AbstractWatcherIntegrationTestCase.java | 2 +- 109 files changed, 365 insertions(+), 439 deletions(-) diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java index 10f0e6af4c120..a66a2027dc41e 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java @@ -150,7 +150,7 @@ public List getNamedWriteables() { private static ContextParser checkLicense(ContextParser realParser) { return (parser, name) -> { - if (getLicenseState().isAnalyticsAllowed() == false) { + if (getLicenseState().isAllowed(XPackLicenseState.Feature.ANALYTICS) == false) { throw LicenseUtils.newComplianceException(XPackField.ANALYTICS); } return realParser.parse(parser, name); diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportAction.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportAction.java index cfdc6eeaa1567..1ceadaab8096c 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportAction.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportAction.java @@ -31,7 +31,7 @@ public String name() { @Override public boolean available() { - return licenseState.isAnalyticsAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS); } @Override diff --git a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java index de46da42f893f..caf5bcfc8eb5b 100644 --- a/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java +++ b/x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java @@ -42,7 +42,7 @@ public AnalyticsUsageTransportAction(TransportService transportService, ClusterS @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isAnalyticsAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS); if (available) { AnalyticsStatsAction.Request statsRequest = new AnalyticsStatsAction.Request(); statsRequest.setParentTask(clusterService.localNode().getId(), task.getId()); diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java index 3d6440e862cd4..12df855e33e2a 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java @@ -63,7 +63,7 @@ public void testAvailable() throws Exception { AnalyticsInfoTransportAction featureSet = new AnalyticsInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), licenseState); boolean available = randomBoolean(); - when(licenseState.isAnalyticsAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS)).thenReturn(available); assertThat(featureSet.available(), is(available)); Client client = mockClient(); AnalyticsUsageTransportAction usageAction = new AnalyticsUsageTransportAction(mock(TransportService.class), clusterService, null, @@ -89,7 +89,7 @@ public void testEnabled() throws Exception { assertThat(featureSet.enabled(), is(true)); assertTrue(featureSet.enabled()); boolean available = randomBoolean(); - when(licenseState.isAnalyticsAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS)).thenReturn(available); Client client = mockClient(); AnalyticsUsageTransportAction usageAction = new AnalyticsUsageTransportAction(mock(TransportService.class), clusterService, null, mock(ActionFilters.class), null, licenseState, client); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java index 1e5445cbfd980..9c1c596d28a74 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java @@ -72,7 +72,8 @@ public class CcrLicenseChecker { * Constructs a CCR license checker with the default rule based on the license state for checking if CCR is allowed. */ CcrLicenseChecker() { - this(XPackPlugin.getSharedLicenseState()::isCcrAllowed, XPackPlugin.getSharedLicenseState()::isSecurityEnabled); + this(() -> XPackPlugin.getSharedLicenseState().isAllowed(XPackLicenseState.Feature.CCR), + XPackPlugin.getSharedLicenseState()::isSecurityEnabled); } /** diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java index 9e73499a08a22..ed2b65b8972a8 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java @@ -47,10 +47,10 @@ public void testAvailable() { CCRInfoTransportAction featureSet = new CCRInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); - when(licenseState.isCcrAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(false); assertThat(featureSet.available(), equalTo(false)); - when(licenseState.isCcrAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(true); assertThat(featureSet.available(), equalTo(true)); } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java index 411de2d7623c1..6ea49997ea846 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java @@ -46,14 +46,14 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { whenLocalNodeElectedMaster(isElectedMaster); // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); - when(licenseState.isCcrAllowed()).thenReturn(ccrAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(ccrAllowed); final StatsCollector collector = createCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } } @@ -61,8 +61,8 @@ public void testShouldCollectReturnsFalseIfNotMaster() { // regardless of CCR being enabled final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings()); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); - when(licenseState.isCcrAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(randomBoolean()); // this controls the blockage final boolean isElectedMaster = false; @@ -75,8 +75,8 @@ public void testShouldCollectReturnsFalseIfCCRIsDisabled() { // this is controls the blockage final Settings settings = ccrDisabledSettings(); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); - when(licenseState.isCcrAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(randomBoolean()); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -86,16 +86,16 @@ public void testShouldCollectReturnsFalseIfCCRIsDisabled() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } } public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() { final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings()); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean()); // this is controls the blockage - when(licenseState.isCcrAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -104,22 +104,22 @@ public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } } public void testShouldCollectReturnsTrue() { final Settings settings = ccrEnabledSettings(); - when(licenseState.isMonitoringAllowed()).thenReturn(true); - when(licenseState.isCcrAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(true); final boolean isElectedMaster = true; final StatsCollector collector = createCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } public void testDoCollect() throws Exception { 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 c497cbe1c007a..e0cf15f9db59d 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 @@ -10,6 +10,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.translog.Translog; import org.elasticsearch.license.License.OperationMode; import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackSettings; @@ -36,6 +37,7 @@ public class XPackLicenseState { * Each value defines the licensed state necessary for the feature to be allowed. */ public enum Feature { + SECURITY(OperationMode.BASIC, false), SECURITY_IP_FILTERING(OperationMode.GOLD, false), SECURITY_AUDITING(OperationMode.GOLD, false), SECURITY_DLS_FLS(OperationMode.PLATINUM, false), @@ -46,7 +48,49 @@ public enum Feature { SECURITY_API_KEY_SERVICE(OperationMode.MISSING, false), SECURITY_AUTHORIZATION_REALM(OperationMode.PLATINUM, true), SECURITY_AUTHORIZATION_ENGINE(OperationMode.PLATINUM, true), - SPATIAL_GEO_CENTROID(OperationMode.GOLD, true); + SECURITY_STATS_AND_HEALTH(OperationMode.MISSING, true), + + WATCHER(OperationMode.STANDARD, true), + MONITORING(OperationMode.MISSING, true), + // TODO: should just check WATCHER directly? + MONITORING_CLUSTER_ALERTS(OperationMode.STANDARD, true), + MONITORING_UPDATE_RETENTION(OperationMode.STANDARD, false), + + CCR(OperationMode.PLATINUM, true), + + GRAPH(OperationMode.PLATINUM, true), + + MACHINE_LEARNING(OperationMode.PLATINUM, true), + + TRANSFORM(OperationMode.MISSING, true), + + ROLLUP(OperationMode.MISSING, true), + + VOTING_ONLY(OperationMode.MISSING, true), + + LOGSTASH(OperationMode.STANDARD, true), + + DEPRECATION(OperationMode.MISSING, true), + + ILM(OperationMode.MISSING, true), + + ENRICH(OperationMode.MISSING, true), + + EQL(OperationMode.MISSING, true), + + SQL(OperationMode.MISSING, true), + + JDBC(OperationMode.PLATINUM, true), + + ODBC(OperationMode.PLATINUM, true), + + VECTORS(OperationMode.MISSING, true), + + SPATIAL(OperationMode.MISSING, true), + + SPATIAL_GEO_CENTROID(OperationMode.GOLD, true), + + ANALYTICS(OperationMode.MISSING, true); final OperationMode minimumOperationMode; final boolean needsActive; @@ -432,57 +476,10 @@ public boolean isAllowed(Feature feature) { return isAllowedByLicense(feature.minimumOperationMode, feature.needsActive); } - public boolean isStatsAndHealthAllowed() { - return allowForAllLicenses(); - } - - public boolean isWatcherAllowed() { - return isAllowedByLicense(OperationMode.STANDARD); - } - - public boolean isMonitoringAllowed() { - return allowForAllLicenses(); - } - - /** - * Monitoring Cluster Alerts requires the equivalent license to use Watcher. - * - * @return {@link #isWatcherAllowed()} - * @see #isWatcherAllowed() - */ - public boolean isMonitoringClusterAlertsAllowed() { - return isWatcherAllowed(); - } - - /** - * Determine if the current license allows the retention of indices to be modified. - *

- * Only users with a non-{@link OperationMode#BASIC} license can update the retention period. - *

- * Note: This does not consider the state of the license so that any change is remembered for when they fix their license. - * - * @return {@code true} if the user is allowed to modify the retention. Otherwise {@code false}. - */ - public boolean isUpdateRetentionAllowed() { - return isAllowedByLicense(OperationMode.STANDARD, false); - } - - public boolean isGraphAllowed() { - return isAllowedByLicense(OperationMode.PLATINUM); - } - - public boolean isMachineLearningAllowed() { - return isAllowedByLicense(OperationMode.PLATINUM); - } - public static boolean isMachineLearningAllowedForOperationMode(final OperationMode operationMode) { return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); } - public boolean isTransformAllowed() { - return allowForAllLicenses(); - } - public static boolean isTransformAllowedForOperationMode(final OperationMode operationMode) { // any license (basic and upwards) return operationMode != License.OperationMode.MISSING; @@ -492,91 +489,6 @@ public static boolean isFipsAllowedForOperationMode(final OperationMode operatio return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); } - public boolean isRollupAllowed() { - return allowForAllLicenses(); - } - - public boolean isVotingOnlyAllowed() { - return allowForAllLicenses(); - } - - public boolean isLogstashAllowed() { - return isAllowedByLicense(OperationMode.STANDARD); - } - - public boolean isBeatsAllowed() { - return isAllowedByLicense(OperationMode.STANDARD); - } - - public boolean isDeprecationAllowed() { - return allowForAllLicenses(); - } - - public boolean isUpgradeAllowed() { - return allowForAllLicenses(); - } - - public boolean isIndexLifecycleAllowed() { - return allowForAllLicenses(); - } - - public boolean isEnrichAllowed() { - return allowForAllLicenses(); - } - - public boolean isEqlAllowed() { - return allowForAllLicenses(); - } - - public boolean isSqlAllowed() { - return allowForAllLicenses(); - } - - public boolean isJdbcAllowed() { - return isAllowedByLicense(OperationMode.PLATINUM); - } - - public boolean isFlattenedAllowed() { - return allowForAllLicenses(); - } - - public boolean isVectorsAllowed() { - return allowForAllLicenses(); - } - - - /** - * Determine if Wildcard support should be enabled. - *

- * Wildcard is available for all license types except {@link OperationMode#MISSING} - */ - public synchronized boolean isWildcardAllowed() { - return status.active; - } - - public boolean isOdbcAllowed() { - return isAllowedByLicense(OperationMode.PLATINUM); - } - - public boolean isSpatialAllowed() { - return allowForAllLicenses(); - } - - public boolean isAnalyticsAllowed() { - return allowForAllLicenses(); - } - - public boolean isConstantKeywordAllowed() { - return allowForAllLicenses(); - } - - /** - * @return true if security is available to be used with the current license type - */ - public boolean isSecurityAvailable() { - return checkAgainstStatus(status -> status.mode != OperationMode.MISSING); - } - /** * Returns whether security is enabled, taking into account the default enabled state * based on the current license level. @@ -616,13 +528,6 @@ private static boolean isSecurityEnabled(final OperationMode mode, final boolean } } - /** - * Determine if cross-cluster replication is allowed - */ - public boolean isCcrAllowed() { - return isAllowedByLicense(OperationMode.PLATINUM); - } - public static boolean isCcrAllowedForOperationMode(final OperationMode operationMode) { return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRInfoTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRInfoTransportAction.java index da6fd885f98a3..4c15544a52d6d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRInfoTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRInfoTransportAction.java @@ -43,7 +43,7 @@ public String name() { @Override public boolean available() { - return licenseState.isCcrAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.CCR); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java index 0d4fdbd5cbcda..8ee3c11668a1b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java @@ -68,7 +68,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat lastFollowTimeInMillis = Math.max(0, Instant.now().toEpochMilli() - lastFollowerIndexCreationDate); } - CCRInfoTransportAction.Usage usage = new CCRInfoTransportAction.Usage(licenseState.isCcrAllowed(), + CCRInfoTransportAction.Usage usage = new CCRInfoTransportAction.Usage(licenseState.isAllowed(XPackLicenseState.Feature.CCR), XPackSettings.CCR_ENABLED_SETTING.get(settings), numberOfFollowerIndices, numberOfAutoFollowPatterns, lastFollowTimeInMillis); listener.onResponse(new XPackUsageFeatureResponse(usage)); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/ActionThrottler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/ActionThrottler.java index d02ee20def0df..08621dd01e3c5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/ActionThrottler.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/actions/throttler/ActionThrottler.java @@ -38,7 +38,7 @@ public TimeValue throttlePeriod() { @Override public Result throttle(String actionId, WatchExecutionContext ctx) { - if (licenseState.isWatcherAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.WATCHER) == false) { return Result.throttle(LICENSE, "watcher license does not allow action execution"); } if (periodThrottler != null) { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java index 3e3774066f747..3877de2e1f0b1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/XPackLicenseStateTests.java @@ -81,7 +81,7 @@ public void testSecurityDefaults() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(true)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_ALL_REALMS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(true)); @@ -104,13 +104,13 @@ public void testSecurityBasicWithoutExplicitSecurityEnabled() { assertThat(licenseState.isSecurityEnabled(), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_TOKEN_SERVICE), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_API_KEY_SERVICE), is(true)); - assertThat(licenseState.isSecurityAvailable(), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY), is(true)); assertThat(licenseState.isSecurityEnabled(), is(false)); } @@ -122,13 +122,13 @@ public void testSecurityBasicWithExplicitSecurityEnabled() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_TOKEN_SERVICE), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_API_KEY_SERVICE), is(true)); - assertThat(licenseState.isSecurityAvailable(), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY), is(true)); assertThat(licenseState.isSecurityEnabled(), is(true)); } @@ -139,7 +139,7 @@ public void testSecurityDefaultBasicExpired() { assertThat(licenseState.isSecurityEnabled(), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(false)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_TOKEN_SERVICE), is(false)); @@ -154,7 +154,7 @@ public void testSecurityEnabledBasicExpired() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(false)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_TOKEN_SERVICE), is(false)); @@ -169,7 +169,7 @@ public void testSecurityStandard() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); } @@ -182,7 +182,7 @@ public void testSecurityStandardExpired() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(false)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(false)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); } @@ -195,7 +195,7 @@ public void testSecurityGold() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(true)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_STANDARD_REALMS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); @@ -211,7 +211,7 @@ public void testSecurityGoldExpired() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(true)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(false)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_STANDARD_REALMS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); @@ -227,7 +227,7 @@ public void testSecurityPlatinum() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(true)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(true)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_ALL_REALMS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(true)); @@ -243,7 +243,7 @@ public void testSecurityPlatinumExpired() { assertThat(licenseState.isSecurityEnabled(), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_IP_FILTERING), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_AUDITING), is(true)); - assertThat(licenseState.isStatsAndHealthAllowed(), is(false)); + assertThat(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH), is(false)); assertThat(licenseState.isAllowed(Feature.SECURITY_DLS_FLS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_ALL_REALMS), is(true)); assertThat(licenseState.isAllowed(Feature.SECURITY_CUSTOM_ROLE_PROVIDERS), is(false)); @@ -304,172 +304,172 @@ public void testMonitoringAckNotBasicToBasic() { } public void testMonitoringAllowed() { - assertAllowed(randomMode(), true, XPackLicenseState::isMonitoringAllowed, true); - assertAllowed(randomMode(), false, XPackLicenseState::isMonitoringAllowed, false); + assertAllowed(randomMode(), true, s -> s.isAllowed(Feature.MONITORING), true); + assertAllowed(randomMode(), false, s -> s.isAllowed(Feature.MONITORING), false); } public void testMonitoringUpdateRetention() { - assertAllowed(STANDARD, true, XPackLicenseState::isUpdateRetentionAllowed, true); - assertAllowed(GOLD, true, XPackLicenseState::isUpdateRetentionAllowed, true); - assertAllowed(PLATINUM, true, XPackLicenseState::isUpdateRetentionAllowed, true); - assertAllowed(TRIAL, true, XPackLicenseState::isUpdateRetentionAllowed, true); - assertAllowed(BASIC, true, XPackLicenseState::isUpdateRetentionAllowed, false); - assertAllowed(MISSING, false, XPackLicenseState::isUpdateRetentionAllowed, false); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), true); + assertAllowed(GOLD, true, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), true); + assertAllowed(PLATINUM, true, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), true); + assertAllowed(TRIAL, true, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), true); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), false); + assertAllowed(MISSING, false, s -> s.isAllowed(Feature.MONITORING_UPDATE_RETENTION), false); } public void testWatcherPlatinumGoldTrialStandard() throws Exception { - assertAllowed(TRIAL, true, XPackLicenseState::isWatcherAllowed, true); - assertAllowed(GOLD, true, XPackLicenseState::isWatcherAllowed, true); - assertAllowed(PLATINUM, true, XPackLicenseState::isWatcherAllowed, true); - assertAllowed(STANDARD, true, XPackLicenseState::isWatcherAllowed, true); + assertAllowed(TRIAL, true, s -> s.isAllowed(Feature.WATCHER), true); + assertAllowed(GOLD, true, s -> s.isAllowed(Feature.WATCHER), true); + assertAllowed(PLATINUM, true, s -> s.isAllowed(Feature.WATCHER), true); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.WATCHER), true); } public void testWatcherBasicLicense() throws Exception { - assertAllowed(BASIC, true, XPackLicenseState::isWatcherAllowed, false); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.WATCHER), false); } public void testWatcherInactive() { - assertAllowed(BASIC, false, XPackLicenseState::isWatcherAllowed, false); + assertAllowed(BASIC, false, s -> s.isAllowed(Feature.WATCHER), false); } public void testWatcherInactivePlatinumGoldTrial() throws Exception { - assertAllowed(TRIAL, false, XPackLicenseState::isWatcherAllowed, false); - assertAllowed(GOLD, false, XPackLicenseState::isWatcherAllowed, false); - assertAllowed(PLATINUM, false, XPackLicenseState::isWatcherAllowed, false); - assertAllowed(STANDARD, false, XPackLicenseState::isWatcherAllowed, false); + assertAllowed(TRIAL, false, s -> s.isAllowed(Feature.WATCHER), false); + assertAllowed(GOLD, false, s -> s.isAllowed(Feature.WATCHER), false); + assertAllowed(PLATINUM, false, s -> s.isAllowed(Feature.WATCHER), false); + assertAllowed(STANDARD, false, s -> s.isAllowed(Feature.WATCHER), false); } public void testGraphPlatinumTrial() throws Exception { - assertAllowed(TRIAL, true, XPackLicenseState::isGraphAllowed, true); - assertAllowed(PLATINUM, true, XPackLicenseState::isGraphAllowed, true); + assertAllowed(TRIAL, true, s -> s.isAllowed(Feature.GRAPH), true); + assertAllowed(PLATINUM, true, s -> s.isAllowed(Feature.GRAPH), true); } public void testGraphBasic() throws Exception { - assertAllowed(BASIC, true, XPackLicenseState::isGraphAllowed, false); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.GRAPH), false); } public void testGraphStandard() throws Exception { - assertAllowed(STANDARD, true, XPackLicenseState::isGraphAllowed, false); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.GRAPH), false); } public void testGraphInactiveBasic() { - assertAllowed(BASIC, false, XPackLicenseState::isGraphAllowed, false); + assertAllowed(BASIC, false, s -> s.isAllowed(Feature.GRAPH), false); } public void testGraphInactivePlatinumTrial() throws Exception { - assertAllowed(TRIAL, false, XPackLicenseState::isMachineLearningAllowed, false); - assertAllowed(PLATINUM, false, XPackLicenseState::isMachineLearningAllowed, false); + assertAllowed(TRIAL, false, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); + assertAllowed(PLATINUM, false, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); } public void testMachineLearningPlatinumTrial() throws Exception { - assertAllowed(TRIAL, true, XPackLicenseState::isMachineLearningAllowed, true); - assertAllowed(PLATINUM, true, XPackLicenseState::isMachineLearningAllowed, true); + assertAllowed(TRIAL, true, s -> s.isAllowed(Feature.MACHINE_LEARNING), true); + assertAllowed(PLATINUM, true, s -> s.isAllowed(Feature.MACHINE_LEARNING), true); } public void testMachineLearningBasic() throws Exception { - assertAllowed(BASIC, true, XPackLicenseState::isMachineLearningAllowed, false); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); } public void testMachineLearningStandard() throws Exception { - assertAllowed(STANDARD, true, XPackLicenseState::isMachineLearningAllowed, false); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); } public void testMachineLearningInactiveBasic() { - assertAllowed(BASIC, false, XPackLicenseState::isMachineLearningAllowed, false); + assertAllowed(BASIC, false, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); } public void testMachineLearningInactivePlatinumTrial() throws Exception { - assertAllowed(TRIAL, false, XPackLicenseState::isMachineLearningAllowed, false); - assertAllowed(PLATINUM, false, XPackLicenseState::isMachineLearningAllowed, false); + assertAllowed(TRIAL, false, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); + assertAllowed(PLATINUM, false, s -> s.isAllowed(Feature.MACHINE_LEARNING), false); } public void testLogstashPlatinumGoldTrialStandard() throws Exception { - assertAllowed(TRIAL, true, XPackLicenseState::isLogstashAllowed, true); - assertAllowed(GOLD, true, XPackLicenseState::isLogstashAllowed, true); - assertAllowed(PLATINUM, true, XPackLicenseState::isLogstashAllowed, true); - assertAllowed(STANDARD, true, XPackLicenseState::isLogstashAllowed, true); + assertAllowed(TRIAL, true, s -> s.isAllowed(Feature.LOGSTASH), true); + assertAllowed(GOLD, true, s -> s.isAllowed(Feature.LOGSTASH), true); + assertAllowed(PLATINUM, true, s -> s.isAllowed(Feature.LOGSTASH), true); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.LOGSTASH), true); } public void testLogstashBasicLicense() throws Exception { - assertAllowed(BASIC, true, XPackLicenseState::isLogstashAllowed, false); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.LOGSTASH), false); } public void testLogstashInactive() { - assertAllowed(BASIC, false, XPackLicenseState::isLogstashAllowed, false); - assertAllowed(TRIAL, false, XPackLicenseState::isLogstashAllowed, false); - assertAllowed(GOLD, false, XPackLicenseState::isLogstashAllowed, false); - assertAllowed(PLATINUM, false, XPackLicenseState::isLogstashAllowed, false); - assertAllowed(STANDARD, false, XPackLicenseState::isLogstashAllowed, false); + assertAllowed(BASIC, false, s -> s.isAllowed(Feature.LOGSTASH), false); + assertAllowed(TRIAL, false, s -> s.isAllowed(Feature.LOGSTASH), false); + assertAllowed(GOLD, false, s -> s.isAllowed(Feature.LOGSTASH), false); + assertAllowed(PLATINUM, false, s -> s.isAllowed(Feature.LOGSTASH), false); + assertAllowed(STANDARD, false, s -> s.isAllowed(Feature.LOGSTASH), false); } public void testSqlDefaults() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); - assertThat(licenseState.isSqlAllowed(), is(true)); - assertThat(licenseState.isJdbcAllowed(), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(true)); } public void testSqlBasic() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(BASIC, true, null); - assertThat(licenseState.isSqlAllowed(), is(true)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlBasicExpired() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(BASIC, false, null); - assertThat(licenseState.isSqlAllowed(), is(false)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlStandard() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(STANDARD, true, null); - assertThat(licenseState.isSqlAllowed(), is(true)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlStandardExpired() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(STANDARD, false, null); - assertThat(licenseState.isSqlAllowed(), is(false)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlGold() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(GOLD, true, null); - assertThat(licenseState.isSqlAllowed(), is(true)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlGoldExpired() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(GOLD, false, null); - assertThat(licenseState.isSqlAllowed(), is(false)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlPlatinum() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(PLATINUM, true, null); - assertThat(licenseState.isSqlAllowed(), is(true)); - assertThat(licenseState.isJdbcAllowed(), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(true)); } public void testSqlPlatinumExpired() { XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY); licenseState.update(PLATINUM, false, null); - assertThat(licenseState.isSqlAllowed(), is(false)); - assertThat(licenseState.isJdbcAllowed(), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.SQL), is(false)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.JDBC), is(false)); } public void testSqlAckAnyToTrialOrPlatinum() { @@ -482,63 +482,63 @@ public void testSqlAckTrialOrPlatinumToNotTrialOrPlatinum() { public void testCcrDefaults() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); - assertTrue(state.isCcrAllowed()); + assertTrue(state.isAllowed(XPackLicenseState.Feature.CCR)); } public void testCcrBasic() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(BASIC, true, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrBasicExpired() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(BASIC, false, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrStandard() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(STANDARD, true, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrStandardExpired() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(STANDARD, false, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrGold() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(GOLD, true, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrGoldExpired() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(GOLD, false, null); - assertThat(state.isCcrAllowed(), is(false)); + assertThat(state.isAllowed(XPackLicenseState.Feature.CCR), is(false)); } public void testCcrPlatinum() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(PLATINUM, true, null); - assertTrue(state.isCcrAllowed()); + assertTrue(state.isAllowed(XPackLicenseState.Feature.CCR)); } public void testCcrPlatinumExpired() { final XPackLicenseState state = new XPackLicenseState(Settings.EMPTY); state.update(PLATINUM, false, null); - assertFalse(state.isCcrAllowed()); + assertFalse(state.isAllowed(XPackLicenseState.Feature.CCR)); } public void testCcrAckAnyToTrialOrPlatinum() { @@ -550,14 +550,14 @@ public void testCcrAckTrialOrPlatinumToNotTrialOrPlatinum() { } public void testTransformBasic() throws Exception { - assertAllowed(BASIC, true, XPackLicenseState::isTransformAllowed, true); + assertAllowed(BASIC, true, s -> s.isAllowed(Feature.TRANSFORM), true); } public void testTransformStandard() throws Exception { - assertAllowed(STANDARD, true, XPackLicenseState::isTransformAllowed, true); + assertAllowed(STANDARD, true, s -> s.isAllowed(Feature.TRANSFORM), true); } public void testTransformInactiveBasic() { - assertAllowed(BASIC, false, XPackLicenseState::isTransformAllowed, false); + assertAllowed(BASIC, false, s -> s.isAllowed(Feature.TRANSFORM), false); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/watcher/actions/throttler/WatchThrottlerTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/watcher/actions/throttler/WatchThrottlerTests.java index fdad70e08d23f..5504a62350bc6 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/watcher/actions/throttler/WatchThrottlerTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/watcher/actions/throttler/WatchThrottlerTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.watcher.actions.throttler; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext; @@ -24,7 +25,7 @@ public void testThrottleDueToAck() throws Exception { Throttler.Result expectedResult = Throttler.Result.throttle(Throttler.Type.ACK, "_reason"); when(ackThrottler.throttle("_action", ctx)).thenReturn(expectedResult); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(true); ActionThrottler throttler = new ActionThrottler(periodThrottler, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); @@ -39,7 +40,7 @@ public void testThrottleDueToPeriod() throws Exception { when(periodThrottler.throttle("_action", ctx)).thenReturn(expectedResult); when(ackThrottler.throttle("_action", ctx)).thenReturn(Throttler.Result.NO); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(true); ActionThrottler throttler = new ActionThrottler(periodThrottler, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); @@ -55,7 +56,7 @@ public void testThrottleDueAckAndPeriod() throws Exception { Throttler.Result ackResult = Throttler.Result.throttle(Throttler.Type.ACK, "_reason_ack"); when(ackThrottler.throttle("_action", ctx)).thenReturn(ackResult); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(true); ActionThrottler throttler = new ActionThrottler(periodThrottler, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); @@ -70,7 +71,7 @@ public void testNoThrottle() throws Exception { when(periodThrottler.throttle("_action", ctx)).thenReturn(Throttler.Result.NO); when(ackThrottler.throttle("_action", ctx)).thenReturn(Throttler.Result.NO); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(true); ActionThrottler throttler = new ActionThrottler(periodThrottler, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); @@ -83,7 +84,7 @@ public void testWithoutPeriod() throws Exception { Throttler.Result ackResult = mock(Throttler.Result.class); when(ackThrottler.throttle("_action", ctx)).thenReturn(ackResult); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(true); ActionThrottler throttler = new ActionThrottler(null, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); @@ -96,7 +97,7 @@ public void testThatRestrictedLicenseReturnsCorrectResult() throws Exception { Throttler.Result ackResult = mock(Throttler.Result.class); when(ackThrottler.throttle("_action", ctx)).thenReturn(ackResult); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isWatcherAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.WATCHER)).thenReturn(false); ActionThrottler throttler = new ActionThrottler(null, ackThrottler, licenseState); Throttler.Result result = throttler.throttle("_action", ctx); assertThat(result, notNullValue()); diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java index bc16c98a2773c..21b20372d9fee 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/TransportDeprecationInfoAction.java @@ -87,7 +87,7 @@ protected ClusterBlockException checkBlock(DeprecationInfoAction.Request request @Override protected final void masterOperation(Task task, final DeprecationInfoAction.Request request, ClusterState state, final ActionListener listener) { - if (licenseState.isDeprecationAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.DEPRECATION)) { NodesDeprecationCheckRequest nodeDepReq = new NodesDeprecationCheckRequest("_all"); ClientHelper.executeAsyncWithOrigin(client, ClientHelper.DEPRECATION_ORIGIN, diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichInfoTransportAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichInfoTransportAction.java index fc75ec4be9c7e..fb93c82950edf 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichInfoTransportAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichInfoTransportAction.java @@ -39,7 +39,7 @@ public String name() { @Override public boolean available() { - return licenseState.isEnrichAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.ENRICH); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichUsageTransportAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichUsageTransportAction.java index 2b91e4ba7446d..929c03ca134e8 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichUsageTransportAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/action/EnrichUsageTransportAction.java @@ -56,7 +56,7 @@ protected void masterOperation( ClusterState state, ActionListener listener ) { - boolean available = licenseState.isEnrichAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ENRICH); listener.onResponse(new XPackUsageFeatureResponse(new EnrichFeatureSetUsage(available, enabled))); } } diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollectorTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollectorTests.java index 3e7e9935f9f85..6a3146b2b7b56 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollectorTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollectorTests.java @@ -46,14 +46,14 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { whenLocalNodeElectedMaster(isElectedMaster); // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); - when(licenseState.isEnrichAllowed()).thenReturn(enrichAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.ENRICH)).thenReturn(enrichAllowed); final EnrichStatsCollector collector = createCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } } @@ -61,8 +61,8 @@ public void testShouldCollectReturnsFalseIfNotMaster() { // regardless of enrich being enabled final Settings settings = randomFrom(enrichEnabledSettings(), enrichDisabledSettings()); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); - when(licenseState.isEnrichAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.ENRICH)).thenReturn(randomBoolean()); // this controls the blockage final boolean isElectedMaster = false; @@ -76,8 +76,8 @@ public void testShouldCollectReturnsFalseIfEnrichIsDisabled() { final Settings settings = enrichDisabledSettings(); boolean isMonitoringAllowed = randomBoolean(); - when(licenseState.isMonitoringAllowed()).thenReturn(isMonitoringAllowed); - when(licenseState.isEnrichAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(isMonitoringAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.ENRICH)).thenReturn(randomBoolean()); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -87,7 +87,7 @@ public void testShouldCollectReturnsFalseIfEnrichIsDisabled() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } if (isElectedMaster && isMonitoringAllowed) { // The enrich setting is only checked if the node is master and monitoring is allowed, @@ -100,9 +100,9 @@ public void testShouldCollectReturnsFalseIfEnrichIsNotAllowed() { final Settings settings = randomFrom(enrichEnabledSettings(), enrichDisabledSettings()); boolean isMonitoringAllowed = randomBoolean(); - when(licenseState.isMonitoringAllowed()).thenReturn(isMonitoringAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(isMonitoringAllowed); // this is controls the blockage - when(licenseState.isEnrichAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.ENRICH)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -111,7 +111,7 @@ public void testShouldCollectReturnsFalseIfEnrichIsNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); } if (isElectedMaster && isMonitoringAllowed && settings.get(XPackSettings.ENRICH_ENABLED_SETTING.getKey()) != null) { assertSettingDeprecationsAndWarnings(new Setting[] { XPackSettings.ENRICH_ENABLED_SETTING }); @@ -121,15 +121,15 @@ public void testShouldCollectReturnsFalseIfEnrichIsNotAllowed() { public void testShouldCollectReturnsTrue() { final Settings settings = enrichEnabledSettings(); - when(licenseState.isMonitoringAllowed()).thenReturn(true); - when(licenseState.isEnrichAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.ENRICH)).thenReturn(true); final boolean isElectedMaster = true; final EnrichStatsCollector collector = createCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING); if (settings.get(XPackSettings.ENRICH_ENABLED_SETTING.getKey()) != null) { assertSettingDeprecationsAndWarnings(new Setting[] { XPackSettings.ENRICH_ENABLED_SETTING }); } diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlInfoTransportAction.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlInfoTransportAction.java index 9fc238a8436db..7798e91a6f7b4 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlInfoTransportAction.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlInfoTransportAction.java @@ -19,7 +19,7 @@ public class EqlInfoTransportAction extends XPackInfoFeatureTransportAction { private final boolean enabled; private final XPackLicenseState licenseState; - + @Inject public EqlInfoTransportAction(TransportService transportService, ActionFilters actionFilters, Settings settings, XPackLicenseState licenseState) { @@ -27,7 +27,7 @@ public EqlInfoTransportAction(TransportService transportService, ActionFilters a this.enabled = EqlPlugin.isEnabled(settings); this.licenseState = licenseState; } - + @Override public String name() { return XPackField.EQL; @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isEqlAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.EQL); } @Override diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlUsageTransportAction.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlUsageTransportAction.java index 3d5b9affe9091..06e518af71fae 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlUsageTransportAction.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/EqlUsageTransportAction.java @@ -52,7 +52,7 @@ public EqlUsageTransportAction(TransportService transportService, ClusterService @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isEqlAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.EQL); if (enabled) { EqlStatsRequest eqlRequest = new EqlStatsRequest(); eqlRequest.includeStats(true); diff --git a/x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/EqlInfoTransportActionTests.java b/x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/EqlInfoTransportActionTests.java index 2c0f12df17ad1..887af17db768f 100644 --- a/x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/EqlInfoTransportActionTests.java +++ b/x-pack/plugin/eql/src/test/java/org/elasticsearch/xpack/eql/EqlInfoTransportActionTests.java @@ -59,7 +59,7 @@ public void testAvailable() { EqlInfoTransportAction featureSet = new EqlInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isEqlAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.EQL)).thenReturn(available); assertThat(featureSet.available(), is(available)); } @@ -67,7 +67,7 @@ public void testEnabled() { boolean enabled = randomBoolean(); Settings.Builder settings = Settings.builder(); settings.put("xpack.eql.enabled", enabled); - + EqlInfoTransportAction featureSet = new EqlInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), settings.build(), licenseState); assertThat(featureSet.enabled(), is(enabled)); @@ -109,11 +109,11 @@ public void testUsageStats() throws Exception { PlainActionFuture future = new PlainActionFuture<>(); usageAction.masterOperation(mock(Task.class), null, null, future); EqlFeatureSetUsage eqlUsage = (EqlFeatureSetUsage) future.get().getUsage(); - + long fooBarBaz = ObjectPath.eval("foo.bar.baz", eqlUsage.stats()); long fooFoo = ObjectPath.eval("foo.foo", eqlUsage.stats()); long spam = ObjectPath.eval("spam", eqlUsage.stats()); - + assertThat(eqlUsage.stats().keySet(), containsInAnyOrder("foo", "spam")); assertThat(fooBarBaz, is(5L)); assertThat(fooFoo, is(1L)); diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphInfoTransportAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphInfoTransportAction.java index d8c181e5196d5..ded865f4e2f47 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphInfoTransportAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState != null && licenseState.isGraphAllowed(); + return licenseState != null && licenseState.isAllowed(XPackLicenseState.Feature.GRAPH); } @Override diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphUsageTransportAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphUsageTransportAction.java index 15a0b44909288..8c24af53abf3e 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphUsageTransportAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/GraphUsageTransportAction.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -42,7 +43,7 @@ public GraphUsageTransportAction(TransportService transportService, ClusterServi protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { GraphFeatureSetUsage usage = - new GraphFeatureSetUsage(licenseState.isGraphAllowed(), XPackSettings.GRAPH_ENABLED.get(settings)); + new GraphFeatureSetUsage(licenseState.isAllowed(Feature.GRAPH), XPackSettings.GRAPH_ENABLED.get(settings)); listener.onResponse(new XPackUsageFeatureResponse(usage)); } } diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java index c0c8822ac232f..563f9d496d054 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/action/TransportGraphExploreAction.java @@ -92,7 +92,7 @@ public TransportGraphExploreAction(ThreadPool threadPool, NodeClient client, Tra @Override protected void doExecute(Task task, GraphExploreRequest request, ActionListener listener) { - if (licenseState.isGraphAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.GRAPH)) { new AsyncGraphAction(request, listener).start(); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.GRAPH)); diff --git a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/GraphInfoTransportActionTests.java b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/GraphInfoTransportActionTests.java index 9e99a9679333f..0ccbe01e81021 100644 --- a/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/GraphInfoTransportActionTests.java +++ b/x-pack/plugin/graph/src/test/java/org/elasticsearch/xpack/graph/GraphInfoTransportActionTests.java @@ -34,7 +34,7 @@ public void testAvailable() throws Exception { GraphInfoTransportAction featureSet = new GraphInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isGraphAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.GRAPH)).thenReturn(available); assertThat(featureSet.available(), is(available)); var usageAction = new GraphUsageTransportAction(mock(TransportService.class), null, null, diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportAction.java index 8356bf1ebe5ab..864c614dcd133 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isIndexLifecycleAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.ILM); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java index 057089286e763..26844ef4b9302 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java @@ -49,7 +49,7 @@ public IndexLifecycleUsageTransportAction(TransportService transportService, Clu @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isIndexLifecycleAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ILM); Metadata metadata = state.metadata(); IndexLifecycleMetadata lifecycleMetadata = metadata.custom(IndexLifecycleMetadata.TYPE); final IndexLifecycleFeatureSetUsage usage; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMInfoTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMInfoTransportAction.java index 4e42967052544..e90084bd5ea32 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMInfoTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isIndexLifecycleAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.ILM); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java index 14e8a4feb270d..2058e11d8a9b3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SLMUsageTransportAction.java @@ -42,7 +42,7 @@ public SLMUsageTransportAction(TransportService transportService, ClusterService @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isIndexLifecycleAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ILM); final SnapshotLifecycleMetadata slmMeta = state.metadata().custom(SnapshotLifecycleMetadata.TYPE); final SLMFeatureSetUsage usage = new SLMFeatureSetUsage(available, enabled, slmMeta == null ? null : slmMeta.getStats()); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java index 2f2c447dedfc7..f02c5d07b549a 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleInfoTransportActionTests.java @@ -59,10 +59,10 @@ public void testAvailable() { IndexLifecycleInfoTransportAction featureSet = new IndexLifecycleInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); - when(licenseState.isIndexLifecycleAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.ILM)).thenReturn(false); assertThat(featureSet.available(), equalTo(false)); - when(licenseState.isIndexLifecycleAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.ILM)).thenReturn(true); assertThat(featureSet.available(), equalTo(true)); } diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportAction.java index 4aa77af2988f4..2c2eb1d89c3db 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportAction.java @@ -39,7 +39,7 @@ public String name() { @Override public boolean available() { - return licenseState.isLogstashAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.LOGSTASH); } @Override diff --git a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashUsageTransportAction.java b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashUsageTransportAction.java index e03cc822ec746..338839edf0ef2 100644 --- a/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashUsageTransportAction.java +++ b/x-pack/plugin/logstash/src/main/java/org/elasticsearch/xpack/logstash/LogstashUsageTransportAction.java @@ -57,7 +57,7 @@ protected void masterOperation( ClusterState state, ActionListener listener ) { - boolean available = licenseState.isLogstashAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.LOGSTASH); LogstashFeatureSetUsage usage = new LogstashFeatureSetUsage(available, XPackSettings.LOGSTASH_ENABLED.get(settings)); listener.onResponse(new XPackUsageFeatureResponse(usage)); } diff --git a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java index e3872352b944d..d192e74356781 100644 --- a/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java +++ b/x-pack/plugin/logstash/src/test/java/org/elasticsearch/xpack/logstash/LogstashInfoTransportActionTests.java @@ -68,7 +68,7 @@ public void testAvailable() throws Exception { licenseState ); boolean available = randomBoolean(); - when(licenseState.isLogstashAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.LOGSTASH)).thenReturn(available); assertThat(featureSet.available(), is(available)); var usageAction = newUsageAction(Settings.EMPTY, available); @@ -85,7 +85,7 @@ public void testAvailable() throws Exception { private LogstashUsageTransportAction newUsageAction(Settings settings, boolean available) { XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isLogstashAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.LOGSTASH)).thenReturn(available); return new LogstashUsageTransportAction( mock(TransportService.class), null, diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/InvalidLicenseEnforcer.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/InvalidLicenseEnforcer.java index bff85d691b4b8..5be9a3c91ddb4 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/InvalidLicenseEnforcer.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/InvalidLicenseEnforcer.java @@ -48,7 +48,7 @@ void listenForLicenseStateChanges() { @Override public void licenseStateChanged() { assert licenseStateListenerRegistered; - if (licenseState.isMachineLearningAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING) == false) { // if the license has expired, close jobs and datafeeds threadPool.generic().execute(new AbstractRunnable() { @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportAction.java index 07fdc476cc307..5d14e02945324 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isMachineLearningAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java index 8b23cd168d881..4fb4b18e8c38f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java @@ -86,7 +86,7 @@ public MachineLearningUsageTransportAction(TransportService transportService, Cl protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { if (enabled == false) { - MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isMachineLearningAllowed(), enabled, + MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), 0); listener.onResponse(new XPackUsageFeatureResponse(usage)); return; @@ -102,7 +102,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat ActionListener trainedModelConfigCountListener = ActionListener.wrap( response -> { addTrainedModelStats(response, inferenceUsage); - MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isMachineLearningAllowed(), + MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled, jobsUsage, datafeedsUsage, analyticsUsage, inferenceUsage, nodeCount); listener.onResponse(new XPackUsageFeatureResponse(usage)); }, diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java index 3772001494eac..7621866c7d99c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportExplainDataFrameAnalyticsAction.java @@ -69,7 +69,7 @@ public TransportExplainDataFrameAnalyticsAction(TransportService transportServic protected void doExecute(Task task, PutDataFrameAnalyticsAction.Request request, ActionListener listener) { - if (licenseState.isMachineLearningAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING) == false) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); return; } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java index 5a255813b83a7..d229f4decbee7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportInternalInferModelAction.java @@ -73,7 +73,7 @@ protected void doExecute(Task task, Request request, ActionListener li listener::onFailure ); - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { responseBuilder.setLicensed(true); this.modelLoadingService.getModel(request.getModelId(), getModelListener); } else { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportOpenJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportOpenJobAction.java index 7139b75624792..091986b057d8c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportOpenJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportOpenJobAction.java @@ -215,7 +215,7 @@ protected void masterOperation(Task task, OpenJobAction.Request request, Cluster } OpenJobAction.JobParams jobParams = request.getJobParams(); - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { // Clear job finished time once the job is started and respond ActionListener clearJobFinishTime = ActionListener.wrap( diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDataFrameAnalyticsAction.java index a4c9beac5ba62..96ee17639b6a6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDataFrameAnalyticsAction.java @@ -231,7 +231,7 @@ private void updateDocMappingAndPutConfig(DataFrameAnalyticsConfig config, @Override protected void doExecute(Task task, PutDataFrameAnalyticsAction.Request request, ActionListener listener) { - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { super.doExecute(task, request, listener); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDatafeedAction.java index ce026956f5ba8..cf5739ece4f20 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutDatafeedAction.java @@ -266,7 +266,7 @@ protected ClusterBlockException checkBlock(PutDatafeedAction.Request request, Cl @Override protected void doExecute(Task task, PutDatafeedAction.Request request, ActionListener listener) { - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { super.doExecute(task, request, listener); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutJobAction.java index aefbb9538bd54..824056ab74925 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutJobAction.java @@ -68,7 +68,7 @@ protected ClusterBlockException checkBlock(PutJobAction.Request request, Cluster @Override protected void doExecute(Task task, PutJobAction.Request request, ActionListener listener) { - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { super.doExecute(task, request, listener); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutTrainedModelAction.java index 8b8499391bb3d..58a07fe7942e4 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportPutTrainedModelAction.java @@ -221,7 +221,7 @@ protected ClusterBlockException checkBlock(Request request, ClusterState state) @Override protected void doExecute(Task task, Request request, ActionListener listener) { - if (licenseState.isMachineLearningAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)) { super.doExecute(task, request, listener); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java index 03c7ab0ce2862..31c3c772e729c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDataFrameAnalyticsAction.java @@ -155,7 +155,7 @@ protected ClusterBlockException checkBlock(StartDataFrameAnalyticsAction.Request @Override protected void masterOperation(Task task, StartDataFrameAnalyticsAction.Request request, ClusterState state, ActionListener listener) { - if (licenseState.isMachineLearningAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING) == false) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); return; } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java index 274fde654945d..aa3f6c1c2790e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java @@ -156,7 +156,7 @@ protected NodeAcknowledgedResponse read(StreamInput in) throws IOException { protected void masterOperation(Task task, StartDatafeedAction.Request request, ClusterState state, ActionListener listener) { StartDatafeedAction.DatafeedParams params = request.getParams(); - if (licenseState.isMachineLearningAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING) == false) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.MACHINE_LEARNING)); return; } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingIT.java index e857f259bb53f..02af98d67e391 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/license/MachineLearningLicensingIT.java @@ -701,7 +701,7 @@ private static OperationMode randomLicenseType() { private static void assertMLAllowed(boolean expected) { for (XPackLicenseState licenseState : internalCluster().getInstances(XPackLicenseState.class)) { - assertEquals(licenseState.isMachineLearningAllowed(), expected); + assertEquals(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), expected); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportActionTests.java index bb3fc5601108d..d31001006262f 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MachineLearningInfoTransportActionTests.java @@ -131,7 +131,7 @@ public void testAvailable() throws Exception { MachineLearningInfoTransportAction featureSet = new MachineLearningInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), commonSettings, licenseState); boolean available = randomBoolean(); - when(licenseState.isMachineLearningAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(available); assertThat(featureSet.available(), is(available)); var usageAction = newUsageAction(commonSettings); PlainActionFuture future = new PlainActionFuture<>(); @@ -170,7 +170,7 @@ public void testEnabled() throws Exception { } public void testUsage() throws Exception { - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); Settings.Builder settings = Settings.builder().put(commonSettings); settings.put("xpack.ml.enabled", true); @@ -328,7 +328,7 @@ public void testUsage() throws Exception { } public void testUsageDisabledML() throws Exception { - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); Settings.Builder settings = Settings.builder().put(commonSettings); settings.put("xpack.ml.enabled", false); @@ -348,7 +348,7 @@ public void testUsageDisabledML() throws Exception { } public void testNodeCount() throws Exception { - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); int nodeCount = randomIntBetween(1, 3); ClusterState clusterState = givenNodeCount(nodeCount); Settings.Builder settings = Settings.builder().put(commonSettings); @@ -375,7 +375,7 @@ public void testNodeCount() throws Exception { } public void testUsageGivenMlMetadataNotInstalled() throws Exception { - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); Settings.Builder settings = Settings.builder().put(commonSettings); settings.put("xpack.ml.enabled", true); when(clusterService.state()).thenReturn(ClusterState.EMPTY_STATE); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsActionTests.java index 50810dfccaf7c..4b13ec879cd01 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsActionTests.java @@ -87,7 +87,7 @@ public Processor create(Map processorFactories, Strin public Map getProcessors(Processor.Parameters parameters) { Map factoryMap = new HashMap<>(); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); factoryMap.put(InferenceProcessor.TYPE, new InferenceProcessor.Factory(parameters.client, parameters.ingestService.getClusterService(), diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessorFactoryTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessorFactoryTests.java index 043cb0d06eec9..c82407f4e7949 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessorFactoryTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/ingest/InferenceProcessorFactoryTests.java @@ -57,7 +57,7 @@ public class InferenceProcessorFactoryTests extends ESTestCase { @Override public Map getProcessors(Processor.Parameters parameters) { XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); return Collections.singletonMap(InferenceProcessor.TYPE, new InferenceProcessor.Factory(parameters.client, parameters.ingestService.getClusterService(), @@ -87,7 +87,7 @@ public void setUpVariables() { ingestService = new IngestService(clusterService, tp, null, null, null, Collections.singletonList(SKINNY_PLUGIN), client); licenseState = mock(XPackLicenseState.class); - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); } public void testNumInferenceProcessors() throws Exception { diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportAction.java index 6769138e4caa0..56828bd8dddea 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isMonitoringAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.MONITORING); } @Override diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java index b7e3bf98b1c06..0b73438a40c22 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java @@ -51,7 +51,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat ActionListener listener) { final boolean collectionEnabled = monitoringService != null && monitoringService.isMonitoringActive(); var usage = - new MonitoringFeatureSetUsage(licenseState.isMonitoringAllowed(), enabled, collectionEnabled, exportersUsage(exporters)); + new MonitoringFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING), enabled, collectionEnabled, exportersUsage(exporters)); listener.onResponse(new XPackUsageFeatureResponse(usage)); } diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerService.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerService.java index 1dc2216839b59..2fd3d8f8ad3b8 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerService.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerService.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.util.concurrent.AbstractLifecycleRunnable; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.threadpool.Scheduler; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.monitoring.MonitoringField; @@ -86,11 +87,11 @@ private String executorName() { * This will ignore the global retention if the license does not allow retention updates. * * @return Never {@code null} - * @see XPackLicenseState#isUpdateRetentionAllowed() + * @see XPackLicenseState.Feature#MONITORING_UPDATE_RETENTION */ public TimeValue getRetention() { // we only care about their value if they are allowed to set it - if (licenseState.isUpdateRetentionAllowed() && globalRetention != null) { + if (licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION) && globalRetention != null) { return globalRetention; } else { @@ -108,7 +109,7 @@ public TimeValue getRetention() { */ public void setGlobalRetention(TimeValue globalRetention) { // notify the user that their setting will be ignored until they get the right license - if (licenseState.isUpdateRetentionAllowed() == false) { + if (licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION) == false) { logger.warn("[{}] setting will be ignored until an appropriate license is applied", MonitoringField.HISTORY_DURATION.getKey()); } @@ -165,7 +166,7 @@ class IndicesCleaner extends AbstractLifecycleRunnable { @Override protected void doRunInLifecycle() throws Exception { - if (licenseState.isMonitoringAllowed() == false) { + if (licenseState.isAllowed(Feature.MONITORING) == false) { logger.debug("cleaning service is disabled due to invalid license"); return; } diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/Collector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/Collector.java index 42bce22533b0c..acb306d33d2f7 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/Collector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/Collector.java @@ -73,7 +73,7 @@ public String toString() { * @param isElectedMaster true if the current local node is the elected master node */ protected boolean shouldCollect(final boolean isElectedMaster) { - if (licenseState.isMonitoringAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.MONITORING) == false) { logger.trace("collector [{}] can not collect data due to invalid license", name()); return false; } diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java index 8f8072ef5b864..4e53b81b720dd 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollector.java @@ -63,7 +63,7 @@ protected boolean shouldCollect(final boolean isElectedMaster) { return isElectedMaster && super.shouldCollect(isElectedMaster) && XPackSettings.CCR_ENABLED_SETTING.get(settings) - && licenseState.isCcrAllowed(); + && licenseState.isAllowed(XPackLicenseState.Feature.CCR); } diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollector.java index c2162c289dffe..78eda5b4e7268 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/enrich/EnrichStatsCollector.java @@ -55,7 +55,7 @@ protected boolean shouldCollect(final boolean isElectedMaster) { return isElectedMaster && super.shouldCollect(isElectedMaster) && XPackSettings.ENRICH_ENABLED_SETTING.get(settings) - && licenseState.isEnrichAllowed(); + && licenseState.isAllowed(XPackLicenseState.Feature.ENRICH); } @Override diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java index 2d33ec05237ca..07ac382fc739b 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollector.java @@ -62,7 +62,7 @@ protected boolean shouldCollect(final boolean isElectedMaster) { return isElectedMaster && super.shouldCollect(isElectedMaster) && XPackSettings.MACHINE_LEARNING_ENABLED.get(settings) - && licenseState.isMachineLearningAllowed(); + && licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING); } @Override diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResource.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResource.java index efec87cc919f4..d1201665424a1 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResource.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResource.java @@ -82,7 +82,7 @@ public ClusterAlertHttpResource(final String resourceOwnerName, @Override protected void doCheck(final RestClient client, final ActionListener listener) { // if we should be adding, then we need to check for existence - if (isWatchDefined() && licenseState.isMonitoringClusterAlertsAllowed()) { + if (isWatchDefined() && licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)) { final CheckedFunction watchChecker = (response) -> shouldReplaceClusterAlert(response, XContentType.JSON.xContent(), LAST_UPDATED_VERSION); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java index 25970ce6218c8..b7d27bd4a6990 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java @@ -37,6 +37,8 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import org.elasticsearch.xpack.core.ssl.SSLConfiguration; import org.elasticsearch.xpack.core.ssl.SSLConfigurationSettings; @@ -835,7 +837,7 @@ private static void configureClusterAlertsResources(final Config config, final S @Override public void openBulk(final ActionListener listener) { - final boolean canUseClusterAlerts = config.licenseState().isMonitoringClusterAlertsAllowed(); + final boolean canUseClusterAlerts = config.licenseState().isAllowed(Feature.MONITORING_CLUSTER_ALERTS); // if this changes between updates, then we need to add OR remove the watches if (clusterAlertsAllowed.compareAndSet(!canUseClusterAlerts, canUseClusterAlerts)) { diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java index 2b7a6aaa4cfb0..b4f3831fb2445 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/local/LocalExporter.java @@ -458,7 +458,7 @@ private boolean hasValidVersion(final Object version, final long minimumVersion) */ private void getClusterAlertsInstallationAsyncActions(final boolean indexExists, final List asyncActions, final AtomicInteger pendingResponses) { - final boolean canAddWatches = licenseState.isMonitoringClusterAlertsAllowed(); + final boolean canAddWatches = licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS); for (final String watchId : ClusterAlertsUtil.WATCH_IDS) { final String uniqueWatchId = ClusterAlertsUtil.createUniqueWatchId(clusterService, watchId); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportActionTests.java index ba4454e76117d..d2ba572c434af 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringInfoTransportActionTests.java @@ -50,7 +50,7 @@ public void testAvailable() { MonitoringInfoTransportAction featureSet = new MonitoringInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isMonitoringAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(available); assertThat(featureSet.available(), is(available)); } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerServiceTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerServiceTests.java index 6ebcebd625a3a..f738308b50b2f 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerServiceTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/cleaner/CleanerServiceTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; @@ -65,32 +66,32 @@ public void testGetRetentionWithSettingWithUpdatesAllowed() { TimeValue expected = TimeValue.timeValueHours(25); Settings settings = Settings.builder().put(MonitoringField.HISTORY_DURATION.getKey(), expected.getStringRep()).build(); - when(licenseState.isUpdateRetentionAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION)).thenReturn(true); assertEquals(expected, new CleanerService(settings, clusterSettings, threadPool, licenseState).getRetention()); - verify(licenseState).isUpdateRetentionAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING_UPDATE_RETENTION); } public void testGetRetentionDefaultValueWithNoSettings() { - when(licenseState.isUpdateRetentionAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION)).thenReturn(true); assertEquals(MonitoringField.HISTORY_DURATION.get(Settings.EMPTY), new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licenseState).getRetention()); - verify(licenseState).isUpdateRetentionAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING_UPDATE_RETENTION); } public void testGetRetentionDefaultValueWithSettingsButUpdatesNotAllowed() { TimeValue notExpected = TimeValue.timeValueHours(25); Settings settings = Settings.builder().put(MonitoringField.HISTORY_DURATION.getKey(), notExpected.getStringRep()).build(); - when(licenseState.isUpdateRetentionAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION)).thenReturn(false); assertEquals(MonitoringField.HISTORY_DURATION.get(Settings.EMPTY), new CleanerService(settings, clusterSettings, threadPool, licenseState).getRetention()); - verify(licenseState).isUpdateRetentionAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING_UPDATE_RETENTION); } public void testSetGlobalRetention() { @@ -98,7 +99,7 @@ public void testSetGlobalRetention() { // only thing calling this method and it will use the settings object to validate the time value TimeValue expected = TimeValue.timeValueHours(2); - when(licenseState.isUpdateRetentionAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION)).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licenseState); @@ -106,7 +107,7 @@ public void testSetGlobalRetention() { assertEquals(expected, service.getRetention()); - verify(licenseState, times(2)).isUpdateRetentionAllowed(); // once by set, once by get + verify(licenseState, times(2)).isAllowed(Feature.MONITORING_UPDATE_RETENTION); // once by set, once by get } public void testSetGlobalRetentionAppliesEvenIfLicenseDisallows() { @@ -115,7 +116,7 @@ public void testSetGlobalRetentionAppliesEvenIfLicenseDisallows() { TimeValue expected = TimeValue.timeValueHours(2); // required to be true on the second call for it to see it take effect - when(licenseState.isUpdateRetentionAllowed()).thenReturn(false).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING_UPDATE_RETENTION)).thenReturn(false).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licenseState); @@ -125,7 +126,7 @@ public void testSetGlobalRetentionAppliesEvenIfLicenseDisallows() { // uses allow=true assertEquals(expected, service.getRetention()); - verify(licenseState, times(2)).isUpdateRetentionAllowed(); + verify(licenseState, times(2)).isAllowed(Feature.MONITORING_UPDATE_RETENTION); } public void testNextExecutionDelay() { @@ -157,7 +158,7 @@ public void testExecution() throws InterruptedException { logger.debug("--> creates a cleaner service that cleans every second"); XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, licenseState, threadPool, new TestExecutionScheduler(1_000)); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java index 2d4e356007d71..b33c9ad21d6c2 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java @@ -20,6 +20,8 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.recovery.RecoveryState; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase; @@ -50,7 +52,7 @@ public class IndexRecoveryCollectorTests extends BaseCollectorTestCase { public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -58,23 +60,23 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsFalseIfNotMaster() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final IndexRecoveryCollector collector = new IndexRecoveryCollector(clusterService, licenseState, client); assertThat(collector.shouldCollect(false), is(false)); } public void testShouldCollectReturnsTrue() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final IndexRecoveryCollector collector = new IndexRecoveryCollector(clusterService, licenseState, client); assertThat(collector.shouldCollect(true), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } public void testDoCollect() throws Exception { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java index 38b02e94aa8b8..088cc2e8fe04e 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java @@ -17,6 +17,8 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase; @@ -45,7 +47,7 @@ public class IndexStatsCollectorTests extends BaseCollectorTestCase { public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -53,23 +55,23 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsFalseIfNotMaster() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final IndexStatsCollector collector = new IndexStatsCollector(clusterService, licenseState, client); assertThat(collector.shouldCollect(false), is(false)); } public void testShouldCollectReturnsTrue() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final IndexStatsCollector collector = new IndexStatsCollector(clusterService, licenseState, client); assertThat(collector.shouldCollect(true), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } public void testDoCollect() throws Exception { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java index f09940b436683..bdc8487405d4e 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsCollectorTests.java @@ -11,6 +11,8 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; @@ -48,14 +50,14 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { whenLocalNodeElectedMaster(isElectedMaster); // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); - when(licenseState.isMachineLearningAllowed()).thenReturn(mlAllowed); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(mlAllowed); final JobStatsCollector collector = new JobStatsCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } @@ -63,8 +65,8 @@ public void testShouldCollectReturnsFalseIfNotMaster() { // regardless of ML being enabled final Settings settings = randomFrom(mlEnabledSettings(), mlDisabledSettings()); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); - when(licenseState.isMachineLearningAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(randomBoolean()); // this controls the blockage final boolean isElectedMaster = false; @@ -77,8 +79,8 @@ public void testShouldCollectReturnsFalseIfMLIsDisabled() { // this is controls the blockage final Settings settings = mlDisabledSettings(); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); - when(licenseState.isMachineLearningAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(randomBoolean()); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(randomBoolean()); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -88,16 +90,16 @@ public void testShouldCollectReturnsFalseIfMLIsDisabled() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsFalseIfMLIsNotAllowed() { final Settings settings = randomFrom(mlEnabledSettings(), mlDisabledSettings()); - when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean()); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(randomBoolean()); // this is controls the blockage - when(licenseState.isMachineLearningAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -106,22 +108,22 @@ public void testShouldCollectReturnsFalseIfMLIsNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsTrue() { final Settings settings = mlEnabledSettings(); - when(licenseState.isMonitoringAllowed()).thenReturn(true); - when(licenseState.isMachineLearningAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING)).thenReturn(true); final boolean isElectedMaster = true; final JobStatsCollector collector = new JobStatsCollector(settings, clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } public void testDoCollect() throws Exception { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java index d2650df9a39f7..fcff930df9796 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java @@ -15,6 +15,8 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase; @@ -38,7 +40,7 @@ public class NodeStatsCollectorTests extends BaseCollectorTestCase { public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -46,22 +48,22 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsTrue() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final boolean isElectedMaster = true; final NodeStatsCollector collector = new NodeStatsCollector(clusterService, licenseState, client); assertThat(collector.shouldCollect(isElectedMaster), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } public void testDoCollectWithFailures() throws Exception { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final TimeValue timeout = TimeValue.parseTimeValue(randomPositiveTimeValue(), NodeStatsCollectorTests.class.getName()); withCollectionTimeout(NodeStatsCollector.NODE_STATS_TIMEOUT, timeout); @@ -84,7 +86,7 @@ public void testDoCollectWithFailures() throws Exception { } public void testDoCollect() throws Exception { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(1, 120)); withCollectionTimeout(NodeStatsCollector.NODE_STATS_TIMEOUT, timeout); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java index 0d46d51cf8bae..6af9ea1213c28 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java @@ -12,6 +12,8 @@ import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.common.Strings; import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; import org.elasticsearch.xpack.monitoring.BaseCollectorTestCase; @@ -43,7 +45,7 @@ public class ShardsCollectorTests extends BaseCollectorTestCase { public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { // this controls the blockage - when(licenseState.isMonitoringAllowed()).thenReturn(false); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(false); final boolean isElectedMaster = randomBoolean(); whenLocalNodeElectedMaster(isElectedMaster); @@ -51,12 +53,12 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() { assertThat(collector.shouldCollect(isElectedMaster), is(false)); if (isElectedMaster) { - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } } public void testShouldCollectReturnsFalseIfNotMaster() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); // this controls the blockage whenLocalNodeElectedMaster(false); @@ -66,13 +68,13 @@ public void testShouldCollectReturnsFalseIfNotMaster() { } public void testShouldCollectReturnsTrue() { - when(licenseState.isMonitoringAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.MONITORING)).thenReturn(true); whenLocalNodeElectedMaster(true); final ShardsCollector collector = new ShardsCollector(clusterService, licenseState); assertThat(collector.shouldCollect(true), is(true)); - verify(licenseState).isMonitoringAllowed(); + verify(licenseState).isAllowed(Feature.MONITORING); } public void testDoCollectWhenNoClusterState() throws Exception { diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResourceTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResourceTests.java index a7ede37505e8c..f788356cfad0c 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResourceTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/ClusterAlertHttpResourceTests.java @@ -60,7 +60,7 @@ public void testWatchToHttpEntity() throws IOException { } public void testDoCheckGetWatchExists() throws IOException { - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(true); final HttpEntity entity = entityForClusterAlert(true, minimumVersion); @@ -68,7 +68,7 @@ public void testDoCheckGetWatchExists() throws IOException { } public void testDoCheckGetWatchDoesNotExist() throws IOException { - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(true); if (randomBoolean()) { // it does not exist because it's literally not there @@ -82,7 +82,7 @@ public void testDoCheckGetWatchDoesNotExist() throws IOException { } public void testDoCheckWithExceptionGetWatchError() throws IOException { - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(true); if (randomBoolean()) { // error because of a server error @@ -100,7 +100,7 @@ public void testDoCheckAsDeleteWatchExistsWhenNoWatchIsSpecified() throws IOExce final boolean clusterAlertsAllowed = randomBoolean(); // should not matter - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(clusterAlertsAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(clusterAlertsAllowed); assertCheckAsDeleteExists(noWatchResource, "/_watcher/watch", watchId); } @@ -110,19 +110,19 @@ public void testDoCheckWithExceptionAsDeleteWatchErrorWhenNoWatchIsSpecified() t final boolean clusterAlertsAllowed = randomBoolean(); // should not matter - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(clusterAlertsAllowed); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(clusterAlertsAllowed); assertCheckAsDeleteWithException(noWatchResource, "/_watcher/watch", watchId); } public void testDoCheckAsDeleteWatchExists() throws IOException { - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(false); assertCheckAsDeleteExists(resource, "/_watcher/watch", watchId); } public void testDoCheckWithExceptionAsDeleteWatchError() throws IOException { - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(false); assertCheckAsDeleteWithException(resource, "/_watcher/watch", watchId); } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java index 59cf0fb735b04..ffa4e456d7d73 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporterResourceTests.java @@ -735,7 +735,7 @@ private void whenWatcherCanBeUsed(final boolean validLicense) { when(state.metadata()).thenReturn(metadata); when(metadata.clusterUUID()).thenReturn("the_clusters_uuid"); - when(licenseState.isMonitoringClusterAlertsAllowed()).thenReturn(validLicense); + when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING_CLUSTER_ALERTS)).thenReturn(validLicense); final HttpEntity entity = new StringEntity("{\"features\":{\"watcher\":{\"enabled\":true,\"available\":true}}}", ContentType.APPLICATION_JSON); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupInfoTransportAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupInfoTransportAction.java index 93330872554cc..7ff25b8cf13c3 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupInfoTransportAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isRollupAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.ROLLUP); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupUsageTransportAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupUsageTransportAction.java index 5253c05517e84..cf476f8b60d60 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupUsageTransportAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupUsageTransportAction.java @@ -41,7 +41,7 @@ public RollupUsageTransportAction(TransportService transportService, ClusterServ @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isRollupAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ROLLUP); // TODO expose the currently running rollup tasks on this node? Unclear the best way to do that RollupFeatureSetUsage usage = new RollupFeatureSetUsage(available, XPackSettings.ROLLUP_ENABLED.get(settings)); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index c3c3ce24e89c2..59b8cdb8f9352 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -97,7 +97,7 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException { protected void masterOperation(Task task, PutRollupJobAction.Request request, ClusterState clusterState, ActionListener listener) { - if (!licenseState.isRollupAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.ROLLUP)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.ROLLUP)); return; } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportStartRollupAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportStartRollupAction.java index 2b35d79e98d6f..858e17655f44c 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportStartRollupAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportStartRollupAction.java @@ -47,7 +47,7 @@ protected void processTasks(StartRollupJobAction.Request request, Consumer listener) { - if (!licenseState.isRollupAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.ROLLUP)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.ROLLUP)); return; } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupInfoTransportActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupInfoTransportActionTests.java index 68e413951e0b5..f701609959bcf 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupInfoTransportActionTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupInfoTransportActionTests.java @@ -38,7 +38,7 @@ public void testAvailable() { RollupInfoTransportAction featureSet = new RollupInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isRollupAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.ROLLUP)).thenReturn(available); assertThat(featureSet.available(), is(available)); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityInfoTransportAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityInfoTransportAction.java index 2fa87e4607100..88a2696450b7e 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityInfoTransportAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityInfoTransportAction.java @@ -34,7 +34,7 @@ public String name() { @Override public boolean available() { - return licenseState.isSecurityAvailable(); + return licenseState.isAllowed(XPackLicenseState.Feature.SECURITY); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityUsageTransportAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityUsageTransportAction.java index ce732276409c9..760107c51bea8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityUsageTransportAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityUsageTransportAction.java @@ -86,7 +86,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat final CountDown countDown = new CountDown(3); final Runnable doCountDown = () -> { if (countDown.countDown()) { - var usage = new SecurityFeatureSetUsage(licenseState.isSecurityAvailable(), enabled, + var usage = new SecurityFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY), enabled, realmsUsageRef.get(), rolesUsageRef.get(), roleMappingUsageRef.get(), sslUsage, auditUsage, ipFilterUsage, anonymousUsage, tokenServiceUsage, apiKeyServiceUsage, fips140Usage); listener.onResponse(new XPackUsageFeatureResponse(usage)); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilter.java index a09aed8605f0e..d19d2a3ae57e5 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilter.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.XPackField; @@ -72,7 +73,7 @@ public void app A functional requirement - when the license of security is disabled (invalid/expires), security will continue to operate normally, except all read operations will be blocked. */ - if (licenseState.isStatsAndHealthAllowed() == false && LICENSE_EXPIRATION_ACTION_MATCHER.test(action)) { + if (licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH) == false && LICENSE_EXPIRATION_ACTION_MATCHER.test(action)) { logger.error("blocking [{}] operation due to expired license. Cluster health, cluster stats and indices stats \n" + "operations are blocked on license expiration. All data operations (read and write) continue to work. \n" + "If you have a new license, please update it. Otherwise, please reach out to your support contact.", action); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandler.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandler.java index fb2444e764735..fb025012c0b69 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandler.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandler.java @@ -68,7 +68,7 @@ protected final RestChannelConsumer prepareRequest(RestRequest request, NodeClie protected Exception checkFeatureAvailable(RestRequest request) { if (XPackSettings.SECURITY_ENABLED.get(settings) == false) { return new IllegalStateException("Security is not enabled but a security rest handler is registered"); - } else if (licenseState.isSecurityAvailable() == false) { + } else if (licenseState.isAllowed(XPackLicenseState.Feature.SECURITY) == false) { return LicenseUtils.newComplianceException(XPackField.SECURITY); } else if (licenseState.isSecurityEnabled() == false) { return new ElasticsearchException("Security must be explicitly enabled when using a [" + diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListener.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListener.java index 572f78d1a3a1a..6b61e71165ce1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListener.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListener.java @@ -35,7 +35,7 @@ public SecurityStatusChangeListener(XPackLicenseState licenseState) { */ @Override public synchronized void licenseStateChanged() { - final boolean newState = licenseState.isSecurityAvailable() && licenseState.isSecurityEnabled(); + final boolean newState = licenseState.isAllowed(XPackLicenseState.Feature.SECURITY) && licenseState.isSecurityEnabled(); // old state might be null (undefined) so do Object comparison if (Objects.equals(newState, securityEnabled) == false) { logger.info("Active license is now [{}]; Security is {}", licenseState.getOperationMode(), newState ? "enabled" : "disabled"); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityInfoTransportActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityInfoTransportActionTests.java index bc31a50965a54..160163dfa5661 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityInfoTransportActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityInfoTransportActionTests.java @@ -71,10 +71,10 @@ public void init() throws Exception { public void testAvailable() { SecurityInfoTransportAction featureSet = new SecurityInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), licenseState); - when(licenseState.isSecurityAvailable()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); assertThat(featureSet.available(), is(true)); - when(licenseState.isSecurityAvailable()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(false); assertThat(featureSet.available(), is(false)); } @@ -94,7 +94,7 @@ public void testUsage() throws Exception { final boolean authcAuthzAvailable = randomBoolean(); final boolean explicitlyDisabled = randomBoolean(); final boolean enabled = explicitlyDisabled == false && randomBoolean(); - when(licenseState.isSecurityAvailable()).thenReturn(authcAuthzAvailable); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(authcAuthzAvailable); when(licenseState.isSecurityEnabled()).thenReturn(enabled); Settings.Builder settings = Settings.builder().put(this.settings); @@ -248,7 +248,7 @@ public void testUsage() throws Exception { } public void testUsageOnTrialLicenseWithSecurityDisabledByDefault() throws Exception { - when(licenseState.isSecurityAvailable()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); when(licenseState.isSecurityEnabled()).thenReturn(false); Settings.Builder settings = Settings.builder().put(this.settings); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilterTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilterTests.java index e2fd531c2c224..090aaa5ce2674 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilterTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/filter/SecurityActionFilterTests.java @@ -24,6 +24,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.tasks.Task; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -66,7 +67,7 @@ public void init() throws Exception { authzService = mock(AuthorizationService.class); licenseState = mock(XPackLicenseState.class); when(licenseState.isSecurityEnabled()).thenReturn(true); - when(licenseState.isStatsAndHealthAllowed()).thenReturn(true); + when(licenseState.isAllowed(Feature.SECURITY_STATS_AND_HEALTH)).thenReturn(true); ThreadPool threadPool = mock(ThreadPool.class); threadContext = new ThreadContext(Settings.EMPTY); when(threadPool.getThreadContext()).thenReturn(threadContext); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java index 1c61bf8720872..1ee44219a43d8 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java @@ -30,7 +30,7 @@ public void testSecurityBaseRestHandlerChecksLicenseState() throws Exception { final boolean securityDefaultEnabled = randomBoolean(); final AtomicBoolean consumerCalled = new AtomicBoolean(false); final XPackLicenseState licenseState = mock(XPackLicenseState.class); - when(licenseState.isSecurityAvailable()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); when(licenseState.isSecurityEnabled()).thenReturn(securityDefaultEnabled); when(licenseState.getOperationMode()).thenReturn( randomFrom(License.OperationMode.BASIC, License.OperationMode.STANDARD, License.OperationMode.GOLD)); @@ -63,7 +63,7 @@ protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClien verifyZeroInteractions(licenseState); handler.handleRequest(fakeRestRequest, fakeRestChannel, client); - verify(licenseState).isSecurityAvailable(); + verify(licenseState).isAllowed(XPackLicenseState.Feature.SECURITY); if (securityDefaultEnabled) { assertTrue(consumerCalled.get()); assertEquals(0, fakeRestChannel.responses().get()); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java index 09b9331570eef..691fab1046274 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java @@ -54,7 +54,7 @@ public void setUp() throws Exception { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .build(); threadPool = new ThreadPool(settings); - when(mockLicenseState.isSecurityAvailable()).thenReturn(true); + when(mockLicenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); when(mockLicenseState.isSecurityEnabled()).thenReturn(true); when(mockLicenseState.isAllowed(Feature.SECURITY_API_KEY_SERVICE)).thenReturn(true); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java index 9b2ca757d9a9d..8fc3686869dad 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java @@ -55,7 +55,7 @@ public void setUp() throws Exception { settings = Settings.builder().put("path.home", createTempDir().toString()).put("node.name", "test-" + getTestName()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build(); threadPool = new ThreadPool(settings); - when(mockLicenseState.isSecurityAvailable()).thenReturn(true); + when(mockLicenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); when(mockLicenseState.isSecurityEnabled()).thenReturn(true); when(mockLicenseState.isAllowed(Feature.SECURITY_API_KEY_SERVICE)).thenReturn(true); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java index eb392b4e70e74..ee0629007f361 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java @@ -54,7 +54,7 @@ public void setUp() throws Exception { .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()) .build(); threadPool = new ThreadPool(settings); - when(mockLicenseState.isSecurityAvailable()).thenReturn(true); + when(mockLicenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); when(mockLicenseState.isSecurityEnabled()).thenReturn(true); when(mockLicenseState.isAllowed(Feature.SECURITY_API_KEY_SERVICE)).thenReturn(true); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java index fd2418c09f7dc..b2823bc863755 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java @@ -42,7 +42,7 @@ public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); final RestGetUserPrivilegesAction action = new RestGetUserPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); - when(licenseState.isSecurityAvailable()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(false); final FakeRestRequest request = new FakeRestRequest(); final FakeRestChannel channel = new FakeRestChannel(request, true, 1); action.handleRequest(request, channel, mock(NodeClient.class)); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java index 50561f427b9b8..3ae635a20da65 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java @@ -53,7 +53,7 @@ public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); final RestHasPrivilegesAction action = new RestHasPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); - when(licenseState.isSecurityAvailable()).thenReturn(false); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(false); try (XContentBuilder bodyBuilder = JsonXContent.contentBuilder().startObject().endObject()) { final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withPath("/_security/user/_has_privileges/") diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListenerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListenerTests.java index 249c6b3d2a4e5..3e09b20a7cf9a 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListenerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityStatusChangeListenerTests.java @@ -30,7 +30,7 @@ public class SecurityStatusChangeListenerTests extends ESTestCase { @Before public void setup() throws IllegalAccessException { licenseState = Mockito.mock(XPackLicenseState.class); - when(licenseState.isSecurityAvailable()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.SECURITY)).thenReturn(true); listener = new SecurityStatusChangeListener(licenseState); diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportAction.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportAction.java index c701d5b4adb5d..f3fbb31e35b0b 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportAction.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportAction.java @@ -32,7 +32,7 @@ public String name() { @Override public boolean available() { - return licenseState.isSpatialAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.SPATIAL); } @Override diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialUsageTransportAction.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialUsageTransportAction.java index a2873a2bcf938..915e03ad05a4e 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialUsageTransportAction.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/SpatialUsageTransportAction.java @@ -40,7 +40,7 @@ public SpatialUsageTransportAction(TransportService transportService, ClusterSer @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - SpatialFeatureSetUsage usage = new SpatialFeatureSetUsage(licenseState.isSpatialAllowed(), true); + SpatialFeatureSetUsage usage = new SpatialFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.SPATIAL), true); listener.onResponse(new XPackUsageFeatureResponse(usage)); } } diff --git a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportActionTests.java b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportActionTests.java index b3236cf7265b9..dd89a23312464 100644 --- a/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportActionTests.java +++ b/x-pack/plugin/spatial/src/test/java/org/elasticsearch/xpack/spatial/SpatialInfoTransportActionTests.java @@ -34,7 +34,7 @@ public void testAvailable() throws Exception { SpatialInfoTransportAction featureSet = new SpatialInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isSpatialAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.SPATIAL)).thenReturn(available); assertThat(featureSet.available(), is(available)); var usageAction = new SpatialUsageTransportAction(mock(TransportService.class), null, null, diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlInfoTransportAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlInfoTransportAction.java index 45a076f251273..3d57a6ab40e5a 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlInfoTransportAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlInfoTransportAction.java @@ -19,7 +19,7 @@ public class SqlInfoTransportAction extends XPackInfoFeatureTransportAction { private final boolean enabled; private final XPackLicenseState licenseState; - + @Inject public SqlInfoTransportAction(TransportService transportService, ActionFilters actionFilters, Settings settings, XPackLicenseState licenseState) { @@ -27,7 +27,7 @@ public SqlInfoTransportAction(TransportService transportService, ActionFilters a this.enabled = XPackSettings.SQL_ENABLED.get(settings); this.licenseState = licenseState; } - + @Override public String name() { return XPackField.SQL; @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isSqlAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.SQL); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlUsageTransportAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlUsageTransportAction.java index 3114f263eee29..7e59f3844434d 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlUsageTransportAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlUsageTransportAction.java @@ -52,7 +52,7 @@ public SqlUsageTransportAction(TransportService transportService, ClusterService @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean available = licenseState.isSqlAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.SQL); if (enabled) { SqlStatsRequest sqlRequest = new SqlStatsRequest(); sqlRequest.includeStats(true); diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java index 00fbb1ba9ab87..afb132e062f66 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java @@ -58,18 +58,18 @@ public class SqlPlugin extends Plugin implements ActionPlugin { XPackLicenseState licenseState = getLicenseState(); switch (mode) { case JDBC: - if (licenseState.isJdbcAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.JDBC) == false) { throw LicenseUtils.newComplianceException("jdbc"); } break; case ODBC: - if (licenseState.isOdbcAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.ODBC) == false) { throw LicenseUtils.newComplianceException("odbc"); } break; case PLAIN: case CLI: - if (licenseState.isSqlAllowed() == false) { + if (licenseState.isAllowed(XPackLicenseState.Feature.SQL) == false) { throw LicenseUtils.newComplianceException(XPackField.SQL); } break; diff --git a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/SqlInfoTransportActionTests.java b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/SqlInfoTransportActionTests.java index 2419dfb188aee..d76b97381cc01 100644 --- a/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/SqlInfoTransportActionTests.java +++ b/x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/SqlInfoTransportActionTests.java @@ -61,7 +61,7 @@ public void testAvailable() { SqlInfoTransportAction featureSet = new SqlInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isSqlAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.SQL)).thenReturn(available); assertThat(featureSet.available(), is(available)); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformInfoTransportAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformInfoTransportAction.java index 847f37a5b9d4b..11a2f0d7fccf5 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformInfoTransportAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformInfoTransportAction.java @@ -80,7 +80,7 @@ public String name() { @Override public boolean available() { - return licenseState.isTransformAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformUsageTransportAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformUsageTransportAction.java index f5d2b29263efd..09ce8ed72e086 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformUsageTransportAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/TransformUsageTransportAction.java @@ -84,7 +84,7 @@ protected void masterOperation( ClusterState state, ActionListener listener ) { - boolean available = licenseState.isTransformAllowed(); + boolean available = licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM); if (enabled == false) { var usage = new TransformFeatureSetUsage(available, enabled, Collections.emptyMap(), new TransformIndexerStats()); listener.onResponse(new XPackUsageFeatureResponse(usage)); diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java index 9fef913443312..59982d60ea67b 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java @@ -131,7 +131,7 @@ protected TransportPreviewTransformAction( @Override protected void doExecute(Task task, PreviewTransformAction.Request request, ActionListener listener) { - if (!licenseState.isTransformAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.TRANSFORM)); return; } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java index 8798d807ff7aa..1942dfe830bbc 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPutTransformAction.java @@ -203,7 +203,7 @@ protected AcknowledgedResponse read(StreamInput in) throws IOException { @Override protected void masterOperation(Task task, Request request, ClusterState clusterState, ActionListener listener) { - if (!licenseState.isTransformAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.TRANSFORM)); return; } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java index 1dbafd387a9f7..6430e6ecd88c8 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java @@ -163,7 +163,7 @@ protected void masterOperation( ClusterState state, ActionListener listener ) throws Exception { - if (!licenseState.isTransformAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.TRANSFORM)); return; } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java index 34f294cb7b876..680bffb171019 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportUpdateTransformAction.java @@ -147,7 +147,7 @@ protected Response read(StreamInput in) throws IOException { @Override protected void masterOperation(Task task, Request request, ClusterState clusterState, ActionListener listener) { - if (!licenseState.isTransformAllowed()) { + if (!licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.TRANSFORM)); return; } diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java index b2329207a79ea..a8957a051060d 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/TransformInfoTransportActionTests.java @@ -59,7 +59,7 @@ public void testAvailable() { licenseState ); boolean available = randomBoolean(); - when(licenseState.isTransformAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)).thenReturn(available); assertThat(featureSet.available(), is(available)); } @@ -132,7 +132,7 @@ private static Aggregation buildAgg(String name, double value) { } public void testUsageDisabled() throws IOException, InterruptedException, ExecutionException { - when(licenseState.isTransformAllowed()).thenReturn(true); + when(licenseState.isAllowed(XPackLicenseState.Feature.TRANSFORM)).thenReturn(true); Settings.Builder settings = Settings.builder(); settings.put("xpack.transform.enabled", false); var usageAction = new TransformUsageTransportAction( diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportAction.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportAction.java index 7974b6ec246f3..c522c3e4ec27f 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportAction.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isVectorsAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.VECTORS); } @Override diff --git a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsUsageTransportAction.java b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsUsageTransportAction.java index aaa1ad48e6a15..fb8461c5bd7bd 100644 --- a/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsUsageTransportAction.java +++ b/x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/VectorsUsageTransportAction.java @@ -47,7 +47,7 @@ public VectorsUsageTransportAction(TransportService transportService, ClusterSer @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - boolean vectorsAvailable = licenseState.isVectorsAllowed(); + boolean vectorsAvailable = licenseState.isAllowed(XPackLicenseState.Feature.VECTORS); boolean vectorsEnabled = XPackSettings.VECTORS_ENABLED.get(settings); int numDenseVectorFields = 0; int numSparseVectorFields = 0; diff --git a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportActionTests.java b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportActionTests.java index af3a0c2b7e0a0..5ac635ee45c2e 100644 --- a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportActionTests.java +++ b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/VectorsInfoTransportActionTests.java @@ -36,7 +36,7 @@ public void testAvailable() throws Exception { VectorsInfoTransportAction featureSet = new VectorsInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isVectorsAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.VECTORS)).thenReturn(available); assertThat(featureSet.available(), is(available)); var usageAction = new VectorsUsageTransportAction(mock(TransportService.class), null, null, diff --git a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeFeatureSet.java b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeFeatureSet.java index a412df53e6205..5755d605d62c1 100644 --- a/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeFeatureSet.java +++ b/x-pack/plugin/voting-only-node/src/main/java/org/elasticsearch/cluster/coordination/VotingOnlyNodeFeatureSet.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -42,7 +43,7 @@ public String name() { @Override public boolean available() { - return licenseState != null && licenseState.isVotingOnlyAllowed(); + return licenseState != null && licenseState.isAllowed(Feature.VOTING_ONLY); } @Override @@ -66,7 +67,7 @@ public UsageTransportAction(TransportService transportService, ClusterService cl @Override protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { - final boolean available = licenseState.isVotingOnlyAllowed(); + final boolean available = licenseState.isAllowed(Feature.VOTING_ONLY); final VotingOnlyNodeFeatureSetUsage usage = new VotingOnlyNodeFeatureSetUsage(available); listener.onResponse(new XPackUsageFeatureResponse(usage)); @@ -91,7 +92,7 @@ protected String name() { @Override protected boolean available() { - return licenseState.isVotingOnlyAllowed(); + return licenseState.isAllowed(Feature.VOTING_ONLY); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportAction.java index 63f071e7d1e50..13c43b79a5354 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportAction.java @@ -35,7 +35,7 @@ public String name() { @Override public boolean available() { - return licenseState.isWatcherAllowed(); + return licenseState.isAllowed(XPackLicenseState.Feature.WATCHER); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherUsageTransportAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherUsageTransportAction.java index 231d6a7f811a2..65051448dbcb2 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherUsageTransportAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherUsageTransportAction.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.protocol.xpack.XPackUsageRequest; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; @@ -69,13 +70,13 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat .collect(Collectors.toList()); Counters mergedCounters = Counters.merge(countersPerNode); WatcherFeatureSetUsage usage = - new WatcherFeatureSetUsage(licenseState.isWatcherAllowed(), true, mergedCounters.toNestedMap()); + new WatcherFeatureSetUsage(licenseState.isAllowed(Feature.WATCHER), true, mergedCounters.toNestedMap()); listener.onResponse(new XPackUsageFeatureResponse(usage)); }, listener::onFailure)); } } else { WatcherFeatureSetUsage usage = - new WatcherFeatureSetUsage(licenseState.isWatcherAllowed(), false, Collections.emptyMap()); + new WatcherFeatureSetUsage(licenseState.isAllowed(Feature.WATCHER), false, Collections.emptyMap()); listener.onResponse(new XPackUsageFeatureResponse(usage)); } } diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/WatcherTransportAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/WatcherTransportAction.java index 5033535c2fd58..88f43931898e8 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/WatcherTransportAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/transport/actions/WatcherTransportAction.java @@ -35,7 +35,7 @@ protected String executor() { @Override protected final void doExecute(Task task, final Request request, ActionListener listener) { - if (licenseState.isWatcherAllowed()) { + if (licenseState.isAllowed(XPackLicenseState.Feature.WATCHER)) { doExecute(request, listener); } else { listener.onFailure(LicenseUtils.newComplianceException(XPackField.WATCHER)); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportActionTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportActionTests.java index d5e5232794991..5e5f47416695e 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportActionTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherInfoTransportActionTests.java @@ -68,7 +68,7 @@ public void testAvailable() { WatcherInfoTransportAction featureSet = new WatcherInfoTransportAction( mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState); boolean available = randomBoolean(); - when(licenseState.isWatcherAllowed()).thenReturn(available); + when(licenseState.isAllowed(XPackLicenseState.Feature.WATCHER)).thenReturn(available); assertThat(featureSet.available(), is(available)); } diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index ab1c6e295fcbd..6588218fd93ee 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -513,7 +513,7 @@ protected void startWatcher() throws Exception { protected void ensureLicenseEnabled() throws Exception { assertBusy(() -> { for (XPackLicenseState licenseState : internalCluster().getInstances(XPackLicenseState.class)) { - assertThat(licenseState.isWatcherAllowed(), is(true)); + assertThat(licenseState.isAllowed(XPackLicenseState.Feature.WATCHER), is(true)); } }); } From 46e2ab6ce5bc06ac6cd52a5a8843f0efefe32e5f Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 Apr 2020 10:49:04 -0700 Subject: [PATCH 2/5] fix checkstyle --- .../main/java/org/elasticsearch/license/XPackLicenseState.java | 1 - .../xpack/monitoring/exporter/http/HttpExporter.java | 1 - 2 files changed, 2 deletions(-) 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 e0cf15f9db59d..83e7d4f2d622b 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 @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.index.translog.Translog; import org.elasticsearch.license.License.OperationMode; import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackSettings; diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java index b7d27bd4a6990..6789025a5cf1c 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/http/HttpExporter.java @@ -37,7 +37,6 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import org.elasticsearch.xpack.core.ssl.SSLConfiguration; From 7769b0feddbbdd2f72e6c115f0b29134279bf8e6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 Apr 2020 10:58:44 -0700 Subject: [PATCH 3/5] line length --- .../xpack/monitoring/MonitoringUsageTransportAction.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java index 0b73438a40c22..8e443504c2bb2 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringUsageTransportAction.java @@ -50,8 +50,8 @@ public MonitoringUsageTransportAction(TransportService transportService, Cluster protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { final boolean collectionEnabled = monitoringService != null && monitoringService.isMonitoringActive(); - var usage = - new MonitoringFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING), enabled, collectionEnabled, exportersUsage(exporters)); + var usage = new MonitoringFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING), + enabled, collectionEnabled, exportersUsage(exporters)); listener.onResponse(new XPackUsageFeatureResponse(usage)); } From d316607eb3b353316e697c8d094a0fc2816d85ce Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 Apr 2020 11:40:24 -0700 Subject: [PATCH 4/5] line length --- .../xpack/ml/MachineLearningUsageTransportAction.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java index 4fb4b18e8c38f..fe22ab9189e0c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearningUsageTransportAction.java @@ -86,7 +86,8 @@ public MachineLearningUsageTransportAction(TransportService transportService, Cl protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state, ActionListener listener) { if (enabled == false) { - MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled, + MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage( + licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), 0); listener.onResponse(new XPackUsageFeatureResponse(usage)); return; @@ -102,7 +103,8 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat ActionListener trainedModelConfigCountListener = ActionListener.wrap( response -> { addTrainedModelStats(response, inferenceUsage); - MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage(licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), + MachineLearningFeatureSetUsage usage = new MachineLearningFeatureSetUsage( + licenseState.isAllowed(XPackLicenseState.Feature.MACHINE_LEARNING), enabled, jobsUsage, datafeedsUsage, analyticsUsage, inferenceUsage, nodeCount); listener.onResponse(new XPackUsageFeatureResponse(usage)); }, From 2a38d0e7527cc9437c367e977293d468413c6250 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 29 Apr 2020 12:06:25 -0700 Subject: [PATCH 5/5] more checkstyle --- .../collector/indices/IndexRecoveryCollectorTests.java | 1 - .../monitoring/collector/indices/IndexStatsCollectorTests.java | 1 - .../xpack/monitoring/collector/node/NodeStatsCollectorTests.java | 1 - .../xpack/monitoring/collector/shards/ShardsCollectorTests.java | 1 - 4 files changed, 4 deletions(-) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java index b33c9ad21d6c2..be02a8d346f6a 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java @@ -20,7 +20,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java index 088cc2e8fe04e..40946f56d56fe 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexStatsCollectorTests.java @@ -17,7 +17,6 @@ import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java index fcff930df9796..f87409dd84a80 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsCollectorTests.java @@ -15,7 +15,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc; diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java index 6af9ea1213c28..f831fa3dcdc77 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/shards/ShardsCollectorTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.routing.TestShardRouting; import org.elasticsearch.common.Strings; import org.elasticsearch.index.shard.ShardId; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState.Feature; import org.elasticsearch.xpack.core.monitoring.MonitoredSystem; import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringDoc;