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:
Ryan Ernst 2016-04-14 23:15:41 -07:00
parent e94942c68c
commit cb6a5b4e85
6 changed files with 53 additions and 53 deletions

View File

@ -60,7 +60,7 @@ public class ShardsResolver extends MonitoringIndexNameResolver.Timestamped<Shar
if (shardRouting != null) { if (shardRouting != null) {
// ShardRouting is rendered inside a startObject() / endObject() but without a name, // ShardRouting is rendered inside a startObject() / endObject() but without a name,
// so we must use XContentBuilder.field(String, ToXContent, ToXContent.Params) here // 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);
} }
} }

View File

@ -58,9 +58,9 @@ public class MonitoringBulkTests extends MarvelIntegTestCase {
for (SearchHit searchHit : searchResponse.getHits()) { for (SearchHit searchHit : searchResponse.getHits()) {
Map<String, Object> source = searchHit.sourceAsMap(); Map<String, Object> source = searchHit.sourceAsMap();
assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.underscore().toString())); assertNotNull(source.get(MonitoringBulkResolver.Fields.CLUSTER_UUID.value()));
assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.underscore().toString())); assertNotNull(source.get(MonitoringBulkResolver.Fields.TIMESTAMP.value()));
assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.underscore().toString())); assertNotNull(source.get(MonitoringBulkResolver.Fields.SOURCE_NODE.value()));
} }
} }

View File

@ -148,9 +148,9 @@ public abstract class MonitoringIndexNameResolverTestCase<M extends MonitoringDo
assertNotNull(sourceFields); assertNotNull(sourceFields);
String[] commons = new String[]{ String[] commons = new String[]{
CLUSTER_UUID.underscore().getValue(), CLUSTER_UUID.value(),
TIMESTAMP.underscore().getValue(), TIMESTAMP.value(),
SOURCE_NODE.underscore().getValue(), SOURCE_NODE.value(),
}; };
assertThat("source must contains default fields", sourceFields.keySet(), hasItems(commons)); assertThat("source must contains default fields", sourceFields.keySet(), hasItems(commons));

View File

@ -77,42 +77,42 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
assertThat(response.getId(), equalTo(clusterUUID)); assertThat(response.getId(), equalTo(clusterUUID));
Map<String, Object> source = response.getSource(); Map<String, Object> source = response.getSource();
assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString()), notNullValue()); assertThat(source.get(MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value()), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString()), notNullValue()); assertThat(source.get(MonitoringIndexNameResolver.Fields.TIMESTAMP.value()), notNullValue());
assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString()), notNullValue()); assertThat(source.get(MonitoringIndexNameResolver.Fields.SOURCE_NODE.value()), notNullValue());
assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString()), equalTo(cluster().getClusterName())); assertThat(source.get(ClusterInfoResolver.Fields.CLUSTER_NAME.value()), equalTo(cluster().getClusterName()));
assertThat(source.get(ClusterInfoResolver.Fields.VERSION.underscore().toString()), equalTo(Version.CURRENT.toString())); assertThat(source.get(ClusterInfoResolver.Fields.VERSION.value()), equalTo(Version.CURRENT.toString()));
logger.debug("--> checking that the document contains license information"); 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)); assertThat(licenseObj, instanceOf(Map.class));
Map license = (Map) licenseObj; Map license = (Map) licenseObj;
assertThat(license, instanceOf(Map.class)); 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())); 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())); 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())); 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)); assertThat(expiryDate, greaterThan(0L));
// We basically recompute the hash here // 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); String recalculated = ClusterInfoResolver.hash(status, uid, type, String.valueOf(expiryDate), clusterUUID);
assertThat(hkey, equalTo(recalculated)); assertThat(hkey, equalTo(recalculated));
assertThat((String) license.get(License.XFields.ISSUER.underscore().toString()), not(isEmptyOrNullString())); assertThat((String) license.get(License.XFields.ISSUER.value()), not(isEmptyOrNullString()));
assertThat((String) license.get(License.XFields.ISSUED_TO.underscore().toString()), not(isEmptyOrNullString())); assertThat((String) license.get(License.XFields.ISSUED_TO.value()), not(isEmptyOrNullString()));
assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.underscore().toString()), greaterThan(0L)); assertThat((Long) license.get(License.XFields.ISSUE_DATE_IN_MILLIS.value()), greaterThan(0L));
assertThat((Integer) license.get(License.XFields.MAX_NODES.underscore().toString()), greaterThan(0)); 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); assertNotNull(clusterStats);
assertThat(clusterStats, instanceOf(Map.class)); assertThat(clusterStats, instanceOf(Map.class));
assertThat(((Map) clusterStats).size(), greaterThan(0)); assertThat(((Map) clusterStats).size(), greaterThan(0));
@ -128,10 +128,10 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
.setTypes(ClusterInfoResolver.TYPE) .setTypes(ClusterInfoResolver.TYPE)
.setQuery( .setQuery(
QueryBuilders.boolQuery() QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.ACTIVE.label())) .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.ACTIVE.label()))
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.INVALID.label())) .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.INVALID.label()))
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.EXPIRED.label())) .should(QueryBuilders.matchQuery(License.XFields.STATUS.value(), License.Status.EXPIRED.label()))
.should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.underscore().toString(), .should(QueryBuilders.matchQuery(ClusterInfoResolver.Fields.CLUSTER_NAME.value(),
cluster().getClusterName())) cluster().getClusterName()))
.minimumNumberShouldMatch(1) .minimumNumberShouldMatch(1)
).get(), 0L); ).get(), 0L);

View File

@ -122,13 +122,13 @@ public class ClusterStateTests extends MarvelIntegTestCase {
logger.debug("--> checking that every document contains the expected fields"); logger.debug("--> checking that every document contains the expected fields");
String[] filters = { String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
SOURCE_NODE.underscore().toString(), SOURCE_NODE.value(),
ClusterStateNodeResolver.Fields.STATE_UUID.underscore().toString(), ClusterStateNodeResolver.Fields.STATE_UUID.value(),
ClusterStateNodeResolver.Fields.NODE.underscore().toString(), ClusterStateNodeResolver.Fields.NODE.value(),
ClusterStateNodeResolver.Fields.NODE.underscore().toString() + "." ClusterStateNodeResolver.Fields.NODE.value() + "."
+ ClusterStateNodeResolver.Fields.ID.underscore().toString(), + ClusterStateNodeResolver.Fields.ID.value(),
}; };
for (SearchHit searchHit : response.getHits().getHits()) { for (SearchHit searchHit : response.getHits().getHits()) {
@ -143,7 +143,7 @@ public class ClusterStateTests extends MarvelIntegTestCase {
assertThat(client().prepareSearch().setSize(0) assertThat(client().prepareSearch().setSize(0)
.setIndices(timestampedIndex) .setIndices(timestampedIndex)
.setTypes(ClusterStateNodeResolver.TYPE) .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)); .get().getHits().getTotalHits(), greaterThan(0L));
logger.debug("--> cluster state nodes successfully collected"); 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"); logger.debug("--> checking that every document contains the expected fields");
String[] filters = { String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(), MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString(), DiscoveryNodeResolver.Fields.NODE.value(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." DiscoveryNodeResolver.Fields.NODE.value() + "."
+ DiscoveryNodeResolver.Fields.ID.underscore().toString(), + DiscoveryNodeResolver.Fields.ID.value(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." DiscoveryNodeResolver.Fields.NODE.value() + "."
+ DiscoveryNodeResolver.Fields.NAME.underscore().toString(), + DiscoveryNodeResolver.Fields.NAME.value(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." DiscoveryNodeResolver.Fields.NODE.value() + "."
+ DiscoveryNodeResolver.Fields.ATTRIBUTES.underscore().toString(), + DiscoveryNodeResolver.Fields.ATTRIBUTES.value(),
DiscoveryNodeResolver.Fields.NODE.underscore().toString() + "." DiscoveryNodeResolver.Fields.NODE.value() + "."
+ DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.underscore().toString(), + DiscoveryNodeResolver.Fields.TRANSPORT_ADDRESS.value(),
}; };
for (SearchHit searchHit : response.getHits().getHits()) { for (SearchHit searchHit : response.getHits().getHits()) {

View File

@ -80,12 +80,12 @@ public class IndexRecoveryTests extends MarvelIntegTestCase {
logger.debug("--> checking that every document contains the expected fields"); logger.debug("--> checking that every document contains the expected fields");
String[] filters = { String[] filters = {
MonitoringIndexNameResolver.Fields.CLUSTER_UUID.underscore().toString(), MonitoringIndexNameResolver.Fields.CLUSTER_UUID.value(),
MonitoringIndexNameResolver.Fields.TIMESTAMP.underscore().toString(), MonitoringIndexNameResolver.Fields.TIMESTAMP.value(),
MonitoringIndexNameResolver.Fields.SOURCE_NODE.underscore().toString(), MonitoringIndexNameResolver.Fields.SOURCE_NODE.value(),
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString(), IndexRecoveryResolver.Fields.INDEX_RECOVERY.value(),
IndexRecoveryResolver.Fields.INDEX_RECOVERY.underscore().toString() + "." IndexRecoveryResolver.Fields.INDEX_RECOVERY.value() + "."
+ IndexRecoveryResolver.Fields.SHARDS.underscore().toString(), + IndexRecoveryResolver.Fields.SHARDS.value(),
}; };
for (SearchHit searchHit : response.getHits().getHits()) { for (SearchHit searchHit : response.getHits().getHits()) {