ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-13478 Upgrade path on ORA 1.6.1 -> 2.0.1 -> 2.1.1 (dsen)
Date Thu, 22 Oct 2015 17:54:09 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 85475b03a -> 077b96e15


AMBARI-13478 Upgrade path on ORA 1.6.1 -> 2.0.1 -> 2.1.1 (dsen)


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

Branch: refs/heads/branch-2.1
Commit: 077b96e15199e0cf2937f44619896fefbeae0b21
Parents: 85475b0
Author: Dmytro Sen <dsen@apache.org>
Authored: Thu Oct 22 20:51:46 2015 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Thu Oct 22 20:53:26 2015 +0300

----------------------------------------------------------------------
 .../ambari/server/orm/DBAccessorImpl.java       | 26 ++++++++++++++++++--
 .../server/upgrade/UpgradeCatalog210.java       | 10 +++++++-
 .../ambari/server/orm/DBAccessorImplTest.java   | 21 ++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/077b96e1/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 cd47252..abd05bc 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
@@ -293,6 +293,27 @@ public class DBAccessorImpl implements DBAccessor {
     return false;
   }
 
+  public String getCheckedForeignKey(String tableName, String fkName) throws SQLException
{
+    DatabaseMetaData metaData = getDatabaseMetaData();
+
+    ResultSet rs = metaData.getImportedKeys(null, null, convertObjectName(tableName));
+
+    if (rs != null) {
+      try {
+        while (rs.next()) {
+          if (StringUtils.equalsIgnoreCase(fkName, rs.getString("FK_NAME"))) {
+            return rs.getString("FK_NAME");
+          }
+        }
+      } finally {
+        rs.close();
+      }
+    }
+
+    LOG.warn("FK {} not found for table {}", convertObjectName(fkName), convertObjectName(tableName));
+
+    return null;
+  }
   @Override
   public boolean tableHasForeignKey(String tableName, String refTableName,
           String columnName, String refColumnName) throws SQLException {
@@ -747,8 +768,9 @@ public class DBAccessorImpl implements DBAccessor {
   @Override
   public void dropFKConstraint(String tableName, String constraintName, boolean ignoreFailure)
throws SQLException {
     // ToDo: figure out if name of index and constraint differs
-    if (tableHasForeignKey(convertObjectName(tableName), constraintName)) {
-      String query = dbmsHelper.getDropFKConstraintStatement(tableName, constraintName);
+    String checkedConstraintName = getCheckedForeignKey(convertObjectName(tableName), constraintName);
+    if (checkedConstraintName != null) {
+      String query = dbmsHelper.getDropFKConstraintStatement(tableName, checkedConstraintName);
       executeQuery(query, ignoreFailure);
     } else {
       LOG.warn("Constraint {} from {} table not found, nothing to drop", constraintName,
tableName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/077b96e1/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 308e7c9..41754d9 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
@@ -486,6 +486,14 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     dbAccessor.dropFKConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hstcmpnntdesiredstatecmpnntnme");
     dbAccessor.dropFKConstraint(SERVICE_CONFIG_HOSTS_TABLE, "FK_scvhosts_scv");
 
+    //These FK's hasn't been deleted previously due to MySQL case sensitivity
+    if (databaseType == Configuration.DatabaseType.MYSQL) {
+      dbAccessor.dropFKConstraint(CONFIG_GROUP_HOST_MAPPING_TABLE, "FK_configgrouphostmapping_config_group_id");
+      dbAccessor.dropFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_ClusterHostMapping_cluster_id");
+      dbAccessor.dropFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_kerberos_principal_host_principal_name");
+      dbAccessor.dropFKConstraint(SERVICE_CONFIG_HOSTS_TABLE, "FK_serviceconfighosts_service_config_id");
+    }
+
     if (databaseType == Configuration.DatabaseType.DERBY) {
       for (String tableName : tablesWithHostNameInPK) {
         String constraintName = getDerbyTableConstraintName("p", tableName);
@@ -1346,7 +1354,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       public void run() {
         EntityManager em = getEntityManagerProvider().get();
         Query nativeQuery = em.createNativeQuery("UPDATE alert_definition SET alert_source=?1,
hash=?2 WHERE " +
-                "definition_name=?3");
+          "definition_name=?3");
         nativeQuery.setParameter(1, source);
         nativeQuery.setParameter(2, newHash);
         nativeQuery.setParameter(3, alertName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/077b96e1/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 05856b3..c867c9f 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
@@ -320,6 +320,27 @@ public class DBAccessorImplTest {
   }
 
   @Test
+  public void testGetCheckedForeignKey() throws Exception {
+    String tableName = getFreeTableName();
+    createMyTable(tableName);
+
+    DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
+
+    List<DBColumnInfo> columns = new ArrayList<DBColumnInfo>();
+    columns.add(new DBColumnInfo("fid", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("fname", String.class, null, null, false));
+
+    String foreignTableName = getFreeTableName();
+    dbAccessor.createTable(foreignTableName, columns, "fid");
+
+    Statement statement = dbAccessor.getConnection().createStatement();
+    statement.execute("ALTER TABLE " + foreignTableName + " ADD CONSTRAINT FK_test1 FOREIGN
KEY (fid) REFERENCES " +
+            tableName + " (id)");
+
+    Assert.assertEquals("FK_TEST1", dbAccessor.getCheckedForeignKey(foreignTableName, "fk_test1"));
+  }
+
+  @Test
   public void testTableExists() throws Exception {
     DBAccessorImpl dbAccessor = injector.getInstance(DBAccessorImpl.class);
 


Mime
View raw message