diff --git a/src/main/java/org/elasticsearch/license/core/ESLicense.java b/src/main/java/org/elasticsearch/license/core/ESLicense.java index bc969deb441..8db4439e5b1 100644 --- a/src/main/java/org/elasticsearch/license/core/ESLicense.java +++ b/src/main/java/org/elasticsearch/license/core/ESLicense.java @@ -29,7 +29,7 @@ public class ESLicense implements Comparable, ToXContent { private final int maxNodes; private ESLicense(String uid, String issuer, String issuedTo, long issueDate, String type, - String subscriptionType, String feature, String signature, long expiryDate, int maxNodes) { + String subscriptionType, String feature, String signature, long expiryDate, int maxNodes) { this.uid = uid; this.issuer = issuer; this.issuedTo = issuedTo; @@ -379,25 +379,25 @@ public class ESLicense implements Comparable, ToXContent { public Builder verify() { if (issuer == null) { - throw new IllegalStateException("issuer can not be null"); + throw new IllegalStateException("issuer can not be null"); } else if (issuedTo == null) { - throw new IllegalStateException("issuedTo can not be null"); + throw new IllegalStateException("issuedTo can not be null"); } else if (issueDate == -1) { - throw new IllegalStateException("issueDate has to be set"); + throw new IllegalStateException("issueDate has to be set"); } else if (type == null) { - throw new IllegalStateException("type can not be null"); + throw new IllegalStateException("type can not be null"); } else if (subscriptionType == null) { - throw new IllegalStateException("subscriptionType can not be null"); + throw new IllegalStateException("subscriptionType can not be null"); } else if (uid == null) { - throw new IllegalStateException("uid can not be null"); + throw new IllegalStateException("uid can not be null"); } else if (feature == null) { - throw new IllegalStateException("at least one feature has to be enabled"); + throw new IllegalStateException("at least one feature has to be enabled"); } else if (signature == null) { - throw new IllegalStateException("signature can not be null"); + throw new IllegalStateException("signature can not be null"); } else if (maxNodes == -1) { - throw new IllegalStateException("maxNodes has to be set"); + throw new IllegalStateException("maxNodes has to be set"); } else if (expiryDate == -1) { - throw new IllegalStateException("expiryDate has to be set"); + throw new IllegalStateException("expiryDate has to be set"); } return this; } diff --git a/src/main/java/org/elasticsearch/license/core/ESLicenses.java b/src/main/java/org/elasticsearch/license/core/ESLicenses.java index 070e81bba42..b0e63b31892 100644 --- a/src/main/java/org/elasticsearch/license/core/ESLicenses.java +++ b/src/main/java/org/elasticsearch/license/core/ESLicenses.java @@ -12,6 +12,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.*; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.*; public class ESLicenses { @@ -37,7 +38,7 @@ public class ESLicenses { } public static List fromSource(String content) throws IOException { - return fromSource(content.getBytes(LicensesCharset.UTF_8), true); + return fromSource(content.getBytes(StandardCharsets.UTF_8), true); } public static List fromSource(byte[] bytes) throws IOException { diff --git a/src/main/java/org/elasticsearch/license/core/LicensesCharset.java b/src/main/java/org/elasticsearch/license/core/LicensesCharset.java deleted file mode 100644 index 04efbb18a87..00000000000 --- a/src/main/java/org/elasticsearch/license/core/LicensesCharset.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.license.core; - -import java.nio.charset.Charset; - -public class LicensesCharset { - - /** - * All operations in should use the universal UTF-8 character set. - */ - public static final Charset UTF_8 = Charset.forName("UTF-8"); - -} diff --git a/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java b/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java index 43e6ea5891a..1af7d600d3b 100644 --- a/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java +++ b/src/main/java/org/elasticsearch/license/core/ResourcePublicKeyDataProvider.java @@ -24,7 +24,7 @@ public class ResourcePublicKeyDataProvider implements PublicKeyDataProvider { @Override public byte[] getEncryptedPublicKeyData() throws KeyNotFoundException { - try(InputStream inputStream = this.getClass().getResourceAsStream(resource)) { + try (InputStream inputStream = this.getClass().getResourceAsStream(resource)) { return Streams.copyToByteArray(inputStream); } catch (IOException ex) { throw new KeyNotFoundException(ex); diff --git a/src/main/java/org/elasticsearch/license/licensor/ESLicenseSigner.java b/src/main/java/org/elasticsearch/license/licensor/ESLicenseSigner.java index a536d1c1e66..a3f4a2a058d 100644 --- a/src/main/java/org/elasticsearch/license/licensor/ESLicenseSigner.java +++ b/src/main/java/org/elasticsearch/license/licensor/ESLicenseSigner.java @@ -18,10 +18,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.license.core.ESLicense; -import org.elasticsearch.license.core.LicensesCharset; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -110,7 +110,7 @@ public class ESLicenseSigner { final byte[] licenseSignature = licenseCreator.signAndSerializeLicense(license); final byte[] hash = Hasher.hash(Base64.encodeBase64String( Files.readAllBytes(publicKeyPath)) - ).getBytes(LicensesCharset.UTF_8); + ).getBytes(StandardCharsets.UTF_8); int headerLength = MAGIC_LENGTH + hash.length + 4 + 4; byte[] bytes = new byte[headerLength + licenseSignature.length]; diff --git a/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java b/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java index 751e4291b26..778c7bf7909 100644 --- a/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java +++ b/src/main/java/org/elasticsearch/license/licensor/tools/LicenseGeneratorTool.java @@ -12,12 +12,12 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.core.ESLicenses; -import org.elasticsearch.license.core.LicensesCharset; import org.elasticsearch.license.licensor.ESLicenseSigner; import java.io.File; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.text.ParseException; @@ -48,7 +48,7 @@ public class LicenseGeneratorTool { switch (command) { case "--license": String licenseInput = args[++i]; - licenseSpecs.addAll(ESLicenses.fromSource(licenseInput.getBytes(LicensesCharset.UTF_8), false)); + licenseSpecs.addAll(ESLicenses.fromSource(licenseInput.getBytes(StandardCharsets.UTF_8), false)); break; case "--licenseFile": File licenseFile = new File(args[++i]); diff --git a/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java b/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java index e78fb7fdcfc..d2c8bfb0039 100644 --- a/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java +++ b/src/main/java/org/elasticsearch/license/plugin/action/get/GetLicenseRequest.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license.plugin.action.get; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeReadOperationRequest; import org.elasticsearch.common.io.stream.StreamInput; diff --git a/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java b/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java index 378aa34cf01..6879763af8d 100644 --- a/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java +++ b/src/main/java/org/elasticsearch/license/plugin/action/get/TransportGetLicenseAction.java @@ -28,7 +28,7 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadOperationA @Inject public TransportGetLicenseAction(Settings settings, TransportService transportService, ClusterService clusterService, LicensesManagerService licensesManagerService, - ThreadPool threadPool, ActionFilters actionFilters) { + ThreadPool threadPool, ActionFilters actionFilters) { super(settings, GetLicenseAction.NAME, transportService, clusterService, threadPool, actionFilters); this.licensesManagerService = licensesManagerService; } diff --git a/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseRequest.java b/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseRequest.java index fe8b1da15f5..3da86e932af 100644 --- a/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseRequest.java +++ b/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseRequest.java @@ -31,6 +31,7 @@ public class PutLicenseRequest extends AcknowledgedRequest { /** * Parses licenses from json format to an instance of {@link org.elasticsearch.license.core.ESLicenses} + * * @param licenseDefinition licenses definition */ public PutLicenseRequest licenses(String licenseDefinition) { diff --git a/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java b/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java index 5424de9fe13..4cceeb4b790 100644 --- a/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java +++ b/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java @@ -11,15 +11,11 @@ import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.license.plugin.core.ElasticsearchLicenseException; import org.elasticsearch.license.plugin.core.LicensesManagerService; -import org.elasticsearch.license.plugin.core.LicensesService; -import org.elasticsearch.license.plugin.core.LicensesStatus; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesClientService.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesClientService.java index 54f12b1d313..6f7c11c2079 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesClientService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesClientService.java @@ -27,10 +27,11 @@ public interface LicensesClientService { /** * Registers a feature for licensing - * @param feature - name of the feature to register (must be in sync with license Generator feature name) + * + * @param feature - name of the feature to register (must be in sync with license Generator feature name) * @param trialLicenseOptions - Trial license specification used to generate a one-time trial license for the feature; * use null if no trial license should be generated for the feature - * @param listener - used to notify on feature enable/disable and specify trial license specification + * @param listener - used to notify on feature enable/disable and specify trial license specification */ void register(String feature, TrialLicenseOptions trialLicenseOptions, Listener listener); } diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java index 8fa1c120be0..b4ea567cbdd 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java @@ -13,9 +13,7 @@ import org.elasticsearch.license.core.ESLicense; import java.util.List; import java.util.Set; -import static org.elasticsearch.license.plugin.core.LicensesService.DeleteLicenseRequestHolder; -import static org.elasticsearch.license.plugin.core.LicensesService.LicensesUpdateResponse; -import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRequestHolder; +import static org.elasticsearch.license.plugin.core.LicensesService.*; @ImplementedBy(LicensesService.class) public interface LicensesManagerService { diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java index 2f8dd110db9..511cc9471bd 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesMetaData.java @@ -20,7 +20,6 @@ import java.util.Set; /** * Contains metadata about registered licenses - * */ public class LicensesMetaData implements MetaData.Custom { @@ -39,7 +38,7 @@ public class LicensesMetaData implements MetaData.Custom { /** * Constructs new licenses metadata * - * @param signatures set of esLicense signatures + * @param signatures set of esLicense signatures * @param encodedTrialLicenses set of encoded trial licenses */ public LicensesMetaData(Set signatures, Set encodedTrialLicenses) { @@ -177,7 +176,7 @@ public class LicensesMetaData implements MetaData.Custom { @Override public void toXContent(LicensesMetaData licensesMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.array(Fields.LICENSES, licensesMetaData.signatures.toArray(new String[licensesMetaData.signatures.size()])); - builder.array(Fields.TRIAL_LICENSES, licensesMetaData.encodedTrialLicenses.toArray(new String [licensesMetaData.encodedTrialLicenses.size()])); + builder.array(Fields.TRIAL_LICENSES, licensesMetaData.encodedTrialLicenses.toArray(new String[licensesMetaData.encodedTrialLicenses.size()])); } @Override diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java index e1c462e2643..815d46b7512 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -50,7 +50,7 @@ import static org.elasticsearch.license.core.ESLicenses.reduceAndMap; * Interfaces through which this is exposed are: * - LicensesManagerService - responsible for managing signed and one-time-trial licenses * - LicensesClientService - responsible for feature registration and notification to consumer plugin(s) - * + *

*

* Registration Scheme: *

@@ -59,7 +59,7 @@ import static org.elasticsearch.license.core.ESLicenses.reduceAndMap; * If the feature can not be registered immediately, it is queued up and registered on the first clusterChanged event with * no {@link GatewayService#STATE_NOT_RECOVERED_BLOCK} block * Upon successful registration, the feature(s) are notified appropriately using the notification scheme - * + *

*

* Notification Scheme: *

@@ -431,11 +431,10 @@ public class LicensesService extends AbstractLifecycleComponent /** * Calls {@link #notifyFeaturesAndScheduleNotification(LicensesMetaData)} with currentLicensesMetaData * if it was not already notified on. - * + *

* Upon completion sets currentLicensesMetaData to {@link #lastObservedLicensesState} * to ensure the same license(s) are not notified on from * {@link #clusterChanged(ClusterChangedEvent)} - * */ private void notifyFeaturesAndScheduleNotificationIfNeeded(final LicensesMetaData currentLicensesMetaData) { final LicensesMetaData lastNotifiedLicensesMetaData = lastObservedLicensesState.get(); @@ -461,6 +460,7 @@ public class LicensesService extends AbstractLifecycleComponent /** * Checks license expiry for all the registered feature(s) + * * @return -1 if there are no expiring license(s) for any registered feature(s), else * returns the minimum of the expiry times of all the registered feature(s) to * schedule an expiry notification diff --git a/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java b/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java index 9533fd76bde..a982ea015d9 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesStatus.java @@ -13,6 +13,7 @@ public enum LicensesStatus { EXPIRED((byte) 2); private byte id; + LicensesStatus(byte id) { this.id = id; } diff --git a/src/main/java/org/elasticsearch/license/plugin/core/TrialLicenseUtils.java b/src/main/java/org/elasticsearch/license/plugin/core/TrialLicenseUtils.java index 18d59a09bf5..758ca87e1d0 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/TrialLicenseUtils.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/TrialLicenseUtils.java @@ -9,9 +9,9 @@ import org.apache.commons.codec.binary.Base64; import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.ESLicense; -import org.elasticsearch.license.core.LicensesCharset; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -81,16 +81,16 @@ public class TrialLicenseUtils { uid = UUID.randomUUID().toString(); } return ESLicense.builder() - .type(DEFAULT_TYPE) - .subscriptionType(DEFAULT_SUBSCRIPTION_TYPE) - .issuer(DEFAULT_ISSUER) - .uid(uid) - .issuedTo(issuedTo) - .issueDate(issueDate) - .feature(feature) - .maxNodes(maxNodes) - .expiryDate(expiryDate) - .build(); + .type(DEFAULT_TYPE) + .subscriptionType(DEFAULT_SUBSCRIPTION_TYPE) + .issuer(DEFAULT_ISSUER) + .uid(uid) + .issuedTo(issuedTo) + .issueDate(issueDate) + .feature(feature) + .maxNodes(maxNodes) + .expiryDate(expiryDate) + .build(); } } @@ -110,17 +110,17 @@ public class TrialLicenseUtils { int uidLen = byteBuffer.getInt(); byte[] uidBytes = new byte[uidLen]; byteBuffer.get(uidBytes); - String uid = new String(uidBytes, LicensesCharset.UTF_8); + String uid = new String(uidBytes, StandardCharsets.UTF_8); int issuedToLen = byteBuffer.getInt(); byte[] issuedToBytes = new byte[issuedToLen]; byteBuffer.get(issuedToBytes); - String issuedTo = new String(issuedToBytes, LicensesCharset.UTF_8); + String issuedTo = new String(issuedToBytes, StandardCharsets.UTF_8); int featureLen = byteBuffer.getInt(); byte[] featureBytes = new byte[featureLen]; byteBuffer.get(featureBytes); - String feature = new String(featureBytes, LicensesCharset.UTF_8); + String feature = new String(featureBytes, StandardCharsets.UTF_8); int maxNodes = byteBuffer.getInt(); long issueDate = byteBuffer.getLong(); @@ -137,9 +137,9 @@ public class TrialLicenseUtils { } public static String toEncodedTrialLicense(ESLicense trialLicense) { - byte[] uidBytes = trialLicense.uid().getBytes(LicensesCharset.UTF_8); - byte[] featureBytes = trialLicense.feature().getBytes(LicensesCharset.UTF_8); - byte[] issuedToBytes = trialLicense.issuedTo().getBytes(LicensesCharset.UTF_8); + byte[] uidBytes = trialLicense.uid().getBytes(StandardCharsets.UTF_8); + byte[] featureBytes = trialLicense.feature().getBytes(StandardCharsets.UTF_8); + byte[] issuedToBytes = trialLicense.issuedTo().getBytes(StandardCharsets.UTF_8); // uid len + uid bytes + issuedTo len + issuedTo bytes + feature bytes length + feature bytes + maxNodes + issueDate + expiryDate int len = 4 + uidBytes.length + 4 + issuedToBytes.length + 4 + featureBytes.length + 4 + 8 + 8; diff --git a/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java b/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java index 96e131706d2..162d4e23bb5 100644 --- a/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java +++ b/src/main/java/org/elasticsearch/license/plugin/rest/RestGetLicenseAction.java @@ -33,25 +33,25 @@ public class RestGetLicenseAction extends BaseRestHandler { /** * Output Format: - * { - *   "licenses" : [ - *     { - *       "uid" : ..., - *       "type" : ..., - *       "subscription_type" :..., - *       "issued_to" : ... (cluster name if one-time trial license, else value from signed license), - *       "issue_date" : YY-MM-DD (date string in UTC), - *       "expiry_date" : YY-MM-DD (date string in UTC), - *       "feature" : ..., - *       "max_nodes" : ... - *     }, - * {...} - *   ] - * }p - * + * { + *   "licenses" : [ + *     { + *       "uid" : ..., + *       "type" : ..., + *       "subscription_type" :..., + *       "issued_to" : ... (cluster name if one-time trial license, else value from signed license), + *       "issue_date" : YY-MM-DD (date string in UTC), + *       "expiry_date" : YY-MM-DD (date string in UTC), + *       "feature" : ..., + *       "max_nodes" : ... + *     }, + * {...} + *   ] + * }p + *

* There will be only one license displayed per feature, the selected license will have the latest expiry_date * out of all other licenses for the feature. - * + *

* The licenses are sorted by latest issue_date */ diff --git a/src/main/java/org/elasticsearch/license/plugin/rest/RestPutLicenseAction.java b/src/main/java/org/elasticsearch/license/plugin/rest/RestPutLicenseAction.java index 6eff06d714d..d0d6d85b1e9 100644 --- a/src/main/java/org/elasticsearch/license/plugin/rest/RestPutLicenseAction.java +++ b/src/main/java/org/elasticsearch/license/plugin/rest/RestPutLicenseAction.java @@ -5,9 +5,6 @@ */ package org.elasticsearch.license.plugin.rest; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; diff --git a/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java b/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java index 98b8e6b5141..259d0c4c825 100644 --- a/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java +++ b/src/test/java/org/elasticsearch/license/AbstractLicensingTestBase.java @@ -14,20 +14,22 @@ import org.elasticsearch.license.core.DateUtils; import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.licensor.ESLicenseSigner; import org.elasticsearch.license.manager.ESLicenseManager; -import org.elasticsearch.test.ElasticsearchTestCase; import org.junit.BeforeClass; import org.junit.runner.RunWith; import java.io.IOException; import java.net.URL; -import java.text.ParseException; -import java.util.*; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.TimeUnit; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomRealisticUnicodeOfCodepointLengthBetween; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.test.ElasticsearchTestCase.randomFrom; + @RunWith(value = com.carrotsearch.randomizedtesting.RandomizedRunner.class) public class AbstractLicensingTestBase { diff --git a/src/test/java/org/elasticsearch/license/TestUtils.java b/src/test/java/org/elasticsearch/license/TestUtils.java index 535734cdeb3..84fee4ce47e 100644 --- a/src/test/java/org/elasticsearch/license/TestUtils.java +++ b/src/test/java/org/elasticsearch/license/TestUtils.java @@ -7,7 +7,11 @@ package org.elasticsearch.license; import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.core.ESLicenses; -import java.util.*; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; diff --git a/src/test/java/org/elasticsearch/license/licensor/LicenseGenerationToolTests.java b/src/test/java/org/elasticsearch/license/licensor/LicenseGenerationToolTests.java index 64e79765727..a6c5e0b2b91 100644 --- a/src/test/java/org/elasticsearch/license/licensor/LicenseGenerationToolTests.java +++ b/src/test/java/org/elasticsearch/license/licensor/LicenseGenerationToolTests.java @@ -15,18 +15,19 @@ import org.junit.Test; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.text.ParseException; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Set; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomAsciiOfLength; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomBoolean; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; public class LicenseGenerationToolTests extends AbstractLicensingTestBase { diff --git a/src/test/java/org/elasticsearch/license/licensor/LicenseSerializationTests.java b/src/test/java/org/elasticsearch/license/licensor/LicenseSerializationTests.java index d6c16787721..c0ebedc6179 100644 --- a/src/test/java/org/elasticsearch/license/licensor/LicenseSerializationTests.java +++ b/src/test/java/org/elasticsearch/license/licensor/LicenseSerializationTests.java @@ -6,24 +6,18 @@ package org.elasticsearch.license.licensor; import org.elasticsearch.license.AbstractLicensingTestBase; -import org.elasticsearch.license.TestUtils; import org.elasticsearch.license.core.DateUtils; import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.core.ESLicenses; -import org.elasticsearch.license.core.LicensesCharset; -import org.hamcrest.core.IsNull; import org.junit.Test; -import java.io.IOException; -import java.text.ParseException; +import java.nio.charset.StandardCharsets; import java.util.*; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; public class LicenseSerializationTests extends AbstractLicensingTestBase { @@ -33,7 +27,7 @@ public class LicenseSerializationTests extends AbstractLicensingTestBase { String issueDate = dateMathString("now", now); String expiryDate = dateMathString("now+10d/d", now); String licenseSpecs = generateESLicenseSpecString(Arrays.asList(new LicenseSpec("shield", issueDate, expiryDate))); - Set esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecs.getBytes(LicensesCharset.UTF_8), false)); + Set esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecs.getBytes(StandardCharsets.UTF_8), false)); ESLicense generatedLicense = esLicensesOutput.iterator().next(); assertThat(esLicensesOutput.size(), equalTo(1)); @@ -51,8 +45,8 @@ public class LicenseSerializationTests extends AbstractLicensingTestBase { String licenseSpecs = generateESLicenseSpecString(Arrays.asList(new LicenseSpec("shield", shieldIssueDate, shieldExpiryDate))); String licenseSpecs1 = generateESLicenseSpecString(Arrays.asList(new LicenseSpec("marvel", marvelIssueDate, marvelExpiryDate))); Set esLicensesOutput = new HashSet<>(); - esLicensesOutput.addAll(ESLicenses.fromSource(licenseSpecs.getBytes(LicensesCharset.UTF_8), false)); - esLicensesOutput.addAll(ESLicenses.fromSource(licenseSpecs1.getBytes(LicensesCharset.UTF_8), false)); + esLicensesOutput.addAll(ESLicenses.fromSource(licenseSpecs.getBytes(StandardCharsets.UTF_8), false)); + esLicensesOutput.addAll(ESLicenses.fromSource(licenseSpecs1.getBytes(StandardCharsets.UTF_8), false)); assertThat(esLicensesOutput.size(), equalTo(2)); for (ESLicense esLicense : esLicensesOutput) { assertThat(esLicense.issueDate(), equalTo(DateUtils.beginningOfTheDay((esLicense.feature().equals("shield")) ? shieldIssueDate : marvelIssueDate))); @@ -70,7 +64,7 @@ public class LicenseSerializationTests extends AbstractLicensingTestBase { ArrayList specs = new ArrayList<>(licenseSpecs.values()); String licenseSpecsSource = generateESLicenseSpecString(specs); - Set esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecsSource.getBytes(LicensesCharset.UTF_8), false)); + Set esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecsSource.getBytes(StandardCharsets.UTF_8), false)); assertThat(esLicensesOutput.size(), equalTo(licenseSpecs.size())); for (ESLicense license : esLicensesOutput) { diff --git a/src/test/java/org/elasticsearch/license/licensor/LicenseVerificationToolTests.java b/src/test/java/org/elasticsearch/license/licensor/LicenseVerificationToolTests.java index 8151f7bd093..677153a6e8c 100644 --- a/src/test/java/org/elasticsearch/license/licensor/LicenseVerificationToolTests.java +++ b/src/test/java/org/elasticsearch/license/licensor/LicenseVerificationToolTests.java @@ -104,8 +104,8 @@ public class LicenseVerificationToolTests extends AbstractLicensingTestBase { for (ESLicense license : output) { licensesOutput.add( ESLicense.builder() - .fromLicenseSpec(license, expectedLicenses.get(license.feature()).signature()) - .build() + .fromLicenseSpec(license, expectedLicenses.get(license.feature()).signature()) + .build() ); } diff --git a/src/test/java/org/elasticsearch/license/manager/LicenseSignatureTest.java b/src/test/java/org/elasticsearch/license/manager/LicenseSignatureTest.java index d212d38a599..16ccded98e3 100644 --- a/src/test/java/org/elasticsearch/license/manager/LicenseSignatureTest.java +++ b/src/test/java/org/elasticsearch/license/manager/LicenseSignatureTest.java @@ -11,11 +11,14 @@ import org.elasticsearch.license.core.ESLicense; import org.junit.BeforeClass; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import static com.carrotsearch.randomizedtesting.RandomizedTest.randomIntBetween; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; public class LicenseSignatureTest extends AbstractLicensingTestBase { diff --git a/src/test/java/org/elasticsearch/license/manager/LicenseVerificationTests.java b/src/test/java/org/elasticsearch/license/manager/LicenseVerificationTests.java index a829bebde32..a81c9d36c8a 100644 --- a/src/test/java/org/elasticsearch/license/manager/LicenseVerificationTests.java +++ b/src/test/java/org/elasticsearch/license/manager/LicenseVerificationTests.java @@ -12,10 +12,12 @@ import org.elasticsearch.license.core.ESLicense; import org.junit.BeforeClass; import org.junit.Test; -import java.util.*; +import java.util.HashMap; +import java.util.Map; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; public class LicenseVerificationTests extends AbstractLicensingTestBase { diff --git a/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTests.java b/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTests.java index 529887ad467..5c426dcec08 100644 --- a/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTests.java +++ b/src/test/java/org/elasticsearch/license/plugin/AbstractLicensesIntegrationTests.java @@ -28,7 +28,9 @@ import org.elasticsearch.license.plugin.core.LicensesStatus; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.InternalTestCluster; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java b/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java index f7c4ae04e0b..7d74626ad7b 100644 --- a/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java +++ b/src/test/java/org/elasticsearch/license/plugin/LicensesPluginIntegrationTests.java @@ -27,7 +27,7 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT private final boolean useEagerLicenseRegistrationPlugin = randomBoolean(); private final int trialLicenseDurationInSeconds = 5; - + protected Settings nodeSettings(int nodeOrdinal) { return ImmutableSettings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) @@ -51,7 +51,7 @@ public class LicensesPluginIntegrationTests extends AbstractLicensesIntegrationT @Test public void testTrialLicenseAndSignedLicenseNotification() throws Exception { - logger.info("using "+ ((useEagerLicenseRegistrationPlugin) ? "eager" : "lazy") + " consumer plugin"); + logger.info("using " + ((useEagerLicenseRegistrationPlugin) ? "eager" : "lazy") + " consumer plugin"); logger.info(" --> trial license generated"); // managerService should report feature to be enabled on all data nodes assertLicenseManagerEnabledFeatureFor(getCurrentFeatureName()); diff --git a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTest.java b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTest.java index e2777347e6c..d9b2eac8dfc 100644 --- a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTest.java +++ b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceClusterTest.java @@ -35,7 +35,7 @@ public class LicensesServiceClusterTest extends AbstractLicensesIntegrationTests private final String FEATURE_NAME = EagerLicenseRegistrationPluginService.FEATURE_NAME; private final int trialLicenseDurationInSeconds = 2; - + protected Settings transportClientSettings() { return super.transportClientSettings(); } diff --git a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java index c0cd707bd08..e77056ecde0 100644 --- a/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java +++ b/src/test/java/org/elasticsearch/license/plugin/LicensesServiceTests.java @@ -10,10 +10,8 @@ import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.base.Predicate; import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.license.TestUtils; import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.manager.ESLicenseManager; @@ -27,9 +25,7 @@ import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import static com.carrotsearch.randomizedtesting.RandomizedTest.randomFrom; import static org.elasticsearch.license.plugin.core.LicensesService.LicensesUpdateResponse; import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.TEST; @@ -332,7 +328,8 @@ public class LicensesServiceTests extends AbstractLicensesIntegrationTests { private Action assertExpiryAction(String feature, String licenseType, TimeValue expiryDuration) { return new Action(new Runnable() { @Override - public void run() {} + public void run() { + } }, 1, 0, TimeValue.timeValueMillis(expiryDuration.getMillis() * 2), "should trigger onDisable for " + feature + " once [" + licenseType + " license expiry]"); } diff --git a/src/test/java/org/elasticsearch/license/plugin/consumer/EagerLicenseRegistrationConsumerPlugin.java b/src/test/java/org/elasticsearch/license/plugin/consumer/EagerLicenseRegistrationConsumerPlugin.java index 36ef38b11c6..3324b3cf3db 100644 --- a/src/test/java/org/elasticsearch/license/plugin/consumer/EagerLicenseRegistrationConsumerPlugin.java +++ b/src/test/java/org/elasticsearch/license/plugin/consumer/EagerLicenseRegistrationConsumerPlugin.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.settings.Settings; /** * Registers licenses upon the start of the service lifecycle * see {@link org.elasticsearch.license.plugin.consumer.EagerLicenseRegistrationPluginService} - * + *

* License registration might happen before clusterService start() */ public class EagerLicenseRegistrationConsumerPlugin extends TestConsumerPluginBase { diff --git a/src/test/java/org/elasticsearch/license/plugin/consumer/LazyLicenseRegistrationConsumerPlugin.java b/src/test/java/org/elasticsearch/license/plugin/consumer/LazyLicenseRegistrationConsumerPlugin.java index aa46007b413..3eec52901dd 100644 --- a/src/test/java/org/elasticsearch/license/plugin/consumer/LazyLicenseRegistrationConsumerPlugin.java +++ b/src/test/java/org/elasticsearch/license/plugin/consumer/LazyLicenseRegistrationConsumerPlugin.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.settings.Settings; /** * Registers licenses only after cluster has recovered * see {@link org.elasticsearch.license.plugin.consumer.LazyLicenseRegistrationPluginService} - * + *

* License registration happens after clusterservice start() */ public class LazyLicenseRegistrationConsumerPlugin extends TestConsumerPluginBase {