From dcae5fb5f0dcc1c97bdb3df0ba870c8cbc95e073 Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 9 Nov 2015 11:04:42 -0500 Subject: [PATCH] ensure no operation is blocked before initial license notification closes elastic/elasticsearch#906 update comment Original commit: elastic/x-pack-elasticsearch@0bd788720f2d020ba904cfe03a262c4377da1d13 --- .../shield/license/ShieldLicenseState.java | 5 ++-- .../shield/license/ShieldLicensee.java | 24 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java b/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java index 0fbb7602e14..5815014bf45 100644 --- a/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java +++ b/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicenseState.java @@ -16,8 +16,9 @@ import org.elasticsearch.license.plugin.core.Licensee.Status; */ public class ShieldLicenseState { - // if we start disabled then we can emit false disabled messages and block legitimate requests... - protected volatile Status status = new Status(OperationMode.TRIAL, LicenseState.ENABLED); + // we initialize the licensee status to enabled with trial operation mode to ensure no + // legitimate requests are blocked before initial license plugin notification + protected volatile Status status = Status.ENABLED; /** * @return true if the license allows for security features to be enabled (authc, authz, ip filter, audit, etc) diff --git a/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java b/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java index 797c4159092..32ea9a70b09 100644 --- a/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java +++ b/shield/src/main/java/org/elasticsearch/shield/license/ShieldLicensee.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; -import org.elasticsearch.license.core.License.OperationMode; import org.elasticsearch.license.plugin.core.*; import org.elasticsearch.shield.ShieldPlugin; @@ -25,16 +24,16 @@ public class ShieldLicensee extends AbstractLicenseeComponent im @Inject public ShieldLicensee(Settings settings, LicenseeRegistry clientService, ShieldLicenseState shieldLicenseState) { super(settings, ShieldPlugin.NAME, clientService); - add(new Listener() { - @Override - public void onChange(Status status) { - shieldLicenseState.updateStatus(status); - } - }); this.shieldLicenseState = shieldLicenseState; this.isTribeNode = settings.getGroups("tribe", true).isEmpty() == false; } + @Override + public void onChange(Status status) { + super.onChange(status); + shieldLicenseState.updateStatus(status); + } + @Override public String[] expirationMessages() { return new String[] { @@ -74,12 +73,11 @@ public class ShieldLicensee extends AbstractLicenseeComponent im } @Override - protected void doStart() throws ElasticsearchException {; - if (isTribeNode) { - //TODO currently we disable licensing on tribe node. remove this once es core supports merging cluster - this.status = new Status(OperationMode.TRIAL, LicenseState.ENABLED); - shieldLicenseState.updateStatus(status); - } else { + protected void doStart() throws ElasticsearchException { + // we rely on the initial licensee state to be enabled with trial operation mode + // to ensure no operation is blocked due to not registering the licensee on a + // tribe node + if (!isTribeNode) { super.doStart(); } }