private Set<AlertDefinitionEntity> getAlertDefinitionEntities(
      String clusterName, String hostName) {

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

    try {
      Cluster cluster = m_clusters.get().getCluster(clusterName);
      if (null == cluster) {
        return Collections.emptySet();
      }

      long clusterId = cluster.getClusterId();

      // services and components
      List<ServiceComponentHost> serviceComponents = cluster.getServiceComponentHosts(hostName);
      if (null == serviceComponents || !serviceComponents.isEmpty()) {
        if (serviceComponents != null) {
          for (ServiceComponentHost serviceComponent : serviceComponents) {
            String serviceName = serviceComponent.getServiceName();
            String componentName = serviceComponent.getServiceComponentName();

            // add all alerts for this service/component pair
            definitions.addAll(m_definitionDao.findByServiceComponent(clusterId, serviceName, componentName));
          }
        }

        // for every service, get the master components and see if the host
        // is a master
        Set<String> services = new HashSet<>();
        for (Entry<String, Service> entry : cluster.getServices().entrySet()) {
          Service service = entry.getValue();
          Map<String, ServiceComponent> components = service.getServiceComponents();
          for (Entry<String, ServiceComponent> component : components.entrySet()) {
            if (component.getValue().isMasterComponent()) {
              Map<String, ServiceComponentHost> hosts = component.getValue().getServiceComponentHosts();

              if (hosts.containsKey(hostName)) {
                services.add(service.getName());
              }
            }
          }
        }

        // add all service scoped alerts
        if (services.size() > 0) {
          definitions.addAll(m_definitionDao.findByServiceMaster(clusterId,
              services));
        }
      }

      // add any alerts not bound to a service (host level alerts)
      definitions.addAll(m_definitionDao.findAgentScoped(clusterId));
    }
    catch (ClusterNotFoundException clusterNotFound) {
      LOG.warn("Unable to get alert definitions for the missing cluster {}",
        clusterName);
      return Collections.emptySet();
    }
    catch (AmbariException ambariException) {
      LOG.error("Unable to get alert definitions", ambariException);
      return Collections.emptySet();
    }

    return definitions;
  }
Gets the alert definition entities for the specified host. This will include the
following types of alert definitions:
<ul>
<li>Service/Component alerts</li>
<li>Service alerts where the host is a MASTER except AGGREGATE alerts</li>
<li>Host alerts that are not bound to a service</li>
</ul>

@param clusterName
         the cluster name (not {@code null}).
@param hostName
         the host name (not {@code null}).
@return the alert definitions for the host, or an empty set (never
        {@code null}).
ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java