Skip to content

Commit

Permalink
Retain the expiryDate for trial licenses
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jkakavas committed May 30, 2018
1 parent e33d107 commit 961c1ab
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public ClusterState execute(ClusterState currentState) throws Exception {
"]. Must be trial or basic.");
}
return updateWithLicense(currentState, type);
} else if (LicenseUtils.licenseNeedsExtended(currentLicensesMetaData.getLicense())) {
return extendBasic(currentState, currentLicensesMetaData);
} else if (LicenseUtils.signatureNeedsUpdate(currentLicensesMetaData.getLicense())) {
return updateLicenseSignature(currentState, currentLicensesMetaData);
} else if (LicenseUtils.licenseNeedsExtended(currentLicensesMetaData.getLicense())) {
return extendBasic(currentState, currentLicensesMetaData);
} else {
return currentState;
}
Expand All @@ -75,11 +75,10 @@ private ClusterState updateLicenseSignature(ClusterState currentState, LicensesM
MetaData.Builder mdBuilder = MetaData.builder(currentState.metaData());
String type = license.type();
long issueDate = license.issueDate();
long expiryDate;
long expiryDate = license.expiryDate();
// extend the basic license expiration date if needed since extendBasic will not be called now
if ("basic".equals(type)) {
expiryDate = LicenseService.BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS;
} else {
expiryDate = issueDate + LicenseService.NON_BASIC_SELF_GENERATED_LICENSE_DURATION.getMillis();
}
License.Builder specBuilder = License.builder()
.uid(license.uid())
Expand All @@ -92,6 +91,8 @@ private ClusterState updateLicenseSignature(ClusterState currentState, LicensesM
Version trialVersion = currentLicenseMetaData.getMostRecentTrialVersion();
LicensesMetaData newLicenseMetadata = new LicensesMetaData(selfGeneratedLicense, trialVersion);
mdBuilder.putCustom(LicensesMetaData.TYPE, newLicenseMetadata);
logger.info("Updating existing license to the new version.\n\nOld license:\n {}\n\n New license:\n{}",
license, newLicenseMetadata.getLicense());
return ClusterState.builder(currentState).metaData(mdBuilder).build();
}

Expand Down

0 comments on commit 961c1ab

Please sign in to comment.