public void setAlertGroups(Set<AlertGroupEntity> alertGroups) {
    Set<AlertGroupEntity> groups = getAlertGroups();
    for (AlertGroupEntity group : groups) {
      group.removeAlertTarget(this);
    }

    this.alertGroups = alertGroups;

    if (null != alertGroups) {
      for (AlertGroupEntity group : alertGroups) {
        group.addAlertTarget(this);
      }
    }
  }
Sets all of the groups that are associated with this target.

@param alertGroups
         the groups, or {@code null} if there are none.
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertTargetEntity.java