ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject ambari git commit: AMBARI-11625. Ambari upgrade hangs.(vbrodetskyi)
Date Tue, 02 Jun 2015 15:00:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 7f3945548 -> dfe0dfebe


AMBARI-11625. Ambari upgrade hangs.(vbrodetskyi)


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

Branch: refs/heads/trunk
Commit: dfe0dfebe4b90efc0eca2ed66da654a2e890c3df
Parents: 7f39455
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Tue Jun 2 13:12:19 2015 +0300
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Tue Jun 2 13:12:44 2015 +0300

----------------------------------------------------------------------
 .../server/upgrade/UpgradeCatalog210.java       | 37 +++++++++++++-------
 1 file changed, 25 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/dfe0dfeb/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
index a79d7f3..e331475 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
@@ -44,6 +44,8 @@ import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.text.MessageFormat;
@@ -910,9 +912,9 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       if (clusterMap != null && !clusterMap.isEmpty()) {
         for (final Cluster cluster : clusterMap.values()) {
 
-          for (String metricName : metricAlerts) {
+          for (String alertName : metricAlerts) {
             AlertDefinitionEntity alertDefinitionEntity =  alertDefinitionDAO.findByName(cluster.getClusterId(),
-                    metricName);
+                    alertName);
             if (alertDefinitionEntity != null) {
               String source = alertDefinitionEntity.getSource();
               JsonObject rootJson = new JsonParser().parse(source).getAsJsonObject();
@@ -920,14 +922,13 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
                     "{{hdfs-site/dfs.web.authentication.kerberos.keytab}}");
               rootJson.get("uri").getAsJsonObject().addProperty("kerberos_principal",
                     "{{hdfs-site/dfs.web.authentication.kerberos.principal}}");
-              alertDefinitionEntity.setSource(rootJson.toString());
-              alertDefinitionDAO.merge(alertDefinitionEntity);
+              updateAlertDefinitionEntitySource(alertName, rootJson.toString());
             }
           }
 
-          for (String metricName : mapredAlerts) {
+          for (String alertName : mapredAlerts) {
             AlertDefinitionEntity alertDefinitionEntity =  alertDefinitionDAO.findByName(cluster.getClusterId(),
-                    metricName);
+                    alertName);
             if (alertDefinitionEntity != null) {
               String source = alertDefinitionEntity.getSource();
               JsonObject rootJson = new JsonParser().parse(source).getAsJsonObject();
@@ -935,14 +936,13 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
                     "{{mapred-site/mapreduce.jobhistory.webapp.spnego-keytab-file}}");
               rootJson.get("uri").getAsJsonObject().addProperty("kerberos_principal",
                     "{{mapred-site/mapreduce.jobhistory.webapp.spnego-principal}}");
-              alertDefinitionEntity.setSource(rootJson.toString());
-              alertDefinitionDAO.merge(alertDefinitionEntity);
+              updateAlertDefinitionEntitySource(alertName, rootJson.toString());
             }
           }
 
-          for (String metricName : rmAlerts) {
+          for (String alertName : rmAlerts) {
             AlertDefinitionEntity alertDefinitionEntity =  alertDefinitionDAO.findByName(cluster.getClusterId(),
-                    metricName);
+                    alertName);
             if (alertDefinitionEntity != null) {
               String source = alertDefinitionEntity.getSource();
               JsonObject rootJson = new JsonParser().parse(source).getAsJsonObject();
@@ -950,8 +950,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
                     "{{yarn-site/yarn.resourcemanager.webapp.spnego-keytab-file}}");
               rootJson.get("uri").getAsJsonObject().addProperty("kerberos_principal",
                     "{{yarn-site/yarn.resourcemanager.webapp.spnego-principal}}");
-              alertDefinitionEntity.setSource(rootJson.toString());
-              alertDefinitionDAO.merge(alertDefinitionEntity);
+              updateAlertDefinitionEntitySource(alertName, rootJson.toString());
             }
           }
         }
@@ -959,6 +958,20 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     }
   }
 
+  private void updateAlertDefinitionEntitySource(final String alertName, final String source)
{
+    executeInTransaction(new Runnable() {
+      @Override
+      public void run() {
+        EntityManager em = getEntityManagerProvider().get();
+        Query nativeQuery = em.createNativeQuery("UPDATE alert_definition SET alert_source=?1
WHERE " +
+                "definition_name=?2");
+        nativeQuery.setParameter(1, source);
+        nativeQuery.setParameter(2, alertName);
+        nativeQuery.executeUpdate();
+      }
+    });
+  }
+
   protected void addMissingConfigs() throws AmbariException {
     updateHiveConfigs();
     updateHdfsConfigs();


Mime
View raw message