@Transactional
  public AlertGroupEntity createDefaultGroup(long clusterId, String serviceName)
      throws AmbariException {

    // AMBARI is a special service that we let through, otherwise we need to
    // verify that the service exists before we create the default group
    String ambariServiceName = RootService.AMBARI.name();
    if (!ambariServiceName.equals(serviceName)) {
      Cluster cluster = m_clusters.get().getClusterById(clusterId);
      Map<String, Service> services = cluster.getServices();

      if (!services.containsKey(serviceName)) {
        String message = MessageFormat.format(
            "Unable to create a default alert group for unknown service {0} in cluster {1}",
            serviceName, cluster.getClusterName());
        throw new AmbariException(message);
      }
    }

    Lock lock = m_locksByService.get(serviceName);
    lock.lock();

    try {
      AlertGroupEntity group = findDefaultServiceGroup(clusterId, serviceName);
      if (null != group) {
        return group;
      }

      group = new AlertGroupEntity();
      group.setClusterId(clusterId);
      group.setDefault(true);
      group.setGroupName(serviceName);
      group.setServiceName(serviceName);

      create(group);
      return group;
    } finally {
      lock.unlock();
    }
  }
Creates a default group in the specified cluster and service. If the
service is not valid, then this will throw an {@link AmbariException}.

@param clusterId
         the cluster that the group is in.
@param serviceName
         the name of the group which is also the service name.
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java