LicensesService cleanup
Original commit: elastic/x-pack-elasticsearch@348a2a6ca9
This commit is contained in:
parent
6d6f196af6
commit
d518cd86db
|
@ -94,7 +94,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
this.transportService = transportService;
|
this.transportService = transportService;
|
||||||
this.lastObservedLicensesState = new AtomicReference<>(null);
|
this.lastObservedLicensesState = new AtomicReference<>(null);
|
||||||
if (DiscoveryNode.dataNode(settings) || DiscoveryNode.masterNode(settings)) {
|
if (DiscoveryNode.masterNode(settings)) {
|
||||||
transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler());
|
transportService.registerHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME, new RegisterTrialLicenseRequestHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,36 +107,32 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
final PutLicenseRequest request = requestHolder.request;
|
final PutLicenseRequest request = requestHolder.request;
|
||||||
final Set<ESLicense> newLicenses = Sets.newHashSet(request.licenses());
|
final Set<ESLicense> newLicenses = Sets.newHashSet(request.licenses());
|
||||||
LicensesStatus status = checkLicenses(newLicenses);
|
LicensesStatus status = checkLicenses(newLicenses);
|
||||||
switch (status) {
|
if (status == LicensesStatus.VALID) {
|
||||||
case VALID:
|
clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask<LicensesUpdateResponse>(request, listener) {
|
||||||
clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask<LicensesUpdateResponse>(request, listener) {
|
@Override
|
||||||
@Override
|
protected LicensesUpdateResponse newResponse(boolean acknowledged) {
|
||||||
protected LicensesUpdateResponse newResponse(boolean acknowledged) {
|
return new LicensesUpdateResponse(acknowledged, LicensesStatus.VALID);
|
||||||
return new LicensesUpdateResponse(acknowledged, LicensesStatus.VALID);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClusterState execute(ClusterState currentState) throws Exception {
|
public ClusterState execute(ClusterState currentState) throws Exception {
|
||||||
MetaData metaData = currentState.metaData();
|
MetaData metaData = currentState.metaData();
|
||||||
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
|
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
|
||||||
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
|
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
|
||||||
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
|
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
|
||||||
Set<String> newSignatures = licenseManager.toSignatures(newLicenses);
|
Set<String> newSignatures = licenseManager.toSignatures(newLicenses);
|
||||||
Set<String> newLicenseSignatures = Sets.union(licensesWrapper.signatures, newSignatures);
|
Set<String> newLicenseSignatures = Sets.union(licensesWrapper.signatures, newSignatures);
|
||||||
if (newLicenseSignatures.size() != licensesWrapper.signatures.size()) {
|
if (newLicenseSignatures.size() != licensesWrapper.signatures.size()) {
|
||||||
LicensesMetaData newLicensesMetaData = new LicensesMetaData(newLicenseSignatures, licensesWrapper.encodedTrialLicenses);
|
LicensesMetaData newLicensesMetaData = new LicensesMetaData(newLicenseSignatures, licensesWrapper.encodedTrialLicenses);
|
||||||
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetaData);
|
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetaData);
|
||||||
} else {
|
} else {
|
||||||
mdBuilder.putCustom(LicensesMetaData.TYPE, currentLicenses);
|
mdBuilder.putCustom(LicensesMetaData.TYPE, currentLicenses);
|
||||||
}
|
|
||||||
return ClusterState.builder(currentState).metaData(mdBuilder).build();
|
|
||||||
}
|
}
|
||||||
});
|
return ClusterState.builder(currentState).metaData(mdBuilder).build();
|
||||||
break;
|
}
|
||||||
case INVALID:
|
});
|
||||||
case EXPIRED:
|
} else {
|
||||||
listener.onResponse(new LicensesUpdateResponse(true, status));
|
listener.onResponse(new LicensesUpdateResponse(true, status));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +164,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
@Override
|
@Override
|
||||||
public ClusterState execute(ClusterState currentState) throws Exception {
|
public ClusterState execute(ClusterState currentState) throws Exception {
|
||||||
MetaData metaData = currentState.metaData();
|
MetaData metaData = currentState.metaData();
|
||||||
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
|
|
||||||
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
|
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
|
||||||
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
|
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
|
||||||
|
|
||||||
|
@ -179,15 +174,16 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
licensesToDelete.add(license);
|
licensesToDelete.add(license);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Set<ESLicense> reducedLicenses = Sets.difference(currentSignedLicenses, licensesToDelete);
|
if (!licensesToDelete.isEmpty()) {
|
||||||
if (reducedLicenses.size() != currentSignedLicenses.size()) {
|
Set<ESLicense> reducedLicenses = Sets.difference(currentSignedLicenses, licensesToDelete);
|
||||||
Set<String> newSignatures = licenseManager.toSignatures(reducedLicenses);
|
Set<String> newSignatures = licenseManager.toSignatures(reducedLicenses);
|
||||||
LicensesMetaData newLicensesMetaData = new LicensesMetaData(newSignatures, licensesWrapper.encodedTrialLicenses);
|
LicensesMetaData newLicensesMetaData = new LicensesMetaData(newSignatures, licensesWrapper.encodedTrialLicenses);
|
||||||
|
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
|
||||||
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetaData);
|
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetaData);
|
||||||
|
return ClusterState.builder(currentState).metaData(mdBuilder).build();
|
||||||
} else {
|
} else {
|
||||||
mdBuilder.putCustom(LicensesMetaData.TYPE, currentLicenses);
|
return currentState;
|
||||||
}
|
}
|
||||||
return ClusterState.builder(currentState).metaData(mdBuilder).build();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -334,12 +330,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws ElasticsearchException {
|
protected void doStop() throws ElasticsearchException {
|
||||||
// Should scheduledNotifications be cancelled on stop as well?
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doClose() throws ElasticsearchException {
|
|
||||||
logger.info("Closing LicensesService");
|
|
||||||
clusterService.remove(this);
|
clusterService.remove(this);
|
||||||
|
|
||||||
// cancel all notifications
|
// cancel all notifications
|
||||||
|
@ -360,6 +350,12 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
lastObservedLicensesState.set(null);
|
lastObservedLicensesState.set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doClose() throws ElasticsearchException {
|
||||||
|
logger.info("Closing LicensesService");
|
||||||
|
transportService.removeHandler(REGISTER_TRIAL_LICENSE_ACTION_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When there is no global block on {@link org.elasticsearch.gateway.GatewayService#STATE_NOT_RECOVERED_BLOCK}:
|
* When there is no global block on {@link org.elasticsearch.gateway.GatewayService#STATE_NOT_RECOVERED_BLOCK}:
|
||||||
* - tries to register any {@link #pendingListeners} by calling {@link #registeredListeners}
|
* - tries to register any {@link #pendingListeners} by calling {@link #registeredListeners}
|
||||||
|
@ -400,7 +396,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// notify all interested plugins
|
// notify all interested plugins
|
||||||
// Change to debug
|
// Change to debug
|
||||||
if (event.previousState().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || addedNewRegisteredListener) {
|
if (event.previousState().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || addedNewRegisteredListener) {
|
||||||
|
|
Loading…
Reference in New Issue