parent
d0a5aea0e9
commit
0b72572711
|
@ -59,17 +59,7 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
||||||
@Override
|
@Override
|
||||||
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> listener) throws ElasticsearchException {
|
protected void masterOperation(final PutLicenseRequest request, ClusterState state, final ActionListener<PutLicenseResponse> listener) throws ElasticsearchException {
|
||||||
final PutLicenseRequestHolder requestHolder = new PutLicenseRequestHolder(request, "put licenses []");
|
final PutLicenseRequestHolder requestHolder = new PutLicenseRequestHolder(request, "put licenses []");
|
||||||
LicensesStatus status = licensesManagerService.checkLicenses(request.license());
|
LicensesStatus status = licensesManagerService.registerLicenses(requestHolder, new ActionListener<ClusterStateUpdateResponse>() {
|
||||||
switch (status) {
|
|
||||||
case VALID:
|
|
||||||
break;
|
|
||||||
case INVALID:
|
|
||||||
throw new ElasticsearchLicenseException("Found Invalid License(s)");
|
|
||||||
case EXPIRED:
|
|
||||||
throw new ElasticsearchLicenseException("Found Expired License(s)");
|
|
||||||
}
|
|
||||||
|
|
||||||
licensesManagerService.registerLicenses(requestHolder, new ActionListener<ClusterStateUpdateResponse>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
|
public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) {
|
||||||
listener.onResponse(new PutLicenseResponse(clusterStateUpdateResponse.isAcknowledged()));
|
listener.onResponse(new PutLicenseResponse(clusterStateUpdateResponse.isAcknowledged()));
|
||||||
|
@ -80,6 +70,15 @@ public class TransportPutLicenseAction extends TransportMasterNodeOperationActio
|
||||||
listener.onFailure(e);
|
listener.onFailure(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
case VALID:
|
||||||
|
return;
|
||||||
|
case INVALID:
|
||||||
|
throw new ElasticsearchLicenseException("Found Invalid License(s)");
|
||||||
|
case EXPIRED:
|
||||||
|
throw new ElasticsearchLicenseException("Found Expired License(s)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import static org.elasticsearch.license.plugin.core.LicensesService.PutLicenseRe
|
||||||
@ImplementedBy(LicensesService.class)
|
@ImplementedBy(LicensesService.class)
|
||||||
public interface LicensesManagerService {
|
public interface LicensesManagerService {
|
||||||
|
|
||||||
public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
||||||
|
|
||||||
public void unregisterLicenses(final DeleteLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
public void unregisterLicenses(final DeleteLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener);
|
||||||
|
|
||||||
|
|
|
@ -47,11 +47,11 @@ import static org.elasticsearch.license.plugin.core.trial.TrialLicenses.TrialLic
|
||||||
import static org.elasticsearch.license.plugin.core.trial.TrialLicensesBuilder.trialLicensesBuilder;
|
import static org.elasticsearch.license.plugin.core.trial.TrialLicensesBuilder.trialLicensesBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service responsible for maintaining and providing access to licenses on nodes.
|
* Service responsible for managing {@link org.elasticsearch.license.plugin.core.LicensesMetaData}
|
||||||
|
* Interfaces through which this is exposed are:
|
||||||
|
* - LicensesManagerService - responsible for adding/deleting signed licenses
|
||||||
|
* - LicensesClientService - allow interested plugins (features) to register to licensing notifications
|
||||||
*
|
*
|
||||||
* TODO: Work in progress:
|
|
||||||
* - implement logic in clusterChanged
|
|
||||||
* - interface with LicenseManager
|
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class LicensesService extends AbstractLifecycleComponent<LicensesService> implements ClusterStateListener, LicensesManagerService, LicensesClientService {
|
public class LicensesService extends AbstractLifecycleComponent<LicensesService> implements ClusterStateListener, LicensesManagerService, LicensesClientService {
|
||||||
|
@ -81,9 +81,17 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
* and if it was successful it adds the license to cluster metadata.
|
* and if it was successful it adds the license to cluster metadata.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener) {
|
public LicensesStatus registerLicenses(final PutLicenseRequestHolder requestHolder, final ActionListener<ClusterStateUpdateResponse> listener) {
|
||||||
final PutLicenseRequest request = requestHolder.request;
|
final PutLicenseRequest request = requestHolder.request;
|
||||||
final ESLicenses newLicenses = request.license();
|
final ESLicenses newLicenses = request.license();
|
||||||
|
LicensesStatus status = checkLicenses(newLicenses);
|
||||||
|
switch (status) {
|
||||||
|
case VALID:
|
||||||
|
break;
|
||||||
|
case INVALID:
|
||||||
|
case EXPIRED:
|
||||||
|
return status;
|
||||||
|
}
|
||||||
clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(request, listener) {
|
clusterService.submitStateUpdateTask(requestHolder.source, new AckedClusterStateUpdateTask<ClusterStateUpdateResponse>(request, listener) {
|
||||||
@Override
|
@Override
|
||||||
protected ClusterStateUpdateResponse newResponse(boolean acknowledged) {
|
protected ClusterStateUpdateResponse newResponse(boolean acknowledged) {
|
||||||
|
@ -116,7 +124,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return LicensesStatus.VALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -445,14 +453,12 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
private void enableFeatureIfNeeded() {
|
private void enableFeatureIfNeeded() {
|
||||||
if (toggle.compareAndSet(false, true) || initialState.compareAndSet(true, false)) {
|
if (toggle.compareAndSet(false, true) || initialState.compareAndSet(true, false)) {
|
||||||
listener.onEnabled();
|
listener.onEnabled();
|
||||||
toggle.set(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableFeatureIfNeeded() {
|
private void disableFeatureIfNeeded() {
|
||||||
if (toggle.compareAndSet(true, false) || initialState.compareAndSet(true, false)) {
|
if (toggle.compareAndSet(true, false) || initialState.compareAndSet(true, false)) {
|
||||||
listener.onDisabled();
|
listener.onDisabled();
|
||||||
toggle.set(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue