long startTime = System.currentTimeMillis();
// String aggTypeName =
// DEFAULT_AGG_TYPE+AggregationType.DELIM+DEFAULT_DECAY_PARAM;
// _defaultAggType = AggregationTypeFactory.getAggregationType(aggTypeName);
HelixManager manager = event.getAttribute("helixmanager");
HealthDataCache cache = event.getAttribute("HealthDataCache");
if (manager == null || cache == null)
{
throw new StageException("helixmanager|HealthDataCache attribute value is null");
}
if(_alertsHolder == null)
{
_statsHolder = new StatsHolder(manager, cache);
_alertsHolder = new AlertsHolder(manager, cache, _statsHolder);
}
else
{
_statsHolder.updateCache(cache);
_alertsHolder.updateCache(cache);
}
if (_statsHolder.getStatsList().size() == 0)
{
logger.info("stat holder is empty");
return;
}
// init agg stats from cache
// initAggStats(cache);
Map<String, LiveInstance> liveInstances = cache.getLiveInstances();
long currTime = System.currentTimeMillis();
// for each live node, read node's stats
long readInstancesStart = System.currentTimeMillis();
for (LiveInstance instance : liveInstances.values())
{
String instanceName = instance.getInstanceName();
logger.debug("instanceName: " + instanceName);
// XXX: now have map of HealthStats, so no need to traverse them...verify
// correctness
Map<String, HealthStat> stats;
stats = cache.getHealthStats(instanceName);
// find participants stats
long modTime = -1;
// TODO: get healthreport child node modified time and reportAgeStat based on that
boolean reportedAge = false;
for (HealthStat participantStat : stats.values())
{
if (participantStat != null && !reportedAge)
{
// generate and report stats for how old this node's report is
modTime = participantStat.getLastModifiedTimeStamp();
reportAgeStat(instance, modTime, currTime);
reportedAge = true;
}
// System.out.println(modTime);
// XXX: need to convert participantStat to a better format
// need to get instanceName in here
if (participantStat != null)
{
// String timestamp = String.valueOf(instance.getModifiedTime()); WANT
// REPORT LEVEL TS
Map<String, Map<String, String>> statMap =
participantStat.getHealthFields(instanceName);
for (String key : statMap.keySet())
{
_statsHolder.applyStat(key, statMap.get(key));
}
}
}
}
// Call _statsHolder.persistStats() once per pipeline. This will
// write the updated persisted stats into zookeeper
_statsHolder.persistStats();
logger.info("Done processing stats: "
+ (System.currentTimeMillis() - readInstancesStart));
// populate _statStatus
_statStatus = _statsHolder.getStatsMap();
for (String statKey : _statStatus.keySet())
{
logger.debug("Stat key, value: " + statKey + ": " + _statStatus.get(statKey));
}
long alertExecuteStartTime = System.currentTimeMillis();
// execute alerts, populate _alertStatus
_alertStatus =
AlertProcessor.executeAllAlerts(_alertsHolder.getAlertList(),
_statsHolder.getStatsList());
logger.info("done executing alerts: "
+ (System.currentTimeMillis() - alertExecuteStartTime));
for (String originAlertName : _alertStatus.keySet())
{
_alertBeanCollection.setAlerts(originAlertName,
_alertStatus.get(originAlertName),
manager.getClusterName());
}
executeAlertActions(manager);
// Write alert fire history to zookeeper
updateAlertHistory(manager);