Skip to content

Commit

Permalink
Add enterprise mode and refactor license check (elastic#51864)
Browse files Browse the repository at this point in the history
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: elastic#51081
  • Loading branch information
ywangd committed Feb 9, 2020
1 parent 2b99291 commit 8bfd656
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private static ElasticsearchStatusException indexMetadataNonCompliantRemoteLicen
RemoteClusterLicenseChecker.buildErrorMessage(
"ccr",
licenseCheck.remoteClusterLicenseInfo(),
RemoteClusterLicenseChecker::isLicensePlatinumOrTrial));
RemoteClusterLicenseChecker::isAllowedByLicense));
return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST);
}

Expand All @@ -426,7 +426,7 @@ private static ElasticsearchStatusException clusterStateNonCompliantRemoteLicens
RemoteClusterLicenseChecker.buildErrorMessage(
"ccr",
licenseCheck.remoteClusterLicenseInfo(),
RemoteClusterLicenseChecker::isLicensePlatinumOrTrial));
RemoteClusterLicenseChecker::isAllowedByLicense));
return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public enum OperationMode {
BASIC((byte) 2),
STANDARD((byte) 3),
GOLD((byte) 4),
PLATINUM((byte) 5);
PLATINUM((byte) 5),
ENTERPRISE((byte) 6);

private final byte id;

Expand Down Expand Up @@ -214,8 +215,9 @@ public static OperationMode resolve(LicenseType type) {
case GOLD:
return GOLD;
case PLATINUM:
case ENTERPRISE: // TODO Add an explicit enterprise operating mode
return PLATINUM;
case ENTERPRISE:
return ENTERPRISE;
case TRIAL:
return TRIAL;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ && isProductionMode(settings, clusterService.localNode())) {
"] license unless TLS is configured or security is disabled");
} else if (XPackSettings.FIPS_MODE_ENABLED.get(settings)
&& newLicense.operationMode() != License.OperationMode.PLATINUM
&& newLicense.operationMode() != License.OperationMode.ENTERPRISE
&& newLicense.operationMode() != License.OperationMode.TRIAL) {
throw new IllegalStateException("Cannot install a [" + newLicense.operationMode() +
"] license unless FIPS mode is disabled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ public RemoteClusterLicenseChecker(final Client client, final Predicate<License.
this.predicate = predicate;
}

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

/**
Expand Down
Loading

0 comments on commit 8bfd656

Please sign in to comment.