Move license status as calculated method
Original commit: elastic/x-pack-elasticsearch@92ce1d9d55
This commit is contained in:
parent
8d48382bab
commit
8e5521a427
|
@ -35,7 +35,7 @@ public class LicensesRenderer extends AbstractRenderer<LicensesMarvelDoc> {
|
|||
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<LicensesMarvelDoc> {
|
|||
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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue