Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste
static final Set<License.LicenseType> VALID_TRIAL_TYPES = Set.of(
License.LicenseType.GOLD, License.LicenseType.PLATINUM, License.LicenseType.ENTERPRISE, License.LicenseType.TRIAL);

/**
* Duration of grace period after a license has expired
*/
static final TimeValue GRACE_PERIOD_DURATION = days(7);

/**
* Period before the license expires when warning starts being added to the response header
*/
Expand Down Expand Up @@ -191,16 +186,9 @@ public void on(License license) {
logExpirationWarning(license.expiryDate(), false);
}
});
expirationCallbacks.add(new ExpirationCallback.Pre(days(0), days(7), TimeValue.timeValueMinutes(10)) {
@Override
public void on(License license) {
logExpirationWarning(license.expiryDate(), false);
}
});
expirationCallbacks.add(new ExpirationCallback.Post(days(0), null, TimeValue.timeValueMinutes(10)) {
@Override
public void on(License license) {
// logged when grace period begins
logExpirationWarning(license.expiryDate(), true);
}
});
Expand Down Expand Up @@ -485,22 +473,16 @@ protected void updateLicenseState(final License license, Version mostRecentTrial
}
if (license != null) {
long time = clock.millis();
boolean active;
final boolean active;
if (license.expiryDate() == BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) {
active = true;
} else {
// We subtract the grace period from the current time to avoid overflowing on an expiration
// date that is near Long.MAX_VALUE
active = time >= license.issueDate() && time - GRACE_PERIOD_DURATION.getMillis() < license.expiryDate();
active = time >= license.issueDate() && time < license.expiryDate();
}
licenseState.update(license.operationMode(), active, license.expiryDate(), mostRecentTrialVersion);

if (active) {
if (time < license.expiryDate()) {
logger.debug("license [{}] - valid", license.uid());
} else {
logger.warn("license [{}] - grace", license.uid());
}
logger.debug("license [{}] - valid", license.uid());
} else {
logger.warn("license [{}] - expired", license.uid());
}
Expand Down Expand Up @@ -551,8 +533,6 @@ static SchedulerEngine.Schedule nextLicenseCheck(License license) {
return license.issueDate();
} else if (time < license.expiryDate()) {
return license.expiryDate();
} else if (time < license.expiryDate() + GRACE_PERIOD_DURATION.getMillis()) {
return license.expiryDate() + GRACE_PERIOD_DURATION.getMillis();
}
return -1; // license is expired, no need to check again
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ public void testEnabledLicenseSchedule() throws Exception {
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime), equalTo(license.expiryDate()));
}

public void testGraceLicenseSchedule() throws Exception {
long triggeredTime = license.expiryDate() + between(1,
((int) LicenseService.GRACE_PERIOD_DURATION.getMillis()));
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
equalTo(license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis()));
}

public void testExpiredLicenseSchedule() throws Exception {
long triggeredTime = license.expiryDate() + LicenseService.GRACE_PERIOD_DURATION.getMillis() +
randomIntBetween(1, 1000);
long triggeredTime = license.expiryDate() + randomIntBetween(1, 1000);
assertThat(schedule.nextScheduledTimeAfter(license.issueDate(), triggeredTime),
equalTo(-1L));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,12 @@ public void testClusterRestartWhileEnabled() throws Exception {
assertLicenseActive(true);
}

public void testClusterRestartWhileGrace() throws Exception {
wipeAllLicenses();
internalCluster().startNode();
assertLicenseActive(true);
putLicense(TestUtils.generateSignedLicense(TimeValue.timeValueMillis(0)));
ensureGreen();
assertLicenseActive(true);
logger.info("--> restart node");
internalCluster().fullRestart();
ensureYellow();
logger.info("--> await node for grace_period");
assertLicenseActive(true);
}

public void testClusterRestartWhileExpired() throws Exception {
wipeAllLicenses();
internalCluster().startNode();
ensureGreen();
assertLicenseActive(true);
putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis() - LicenseService.GRACE_PERIOD_DURATION.getMillis()));
putLicense(TestUtils.generateExpiredNonBasicLicense(System.currentTimeMillis()));
assertLicenseActive(false);
logger.info("--> restart node");
internalCluster().fullRestart();
Expand Down