for (MeasurementDefinition metricDefinition : metricDefinitions) {
String name = metricDefinition.getName();
try {
DataType dataType = metricDefinition.getDataType();
if (dataType == DataType.MEASUREMENT || metricDefinition.getDataType() == DataType.TRAIT) {
MeasurementReport report = new MeasurementReport();
Set<MeasurementScheduleRequest> requests = new HashSet<MeasurementScheduleRequest>();
MeasurementScheduleRequest request = new MeasurementScheduleRequest(1, metricDefinition
.getName(), 0, true, metricDefinition.getDataType());
requests.add(request);
measurementFacet.getValues(report, requests);
if (dataType == DataType.MEASUREMENT) {
assert report.getNumericData().isEmpty() || report.getNumericData().size() == 1;
assert report.getTraitData().isEmpty();
assert report.getCallTimeData().isEmpty();
MeasurementDataNumeric dataNumeric = (report.getNumericData().isEmpty()) ? null
: report.getNumericData().iterator().next();
Double value = (dataNumeric != null) ? dataNumeric.getValue() : null;
System.out.println("Validating numeric metric '" + name + "' value (" + value + ")...");
validateNumericMetricValue(metricDefinition.getName(), value, resource);
} else if (metricDefinition.getDataType() == DataType.TRAIT) {
assert report.getTraitData().isEmpty() || report.getTraitData().size() == 1;
assert report.getNumericData().isEmpty();
assert report.getCallTimeData().isEmpty();
MeasurementDataTrait dataTrait = (report.getTraitData().size() == 1) ? report
.getTraitData().iterator().next() : null;
String value = (dataTrait != null) ? dataTrait.getValue() : null;
System.out.println("Validating trait '" + name + "' value (" + value + ")...");
validateTraitMetricValue(metricDefinition.getName(), value, resource);
}