/** Get metrics data for this service node (self) for current interval. */ public MetricsData getMyMetrics(String clusterId, String serviceId) { String key = clusterId + "/" + serviceId + "/" + getContext().getZkNodeId().getPathToken(); ExportMeta exportMeta = exportPathMap.get(key); if (exportMeta == null) { logger.trace( "MetricsData not found: data has not been exported: clusterId={}; serviceId={}; exportMeta={}", clusterId, serviceId, exportMeta); return null; } if (exportMeta.dataPath == null) { logger.trace( "MetricsData not found: waiting for data to be reported in ZK: clusterId={}; serviceId={}; exportMeta.dataPath={}", clusterId, serviceId, exportMeta.dataPath); synchronized (exportMeta) { try { exportMeta.wait(); } catch (InterruptedException e) { logger.warn("Interrupted while waiting: " + e, e); } } } try { logger.debug("Retrieving metrics: path={}", exportMeta.dataPath); Stat stat = new Stat(); byte[] bytes = getContext().getZkClient().getData(exportMeta.dataPath, true, stat); MetricsData metricsData = JacksonUtil.getObjectMapper().readValue(bytes, MetricsData.class); metricsData.setClusterId(clusterId); metricsData.setServiceId(serviceId); metricsData.setLastUpdatedTimestamp(stat.getMtime()); return metricsData; } catch (KeeperException e) { if (e.code() == KeeperException.Code.NONODE) { return null; } throw new ReignException(e); } catch (Exception e) { throw new ReignException(e); } }