You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2015/07/07 10:37:26 UTC
[2/2] ambari git commit: AMBARI-12305. Ambari-server upgrade from
1.6.1 to 2.1.0 fails, dml update error (aonishuk)
AMBARI-12305. Ambari-server upgrade from 1.6.1 to 2.1.0 fails, dml update error (aonishuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ff96ed45
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ff96ed45
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ff96ed45
Branch: refs/heads/branch-2.1
Commit: ff96ed451d6dccaf211e69db1a391cf7009b5803
Parents: 22740e1
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Tue Jul 7 11:37:16 2015 +0300
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Tue Jul 7 11:37:16 2015 +0300
----------------------------------------------------------------------
.../apache/ambari/server/orm/DBAccessor.java | 4 +-
.../ambari/server/orm/DBAccessorImpl.java | 96 ++++++++++++++------
.../server/upgrade/UpgradeCatalog170.java | 84 ++++++-----------
.../server/upgrade/UpgradeCatalog200.java | 8 +-
.../server/upgrade/UpgradeCatalog210.java | 8 +-
.../server/upgrade/UpgradeCatalog200Test.java | 4 +-
.../server/upgrade/UpgradeCatalog210Test.java | 19 +++-
7 files changed, 124 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
index a5960a0..9104624 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/DBAccessor.java
@@ -464,7 +464,7 @@ public interface DBAccessor {
* @return the string list of index names
* @throws SQLException
*/
- //List<String> getIndexesList(String tableName, boolean unique) throws SQLException;
+ List<String> getIndexesList(String tableName, boolean unique) throws SQLException;
/**
* Check if index is already in scheme
@@ -476,7 +476,7 @@ public interface DBAccessor {
* name of the index to check
* @return true if index present in the schema
*/
- //boolean tableHasIndex(String tableName, boolean unique, String indexName) throws SQLException;
+ boolean tableHasIndex(String tableName, boolean unique, String indexName) throws SQLException;
/**
* Gets the column's SQL type
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/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 3a1d237..ef65853 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
@@ -350,11 +350,23 @@ public class DBAccessorImpl implements DBAccessor {
}
@Override
+ public boolean tableHasIndex(String tableName, boolean unique, String indexName) throws SQLException{
+ if (tableExists(tableName)){
+ List<String> indexList = getIndexesList(tableName, false);
+ return (CustomStringUtils.containsCaseInsensitive(indexName, indexList));
+ }
+ return false;
+ }
+
+ @Override
public void createIndex(String indexName, String tableName,
String... columnNames) throws SQLException {
- String query = dbmsHelper.getCreateIndexStatement(indexName, tableName, columnNames);
-
- executeQuery(query);
+ if (!tableHasIndex(tableName, false, indexName)) {
+ String query = dbmsHelper.getCreateIndexStatement(indexName, tableName, columnNames);
+ executeQuery(query);
+ } else {
+ LOG.info("Index {} already exist, skipping creation, table = {}", indexName, tableName);
+ }
}
@Override
@@ -440,7 +452,7 @@ public class DBAccessorImpl implements DBAccessor {
@Override
public void addUniqueConstraint(String tableName, String constraintName, String... columnNames)
throws SQLException {
- if (!tableHasConstraint(tableName, constraintName)) {
+ if (!tableHasConstraint(tableName, constraintName) && tableHasColumn(tableName, columnNames)) {
String query = dbmsHelper.getAddUniqueConstraintStatement(tableName, constraintName, columnNames);
try {
executeQuery(query);
@@ -449,7 +461,7 @@ public class DBAccessorImpl implements DBAccessor {
throw e;
}
} else {
- LOG.info("Unique constraint {} already exists, skipping", constraintName);
+ LOG.info("Unique constraint {} already exists or columns {} not found, skipping", constraintName, StringUtils.join(columnNames, ", "));
}
}
@@ -457,7 +469,6 @@ public class DBAccessorImpl implements DBAccessor {
public void addPKConstraint(String tableName, String constraintName, boolean ignoreErrors, String... columnName) throws SQLException {
if (!tableHasPrimaryKey(tableName, null) && tableHasColumn(tableName, columnName)) {
String query = dbmsHelper.getAddPrimaryKeyConstraintStatement(tableName, constraintName, columnName);
-
executeQuery(query, ignoreErrors);
} else {
LOG.warn("Primary constraint {} not altered to table {} as column {} not present or constraint already exists",
@@ -861,7 +872,9 @@ public class DBAccessorImpl implements DBAccessor {
return res;
}
- private ResultSetMetaData getColumnMetadata(String tableName, String columnName) throws SQLException {
+ @Override
+ public Class getColumnClass(String tableName, String columnName)
+ throws SQLException, ClassNotFoundException {
// We doesn't require any actual result except metadata, so WHERE clause shouldn't match
String query = String.format("SELECT %s FROM %s WHERE 1=2", convertObjectName(columnName), convertObjectName(tableName));
Statement statement = null;
@@ -869,7 +882,7 @@ public class DBAccessorImpl implements DBAccessor {
try {
statement = getConnection().createStatement();
rs = statement.executeQuery(query);
- return rs.getMetaData();
+ return Class.forName(rs.getMetaData().getColumnClassName(1));
} finally {
if (statement != null) {
statement.close();
@@ -881,39 +894,46 @@ public class DBAccessorImpl implements DBAccessor {
}
@Override
- public Class getColumnClass(String tableName, String columnName)
- throws SQLException, ClassNotFoundException {
- ResultSetMetaData rsmd = getColumnMetadata(tableName, columnName);
- return Class.forName(rsmd.getColumnClassName(1));
- }
-
- @Override
public boolean isColumnNullable(String tableName, String columnName) throws SQLException {
- ResultSetMetaData rsmd = getColumnMetadata(tableName, columnName);
- return !(rsmd.isNullable(1) == ResultSetMetaData.columnNoNulls);
+ // We doesn't require any actual result except metadata, so WHERE clause shouldn't match
+ String query = String.format("SELECT %s FROM %s WHERE 1=2", convertObjectName(columnName), convertObjectName(tableName));
+ Statement statement = null;
+ ResultSet rs = null;
+ try {
+ statement = getConnection().createStatement();
+ rs = statement.executeQuery(query);
+ return !(rs.getMetaData().isNullable(1) == ResultSetMetaData.columnNoNulls);
+ } finally {
+ if (statement != null) {
+ statement.close();
+ }
+ if (rs != null) {
+ rs.close();
+ }
+ }
}
@Override
public void setColumnNullable(String tableName, DBAccessor.DBColumnInfo columnInfo, boolean nullable)
throws SQLException {
+ String columnName = columnInfo.getName();
- String statement = dbmsHelper.getSetNullableStatement(tableName, columnInfo, nullable);
- executeQuery(statement);
+ // if column is already in nullable state, we shouldn't do anything. This is important for Oracle
+ if (isColumnNullable(tableName, columnName) != nullable) {
+ String query = dbmsHelper.getSetNullableStatement(tableName, columnInfo, nullable);
+ executeQuery(query);
+ } else {
+ LOG.info("Column nullability property is not changed due to {} column from {} table is already in {} state, skipping",
+ columnName, tableName, (nullable) ? "nullable" : "not nullable");
+ }
}
@Override
public void setColumnNullable(String tableName, String columnName, boolean nullable)
throws SQLException {
try {
- // if column is already in nullable state, we shouldn't do anything. This is important for Oracle
- if (isColumnNullable(tableName, columnName) != nullable) {
- Class columnClass = getColumnClass(tableName, columnName);
- String query = dbmsHelper.getSetNullableStatement(tableName, new DBColumnInfo(columnName, columnClass), nullable);
- executeQuery(query);
- } else {
- LOG.info("Column nullability property is not changed due to {} column from {} table is already in {} state, skipping",
- columnName, tableName, (nullable) ? "nullable" : "not nullable");
- }
+ Class columnClass = getColumnClass(tableName, columnName);
+ setColumnNullable(tableName,new DBColumnInfo(columnName, columnClass), nullable);
} catch (ClassNotFoundException e) {
LOG.error("Could not modify table=[], column={}, error={}", tableName, columnName, e.getMessage());
}
@@ -942,4 +962,24 @@ public class DBAccessorImpl implements DBAccessor {
alterColumn(tableName, new DBColumnInfo(columnName, toType, null));
}
+ @Override
+ public List<String> getIndexesList(String tableName, boolean unique)
+ throws SQLException{
+ ResultSet rs = getDatabaseMetaData().getIndexInfo(null, null, convertObjectName(tableName), unique, false);
+ List<String> indexList = new ArrayList<String>();
+ if (rs != null){
+ try{
+ while (rs.next()) {
+ String indexName = rs.getString(convertObjectName("index_name"));
+ if (indexName != null) { // hack for Oracle database, as she could return null values
+ indexList.add(indexName);
+ }
+ }
+ }finally {
+ rs.close();
+ }
+ }
+ return indexList;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
index 00e033b..c54039f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
@@ -96,6 +96,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -429,37 +430,24 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
dbAccessor.addColumn("configgroup", new DBColumnInfo("service_name", String.class, 255));
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_definition_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_group_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_target_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_history_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_notice_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('alert_current_id_seq', 0)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('group_id_seq', 1)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('member_id_seq', 1)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('resource_type_id_seq', 4)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('resource_id_seq', 2)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('principal_type_id_seq', 3)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('principal_id_seq', 2)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('permission_id_seq', 5)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('privilege_id_seq', 1)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('service_config_id_seq', 1)", false);
-
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('service_config_application_id_seq', 1)", false);
+ addSequences(Arrays.asList(
+ "alert_definition_id_seq",
+ "alert_group_id_seq",
+ "alert_target_id_seq",
+ "alert_history_id_seq",
+ "alert_notice_id_seq",
+ "alert_current_id_seq"
+ ), 0L, false);
+ addSequence("group_id_seq", 1L, false);
+ addSequence("member_id_seq", 1L, false);
+ addSequence("resource_type_id_seq", 4L, false);
+ addSequence("resource_id_seq", 2L, false);
+ addSequence("principal_type_id_seq", 3L, false);
+ addSequence("principal_id_seq", 2L, false);
+ addSequence("permission_id_seq", 5L, false);
+ addSequence("privilege_id_seq", 1L, false);
+ addSequence("service_config_id_seq", 1L, false);
+ addSequence("service_config_application_id_seq", 1L, false);
long count = 1;
@@ -484,7 +472,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
}
}
- dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, sequence_value) VALUES('config_id_seq', " + count + ")", false);
+ addSequence("config_id_seq", count, false);
dbAccessor.addFKConstraint("users", "FK_users_principal_id", "principal_id", "adminprincipal", "principal_id", true);
dbAccessor.addFKConstraint("clusters", "FK_clusters_resource_id", "resource_id", "adminresource", "resource_id", true);
@@ -499,9 +487,9 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
dbAccessor.addFKConstraint("members", "FK_members_user_id", "user_id", "users", "user_id", true);
dbAccessor.addFKConstraint("members", "FK_members_group_id", "group_id", "groups", "group_id", true);
- dbAccessor.executeQuery("ALTER TABLE groups ADD CONSTRAINT UNQ_groups_0 UNIQUE (group_name, ldap_group)");
- dbAccessor.executeQuery("ALTER TABLE members ADD CONSTRAINT UNQ_members_0 UNIQUE (group_id, user_id)");
- dbAccessor.executeQuery("ALTER TABLE adminpermission ADD CONSTRAINT UQ_perm_name_resource_type_id UNIQUE (permission_name, resource_type_id)");
+ dbAccessor.addUniqueConstraint("groups", "UNQ_groups_0", "group_name", "ldap_group");
+ dbAccessor.addUniqueConstraint("members", "UNQ_members_0", "group_id", "user_id");
+ dbAccessor.addUniqueConstraint("adminpermission", "UQ_perm_name_resource_type_id", "permission_name", "resource_type_id");
}
/**
@@ -511,7 +499,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
private void addConfigAttributesColumn(String tableName) throws SQLException {
final DatabaseType databaseType = configuration.getDatabaseType();
if (databaseType == DatabaseType.ORACLE) {
- dbAccessor.executeQuery("ALTER TABLE " + tableName + " ADD config_attributes CLOB NULL");
+ dbAccessor.addColumn(tableName, new DBColumnInfo("config_attributes", char[].class));
} else {
DBColumnInfo clusterConfigAttributesColumn = new DBColumnInfo(
"config_attributes", Character[].class, null, null, true);
@@ -963,11 +951,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
"fk_alert_def_cluster_id",
"cluster_id", "clusters", "cluster_id", false);
- dbAccessor.executeQuery(
- "ALTER TABLE "
- + ALERT_TABLE_DEFINITION
- + " ADD CONSTRAINT uni_alert_def_name UNIQUE (cluster_id,definition_name)",
- false);
+ dbAccessor.addUniqueConstraint(ALERT_TABLE_DEFINITION, "uni_alert_def_name", "cluster_id", "definition_name");
// alert_history
columns = new ArrayList<DBColumnInfo>();
@@ -1014,9 +998,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
"fk_alert_current_history_id", "history_id", ALERT_TABLE_HISTORY,
"alert_id", false);
- dbAccessor.executeQuery("ALTER TABLE " + ALERT_TABLE_CURRENT
- + " ADD CONSTRAINT uni_alert_current_hist_id UNIQUE (history_id)",
- false);
+ dbAccessor.addUniqueConstraint(ALERT_TABLE_CURRENT, "uni_alert_current_hist_id", "history_id");
// alert_group
columns = new ArrayList<DBColumnInfo>();
@@ -1027,11 +1009,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
columns.add(new DBColumnInfo("service_name", String.class, 255, null, true));
dbAccessor.createTable(ALERT_TABLE_GROUP, columns, "group_id");
- dbAccessor.executeQuery(
- "ALTER TABLE "
- + ALERT_TABLE_GROUP
- + " ADD CONSTRAINT uni_alert_group_name UNIQUE (cluster_id,group_name)",
- false);
+ dbAccessor.addUniqueConstraint(ALERT_TABLE_GROUP, "uni_alert_group_name", "cluster_id", "group_name");
// alert_target
columns = new ArrayList<DBColumnInfo>();
@@ -1042,9 +1020,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
columns.add(new DBColumnInfo("description", String.class, 1024, null, true));
dbAccessor.createTable(ALERT_TABLE_TARGET, columns, "target_id");
- dbAccessor.executeQuery("ALTER TABLE " + ALERT_TABLE_TARGET
- + " ADD CONSTRAINT uni_alert_target_name UNIQUE (target_name)",
- false);
+ dbAccessor.addUniqueConstraint(ALERT_TABLE_TARGET, "uni_alert_target_name", "target_name");
// alert_group_target
columns = new ArrayList<DBColumnInfo>();
@@ -1092,9 +1068,7 @@ public class UpgradeCatalog170 extends AbstractUpgradeCatalog {
dbAccessor.addFKConstraint(ALERT_TABLE_NOTICE, "fk_alert_notice_hist_id",
"history_id", ALERT_TABLE_HISTORY, "alert_id", false);
- dbAccessor.executeQuery("ALTER TABLE " + ALERT_TABLE_NOTICE
- + " ADD CONSTRAINT uni_alert_notice_uuid UNIQUE (uuid)", false);
-
+ dbAccessor.addUniqueConstraint(ALERT_TABLE_NOTICE, "uni_alert_notice_uuid", "uuid");
// Indexes
dbAccessor.createIndex("idx_alert_history_def_id", ALERT_TABLE_HISTORY,
"alert_definition_id");
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
index 1a9bfaa..2c9bf30 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog200.java
@@ -241,7 +241,9 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
// Foreign Key Constraints
dbAccessor.addFKConstraint("cluster_version", "FK_cluster_version_cluster_id", "cluster_id", "clusters", "cluster_id", false);
dbAccessor.addFKConstraint("cluster_version", "FK_cluster_version_repovers_id", "repo_version_id", "repo_version", "repo_version_id", false);
- dbAccessor.addFKConstraint("host_version", "FK_host_version_host_name", "host_name", "hosts", "host_name", false);
+ if (dbAccessor.tableHasColumn("host_version", "host_name")) {
+ dbAccessor.addFKConstraint("host_version", "FK_host_version_host_name", "host_name", "hosts", "host_name", false);
+ }
dbAccessor.addFKConstraint("host_version", "FK_host_version_repovers_id", "repo_version_id", "repo_version", "repo_version_id", false);
// New sequences
@@ -305,7 +307,9 @@ public class UpgradeCatalog200 extends AbstractUpgradeCatalog {
columns.add(new DBColumnInfo("principal_name", String.class, 255, null, false));
columns.add(new DBColumnInfo("host_name", String.class, 255, null, false));
dbAccessor.createTable(KERBEROS_PRINCIPAL_HOST_TABLE, columns, "principal_name", "host_name");
- dbAccessor.addFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_hostname", "host_name", "hosts", "host_name", true, false);
+ if (dbAccessor.tableHasColumn(KERBEROS_PRINCIPAL_HOST_TABLE, "host_name")) {
+ dbAccessor.addFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_hostname", "host_name", "hosts", "host_name", true, false);
+ }
dbAccessor.addFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_principalname", "principal_name", KERBEROS_PRINCIPAL_TABLE, "principal_name", true, false);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/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 eb1bab5..3d4d701 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
@@ -266,13 +266,6 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
), 0L, false);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public void onPostUpgrade() throws AmbariException, SQLException {
- cleanupStackUpdates();
- }
private void executeAlertDDLUpdates() throws AmbariException, SQLException {
//Fix latest_text column type to match for all DBMS
@@ -982,6 +975,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
@Override
protected void executePreDMLUpdates() throws AmbariException, SQLException {
executeStackPreDMLUpdates();
+ cleanupStackUpdates();
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
index f28fd8b..484c18d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
@@ -169,7 +169,7 @@ public class UpgradeCatalog200Test {
// Alert Definition
dbAccessor.addColumn(eq("alert_definition"),
- capture(alertDefinitionIgnoreColumnCapture));
+ capture(alertDefinitionIgnoreColumnCapture));
dbAccessor.addColumn(eq("alert_definition"),
capture(alertDefinitionDescriptionColumnCapture));
@@ -246,6 +246,8 @@ public class UpgradeCatalog200Test {
dbAccessor.createTable(eq("kerberos_principal_host"), capture(kerberosPrincipalHostCapture),
eq("principal_name"), eq("host_name"));
+ expect(dbAccessor.tableHasColumn("kerberos_principal_host", "host_name")).andReturn(true).atLeastOnce();
+
dbAccessor.addFKConstraint(eq("kerberos_principal_host"), eq("FK_krb_pr_host_hostname"),
eq("host_name"), eq("hosts"), eq("host_name"), eq(true), eq(false));
http://git-wip-us.apache.org/repos/asf/ambari/blob/ff96ed45/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index 4f96ce9..8708047 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -89,6 +89,7 @@ import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.persist.PersistService;
+import org.powermock.api.easymock.PowerMock;
/**
* {@link org.apache.ambari.server.upgrade.UpgradeCatalog210} unit tests.
@@ -170,16 +171,26 @@ public class UpgradeCatalog210Test {
@Test
public void testExecutePreDMLUpdates() throws Exception {
Method executeStackPreDMLUpdates = UpgradeCatalog210.class.getDeclaredMethod("executeStackPreDMLUpdates");
+ Method cleanupStackUpdates = UpgradeCatalog210.class.getDeclaredMethod("cleanupStackUpdates");
- UpgradeCatalog210 upgradeCatalog210 = createMockBuilder(UpgradeCatalog210.class)
- .addMockedMethod( executeStackPreDMLUpdates) .createMock();
+ final UpgradeCatalog210 upgradeCatalog210 = createMockBuilder(UpgradeCatalog210.class)
+ .addMockedMethod(executeStackPreDMLUpdates)
+ .addMockedMethod(cleanupStackUpdates).createMock();
+
+ final Injector mockInjector = Guice.createInjector(new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(UpgradeCatalog210.class).toInstance(upgradeCatalog210);
+ bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class));
+ bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class));
+ }
+ });
upgradeCatalog210.executeStackPreDMLUpdates();
expectLastCall().once();
replay(upgradeCatalog210);
-
- upgradeCatalog210.executePreDMLUpdates();
+ mockInjector.getInstance(UpgradeCatalog210.class).executePreDMLUpdates();
verify(upgradeCatalog210);
}