LicensesService cleanup

Original commit: elastic/x-pack-elasticsearch@348a2a6ca9
This commit is contained in:
Igor Motov 2014-10-30 17:14:43 -04:00
parent 6d6f196af6
commit d518cd86db
1 changed files with 36 additions and 41 deletions

View File

@ -94,7 +94,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
this.threadPool = threadPool;
this.transportService = transportService;
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());
}
}
@ -107,8 +107,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
final PutLicenseRequest request = requestHolder.request;
final Set<ESLicense> newLicenses = Sets.newHashSet(request.licenses());
LicensesStatus status = checkLicenses(newLicenses);
switch (status) {
case VALID:
if (status == LicensesStatus.VALID) {
clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask<LicensesUpdateResponse>(request, listener) {
@Override
protected LicensesUpdateResponse newResponse(boolean acknowledged) {
@ -132,11 +131,8 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
return ClusterState.builder(currentState).metaData(mdBuilder).build();
}
});
break;
case INVALID:
case EXPIRED:
} else {
listener.onResponse(new LicensesUpdateResponse(true, status));
break;
}
}
@ -168,7 +164,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
MetaData metaData = currentState.metaData();
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
LicensesMetaData currentLicenses = metaData.custom(LicensesMetaData.TYPE);
final LicensesWrapper licensesWrapper = LicensesWrapper.wrap(currentLicenses);
@ -179,15 +174,16 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
licensesToDelete.add(license);
}
}
if (!licensesToDelete.isEmpty()) {
Set<ESLicense> reducedLicenses = Sets.difference(currentSignedLicenses, licensesToDelete);
if (reducedLicenses.size() != currentSignedLicenses.size()) {
Set<String> newSignatures = licenseManager.toSignatures(reducedLicenses);
LicensesMetaData newLicensesMetaData = new LicensesMetaData(newSignatures, licensesWrapper.encodedTrialLicenses);
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicensesMetaData);
} else {
mdBuilder.putCustom(LicensesMetaData.TYPE, currentLicenses);
}
return ClusterState.builder(currentState).metaData(mdBuilder).build();
} else {
return currentState;
}
}
});
}
@ -334,12 +330,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
@Override
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);
// cancel all notifications
@ -360,6 +350,12 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
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}:
* - tries to register any {@link #pendingListeners} by calling {@link #registeredListeners}
@ -400,7 +396,6 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
}
}
// notify all interested plugins
// Change to debug
if (event.previousState().blocks().hasGlobalBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK) || addedNewRegisteredListener) {