*/
public List<MetricDefinition> getMetrics(String stackName, String stackVersion,
String serviceName, String componentName, String metricType)
throws AmbariException {
ServiceInfo svc = getService(stackName, stackVersion, serviceName);
if (null == svc.getMetricsFile() || !svc.getMetricsFile().exists()) {
LOG.debug("Metrics file for " + stackName + "/" + stackVersion + "/" + serviceName + " not found.");
return null;
}
Map<String, Map<String, List<MetricDefinition>>> map = svc.getMetrics();
// check for cached
if (null == map) {
// data layout:
// "DATANODE" -> "Component" -> [ MetricDefinition, MetricDefinition, ... ]
// \-> "HostComponent" -> [ MetricDefinition, ... ]
Type type = new TypeToken<Map<String, Map<String, List<MetricDefinition>>>>(){}.getType();
Gson gson = new Gson();
try {
map = gson.fromJson(new FileReader(svc.getMetricsFile()), type);
svc.setMetrics(map);
} catch (Exception e) {
LOG.error ("Could not read the metrics file", e);
throw new AmbariException("Could not read metrics file", e);
}