Simplify xcontentstring usages
This is the xplugins side of elastic/elasticsearchelastic/elasticsearch#17774. Original commit: elastic/x-pack-elasticsearch@5c05609840
This commit is contained in:
parent
e94942c68c
commit
cb6a5b4e85
|
@ -60,7 +60,7 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
|
|||
if (shardRouting != null) {
|
||||
// ShardRouting is rendered inside a startObject() / endObject() but without a name,
|
||||
// so we must use XContentBuilder.field(String, ToXContent, ToXContent.Params) here
|
||||
builder.field(Fields.SHARD.underscore().toString(), shardRouting, params);
|
||||
builder.field(Fields.SHARD.value(), shardRouting, params);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,9 +58,9 @@ public class MonitoringBulkTests extends MarvelIntegTestCase {
|
|||
|
||||
for (SearchHit searchHit : searchResponse.getHits()) {
|
||||
Map<String, Object> source = searchHit.sourceAsMap();
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.underscore().toString()));
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.underscore().toString()));
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.underscore().toString()));
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.value()));
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.value()));
|
||||
assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.value()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
|
|||
assertNotNull(sourceFields);
|
||||
|
||||
String[] commons = new String[]{
|
||||
CLUSTER_UUID.underscore().getValue(),
|
||||
TIMESTAMP.underscore().getValue(),
|
||||
SOURCE_NODE.underscore().getValue(),
|
||||
CLUSTER_UUID.value(),
|
||||
TIMESTAMP.value(),
|
||||
SOURCE_NODE.value(),
|
||||
};
|
||||
assertThat("source must contains default fields", sourceFields.keySet(), hasItems(commons));
|
||||
|
||||
|
|
|
@ -77,42 +77,42 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
|
|||
assertThat(response.getId(), equalTo(clusterUUID));
|
||||
|
||||
Map<String, Object> source = response.getSource();
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString()), notNullValue());
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString()), notNullValue());
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString()), notNullValue());
|
||||
assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString()), equalTo(cluster().getClusterName()));
|
||||
assertThat(source.get(ClusterInfoResolver.Fields.VERSION.underscore().toString()), equalTo(Version.CURRENT.toString()));
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value()), notNullValue());
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.value()), notNullValue());
|
||||
assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.value()), notNullValue());
|
||||
assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.value()), equalTo(cluster().getClusterName()));
|
||||
assertThat(source.get(ClusterInfoResolver.Fields.VERSION.value()), equalTo(Version.CURRENT.toString()));
|
||||
|
||||
logger.debug("--> checking that the document contains license information");
|
||||
Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.underscore().toString());
|
||||
Object licenseObj = source.get(ClusterInfoResolver.Fields.LICENSE.value());
|
||||
assertThat(licenseObj, instanceOf(Map.class));
|
||||
Map license = (Map) licenseObj;
|
||||
|
||||
assertThat(license, instanceOf(Map.class));
|
||||
|
||||
String uid = (String) license.get(ClusterInfoResolver.Fields.UID.underscore().toString());
|
||||
String uid = (String) license.get(ClusterInfoResolver.Fields.UID.value());
|
||||
assertThat(uid, not(isEmptyOrNullString()));
|
||||
|
||||
String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.underscore().toString());
|
||||
String type = (String) license.get(ClusterInfoResolver.Fields.TYPE.value());
|
||||
assertThat(type, not(isEmptyOrNullString()));
|
||||
|
||||
String status = (String) license.get(License.XFields.STATUS.underscore().toString());
|
||||
String status = (String) license.get(License.XFields.STATUS.value());
|
||||
assertThat(status, not(isEmptyOrNullString()));
|
||||
|
||||
Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.underscore().toString());
|
||||
Long expiryDate = (Long) license.get(License.XFields.EXPIRY_DATE_IN_MILLIS.value());
|
||||
assertThat(expiryDate, greaterThan(0L));
|
||||
|
||||
// We basically recompute the hash here
|
||||
String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.underscore().toString());
|
||||
String hkey = (String) license.get(ClusterInfoResolver.Fields.HKEY.value());
|
||||
String recalculated = ClusterInfoResolver.hash(status, uid, type, String.valueOf(expiryDate), clusterUUID);
|
||||
assertThat(hkey, equalTo(recalculated));
|
||||
|
||||
assertThat((String) license.get(License.XFields.ISSUER.underscore().toString()), not(isEmptyOrNullString()));
|
||||
assertThat((String) license.get(License.XFields.ISSUED_TO.underscore().toString()), not(isEmptyOrNullString()));
|
||||
assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.underscore().toString()), greaterThan(0L));
|
||||
assertThat((Integer) license.get(License.XFields.MAX_NODES.underscore().toString()), greaterThan(0));
|
||||
assertThat((String) license.get(License.XFields.ISSUER.value()), not(isEmptyOrNullString()));
|
||||
assertThat((String) license.get(License.XFields.ISSUED_TO.value()), not(isEmptyOrNullString()));
|
||||
assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.value()), greaterThan(0L));
|
||||
assertThat((Integer) license.get(License.XFields.MAX_NODES.value()), greaterThan(0));
|
||||
|
||||
Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.underscore().toString());
|
||||
Object clusterStats = source.get(ClusterInfoResolver.Fields.CLUSTER_STATS.value());
|
||||
assertNotNull(clusterStats);
|
||||
assertThat(clusterStats, instanceOf(Map.class));
|
||||
assertThat(((Map) clusterStats).size(), greaterThan(0));
|
||||
|
@ -128,10 +128,10 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
|
|||
.setTypes(ClusterInfoResolver.TYPE)
|
||||
.setQuery(
|
||||
QueryBuilders.boolQuery()
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.ACTIVE.label()))
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.INVALID.label()))
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.EXPIRED.label()))
|
||||
.should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString(),
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.ACTIVE.label()))
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.INVALID.label()))
|
||||
.should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.EXPIRED.label()))
|
||||
.should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.value(),
|
||||
cluster().getClusterName()))
|
||||
.minimumNumberShouldMatch(1)
|
||||
).get(), 0L);
|
||||
|
|
|
@ -122,13 +122,13 @@ public class ClusterStateTests extends MarvelIntegTestCase {
|
|||
|
||||
logger.debug("--> checking that every document contains the expected fields");
|
||||
String[] filters = {
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
|
||||
SOURCE_NODE.underscore().toString(),
|
||||
ClusterStateNodeResolver.Fields.STATE_UUID.underscore().toString(),
|
||||
ClusterStateNodeResolver.Fields.NODE.underscore().toString(),
|
||||
ClusterStateNodeResolver.Fields.NODE.underscore().toString() + "."
|
||||
+ ClusterStateNodeResolver.Fields.ID.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
|
||||
SOURCE_NODE.value(),
|
||||
ClusterStateNodeResolver.Fields.STATE_UUID.value(),
|
||||
ClusterStateNodeResolver.Fields.NODE.value(),
|
||||
ClusterStateNodeResolver.Fields.NODE.value() + "."
|
||||
+ ClusterStateNodeResolver.Fields.ID.value(),
|
||||
};
|
||||
|
||||
for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
|
@ -143,7 +143,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
|
|||
assertThat(client().prepareSearch().setSize(0)
|
||||
.setIndices(timestampedIndex)
|
||||
.setTypes(ClusterStateNodeResolver.TYPE)
|
||||
.setQuery(QueryBuilders.matchQuery(SOURCE_NODE.underscore().toString() + ".attributes.custom", randomInt))
|
||||
.setQuery(QueryBuilders.matchQuery(SOURCE_NODE.value() + ".attributes.custom", randomInt))
|
||||
.get().getHits().getTotalHits(), greaterThan(0L));
|
||||
|
||||
logger.debug("--> cluster state nodes successfully collected");
|
||||
|
@ -167,18 +167,18 @@ public class ClusterStateTests extends MarvelIntegTestCase {
|
|||
|
||||
logger.debug("--> checking that every document contains the expected fields");
|
||||
String[] filters = {
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(),
|
||||
DiscoveryNodeResolver.Fields.NODE.underscore().toString(),
|
||||
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
|
||||
+ DiscoveryNodeResolver.Fields.ID.underscore().toString(),
|
||||
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
|
||||
+ DiscoveryNodeResolver.Fields.NAME.underscore().toString(),
|
||||
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
|
||||
+ DiscoveryNodeResolver.Fields.ATTRIBUTES.underscore().toString(),
|
||||
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "."
|
||||
+ DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
|
||||
MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(),
|
||||
DiscoveryNodeResolver.Fields.NODE.value(),
|
||||
DiscoveryNodeResolver.Fields.NODE.value() + "."
|
||||
+ DiscoveryNodeResolver.Fields.ID.value(),
|
||||
DiscoveryNodeResolver.Fields.NODE.value() + "."
|
||||
+ DiscoveryNodeResolver.Fields.NAME.value(),
|
||||
DiscoveryNodeResolver.Fields.NODE.value() + "."
|
||||
+ DiscoveryNodeResolver.Fields.ATTRIBUTES.value(),
|
||||
DiscoveryNodeResolver.Fields.NODE.value() + "."
|
||||
+ DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.value(),
|
||||
};
|
||||
|
||||
for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
|
|
|
@ -80,12 +80,12 @@ public class IndexRecoveryTests extends MarvelIntegTestCase {
|
|||
|
||||
logger.debug("--> checking that every document contains the expected fields");
|
||||
String[] filters = {
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(),
|
||||
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString(),
|
||||
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString() + "."
|
||||
+ IndexRecoveryResolver.Fields.SHARDS.underscore().toString(),
|
||||
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
|
||||
MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
|
||||
MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(),
|
||||
IndexRecoveryResolver.Fields.INDEX_RECOVERY.value(),
|
||||
IndexRecoveryResolver.Fields.INDEX_RECOVERY.value() + "."
|
||||
+ IndexRecoveryResolver.Fields.SHARDS.value(),
|
||||
};
|
||||
|
||||
for (SearchHit searchHit : response.getHits().getHits()) {
|
||||
|
|
Loading…
Reference in New Issue