Skip to content

Commit 4ab16c6

Browse files
authored
Add enterprise mode and refactor license check (#51864)
Add enterprise operation mode to properly map enterprise license. Aslo refactor XPackLicenstate class to consolidate license status and mode checks. This class has many sychronised methods to check basically three things: * Minimum operation mode required * Whether security is enabled * Whether current license needs to be active Depends on the actual feature, either 1, 2 or all of above checks are performed. These are now consolidated in to 3 helper methods (2 of them are new). The synchronization is pushed down to the helper methods so actual checking methods no longer need to worry about it. resolves: #51081
1 parent cb34d1a commit 4ab16c6

File tree

21 files changed

+205
-220
lines changed

21 files changed

+205
-220
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ private static ElasticsearchStatusException indexMetadataNonCompliantRemoteLicen
412412
RemoteClusterLicenseChecker.buildErrorMessage(
413413
"ccr",
414414
licenseCheck.remoteClusterLicenseInfo(),
415-
RemoteClusterLicenseChecker::isLicensePlatinumOrTrial));
415+
RemoteClusterLicenseChecker::isAllowedByLicense));
416416
return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST);
417417
}
418418

@@ -426,7 +426,7 @@ private static ElasticsearchStatusException clusterStateNonCompliantRemoteLicens
426426
RemoteClusterLicenseChecker.buildErrorMessage(
427427
"ccr",
428428
licenseCheck.remoteClusterLicenseInfo(),
429-
RemoteClusterLicenseChecker::isLicensePlatinumOrTrial));
429+
RemoteClusterLicenseChecker::isAllowedByLicense));
430430
return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST);
431431
}
432432

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public enum OperationMode {
175175
BASIC((byte) 2),
176176
STANDARD((byte) 3),
177177
GOLD((byte) 4),
178-
PLATINUM((byte) 5);
178+
PLATINUM((byte) 5),
179+
ENTERPRISE((byte) 6);
179180

180181
private final byte id;
181182

@@ -208,8 +209,9 @@ public static OperationMode resolve(LicenseType type) {
208209
case GOLD:
209210
return GOLD;
210211
case PLATINUM:
211-
case ENTERPRISE: // TODO Add an explicit enterprise operating mode
212212
return PLATINUM;
213+
case ENTERPRISE:
214+
return ENTERPRISE;
213215
case TRIAL:
214216
return TRIAL;
215217
default:

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

+1
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ && isProductionMode(settings, clusterService.localNode())) {
256256
"] license unless TLS is configured or security is disabled");
257257
} else if (XPackSettings.FIPS_MODE_ENABLED.get(settings)
258258
&& newLicense.operationMode() != License.OperationMode.PLATINUM
259+
&& newLicense.operationMode() != License.OperationMode.ENTERPRISE
259260
&& newLicense.operationMode() != License.OperationMode.TRIAL) {
260261
throw new IllegalStateException("Cannot install a [" + newLicense.operationMode() +
261262
"] license unless FIPS mode is disabled");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ public RemoteClusterLicenseChecker(final Client client, final Predicate<License.
138138
this.predicate = predicate;
139139
}
140140

141-
public static boolean isLicensePlatinumOrTrial(final XPackInfoResponse.LicenseInfo licenseInfo) {
141+
public static boolean isAllowedByLicense(final XPackInfoResponse.LicenseInfo licenseInfo) {
142142
final License.OperationMode mode = License.OperationMode.parse(licenseInfo.getMode());
143-
return mode == License.OperationMode.PLATINUM || mode == License.OperationMode.TRIAL;
143+
return XPackLicenseState.isAllowedByOperationMode(mode, License.OperationMode.PLATINUM, true);
144144
}
145145

146146
/**

0 commit comments

Comments
 (0)