You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2017/06/29 22:42:42 UTC

ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move

Repository: ambari
Updated Branches:
  refs/heads/branch-feature-AMBARI-21348 6bab5a537 -> c05393c92


AMBARI-21362. Ambari upgrade not idempotent due to column move


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

Branch: refs/heads/branch-feature-AMBARI-21348
Commit: c05393c921b8cc9c147b228e3b21a9935a148494
Parents: 6bab5a5
Author: Attila Doroszlai <ad...@hortonworks.com>
Authored: Tue Jun 27 14:33:27 2017 +0200
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Thu Jun 29 15:42:10 2017 -0700

----------------------------------------------------------------------
 .../ambari/server/orm/DBAccessorImpl.java       |  5 +++-
 .../ambari/server/orm/DBAccessorImplTest.java   | 29 ++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c05393c9/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
index c11a1dd..f3250b8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessorImpl.java
@@ -1410,7 +1410,10 @@ public class DBAccessorImpl implements DBAccessor {
   public void moveColumnToAnotherTable(String sourceTableName, DBColumnInfo sourceColumn, String sourceIDFieldName,
               String targetTableName, DBColumnInfo targetColumn, String targetIDFieldName, Object initialValue) throws SQLException {
 
-    if (this.tableHasColumn(sourceTableName, sourceIDFieldName)) {
+    if (tableHasColumn(sourceTableName, sourceIDFieldName) &&
+      tableHasColumn(sourceTableName, sourceColumn.getName()) &&
+      tableHasColumn(targetTableName, targetIDFieldName)
+    ) {
 
       final String moveSQL = dbmsHelper.getCopyColumnToAnotherTableStatement(sourceTableName, sourceColumn.getName(),
         sourceIDFieldName, targetTableName, targetColumn.getName(),targetIDFieldName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c05393c9/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
index ea43bb2..d576cc8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/DBAccessorImplTest.java
@@ -639,4 +639,33 @@ public class DBAccessorImplTest {
     }
 
    }
+
+  @Test
+  public void testMoveNonexistentColumnIsNoop() throws Exception {
+    DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
+    String sourceTableName = getFreeTableName();
+    String targetTableName = getFreeTableName();
+    int testRowAmount = 10;
+
+    createMyTable(sourceTableName, "col1");
+    createMyTable(targetTableName, "col1", "col2");
+
+    for (Integer i=0; i < testRowAmount; i++){
+      dbAccessor.insertRow(sourceTableName,
+        new String[] {"id", "col1"},
+        new String[]{i.toString(), String.format("'source,1,%s'", i)}, false);
+
+      dbAccessor.insertRow(targetTableName,
+        new String[] {"id", "col1", "col2"},
+        new String[]{i.toString(), String.format("'target,1,%s'", i), String.format("'target,2,%s'", i)}, false);
+    }
+
+    DBColumnInfo sourceColumn = new DBColumnInfo("col2", String.class, null, null, false);
+    DBColumnInfo targetColumn = new DBColumnInfo("col2", String.class, null, null, false);
+
+    dbAccessor.moveColumnToAnotherTable(sourceTableName, sourceColumn, "id",
+      targetTableName, targetColumn, "id", "initial");
+
+    // should not result in exception due to unknown column in source table
+  }
 }