Skip to content

Commit 316a2f1

Browse files
authored
Convert remaining license methods to isAllowed (elastic#55908)
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.
1 parent 3b7ae2d commit 316a2f1

File tree

109 files changed

+362
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+362
-440
lines changed

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/AnalyticsPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
153153

154154
private static <T> ContextParser<String, T> checkLicense(ContextParser<String, T> realParser) {
155155
return (parser, name) -> {
156-
if (getLicenseState().isAnalyticsAllowed() == false) {
156+
if (getLicenseState().isAllowed(XPackLicenseState.Feature.ANALYTICS) == false) {
157157
throw LicenseUtils.newComplianceException(XPackField.ANALYTICS);
158158
}
159159
return realParser.parse(parser, name);

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public String name() {
3131

3232
@Override
3333
public boolean available() {
34-
return licenseState.isAnalyticsAllowed();
34+
return licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS);
3535
}
3636

3737
@Override

x-pack/plugin/analytics/src/main/java/org/elasticsearch/xpack/analytics/action/AnalyticsUsageTransportAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public AnalyticsUsageTransportAction(TransportService transportService, ClusterS
4242
@Override
4343
protected void masterOperation(Task task, XPackUsageRequest request, ClusterState state,
4444
ActionListener<XPackUsageFeatureResponse> listener) {
45-
boolean available = licenseState.isAnalyticsAllowed();
45+
boolean available = licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS);
4646
if (available) {
4747
AnalyticsStatsAction.Request statsRequest = new AnalyticsStatsAction.Request();
4848
statsRequest.setParentTask(clusterService.localNode().getId(), task.getId());

x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/action/AnalyticsInfoTransportActionTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testAvailable() throws Exception {
6363
AnalyticsInfoTransportAction featureSet = new AnalyticsInfoTransportAction(
6464
mock(TransportService.class), mock(ActionFilters.class), licenseState);
6565
boolean available = randomBoolean();
66-
when(licenseState.isAnalyticsAllowed()).thenReturn(available);
66+
when(licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS)).thenReturn(available);
6767
assertThat(featureSet.available(), is(available));
6868
Client client = mockClient();
6969
AnalyticsUsageTransportAction usageAction = new AnalyticsUsageTransportAction(mock(TransportService.class), clusterService, null,
@@ -89,7 +89,7 @@ public void testEnabled() throws Exception {
8989
assertThat(featureSet.enabled(), is(true));
9090
assertTrue(featureSet.enabled());
9191
boolean available = randomBoolean();
92-
when(licenseState.isAnalyticsAllowed()).thenReturn(available);
92+
when(licenseState.isAllowed(XPackLicenseState.Feature.ANALYTICS)).thenReturn(available);
9393
Client client = mockClient();
9494
AnalyticsUsageTransportAction usageAction = new AnalyticsUsageTransportAction(mock(TransportService.class),
9595
clusterService, null, mock(ActionFilters.class), null, licenseState, client);

x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public class CcrLicenseChecker {
7272
* Constructs a CCR license checker with the default rule based on the license state for checking if CCR is allowed.
7373
*/
7474
CcrLicenseChecker() {
75-
this(XPackPlugin.getSharedLicenseState()::isCcrAllowed, XPackPlugin.getSharedLicenseState()::isSecurityEnabled);
75+
this(() -> XPackPlugin.getSharedLicenseState().isAllowed(XPackLicenseState.Feature.CCR),
76+
XPackPlugin.getSharedLicenseState()::isSecurityEnabled);
7677
}
7778

7879
/**

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CCRInfoTransportActionTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public void testAvailable() {
4747
CCRInfoTransportAction featureSet = new CCRInfoTransportAction(
4848
mock(TransportService.class), mock(ActionFilters.class), Settings.EMPTY, licenseState);
4949

50-
when(licenseState.isCcrAllowed()).thenReturn(false);
50+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(false);
5151
assertThat(featureSet.available(), equalTo(false));
5252

53-
when(licenseState.isCcrAllowed()).thenReturn(true);
53+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(true);
5454
assertThat(featureSet.available(), equalTo(true));
5555
}
5656

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/monitoring/collector/ccr/StatsCollectorTests.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ public void testShouldCollectReturnsFalseIfMonitoringNotAllowed() {
4646
whenLocalNodeElectedMaster(isElectedMaster);
4747

4848
// this controls the blockage
49-
when(licenseState.isMonitoringAllowed()).thenReturn(false);
50-
when(licenseState.isCcrAllowed()).thenReturn(ccrAllowed);
49+
when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(false);
50+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(ccrAllowed);
5151

5252
final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
5353

5454
assertThat(collector.shouldCollect(isElectedMaster), is(false));
5555
if (isElectedMaster) {
56-
verify(licenseState).isMonitoringAllowed();
56+
verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING);
5757
}
5858
}
5959

6060
public void testShouldCollectReturnsFalseIfNotMaster() {
6161
// regardless of CCR being enabled
6262
final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
6363

64-
when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
65-
when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
64+
when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean());
65+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(randomBoolean());
6666
// this controls the blockage
6767
final boolean isElectedMaster = false;
6868

@@ -75,8 +75,8 @@ public void testShouldCollectReturnsFalseIfCCRIsDisabled() {
7575
// this is controls the blockage
7676
final Settings settings = ccrDisabledSettings();
7777

78-
when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
79-
when(licenseState.isCcrAllowed()).thenReturn(randomBoolean());
78+
when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean());
79+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(randomBoolean());
8080

8181
final boolean isElectedMaster = randomBoolean();
8282
whenLocalNodeElectedMaster(isElectedMaster);
@@ -86,16 +86,16 @@ public void testShouldCollectReturnsFalseIfCCRIsDisabled() {
8686
assertThat(collector.shouldCollect(isElectedMaster), is(false));
8787

8888
if (isElectedMaster) {
89-
verify(licenseState).isMonitoringAllowed();
89+
verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING);
9090
}
9191
}
9292

9393
public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() {
9494
final Settings settings = randomFrom(ccrEnabledSettings(), ccrDisabledSettings());
9595

96-
when(licenseState.isMonitoringAllowed()).thenReturn(randomBoolean());
96+
when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(randomBoolean());
9797
// this is controls the blockage
98-
when(licenseState.isCcrAllowed()).thenReturn(false);
98+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(false);
9999
final boolean isElectedMaster = randomBoolean();
100100
whenLocalNodeElectedMaster(isElectedMaster);
101101

@@ -104,22 +104,22 @@ public void testShouldCollectReturnsFalseIfCCRIsNotAllowed() {
104104
assertThat(collector.shouldCollect(isElectedMaster), is(false));
105105

106106
if (isElectedMaster) {
107-
verify(licenseState).isMonitoringAllowed();
107+
verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING);
108108
}
109109
}
110110

111111
public void testShouldCollectReturnsTrue() {
112112
final Settings settings = ccrEnabledSettings();
113113

114-
when(licenseState.isMonitoringAllowed()).thenReturn(true);
115-
when(licenseState.isCcrAllowed()).thenReturn(true);
114+
when(licenseState.isAllowed(XPackLicenseState.Feature.MONITORING)).thenReturn(true);
115+
when(licenseState.isAllowed(XPackLicenseState.Feature.CCR)).thenReturn(true);
116116
final boolean isElectedMaster = true;
117117

118118
final StatsCollector collector = createCollector(settings, clusterService, licenseState, client);
119119

120120
assertThat(collector.shouldCollect(isElectedMaster), is(true));
121121

122-
verify(licenseState).isMonitoringAllowed();
122+
verify(licenseState).isAllowed(XPackLicenseState.Feature.MONITORING);
123123
}
124124

125125
public void testDoCollect() throws Exception {

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

+44-140
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class XPackLicenseState {
3636
* Each value defines the licensed state necessary for the feature to be allowed.
3737
*/
3838
public enum Feature {
39+
SECURITY(OperationMode.BASIC, false),
3940
SECURITY_IP_FILTERING(OperationMode.GOLD, false),
4041
SECURITY_AUDITING(OperationMode.GOLD, false),
4142
SECURITY_DLS_FLS(OperationMode.PLATINUM, false),
@@ -46,7 +47,49 @@ public enum Feature {
4647
SECURITY_API_KEY_SERVICE(OperationMode.MISSING, false),
4748
SECURITY_AUTHORIZATION_REALM(OperationMode.PLATINUM, true),
4849
SECURITY_AUTHORIZATION_ENGINE(OperationMode.PLATINUM, true),
49-
SPATIAL_GEO_CENTROID(OperationMode.GOLD, true);
50+
SECURITY_STATS_AND_HEALTH(OperationMode.MISSING, true),
51+
52+
WATCHER(OperationMode.STANDARD, true),
53+
MONITORING(OperationMode.MISSING, true),
54+
// TODO: should just check WATCHER directly?
55+
MONITORING_CLUSTER_ALERTS(OperationMode.STANDARD, true),
56+
MONITORING_UPDATE_RETENTION(OperationMode.STANDARD, false),
57+
58+
CCR(OperationMode.PLATINUM, true),
59+
60+
GRAPH(OperationMode.PLATINUM, true),
61+
62+
MACHINE_LEARNING(OperationMode.PLATINUM, true),
63+
64+
TRANSFORM(OperationMode.MISSING, true),
65+
66+
ROLLUP(OperationMode.MISSING, true),
67+
68+
VOTING_ONLY(OperationMode.MISSING, true),
69+
70+
LOGSTASH(OperationMode.STANDARD, true),
71+
72+
DEPRECATION(OperationMode.MISSING, true),
73+
74+
ILM(OperationMode.MISSING, true),
75+
76+
ENRICH(OperationMode.MISSING, true),
77+
78+
EQL(OperationMode.MISSING, true),
79+
80+
SQL(OperationMode.MISSING, true),
81+
82+
JDBC(OperationMode.PLATINUM, true),
83+
84+
ODBC(OperationMode.PLATINUM, true),
85+
86+
VECTORS(OperationMode.MISSING, true),
87+
88+
SPATIAL(OperationMode.MISSING, true),
89+
90+
SPATIAL_GEO_CENTROID(OperationMode.GOLD, true),
91+
92+
ANALYTICS(OperationMode.MISSING, true);
5093

5194
final OperationMode minimumOperationMode;
5295
final boolean needsActive;
@@ -432,57 +475,10 @@ public boolean isAllowed(Feature feature) {
432475
return isAllowedByLicense(feature.minimumOperationMode, feature.needsActive);
433476
}
434477

435-
public boolean isStatsAndHealthAllowed() {
436-
return allowForAllLicenses();
437-
}
438-
439-
public boolean isWatcherAllowed() {
440-
return isAllowedByLicense(OperationMode.STANDARD);
441-
}
442-
443-
public boolean isMonitoringAllowed() {
444-
return allowForAllLicenses();
445-
}
446-
447-
/**
448-
* Monitoring Cluster Alerts requires the equivalent license to use Watcher.
449-
*
450-
* @return {@link #isWatcherAllowed()}
451-
* @see #isWatcherAllowed()
452-
*/
453-
public boolean isMonitoringClusterAlertsAllowed() {
454-
return isWatcherAllowed();
455-
}
456-
457-
/**
458-
* Determine if the current license allows the retention of indices to be modified.
459-
* <p>
460-
* Only users with a non-{@link OperationMode#BASIC} license can update the retention period.
461-
* <p>
462-
* Note: This does not consider the <em>state</em> of the license so that any change is remembered for when they fix their license.
463-
*
464-
* @return {@code true} if the user is allowed to modify the retention. Otherwise {@code false}.
465-
*/
466-
public boolean isUpdateRetentionAllowed() {
467-
return isAllowedByLicense(OperationMode.STANDARD, false);
468-
}
469-
470-
public boolean isGraphAllowed() {
471-
return isAllowedByLicense(OperationMode.PLATINUM);
472-
}
473-
474-
public boolean isMachineLearningAllowed() {
475-
return isAllowedByLicense(OperationMode.PLATINUM);
476-
}
477-
478478
public static boolean isMachineLearningAllowedForOperationMode(final OperationMode operationMode) {
479479
return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM);
480480
}
481481

482-
public boolean isTransformAllowed() {
483-
return allowForAllLicenses();
484-
}
485-
486482
public static boolean isTransformAllowedForOperationMode(final OperationMode operationMode) {
487483
// any license (basic and upwards)
488484
return operationMode != License.OperationMode.MISSING;
@@ -492,91 +488,6 @@ public static boolean isFipsAllowedForOperationMode(final OperationMode operatio
492488
return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM);
493489
}
494490

495-
public boolean isRollupAllowed() {
496-
return allowForAllLicenses();
497-
}
498-
499-
public boolean isVotingOnlyAllowed() {
500-
return allowForAllLicenses();
501-
}
502-
503-
public boolean isLogstashAllowed() {
504-
return isAllowedByLicense(OperationMode.STANDARD);
505-
}
506-
507-
public boolean isBeatsAllowed() {
508-
return isAllowedByLicense(OperationMode.STANDARD);
509-
}
510-
511-
public boolean isDeprecationAllowed() {
512-
return allowForAllLicenses();
513-
}
514-
515-
public boolean isUpgradeAllowed() {
516-
return allowForAllLicenses();
517-
}
518-
519-
public boolean isIndexLifecycleAllowed() {
520-
return allowForAllLicenses();
521-
}
522-
523-
public boolean isEnrichAllowed() {
524-
return allowForAllLicenses();
525-
}
526-
527-
public boolean isEqlAllowed() {
528-
return allowForAllLicenses();
529-
}
530-
531-
public boolean isSqlAllowed() {
532-
return allowForAllLicenses();
533-
}
534-
535-
public boolean isJdbcAllowed() {
536-
return isAllowedByLicense(OperationMode.PLATINUM);
537-
}
538-
539-
public boolean isFlattenedAllowed() {
540-
return allowForAllLicenses();
541-
}
542-
543-
public boolean isVectorsAllowed() {
544-
return allowForAllLicenses();
545-
}
546-
547-
548-
/**
549-
* Determine if Wildcard support should be enabled.
550-
* <p>
551-
* Wildcard is available for all license types except {@link OperationMode#MISSING}
552-
*/
553-
public synchronized boolean isWildcardAllowed() {
554-
return status.active;
555-
}
556-
557-
public boolean isOdbcAllowed() {
558-
return isAllowedByLicense(OperationMode.PLATINUM);
559-
}
560-
561-
public boolean isSpatialAllowed() {
562-
return allowForAllLicenses();
563-
}
564-
565-
public boolean isAnalyticsAllowed() {
566-
return allowForAllLicenses();
567-
}
568-
569-
public boolean isConstantKeywordAllowed() {
570-
return allowForAllLicenses();
571-
}
572-
573-
/**
574-
* @return true if security is available to be used with the current license type
575-
*/
576-
public boolean isSecurityAvailable() {
577-
return checkAgainstStatus(status -> status.mode != OperationMode.MISSING);
578-
}
579-
580491
/**
581492
* Returns whether security is enabled, taking into account the default enabled state
582493
* based on the current license level.
@@ -616,13 +527,6 @@ private static boolean isSecurityEnabled(final OperationMode mode, final boolean
616527
}
617528
}
618529

619-
/**
620-
* Determine if cross-cluster replication is allowed
621-
*/
622-
public boolean isCcrAllowed() {
623-
return isAllowedByLicense(OperationMode.PLATINUM);
624-
}
625-
626530
public static boolean isCcrAllowedForOperationMode(final OperationMode operationMode) {
627531
return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM);
628532
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRInfoTransportAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public String name() {
4343

4444
@Override
4545
public boolean available() {
46-
return licenseState.isCcrAllowed();
46+
return licenseState.isAllowed(XPackLicenseState.Feature.CCR);
4747
}
4848

4949
@Override

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/ccr/CCRUsageTransportAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void masterOperation(Task task, XPackUsageRequest request, ClusterStat
6868
lastFollowTimeInMillis = Math.max(0, Instant.now().toEpochMilli() - lastFollowerIndexCreationDate);
6969
}
7070

71-
CCRInfoTransportAction.Usage usage = new CCRInfoTransportAction.Usage(licenseState.isCcrAllowed(),
71+
CCRInfoTransportAction.Usage usage = new CCRInfoTransportAction.Usage(licenseState.isAllowed(XPackLicenseState.Feature.CCR),
7272
XPackSettings.CCR_ENABLED_SETTING.get(settings), numberOfFollowerIndices, numberOfAutoFollowPatterns, lastFollowTimeInMillis);
7373
listener.onResponse(new XPackUsageFeatureResponse(usage));
7474
}

0 commit comments

Comments
 (0)