private String hash(String clusterName, String hostName) {
    Set<AlertDefinitionEntity> definitions = getAlertDefinitionEntities(
        clusterName,
        hostName);

    // no definitions found for this host, don't bother hashing
    if(definitions.isEmpty()) {
      return NULL_MD5_HASH;
    }

    // strip out all AGGREGATE types
    Iterator<AlertDefinitionEntity> iterator = definitions.iterator();
    while (iterator.hasNext()) {
      if (SourceType.AGGREGATE.equals(iterator.next().getSourceType())) {
        iterator.remove();
      }
    }

    // build the UUIDs
    List<String> uuids = new ArrayList<>(definitions.size());
    for (AlertDefinitionEntity definition : definitions) {
      uuids.add(definition.getHash());
    }

    // sort the UUIDs so that the digest is created with bytes in the same order
    Collections.sort(uuids);

    try {
      MessageDigest digest = MessageDigest.getInstance("MD5");
      for (String uuid : uuids) {
        digest.update(uuid.getBytes());
      }

      byte[] hashBytes = digest.digest();
      return Hex.encodeHexString(hashBytes);
    } catch (NoSuchAlgorithmException nsae) {
      LOG.warn("Unable to calculate MD5 alert definition hash", nsae);
      return NULL_MD5_HASH;
    }
  }
Calculates a unique hash value representing all of the alert definitions
that should be scheduled to run on a given host. Alerts of type
{@link SourceType#AGGREGATE} are not included in the hash since they are
not run on the agents.

@param clusterName
         the cluster name (not {@code null}).
@param hostName
         the host name (not {@code null}).
@return the unique hash or {@value #NULL_MD5_HASH} if none.
ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java