Browse Source

AMBARI-12731 Exceptions in ambari-server log: duplicate key value violates unique constraint "uni_alert_group_name" (dsen)

Dmytro Sen 10 years ago
parent
commit
a788a9f28b

+ 9 - 7
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java

@@ -125,14 +125,16 @@ public class AlertServiceStateListener {
     String stackVersion = event.getStackVersion();
     String serviceName = event.getServiceName();
 
-    // create the default alert group for the new service; this MUST be done
-    // before adding definitions so that they are properly added to the
+    // create the default alert group for the new service if absent; this MUST
+    // be done before adding definitions so that they are properly added to the
     // default group
-    try {
-      m_alertDispatchDao.createDefaultGroup(clusterId, serviceName);
-    } catch (AmbariException ambariException) {
-      LOG.error("Unable to create a default alert group for {}", event.getServiceName(),
-          ambariException);
+    if (null == m_alertDispatchDao.findDefaultServiceGroup(clusterId, serviceName)) {
+      try {
+        m_alertDispatchDao.createDefaultGroup(clusterId, serviceName);
+      } catch (AmbariException ambariException) {
+        LOG.error("Unable to create a default alert group for {}",
+          event.getServiceName(), ambariException);
+      }
     }
 
     // populate alert definitions for the new service from the database, but

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java

@@ -406,7 +406,7 @@ public class AlertDispatchDAO {
    *          the predicate to apply, or {@code null} for none.
    * @return the total count of rows that would be returned in a result set.
    */
-  @Transactional
+  @RequiresSession
   public int getNoticesCount(Predicate predicate) {
     return 0;
   }
@@ -457,6 +457,7 @@ public class AlertDispatchDAO {
    * @param serviceName
    *          the name of the group which is also the service name.
    */
+  @Transactional
   public AlertGroupEntity createDefaultGroup(long clusterId, String serviceName)
       throws AmbariException {
     // AMBARI is a special service that we let through, otherwise we need to