public Set<AlertDefinition> getAlertDefinitions(Reader reader,
      String serviceName) throws AmbariException {

    // { MAPR : {definitions}, YARN : {definitions} }
    Map<String, Map<String, List<AlertDefinition>>> serviceDefinitionMap = null;

    try {
      Type type = new TypeToken<Map<String, Map<String, List<AlertDefinition>>>>() {}.getType();
      serviceDefinitionMap = m_gson.fromJson(reader, type);
    } catch (Exception e) {
      LOG.error("Could not read the alert definitions", e);
      throw new AmbariException("Could not read alert definitions", e);
    } finally {
      IOUtils.closeQuietly(reader);
    }

    Set<AlertDefinition> definitions = new HashSet<>();

    // it's OK if the service doesn't have any definitions; this can happen if
    // 2 services are defined in a single metainfo.xml and only 1 service has
    // alerts defined
    Map<String, List<AlertDefinition>> definitionMap = serviceDefinitionMap.get(serviceName);
    if (null == definitionMap) {
      return definitions;
    }

    for (Entry<String, List<AlertDefinition>> entry : definitionMap.entrySet()) {
      for (AlertDefinition ad : entry.getValue()) {
        ad.setServiceName(serviceName);
        if (!entry.getKey().equals("service")) {
          ad.setComponentName(entry.getKey());
        }
      }
      definitions.addAll(entry.getValue());
    }

    return definitions;
  }
Gets a list of all of the alert definitions defined in the resource pointed
to by the specified reader for the given service. There should have a
mapping between the service and the alerts defined for that service. This
is necessary since some services are combined in a single
{@code metainfo.xml} and only have a single directory on the stack.
<p/>
The supplied reader is closed when this method completes.

@param reader
         the reader to read from (not {@code null}). This will be closed
         after reading is done.
@param serviceName
         the name of the service to extract definitions for (not
         {@code null}).
@return the definitions for the specified service, or an empty set.
@throws AmbariException
          if there was a problem reading or parsing the JSON.
ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionFactory.java