Skip to content

Commit 8ef5581

Browse files
authored
Remove license_mode from Licensing codebase (#93798)
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.
1 parent cf80784 commit 8ef5581

File tree

9 files changed

+6
-450
lines changed

9 files changed

+6
-450
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/License.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static LicenseType resolve(String name) {
9393
case "basic" -> BASIC;
9494
case "standard" -> STANDARD;
9595
case "silver", "gold" -> GOLD;
96-
case "platinum", "cloud_internal", "internal" -> // bwc for 1.x subscription_type field
96+
case "platinum", "internal" -> // bwc for 1.x subscription_type field
9797
PLATINUM;
9898
case "enterprise" -> ENTERPRISE;
9999
default -> throw new IllegalArgumentException("unknown license type [" + name + "]");
@@ -358,42 +358,12 @@ public String signature() {
358358
}
359359

360360
/**
361-
* @return the operation mode of the license as computed from the license type or from
362-
* the license mode file
361+
* @return the operation mode of the license as computed from the license type
363362
*/
364363
public OperationMode operationMode() {
365-
synchronized (this) {
366-
if (canReadOperationModeFromFile() && operationModeFileWatcher != null) {
367-
return operationModeFileWatcher.getCurrentOperationMode();
368-
}
369-
}
370364
return operationMode;
371365
}
372366

373-
private boolean canReadOperationModeFromFile() {
374-
return type.equals("cloud_internal");
375-
}
376-
377-
private volatile OperationModeFileWatcher operationModeFileWatcher;
378-
379-
/**
380-
* Sets the operation mode file watcher for the license and initializes the
381-
* file watcher when the license type allows to override operation mode from file
382-
*/
383-
public synchronized void setOperationModeFileWatcher(final OperationModeFileWatcher operationModeFileWatcher) {
384-
this.operationModeFileWatcher = operationModeFileWatcher;
385-
if (canReadOperationModeFromFile()) {
386-
this.operationModeFileWatcher.init();
387-
}
388-
}
389-
390-
/**
391-
* Removes operation mode file watcher, so unused license objects can be gc'ed
392-
*/
393-
public synchronized void removeOperationModeFileWatcher() {
394-
this.operationModeFileWatcher = null;
395-
}
396-
397367
private void validate() {
398368
if (issuer == null) {
399369
throw new IllegalStateException("issuer can not be null");

x-pack/plugin/core/src/main/java/org/elasticsearch/license/LicenseService.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@
3131
import org.elasticsearch.core.Nullable;
3232
import org.elasticsearch.core.SuppressForbidden;
3333
import org.elasticsearch.core.TimeValue;
34-
import org.elasticsearch.env.Environment;
3534
import org.elasticsearch.gateway.GatewayService;
3635
import org.elasticsearch.protocol.xpack.XPackInfoResponse;
3736
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
3837
import org.elasticsearch.protocol.xpack.license.LicensesStatus;
3938
import org.elasticsearch.protocol.xpack.license.PutLicenseResponse;
4039
import org.elasticsearch.threadpool.ThreadPool;
41-
import org.elasticsearch.watcher.ResourceWatcherService;
4240
import org.elasticsearch.xpack.core.XPackPlugin;
4341
import org.elasticsearch.xpack.core.XPackSettings;
4442

@@ -120,11 +118,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
120118
private final SchedulerEngine scheduler;
121119
private final Clock clock;
122120

123-
/**
124-
* File watcher for operation mode changes
125-
*/
126-
private final OperationModeFileWatcher operationModeFileWatcher;
127-
128121
/**
129122
* Callbacks to notify relative to license expiry
130123
*/
@@ -157,8 +150,6 @@ public LicenseService(
157150
ThreadPool threadPool,
158151
ClusterService clusterService,
159152
Clock clock,
160-
Environment env,
161-
ResourceWatcherService resourceWatcherService,
162153
XPackLicenseState licenseState
163154
) {
164155
this.settings = settings;
@@ -167,12 +158,6 @@ public LicenseService(
167158
this.scheduler = new SchedulerEngine(settings, clock);
168159
this.licenseState = licenseState;
169160
this.allowedLicenseTypes = ALLOWED_LICENSE_TYPES_SETTING.get(settings);
170-
this.operationModeFileWatcher = new OperationModeFileWatcher(
171-
resourceWatcherService,
172-
XPackPlugin.resolveConfigFile(env, "license_mode"),
173-
logger,
174-
() -> updateLicenseState(getLicensesMetadata())
175-
);
176161
this.scheduler.register(this);
177162
populateExpirationCallbacks();
178163

@@ -561,12 +546,6 @@ public void clusterChanged(ClusterChangedEvent event) {
561546
}
562547
}
563548

564-
private void updateLicenseState(LicensesMetadata licensesMetadata) {
565-
if (licensesMetadata != null) {
566-
updateLicenseState(getLicense(licensesMetadata));
567-
}
568-
}
569-
570549
protected static String getExpiryWarning(long licenseExpiryDate, long currentTime) {
571550
final long diff = licenseExpiryDate - currentTime;
572551
if (LICENSE_EXPIRATION_WARNING_PERIOD.getMillis() > diff) {
@@ -622,7 +601,6 @@ private void onUpdate(final LicensesMetadata currentLicensesMetadata) {
622601
final License previousLicense = currentLicenseHolder.get();
623602
if (license.equals(previousLicense) == false) {
624603
currentLicenseHolder.set(license);
625-
license.setOperationModeFileWatcher(operationModeFileWatcher);
626604
scheduler.add(new SchedulerEngine.Job(LICENSE_JOB, nextLicenseCheck(license)));
627605
for (ExpirationCallback expirationCallback : expirationCallbacks) {
628606
scheduler.add(
@@ -632,10 +610,6 @@ private void onUpdate(final LicensesMetadata currentLicensesMetadata) {
632610
)
633611
);
634612
}
635-
if (previousLicense != null) {
636-
// remove operationModeFileWatcher to gc the old license object
637-
previousLicense.removeOperationModeFileWatcher();
638-
}
639613
logger.info("license [{}] mode [{}] - valid", license.uid(), license.operationMode().name().toLowerCase(Locale.ROOT));
640614
}
641615
updateLicenseState(license);

x-pack/plugin/core/src/main/java/org/elasticsearch/license/OperationModeFileWatcher.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,7 @@ public Collection<Object> createComponents(
312312
List<Object> components = new ArrayList<>();
313313

314314
final SSLService sslService = createSSLService(environment, resourceWatcherService);
315-
setLicenseService(
316-
new LicenseService(settings, threadPool, clusterService, getClock(), environment, resourceWatcherService, getLicenseState())
317-
);
315+
setLicenseService(new LicenseService(settings, threadPool, clusterService, getClock(), getLicenseState()));
318316

319317
setEpochMillisSupplier(threadPool::absoluteTimeInMillis);
320318

x-pack/plugin/core/src/test/java/org/elasticsearch/license/AbstractLicenseServiceTestCase.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import org.elasticsearch.test.ESTestCase;
2121
import org.elasticsearch.threadpool.TestThreadPool;
2222
import org.elasticsearch.threadpool.ThreadPool;
23-
import org.elasticsearch.watcher.ResourceWatcherService;
2423
import org.elasticsearch.xpack.core.XPackPlugin;
2524
import org.elasticsearch.xpack.core.watcher.watch.ClockMock;
2625
import org.junit.After;
2726
import org.junit.Before;
2827

29-
import java.nio.file.Path;
3028
import java.util.stream.Stream;
3129

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

3937
protected LicenseService licenseService;
4038
protected ClusterService clusterService;
41-
protected ResourceWatcherService resourceWatcherService;
4239
protected ClockMock clock;
4340
protected DiscoveryNodes discoveryNodes;
4441
protected Environment environment;
@@ -50,7 +47,6 @@ public void init() throws Exception {
5047
clusterService = mock(ClusterService.class);
5148
clock = ClockMock.frozen();
5249
discoveryNodes = mock(DiscoveryNodes.class);
53-
resourceWatcherService = mock(ResourceWatcherService.class);
5450
environment = mock(Environment.class);
5551
threadPool = new TestThreadPool("license-test");
5652
}
@@ -65,11 +61,9 @@ protected void setInitialState(License license, XPackLicenseState licenseState,
6561
}
6662

6763
protected void setInitialState(License license, XPackLicenseState licenseState, Settings settings, String selfGeneratedType) {
68-
Path tempDir = createTempDir();
69-
when(environment.configFile()).thenReturn(tempDir);
7064
licenseType = selfGeneratedType;
7165
settings = Settings.builder().put(settings).put(LicenseService.SELF_GENERATED_LICENSE_TYPE.getKey(), licenseType).build();
72-
licenseService = new LicenseService(settings, threadPool, clusterService, clock, environment, resourceWatcherService, licenseState);
66+
licenseService = new LicenseService(settings, threadPool, clusterService, clock, licenseState);
7367
ClusterState state = mock(ClusterState.class);
7468
final ClusterBlocks noBlock = ClusterBlocks.builder().build();
7569
when(state.blocks()).thenReturn(noBlock);

x-pack/plugin/core/src/test/java/org/elasticsearch/license/LicenseOperationModeUpdateTests.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)