Remove LicensingCharset & reformat code
Original commit: elastic/x-pack-elasticsearch@be5dc1c817
This commit is contained in:
parent
1eec394f8f
commit
9b30af3958
|
@ -29,7 +29,7 @@ public class ESLicense implements Comparable<ESLicense>, 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<ESLicense>, 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;
|
||||
}
|
||||
|
|
|
@ -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<ESLicense> fromSource(String content) throws IOException {
|
||||
return fromSource(content.getBytes(LicensesCharset.UTF_8), true);
|
||||
return fromSource(content.getBytes(StandardCharsets.UTF_8), true);
|
||||
}
|
||||
|
||||
public static List<ESLicense> fromSource(byte[] bytes) throws IOException {
|
||||
|
|
|
@ -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");
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
|
|||
|
||||
/**
|
||||
* Parses licenses from json format to an instance of {@link org.elasticsearch.license.core.ESLicenses}
|
||||
*
|
||||
* @param licenseDefinition licenses definition
|
||||
*/
|
||||
public PutLicenseRequest licenses(String licenseDefinition) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 <code>null</code> 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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<String> signatures, Set<String> 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
|
||||
|
|
|
@ -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)
|
||||
*
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Registration Scheme:
|
||||
* <p/>
|
||||
|
@ -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
|
||||
*
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Notification Scheme:
|
||||
* <p/>
|
||||
|
@ -431,11 +431,10 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
|||
/**
|
||||
* Calls {@link #notifyFeaturesAndScheduleNotification(LicensesMetaData)} with <code>currentLicensesMetaData</code>
|
||||
* if it was not already notified on.
|
||||
*
|
||||
* <p/>
|
||||
* Upon completion sets <code>currentLicensesMetaData</code> 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<LicensesService>
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -13,6 +13,7 @@ public enum LicensesStatus {
|
|||
EXPIRED((byte) 2);
|
||||
|
||||
private byte id;
|
||||
|
||||
LicensesStatus(byte id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
* <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.
|
||||
*
|
||||
* <p/>
|
||||
* The licenses are sorted by latest issue_date
|
||||
*/
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecs.getBytes(LicensesCharset.UTF_8), false));
|
||||
Set<ESLicense> 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<ESLicense> 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<LicenseSpec> specs = new ArrayList<>(licenseSpecs.values());
|
||||
String licenseSpecsSource = generateESLicenseSpecString(specs);
|
||||
Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecsSource.getBytes(LicensesCharset.UTF_8), false));
|
||||
Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseSpecsSource.getBytes(StandardCharsets.UTF_8), false));
|
||||
assertThat(esLicensesOutput.size(), equalTo(licenseSpecs.size()));
|
||||
|
||||
for (ESLicense license : esLicensesOutput) {
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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]");
|
||||
}
|
||||
|
|
|
@ -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}
|
||||
*
|
||||
* <p/>
|
||||
* License registration might happen before clusterService start()
|
||||
*/
|
||||
public class EagerLicenseRegistrationConsumerPlugin extends TestConsumerPluginBase {
|
||||
|
|
|
@ -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}
|
||||
*
|
||||
* <p/>
|
||||
* License registration happens after clusterservice start()
|
||||
*/
|
||||
public class LazyLicenseRegistrationConsumerPlugin extends TestConsumerPluginBase {
|
||||
|
|
Loading…
Reference in New Issue