diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseResponse.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseResponse.java index 2803389b12a..ea0870924d4 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseResponse.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/PutLicenseResponse.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.license.plugin.core.LicensesStatus; import java.io.IOException; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -26,6 +27,10 @@ public class PutLicenseResponse extends AcknowledgedResponse implements ToXConte PutLicenseResponse() { } + public PutLicenseResponse(boolean acknowledged, LicensesStatus status) { + this(acknowledged, status, null, Collections.emptyMap()); + } + public PutLicenseResponse(boolean acknowledged, LicensesStatus status, String acknowledgeHeader, Map acknowledgeMessages) { super(acknowledged); diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java index 2a1063c446a..d527be2cf0c 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/action/put/TransportPutLicenseAction.java @@ -20,8 +20,6 @@ import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import static org.elasticsearch.license.plugin.core.LicensesService.LicensesUpdateResponse; - public class TransportPutLicenseAction extends TransportMasterNodeAction { private final LicensesService licensesService; @@ -53,18 +51,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeAction listener) throws ElasticsearchException { - licensesService.registerLicense(request, new ActionListener() { - @Override - public void onResponse(LicensesUpdateResponse licensesUpdateResponse) { - listener.onResponse(new PutLicenseResponse(licensesUpdateResponse.isAcknowledged(), licensesUpdateResponse.status(), - licensesUpdateResponse.acknowledgementHeader(), licensesUpdateResponse.acknowledgeMessages())); - } - - @Override - public void onFailure(Throwable e) { - listener.onFailure(e); - } - }); + licensesService.registerLicense(request, listener); } } diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java index 4368267727b..7714f1e1732 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -34,6 +34,7 @@ import org.elasticsearch.license.core.License; import org.elasticsearch.license.core.LicenseVerifier; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest; import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; +import org.elasticsearch.license.plugin.action.put.PutLicenseResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.EmptyTransportResponseHandler; import org.elasticsearch.transport.TransportChannel; @@ -46,7 +47,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -251,13 +251,13 @@ public class LicensesService extends AbstractLifecycleComponent * Registers new license in the cluster * Master only operation. Installs a new license on the master provided it is VALID */ - public void registerLicense(final PutLicenseRequest request, final ActionListener listener) { + public void registerLicense(final PutLicenseRequest request, final ActionListener listener) { final License newLicense = request.license(); final long now = System.currentTimeMillis(); if (!verifyLicense(newLicense) || newLicense.issueDate() > now) { - listener.onResponse(new LicensesUpdateResponse(true, LicensesStatus.INVALID)); + listener.onResponse(new PutLicenseResponse(true, LicensesStatus.INVALID)); } else if (newLicense.expiryDate() < now) { - listener.onResponse(new LicensesUpdateResponse(true, LicensesStatus.EXPIRED)); + listener.onResponse(new PutLicenseResponse(true, LicensesStatus.EXPIRED)); } else { if (!request.acknowledged()) { final LicensesMetaData currentMetaData = clusterService.state().metaData().custom(LicensesMetaData.TYPE); @@ -278,17 +278,17 @@ public class LicensesService extends AbstractLifecycleComponent } if (!acknowledgeMessages.isEmpty()) { // needs acknowledgement - listener.onResponse(new LicensesUpdateResponse(false, LicensesStatus.VALID, ACKNOWLEDGEMENT_HEADER, + listener.onResponse(new PutLicenseResponse(false, LicensesStatus.VALID, ACKNOWLEDGEMENT_HEADER, acknowledgeMessages)); return; } } } clusterService.submitStateUpdateTask("register license [" + newLicense.uid() + "]", new - AckedClusterStateUpdateTask(request, listener) { + AckedClusterStateUpdateTask(request, listener) { @Override - protected LicensesUpdateResponse newResponse(boolean acknowledged) { - return new LicensesUpdateResponse(acknowledged, LicensesStatus.VALID); + protected PutLicenseResponse newResponse(boolean acknowledged) { + return new PutLicenseResponse(acknowledged, LicensesStatus.VALID); } @Override @@ -317,36 +317,6 @@ public class LicensesService extends AbstractLifecycleComponent return TimeValue.timeValueHours(days * 24); } - public static class LicensesUpdateResponse extends ClusterStateUpdateResponse { - private final LicensesStatus status; - private final String acknowledgementHeader; - private final Map acknowledgeMessages; - - public LicensesUpdateResponse(boolean acknowledged, LicensesStatus status) { - this(acknowledged, status, null, Collections.emptyMap()); - } - - public LicensesUpdateResponse(boolean acknowledged, LicensesStatus status, String acknowledgementHeader, - Map acknowledgeMessages) { - super(acknowledged); - this.status = status; - this.acknowledgeMessages = acknowledgeMessages; - this.acknowledgementHeader = acknowledgementHeader; - } - - public LicensesStatus status() { - return status; - } - - public String acknowledgementHeader() { - return acknowledgementHeader; - } - - public Map acknowledgeMessages() { - return acknowledgeMessages; - } - } - /** * Remove license from the cluster state metadata */ diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java index 0dc69597a89..0d0f68ab8e4 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/TestUtils.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.license.core.License; import org.elasticsearch.license.licensor.LicenseSigner; import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; +import org.elasticsearch.license.plugin.action.put.PutLicenseResponse; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicensesService; import org.elasticsearch.license.plugin.core.LicensesStatus; @@ -138,9 +139,9 @@ public class TestUtils { PutLicenseRequest putLicenseRequest = new PutLicenseRequest().license(license); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference status = new AtomicReference<>(); - licensesService.registerLicense(putLicenseRequest, new ActionListener() { + licensesService.registerLicense(putLicenseRequest, new ActionListener() { @Override - public void onResponse(LicensesService.LicensesUpdateResponse licensesUpdateResponse) { + public void onResponse(PutLicenseResponse licensesUpdateResponse) { status.set(licensesUpdateResponse.status()); latch.countDown(); } diff --git a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java index aa5c9d70486..06f2582f2bc 100644 --- a/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java +++ b/elasticsearch/x-pack/license-plugin/src/test/java/org/elasticsearch/license/plugin/core/LicensesAcknowledgementTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.TestUtils; import org.elasticsearch.license.plugin.action.put.PutLicenseRequest; +import org.elasticsearch.license.plugin.action.put.PutLicenseResponse; import org.elasticsearch.test.ESSingleNodeTestCase; import java.util.Collections; @@ -128,7 +129,7 @@ public class LicensesAcknowledgementTests extends ESSingleNodeTestCase { licensesService.stop(); } - private static class AssertingLicensesUpdateResponse implements ActionListener { + private static class AssertingLicensesUpdateResponse implements ActionListener { private final boolean expectedAcknowledgement; private final LicensesStatus expectedStatus; private final Map expectedAckMessages; @@ -143,7 +144,7 @@ public class LicensesAcknowledgementTests extends ESSingleNodeTestCase { } @Override - public void onResponse(LicensesService.LicensesUpdateResponse licensesUpdateResponse) { + public void onResponse(PutLicenseResponse licensesUpdateResponse) { assertThat(licensesUpdateResponse.isAcknowledged(), equalTo(expectedAcknowledgement)); assertThat(licensesUpdateResponse.status(), equalTo(expectedStatus)); assertThat(licensesUpdateResponse.acknowledgeMessages().size(), equalTo(expectedAckMessages.size()));