-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-introduce LicenseService as an interface (#94646)
This commit introduces an interface and contract for the license service . The contract is split into a read only interface (parent) and mutable interface (sub interface). Attempts are made to avoid leaking implementation details in the interface. As a result there are a couple places early in the lifecycle where we need to intanceof check and downcast to avoid a leaky contract but those are special cases. Usage of the interface should generally be constrained to @Inject the LicenseService and call getXPackLicenseState() as input to the licensed feature check, or to inject the service into transport actions. The implementation is now wired in via the new PluginComponentBinding which allows plugin components, which are interfaces, to be @Inject to the relevant actions. This commit builds on #94171 #94347 #94261 #94566
- Loading branch information
1 parent
bec25f0
commit f4fd953
Showing
33 changed files
with
331 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.license; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.common.component.LifecycleComponent; | ||
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse; | ||
|
||
/** | ||
* Interface to read the current license. Consumers should generally not need to read the license directly and should instead | ||
* prefer {@link XPackLicenseState} and/or {@link LicensedFeature} to make license decisions. | ||
* <b>This interface is not intended to be implemented by alternative implementations and exists for internal use only.</b> | ||
*/ | ||
public interface LicenseService extends LifecycleComponent { | ||
|
||
/** | ||
* Get the current license. Reading the license directly should generally be avoided and | ||
* license decisions should generally prefer {@link XPackLicenseState} and/or {@link LicensedFeature}. | ||
* @return the current license, null or {@link LicensesMetadata#LICENSE_TOMBSTONE} if no license is available. | ||
*/ | ||
License getLicense(); | ||
|
||
/** | ||
* Interface to update the current license. | ||
* <b>This interface is not intended to be implemented by alternative implementations and exists for internal use only.</b> | ||
*/ | ||
interface MutableLicenseService extends LicenseService, LifecycleComponent { | ||
|
||
/** | ||
* Creates or updates the current license as defined by the request. | ||
*/ | ||
void registerLicense(PutLicenseRequest request, ActionListener<PutLicenseResponse> listener); | ||
|
||
/** | ||
* Removes the current license. Implementations should remove the current license and ensure that attempts to read returns | ||
* {@link LicensesMetadata#LICENSE_TOMBSTONE} if a license was removed. Additionally the {@link XPackLicenseState} must be updated. | ||
*/ | ||
void removeLicense(ActionListener<? extends AcknowledgedResponse> listener); | ||
|
||
/** | ||
* Installs a basic license. | ||
*/ | ||
void startBasicLicense(PostStartBasicRequest request, ActionListener<PostStartBasicResponse> listener); | ||
|
||
/** | ||
* Installs a trial license. | ||
*/ | ||
void startTrialLicense(PostStartTrialRequest request, ActionListener<PostStartTrialResponse> listener); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.