-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert remote license checker to use LicensedFeature #79876
Changes from 5 commits
24dca59
6a50271
515ba66
da5da16
7545161
2acd57c
8912627
65c1db5
52f4659
f1264b4
6095dcc
c6b716f
47798b4
5bbf127
c72827d
076cec9
a7d25f4
9240b9d
4f5ff16
3c18ee2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,11 +27,12 @@ | |||||||||||||
import java.util.Locale; | ||||||||||||||
import java.util.Set; | ||||||||||||||
import java.util.concurrent.atomic.AtomicReference; | ||||||||||||||
import java.util.function.Predicate; | ||||||||||||||
import java.util.stream.Collectors; | ||||||||||||||
|
||||||||||||||
import static org.elasticsearch.license.XPackLicenseState.isAllowedByOperationMode; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Checks remote clusters for license compatibility with a specified license predicate. | ||||||||||||||
* Checks remote clusters for license compatibility with a specified licensed feature. | ||||||||||||||
*/ | ||||||||||||||
public final class RemoteClusterLicenseChecker { | ||||||||||||||
|
||||||||||||||
|
@@ -125,23 +126,18 @@ private LicenseCheck(final RemoteClusterLicenseInfo remoteClusterLicenseInfo) { | |||||||||||||
|
||||||||||||||
private static final ClusterNameExpressionResolver clusterNameExpressionResolver = new ClusterNameExpressionResolver(); | ||||||||||||||
private final Client client; | ||||||||||||||
private final Predicate<License.OperationMode> predicate; | ||||||||||||||
private final LicensedFeature feature; | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
* Constructs a remote cluster license checker with the specified license predicate for checking license compatibility. The predicate | ||||||||||||||
* does not need to check for the active license state as this is handled by the remote cluster license checker. | ||||||||||||||
* | ||||||||||||||
* @param client the client | ||||||||||||||
* @param predicate the license predicate | ||||||||||||||
* @param feature the licensed feature | ||||||||||||||
*/ | ||||||||||||||
public RemoteClusterLicenseChecker(final Client client, final Predicate<License.OperationMode> predicate) { | ||||||||||||||
public RemoteClusterLicenseChecker(final Client client, final LicensedFeature feature) { | ||||||||||||||
ywangd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
this.client = client; | ||||||||||||||
this.predicate = predicate; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
public static boolean isAllowedByLicense(final XPackInfoResponse.LicenseInfo licenseInfo) { | ||||||||||||||
final License.OperationMode mode = License.OperationMode.parse(licenseInfo.getMode()); | ||||||||||||||
return XPackLicenseState.isAllowedByOperationMode(mode, License.OperationMode.PLATINUM); | ||||||||||||||
this.feature = feature; | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/** | ||||||||||||||
|
@@ -169,8 +165,10 @@ public void onResponse(final XPackInfoResponse xPackInfoResponse) { | |||||||||||||
listener.onFailure(new ResourceNotFoundException("license info is missing for cluster [" + clusterAlias.get() + "]")); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
if ((licenseInfo.getStatus() == LicenseStatus.ACTIVE) == false | ||||||||||||||
|| predicate.test(License.OperationMode.parse(licenseInfo.getMode())) == false) { | ||||||||||||||
|
||||||||||||||
if (licenseInfo.getStatus() == LicenseStatus.ACTIVE == false | ||||||||||||||
|| isAllowedByOperationMode(License.OperationMode.parse(licenseInfo.getMode()), | ||||||||||||||
feature.getMinimumOperationMode()) == false) { | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a real issue but I feel a bit itchy that we don't check whether the feature actual needs an Active license here. It does and requiring active license is a norm going forward. But for the sake of clarity in this particular scope, I'd have something like
Suggested change
|
||||||||||||||
listener.onResponse(LicenseCheck.failure(new RemoteClusterLicenseInfo(clusterAlias.get(), licenseInfo))); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
|
@@ -273,20 +271,20 @@ public static List<String> remoteClusterAliases(final Set<String> remoteClusters | |||||||||||||
* @return an error message representing license incompatibility | ||||||||||||||
*/ | ||||||||||||||
public static String buildErrorMessage( | ||||||||||||||
final String feature, | ||||||||||||||
final RemoteClusterLicenseInfo remoteClusterLicenseInfo, | ||||||||||||||
final Predicate<XPackInfoResponse.LicenseInfo> predicate) { | ||||||||||||||
final LicensedFeature feature, | ||||||||||||||
final RemoteClusterLicenseInfo remoteClusterLicenseInfo) { | ||||||||||||||
final StringBuilder error = new StringBuilder(); | ||||||||||||||
if (remoteClusterLicenseInfo.licenseInfo().getStatus() != LicenseStatus.ACTIVE) { | ||||||||||||||
error.append(String.format(Locale.ROOT, "the license on cluster [%s] is not active", remoteClusterLicenseInfo.clusterAlias())); | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, this assumes the feature requires an active license, which is true. But the assumption is somewhat disconnected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've adjusted this so that if the feature is present, it checks the isNeedsActive(). It also checks if the feature is not present, to match the current behavior where an active license is still needed for the BASIC functionality. |
||||||||||||||
} else { | ||||||||||||||
assert predicate.test(remoteClusterLicenseInfo.licenseInfo()) == false : "license must be incompatible to build error message"; | ||||||||||||||
assert isAllowedByOperationMode(License.OperationMode.parse(remoteClusterLicenseInfo.licenseInfo().getMode()), | ||||||||||||||
feature.getMinimumOperationMode()) == false : "license must be incompatible to build error message"; | ||||||||||||||
final String message = String.format( | ||||||||||||||
Locale.ROOT, | ||||||||||||||
"the license mode [%s] on cluster [%s] does not enable [%s]", | ||||||||||||||
License.OperationMode.parse(remoteClusterLicenseInfo.licenseInfo().getMode()), | ||||||||||||||
remoteClusterLicenseInfo.clusterAlias(), | ||||||||||||||
feature); | ||||||||||||||
feature.getName()); | ||||||||||||||
error.append(message); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.