From 0b7257271118d591f165eb8f288f311b74cc3739 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Fri, 17 Oct 2014 10:35:17 -0400 Subject: [PATCH] minor fixes Original commit: elastic/x-pack-elasticsearch@59fcb1728fd2d9355ef7e14dcbe3431cbf9afc57 --- .../action/put/TransportPutLicenseAction.java | 21 +++++++++--------- .../plugin/core/LicensesManagerService.java | 2 +- .../license/plugin/core/LicensesService.java | 22 ++++++++++++------- 3 files changed, 25 insertions(+), 20 deletions(-) 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 27694c6f670..3f9557aa711 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 @@ -59,17 +59,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio @Override protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener listener) throws ElasticsearchException { final PutLicenseRequestHolder requestHolder = new PutLicenseRequestHolder(request, "put licenses []"); - LicensesStatus status = licensesManagerService.checkLicenses(request.license()); - switch (status) { - case VALID: - break; - case INVALID: - throw new ElasticsearchLicenseException("Found Invalid License(s)"); - case EXPIRED: - throw new ElasticsearchLicenseException("Found Expired License(s)"); - } - - licensesManagerService.registerLicenses(requestHolder, new ActionListener() { + LicensesStatus status = licensesManagerService.registerLicenses(requestHolder, new ActionListener() { @Override public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { listener.onResponse(new PutLicenseResponse(clusterStateUpdateResponse.isAcknowledged())); @@ -80,6 +70,15 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio listener.onFailure(e); } }); + + switch (status) { + case VALID: + return; + case INVALID: + throw new ElasticsearchLicenseException("Found Invalid License(s)"); + case EXPIRED: + throw new ElasticsearchLicenseException("Found Expired License(s)"); + } } } 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 776ca6479e3..836db9eb73b 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesManagerService.java @@ -17,7 +17,7 @@ import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRe @ImplementedBy(LicensesService.class) public interface LicensesManagerService { - public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener listener); + public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener listener); public void unregisterLicenses(final DeleteLicenseRequestHolder requestHolder, final ActionListener listener); 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 db5ff02163f..6b269eedf9c 100644 --- a/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -47,11 +47,11 @@ import static org.elasticsearch.license.plugin.core.trial.TrialLicenses.TrialLic import static org.elasticsearch.license.plugin.core.trial.TrialLicensesBuilder.trialLicensesBuilder; /** - * Service responsible for maintaining and providing access to licenses on nodes. + * Service responsible for managing {@link org.elasticsearch.license.plugin.core.LicensesMetaData} + * Interfaces through which this is exposed are: + * - LicensesManagerService - responsible for adding/deleting signed licenses + * - LicensesClientService - allow interested plugins (features) to register to licensing notifications * - * TODO: Work in progress: - * - implement logic in clusterChanged - * - interface with LicenseManager */ @Singleton public class LicensesService extends AbstractLifecycleComponent implements ClusterStateListener, LicensesManagerService, LicensesClientService { @@ -81,9 +81,17 @@ public class LicensesService extends AbstractLifecycleComponent * and if it was successful it adds the license to cluster metadata. */ @Override - public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener listener) { + public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener listener) { final PutLicenseRequest request = requestHolder.request; final ESLicenses newLicenses = request.license(); + LicensesStatus status = checkLicenses(newLicenses); + switch (status) { + case VALID: + break; + case INVALID: + case EXPIRED: + return status; + } clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask(request, listener) { @Override protected ClusterStateUpdateResponse newResponse(boolean acknowledged) { @@ -116,7 +124,7 @@ public class LicensesService extends AbstractLifecycleComponent return builder.build(); } }); - + return LicensesStatus.VALID; } @Override @@ -445,14 +453,12 @@ public class LicensesService extends AbstractLifecycleComponent private void enableFeatureIfNeeded() { if (toggle.compareAndSet(false, true) || initialState.compareAndSet(true, false)) { listener.onEnabled(); - toggle.set(true); } } private void disableFeatureIfNeeded() { if (toggle.compareAndSet(true, false) || initialState.compareAndSet(true, false)) { listener.onDisabled(); - toggle.set(false); } } }