ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [2/2] ambari git commit: AMBARI-12322. Installer wizard: cluster deploy failed due to deadlock. (swagle)
Date Wed, 08 Jul 2015 17:41:09 GMT
AMBARI-12322. Installer wizard: cluster deploy failed due to deadlock. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2275ae83
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2275ae83
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2275ae83

Branch: refs/heads/trunk
Commit: 2275ae8392432d986bcf014dca88ac0a190dab91
Parents: 1c7f70f
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Wed Jul 8 10:41:01 2015 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Wed Jul 8 10:41:01 2015 -0700

----------------------------------------------------------------------
 .../alerts/AlertServiceStateListener.java       | 49 ++++++++++++++------
 1 file changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2275ae83/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
index 44f9b50..41f9e81 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
@@ -34,6 +34,8 @@ import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.AlertDispatchDAO;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.alert.AlertDefinition;
 import org.apache.ambari.server.state.alert.AlertDefinitionFactory;
 import org.slf4j.Logger;
@@ -90,6 +92,12 @@ public class AlertServiceStateListener {
   private AlertDefinitionDAO m_definitionDao;
 
   /**
+   * Used to retrieve a cluster using clusterId from event.
+   */
+  @Inject
+  private Provider<Clusters> clusters;
+
+  /**
    * Constructor.
    *
    * @param publisher
@@ -160,23 +168,38 @@ public class AlertServiceStateListener {
   @AllowConcurrentEvents
   public void onAmbariEvent(ServiceRemovedEvent event) {
     LOG.debug("Received event {}", event);
+    Cluster cluster = null;
 
-    List<AlertDefinitionEntity> definitions = m_definitionDao.findByService(event.getClusterId(),
-        event.getServiceName());
+    try {
+      cluster = clusters.get().getClusterById(event.getClusterId());
+    } catch (AmbariException e) {
+      LOG.warn("Unable to retrieve cluster info for id: " + event.getClusterId());
+    }
 
-    for (AlertDefinitionEntity definition : definitions) {
+    if (cluster != null) {
+      // TODO: Explicit locking used to prevent deadlock situation caused during cluster
delete
+      cluster.getClusterGlobalLock().writeLock().lock();
       try {
-        m_definitionDao.remove(definition);
-
-        // remove the default group for the service
-        AlertGroupEntity group = m_alertDispatchDao.findGroupByName(event.getClusterId(),
-            event.getServiceName());
-
-        if (null != group && group.isDefault()) {
-          m_alertDispatchDao.remove(group);
+        List<AlertDefinitionEntity> definitions = m_definitionDao.findByService(event.getClusterId(),
+          event.getServiceName());
+
+        for (AlertDefinitionEntity definition : definitions) {
+          try {
+            m_definitionDao.remove(definition);
+
+            // remove the default group for the service
+            AlertGroupEntity group = m_alertDispatchDao.findGroupByName(event.getClusterId(),
+              event.getServiceName());
+
+            if (null != group && group.isDefault()) {
+              m_alertDispatchDao.remove(group);
+            }
+          } catch (Exception exception) {
+            LOG.error("Unable to remove alert definition {}", definition.getDefinitionName(),
exception);
+          }
         }
-      } catch (Exception exception) {
-        LOG.error("Unable to remove alert definition {}", definition.getDefinitionName(),
exception);
+      } finally {
+        cluster.getClusterGlobalLock().writeLock().unlock();
       }
     }
   }


Mime
View raw message