Move license status as calculated method

Original commit: elastic/x-pack-elasticsearch@92ce1d9d55
This commit is contained in:
Tanguy Leroux 2015-08-25 17:16:06 +02:00
parent 8d48382bab
commit 8e5521a427
2 changed files with 7 additions and 18 deletions

View File

@ -35,7 +35,7 @@ public class LicensesRenderer extends AbstractRenderer<LicensesMarvelDoc> {
if (licenses != null) { if (licenses != null) {
for (License license : licenses) { for (License license : licenses) {
builder.startObject(); builder.startObject();
builder.field(Fields.STATUS, status(license)); builder.field(Fields.STATUS, license.status().label());
builder.field(Fields.UID, license.uid()); builder.field(Fields.UID, license.uid());
builder.field(Fields.TYPE, license.type()); builder.field(Fields.TYPE, license.type());
builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, license.issueDate()); builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, license.issueDate());
@ -52,20 +52,8 @@ public class LicensesRenderer extends AbstractRenderer<LicensesMarvelDoc> {
builder.endArray(); builder.endArray();
} }
// TODO (tlrx): move status as a calculated getter in License class then remove this method
public static String status(License license) {
String status = "active";
long now = System.currentTimeMillis();
if (license.issueDate() > now) {
status = "invalid";
} else if (license.expiryDate() < now) {
status = "expired";
}
return status;
}
public static String hash(License license, String clusterName) { public static String hash(License license, String clusterName) {
return hash(status(license), license.uid(), license.type(), String.valueOf(license.expiryDate()), clusterName); return hash(license.status().label(), license.uid(), license.type(), String.valueOf(license.expiryDate()), clusterName);
} }
public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) { public static String hash(String licenseStatus, String licenseUid, String licenseType, String licenseExpiryDate, String clusterUUID) {

View File

@ -11,6 +11,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.license.plugin.LicensePlugin;
import org.elasticsearch.marvel.MarvelPlugin; import org.elasticsearch.marvel.MarvelPlugin;
import org.elasticsearch.marvel.agent.collector.licenses.LicensesCollector; import org.elasticsearch.marvel.agent.collector.licenses.LicensesCollector;
@ -110,9 +111,9 @@ public class LicensesRendererIT extends ESIntegTestCase {
.setIndices(MarvelSettings.MARVEL_DATA_INDEX_NAME) .setIndices(MarvelSettings.MARVEL_DATA_INDEX_NAME)
.setTypes(LicensesCollector.TYPE) .setTypes(LicensesCollector.TYPE)
.setQuery(QueryBuilders.boolQuery() .setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "active")) .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.ACTIVE.label()))
.should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "inactive")) .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.INVALID.label()))
.should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "expired")) .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.EXPIRED.label()))
.minimumNumberShouldMatch(1) .minimumNumberShouldMatch(1)
).get(), 0L); ).get(), 0L);