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 @@ -114,7 +114,7 @@ public class LicenseService extends AbstractLifecycleComponent implements Cluste

public static final String LICENSE_JOB = "licenseJob";

private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("EEEE, MMMMM dd, yyyy");
private static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("EEEE, MMMM dd, yyyy");

private static final String ACKNOWLEDGEMENT_HEADER = "This license update requires acknowledgement. To acknowledge the license, " +
"please read the following messages and update the license again, this time with the \"acknowledge=true\" parameter:";
Expand All @@ -134,11 +134,15 @@ public LicenseService(Settings settings, ClusterService clusterService, Clock cl
}

private void logExpirationWarning(long expirationMillis, boolean expired) {
logger.warn("{}", buildExpirationMessage(expirationMillis, expired));
}

static CharSequence buildExpirationMessage(long expirationMillis, boolean expired) {
String expiredMsg = expired ? "expired" : "will expire";
String general = LoggerMessageFormat.format(null, "License [{}] on [{}].\n" +
"# If you have a new license, please update it. Otherwise, please reach out to\n" +
"# your support contact.\n" +
"# ", expiredMsg, DATE_FORMATTER.formatMillis(expirationMillis));
"# If you have a new license, please update it. Otherwise, please reach out to\n" +
"# your support contact.\n" +
"# ", expiredMsg, DATE_FORMATTER.formatMillis(expirationMillis));
if (expired) {
general = general.toUpperCase(Locale.ROOT);
}
Expand All @@ -161,7 +165,7 @@ private void logExpirationWarning(long expirationMillis, boolean expired) {
}
}
});
logger.warn("{}", builder);
return builder;
}

private void populateExpirationCallbacks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license;


import org.elasticsearch.bootstrap.JavaVersion;
import org.elasticsearch.test.ESTestCase;

import java.time.LocalDate;
import java.time.ZoneOffset;

import static org.hamcrest.Matchers.startsWith;

/**
* Due to changes in JDK9 where locale data is used from CLDR, the licence message will differ in jdk 8 and jdk9+
* https://openjdk.java.net/jeps/252
*/
public class LicenseServiceTests extends ESTestCase {

public void testLogExpirationWarningOnJdk9AndNewer() {
assumeTrue("this is for JDK9+", JavaVersion.current().compareTo(JavaVersion.parse("9")) >= 0);

long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
final boolean expired = randomBoolean();
final String message = LicenseService.buildExpirationMessage(time, expired).toString();
if (expired) {
assertThat(message, startsWith("LICENSE [EXPIRED] ON [THU, NOV 15, 2018].\n"));
} else {
assertThat(message, startsWith("License [will expire] on [Thu, Nov 15, 2018].\n"));
}
}

public void testLogExpirationWarningOnJdk8() {
assumeTrue("this is for JDK8 only", JavaVersion.current().equals(JavaVersion.parse("8")));

long time = LocalDate.of(2018, 11, 15).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
final boolean expired = randomBoolean();
final String message = LicenseService.buildExpirationMessage(time, expired).toString();
if (expired) {
assertThat(message, startsWith("LICENSE [EXPIRED] ON [THURSDAY, NOVEMBER 15, 2018].\n"));
} else {
assertThat(message, startsWith("License [will expire] on [Thursday, November 15, 2018].\n"));
}
}

}