Explorar o código

AMBARI-4843. Ambari DDL for MySQL should not create ambarirca database.(vbrodetskyi)

Vitaly Brodetskyi %!s(int64=11) %!d(string=hai) anos
pai
achega
d8cfceb9d3

+ 5 - 0
ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java

@@ -94,6 +94,7 @@ public class Configuration {
   public static final String CLIENT_API_SSL_KEY_NAME_KEY = "client.api.ssl.key_name";
   public static final String SERVER_DB_NAME_KEY = "server.jdbc.database";
   public static final String SERVER_DB_NAME_DEFAULT = "ambari";
+  public static final String SERVER_JDBC_SCHEMA_NAME = "server.jdbc.schema";
   public static final String POSTGRES_DB_NAME = "postgres";
   public static final String ORACLE_DB_NAME = "oracle";
   public static final String MYSQL_DB_NAME = "mysql";
@@ -941,4 +942,8 @@ public class Configuration {
   public String getResourceDirPath() {
     return properties.getProperty(RESOURCES_DIR_KEY, RESOURCES_DIR_DEFAULT);
   }
+
+  public String getServerJDBCSchemaName() {
+    return properties.getProperty(SERVER_JDBC_SCHEMA_NAME, SERVER_DB_NAME_DEFAULT);
+  }
 }

+ 19 - 0
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java

@@ -234,6 +234,19 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
       }
     }
 
+    //Move tables from ambarirca db to ambari db; drop ambarirca; Mysql
+    if (getDbType().equals(Configuration.MYSQL_DB_NAME)) {
+      String dbName = configuration.getServerJDBCSchemaName();
+      moveRCATableInMySQL("workflow", dbName);
+      moveRCATableInMySQL("job", dbName);
+      moveRCATableInMySQL("task", dbName);
+      moveRCATableInMySQL("taskAttempt", dbName);
+      moveRCATableInMySQL("hdfsEvent", dbName);
+      moveRCATableInMySQL("mapreduceEvent", dbName);
+      moveRCATableInMySQL("clusterEvent", dbName);
+      dbAccessor.executeQuery("DROP DATABASE IF EXISTS ambarirca;");
+    }
+
     // ========================================================================
     // Add constraints
 
@@ -255,6 +268,12 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
     updateMetaInfoVersion(getTargetVersion());
   }
 
+  private void moveRCATableInMySQL(String tableName, String dbName) throws SQLException {
+    if (!dbAccessor.tableExists(tableName)) {
+      dbAccessor.executeQuery(String.format("RENAME TABLE ambarirca.%s TO %s.%s;", tableName, dbName, tableName), true);
+    }
+  }
+
   @Override
   public void executeDMLUpdates() throws AmbariException, SQLException {
     // Service Config mapping

+ 0 - 3
ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql

@@ -286,9 +286,6 @@ create index idx_qrtz_ft_tg on QRTZ_FIRED_TRIGGERS(SCHED_NAME,TRIGGER_GROUP);
 
 commit;
 
-CREATE DATABASE ambarirca;
-USE ambarirca;
-
 CREATE TABLE workflow (
   workflowId VARCHAR(255), workflowName TEXT,
   parentWorkflowId VARCHAR(255),