From 354fa28bd090fb72322277084ae957adb1cc8281 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 27 Oct 2021 18:32:48 -0700 Subject: [PATCH] Convert remote license checker to use LicensedFeature (#79876) The RemoteClusterLicenseChecker pulls the license level of a remote cluster and checks it allows a local feature to communicate with that cluster. It does the check with a lambda, but these methods could be out of sync with the actual licensed feature. This commit converts the remote license checker to take in the feature object that should be checked. --- .../xpack/ccr/CcrLicenseChecker.java | 15 ++---- .../license/RemoteClusterLicenseChecker.java | 50 ++++++++++--------- .../license/XPackLicenseState.java | 10 +--- .../RemoteClusterLicenseCheckerTests.java | 50 +++++++------------ .../validation/SourceDestValidatorTests.java | 40 ++++----------- .../action/TransportStartDatafeedAction.java | 8 +-- .../TransportPreviewTransformAction.java | 2 +- .../TransportValidateTransformAction.java | 2 +- 8 files changed, 65 insertions(+), 112 deletions(-) diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java index 581b2267ccd41..623d9c50bb903 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/CcrLicenseChecker.java @@ -38,7 +38,6 @@ import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.indices.IndexClosedException; import org.elasticsearch.license.RemoteClusterLicenseChecker; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.ccr.action.ShardChangesAction; import org.elasticsearch.xpack.core.ClientHelper; @@ -244,7 +243,7 @@ private void checkRemoteClusterLicenseAndFetchClusterState( final Function unknownLicense ) { // we have to check the license on the remote cluster - new RemoteClusterLicenseChecker(client, XPackLicenseState::isCcrAllowedForOperationMode).checkRemoteClusterLicenses( + new RemoteClusterLicenseChecker(client, CcrConstants.CCR_FEATURE).checkRemoteClusterLicenses( Collections.singletonList(clusterAlias), new ActionListener() { @@ -452,11 +451,7 @@ private static ElasticsearchStatusException indexMetadataNonCompliantRemoteLicen clusterAlias, leaderIndex, clusterAlias, - RemoteClusterLicenseChecker.buildErrorMessage( - "ccr", - licenseCheck.remoteClusterLicenseInfo(), - RemoteClusterLicenseChecker::isAllowedByLicense - ) + RemoteClusterLicenseChecker.buildErrorMessage(CcrConstants.CCR_FEATURE, licenseCheck.remoteClusterLicenseInfo()) ); return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST); } @@ -469,11 +464,7 @@ private static ElasticsearchStatusException clusterStateNonCompliantRemoteLicens Locale.ROOT, "can not fetch remote cluster state as the remote cluster [%s] is not licensed for [ccr]; %s", clusterAlias, - RemoteClusterLicenseChecker.buildErrorMessage( - "ccr", - licenseCheck.remoteClusterLicenseInfo(), - RemoteClusterLicenseChecker::isAllowedByLicense - ) + RemoteClusterLicenseChecker.buildErrorMessage(CcrConstants.CCR_FEATURE, licenseCheck.remoteClusterLicenseInfo()) ); return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RemoteClusterLicenseChecker.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RemoteClusterLicenseChecker.java index 420902cce4ab7..9df955d3c19ad 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RemoteClusterLicenseChecker.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RemoteClusterLicenseChecker.java @@ -14,6 +14,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.ClusterNameExpressionResolver; import org.elasticsearch.common.util.concurrent.ThreadContext; +import org.elasticsearch.core.Nullable; import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.protocol.xpack.XPackInfoResponse; import org.elasticsearch.protocol.xpack.license.LicenseStatus; @@ -27,11 +28,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 +127,19 @@ private LicenseCheck(final RemoteClusterLicenseInfo remoteClusterLicenseInfo) { private static final ClusterNameExpressionResolver clusterNameExpressionResolver = new ClusterNameExpressionResolver(); private final Client client; - private final Predicate 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. + * Constructs a remote cluster license checker with the specified licensed feature for checking license compatibility. The feature + * does not need to check for the active license state as this is handled by the remote cluster license checker. If the feature + * is {@code null} a check is only performed on whether the license is active. * * @param client the client - * @param predicate the license predicate + * @param feature the licensed feature */ - public RemoteClusterLicenseChecker(final Client client, final Predicate predicate) { + public RemoteClusterLicenseChecker(final Client client, @Nullable final LicensedFeature feature) { 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 +167,8 @@ 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 (isActive(feature, licenseInfo) == false || isAllowed(feature, licenseInfo) == false) { listener.onResponse(LicenseCheck.failure(new RemoteClusterLicenseInfo(clusterAlias.get(), licenseInfo))); return; } @@ -197,6 +195,15 @@ public void onFailure(final Exception e) { remoteClusterLicense(clusterAlias.get(), infoListener); } + private static boolean isActive(LicensedFeature feature, XPackInfoResponse.LicenseInfo licenseInfo) { + return feature != null && feature.isNeedsActive() == false || licenseInfo.getStatus() == LicenseStatus.ACTIVE; + } + + private static boolean isAllowed(LicensedFeature feature, XPackInfoResponse.LicenseInfo licenseInfo) { + License.OperationMode mode = License.OperationMode.parse(licenseInfo.getMode()); + return feature == null || isAllowedByOperationMode(mode, feature.getMinimumOperationMode()); + } + private void remoteClusterLicense(final String clusterAlias, final ActionListener listener) { final ThreadContext threadContext = client.threadPool().getThreadContext(); final ContextPreservingActionListener contextPreservingActionListener = new ContextPreservingActionListener<>( @@ -274,22 +281,19 @@ public static List remoteClusterAliases(final Set remoteClusters * @param remoteClusterLicenseInfo the remote cluster license info of the cluster that failed the license check * @return an error message representing license incompatibility */ - public static String buildErrorMessage( - final String feature, - final RemoteClusterLicenseInfo remoteClusterLicenseInfo, - final Predicate predicate - ) { + public static String buildErrorMessage(final LicensedFeature feature, final RemoteClusterLicenseInfo remoteClusterLicenseInfo) { final StringBuilder error = new StringBuilder(); - if (remoteClusterLicenseInfo.licenseInfo().getStatus() != LicenseStatus.ACTIVE) { + if (isActive(feature, remoteClusterLicenseInfo.licenseInfo()) == false) { error.append(String.format(Locale.ROOT, "the license on cluster [%s] is not active", remoteClusterLicenseInfo.clusterAlias())); } else { - assert predicate.test(remoteClusterLicenseInfo.licenseInfo()) == false : "license must be incompatible to build error message"; + assert isAllowed(feature, remoteClusterLicenseInfo.licenseInfo()) == 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); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java index aa54b2b6a80ff..aea1fa35e6a6d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java @@ -458,10 +458,6 @@ public Map getLastUsed() { return usage.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> timeConverter.apply(e.getValue()))); } - public static boolean isMachineLearningAllowedForOperationMode(final OperationMode operationMode) { - return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); - } - public static boolean isFipsAllowedForOperationMode(final OperationMode operationMode) { return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); } @@ -508,11 +504,7 @@ private static boolean isSecurityEnabled( } } - public static boolean isCcrAllowedForOperationMode(final OperationMode operationMode) { - return isAllowedByOperationMode(operationMode, OperationMode.PLATINUM); - } - - public static boolean isAllowedByOperationMode(final OperationMode operationMode, final OperationMode minimumMode) { + static boolean isAllowedByOperationMode(final OperationMode operationMode, final OperationMode minimumMode) { if (OperationMode.TRIAL == operationMode) { return true; } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/RemoteClusterLicenseCheckerTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/RemoteClusterLicenseCheckerTests.java index 987d3137509d6..796c4c2681b72 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/license/RemoteClusterLicenseCheckerTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/license/RemoteClusterLicenseCheckerTests.java @@ -157,10 +157,8 @@ public void testCheckRemoteClusterLicensesGivenCompatibleLicenses() { responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final AtomicReference licenseCheck = new AtomicReference<>(); licenseChecker.checkRemoteClusterLicenses( @@ -202,10 +200,8 @@ public void testCheckRemoteClusterLicensesGivenIncompatibleLicense() { return null; }).when(client).execute(same(XPackInfoAction.INSTANCE), any(), any()); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final AtomicReference licenseCheck = new AtomicReference<>(); licenseChecker.checkRemoteClusterLicenses( @@ -251,10 +247,8 @@ public void testCheckRemoteClusterLicencesGivenNonExistentCluster() { responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final AtomicReference exception = new AtomicReference<>(); licenseChecker.checkRemoteClusterLicenses( @@ -294,10 +288,8 @@ public void testRemoteClusterLicenseCallUsesSystemContext() throws InterruptedEx return null; }).when(client).execute(same(XPackInfoAction.INSTANCE), any(), any()); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final List remoteClusterAliases = Collections.singletonList("valid"); licenseChecker.checkRemoteClusterLicenses( @@ -337,10 +329,8 @@ public void testListenerIsExecutedWithCallingContext() throws InterruptedExcepti responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); responses.add(new XPackInfoResponse(null, createPlatinumLicenseResponse(), null)); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final AtomicBoolean listenerInvoked = new AtomicBoolean(); threadPool.getThreadContext().putHeader("key", "value"); @@ -383,10 +373,8 @@ public void testBuildErrorMessageForActiveCompatibleLicense() { "platinum-cluster", platinumLicence ); - final AssertionError e = expectThrows( - AssertionError.class, - () -> RemoteClusterLicenseChecker.buildErrorMessage("", info, RemoteClusterLicenseChecker::isAllowedByLicense) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "foo", License.OperationMode.PLATINUM); + final AssertionError e = expectThrows(AssertionError.class, () -> RemoteClusterLicenseChecker.buildErrorMessage(feature, info)); assertThat(e, hasToString(containsString("license must be incompatible to build error message"))); } @@ -396,9 +384,10 @@ public void testBuildErrorMessageForIncompatibleLicense() { "basic-cluster", basicLicense ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); assertThat( - RemoteClusterLicenseChecker.buildErrorMessage("Feature", info, RemoteClusterLicenseChecker::isAllowedByLicense), - equalTo("the license mode [BASIC] on cluster [basic-cluster] does not enable [Feature]") + RemoteClusterLicenseChecker.buildErrorMessage(feature, info), + equalTo("the license mode [BASIC] on cluster [basic-cluster] does not enable [feature]") ); } @@ -408,8 +397,9 @@ public void testBuildErrorMessageForInactiveLicense() { "expired-cluster", expiredLicense ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "foo", License.OperationMode.PLATINUM); assertThat( - RemoteClusterLicenseChecker.buildErrorMessage("Feature", info, RemoteClusterLicenseChecker::isAllowedByLicense), + RemoteClusterLicenseChecker.buildErrorMessage(feature, info), equalTo("the license on cluster [expired-cluster] is not active") ); } @@ -424,10 +414,8 @@ public void testCheckRemoteClusterLicencesNoLicenseMetadata() { return null; }).when(client).execute(same(XPackInfoAction.INSTANCE), any(), any()); - final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker( - client, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.PLATINUM); + final RemoteClusterLicenseChecker licenseChecker = new RemoteClusterLicenseChecker(client, feature); final AtomicReference exception = new AtomicReference<>(); licenseChecker.checkRemoteClusterLicenses( diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java index 4f4a29ad7cb80..78ffe9ffcd37e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/validation/SourceDestValidatorTests.java @@ -30,8 +30,8 @@ import org.elasticsearch.ingest.Processor; import org.elasticsearch.ingest.TestProcessor; import org.elasticsearch.license.License; +import org.elasticsearch.license.LicensedFeature; import org.elasticsearch.license.RemoteClusterLicenseChecker; -import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.protocol.xpack.XPackInfoResponse; import org.elasticsearch.protocol.xpack.XPackInfoResponse.LicenseInfo; @@ -100,6 +100,7 @@ public class SourceDestValidatorTests extends ESTestCase { private Client clientWithPlatinumLicense; private Client clientWithTrialLicense; private RemoteClusterLicenseChecker remoteClusterLicenseCheckerBasic; + private LicensedFeature platinumFeature; private final ThreadPool threadPool = new TestThreadPool(getClass().getName()); private final TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool); @@ -201,10 +202,9 @@ protected void public void setupComponents() { clientWithBasicLicense = new MockClientLicenseCheck(getTestName(), "basic", LicenseStatus.ACTIVE); clientWithExpiredBasicLicense = new MockClientLicenseCheck(getTestName(), "basic", LicenseStatus.EXPIRED); - remoteClusterLicenseCheckerBasic = new RemoteClusterLicenseChecker( - clientWithBasicLicense, - (operationMode -> operationMode != License.OperationMode.MISSING) - ); + LicensedFeature.Momentary feature = LicensedFeature.momentary(null, "feature", License.OperationMode.BASIC); + platinumFeature = LicensedFeature.momentary(null, "platinum-feature", License.OperationMode.PLATINUM); + remoteClusterLicenseCheckerBasic = new RemoteClusterLicenseChecker(clientWithBasicLicense, feature); clientWithPlatinumLicense = new MockClientLicenseCheck(getTestName(), "platinum", LicenseStatus.ACTIVE); clientWithTrialLicense = new MockClientLicenseCheck(getTestName(), "trial", LicenseStatus.ACTIVE); } @@ -680,10 +680,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithBasicLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithBasicLicense, platinumFeature), ingestService, new String[] { REMOTE_BASIC + ":" + "SOURCE_1" }, "dest", @@ -714,10 +711,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithPlatinumLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithPlatinumLicense, platinumFeature), ingestService, new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" }, "dest", @@ -739,10 +733,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithPlatinumLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithPlatinumLicense, platinumFeature), ingestService, new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" }, "dest", @@ -765,10 +756,7 @@ public void testRemoteSourcePlatinum() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithTrialLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithTrialLicense, platinumFeature), ingestService, new String[] { REMOTE_PLATINUM + ":" + "SOURCE_1" }, "dest", @@ -793,10 +781,7 @@ public void testRemoteSourceLicenseInActive() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithExpiredBasicLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense, platinumFeature), ingestService, new String[] { REMOTE_BASIC + ":" + "SOURCE_1" }, "dest", @@ -824,10 +809,7 @@ public void testRemoteSourceDoesNotExist() throws InterruptedException { CLUSTER_STATE, indexNameExpressionResolver, remoteClusterService, - new RemoteClusterLicenseChecker( - clientWithExpiredBasicLicense, - operationMode -> XPackLicenseState.isAllowedByOperationMode(operationMode, License.OperationMode.PLATINUM) - ), + new RemoteClusterLicenseChecker(clientWithExpiredBasicLicense, platinumFeature), ingestService, new String[] { "non_existing_remote:" + "SOURCE_1" }, "dest", diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java index bac2fe905b95c..77a089f84e0dc 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportStartDatafeedAction.java @@ -225,7 +225,7 @@ public void onFailure(Exception e) { if (remoteIndices.isEmpty() == false) { final RemoteClusterLicenseChecker remoteClusterLicenseChecker = new RemoteClusterLicenseChecker( client, - XPackLicenseState::isMachineLearningAllowedForOperationMode + MachineLearningField.ML_API_FEATURE ); remoteClusterLicenseChecker.checkRemoteClusterLicenses( RemoteClusterLicenseChecker.remoteClusterAliases( @@ -459,11 +459,7 @@ private ElasticsearchStatusException createUnlicensedError( "cannot start datafeed [%s] as it is configured to use indices on remote cluster [%s] that is not licensed for ml; %s", datafeedId, licenseCheck.remoteClusterLicenseInfo().clusterAlias(), - RemoteClusterLicenseChecker.buildErrorMessage( - "ml", - licenseCheck.remoteClusterLicenseInfo(), - RemoteClusterLicenseChecker::isAllowedByLicense - ) + RemoteClusterLicenseChecker.buildErrorMessage(MachineLearningField.ML_API_FEATURE, licenseCheck.remoteClusterLicenseInfo()) ); return new ElasticsearchStatusException(message, RestStatus.BAD_REQUEST); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java index 75b28dc3d66a2..a10e9b9735030 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportPreviewTransformAction.java @@ -134,7 +134,7 @@ protected TransportPreviewTransformAction( transportService.getRemoteClusterService(), DiscoveryNode.isRemoteClusterClient(settings) /* transforms are BASIC so always allowed, no need to check license */ - ? new RemoteClusterLicenseChecker(client, mode -> true) + ? new RemoteClusterLicenseChecker(client, null) : null, ingestService, clusterService.getNodeName(), diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportValidateTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportValidateTransformAction.java index c9eb633b8432c..4b4b062f4362c 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportValidateTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportValidateTransformAction.java @@ -85,7 +85,7 @@ protected TransportValidateTransformAction( transportService.getRemoteClusterService(), DiscoveryNode.isRemoteClusterClient(settings) /* transforms are BASIC so always allowed, no need to check license */ - ? new RemoteClusterLicenseChecker(client, mode -> true) + ? new RemoteClusterLicenseChecker(client, null) : null, ingestService, clusterService.getNodeName(),