Skip to content

Commit 4bc7545

Browse files
authored
Add enterprise mode and refactor license check (#51864) (#52115)
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 2a5c181 commit 4bc7545

File tree

22 files changed

+219
-230
lines changed

22 files changed

+219
-230
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
@@ -181,7 +181,8 @@ public enum OperationMode {
181181
BASIC((byte) 2),
182182
STANDARD((byte) 3),
183183
GOLD((byte) 4),
184-
PLATINUM((byte) 5);
184+
PLATINUM((byte) 5),
185+
ENTERPRISE((byte) 6);
185186

186187
private final byte id;
187188

@@ -214,8 +215,9 @@ public static OperationMode resolve(LicenseType type) {
214215
case GOLD:
215216
return GOLD;
216217
case PLATINUM:
217-
case ENTERPRISE: // TODO Add an explicit enterprise operating mode
218218
return PLATINUM;
219+
case ENTERPRISE:
220+
return ENTERPRISE;
219221
case TRIAL:
220222
return TRIAL;
221223
default:

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

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ && isProductionMode(settings, clusterService.localNode())) {
257257
"] license unless TLS is configured or security is disabled");
258258
} else if (XPackSettings.FIPS_MODE_ENABLED.get(settings)
259259
&& newLicense.operationMode() != License.OperationMode.PLATINUM
260+
&& newLicense.operationMode() != License.OperationMode.ENTERPRISE
260261
&& newLicense.operationMode() != License.OperationMode.TRIAL) {
261262
throw new IllegalStateException("Cannot install a [" + newLicense.operationMode() +
262263
"] 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)