LicensesClientService.register works even if there is no master; LicensesManagerService.licenses() returns

one appropriate license per registered feature

Original commit: elastic/x-pack-elasticsearch@4d3ac103d6
This commit is contained in:
Areek Zillur 2014-10-23 15:37:58 -04:00
parent 935f98a4b8
commit 28bc28e30d
13 changed files with 126 additions and 83 deletions

View File

@ -26,15 +26,15 @@ public class ESLicenses {
builder.endObject(); builder.endObject();
} }
public static Set<ESLicense> fromSource(String content) throws IOException { public static List<ESLicense> fromSource(String content) throws IOException {
return fromSource(content.getBytes(LicensesCharset.UTF_8)); return fromSource(content.getBytes(LicensesCharset.UTF_8));
} }
public static Set<ESLicense> fromSource(byte[] bytes) throws IOException { public static List<ESLicense> fromSource(byte[] bytes) throws IOException {
return fromXContent(XContentFactory.xContent(bytes).createParser(bytes)); return fromXContent(XContentFactory.xContent(bytes).createParser(bytes));
} }
private static Set<ESLicense> fromXContent(XContentParser parser) throws IOException { private static List<ESLicense> fromXContent(XContentParser parser) throws IOException {
Set<ESLicense> esLicenses = new HashSet<>(); Set<ESLicense> esLicenses = new HashSet<>();
final Map<String, Object> licensesMap = parser.mapAndClose(); final Map<String, Object> licensesMap = parser.mapAndClose();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -43,19 +43,19 @@ public class ESLicenses {
final ESLicense esLicense = ESLicense.fromXContent(licenseMap); final ESLicense esLicense = ESLicense.fromXContent(licenseMap);
esLicenses.add(esLicense); esLicenses.add(esLicense);
} }
return esLicenses; return new ArrayList<>(esLicenses);
} }
public static Set<ESLicense> readFrom(StreamInput in) throws IOException { public static List<ESLicense> readFrom(StreamInput in) throws IOException {
int size = in.readVInt(); int size = in.readVInt();
Set<ESLicense> esLicenses = new HashSet<>(size); List<ESLicense> esLicenses = new ArrayList<>(size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
esLicenses.add(ESLicense.readFrom(in)); esLicenses.add(ESLicense.readFrom(in));
} }
return esLicenses; return esLicenses;
} }
public static void writeTo(Set<ESLicense> esLicenses, StreamOutput out) throws IOException { public static void writeTo(List<ESLicense> esLicenses, StreamOutput out) throws IOException {
out.writeVInt(esLicenses.size()); out.writeVInt(esLicenses.size());
for (ESLicense license : esLicenses) { for (ESLicense license : esLicenses) {
ESLicense.writeTo(license, out); ESLicense.writeTo(license, out);

View File

@ -12,21 +12,23 @@ import org.elasticsearch.license.core.ESLicense;
import org.elasticsearch.license.core.ESLicenses; import org.elasticsearch.license.core.ESLicenses;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
public class GetLicenseResponse extends ActionResponse { public class GetLicenseResponse extends ActionResponse {
private Set<ESLicense> licenses = new HashSet<>(); private List<ESLicense> licenses = new ArrayList<>();
GetLicenseResponse() { GetLicenseResponse() {
} }
GetLicenseResponse(Set<ESLicense> esLicenses) { GetLicenseResponse(List<ESLicense> esLicenses) {
this.licenses = esLicenses; this.licenses = esLicenses;
} }
public Set<ESLicense> licenses() { public List<ESLicense> licenses() {
return licenses; return licenses;
} }

View File

@ -20,6 +20,7 @@ import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import java.util.List;
import java.util.Set; import java.util.Set;
public class TransportGetLicenseAction extends TransportMasterNodeReadOperationAction<GetLicenseRequest, GetLicenseResponse> { public class TransportGetLicenseAction extends TransportMasterNodeReadOperationAction<GetLicenseRequest, GetLicenseResponse> {
@ -55,7 +56,7 @@ public class TransportGetLicenseAction extends TransportMasterNodeReadOperationA
@Override @Override
protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse> listener) throws ElasticsearchException { protected void masterOperation(final GetLicenseRequest request, ClusterState state, final ActionListener<GetLicenseResponse> listener) throws ElasticsearchException {
final Set<ESLicense> currentLicenses = licensesManagerService.getLicenses(); final List<ESLicense> currentLicenses = licensesManagerService.getLicenses();
listener.onResponse(new GetLicenseResponse(currentLicenses)); listener.onResponse(new GetLicenseResponse(currentLicenses));
} }
} }

View File

@ -14,12 +14,12 @@ import org.elasticsearch.license.core.ESLicense;
import org.elasticsearch.license.core.ESLicenses; import org.elasticsearch.license.core.ESLicenses;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.List;
public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> { public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
private Set<ESLicense> licenses; private List<ESLicense> licenses;
public PutLicenseRequest() { public PutLicenseRequest() {
} }
@ -41,12 +41,12 @@ public class PutLicenseRequest extends AcknowledgedRequest<PutLicenseRequest> {
} }
} }
public PutLicenseRequest licenses(Set<ESLicense> esLicenses) { public PutLicenseRequest licenses(List<ESLicense> esLicenses) {
this.licenses = esLicenses; this.licenses = esLicenses;
return this; return this;
} }
public Set<ESLicense> licenses() { public List<ESLicense> licenses() {
return licenses; return licenses;
} }

View File

@ -8,8 +8,11 @@ package org.elasticsearch.license.plugin.action.put;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder; import org.elasticsearch.action.support.master.AcknowledgedRequestBuilder;
import org.elasticsearch.client.ClusterAdminClient; import org.elasticsearch.client.ClusterAdminClient;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.core.ESLicense;
import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
@ -32,7 +35,7 @@ public class PutLicenseRequestBuilder extends AcknowledgedRequestBuilder<PutLice
* @param licenses license * @param licenses license
* @return this builder * @return this builder
*/ */
public PutLicenseRequestBuilder setLicense(Set<ESLicense> licenses) { public PutLicenseRequestBuilder setLicense(List<ESLicense> licenses) {
request.licenses(licenses); request.licenses(licenses);
return this; return this;
} }

View File

@ -10,6 +10,7 @@ import org.elasticsearch.cluster.ack.ClusterStateUpdateResponse;
import org.elasticsearch.common.inject.ImplementedBy; import org.elasticsearch.common.inject.ImplementedBy;
import org.elasticsearch.license.core.ESLicense; import org.elasticsearch.license.core.ESLicense;
import java.util.List;
import java.util.Set; import java.util.Set;
import static org.elasticsearch.license.plugin.core.LicensesService.DeleteLicenseRequestHolder; import static org.elasticsearch.license.plugin.core.LicensesService.DeleteLicenseRequestHolder;
@ -28,5 +29,5 @@ public interface LicensesManagerService {
public Set<String> enabledFeatures(); public Set<String> enabledFeatures();
public Set<ESLicense> getLicenses(); public List<ESLicense> getLicenses();
} }

View File

@ -38,6 +38,7 @@ import org.elasticsearch.transport.*;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -70,6 +71,8 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
private List<ListenerHolder> registeredListeners = new CopyOnWriteArrayList<>(); private List<ListenerHolder> registeredListeners = new CopyOnWriteArrayList<>();
private Queue<ListenerHolder> pendingRegistrations = new ConcurrentLinkedQueue<>();
private volatile ScheduledFuture notificationScheduler; private volatile ScheduledFuture notificationScheduler;
@Inject @Inject
@ -93,7 +96,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
@Override @Override
public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener) { public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener) {
final PutLicenseRequest request = requestHolder.request; final PutLicenseRequest request = requestHolder.request;
final Set<ESLicense> newLicenses = request.licenses(); final Set<ESLicense> newLicenses = Sets.newHashSet(request.licenses());
LicensesStatus status = checkLicenses(newLicenses); LicensesStatus status = checkLicenses(newLicenses);
switch (status) { switch (status) {
case VALID: case VALID:
@ -114,7 +117,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData()); MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE); LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses); final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
licensesWrapper.addSignedLicenses(esLicenseManager, newLicenses); licensesWrapper.addSignedLicenses(esLicenseManager, Sets.newHashSet(newLicenses));
mdBuilder.putCustom(LicensesMetaData.TYPE, licensesWrapper.createLicensesMetaData()); mdBuilder.putCustom(LicensesMetaData.TYPE, licensesWrapper.createLicensesMetaData());
return ClusterState.builder(currentState).metaData(mdBuilder).build(); return ClusterState.builder(currentState).metaData(mdBuilder).build();
} }
@ -177,7 +180,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
} }
@Override @Override
public Set<ESLicense> getLicenses() { public List<ESLicense> getLicenses() {
LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
Set<ESLicense> trialLicenses = new HashSet<>(); Set<ESLicense> trialLicenses = new HashSet<>();
if (currentMetaData != null) { if (currentMetaData != null) {
@ -197,10 +200,31 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
); );
} }
Set<ESLicense> licenses = Sets.union(currentLicenses, trialLicenses); Set<ESLicense> licenses = Sets.union(currentLicenses, trialLicenses);
//TODO: sort in some order
return licenses; // bucket license for feature with the latest expiry date
Map<String, ESLicense> licenseMap = new HashMap<>();
for (ESLicense license : licenses) {
if (!licenseMap.containsKey(license.feature())) {
licenseMap.put(license.feature(), license);
} else {
ESLicense prevLicense = licenseMap.get(license.feature());
if (license.expiryDate() > prevLicense.expiryDate()) {
licenseMap.put(license.feature(), license);
}
}
}
// sort the licenses by issue date
List<ESLicense> reducedLicenses = new ArrayList<>(licenseMap.values());
Collections.sort(reducedLicenses, new Comparator<ESLicense>() {
@Override
public int compare(ESLicense license1, ESLicense license2) {
return (int) (license2.issueDate() - license1.issueDate());
}
});
return reducedLicenses;
} }
return Sets.newHashSet(); return Collections.emptyList();
} }
@ -283,6 +307,17 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
public void clusterChanged(ClusterChangedEvent event) { public void clusterChanged(ClusterChangedEvent event) {
if (!event.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { if (!event.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
if (!pendingRegistrations.isEmpty()) {
while (true) {
ListenerHolder pendingRegistrationLister = pendingRegistrations.poll();
if (pendingRegistrationLister != null) {
registerListener(pendingRegistrationLister);
} else {
break;
}
}
}
// notify all interested plugins // notify all interested plugins
if (checkIfUpdatedMetaData(event)) { if (checkIfUpdatedMetaData(event)) {
final LicensesMetaData currentLicensesMetaData = event.state().getMetaData().custom(LicensesMetaData.TYPE); final LicensesMetaData currentLicensesMetaData = event.state().getMetaData().custom(LicensesMetaData.TYPE);
@ -313,43 +348,49 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
@Override @Override
public void register(String feature, TrialLicenseOptions trialLicenseOptions, Listener listener) { public void register(String feature, TrialLicenseOptions trialLicenseOptions, Listener listener) {
registeredListeners.add(new ListenerHolder(feature, trialLicenseOptions, listener)); final ListenerHolder listenerHolder = new ListenerHolder(feature, trialLicenseOptions, listener);
registeredListeners.add(listenerHolder);
if (!clusterService.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { //if (!clusterService.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) {
LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); registerListener(listenerHolder);
registerListeners(currentMetaData); //}
}
} }
private void registerListeners(LicensesMetaData currentMetaData) { private void registerListener(final ListenerHolder listenerHolder) {
for (ListenerHolder listenerHolder : registeredListeners) { LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE);
if (listenerHolder.registered.compareAndSet(false, true)) { if (!esLicenseManager.hasLicenseForFeature(listenerHolder.feature, getEffectiveLicenses())) {
if (!esLicenseManager.hasLicenseForFeature(listenerHolder.feature, getEffectiveLicenses())) { // does not have actual license so generate a trial license
// does not have actual license so generate a trial license TrialLicenseOptions options = listenerHolder.trialLicenseOptions;
TrialLicenseOptions options = listenerHolder.trialLicenseOptions; if (options != null) {
if (options != null) { // Trial license option is provided
// Trial license option is provided RegisterTrialLicenseRequest request = new RegisterTrialLicenseRequest(listenerHolder.feature,
RegisterTrialLicenseRequest request = new RegisterTrialLicenseRequest(listenerHolder.feature, new TimeValue(options.durationInDays, TimeUnit.DAYS), options.maxNodes);
new TimeValue(options.durationInDays, TimeUnit.DAYS), options.maxNodes); if (clusterService.state().nodes().localNodeMaster()) {
if (clusterService.state().nodes().localNodeMaster()) { registerTrialLicense(request);
registerTrialLicense(request); } else {
} else { DiscoveryNode masterNode = clusterService.state().nodes().masterNode();
DiscoveryNode masterNode; logger.info("has STATE_NOT_RECOVERED_BLOCK: " + clusterService.state().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)
if ((masterNode = clusterService.state().nodes().masterNode()) != null) { + " has masterNode: " + (masterNode != null));
transportService.sendRequest(masterNode, if (masterNode != null) {
REGISTER_TRIAL_LICENSE_ACTION_NAME, request, EmptyTransportResponseHandler.INSTANCE_SAME); transportService.sendRequest(masterNode,
} else { REGISTER_TRIAL_LICENSE_ACTION_NAME, request, EmptyTransportResponseHandler.INSTANCE_SAME);
// could not sent register trial license request to master
}
}
} else { } else {
// notify feature as clusterChangedEvent may not happen // could not sent register trial license request to master
// Change to debug pendingRegistrations.add(listenerHolder);
logger.info("calling notifyFeatures from registerListeners");
notifyFeatures(currentMetaData);
} }
} }
} else {
// notify feature as clusterChangedEvent may not happen
// as no trial or signed license has been found for feature
// Change to debug
logger.info("calling notifyFeatures from registerListeners");
notifyFeatures(currentMetaData);
} }
} else {
// signed license already found for the new registered
// feature, notify feature on registration
notifyFeatures(currentMetaData);
} }
} }
@ -505,7 +546,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
final String feature; final String feature;
final TrialLicenseOptions trialLicenseOptions; final TrialLicenseOptions trialLicenseOptions;
final Listener listener; final Listener listener;
final AtomicBoolean registered = new AtomicBoolean(false);
final AtomicBoolean enabled = new AtomicBoolean(false); // by default, a consumer plugin should be disabled final AtomicBoolean enabled = new AtomicBoolean(false); // by default, a consumer plugin should be disabled

View File

@ -13,9 +13,7 @@ import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap; import java.util.*;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -31,7 +29,7 @@ public class LicenseGenerationTests extends AbstractLicensingTestBase {
String licenseOutput = generateSignedLicenses(map); String licenseOutput = generateSignedLicenses(map);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(licenseOutput); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseOutput));
TestUtils.verifyESLicenses(esLicensesOutput, map); TestUtils.verifyESLicenses(esLicensesOutput, map);
} }
@ -49,7 +47,7 @@ public class LicenseGenerationTests extends AbstractLicensingTestBase {
String licenseOutput = generateSignedLicenses(map); String licenseOutput = generateSignedLicenses(map);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(licenseOutput); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(licenseOutput));
TestUtils.verifyESLicenses(esLicensesOutput, map); TestUtils.verifyESLicenses(esLicensesOutput, map);
} }

View File

@ -18,6 +18,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -42,7 +43,7 @@ public class LicenseVerificationToolTests extends AbstractLicensingTestBase {
String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile}); String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile});
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(effectiveLicenseStr); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(effectiveLicenseStr));
map.put(TestUtils.SHIELD, featureWithLongerExpiryDate); map.put(TestUtils.SHIELD, featureWithLongerExpiryDate);
// verify that the effective license strips out license for the same feature with earlier expiry dates // verify that the effective license strips out license for the same feature with earlier expiry dates
@ -67,7 +68,7 @@ public class LicenseVerificationToolTests extends AbstractLicensingTestBase {
String secondLicenseFile = getAsFilePath(signedLicense); String secondLicenseFile = getAsFilePath(signedLicense);
String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile}); String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile});
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(effectiveLicenseStr); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(effectiveLicenseStr));
// verify that the effective license contains both feature licenses // verify that the effective license contains both feature licenses
TestUtils.verifyESLicenses(esLicensesOutput, map); TestUtils.verifyESLicenses(esLicensesOutput, map);
@ -100,7 +101,7 @@ public class LicenseVerificationToolTests extends AbstractLicensingTestBase {
String secondLicenseFile = getAsFilePath(signedLicense); String secondLicenseFile = getAsFilePath(signedLicense);
String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile}); String effectiveLicenseStr = runLicenseVerificationTool(new String[]{firstLicenseFile, secondLicenseFile});
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(effectiveLicenseStr); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(effectiveLicenseStr));
map.put(TestUtils.SHIELD, shieldFeatureWithLongerExpiryDate); map.put(TestUtils.SHIELD, shieldFeatureWithLongerExpiryDate);
map.put(TestUtils.MARVEL, marvelFeatureWithLongerExpiryDate); map.put(TestUtils.MARVEL, marvelFeatureWithLongerExpiryDate);

View File

@ -52,7 +52,7 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
new TestUtils.FeatureAttributes("shield", "subscription", "platinum", "foo bar Inc.", "elasticsearch", 2, issueDateStr, expiryDateStr); new TestUtils.FeatureAttributes("shield", "subscription", "platinum", "foo bar Inc.", "elasticsearch", 2, issueDateStr, expiryDateStr);
map.put(TestUtils.SHIELD, featureAttributes); map.put(TestUtils.SHIELD, featureAttributes);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(generateSignedLicenses(map)); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(generateSignedLicenses(map)));
esLicenseProvider.setLicenses(esLicensesOutput); esLicenseProvider.setLicenses(esLicensesOutput);
@ -76,7 +76,7 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
map.put(TestUtils.SHIELD, shildFeatureAttributes); map.put(TestUtils.SHIELD, shildFeatureAttributes);
map.put(TestUtils.MARVEL, marvelFeatureAttributes); map.put(TestUtils.MARVEL, marvelFeatureAttributes);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(generateSignedLicenses(map)); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(generateSignedLicenses(map)));
esLicenseProvider.setLicenses(esLicensesOutput); esLicenseProvider.setLicenses(esLicensesOutput);
@ -131,7 +131,7 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
map.put(TestUtils.SHIELD, shildFeatureAttributes); map.put(TestUtils.SHIELD, shildFeatureAttributes);
map.put(TestUtils.MARVEL, marvelFeatureAttributes); map.put(TestUtils.MARVEL, marvelFeatureAttributes);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(generateSignedLicenses(map)); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(generateSignedLicenses(map)));
esLicenseProvider.setLicenses(esLicensesOutput); esLicenseProvider.setLicenses(esLicensesOutput);
@ -153,7 +153,7 @@ public class LicenseVerificationTests extends AbstractLicensingTestBase {
new TestUtils.FeatureAttributes("shield", "subscription", "platinum", "foo bar Inc.", "elasticsearch", 2, issueDateStr, expiryDateStr); new TestUtils.FeatureAttributes("shield", "subscription", "platinum", "foo bar Inc.", "elasticsearch", 2, issueDateStr, expiryDateStr);
map.put(TestUtils.SHIELD, featureAttributes); map.put(TestUtils.SHIELD, featureAttributes);
Set<ESLicense> esLicensesOutput = ESLicenses.fromSource(generateSignedLicenses(map)); Set<ESLicense> esLicensesOutput = new HashSet<>(ESLicenses.fromSource(generateSignedLicenses(map)));
ESLicense esLicense = Utils.reduceAndMap(esLicensesOutput).get(TestUtils.SHIELD); ESLicense esLicense = Utils.reduceAndMap(esLicensesOutput).get(TestUtils.SHIELD);

View File

@ -28,10 +28,7 @@ import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.ParseException; import java.text.ParseException;
import java.util.Collections; import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
@ -98,7 +95,7 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster()); PutLicenseRequestBuilder putLicenseRequestBuilder = new PutLicenseRequestBuilder(client().admin().cluster());
//putLicenseRequest.license(licenseString); //putLicenseRequest.license(licenseString);
final Set<ESLicense> putLicenses = ESLicenses.fromSource(licenseOutput); final List<ESLicense> putLicenses = ESLicenses.fromSource(licenseOutput);
putLicenseRequestBuilder.setLicense(putLicenses); putLicenseRequestBuilder.setLicense(putLicenses);
//LicenseUtils.printLicense(putLicenses); //LicenseUtils.printLicense(putLicenses);
ensureGreen(); ensureGreen();
@ -116,7 +113,7 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
assertThat(getLicenseResponse.licenses(), notNullValue()); assertThat(getLicenseResponse.licenses(), notNullValue());
//LicenseUtils.printLicense(getLicenseResponse.licenses()); //LicenseUtils.printLicense(getLicenseResponse.licenses());
TestUtils.isSame(putLicenses, getLicenseResponse.licenses()); TestUtils.isSame(new HashSet<>(putLicenses), new HashSet<>(getLicenseResponse.licenses()));
final ActionFuture<DeleteLicenseResponse> deleteFuture = new DeleteLicenseRequestBuilder(client().admin().cluster()) final ActionFuture<DeleteLicenseResponse> deleteFuture = new DeleteLicenseRequestBuilder(client().admin().cluster())
@ -137,7 +134,7 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
String licenseString = TestUtils.generateESLicenses(map); String licenseString = TestUtils.generateESLicenses(map);
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath); String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
Set<ESLicense> esLicenses = ESLicenses.fromSource(licenseOutput); Set<ESLicense> esLicenses = new HashSet<>(ESLicenses.fromSource(licenseOutput));
ESLicense esLicense = Utils.reduceAndMap(esLicenses).get(TestUtils.SHIELD); ESLicense esLicense = Utils.reduceAndMap(esLicenses).get(TestUtils.SHIELD);
@ -149,7 +146,7 @@ public class LicenseTransportTests extends ElasticsearchIntegrationTest {
.build(); .build();
PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster()); PutLicenseRequestBuilder builder = new PutLicenseRequestBuilder(client().admin().cluster());
builder.setLicense(Collections.singleton(tamperedLicense)); builder.setLicense(Collections.singletonList(tamperedLicense));
final ListenableActionFuture<PutLicenseResponse> execute = builder.execute(); final ListenableActionFuture<PutLicenseResponse> execute = builder.execute();

View File

@ -10,7 +10,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.InternalTestCluster; import org.elasticsearch.test.InternalTestCluster;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import static org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
@ -19,6 +18,7 @@ import static org.elasticsearch.test.ElasticsearchIntegrationTest.Scope.SUITE;
@ClusterScope(scope = SUITE, numDataNodes = 10) @ClusterScope(scope = SUITE, numDataNodes = 10)
public class LicensesPluginIntegrationTests extends ElasticsearchIntegrationTest { public class LicensesPluginIntegrationTests extends ElasticsearchIntegrationTest {
@Override @Override
protected Settings nodeSettings(int nodeOrdinal) { protected Settings nodeSettings(int nodeOrdinal) {
return ImmutableSettings.settingsBuilder() return ImmutableSettings.settingsBuilder()
@ -33,13 +33,13 @@ public class LicensesPluginIntegrationTests extends ElasticsearchIntegrationTest
return nodeSettings(0); return nodeSettings(0);
} }
@Test @Ignore @Test
public void testLicenseRegistration() throws Exception { public void testLicenseRegistration() throws Exception {
LicensesManagerService managerService = licensesManagerService(); LicensesManagerService managerService = licensesManagerService();
assertTrue(managerService.enabledFeatures().contains(TestPluginService.FEATURE_NAME)); assertTrue(managerService.enabledFeatures().contains(TestPluginService.FEATURE_NAME));
} }
@Test @Ignore @Test
public void testFeatureActivation() throws Exception { public void testFeatureActivation() throws Exception {
TestPluginService pluginService = consumerPluginService(); TestPluginService pluginService = consumerPluginService();
assertTrue(pluginService.enabled()); assertTrue(pluginService.enabled());

View File

@ -117,7 +117,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
map.put(TestUtils.SHIELD, featureAttributes); map.put(TestUtils.SHIELD, featureAttributes);
String licenseString = TestUtils.generateESLicenses(map); String licenseString = TestUtils.generateESLicenses(map);
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath); String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
Set<ESLicense> licenses = ESLicenses.fromSource(licenseOutput); Set<ESLicense> licenses = new HashSet<>(ESLicenses.fromSource(licenseOutput));
assertTrue(LicensesStatus.VALID == licensesManagerService.checkLicenses(licenses)); assertTrue(LicensesStatus.VALID == licensesManagerService.checkLicenses(licenses));
@ -141,7 +141,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
map.put(TestUtils.SHIELD, featureAttributes1); map.put(TestUtils.SHIELD, featureAttributes1);
String licenseString = TestUtils.generateESLicenses(map); String licenseString = TestUtils.generateESLicenses(map);
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath); String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
Set<ESLicense> licenses = ESLicenses.fromSource(licenseOutput); List<ESLicense> licenses = ESLicenses.fromSource(licenseOutput);
LicensesManagerService licensesManagerService = masterLicensesManagerService(); LicensesManagerService licensesManagerService = masterLicensesManagerService();
ESLicenseManager esLicenseManager = ((LicensesService) licensesManagerService).getEsLicenseManager(); ESLicenseManager esLicenseManager = ((LicensesService) licensesManagerService).getEsLicenseManager();
@ -163,7 +163,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
latch1.await(); latch1.await();
LicensesMetaData metaData = clusterService().state().metaData().custom(LicensesMetaData.TYPE); LicensesMetaData metaData = clusterService().state().metaData().custom(LicensesMetaData.TYPE);
Set<ESLicense> metaDataLicense = esLicenseManager.fromSignatures(metaData.getSignatures()); Set<ESLicense> metaDataLicense = esLicenseManager.fromSignatures(metaData.getSignatures());
TestUtils.isSame(licenses, metaDataLicense); TestUtils.isSame(new HashSet<>(licenses), metaDataLicense);
TestUtils.FeatureAttributes featureAttributes2 = TestUtils.FeatureAttributes featureAttributes2 =
@ -171,7 +171,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
map.put(TestUtils.SHIELD, featureAttributes2); map.put(TestUtils.SHIELD, featureAttributes2);
licenseString = TestUtils.generateESLicenses(map); licenseString = TestUtils.generateESLicenses(map);
licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath); licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
Set<ESLicense> licenses2 = ESLicenses.fromSource(licenseOutput); List<ESLicense> licenses2 = ESLicenses.fromSource(licenseOutput);
final CountDownLatch latch2 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(1);
licensesManagerService.registerLicenses(new LicensesService.PutLicenseRequestHolder(new PutLicenseRequest().licenses(licenses2), "test"), new ActionListener<ClusterStateUpdateResponse>() { licensesManagerService.registerLicenses(new LicensesService.PutLicenseRequestHolder(new PutLicenseRequest().licenses(licenses2), "test"), new ActionListener<ClusterStateUpdateResponse>() {
@Override @Override
@ -190,7 +190,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
latch2.await(); latch2.await();
metaData = clusterService().state().metaData().custom(LicensesMetaData.TYPE); metaData = clusterService().state().metaData().custom(LicensesMetaData.TYPE);
metaDataLicense = esLicenseManager.fromSignatures(metaData.getSignatures()); metaDataLicense = esLicenseManager.fromSignatures(metaData.getSignatures());
TestUtils.isSame(licenses2, metaDataLicense); TestUtils.isSame(new HashSet<>(licenses2), metaDataLicense);
} }
@Test @Test
@ -281,7 +281,7 @@ public class LicensesServiceTests extends ElasticsearchIntegrationTest {
map.put(TestUtils.SHIELD, featureAttributes1); map.put(TestUtils.SHIELD, featureAttributes1);
String licenseString = TestUtils.generateESLicenses(map); String licenseString = TestUtils.generateESLicenses(map);
String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath); String licenseOutput = TestUtils.runLicenseGenerationTool(licenseString, pubKeyPath, priKeyPath);
Set<ESLicense> licenses = ESLicenses.fromSource(licenseOutput); List<ESLicense> licenses = ESLicenses.fromSource(licenseOutput);
final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch1 = new CountDownLatch(1);
masterLicensesManagerService.registerLicenses(new LicensesService.PutLicenseRequestHolder(new PutLicenseRequest().licenses(licenses), "test"), new ActionListener<ClusterStateUpdateResponse>() { masterLicensesManagerService.registerLicenses(new LicensesService.PutLicenseRequestHolder(new PutLicenseRequest().licenses(licenses), "test"), new ActionListener<ClusterStateUpdateResponse>() {