diff --git a/src/main/java/org/elasticsearch/license/core/ESLicense.java b/src/main/java/org/elasticsearch/license/core/ESLicense.java index 8db4439e5b1..51dbf0ab772 100644 --- a/src/main/java/org/elasticsearch/license/core/ESLicense.java +++ b/src/main/java/org/elasticsearch/license/core/ESLicense.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -public class ESLicense implements Comparable, ToXContent { +public class ESLicense implements ToXContent { private final String uid; private final String issuer; @@ -113,12 +113,6 @@ public class ESLicense implements Comparable, ToXContent { return signature; } - @Override - public int compareTo(ESLicense o) { - assert o != null; - return Long.compare(expiryDate, o.expiryDate); - } - public void verify() { if (issuer == null) { throw new IllegalStateException("issuer can not be null"); 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 b9e350eb044..82b8b05714c 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license.plugin.core; -import net.nicholaswilliams.java.licensing.exception.ExpiredLicenseException; import net.nicholaswilliams.java.licensing.exception.InvalidLicenseException; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; @@ -280,8 +279,6 @@ public class LicensesService extends AbstractLifecycleComponent LicensesStatus status = LicensesStatus.VALID; try { licenseManager.verifyLicenses(licenseMap); - } catch (ExpiredLicenseException e) { - status = LicensesStatus.EXPIRED; } catch (InvalidLicenseException e) { status = LicensesStatus.INVALID; } @@ -297,9 +294,8 @@ public class LicensesService extends AbstractLifecycleComponent clusterService.submitStateUpdateTask("register trial license []", new ProcessedClusterStateUpdateTask() { @Override public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { - logger.debug("Processed Trial License registration"); LicensesMetaData licensesMetaData = newState.metaData().custom(LicensesMetaData.TYPE); - logLicenseMetaDataStats("new", licensesMetaData); + logLicenseMetaDataStats("after trial license registration", licensesMetaData); } @Override @@ -351,7 +347,6 @@ public class LicensesService extends AbstractLifecycleComponent @Override protected void doStart() throws ElasticsearchException { - logger.debug("Started LicensesService"); clusterService.add(this); } @@ -379,7 +374,6 @@ public class LicensesService extends AbstractLifecycleComponent @Override protected void doClose() throws ElasticsearchException { - logger.debug("Closing LicensesService"); transportService.removeHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME); } @@ -406,7 +400,9 @@ public class LicensesService extends AbstractLifecycleComponent ListenerHolder pendingRegistrationListener; while ((pendingRegistrationListener = pendingListeners.poll()) != null) { boolean masterAvailable = registerListener(pendingRegistrationListener); - logger.debug("trying to register pending listener for " + pendingRegistrationListener.feature + " masterAvailable: " + masterAvailable); + if (logger.isDebugEnabled()) { + logger.debug("trying to register pending listener for " + pendingRegistrationListener.feature + " masterAvailable: " + masterAvailable); + } if (!masterAvailable) { // if the master is not available do not, break out of trying pendingListeners pendingListeners.add(pendingRegistrationListener); @@ -417,13 +413,11 @@ public class LicensesService extends AbstractLifecycleComponent // notify all interested plugins if (previousClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { - logger.debug("calling notifyFeaturesAndScheduleNotification from clusterChanged"); notifyFeaturesAndScheduleNotification(currentLicensesMetaData); } else { - logger.debug("calling notifyFeaturesAndScheduleNotificationIfNeeded from clusterChanged"); notifyFeaturesAndScheduleNotificationIfNeeded(currentLicensesMetaData); } - } else { + } else if (logger.isDebugEnabled()) { logger.debug("clusterChanged: no action [has STATE_NOT_RECOVERED_BLOCK]"); } } @@ -439,12 +433,14 @@ public class LicensesService extends AbstractLifecycleComponent private void notifyFeaturesAndScheduleNotificationIfNeeded(final LicensesMetaData currentLicensesMetaData) { final LicensesMetaData lastNotifiedLicensesMetaData = lastObservedLicensesState.get(); if (lastNotifiedLicensesMetaData != null && lastNotifiedLicensesMetaData.equals(currentLicensesMetaData)) { - logger.debug("currentLicensesMetaData has been already notified on"); + if (logger.isDebugEnabled()) { + logger.debug("currentLicensesMetaData has been already notified on"); + } return; } notifyFeaturesAndScheduleNotification(currentLicensesMetaData); - logLicenseMetaDataStats("Setting last observed metaData", currentLicensesMetaData); lastObservedLicensesState.set(currentLicensesMetaData); + logLicenseMetaDataStats("Setting last observed metaData", currentLicensesMetaData); } /** @@ -572,12 +568,10 @@ public class LicensesService extends AbstractLifecycleComponent RegisterTrialLicenseRequest request = new RegisterTrialLicenseRequest(listenerHolder.feature, options.duration, options.maxNodes); if (currentState.nodes().localNodeMaster()) { - logger.debug("Executing trial license request"); registerTrialLicense(request); } else { DiscoveryNode masterNode = currentState.nodes().masterNode(); if (masterNode != null) { - logger.debug("Sending trial license request to master"); transportService.sendRequest(masterNode, REGISTER_TRIAL_LICENSE_ACTION_NAME, request, EmptyTransportResponseHandler.INSTANCE_SAME); } else { @@ -586,12 +580,12 @@ public class LicensesService extends AbstractLifecycleComponent return false; } } - } else { + } else if (logger.isDebugEnabled()) { // notify feature as clusterChangedEvent may not happen // as no trial or signed license has been found for feature logger.debug("Calling notifyFeaturesAndScheduleNotification [no trial license spec provided]"); } - } else { + } else if (logger.isDebugEnabled()) { // signed license already found for the new registered // feature, notify feature on registration logger.debug("Calling notifyFeaturesAndScheduleNotification [signed/trial license available]"); @@ -607,7 +601,6 @@ public class LicensesService extends AbstractLifecycleComponent if ((featureLicense = effectiveLicenses.get(feature)) != null) { return featureLicense.expiryDate(); } - logger.debug("no effective license for " + feature); return -1l; } @@ -653,7 +646,9 @@ public class LicensesService extends AbstractLifecycleComponent try { final TimeValue delay = TimeValue.timeValueMillis(nextScheduleDelay); scheduledNotifications.add(threadPool.schedule(delay, executorName(), new LicensingClientNotificationJob())); - logger.debug("Scheduling next notification after: " + delay); + if (logger.isDebugEnabled()) { + logger.debug("Scheduling next notification after: " + delay); + } } catch (EsRejectedExecutionException ex) { logger.debug("Couldn't re-schedule licensing client notification job", ex); } @@ -679,7 +674,7 @@ public class LicensesService extends AbstractLifecycleComponent if (!currentClusterState.blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK)) { LicensesMetaData currentLicensesMetaData = currentClusterState.metaData().custom(LicensesMetaData.TYPE); notifyFeaturesAndScheduleNotification(currentLicensesMetaData); - } else { + } else if (logger.isDebugEnabled()) { logger.debug("skip notification [STATE_NOT_RECOVERED_BLOCK]"); } } @@ -734,15 +729,19 @@ public class LicensesService extends AbstractLifecycleComponent private void enableFeatureIfNeeded() { if (enabled.compareAndSet(false, true)) { - logger.debug("feature: " + feature + " calling onEnabled"); listener.onEnabled(); + if (logger.isDebugEnabled()) { + logger.debug("feature: " + feature + " calling onEnabled"); + } } } private void disableFeatureIfNeeded() { if (enabled.compareAndSet(true, false)) { - logger.debug("feature: " + feature + " calling onDisabled"); listener.onDisabled(); + if (logger.isDebugEnabled()) { + logger.debug("feature: " + feature + " calling onDisabled"); + } } }