Skip to content

Commit

Permalink
Remove license_mode from Licensing codebase (#93798)
Browse files Browse the repository at this point in the history
The license_mode / file configuration has never been used and
represents a way to configure the license that is not compatible
with future plans. This commit removes the unused functionality.
  • Loading branch information
jakelandis committed Feb 21, 2023
1 parent cf80784 commit 8ef5581
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 450 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static LicenseType resolve(String name) {
case "basic" -> BASIC;
case "standard" -> STANDARD;
case "silver", "gold" -> GOLD;
case "platinum", "cloud_internal", "internal" -> // bwc for 1.x subscription_type field
case "platinum", "internal" -> // bwc for 1.x subscription_type field
PLATINUM;
case "enterprise" -> ENTERPRISE;
default -> throw new IllegalArgumentException("unknown license type [" + name + "]");
Expand Down Expand Up @@ -358,42 +358,12 @@ public String signature() {
}

/**
* @return the operation mode of the license as computed from the license type or from
* the license mode file
* @return the operation mode of the license as computed from the license type
*/
public OperationMode operationMode() {
synchronized (this) {
if (canReadOperationModeFromFile() && operationModeFileWatcher != null) {
return operationModeFileWatcher.getCurrentOperationMode();
}
}
return operationMode;
}

private boolean canReadOperationModeFromFile() {
return type.equals("cloud_internal");
}

private volatile OperationModeFileWatcher operationModeFileWatcher;

/**
* Sets the operation mode file watcher for the license and initializes the
* file watcher when the license type allows to override operation mode from file
*/
public synchronized void setOperationModeFileWatcher(final OperationModeFileWatcher operationModeFileWatcher) {
this.operationModeFileWatcher = operationModeFileWatcher;
if (canReadOperationModeFromFile()) {
this.operationModeFileWatcher.init();
}
}

/**
* Removes operation mode file watcher, so unused license objects can be gc'ed
*/
public synchronized void removeOperationModeFileWatcher() {
this.operationModeFileWatcher = null;
}

private void validate() {
if (issuer == null) {
throw new IllegalStateException("issuer can not be null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.env.Environment;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.XPackSettings;

Expand Down Expand Up @@ -120,11 +118,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
private final SchedulerEngine scheduler;
private final Clock clock;

/**
* File watcher for operation mode changes
*/
private final OperationModeFileWatcher operationModeFileWatcher;

/**
* Callbacks to notify relative to license expiry
*/
Expand Down Expand Up @@ -157,8 +150,6 @@ public LicenseService(
ThreadPool threadPool,
ClusterService clusterService,
Clock clock,
Environment env,
ResourceWatcherService resourceWatcherService,
XPackLicenseState licenseState
) {
this.settings = settings;
Expand All @@ -167,12 +158,6 @@ public LicenseService(
this.scheduler = new SchedulerEngine(settings, clock);
this.licenseState = licenseState;
this.allowedLicenseTypes = ALLOWED_LICENSE_TYPES_SETTING.get(settings);
this.operationModeFileWatcher = new OperationModeFileWatcher(
resourceWatcherService,
XPackPlugin.resolveConfigFile(env, "license_mode"),
logger,
() -> updateLicenseState(getLicensesMetadata())
);
this.scheduler.register(this);
populateExpirationCallbacks();

Expand Down Expand Up @@ -561,12 +546,6 @@ public void clusterChanged(ClusterChangedEvent event) {
}
}

private void updateLicenseState(LicensesMetadata licensesMetadata) {
if (licensesMetadata != null) {
updateLicenseState(getLicense(licensesMetadata));
}
}

protected static String getExpiryWarning(long licenseExpiryDate, long currentTime) {
final long diff = licenseExpiryDate - currentTime;
if (LICENSE_EXPIRATION_WARNING_PERIOD.getMillis() > diff) {
Expand Down Expand Up @@ -622,7 +601,6 @@ private void onUpdate(final LicensesMetadata currentLicensesMetadata) {
final License previousLicense = currentLicenseHolder.get();
if (license.equals(previousLicense) == false) {
currentLicenseHolder.set(license);
license.setOperationModeFileWatcher(operationModeFileWatcher);
scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, nextLicenseCheck(license)));
for (ExpirationCallback expirationCallback : expirationCallbacks) {
scheduler.add(
Expand All @@ -632,10 +610,6 @@ private void onUpdate(final LicensesMetadata currentLicensesMetadata) {
)
);
}
if (previousLicense != null) {
// remove operationModeFileWatcher to gc the old license object
previousLicense.removeOperationModeFileWatcher();
}
logger.info("license [{}] mode [{}] - valid", license.uid(), license.operationMode().name().toLowerCase(Locale.ROOT));
}
updateLicenseState(license);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ public Collection<Object> createComponents(
List<Object> components = new ArrayList<>();

final SSLService sslService = createSSLService(environment, resourceWatcherService);
setLicenseService(
new LicenseService(settings, threadPool, clusterService, getClock(), environment, resourceWatcherService, getLicenseState())
);
setLicenseService(new LicenseService(settings, threadPool, clusterService, getClock(), getLicenseState()));

setEpochMillisSupplier(threadPool::absoluteTimeInMillis);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.TestThreadPool;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
import org.elasticsearch.xpack.core.XPackPlugin;
import org.elasticsearch.xpack.core.watcher.watch.ClockMock;
import org.junit.After;
import org.junit.Before;

import java.nio.file.Path;
import java.util.stream.Stream;

import static java.util.Collections.emptySet;
Expand All @@ -38,7 +36,6 @@ public abstract class AbstractLicenseServiceTestCase extends ESTestCase {

protected LicenseService licenseService;
protected ClusterService clusterService;
protected ResourceWatcherService resourceWatcherService;
protected ClockMock clock;
protected DiscoveryNodes discoveryNodes;
protected Environment environment;
Expand All @@ -50,7 +47,6 @@ public void init() throws Exception {
clusterService = mock(ClusterService.class);
clock = ClockMock.frozen();
discoveryNodes = mock(DiscoveryNodes.class);
resourceWatcherService = mock(ResourceWatcherService.class);
environment = mock(Environment.class);
threadPool = new TestThreadPool("license-test");
}
Expand All @@ -65,11 +61,9 @@ protected void setInitialState(License license, XPackLicenseState licenseState,
}

protected void setInitialState(License license, XPackLicenseState licenseState, Settings settings, String selfGeneratedType) {
Path tempDir = createTempDir();
when(environment.configFile()).thenReturn(tempDir);
licenseType = selfGeneratedType;
settings = Settings.builder().put(settings).put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), licenseType).build();
licenseService = new LicenseService(settings, threadPool, clusterService, clock, environment, resourceWatcherService, licenseState);
licenseService = new LicenseService(settings, threadPool, clusterService, clock, licenseState);
ClusterState state = mock(ClusterState.class);
final ClusterBlocks noBlock = ClusterBlocks.builder().build();
when(state.blocks()).thenReturn(noBlock);
Expand Down

This file was deleted.

0 comments on commit 8ef5581

Please sign in to comment.