public Set<MeasurementData> getRealTimeMeasurementValue(int resourceId, Set<MeasurementScheduleRequest> requests) {
if (requests.size() == 0) {
// There's no need to even call getValues() on the ResourceComponent if the list of metric names is empty.
return Collections.emptySet();
}
MeasurementFacet measurementFacet;
ResourceContainer resourceContainer = inventoryManager.getResourceContainer(resourceId);
if (resourceContainer == null) {
LOG.warn("Can not get resource container for resource with id " + resourceId);
return Collections.emptySet();
}
Resource resource = resourceContainer.getResource();
ResourceType resourceType = resource.getResourceType();
if (resourceType.getMetricDefinitions().isEmpty())
return Collections.emptySet();
try {
measurementFacet = ComponentUtil.getComponent(resourceId, MeasurementFacet.class, FacetLockType.READ,
FACET_METHOD_TIMEOUT, true, true, true);
} catch (Exception e) {
LOG.warn("Cannot get measurement facet for Resource [" + resourceId + "]. Cause: " + e);
return Collections.emptySet();
}
MeasurementReport report = new MeasurementReport();
for (MeasurementScheduleRequest request : requests) {
request.setEnabled(true);
}
try {
measurementFacet.getValues(report, Collections.unmodifiableSet(requests));
} catch (Throwable t) {
LOG.error("Could not get measurement values", t);
return Collections.emptySet();
}