You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2015/05/28 18:12:28 UTC

ambari git commit: AMBARI-11487 - Changed Configurations During Upgrade Are Reverted During Finalize (jonathanhurley)

Repository: ambari
Updated Branches:
  refs/heads/trunk e2b8a0e92 -> b04fb769a


AMBARI-11487 - Changed Configurations During Upgrade Are Reverted During Finalize (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: b04fb769a3bd6ef7a3968f01a374bd08490502a6
Parents: e2b8a0e
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Thu May 28 10:53:02 2015 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu May 28 12:12:21 2015 -0400

----------------------------------------------------------------------
 .../ambari/server/orm/dao/ClusterDAO.java       | 40 ++++++++++++++++++--
 .../apache/ambari/server/state/ConfigImpl.java  | 11 +++++-
 .../server/state/cluster/ClusterImpl.java       | 15 ++++----
 .../server/state/cluster/ClusterTest.java       | 11 ++++++
 4 files changed, 63 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b04fb769/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
index 0ac952c..6e55128 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
@@ -18,7 +18,6 @@
 
 package org.apache.ambari.server.orm.dao;
 
-import java.math.BigDecimal;
 import java.util.List;
 
 import javax.persistence.EntityManager;
@@ -238,7 +237,7 @@ public class ClusterDAO {
 
   /**
    * Retrieve entity data from DB
-   * 
+   *
    * @param clusterEntity
    *          entity to refresh
    */
@@ -247,11 +246,44 @@ public class ClusterDAO {
     entityManagerProvider.get().refresh(clusterEntity);
   }
 
-  @Transactional
+  /**
+   * Merge the specified entity into the current persistence context.
+   *
+   * @param clusterEntity
+   *          the entity to merge (not {@code null}).
+   * @return the managed entity which was merged (never {@code null}).
+   */
   public ClusterEntity merge(ClusterEntity clusterEntity) {
-    return entityManagerProvider.get().merge(clusterEntity);
+    return merge(clusterEntity, false);
+  }
+
+  /**
+   * Merge the specified entity into the current persistence context, optionally
+   * instructing the {@link EntityManager} to write any queued persist/merges
+   * into the database immediately.
+   *
+   * @param clusterEntity
+   *          the entity to merge (not {@code null}).
+   * @param flush
+   *          if {@code true} then {@link EntityManager#flush()} will be invoked
+   *          immediately after the merge.
+   * @return the managed entity which was merged (never {@code null}).
+   */
+  @Transactional
+  public ClusterEntity merge(ClusterEntity clusterEntity, boolean flush) {
+    EntityManager entityManager = entityManagerProvider.get();
+    clusterEntity = entityManager.merge(clusterEntity);
+
+    // force any queued persist/merges to be written to the database, including
+    // the merge from above
+    if (flush) {
+      entityManager.flush();
+    }
+
+    return clusterEntity;
   }
 
+
   @Transactional
   public void remove(ClusterEntity clusterEntity) {
     entityManagerProvider.get().remove(merge(clusterEntity));

http://git-wip-us.apache.org/repos/asf/ambari/blob/b04fb769/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
index 1543ad7..71604c1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
@@ -221,7 +221,10 @@ public class ConfigImpl implements Config {
 
       clusterDAO.createConfig(entity);
       clusterEntity.getClusterConfigEntities().add(entity);
-      clusterDAO.merge(clusterEntity);
+
+      // save the entity, forcing a flush to ensure the refresh picks up the
+      // newest data
+      clusterDAO.merge(clusterEntity, true);
       cluster.refresh();
     } else {
       // only supporting changes to the properties
@@ -244,7 +247,11 @@ public class ConfigImpl implements Config {
             getType(), getVersion());
 
         entity.setData(gson.toJson(getProperties()));
-        clusterDAO.merge(clusterEntity);
+
+        // save the entity, forcing a flush to ensure the refresh picks up the
+        // newest data
+        clusterDAO.merge(clusterEntity, true);
+        cluster.refresh();
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b04fb769/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 98f7cfc..0d1bccd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -616,7 +616,7 @@ public class ClusterImpl implements Cluster {
       clusterEntity.setClusterName(clusterName);
 
       // RollbackException possibility if UNIQUE constraint violated
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
       clusters.updateClusterName(oldName, clusterName);
     } finally {
       clusterGlobalLock.writeLock().unlock();
@@ -900,7 +900,7 @@ public class ClusterImpl implements Cluster {
           stackId.getStackVersion());
 
       clusterEntity.setDesiredStack(stackEntity);
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
 
       if (cascade) {
         for (Service service : getServices().values()) {
@@ -960,7 +960,7 @@ public class ClusterImpl implements Cluster {
     clusterGlobalLock.writeLock().lock();
     try {
       clusterEntity.setProvisioningState(provisioningState);
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
     } finally {
       clusterGlobalLock.writeLock().unlock();
     }
@@ -988,7 +988,7 @@ public class ClusterImpl implements Cluster {
     clusterGlobalLock.writeLock().lock();
     try {
       clusterEntity.setSecurityType(securityType);
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
     } finally {
       clusterGlobalLock.writeLock().unlock();
     }
@@ -2233,7 +2233,7 @@ public class ClusterImpl implements Cluster {
           entity.setSelected(0);
         }
       }
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
 
       for (ClusterConfigEntity configEntity : serviceConfigEntity.getClusterConfigEntities()) {
         selectConfig(configEntity.getType(), configEntity.getTag(), user);
@@ -2309,8 +2309,7 @@ public class ClusterImpl implements Cluster {
     entity.setTag(tag);
     entities.add(entity);
 
-    clusterDAO.merge(clusterEntity);
-
+    clusterEntity = clusterDAO.merge(clusterEntity);
   }
 
   @Transactional
@@ -2718,7 +2717,7 @@ public class ClusterImpl implements Cluster {
         }
       }
 
-      clusterDAO.merge(clusterEntity);
+      clusterEntity = clusterDAO.merge(clusterEntity);
 
       cacheConfigurations();
     } finally {

http://git-wip-us.apache.org/repos/asf/ambari/blob/b04fb769/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index 710c046..409b955 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -1961,5 +1961,16 @@ public class ClusterTest {
     assertTrue(clusterConfigEntity.getData().contains("two"));
     assertTrue(clusterConfigEntity.getData().contains("three"));
     assertTrue(clusterConfigEntity.getData().contains("four"));
+
+    cluster.refresh();
+
+    clusterEntity = clusterDAO.findByName("c1");
+    assertEquals(1, clusterEntity.getClusterConfigEntities().size());
+    clusterConfigEntity = clusterEntity.getClusterConfigEntities().iterator().next();
+    assertTrue(clusterConfigEntity.getData().contains("one"));
+    assertTrue(clusterConfigEntity.getData().contains("two"));
+    assertTrue(clusterConfigEntity.getData().contains("three"));
+    assertTrue(clusterConfigEntity.getData().contains("four"));
+
   }
 }