[08/29] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
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/b0271155 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b0271155 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b0271155 Branch: refs/heads/branch-feature-AMBARI-21348 Commit: b0271155b3a80945aba2b9989caabe9a96428031 Parents: 18b1035 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:33:05 2017 +0200 -- .../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/b0271155/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/b0271155/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 + } }
[12/36] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
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/5c874ccb Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5c874ccb Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5c874ccb Branch: refs/heads/feature-branch-AMBARI-21307 Commit: 5c874ccb40b282e5074588906cb7de1f7eeae614 Parents: a3681c0 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:31:49 2017 +0200 -- .../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/5c874ccb/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 13e7d7d..83ea8e1 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 @@ -1411,7 +1411,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/5c874ccb/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 ca2674c..b4ffbf1 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 @@ -638,4 +638,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 + } }
[50/63] [abbrv] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
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/5c874ccb Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5c874ccb Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5c874ccb Branch: refs/heads/branch-feature-logsearch-ui Commit: 5c874ccb40b282e5074588906cb7de1f7eeae614 Parents: a3681c0 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:31:49 2017 +0200 -- .../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/5c874ccb/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 13e7d7d..83ea8e1 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 @@ -1411,7 +1411,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/5c874ccb/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 ca2674c..b4ffbf1 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 @@ -638,4 +638,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 + } }
[22/33] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
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/5c874ccb Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5c874ccb Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5c874ccb Branch: refs/heads/branch-feature-AMBARI-20859 Commit: 5c874ccb40b282e5074588906cb7de1f7eeae614 Parents: a3681c0 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:31:49 2017 +0200 -- .../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/5c874ccb/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 13e7d7d..83ea8e1 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 @@ -1411,7 +1411,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/5c874ccb/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 ca2674c..b4ffbf1 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 @@ -638,4 +638,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 + } }
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 DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Siddharth Wagle 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 + } }
[2/2] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
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/b0271155 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b0271155 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b0271155 Branch: refs/heads/branch-2.5 Commit: b0271155b3a80945aba2b9989caabe9a96428031 Parents: 18b1035 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:33:05 2017 +0200 -- .../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/b0271155/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/b0271155/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 + } }
[1/2] ambari git commit: AMBARI-21362. Ambari upgrade not idempotent due to column move
Repository: ambari Updated Branches: refs/heads/branch-2.5 18b1035c2 -> b0271155b refs/heads/trunk a3681c019 -> 5c874ccb4 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/5c874ccb Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5c874ccb Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5c874ccb Branch: refs/heads/trunk Commit: 5c874ccb40b282e5074588906cb7de1f7eeae614 Parents: a3681c0 Author: Attila DoroszlaiAuthored: Tue Jun 27 14:33:27 2017 +0200 Committer: Attila Doroszlai Committed: Wed Jun 28 18:31:49 2017 +0200 -- .../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/5c874ccb/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 13e7d7d..83ea8e1 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 @@ -1411,7 +1411,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/5c874ccb/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 ca2674c..b4ffbf1 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 @@ -638,4 +638,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 + } }