From 8e5521a4273797d73e346adb8e4aa55cd7113cd0 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 25 Aug 2015 17:16:06 +0200 Subject: [PATCH] Move license status as calculated method Original commit: elastic/x-pack-elasticsearch@92ce1d9d553c8d2291360f177836044383711de5 --- .../renderer/licenses/LicensesRenderer.java | 16 ++-------------- .../renderer/licenses/LicensesRendererIT.java | 9 +++++---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRenderer.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRenderer.java index 2d34a854e33..1b149dec480 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRenderer.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRenderer.java @@ -35,7 +35,7 @@ public class LicensesRenderer extends AbstractRenderer { if (licenses != null) { for (License license : licenses) { builder.startObject(); - builder.field(Fields.STATUS, status(license)); + builder.field(Fields.STATUS, license.status().label()); builder.field(Fields.UID, license.uid()); builder.field(Fields.TYPE, license.type()); builder.dateValueField(Fields.ISSUE_DATE_IN_MILLIS, Fields.ISSUE_DATE, license.issueDate()); @@ -52,20 +52,8 @@ public class LicensesRenderer extends AbstractRenderer { 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) { - 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) { diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRendererIT.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRendererIT.java index 69074ca9b06..a53c4509e09 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRendererIT.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/renderer/licenses/LicensesRendererIT.java @@ -11,6 +11,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.LicensePlugin; import org.elasticsearch.marvel.MarvelPlugin; import org.elasticsearch.marvel.agent.collector.licenses.LicensesCollector; @@ -110,10 +111,10 @@ public class LicensesRendererIT extends ESIntegTestCase { .setIndices(MarvelSettings.MARVEL_DATA_INDEX_NAME) .setTypes(LicensesCollector.TYPE) .setQuery(QueryBuilders.boolQuery() - .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "active")) - .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "inactive")) - .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), "expired")) - .minimumNumberShouldMatch(1) + .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.ACTIVE.label())) + .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.INVALID.label())) + .should(QueryBuilders.matchQuery(LicensesRenderer.Fields.STATUS.underscore().toString(), License.Status.EXPIRED.label())) + .minimumNumberShouldMatch(1) ).get(), 0L); }