ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpapirkovs...@apache.org
Subject git commit: AMBARI-4731. After upgrade from 1.4.1 to 1.4.4, create config group fails with error: 500. (mpapirkovskyy)
Date Fri, 28 Feb 2014 18:37:37 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 41046349c -> acfb1db9c


AMBARI-4731. After upgrade from 1.4.1 to 1.4.4, create config group fails with error: 500.
(mpapirkovskyy)


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

Branch: refs/heads/trunk
Commit: acfb1db9c9b42793754f62cba978a98a34ff8367
Parents: 4104634
Author: Myroslav Papirkovskyy <mpapyrkovskyy@hortonworks.com>
Authored: Fri Feb 28 20:35:02 2014 +0200
Committer: Myroslav Papirkovskyy <mpapyrkovskyy@hortonworks.com>
Committed: Fri Feb 28 20:37:19 2014 +0200

----------------------------------------------------------------------
 .../server/upgrade/AbstractUpgradeCatalog.java  |   5 +-
 .../server/upgrade/SchemaUpgradeHelper.java     |   8 +-
 .../server/upgrade/UpgradeCatalog150.java       | 119 +++++++++----------
 3 files changed, 66 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/acfb1db9/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
index 69bed8f..83278b7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
@@ -150,7 +150,10 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog
{
         func.run();
         entityManager.getTransaction().commit();
       } catch (Exception e) {
-        entityManager.getTransaction().rollback();
+        LOG.error("Error in transaction ", e);
+        if (entityManager.getTransaction().isActive()) {
+          entityManager.getTransaction().rollback();
+        }
         throw new RuntimeException(e);
       }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/acfb1db9/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index fc1c0db..38fd54f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -154,7 +154,10 @@ public class SchemaUpgradeHelper {
           throw e;
         } catch (SQLException e) {
           LOG.error("Upgrade failed. ", e);
-          throw new AmbariException(e.getMessage());
+          throw new AmbariException(e.getMessage(), e);
+        } catch (Exception e) {
+          LOG.error("Upgrade failed. ", e);
+          throw new AmbariException(e.getMessage(), e);
         }
       }
     }
@@ -173,6 +176,9 @@ public class SchemaUpgradeHelper {
         } catch (SQLException e) {
           LOG.error("Upgrade failed. ", e);
           throw new AmbariException(e.getMessage());
+        } catch (Exception e) {
+          LOG.error("Upgrade failed. ", e);
+          throw new AmbariException(e.getMessage(), e);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/acfb1db9/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
index 2cba0a8..9571eb4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
@@ -1,38 +1,30 @@
 package org.apache.ambari.server.upgrade;
 
-import java.io.File;
-import java.io.IOException;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Expression;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-
+import com.google.inject.Inject;
+import com.google.inject.Injector;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
 import org.apache.ambari.server.orm.entities.ClusterStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
-import org.apache.ambari.server.state.State;
 import org.eclipse.persistence.jpa.JpaEntityManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.inject.Inject;
-import com.google.inject.Injector;
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import javax.persistence.criteria.*;
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
 
 public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
   private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog150.class);
@@ -341,56 +333,58 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
       }
     }
 
+    //add new sequence for config groups
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, \"value\") " +
+      "VALUES('configgroup_id_seq', 1)", true);
+
     //clear cache due to direct table manipulation
     ((JpaEntityManager)em.getDelegate()).getServerSession().getIdentityMapAccessor().invalidateAll();
 
     // Updates
 
-    // HostComponentState
-    CriteriaBuilder cb = em.getCriteriaBuilder();
-    CriteriaQuery<HostComponentStateEntity> c1 = cb.createQuery(HostComponentStateEntity.class);
-    Root<HostComponentStateEntity> hsc = c1.from(HostComponentStateEntity.class);
-    Expression<String> exp = hsc.get("current_state");
-    List<String> statuses = new ArrayList<String>() {{
-       add("STOP_FAILED");
-       add("START_FAILED");
-    }};
-    Predicate predicate = exp.in(statuses);
-    c1.select(hsc).where(predicate);
-
-    TypedQuery<HostComponentStateEntity> q1 = em.createQuery(c1);
-    List<HostComponentStateEntity> r1 = q1.getResultList();
-
-    HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class);
-    if (r1 != null && !r1.isEmpty()) {
-      for (HostComponentStateEntity entity : r1) {
-        entity.setCurrentState(State.INSTALLED);
-        hostComponentStateDAO.merge(entity);
+    // HostComponentState - reverted to native query due to incorrect criteria api usage
+    // (it forces us to use enums not strings, which were deleted)
+    executeInTransaction(new Runnable() {
+      @Override
+      public void run() {
+        EntityManager em = getEntityManagerProvider().get();
+        Query nativeQuery = em.createNativeQuery("UPDATE hostcomponentstate SET current_state=?1
WHERE current_state in (?2, ?3)");
+        nativeQuery.setParameter(1, "INSTALLED");
+        nativeQuery.setParameter(2, "STOP_FAILED");
+        nativeQuery.setParameter(3, "START_FAILED");
+        nativeQuery.executeUpdate();
       }
-    }
+    });
 
     // HostRoleCommand
-    CriteriaQuery<HostRoleCommandEntity> c2 = cb.createQuery(HostRoleCommandEntity.class);
-    Root<HostRoleCommandEntity> hrc = c2.from(HostRoleCommandEntity.class);
-    statuses = new ArrayList<String>() {{
-      add("PENDING");
-      add("QUEUED");
-      add("IN_PROGRESS");
-    }};
-    exp = hrc.get("status");
-    predicate = exp.in(statuses);
-    c2.select(hrc).where(predicate);
-
-    TypedQuery<HostRoleCommandEntity> q2 = em.createQuery(c2);
-    List<HostRoleCommandEntity> r2 = q2.getResultList();
-
-    HostRoleCommandDAO hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
-    if (r2 != null && !r2.isEmpty()) {
-      for (HostRoleCommandEntity entity : r2) {
-        entity.setStatus(HostRoleStatus.ABORTED);
-        hostRoleCommandDAO.merge(entity);
+    executeInTransaction(new Runnable() {
+      @Override
+      public void run() {
+        EntityManager em = getEntityManagerProvider().get();
+        CriteriaBuilder cb = em.getCriteriaBuilder();
+        CriteriaQuery<HostRoleCommandEntity> c2 = cb.createQuery(HostRoleCommandEntity.class);
+        Root<HostRoleCommandEntity> hrc = c2.from(HostRoleCommandEntity.class);
+        List<HostRoleStatus> statuses = new ArrayList<HostRoleStatus>() {{
+          add(HostRoleStatus.PENDING);
+          add(HostRoleStatus.QUEUED);
+          add(HostRoleStatus.IN_PROGRESS);
+        }};
+        Expression<String> exp = hrc.get("status");
+        Predicate predicate = exp.in(statuses);
+        c2.select(hrc).where(predicate);
+
+        TypedQuery<HostRoleCommandEntity> q2 = em.createQuery(c2);
+        List<HostRoleCommandEntity> r2 = q2.getResultList();
+
+        HostRoleCommandDAO hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
+        if (r2 != null && !r2.isEmpty()) {
+          for (HostRoleCommandEntity entity : r2) {
+            entity.setStatus(HostRoleStatus.ABORTED);
+            hostRoleCommandDAO.merge(entity);
+          }
+        }
       }
-    }
+    });
 
     // Stack version changes from HDPLocal to HDP
     stackUpgradeUtil.updateStackDetails("HDP", null);
@@ -438,10 +432,7 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
       "UNION ALL " +
       "SELECT 'user_id_seq', nextval('users_user_id_seq') " +
       "UNION ALL " +
-      "SELECT 'host_role_command_id_seq', COALESCE((SELECT max(task_id) FROM host_role_command),
1) + 50 " +
-      "UNION ALL " +
-      "SELECT 'configgroup_id_seq', 1";
-    //TODO verify issue with configgroup_id_seq which was added later, possibly need to be
added for mysql and oracle and separated for postgres
+      "SELECT 'host_role_command_id_seq', COALESCE((SELECT max(task_id) FROM host_role_command),
1) + 50 ";
   }
 
   private String getPostgresRequestUpgradeQuery() {


Mime
View raw message