remove redundant license update response
Original commit: elastic/x-pack-elasticsearch@ef2aea8324
This commit is contained in:
parent
6ff8124640
commit
9a398b9413
|
@ -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.<String, String[]>emptyMap());
|
||||
}
|
||||
|
||||
public PutLicenseResponse(boolean acknowledged, LicensesStatus status, String acknowledgeHeader,
|
||||
Map<String, String[]> acknowledgeMessages) {
|
||||
super(acknowledged);
|
||||
|
|
|
@ -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<PutLicenseRequest, PutLicenseResponse> {
|
||||
|
||||
private final LicensesService licensesService;
|
||||
|
@ -53,18 +51,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeAction<PutLice
|
|||
@Override
|
||||
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse>
|
||||
listener) throws ElasticsearchException {
|
||||
licensesService.registerLicense(request, new ActionListener<LicensesUpdateResponse>() {
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<LicensesService>
|
|||
* 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<LicensesUpdateResponse> listener) {
|
||||
public void registerLicense(final PutLicenseRequest request, final ActionListener<PutLicenseResponse> 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<LicensesService>
|
|||
}
|
||||
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<LicensesUpdateResponse>(request, listener) {
|
||||
AckedClusterStateUpdateTask<PutLicenseResponse>(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<LicensesService>
|
|||
return TimeValue.timeValueHours(days * 24);
|
||||
}
|
||||
|
||||
public static class LicensesUpdateResponse extends ClusterStateUpdateResponse {
|
||||
private final LicensesStatus status;
|
||||
private final String acknowledgementHeader;
|
||||
private final Map<String, String[]> acknowledgeMessages;
|
||||
|
||||
public LicensesUpdateResponse(boolean acknowledged, LicensesStatus status) {
|
||||
this(acknowledged, status, null, Collections.<String, String[]>emptyMap());
|
||||
}
|
||||
|
||||
public LicensesUpdateResponse(boolean acknowledged, LicensesStatus status, String acknowledgementHeader,
|
||||
Map<String, String[]> acknowledgeMessages) {
|
||||
super(acknowledged);
|
||||
this.status = status;
|
||||
this.acknowledgeMessages = acknowledgeMessages;
|
||||
this.acknowledgementHeader = acknowledgementHeader;
|
||||
}
|
||||
|
||||
public LicensesStatus status() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String acknowledgementHeader() {
|
||||
return acknowledgementHeader;
|
||||
}
|
||||
|
||||
public Map<String, String[]> acknowledgeMessages() {
|
||||
return acknowledgeMessages;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove license from the cluster state metadata
|
||||
*/
|
||||
|
|
|
@ -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<LicensesStatus> status = new AtomicReference<>();
|
||||
licensesService.registerLicense(putLicenseRequest, new ActionListener<LicensesService.LicensesUpdateResponse>() {
|
||||
licensesService.registerLicense(putLicenseRequest, new ActionListener<PutLicenseResponse>() {
|
||||
@Override
|
||||
public void onResponse(LicensesService.LicensesUpdateResponse licensesUpdateResponse) {
|
||||
public void onResponse(PutLicenseResponse licensesUpdateResponse) {
|
||||
status.set(licensesUpdateResponse.status());
|
||||
latch.countDown();
|
||||
}
|
||||
|
|
|
@ -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<LicensesService.LicensesUpdateResponse> {
|
||||
private static class AssertingLicensesUpdateResponse implements ActionListener<PutLicenseResponse> {
|
||||
private final boolean expectedAcknowledgement;
|
||||
private final LicensesStatus expectedStatus;
|
||||
private final Map<String, String[]> 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()));
|
||||
|
|
Loading…
Reference in New Issue