-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add license checks for autoscaling (#66235)
This commit enables license checks for autoscaling. Autoscaling will be licensed under at the Enterprise license tier. All REST actions except for deleting autoscaling policies when a license is out of compliance.
- Loading branch information
1 parent
41ad305
commit b8c55d6
Showing
12 changed files
with
274 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...rnalClusterTest/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseCheckerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.autoscaling; | ||
|
||
import org.elasticsearch.ElasticsearchSecurityException; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
import org.elasticsearch.xpack.autoscaling.action.DeleteAutoscalingPolicyAction; | ||
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingCapacityAction; | ||
import org.elasticsearch.xpack.autoscaling.action.GetAutoscalingPolicyAction; | ||
import org.elasticsearch.xpack.autoscaling.action.PutAutoscalingPolicyAction; | ||
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
|
||
public class AutoscalingLicenseCheckerIT extends ESSingleNodeTestCase { | ||
|
||
public static class NonCompliantLicenseLocalStateAutoscaling extends LocalStateCompositeXPackPlugin { | ||
|
||
public NonCompliantLicenseLocalStateAutoscaling(final Settings settings, final Path configPath) { | ||
super(settings, configPath); | ||
plugins.add(new Autoscaling(new AutoscalingLicenseChecker(() -> false))); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> getPlugins() { | ||
return Collections.singletonList(NonCompliantLicenseLocalStateAutoscaling.class); | ||
} | ||
|
||
public void testCanNotPutPolicyWithNonCompliantLicense() throws InterruptedException { | ||
final PutAutoscalingPolicyAction.Request request = new PutAutoscalingPolicyAction.Request( | ||
"", | ||
Collections.emptySortedSet(), | ||
Collections.emptySortedMap() | ||
); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
client().execute(PutAutoscalingPolicyAction.INSTANCE, request, new ActionListener<AcknowledgedResponse>() { | ||
|
||
@Override | ||
public void onResponse(final AcknowledgedResponse response) { | ||
try { | ||
fail(); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(final Exception e) { | ||
try { | ||
assertNonCompliantLicense(e); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
}); | ||
latch.await(); | ||
} | ||
|
||
public void testCanNotGetPolicyWithNonCompliantLicense() throws InterruptedException { | ||
final GetAutoscalingPolicyAction.Request request = new GetAutoscalingPolicyAction.Request(""); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
client().execute(GetAutoscalingPolicyAction.INSTANCE, request, new ActionListener<GetAutoscalingPolicyAction.Response>() { | ||
|
||
@Override | ||
public void onResponse(final GetAutoscalingPolicyAction.Response response) { | ||
try { | ||
fail(); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(final Exception e) { | ||
try { | ||
assertNonCompliantLicense(e); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
}); | ||
latch.await(); | ||
} | ||
|
||
public void testCanNonGetAutoscalingCapacityDecisionWithNonCompliantLicense() throws InterruptedException { | ||
final GetAutoscalingCapacityAction.Request request = new GetAutoscalingCapacityAction.Request(); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
client().execute(GetAutoscalingCapacityAction.INSTANCE, request, new ActionListener<GetAutoscalingCapacityAction.Response>() { | ||
|
||
@Override | ||
public void onResponse(final GetAutoscalingCapacityAction.Response response) { | ||
try { | ||
fail(); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(final Exception e) { | ||
try { | ||
assertNonCompliantLicense(e); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
}); | ||
latch.await(); | ||
} | ||
|
||
public void testCanDeleteAutoscalingPolicyEvenWithNonCompliantLicense() throws InterruptedException { | ||
final DeleteAutoscalingPolicyAction.Request request = new DeleteAutoscalingPolicyAction.Request("*"); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
client().execute(DeleteAutoscalingPolicyAction.INSTANCE, request, new ActionListener<AcknowledgedResponse>() { | ||
|
||
@Override | ||
public void onResponse(final AcknowledgedResponse response) { | ||
latch.countDown(); | ||
} | ||
|
||
@Override | ||
public void onFailure(final Exception e) { | ||
try { | ||
fail(); | ||
} finally { | ||
latch.countDown(); | ||
} | ||
} | ||
|
||
}); | ||
latch.await(); | ||
} | ||
|
||
private void assertNonCompliantLicense(final Exception e) { | ||
assertThat(e, instanceOf(ElasticsearchSecurityException.class)); | ||
assertThat(e.getMessage(), equalTo("current license is non-compliant for [autoscaling]")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...oscaling/src/main/java/org/elasticsearch/xpack/autoscaling/AutoscalingLicenseChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.autoscaling; | ||
|
||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.xpack.core.XPackPlugin; | ||
|
||
import java.util.Objects; | ||
import java.util.function.BooleanSupplier; | ||
|
||
/** | ||
* Encapsulates license checking for autoscaling. | ||
*/ | ||
public class AutoscalingLicenseChecker { | ||
|
||
private final BooleanSupplier isAutoscalingAllowed; | ||
|
||
/** | ||
* Constructs an autoscaling license checker with the default rule based on the license state for checking if autoscaling is allowed. | ||
*/ | ||
AutoscalingLicenseChecker() { | ||
this(() -> XPackPlugin.getSharedLicenseState().checkFeature(XPackLicenseState.Feature.AUTOSCALING)); | ||
} | ||
|
||
/** | ||
* Constructs an autoscaling license checker with the specified boolean supplier. | ||
* | ||
* @param isAutoscalingAllowed a boolean supplier that should return true is autoscaling is allowed and otherwise false. | ||
*/ | ||
public AutoscalingLicenseChecker(final BooleanSupplier isAutoscalingAllowed) { | ||
this.isAutoscalingAllowed = Objects.requireNonNull(isAutoscalingAllowed); | ||
} | ||
|
||
/** | ||
* Returns whether or not autoscaling is allowed. | ||
* | ||
* @return true if autoscaling is allowed, otherwise false | ||
*/ | ||
public boolean isAutoscalingAllowed() { | ||
return isAutoscalingAllowed.getAsBoolean(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.