private void onAlertEvent(long clusterId, String alertName) {
    AlertDefinition aggregateDefinition = m_aggregateMapping.getAggregateDefinition(clusterId,
        alertName);

    if (null == aggregateDefinition || null == m_alertsDao) {
      return;
    }

    AggregateSource aggregateSource = (AggregateSource) aggregateDefinition.getSource();

    AlertSummaryDTO summary = m_alertsDao.findAggregateCounts(clusterId,
        aggregateSource.getAlertName());

    // OK should be based off of true OKs and those in maintenance mode
    int okCount = summary.getOkCount() + summary.getMaintenanceCount();

    int warningCount = summary.getWarningCount();
    int criticalCount = summary.getCriticalCount();
    int unknownCount = summary.getUnknownCount();
    int totalCount = okCount + warningCount + criticalCount + unknownCount;

    Alert aggregateAlert = new Alert(aggregateDefinition.getName(), null,
        aggregateDefinition.getServiceName(), null, null, AlertState.UNKNOWN);

    aggregateAlert.setLabel(aggregateDefinition.getLabel());
    aggregateAlert.setTimestamp(System.currentTimeMillis());
    aggregateAlert.setClusterId(clusterId);

    if (0 == totalCount) {
      aggregateAlert.setText("There are no instances of the aggregated alert.");
    } else if (summary.getUnknownCount() > 0) {
      aggregateAlert.setText("There are alerts with a state of UNKNOWN.");
    } else {
      Reporting reporting = aggregateSource.getReporting();

      int numerator = summary.getCriticalCount() + summary.getWarningCount();
      int denominator = totalCount;

      double value = ((double) (numerator) / denominator);
      if(Reporting.ReportingType.PERCENT.equals(reporting.getType())) {
        value *= 100;
      }

      if (value >= reporting.getCritical().getValue()) {
        aggregateAlert.setState(AlertState.CRITICAL);
        aggregateAlert.setText(MessageFormat.format(
            reporting.getCritical().getText(),
            denominator, numerator));

      } else if (value >= reporting.getWarning().getValue()) {
        aggregateAlert.setState(AlertState.WARNING);
        aggregateAlert.setText(MessageFormat.format(
            reporting.getWarning().getText(),
            denominator, numerator));

      } else {
        aggregateAlert.setState(AlertState.OK);
        aggregateAlert.setText(MessageFormat.format(
            reporting.getOk().getText(),
            denominator, numerator));
      }
    }

    // now that the alert has been created, see if we need to send it; only send
    // alerts if the state or the text has changed
    boolean sendAlertEvent = true;
    Alert cachedAlert = m_alertCache.get(aggregateAlert.getName());
    if (null != cachedAlert) {
      AlertState cachedState = cachedAlert.getState();
      AlertState alertState = aggregateAlert.getState();
      String cachedText = cachedAlert.getText();
      String alertText = aggregateAlert.getText();

      if (cachedState == alertState && StringUtils.equals(cachedText, alertText)) {
        sendAlertEvent = false;
      }
    }

    // update the cache
    m_alertCache.put(aggregateAlert.getName(), aggregateAlert);

    // make a new event and allow others to consume it, but only if the
    // aggregate has changed
    if (sendAlertEvent) {
      AlertReceivedEvent aggEvent = new AlertReceivedEvent(clusterId, aggregateAlert);
      m_publisher.publish(aggEvent);
    }
  }
Calculates the aggregate alert state if there is an aggregate alert for the
specified alert.
<p/>
This method should not be decoratd with {@link AllowConcurrentEvents} since
it would need extra locking around {@link #m_alertCache}.

@param clusterId
         the ID of the cluster.
@param alertName
         the name of the alert to use when looking up the aggregate.
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertAggregateListener.java