You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2015/09/11 02:24:36 UTC
ambari git commit: AMBARI-13057. UpgradeCatalogs should use integer
specifiers (ncole)
Repository: ambari
Updated Branches:
refs/heads/branch-2.1 9e3b7d35e -> 902cb2316
AMBARI-13057. UpgradeCatalogs should use integer specifiers (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/902cb231
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/902cb231
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/902cb231
Branch: refs/heads/branch-2.1
Commit: 902cb2316e94bb7c37a54fa4257b0c57dbc8a362
Parents: 9e3b7d3
Author: Nate Cole <nc...@hortonworks.com>
Authored: Thu Sep 10 20:23:48 2015 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Thu Sep 10 20:23:48 2015 -0400
----------------------------------------------------------------------
.../server/upgrade/UpgradeCatalog210.java | 4 ++--
.../server/upgrade/UpgradeCatalog211.java | 13 +++++++-----
.../server/upgrade/UpgradeCatalog211Test.java | 21 +++++++++++++++++---
3 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/902cb231/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 1981514..8fdf640 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
@@ -917,9 +917,9 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
if (count > 0) {
// Delete hosts and host_state table entries for this duplicate host entry
dbAccessor.executeQuery(
- MessageFormat.format("DELETE from {0} WHERE {1} = {2}", HOST_STATE_TABLE, HOST_ID_COL, hostToDeleteId));
+ MessageFormat.format("DELETE from {0} WHERE {1} = {2,number,#}", HOST_STATE_TABLE, HOST_ID_COL, hostToDeleteId));
dbAccessor.executeQuery(
- MessageFormat.format("DELETE from {0} WHERE {1} = {2}", HOSTS_TABLE, HOST_ID_COL, hostToDeleteId));
+ MessageFormat.format("DELETE from {0} WHERE {1} = {2,number,#}", HOSTS_TABLE, HOST_ID_COL, hostToDeleteId));
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/902cb231/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
index c650ae7..cafbc35 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog211.java
@@ -57,6 +57,11 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
*/
private static final Logger LOG = LoggerFactory.getLogger(UpgradeCatalog211.class);
+ // this "id holder" is a field only for a test that verifies "big" 4 digit+
+ // numbers are formatted correctly
+ private AtomicLong m_hcsId = new AtomicLong(1);
+
+
@Inject
DaoUtils daoUtils;
@@ -200,8 +205,6 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
dbAccessor.addColumn(HOST_COMPONENT_STATE_TABLE,
new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, true));
- // insert sequence values
- AtomicLong id = new AtomicLong(1);
Statement statement = null;
ResultSet resultSet = null;
try {
@@ -219,8 +222,8 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
final Long hostId = resultSet.getLong("host_id");
String updateSQL = MessageFormat.format(
- "UPDATE {0} SET {1} = {2} WHERE cluster_id = {3} AND service_name = ''{4}'' AND component_name = ''{5}'' and host_id = {6}",
- HOST_COMPONENT_STATE_TABLE, HOST_COMPONENT_STATE_ID_COLUMN, id.getAndIncrement(),
+ "UPDATE {0} SET {1} = {2,number,#} WHERE cluster_id = {3} AND service_name = ''{4}'' AND component_name = ''{5}'' and host_id = {6,number,#}",
+ HOST_COMPONENT_STATE_TABLE, HOST_COMPONENT_STATE_ID_COLUMN, m_hcsId.getAndIncrement(),
clusterId, serviceName, componentName, hostId);
dbAccessor.executeQuery(updateSQL);
@@ -236,7 +239,7 @@ public class UpgradeCatalog211 extends AbstractUpgradeCatalog {
new DBColumnInfo(HOST_COMPONENT_STATE_ID_COLUMN, Long.class, null, null, false));
// Add sequence for hostcomponentstate id
- addSequence("hostcomponentstate_id_seq", id.get(), false);
+ addSequence("hostcomponentstate_id_seq", m_hcsId.get(), false);
// drop the current PK
String primaryKeyConstraintName = null;
http://git-wip-us.apache.org/repos/asf/ambari/blob/902cb231/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
index b04515a..b692368 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
@@ -18,8 +18,6 @@
package org.apache.ambari.server.upgrade;
-import static org.easymock.EasyMock.anyBoolean;
-import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.expect;
@@ -33,6 +31,7 @@ import java.sql.Statement;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
import javax.persistence.EntityManager;
@@ -90,8 +89,17 @@ public class UpgradeCatalog211Test extends EasyMockSupport {
expectLastCall().andReturn(statement).anyTimes();
statement.executeQuery("SELECT COUNT(*) from ambari_sequences where sequence_name='hostcomponentstate_id_seq'");
expectLastCall().andReturn(resultSet).atLeastOnce();
+
+ ResultSet rs1 = createNiceMock(ResultSet.class);
+ expect(rs1.next()).andReturn(Boolean.TRUE).once();
+
statement.executeQuery(anyObject(String.class));
- expectLastCall().andReturn(resultSet).anyTimes();
+ expectLastCall().andReturn(rs1).anyTimes();
+
+ Capture<String> queryCapture = new Capture<String>();
+ dbAccessor.executeQuery(capture(queryCapture));
+ expectLastCall().once();
+
dbAccessor.setColumnNullable("viewinstanceproperty", "value", true);
expectLastCall().once();
dbAccessor.setColumnNullable("viewinstancedata", "value", true);
@@ -112,9 +120,16 @@ public class UpgradeCatalog211Test extends EasyMockSupport {
f.setAccessible(true);
f.set(upgradeCatalog, configuration);
+ f = UpgradeCatalog211.class.getDeclaredField("m_hcsId");
+ f.setAccessible(true);
+ f.set(upgradeCatalog, new AtomicLong(1001));
+
upgradeCatalog.executeDDLUpdates();
verifyAll();
+ Assert.assertTrue(queryCapture.hasCaptured());
+ Assert.assertTrue(queryCapture.getValue().contains("1001"));
+
// Verify sections
// Example: alertSectionDDL.verify(dbAccessor);
} finally {