Skip to content

Commit 961c1ab

Browse files
committed
Retain the expiryDate for trial licenses
While updating the license signature to the new license spec retain the trial license expiration date to that of the existing license. Resolves elastic#30882
1 parent e33d107 commit 961c1ab

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public ClusterState execute(ClusterState currentState) throws Exception {
6161
"]. Must be trial or basic.");
6262
}
6363
return updateWithLicense(currentState, type);
64-
} else if (LicenseUtils.licenseNeedsExtended(currentLicensesMetaData.getLicense())) {
65-
return extendBasic(currentState, currentLicensesMetaData);
6664
} else if (LicenseUtils.signatureNeedsUpdate(currentLicensesMetaData.getLicense())) {
6765
return updateLicenseSignature(currentState, currentLicensesMetaData);
66+
} else if (LicenseUtils.licenseNeedsExtended(currentLicensesMetaData.getLicense())) {
67+
return extendBasic(currentState, currentLicensesMetaData);
6868
} else {
6969
return currentState;
7070
}
@@ -75,11 +75,10 @@ private ClusterState updateLicenseSignature(ClusterState currentState, LicensesM
7575
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
7676
String type = license.type();
7777
long issueDate = license.issueDate();
78-
long expiryDate;
78+
long expiryDate = license.expiryDate();
79+
// extend the basic license expiration date if needed since extendBasic will not be called now
7980
if ("basic".equals(type)) {
8081
expiryDate = LicenseService.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS;
81-
} else {
82-
expiryDate = issueDate + LicenseService.NON_BASIC_SELF_GENERATED_LICENSE_DURATION.getMillis();
8382
}
8483
License.Builder specBuilder = License.builder()
8584
.uid(license.uid())
@@ -92,6 +91,8 @@ private ClusterState updateLicenseSignature(ClusterState currentState, LicensesM
9291
Version trialVersion = currentLicenseMetaData.getMostRecentTrialVersion();
9392
LicensesMetaData newLicenseMetadata = new LicensesMetaData(selfGeneratedLicense, trialVersion);
9493
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicenseMetadata);
94+
logger.info("Updating existing license to the new version.\n\nOld license:\n {}\n\n New license:\n{}",
95+
license, newLicenseMetadata.getLicense());
9596
return ClusterState.builder(currentState).metaData(mdBuilder).build();
9697
}
9798

0 commit comments

Comments
 (0)