Browse Source

AMBARI-1781. Ambari Server should work with MySQL and Oracle where the Ambari Server data might be stored. (smohanty)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1464222 13f79535-47bb-0310-9956-ffa450edef68
Sumit Mohanty 12 years ago
parent
commit
8550a671c7
55 changed files with 1765 additions and 904 deletions
  1. 3 0
      CHANGES.txt
  2. 6 1
      ambari-agent/src/main/puppet/modules/hdp-hadoop/manifests/params.pp
  3. 4 4
      ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/log4j.properties.erb
  4. 58 0
      ambari-server/src/main/java/org/apache/ambari/eventdb/db/OracleConnector.java
  5. 5 6
      ambari-server/src/main/java/org/apache/ambari/eventdb/db/PostgresConnector.java
  6. 20 5
      ambari-server/src/main/java/org/apache/ambari/eventdb/webservice/WorkflowJsonService.java
  7. 2 2
      ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java
  8. 76 19
      ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
  9. 3 3
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
  10. 4 0
      ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java
  11. 46 10
      ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
  12. 47 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/JPATableGenerationStrategy.java
  13. 17 7
      ambari-server/src/main/java/org/apache/ambari/server/orm/PersistenceType.java
  14. 7 2
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
  15. 29 19
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java
  16. 18 14
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java
  17. 54 44
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
  18. 24 22
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
  19. 20 17
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterStateEntity.java
  20. 34 26
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentConfigMappingEntity.java
  21. 13 12
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java
  22. 35 25
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntity.java
  23. 42 33
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredConfigMappingEntity.java
  24. 43 38
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
  25. 42 39
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
  26. 41 37
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostConfigMappingEntity.java
  27. 8 7
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostConfigMappingEntityPK.java
  28. 101 120
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
  29. 83 72
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
  30. 32 40
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
  31. 7 8
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KeyValueEntity.java
  32. 8 8
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/MetainfoEntity.java
  33. 10 15
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RoleEntity.java
  34. 20 19
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RoleSuccessCriteriaEntity.java
  35. 36 31
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
  36. 26 19
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigMappingEntity.java
  37. 29 27
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
  38. 35 30
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java
  39. 34 25
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java
  40. 11 3
      ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java
  41. 139 16
      ambari-server/src/main/python/ambari-server.py
  42. 22 18
      ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
  43. 38 38
      ambari-server/src/main/resources/META-INF/persistence.xml
  44. 172 0
      ambari-server/src/main/resources/mysql-ddl.sql
  45. 209 0
      ambari-server/src/main/resources/oracle-DDL.sql
  46. 23 1
      ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
  47. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java
  48. 5 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
  49. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
  50. 2 1
      ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java
  51. 2 1
      ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java
  52. 2 1
      ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsServiceTest.java
  53. 11 13
      ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationTestModule.java
  54. 1 1
      ambari-server/src/test/java/org/apache/ambari/server/utils/TestStageUtils.java
  55. 4 2
      ambari-server/src/test/python/TestAmbaryServer.py

+ 3 - 0
CHANGES.txt

@@ -544,6 +544,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1781. Ambari Server should work with MySQL and Oracle where the 
+ Ambari Server data might be stored. (smohanty)
+
  AMBARI-1775. Security wizard - Javascript error is thrown when zooKeeper
  is included as a secure service. (jaimin)
 

+ 6 - 1
ambari-agent/src/main/puppet/modules/hdp-hadoop/manifests/params.pp

@@ -176,5 +176,10 @@ class hdp-hadoop::params(
   } else {
     $rca_prefix = "###"
   }
-  $ambari_db_server_host = hdp_default("ambari_db_server_host", "localhost")
+  # $ambari_db_server_host = hdp_default("ambari_db_server_host", "localhost")
+  $ambari_db_rca_url = hdp_default("ambari_db_rca_url", "jdbc:postgresql://localhost/ambarirca")
+  $ambari_db_rca_driver = hdp_default("ambari_db_rca_driver", "org.postgresql.Driver")
+  $ambari_db_rca_username = hdp_default("ambari_db_rca_username", "mapred")
+  $ambari_db_rca_password = hdp_default("ambari_db_rca_password", "mapred")
+
 }

+ 4 - 4
ambari-agent/src/main/puppet/modules/hdp-hadoop/templates/log4j.properties.erb

@@ -171,10 +171,10 @@ log4j.logger.org.apache.hadoop.mapred.JobInProgress$JobSummary=${hadoop.mapreduc
 log4j.additivity.org.apache.hadoop.mapred.JobInProgress$JobSummary=false
 
 
-<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.database=jdbc:postgresql://<%=scope.function_hdp_host("ambari_db_server_host")%>:5432/ambarirca
-<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.driver=org.postgresql.Driver
-<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.user=mapred
-<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.password=mapred
+<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.database=<%=scope.function_hdp_host("ambari_db_rca_url")%>
+<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.driver=<%=scope.function_hdp_host("ambari_db_rca_driver")%>
+<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.user=<%=scope.function_hdp_host("ambari_db_rca_username")%>
+<%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.password=<%=scope.function_hdp_host("ambari_db_rca_password")%>
 <%=scope.function_hdp_template_var("rca_prefix")%>ambari.jobhistory.logger=DEBUG,JHA
 
 <%=scope.function_hdp_template_var("rca_prefix")%>log4j.appender.JHA=org.apache.ambari.log4j.hadoop.mapreduce.jobhistory.JobHistoryAppender

+ 58 - 0
ambari-server/src/main/java/org/apache/ambari/eventdb/db/OracleConnector.java

@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.eventdb.db;
+
+import org.apache.ambari.eventdb.model.Workflows;
+
+import java.io.IOException;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+public class OracleConnector extends PostgresConnector {
+
+  public OracleConnector(String connectionURL, String driverName, String username, String password) throws IOException {
+    super(connectionURL, driverName, username, password);
+  }
+
+  @Override
+  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause, Workflows.WorkflowDBEntry.WorkflowFields field, boolean sortAscending, int offset, int limit) throws IOException {
+    if (db == null)
+      throw new IOException("db not initialized");
+
+    String order = " ORDER BY " + field.toString() + " " + (sortAscending ? SORT_ASC : SORT_DESC);
+
+    String query = "select * \n" +
+        "  from ( select " +
+//        "/*+ FIRST_ROWS(n) */ \n" +
+        "  a.*, ROWNUM rnum \n" +
+        "      from ("
+        + statement.getStatementString() + searchClause + order +
+        ") a \n" +
+        "      where ROWNUM <= " + (offset + limit) + ") \n" +
+        "where rnum  >= " + offset;
+
+    try {
+      return db.prepareStatement(query);
+    } catch (SQLException e) {
+      throw new IOException(e);
+    }
+
+  }
+
+
+}

+ 5 - 6
ambari-server/src/main/java/org/apache/ambari/eventdb/db/PostgresConnector.java

@@ -57,7 +57,7 @@ public class PostgresConnector implements DBConnector {
   
   private static final ObjectMapper jsonMapper = new ObjectMapper();
   
-  private Connection db;
+  protected Connection db;
   
   public static enum Statements {
     SJ_INSERT_JOB_PS(""),
@@ -104,11 +104,10 @@ public class PostgresConnector implements DBConnector {
   
   private Map<Statements,PreparedStatement> preparedStatements = new EnumMap<Statements,PreparedStatement>(Statements.class);
   
-  public PostgresConnector(String hostname, String dbname, String username, String password) throws IOException {
-    String url = "jdbc:postgresql://" + hostname + "/" + dbname;
+  public PostgresConnector(String connectionURL, String driverName, String username, String password) throws IOException {
     try {
-      Class.forName("org.postgresql.Driver");
-      db = DriverManager.getConnection(url, username, password);
+      Class.forName(driverName);
+      db = DriverManager.getConnection(connectionURL, username, password);
     } catch (ClassNotFoundException e) {
       db = null;
       throw new IOException(e);
@@ -494,7 +493,7 @@ public class PostgresConnector implements DBConnector {
     }
   }
   
-  private PreparedStatement getQualifiedPS(Statements statement, String searchClause, WorkflowFields field, boolean sortAscending, int offset, int limit)
+  protected PreparedStatement getQualifiedPS(Statements statement, String searchClause, WorkflowFields field, boolean sortAscending, int offset, int limit)
       throws IOException {
     if (db == null)
       throw new IOException("postgres db not initialized");

+ 20 - 5
ambari-server/src/main/java/org/apache/ambari/eventdb/webservice/WorkflowJsonService.java

@@ -33,6 +33,7 @@ import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 
+import org.apache.ambari.eventdb.db.OracleConnector;
 import org.apache.ambari.eventdb.db.PostgresConnector;
 import org.apache.ambari.eventdb.model.DataTable;
 import org.apache.ambari.eventdb.model.Jobs;
@@ -45,6 +46,8 @@ import org.apache.ambari.eventdb.model.TaskLocalityData.DataPoint;
 import org.apache.ambari.eventdb.model.Workflows;
 import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry;
 import org.apache.ambari.eventdb.model.Workflows.WorkflowDBEntry.WorkflowFields;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.lang.StringUtils;
 
 @Path("/jobhistory")
 public class WorkflowJsonService {
@@ -54,10 +57,10 @@ public class WorkflowJsonService {
   private static final String USERNAME = PREFIX + "db.user";
   private static final String PASSWORD = PREFIX + "db.password";
   
-  private static final String DEFAULT_HOSTNAME = "localhost";
-  private static final String DEFAULT_DBNAME = "ambarirca";
-  private static final String DEFAULT_USERNAME = "mapred";
-  private static final String DEFAULT_PASSWORD = "mapred";
+  private static String DEFAULT_DRIVER = "localhost";
+  private static String DEFAULT_URL = "ambarirca";
+  private static String DEFAULT_USERNAME = "mapred";
+  private static String DEFAULT_PASSWORD = "mapred";
   
   private static final Workflows EMPTY_WORKFLOWS = new Workflows();
   private static final List<JobDBEntry> EMPTY_JOBS = Collections.emptyList();
@@ -67,7 +70,19 @@ public class WorkflowJsonService {
   }
   
   PostgresConnector getConnector() throws IOException {
-    return new PostgresConnector(DEFAULT_HOSTNAME, DEFAULT_DBNAME, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+    //TODO fix temp hack
+    if (StringUtils.contains(DEFAULT_DRIVER, "oracle")) {
+      return new OracleConnector(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+    } else {
+      return new PostgresConnector(DEFAULT_DRIVER, DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD);
+    }
+  }
+
+  public static void setDBProperties(Configuration configuration) {
+    DEFAULT_DRIVER = configuration.getRcaDatabaseDriver();
+    DEFAULT_URL = configuration.getRcaDatabaseUrl();
+    DEFAULT_USERNAME = configuration.getRcaDatabaseUser();
+    DEFAULT_PASSWORD = configuration.getRcaDatabasePassword();
   }
   
   @Context

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/HostRoleCommand.java

@@ -72,8 +72,8 @@ public class HostRoleCommand {
     this.hostName = hostRoleCommandEntity.getHostName();
     role = hostRoleCommandEntity.getRole();
     status = hostRoleCommandEntity.getStatus();
-    stdout = new String(hostRoleCommandEntity.getStdOut());
-    stderr = new String(hostRoleCommandEntity.getStdError());
+    stdout = hostRoleCommandEntity.getStdOut() != null ? new String(hostRoleCommandEntity.getStdOut()) : "";
+    stderr = hostRoleCommandEntity.getStdError() != null ? new String(hostRoleCommandEntity.getStdError()) : "";
     exitCode = hostRoleCommandEntity.getExitcode();
     startTime = hostRoleCommandEntity.getStartTime();
     lastAttemptTime = hostRoleCommandEntity.getLastAttemptTime();

+ 76 - 19
ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java

@@ -18,6 +18,7 @@
 package org.apache.ambari.server.configuration;
 
 import com.google.inject.Singleton;
+import org.apache.ambari.server.orm.JPATableGenerationStrategy;
 import org.apache.ambari.server.orm.PersistenceType;
 import org.apache.ambari.server.security.ClientSecurityType;
 import org.apache.ambari.server.security.authorization.LdapServerProperties;
@@ -106,16 +107,37 @@ public class Configuration {
   public static final String ADMIN_ROLE_NAME_KEY =
       "authorization.adminRoleName";
 
-  public static final String PERSISTENCE_IN_MEMORY_KEY =
-      "server.persistence.inMemory";
-  public static final String SERVER_JDBC_USER_NAME_KEY =
-      "server.jdbc.user.name";
-  private static final String SERVER_JDBC_USER_NAME_DEFAULT =
-      "ambari-server";
-  public static final String SERVER_JDBC_USER_PASSWD_KEY =
-      "server.jdbc.user.passwd";
-  private static final String SERVER_JDBC_USER_PASSWD_DEFAULT =
-      "bigdata";
+  public static final String SERVER_PERSISTENCE_TYPE_KEY = "server.persistence.type";
+  public static final String SERVER_JDBC_USER_NAME_KEY = "server.jdbc.user.name";
+  public static final String SERVER_JDBC_USER_PASSWD_KEY = "server.jdbc.user.passwd";
+  public static final String SERVER_JDBC_DRIVER_KEY = "server.jdbc.driver";
+  public static final String SERVER_JDBC_URL_KEY = "server.jdbc.url";
+
+//  public static final String SERVER_RCA_PERSISTENCE_TYPE_KEY = "server.rca.persistence.type";
+  public static final String SERVER_JDBC_RCA_USER_NAME_KEY = "server.jdbc.rca.user.name";
+  public static final String SERVER_JDBC_RCA_USER_PASSWD_KEY = "server.jdbc.rca.user.passwd";
+  public static final String SERVER_JDBC_RCA_DRIVER_KEY = "server.jdbc.rca.driver";
+  public static final String SERVER_JDBC_RCA_URL_KEY = "server.jdbc.rca.url";
+
+
+  public static final String SERVER_JDBC_GENERATE_TABLES_KEY = "server.jdbc.generateTables";
+
+  public static final String JDBC_UNIT_NAME = "ambari-server";
+
+  public static final String JDBC_LOCAL_URL = "jdbc:postgresql://localhost/ambari";
+  public static final String JDBC_LOCAL_DRIVER = "org.postgresql.Driver";
+
+  public static final String JDBC_IN_MEMORY_URL = "jdbc:derby:memory:myDB/ambari;create=true";
+  public static final String JDBC_IN_MEMROY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
+
+  public static final String JDBC_RCA_LOCAL_URL = "jdbc:postgresql://localhost/ambarirca";
+  public static final String JDBC_RCA_LOCAL_DRIVER = "org.postgresql.Driver";
+
+  private static final String SERVER_JDBC_USER_NAME_DEFAULT = "ambari-server";
+  private static final String SERVER_JDBC_USER_PASSWD_DEFAULT = "bigdata";
+
+  private static final String SERVER_JDBC_RCA_USER_NAME_DEFAULT = "mapred";
+  private static final String SERVER_JDBC_RCA_USER_PASSWD_DEFAULT = "mapred";
 
   public static final String OS_VERSION_KEY =
       "server.os_type";
@@ -162,7 +184,7 @@ public class Configuration {
   private static final String LDAP_GROUP_SEARCH_FILTER_DEFAULT = "";
 
   //TODO for development purposes only, should be changed to 'false'
-  private static final String PERSISTENCE_IN_MEMORY_DEFAULT = "true";
+  private static final String SERVER_PERSISTENCE_TYPE_DEFAULT = "local";
 
 
 
@@ -380,14 +402,23 @@ public class Configuration {
     return ("true".equals(properties.getProperty(API_USE_SSL, "false")));
   }
 
-
+  /**
+   * Check persistence type Ambari Server should use. Possible values:
+   * in-memory - use in-memory Derby database to store data
+   * local - use local Postgres instance
+   * remote - use provided jdbc driver name and url to connect to database
+   */
   public PersistenceType getPersistenceType() {
-    String value = properties.getProperty(PERSISTENCE_IN_MEMORY_KEY, PERSISTENCE_IN_MEMORY_DEFAULT);
-    if ("true".equalsIgnoreCase(value)) {
-      return PersistenceType.IN_MEMORY;
-    } else {
-      return PersistenceType.POSTGRES;
-    }
+    String value = properties.getProperty(SERVER_PERSISTENCE_TYPE_KEY, SERVER_PERSISTENCE_TYPE_DEFAULT);
+    return PersistenceType.fromString(value);
+  }
+
+  public String getDatabaseDriver() {
+    return properties.getProperty(SERVER_JDBC_DRIVER_KEY);
+  }
+
+  public String getDatabaseUrl() {
+    return properties.getProperty(SERVER_JDBC_URL_KEY);
   }
 
   public String getDatabaseUser() {
@@ -396,9 +427,30 @@ public class Configuration {
 
   public String getDatabasePassword() {
     String filePath = properties.getProperty(SERVER_JDBC_USER_PASSWD_KEY);
+    return readPassword(filePath, SERVER_JDBC_USER_PASSWD_DEFAULT);
+  }
+
+  public String getRcaDatabaseDriver() {
+    return properties.getProperty(SERVER_JDBC_RCA_DRIVER_KEY, JDBC_RCA_LOCAL_DRIVER);
+  }
+
+  public String getRcaDatabaseUrl() {
+    return properties.getProperty(SERVER_JDBC_RCA_URL_KEY, JDBC_RCA_LOCAL_URL);
+  }
+
+  public String getRcaDatabaseUser() {
+    return properties.getProperty(SERVER_JDBC_RCA_USER_NAME_KEY, SERVER_JDBC_RCA_USER_NAME_DEFAULT);
+  }
+
+  public String getRcaDatabasePassword() {
+    String filePath = properties.getProperty(SERVER_JDBC_RCA_USER_PASSWD_KEY);
+    return readPassword(filePath, SERVER_JDBC_RCA_USER_PASSWD_DEFAULT);
+  }
+
+  private String readPassword(String filePath, String defaultPassword) {
     if (filePath == null) {
       LOG.debug("DB password file not specified - using default");
-      return SERVER_JDBC_USER_PASSWD_DEFAULT;
+      return defaultPassword;
     } else {
       LOG.debug("Reading password from file {}", filePath);
       String password;
@@ -411,6 +463,7 @@ public class Configuration {
     }
   }
 
+
   /**
    * Gets parameters of LDAP server to connect to
    * @return LdapServerProperties object representing connection parameters
@@ -464,4 +517,8 @@ public class Configuration {
     return Integer.parseInt(properties.getProperty(CLIENT_API_PORT_KEY, String.valueOf(CLIENT_API_PORT_DEFAULT)));
   }
 
+  public JPATableGenerationStrategy getJPATableGenerationStrategy() {
+    return JPATableGenerationStrategy.fromString(System.getProperty(SERVER_JDBC_GENERATE_TABLES_KEY));
+  }
+
 }

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -921,7 +921,7 @@ public class AmbariManagementControllerImpl implements
 
     // Generate cluster host info
     execCmd.setClusterHostInfo(
-        StageUtils.getClusterHostInfo(cluster, hostsMap));
+        StageUtils.getClusterHostInfo(cluster, hostsMap, injector));
 
     Host host = clusters.getHost(scHost.getHostName());
 
@@ -2077,7 +2077,7 @@ public class AmbariManagementControllerImpl implements
         // Generate cluster host info
         stage.getExecutionCommandWrapper(clientHost, smokeTestRole)
             .getExecutionCommand()
-            .setClusterHostInfo(StageUtils.getClusterHostInfo(cluster, hostsMap));
+            .setClusterHostInfo(StageUtils.getClusterHostInfo(cluster, hostsMap, injector));
       }
 
       RoleGraph rg = new RoleGraph(rco);
@@ -3915,7 +3915,7 @@ public class AmbariManagementControllerImpl implements
 
     // Generate cluster host info
     execCmd.setClusterHostInfo(
-      StageUtils.getClusterHostInfo(clusters.getCluster(clusterName), hostsMap));
+      StageUtils.getClusterHostInfo(clusters.getCluster(clusterName), hostsMap, injector));
   }
 
   private void addDecommissionDatanodeAction(

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariServer.java

@@ -25,6 +25,7 @@ import java.util.Map;
 
 import com.google.inject.persist.PersistFilter;
 import com.google.gson.Gson;
+import org.apache.ambari.eventdb.webservice.WorkflowJsonService;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.HeartBeatHandler;
@@ -412,6 +413,9 @@ public class AmbariServer {
     AmbariMetaService.init(injector.getInstance(AmbariMetaInfo.class));
     BootStrapResource.init(injector.getInstance(BootStrapImpl.class));
     StageUtils.setGson(injector.getInstance(Gson.class));
+    WorkflowJsonService.setDBProperties(
+        injector.getInstance(Configuration.class)
+    );
   }
 
   public static void main(String[] args) throws Exception {

+ 46 - 10
ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java

@@ -75,15 +75,7 @@ public class ControllerModule extends AbstractModule {
     bind(HostsMap.class).toInstance(hostsMap);
     bind(PasswordEncoder.class).toInstance(new StandardPasswordEncoder());
 
-    JpaPersistModule jpaPersistModule = new JpaPersistModule(configuration.getPersistenceType().getUnitName());
-    if (configuration.getPersistenceType() == PersistenceType.POSTGRES) {
-      Properties properties = new Properties();
-      properties.setProperty("javax.persistence.jdbc.user", configuration.getDatabaseUser());
-      properties.setProperty("javax.persistence.jdbc.password", configuration.getDatabasePassword());
-      jpaPersistModule.properties(properties);
-    }
-
-    install(jpaPersistModule);
+    install(buildJpaPersistModule());
 
     bind(Gson.class).in(Scopes.SINGLETON);
     bind(Clusters.class).to(ClustersImpl.class);
@@ -92,10 +84,54 @@ public class ControllerModule extends AbstractModule {
     bindConstant().annotatedWith(Names.named("actionTimeout")).to(300000L);
     bind(AmbariManagementController.class)
         .to(AmbariManagementControllerImpl.class);
-    bind(HBaseMasterPortScanner.class).in(Singleton.class);;
+    bind(HBaseMasterPortScanner.class).in(Singleton.class);
     bind(ServerActionManager.class).to(ServerActionManagerImpl.class);
   }
 
+  private JpaPersistModule buildJpaPersistModule() {
+    PersistenceType persistenceType = configuration.getPersistenceType();
+    JpaPersistModule jpaPersistModule = new JpaPersistModule(Configuration.JDBC_UNIT_NAME);
+
+    Properties properties = new Properties();
+
+    switch (persistenceType) {
+      case IN_MEMORY:
+        properties.put("javax.persistence.jdbc.url", Configuration.JDBC_IN_MEMORY_URL);
+        properties.put("javax.persistence.jdbc.driver", Configuration.JDBC_IN_MEMROY_DRIVER);
+        properties.put("eclipselink.ddl-generation", "drop-and-create-tables");
+        properties.put("eclipselink.orm.throw.exceptions", "true");
+        jpaPersistModule.properties(properties);
+        return jpaPersistModule;
+      case REMOTE:
+        properties.put("javax.persistence.jdbc.url", configuration.getDatabaseUrl());
+        properties.put("javax.persistence.jdbc.driver", configuration.getDatabaseDriver());
+        break;
+      case LOCAL:
+        properties.put("javax.persistence.jdbc.url", Configuration.JDBC_LOCAL_URL);
+        properties.put("javax.persistence.jdbc.driver", Configuration.JDBC_LOCAL_DRIVER);
+        break;
+    }
+
+    properties.setProperty("javax.persistence.jdbc.user", configuration.getDatabaseUser());
+    properties.setProperty("javax.persistence.jdbc.password", configuration.getDatabasePassword());
+
+    switch (configuration.getJPATableGenerationStrategy()) {
+      case CREATE:
+        properties.setProperty("eclipselink.ddl-generation", "create-tables");
+        break;
+      case DROP_AND_CREATE:
+        properties.setProperty("eclipselink.ddl-generation", "drop-and-create-tables");
+        break;
+    }
+    properties.setProperty("eclipselink.ddl-generation.output-mode", "both");
+    properties.setProperty("eclipselink.create-ddl-jdbc-file-name", "DDL-create.jdbc");
+    properties.setProperty("eclipselink.drop-ddl-jdbc-file-name", "DDL-drop.jdbc");
+
+    jpaPersistModule.properties(properties);
+
+    return jpaPersistModule;
+  }
+
   private void installFactories() {
     install(new FactoryModuleBuilder().implement(
         Cluster.class, ClusterImpl.class).build(ClusterFactory.class));

+ 47 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/JPATableGenerationStrategy.java

@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.orm;
+
+public enum JPATableGenerationStrategy {
+  //create tables which don't exist
+  CREATE("create"),
+  //drop and create all tables
+  DROP_AND_CREATE("dropAndCreate"),
+  //don't create tables
+  NONE("none");
+
+  private String value;
+
+  private JPATableGenerationStrategy(String value) {
+    this.value = value;
+  }
+
+  public String getValue() {
+    return value;
+  }
+
+  public static JPATableGenerationStrategy fromString(String value) {
+    for (JPATableGenerationStrategy strategy : values()) {
+      if (strategy.value.equalsIgnoreCase(value)) {
+        return strategy;
+      }
+    }
+    return NONE;
+  }
+}

+ 17 - 7
ambari-server/src/main/java/org/apache/ambari/server/orm/PersistenceType.java

@@ -18,16 +18,26 @@
 package org.apache.ambari.server.orm;
 
 public enum PersistenceType {
-  IN_MEMORY("ambari-javadb"),
-  POSTGRES("ambari-postgres");
+  IN_MEMORY("in-memory"),
+  LOCAL("local"),
+  REMOTE("remote");
 
-  String unitName;
+  String value;
 
-  PersistenceType(String unitName) {
-    this.unitName = unitName;
+  PersistenceType(String value) {
+    this.value = value;
   }
 
-  public String getUnitName() {
-    return unitName;
+  public static PersistenceType fromString(String typeString) {
+    for (PersistenceType type : values()) {
+      if (type.value.equals(typeString)) {
+        return type;
+      }
+    }
+    throw new IllegalArgumentException("Unknown persistence type: "+ typeString);
+  }
+
+  public String getValue() {
+    return value;
   }
 }

+ 7 - 2
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java

@@ -53,8 +53,13 @@ public class HostDAO {
   @Transactional
   public List<HostEntity> findByStage(StageEntity stageEntity) {
     TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery(
-        "SELECT DISTINCT host FROM HostEntity host JOIN host.hostRoleCommandEntities command JOIN command.stage stage " +
-            "WHERE stage=:stageEntity", HostEntity.class);
+        "SELECT host FROM HostEntity host " +
+            "WHERE host.hostName IN (" +
+            "SELECT DISTINCT host.hostName " +
+            "FROM HostEntity host " +
+            "JOIN host.hostRoleCommandEntities command " +
+            "JOIN command.stage stage " +
+            "WHERE stage=:stageEntity)", HostEntity.class);
     query.setParameter("stageEntity", stageEntity);
     try {
       return query.getResultList();

+ 29 - 19
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigEntity.java

@@ -22,21 +22,46 @@ import javax.persistence.*;
 import java.util.Collection;
 
 @IdClass(ClusterConfigEntityPK.class)
-@Table(name = "clusterconfig", schema = "ambari", catalog = "")
+@Table(name = "clusterconfig")
 @Entity
 public class ClusterConfigEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   private Long clusterId;
-  private String configJson;
+
+  @Id
+  @Column(name = "type_name")
   private String type;
+
+  @Id
+  @Column(name = "version_tag")
   private String tag;
+
+  @Basic(fetch=FetchType.LAZY)
+  @Column(name = "config_data", nullable = false, insertable = true, updatable = false, length=32000)
+  @Lob
+  private String configJson;
+
+  @Column(name = "create_timestamp", nullable=false, insertable=true, updatable=false)
   private long timestamp;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
+  private ClusterEntity clusterEntity;
+
+  @OneToMany(mappedBy = "clusterConfigEntity")
   private Collection<HostComponentConfigMappingEntity> hostComponentConfigMappingEntities;
+
+  @OneToMany(mappedBy = "clusterConfigEntity")
   private Collection<ServiceConfigMappingEntity> serviceConfigMappingEntities;
+
+  @OneToMany(mappedBy = "clusterConfigEntity")
   private Collection<HostComponentDesiredConfigMappingEntity> hostComponentDesiredConfigMappingEntities;
+
+  @OneToMany(mappedBy = "clusterConfigEntity")
   private Collection<ComponentConfigMappingEntity> componentConfigMappingEntities;
   
-  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -45,8 +70,6 @@ public class ClusterConfigEntity {
     this.clusterId = clusterId;
   }
   
-  @Column(name = "type_name")
-  @Id
   public String getType() {
     return type;
   }
@@ -55,8 +78,6 @@ public class ClusterConfigEntity {
     type = typeName;
   }
   
-  @Column(name = "version_tag")
-  @Id
   public String getTag() {
     return tag;
   }
@@ -65,8 +86,6 @@ public class ClusterConfigEntity {
     tag = versionTag;
   }
 
-  @Column(name = "config_data", nullable = false, insertable = true, updatable = false, length=32000)
-  @Basic(fetch=FetchType.LAZY)
   public String getData() {
     return configJson;
   }
@@ -75,7 +94,6 @@ public class ClusterConfigEntity {
     this.configJson = data;
   }
   
-  @Column(name = "create_timestamp", nullable=false, insertable=true, updatable=false)
   public long getTimestamp() {
     return timestamp;
   }
@@ -105,10 +123,6 @@ public class ClusterConfigEntity {
     return result;
   }
 
-  private ClusterEntity clusterEntity;
-
-  @ManyToOne
-  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   public ClusterEntity getClusterEntity() {
     return clusterEntity;
   }
@@ -117,7 +131,6 @@ public class ClusterConfigEntity {
     this.clusterEntity = clusterEntity;
   }
 
-  @OneToMany(mappedBy = "clusterConfigEntity")
   public Collection<HostComponentConfigMappingEntity> getHostComponentConfigMappingEntities() {
     return hostComponentConfigMappingEntities;
   }
@@ -126,7 +139,6 @@ public class ClusterConfigEntity {
     this.hostComponentConfigMappingEntities = hostComponentConfigMappingEntities;
   }
 
-  @OneToMany(mappedBy = "clusterConfigEntity")
   public Collection<ServiceConfigMappingEntity> getServiceConfigMappingEntities() {
     return serviceConfigMappingEntities;
   }
@@ -135,7 +147,6 @@ public class ClusterConfigEntity {
     this.serviceConfigMappingEntities = serviceConfigMappingEntities;
   }
 
-  @OneToMany(mappedBy = "clusterConfigEntity")
   public Collection<HostComponentDesiredConfigMappingEntity> getHostComponentDesiredConfigMappingEntities() {
     return hostComponentDesiredConfigMappingEntities;
   }
@@ -144,7 +155,6 @@ public class ClusterConfigEntity {
     this.hostComponentDesiredConfigMappingEntities = hostComponentDesiredConfigMappingEntities;
   }
 
-  @OneToMany(mappedBy = "clusterConfigEntity")
   public Collection<ComponentConfigMappingEntity> getComponentConfigMappingEntities() {
     return componentConfigMappingEntities;
   }

+ 18 - 14
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterConfigMappingEntity.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -29,19 +29,32 @@ import javax.persistence.Table;
  * Entity that maps to a cluster config mapping.
  */
 @IdClass(ClusterConfigMappingEntityPK.class)
-@Table(name = "clusterconfigmapping", schema = "ambari", catalog = "")
+@Table(name = "clusterconfigmapping")
 @Entity
 public class ClusterConfigMappingEntity {
 
+  @Id
+  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "type_name", insertable = true, updatable = false, nullable = false)
   private String typeName;
+
+  @Id
+  @Column(name = "create_timestamp", insertable = true, updatable = false, nullable = false)
+  private Long createTimestamp;
+
+  @Column(name = "version_tag", insertable = true, updatable = false, nullable = false)
   private String versionTag;
+
+  @Column(name = "selected", insertable = true, updatable = true, nullable = false)
   private int selectedInd = 0;
-  private Long createTimestamp;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   private ClusterEntity clusterEntity;
   
-  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -50,8 +63,6 @@ public class ClusterConfigMappingEntity {
     clusterId = id;
   }
   
-  @Column(name = "type_name", insertable = true, updatable = false, nullable = false)
-  @Id
   public String getType() {
     return typeName;
   }
@@ -59,8 +70,6 @@ public class ClusterConfigMappingEntity {
     typeName = type;
   }
 
-  @Column(name = "create_timestamp", insertable = true, updatable = false, nullable = false)
-  @Id
   public Long getCreateTimestamp() {
     return createTimestamp;
   }
@@ -69,7 +78,6 @@ public class ClusterConfigMappingEntity {
     createTimestamp = timestamp;
   }  
   
-  @Column(name = "version_tag", insertable = true, updatable = false, nullable = false)
   public String getVersion() {
     return versionTag;
   }
@@ -78,8 +86,6 @@ public class ClusterConfigMappingEntity {
     versionTag = version;
   }
  
-
-  @Column(name = "selected", insertable = true, updatable = true, nullable = false)
   public int isSelected() {
     return selectedInd;
   }
@@ -88,8 +94,6 @@ public class ClusterConfigMappingEntity {
     selectedInd = selected;
   }
   
-  @ManyToOne
-  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   public ClusterEntity getClusterEntity() {
     return clusterEntity;
   }

+ 54 - 44
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java

@@ -21,7 +21,9 @@ package org.apache.ambari.server.orm.entities;
 import javax.persistence.*;
 import java.util.Collection;
 
-@javax.persistence.Table(name = "clusters", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@Table(name = "clusters")
 @NamedQueries({
     @NamedQuery(name = "clusterByName", query =
         "SELECT cluster " +
@@ -32,13 +34,54 @@ import java.util.Collection;
             "FROM ClusterEntity clusters")
 })
 @Entity
-@SequenceGenerator(name = "ambari.clusters_cluster_id_seq", allocationSize = 1)
+@TableGenerator(name = "cluster_id_generator",
+    table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "value"
+    , pkColumnValue = "cluster_id_seq"
+    , initialValue = 1
+    , allocationSize = 1
+)
 public class ClusterEntity {
-  private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = true, updatable = true)
   @Id
-  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ambari.clusters_cluster_id_seq")
+  @Column(name = "cluster_id", nullable = false, insertable = true, updatable = true)
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = "cluster_id_generator")
+  private Long clusterId;
+
+  @Basic
+  @Column(name = "cluster_name", nullable = false, insertable = true,
+      updatable = true, unique = true, length = 100)
+  private String clusterName;
+
+  @Basic
+  @Column(name = "desired_cluster_state", insertable = true, updatable = true)
+  private String desiredClusterState = "";
+
+  @Basic
+  @Column(name = "cluster_info", insertable = true, updatable = true)
+  private String clusterInfo = "";
+
+  @Basic
+  @Column(name = "desired_stack_version", insertable = true, updatable = true)
+  private String desiredStackVersion = "";
+
+  @OneToMany(mappedBy = "clusterEntity")
+  private Collection<ClusterServiceEntity> clusterServiceEntities;
+
+  @OneToOne(mappedBy = "clusterEntity", cascade = CascadeType.REMOVE)
+  private ClusterStateEntity clusterStateEntity;
+
+  @ManyToMany(mappedBy = "clusterEntities")
+  private Collection<HostEntity> hostEntities;
+
+  @OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
+  private Collection<StageEntity> stages;
+
+  @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
+  private Collection<ClusterConfigEntity> configEntities;
+
+  @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
+  private Collection<ClusterConfigMappingEntity> configMappingEntities;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -47,11 +90,6 @@ public class ClusterEntity {
     this.clusterId = clusterId;
   }
 
-  private String clusterName;
-
-  @javax.persistence.Column(name = "cluster_name", nullable = false, insertable = true,
-          updatable = true, unique = true, length = 100)
-  @Basic
   public String getClusterName() {
     return clusterName;
   }
@@ -60,36 +98,24 @@ public class ClusterEntity {
     this.clusterName = clusterName;
   }
 
-  private String desiredClusterState = "";
-
-  @javax.persistence.Column(name = "desired_cluster_state", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getDesiredClusterState() {
-    return desiredClusterState;
+    return defaultString(desiredClusterState);
   }
 
   public void setDesiredClusterState(String desiredClusterState) {
     this.desiredClusterState = desiredClusterState;
   }
 
-  private String clusterInfo = "";
-
-  @javax.persistence.Column(name = "cluster_info", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getClusterInfo() {
-    return clusterInfo;
+    return defaultString(clusterInfo);
   }
 
   public void setClusterInfo(String clusterInfo) {
     this.clusterInfo = clusterInfo;
   }
 
-  private String desiredStackVersion = "";
-
-  @javax.persistence.Column(name = "desired_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getDesiredStackVersion() {
-    return desiredStackVersion;
+    return defaultString(desiredStackVersion);
   }
 
   public void setDesiredStackVersion(String desiredStackVersion) {
@@ -124,9 +150,6 @@ public class ClusterEntity {
     return result;
   }
 
-  private Collection<ClusterServiceEntity> clusterServiceEntities;
-
-  @OneToMany(mappedBy = "clusterEntity")
   public Collection<ClusterServiceEntity> getClusterServiceEntities() {
     return clusterServiceEntities;
   }
@@ -135,9 +158,6 @@ public class ClusterEntity {
     this.clusterServiceEntities = clusterServiceEntities;
   }
 
-  private ClusterStateEntity clusterStateEntity;
-
-  @OneToOne(mappedBy = "clusterEntity", cascade = CascadeType.REMOVE)
   public ClusterStateEntity getClusterStateEntity() {
     return clusterStateEntity;
   }
@@ -146,9 +166,6 @@ public class ClusterEntity {
     this.clusterStateEntity = clusterStateEntity;
   }
 
-  private Collection<HostEntity> hostEntities;
-
-  @ManyToMany(mappedBy = "clusterEntities")
   public Collection<HostEntity> getHostEntities() {
     return hostEntities;
   }
@@ -157,9 +174,6 @@ public class ClusterEntity {
     this.hostEntities = hostEntities;
   }
 
-  private Collection<StageEntity> stages;
-
-  @OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
   public Collection<StageEntity> getStages() {
     return stages;
   }
@@ -167,19 +181,15 @@ public class ClusterEntity {
   public void setStages(Collection<StageEntity> stages) {
     this.stages = stages;
   }
-  
-  private Collection<ClusterConfigEntity> configEntities;
-  @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
+
   public Collection<ClusterConfigEntity> getClusterConfigEntities() {
     return configEntities;
   }
-  
+
   public void setClusterConfigEntities(Collection<ClusterConfigEntity> entities) {
     configEntities = entities;
   }
-  
-  private Collection<ClusterConfigMappingEntity> configMappingEntities;
-  @OneToMany(mappedBy = "clusterEntity", cascade = CascadeType.ALL)
+
   public Collection<ClusterConfigMappingEntity> getConfigMappingEntities() {
     return configMappingEntities;
   }

+ 24 - 22
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java

@@ -22,7 +22,7 @@ import javax.persistence.*;
 import java.util.Collection;
 
 @javax.persistence.IdClass(ClusterServiceEntityPK.class)
-@javax.persistence.Table(name = "clusterservices", schema = "ambari", catalog = "")
+@javax.persistence.Table(name = "clusterservices")
 @NamedQueries({
         @NamedQuery(name = "clusterServiceByClusterAndServiceNames", query =
                 "SELECT clusterService " +
@@ -32,10 +32,32 @@ import java.util.Collection;
 })
 @Entity
 public class ClusterServiceEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   @Id
+  @Column(name = "service_name", nullable = false, insertable = true, updatable = true)
+  private String serviceName;
+
+  @Basic
+  @Column(name = "service_enabled", nullable = false, insertable = true, updatable = true, length = 10)
+  private Integer serviceEnabled = 0;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
+  private ClusterEntity clusterEntity;
+
+  @OneToOne(mappedBy = "clusterServiceEntity", cascade = CascadeType.ALL)
+  private ServiceDesiredStateEntity serviceDesiredStateEntity;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  private Collection<ServiceComponentDesiredStateEntity> serviceComponentDesiredStateEntities;
+
+  @OneToMany(mappedBy = "serviceEntity", cascade = CascadeType.ALL)
+  private Collection<ServiceConfigMappingEntity> serviceConfigMappings;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -44,10 +66,6 @@ public class ClusterServiceEntity {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
-
-  @javax.persistence.Column(name = "service_name", nullable = false, insertable = true, updatable = true)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -56,10 +74,6 @@ public class ClusterServiceEntity {
     this.serviceName = serviceName;
   }
 
-  private Integer serviceEnabled = 0;
-
-  @javax.persistence.Column(name = "service_enabled", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public int getServiceEnabled() {
     return serviceEnabled;
   }
@@ -91,10 +105,6 @@ public class ClusterServiceEntity {
     return result;
   }
 
-  private ClusterEntity clusterEntity;
-
-  @ManyToOne
-  @javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   public ClusterEntity getClusterEntity() {
     return clusterEntity;
   }
@@ -103,9 +113,6 @@ public class ClusterServiceEntity {
     this.clusterEntity = clusterEntity;
   }
 
-  private ServiceDesiredStateEntity serviceDesiredStateEntity;
-
-  @OneToOne(mappedBy = "clusterServiceEntity", cascade = CascadeType.ALL)
   public ServiceDesiredStateEntity getServiceDesiredStateEntity() {
     return serviceDesiredStateEntity;
   }
@@ -114,9 +121,6 @@ public class ClusterServiceEntity {
     this.serviceDesiredStateEntity = serviceDesiredStateEntity;
   }
 
-  private Collection<ServiceComponentDesiredStateEntity> serviceComponentDesiredStateEntities;
-
-  @OneToMany(mappedBy = "clusterServiceEntity")
   public Collection<ServiceComponentDesiredStateEntity> getServiceComponentDesiredStateEntities() {
     return serviceComponentDesiredStateEntities;
   }
@@ -125,8 +129,6 @@ public class ClusterServiceEntity {
     this.serviceComponentDesiredStateEntities = serviceComponentDesiredStateEntities;
   }
 
-  private Collection<ServiceConfigMappingEntity> serviceConfigMappings;
-  @OneToMany(mappedBy = "serviceEntity", cascade = CascadeType.ALL)
   public Collection<ServiceConfigMappingEntity> getServiceConfigMappings() {
     return serviceConfigMappings;
   }

+ 20 - 17
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterStateEntity.java

@@ -18,21 +18,30 @@
 
 package org.apache.ambari.server.orm.entities;
 
-import javax.persistence.Basic;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.OneToOne;
+import javax.persistence.*;
 
-@javax.persistence.Table(name = "clusterstate", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@javax.persistence.Table(name = "clusterstate")
 @Entity
 public class ClusterStateEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   private Long clusterId;
-  private String currentClusterState = "";
-  private String currentStackVersion = "";
+
+  @Basic
+  @Column(name = "current_cluster_state", insertable = true, updatable = true)
+  private String currentClusterState;
+
+  @Basic
+  @Column(name = "current_stack_version", insertable = true, updatable = true)
+  private String currentStackVersion;
+
+  @OneToOne
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   private ClusterEntity clusterEntity;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -41,20 +50,16 @@ public class ClusterStateEntity {
     this.clusterId = clusterId;
   }
 
-  @javax.persistence.Column(name = "current_cluster_state", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getCurrentClusterState() {
-    return currentClusterState;
+    return defaultString(currentClusterState);
   }
 
   public void setCurrentClusterState(String currentClusterState) {
     this.currentClusterState = currentClusterState;
   }
 
-  @javax.persistence.Column(name = "current_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getCurrentStackVersion() {
-    return currentStackVersion;
+    return defaultString(currentStackVersion);
   }
 
   public void setCurrentStackVersion(String currentStackVersion) {
@@ -84,8 +89,6 @@ public class ClusterStateEntity {
     return result;
   }
 
-  @OneToOne
-  @javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   public ClusterEntity getClusterEntity() {
     return clusterEntity;
   }

+ 34 - 26
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentConfigMappingEntity.java

@@ -28,19 +28,47 @@ import javax.persistence.Table;
 
 @IdClass(ComponentConfigMappingEntityPK.class)
 @Entity
-@Table(name = "componentconfigmapping", schema = "ambari", catalog = "")
+@Table(name = "componentconfigmapping")
 public class ComponentConfigMappingEntity {
+
+  @Id
+  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
   private String serviceName;
+
+  @Id
+  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
   private String componentName;
+
+  @Id
+  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
   private String configType;
+
+  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   private String configTag;
+
+  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   private Long timestamp;
-  private ServiceComponentDesiredStateEntity componentEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
+      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)
+  })
+  private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
+  })
   private ClusterConfigEntity clusterConfigEntity;
 
-  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -49,8 +77,6 @@ public class ComponentConfigMappingEntity {
     clusterId = id;
   }
 
-  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -59,8 +85,6 @@ public class ComponentConfigMappingEntity {
     serviceName = name;
   }
 
-  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
-  @Id
   public String getComponentName() {
     return componentName;
   }
@@ -69,8 +93,6 @@ public class ComponentConfigMappingEntity {
     componentName = name;
   }
 
-  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
-  @Id
   public String getConfigType() {
     return configType;
   }
@@ -79,7 +101,6 @@ public class ComponentConfigMappingEntity {
     configType = type;
   }
 
-  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   public String getVersionTag() {
     return configTag;
   }
@@ -88,7 +109,6 @@ public class ComponentConfigMappingEntity {
     configTag = tag;
   }
 
-  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   public Long getTimestamp() {
     return timestamp;
   }
@@ -122,26 +142,14 @@ public class ComponentConfigMappingEntity {
   }
 
 
-  @ManyToOne
-  @JoinColumns({
-    @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-    @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
-    @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)
-  })
   public ServiceComponentDesiredStateEntity getServiceComponentDesiredStateEntity() {
-    return componentEntity;
+    return serviceComponentDesiredStateEntity;
   }
 
   public void setServiceComponentDesiredStateEntity(ServiceComponentDesiredStateEntity entity) {
-    componentEntity = entity;
+    serviceComponentDesiredStateEntity = entity;
   }
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
-  })
   public ClusterConfigEntity getClusterConfigEntity() {
     return clusterConfigEntity;
   }

+ 13 - 12
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ExecutionCommandEntity.java

@@ -21,13 +21,23 @@ package org.apache.ambari.server.orm.entities;
 import javax.persistence.*;
 import java.util.Arrays;
 
-@Table(name = "execution_command", schema = "ambari", catalog = "")
+@Table(name = "execution_command")
 @Entity
 public class ExecutionCommandEntity {
-  private Long taskId;
 
-  @Column(name = "task_id")
   @Id
+  @Column(name = "task_id")
+  private Long taskId;
+
+  @Basic
+  @Lob
+  @Column(name = "command")
+  private byte[] command;
+
+  @OneToOne
+  @JoinColumn(name = "task_id", referencedColumnName = "task_id", nullable = false, insertable = false, updatable = false)
+  private HostRoleCommandEntity hostRoleCommand;
+
   public Long getTaskId() {
     return taskId;
   }
@@ -36,11 +46,6 @@ public class ExecutionCommandEntity {
     this.taskId = taskId;
   }
 
-  private byte[] command;
-
-  @Column(name = "command")
-  @Lob
-  @Basic
   public byte[] getCommand() {
     return command;
   }
@@ -69,10 +74,6 @@ public class ExecutionCommandEntity {
     return result;
   }
 
-  private HostRoleCommandEntity hostRoleCommand;
-
-  @OneToOne
-  @JoinColumn(name = "task_id", referencedColumnName = "task_id", nullable = false, insertable = false, updatable = false)
   public HostRoleCommandEntity getHostRoleCommand() {
     return hostRoleCommand;
   }

+ 35 - 25
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentConfigMappingEntity.java

@@ -27,21 +27,53 @@ import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 @IdClass(HostComponentConfigMappingEntityPK.class)
-@Table(name = "hostcomponentconfigmapping", schema = "ambari", catalog = "")
+@Table(name = "hostcomponentconfigmapping")
 @Entity
 public class HostComponentConfigMappingEntity {
+
+  @Id
+  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
   private String serviceName;
+
+  @Id
+  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
   private String componentName;
+
+  @Id
+  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
   private String hostName;
+
+  @Id
+  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
   private String configType;
+
+  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   private String configTag;
+
+  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   private Long timestamp;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
+      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false),
+      @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false) })
   private HostComponentStateEntity hostComponentStateEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
+  })
   private ClusterConfigEntity clusterConfigEntity;
 
-  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
-  @Id
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -50,8 +82,6 @@ public class HostComponentConfigMappingEntity {
     clusterId = id;
   }
 
-  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -60,8 +90,6 @@ public class HostComponentConfigMappingEntity {
     serviceName = name;
   }
 
-  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
-  @Id
   public String getComponentName() {
     return componentName;
   }
@@ -70,8 +98,6 @@ public class HostComponentConfigMappingEntity {
     componentName = name;
   }
 
-  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
-  @Id
   public String getHostName() {
     return hostName;
   }
@@ -80,8 +106,6 @@ public class HostComponentConfigMappingEntity {
     hostName = name;
   }
 
-  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
-  @Id
   public String getConfigType() {
     return configType;
   }
@@ -90,7 +114,6 @@ public class HostComponentConfigMappingEntity {
     configType = type;
   }
 
-  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   public String getVersionTag() {
     return configTag;
   }
@@ -99,7 +122,6 @@ public class HostComponentConfigMappingEntity {
     configTag = tag;
   }
 
-  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   public Long getTimestamp() {
     return timestamp;
   }
@@ -108,12 +130,6 @@ public class HostComponentConfigMappingEntity {
     timestamp = stamp;
   }
 
-  @ManyToOne
-  @JoinColumns({
-    @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-    @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
-    @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false),
-    @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false) })
   public HostComponentStateEntity getHostComponentStateEntity() {
     return hostComponentStateEntity;
   }
@@ -122,12 +138,6 @@ public class HostComponentConfigMappingEntity {
     hostComponentStateEntity = entity;
   }
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
-  })
   public ClusterConfigEntity getClusterConfigEntity() {
     return clusterConfigEntity;
   }

+ 42 - 33
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredConfigMappingEntity.java

@@ -27,21 +27,52 @@ import javax.persistence.ManyToOne;
 import javax.persistence.Table;
 
 @IdClass(HostComponentDesiredConfigMappingEntityPK.class)
-@Table(name = "hostcomponentdesiredconfigmapping", schema = "ambari", catalog = "")
+@Table(name = "hcdesiredconfigmapping")
 @Entity
 public class HostComponentDesiredConfigMappingEntity {
+
+  @Id
+  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
   private String serviceName;
+
+  @Id
+  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
   private String componentName;
+
+  @Id
+  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
   private String hostName;
+
+  @Id
+  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
   private String configType;
+
+  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   private String configTag;
+
+  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   private Long timestamp;
-  private HostComponentDesiredStateEntity hostComponentEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
+      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false),
+      @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false) })
+  private HostComponentDesiredStateEntity hostComponentDesiredStateEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
+  })
   private ClusterConfigEntity clusterConfigEntity;
 
-  @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -49,9 +80,7 @@ public class HostComponentDesiredConfigMappingEntity {
   public void setClusterId(Long id) {
     clusterId = id;
   }
-  
-  @Column(name = "service_name", insertable = false, updatable = false, nullable = false)
-  @Id
+
   public String getServiceName() {
     return serviceName;
   }
@@ -59,9 +88,7 @@ public class HostComponentDesiredConfigMappingEntity {
   public void setServiceName(String name) {
     serviceName = name;
   }
-  
-  @Column(name = "component_name", insertable = false, updatable = false, nullable = false)
-  @Id
+
   public String getComponentName() {
     return componentName;
   }
@@ -69,9 +96,7 @@ public class HostComponentDesiredConfigMappingEntity {
   public void setComponentName(String name) {
     componentName = name;
   }
-  
-  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
-  @Id
+
   public String getHostName() {
     return hostName;
   }
@@ -80,8 +105,6 @@ public class HostComponentDesiredConfigMappingEntity {
     hostName = name;
   }
 
-  @Column(name = "config_type", insertable = true, updatable = false, nullable = false)
-  @Id
   public String getConfigType() {
     return configType;
   }
@@ -89,8 +112,7 @@ public class HostComponentDesiredConfigMappingEntity {
   public void setConfigType(String type) {
     configType = type;
   }
-  
-  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
+
   public String getVersionTag() {
     return configTag;
   }
@@ -99,7 +121,6 @@ public class HostComponentDesiredConfigMappingEntity {
     configTag = tag;
   }
   
-  @Column(name="timestamp", nullable = false, insertable = true, updatable = true)
   public Long getTimestamp() {
     return timestamp;
   }
@@ -107,27 +128,15 @@ public class HostComponentDesiredConfigMappingEntity {
   public void setTimestamp(Long stamp) {
     timestamp = stamp;
   }
-  
-  @ManyToOne
-  @JoinColumns({
-    @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-    @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
-    @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false),
-    @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false) })
+
   public HostComponentDesiredStateEntity getHostComponentDesiredStateEntity() {
-    return hostComponentEntity;
+    return hostComponentDesiredStateEntity;
   }
   
   public void setHostComponentDesiredStateEntity(HostComponentDesiredStateEntity entity) {
-    hostComponentEntity = entity;
+    hostComponentDesiredStateEntity = entity;
   }
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
-  })
   public ClusterConfigEntity getClusterConfigEntity() {
     return clusterConfigEntity;
   }

+ 43 - 38
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java

@@ -23,14 +23,52 @@ import javax.persistence.*;
 
 import org.apache.ambari.server.state.State;
 
+import static org.apache.commons.lang.StringUtils.defaultString;
+
 @javax.persistence.IdClass(HostComponentDesiredStateEntityPK.class)
-@javax.persistence.Table(name = "hostcomponentdesiredstate", schema = "ambari", catalog = "")
+@javax.persistence.Table(name = "hostcomponentdesiredstate")
 @Entity
 public class HostComponentDesiredStateEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   @Id
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  private String serviceName;
+
+  @Id
+  @Column(name = "host_name", insertable = false, updatable = false)
+  private String hostName = "";
+
+  @Id
+  @Column(name = "component_name", insertable = false, updatable = false)
+  private String componentName = "";
+
+  @Basic
+  @Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
+  @Enumerated(value = EnumType.STRING)
+  private State desiredState = State.INIT;
+
+  @Basic
+  @Column(name = "desired_stack_version", insertable = true, updatable = true)
+  private String desiredStackVersion = "";
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
+      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)})
+  private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+  private HostEntity hostEntity;
+
+  @OneToMany(mappedBy = "hostComponentDesiredStateEntity", cascade = CascadeType.ALL)
+  private Collection<HostComponentDesiredConfigMappingEntity> desiredConfigMappingEntities;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -39,10 +77,6 @@ public class HostComponentDesiredStateEntity {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
-
-  @javax.persistence.Column(name = "service_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -51,35 +85,22 @@ public class HostComponentDesiredStateEntity {
     this.serviceName = serviceName;
   }
 
-  private String hostName = "";
-
-  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getHostName() {
-    return hostName;
+    return defaultString(hostName);
   }
 
   public void setHostName(String hostName) {
     this.hostName = hostName;
   }
 
-  private String componentName = "";
-
-  @javax.persistence.Column(name = "component_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getComponentName() {
-    return componentName;
+    return defaultString(componentName);
   }
 
   public void setComponentName(String componentName) {
     this.componentName = componentName;
   }
 
-  private State desiredState = State.INIT;
-
-  @javax.persistence.Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
-  @Enumerated(value = EnumType.STRING)
-  @Basic
   public State getDesiredState() {
     return desiredState;
   }
@@ -88,12 +109,8 @@ public class HostComponentDesiredStateEntity {
     this.desiredState = desiredState;
   }
 
-  private String desiredStackVersion = "";
-
-  @javax.persistence.Column(name = "desired_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getDesiredStackVersion() {
-    return desiredStackVersion;
+    return defaultString(desiredStackVersion);
   }
 
   public void setDesiredStackVersion(String desiredStackVersion) {
@@ -129,13 +146,7 @@ public class HostComponentDesiredStateEntity {
     return result;
   }
 
-  private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
-      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)})
   public ServiceComponentDesiredStateEntity getServiceComponentDesiredStateEntity() {
     return serviceComponentDesiredStateEntity;
   }
@@ -144,10 +155,6 @@ public class HostComponentDesiredStateEntity {
     this.serviceComponentDesiredStateEntity = serviceComponentDesiredStateEntity;
   }
 
-  private HostEntity hostEntity;
-
-  @ManyToOne
-  @javax.persistence.JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   public HostEntity getHostEntity() {
     return hostEntity;
   }
@@ -156,8 +163,6 @@ public class HostComponentDesiredStateEntity {
     this.hostEntity = hostEntity;
   }
 
-  private Collection<HostComponentDesiredConfigMappingEntity> desiredConfigMappingEntities;
-  @OneToMany(mappedBy = "hostComponentDesiredStateEntity", cascade = CascadeType.ALL)
   public Collection<HostComponentDesiredConfigMappingEntity> getHostComponentDesiredConfigMappingEntities() {
     return desiredConfigMappingEntities;
   }

+ 42 - 39
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java

@@ -24,14 +24,51 @@ import org.apache.ambari.server.state.State;
 
 import javax.persistence.*;
 
-@javax.persistence.IdClass(HostComponentStateEntityPK.class)
-@javax.persistence.Table(name = "hostcomponentstate", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@IdClass(HostComponentStateEntityPK.class)
+@Table(name = "hostcomponentstate")
 @Entity
 public class HostComponentStateEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
   @Id
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  private String serviceName;
+
+  @Id
+  @Column(name = "host_name", insertable = false, updatable = false)
+  private String hostName = "";
+
+  @Id
+  @Column(name = "component_name", nullable = false, insertable = false, updatable = false)
+  private String componentName;
+
+  @Enumerated(value = EnumType.STRING)
+  @Column(name = "current_state", nullable = false, insertable = true, updatable = true)
+  private State currentState = State.INIT;
+
+  @Basic
+  @Column(name = "current_stack_version", nullable = false, insertable = true, updatable = true)
+  private String currentStackVersion;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
+      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)})
+  private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+  private HostEntity hostEntity;
+
+  @OneToMany(mappedBy = "hostComponentStateEntity", cascade = CascadeType.ALL)
+  private Collection<HostComponentConfigMappingEntity> configMappingEntities;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -40,10 +77,6 @@ public class HostComponentStateEntity {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
-
-  @javax.persistence.Column(name = "service_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -52,22 +85,14 @@ public class HostComponentStateEntity {
     this.serviceName = serviceName;
   }
 
-  private String hostName = "";
-
-  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getHostName() {
-    return hostName;
+    return defaultString(hostName);
   }
 
   public void setHostName(String hostName) {
     this.hostName = hostName;
   }
 
-  private String componentName;
-
-  @javax.persistence.Column(name = "component_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getComponentName() {
     return componentName;
   }
@@ -76,10 +101,6 @@ public class HostComponentStateEntity {
     this.componentName = componentName;
   }
 
-  private State currentState = State.INIT;
-
-  @javax.persistence.Column(name = "current_state", nullable = false, insertable = true, updatable = true)
-  @Enumerated(value = EnumType.STRING)
   public State getCurrentState() {
     return currentState;
   }
@@ -88,10 +109,6 @@ public class HostComponentStateEntity {
     this.currentState = currentState;
   }
 
-  private String currentStackVersion;
-
-  @javax.persistence.Column(name = "current_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getCurrentStackVersion() {
     return currentStackVersion;
   }
@@ -129,13 +146,6 @@ public class HostComponentStateEntity {
     return result;
   }
 
-  private ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity;
-
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false),
-      @JoinColumn(name = "component_name", referencedColumnName = "component_name", nullable = false)})
   public ServiceComponentDesiredStateEntity getServiceComponentDesiredStateEntity() {
     return serviceComponentDesiredStateEntity;
   }
@@ -144,10 +154,6 @@ public class HostComponentStateEntity {
     this.serviceComponentDesiredStateEntity = serviceComponentDesiredStateEntity;
   }
 
-  private HostEntity hostEntity;
-
-  @ManyToOne
-  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   public HostEntity getHostEntity() {
     return hostEntity;
   }
@@ -156,9 +162,7 @@ public class HostComponentStateEntity {
     this.hostEntity = hostEntity;
   }
 
-  private Collection<HostComponentConfigMappingEntity> configMappingEntities;
-  @OneToMany(mappedBy = "hostComponentStateEntity", cascade = CascadeType.ALL)
-   public Collection<HostComponentConfigMappingEntity> getHostComponentConfigMappingEntities() {
+  public Collection<HostComponentConfigMappingEntity> getHostComponentConfigMappingEntities() {
     return configMappingEntities;
   }
 
@@ -167,5 +171,4 @@ public class HostComponentStateEntity {
   }
 
 
-
 }

+ 41 - 37
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostConfigMappingEntity.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -26,86 +26,90 @@ import javax.persistence.Table;
 /**
  * Entity that represents a host config mapping and override.
  */
-@Table(name = "hostconfigmapping", schema = "ambari", catalog = "")
+@Table(name = "hostconfigmapping")
 @Entity
 @IdClass(HostConfigMappingEntityPK.class)
 public class HostConfigMappingEntity {
+
+  @Id
+  @Column(name = "cluster_id", insertable = true, updatable = false, nullable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "host_name", insertable = true, updatable = false, nullable = false)
   private String hostName;
-  private String typeName;
+
+  @Id
+  @Column(name = "type_name", insertable = true, updatable = false, nullable = false)
+  private String type;
+
+  @Id
+  @Column(name = "create_timestamp", insertable = true, updatable = false, nullable = false)
+  private Long createTimestamp;
+
+  @Column(name = "version_tag", insertable = true, updatable = false, nullable = false)
   private String versionTag;
+
+  @Column(name = "service_name", insertable = true, updatable = true)
   private String serviceName;
-  private Long createTimestamp;
-  private int selectedInd = 0;
-  
-  @Column(name = "cluster_id", insertable = true, updatable = false, nullable = false)
-  @Id
+
+  @Column(name = "selected", insertable = true, updatable = true, nullable = false)
+  private int selected = 0;
+
   public Long getClusterId() {
     return clusterId;
   }
-  
+
   public void setClusterId(Long id) {
     clusterId = id;
   }
-  
-  @Column(name = "host_name", insertable = true, updatable = false, nullable = false)
-  @Id
+
   public String getHostName() {
     return hostName;
   }
-  
+
   public void setHostName(String name) {
     hostName = name;
   }
-  
-  @Column(name = "type_name", insertable = true, updatable = false, nullable = false)
-  @Id
+
   public String getType() {
-    return typeName;
+    return type;
   }
-  
+
   public void setType(String type) {
-    typeName = type;
+    this.type = type;
   }
-  
-  @Column(name = "create_timestamp", insertable = true, updatable = false, nullable = false)
-  @Id
+
   public Long getCreateTimestamp() {
     return createTimestamp;
   }
-  
+
   public void setCreateTimestamp(Long timestamp) {
     createTimestamp = timestamp;
   }
-  
-  
-  @Column(name = "version_tag", insertable = true, updatable = false, nullable = false)
+
   public String getVersion() {
     return versionTag;
   }
-  
+
   public void setVersion(String version) {
     versionTag = version;
   }
- 
 
-  @Column(name = "selected", insertable = true, updatable = true, nullable = false)
   public int isSelected() {
-    return selectedInd;
+    return selected;
   }
 
   public void setSelected(int selected) {
-    selectedInd = selected;
-  }  
-  
-  
-  @Column(name = "service_name", insertable = true, updatable = true)
+    this.selected = selected;
+  }
+
   public String getServiceName() {
     return serviceName;
   }
-  
+
   public void setServiceName(String name) {
     serviceName = name;
   }
-  
+
 }

+ 8 - 7
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostConfigMappingEntityPK.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -19,15 +19,16 @@ package org.apache.ambari.server.orm.entities;
 
 import javax.persistence.Column;
 import javax.persistence.Id;
+import java.io.Serializable;
 
 /**
  * PK class for host config mappings.
  *
  */
-public class HostConfigMappingEntityPK {
+public class HostConfigMappingEntityPK implements Serializable {
   private Long clusterId;
   private String hostName;
-  private String typeName;
+  private String type;
   private Long createTimestamp;
 
   @Column(name = "cluster_id", nullable = false, insertable = true, updatable = true, length = 10)
@@ -53,11 +54,11 @@ public class HostConfigMappingEntityPK {
   @Column(name = "type_name", insertable = true, updatable = true, nullable = false)
   @Id
   public String getType() {
-    return typeName;
+    return type;
   }
   
   public void setType(String type) {
-    typeName = type;
+    this.type = type;
   }
   
   @Column(name = "create_timestamp", insertable = true, updatable = true, nullable = false)
@@ -81,7 +82,7 @@ public class HostConfigMappingEntityPK {
 
     if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId != null) return false;
     if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
-    if (typeName != null ? !typeName.equals(that.typeName) : that.typeName != null) return false;
+    if (type != null ? !type.equals(that.type) : that.type != null) return false;
     if (createTimestamp != null ? !createTimestamp.equals (that.createTimestamp) : that.createTimestamp != null) return false;
 
     return true;
@@ -90,7 +91,7 @@ public class HostConfigMappingEntityPK {
   @Override
   public int hashCode() {
     int result = clusterId !=null ? clusterId.intValue() : 0;
-    result = 31 * result + (typeName != null ? typeName.hashCode() : 0);
+    result = 31 * result + (type != null ? type.hashCode() : 0);
     result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
     result = 31 * result + createTimestamp.intValue();
     return result;

+ 101 - 120
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java

@@ -21,13 +21,101 @@ package org.apache.ambari.server.orm.entities;
 import javax.persistence.*;
 import java.util.Collection;
 
-@javax.persistence.Table(name = "hosts", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@javax.persistence.Table(name = "hosts")
 @Entity
 public class HostEntity {
-  private String hostName;
 
-  @javax.persistence.Column(name = "host_name", nullable = false, insertable = true, updatable = true)
   @Id
+  @Column(name = "host_name", nullable = false, insertable = true, updatable = true)
+  private String hostName;
+
+  @Column(name = "ipv4", nullable = true, insertable = true, updatable = true)
+  @Basic
+  private String ipv4;
+
+  @Column(name = "ipv6", nullable = true, insertable = true, updatable = true)
+  @Basic
+  private String ipv6;
+
+  @Column(name="public_host_name", nullable = true, insertable = true, updatable = true)
+  @Basic
+  private String publicHostName;
+
+  @Column(name = "total_mem", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Long totalMem = 0L;
+
+  @Column(name = "cpu_count", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Integer cpuCount = 0;
+
+  @Column(name = "ph_cpu_count", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Integer phCpuCount = 0;
+
+  @Column(name = "cpu_info", insertable = true, updatable = true)
+  @Basic
+  private String cpuInfo = "";
+
+  @Column(name = "os_arch", insertable = true, updatable = true)
+  @Basic
+  private String osArch = "";
+
+  @Lob
+  @Column(name = "disks_info", nullable = false, insertable = true,
+      updatable = true, length = 10000)
+  @Basic
+  private String disksInfo = "";
+
+  @Column(name = "os_info", insertable = true, updatable = true,
+      length = 1000)
+  @Basic
+  private String osInfo = "";
+
+  @Column(name = "os_type", insertable = true, updatable = true)
+  @Basic
+  private String osType = "";
+
+  @Column(name = "discovery_status", insertable = true, updatable = true,
+      length = 2000)
+  @Basic
+  private String discoveryStatus = "";
+
+  @Column(name = "last_registration_time", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Long lastRegistrationTime = 0L;
+
+  @Column(name = "rack_info", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private String rackInfo = "/default-rack";
+
+  @Column(name = "host_attributes", insertable = true, updatable = true,
+      length = 20000)
+  @Basic
+  @Lob
+  private String hostAttributes = "";
+
+  @OneToMany(mappedBy = "hostEntity")
+  private Collection<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  private Collection<HostComponentStateEntity> hostComponentStateEntities;
+
+  @ManyToMany
+  @JoinTable(name = "ClusterHostMapping",
+      joinColumns = {@JoinColumn(name = "host_name", referencedColumnName = "host_name")},
+      inverseJoinColumns = {@JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")}
+  )
+  private Collection<ClusterEntity> clusterEntities;
+
+  @OneToOne(mappedBy = "hostEntity")
+  private HostStateEntity hostStateEntity;
+
+  @OneToMany(mappedBy = "host")
+  private Collection<HostRoleCommandEntity> hostRoleCommandEntities;
+
   public String getHostName() {
     return hostName;
   }
@@ -36,10 +124,6 @@ public class HostEntity {
     this.hostName = hostName;
   }
 
-  private String ipv4;
-
-  @javax.persistence.Column(name = "ipv4", nullable = true, insertable = true, updatable = true)
-  @Basic
   public String getIpv4() {
     return ipv4;
   }
@@ -48,10 +132,6 @@ public class HostEntity {
     this.ipv4 = ipv4;
   }
 
-  private String ipv6;
-
-  @javax.persistence.Column(name = "ipv6", nullable = true, insertable = true, updatable = true)
-  @Basic
   public String getIpv6() {
     return ipv6;
   }
@@ -59,22 +139,15 @@ public class HostEntity {
   public void setIpv6(String ipv6) {
     this.ipv6 = ipv6;
   }
-  
-  private String publicHostName;
-  @Column(name="public_host_name", nullable = true, insertable = true, updatable = true)
-  @Basic
+
   public String getPublicHostName() {
     return publicHostName;
   }
-  
+
   public void setPublicHostName(String name) {
     publicHostName = name;
   }
 
-  private Long totalMem = 0L;
-
-  @javax.persistence.Column(name = "total_mem", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public Long getTotalMem() {
     return totalMem;
   }
@@ -83,10 +156,6 @@ public class HostEntity {
     this.totalMem = totalMem;
   }
 
-  private Integer cpuCount = 0;
-
-  @javax.persistence.Column(name = "cpu_count", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public Integer getCpuCount() {
     return cpuCount;
   }
@@ -94,11 +163,7 @@ public class HostEntity {
   public void setCpuCount(Integer cpuCount) {
     this.cpuCount = cpuCount;
   }
-
-  private Integer phCpuCount = 0;
-
-  @javax.persistence.Column(name = "ph_cpu_count", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
+  
   public Integer getPhCpuCount() {
     return phCpuCount;
   }
@@ -107,87 +172,54 @@ public class HostEntity {
     this.phCpuCount = phCpuCount;
   }
   
-  
-  
-  private String cpuInfo = "";
-
-  @javax.persistence.Column(name = "cpu_info", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getCpuInfo() {
-    return cpuInfo;
+    return defaultString(cpuInfo);
   }
 
   public void setCpuInfo(String cpuInfo) {
     this.cpuInfo = cpuInfo;
   }
 
-  private String osArch = "";
-
-  @javax.persistence.Column(name = "os_arch", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getOsArch() {
-    return osArch;
+    return defaultString(osArch);
   }
 
   public void setOsArch(String osArch) {
     this.osArch = osArch;
   }
 
-  private String disksInfo = "";
-
-  @javax.persistence.Column(name = "disks_info", nullable = false, insertable = true,
-		  updatable = true, length = 2000)
-  @Basic
   public String getDisksInfo() {
-    return disksInfo;
+    return defaultString(disksInfo);
   }
 
   public void setDisksInfo(String disksInfo) {
     this.disksInfo = disksInfo;
   }
 
-  private String osInfo = "";
-
-  @javax.persistence.Column(name = "os_info", nullable = false, insertable = true, updatable = true,
-      length = 1000)
-  @Basic
   public String getOsInfo() {
-    return osInfo;
+    return defaultString(osInfo);
   }
 
   public void setOsInfo(String osInfo) {
     this.osInfo = osInfo;
   }
 
-  private String osType = "";
-
-  @javax.persistence.Column(name = "os_type", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getOsType() {
-    return osType;
+    return defaultString(osType);
   }
 
   public void setOsType(String osType) {
     this.osType = osType;
   }
 
-  private String discoveryStatus = "";
-
-  @javax.persistence.Column(name = "discovery_status", nullable = false, insertable = true, updatable = true,
-      length = 2000)
-  @Basic
   public String getDiscoveryStatus() {
-    return discoveryStatus;
+    return defaultString(discoveryStatus);
   }
 
   public void setDiscoveryStatus(String discoveryStatus) {
     this.discoveryStatus = discoveryStatus;
   }
 
-  private Long lastRegistrationTime = 0L;
-
-  @javax.persistence.Column(name = "last_registration_time", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public Long getLastRegistrationTime() {
     return lastRegistrationTime;
   }
@@ -196,10 +228,6 @@ public class HostEntity {
     this.lastRegistrationTime = lastRegistrationTime;
   }
 
-  private String rackInfo = "/default-rack";
-
-  @javax.persistence.Column(name = "rack_info", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getRackInfo() {
     return rackInfo;
   }
@@ -208,13 +236,8 @@ public class HostEntity {
     this.rackInfo = rackInfo;
   }
 
-  private String hostAttributes = "";
-
-  @javax.persistence.Column(name = "host_attributes", nullable = false, insertable = true, updatable = true,
-      length = 20000)
-  @Basic
   public String getHostAttributes() {
-    return hostAttributes;
+    return defaultString(hostAttributes);
   }
 
   public void setHostAttributes(String hostAttributes) {
@@ -265,9 +288,6 @@ public class HostEntity {
     return result;
   }
 
-  private Collection<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities;
-
-  @OneToMany(mappedBy = "hostEntity")
   public Collection<HostComponentDesiredStateEntity> getHostComponentDesiredStateEntities() {
     return hostComponentDesiredStateEntities;
   }
@@ -276,9 +296,6 @@ public class HostEntity {
     this.hostComponentDesiredStateEntities = hostComponentDesiredStateEntities;
   }
 
-  private Collection<HostComponentStateEntity> hostComponentStateEntities;
-
-  @OneToMany(mappedBy = "hostEntity")
   public Collection<HostComponentStateEntity> getHostComponentStateEntities() {
     return hostComponentStateEntities;
   }
@@ -287,15 +304,6 @@ public class HostEntity {
     this.hostComponentStateEntities = hostComponentStateEntities;
   }
 
-  private Collection<ClusterEntity> clusterEntities;
-
-  @ManyToMany
-//  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")
-  @JoinTable(name = "ClusterHostMapping", catalog = "", schema = "ambari",
-          joinColumns = {@JoinColumn(name = "host_name", referencedColumnName = "host_name")},
-          inverseJoinColumns = {@JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")}
-
-  )
   public Collection<ClusterEntity> getClusterEntities() {
     return clusterEntities;
   }
@@ -304,9 +312,6 @@ public class HostEntity {
     this.clusterEntities = clusterEntities;
   }
 
-  private HostStateEntity hostStateEntity;
-
-  @OneToOne(mappedBy = "hostEntity")
   public HostStateEntity getHostStateEntity() {
     return hostStateEntity;
   }
@@ -315,9 +320,6 @@ public class HostEntity {
     this.hostStateEntity = hostStateEntity;
   }
 
-  private Collection<HostRoleCommandEntity> hostRoleCommandEntities;
-
-  @OneToMany(mappedBy = "host")
   public Collection<HostRoleCommandEntity> getHostRoleCommandEntities() {
     return hostRoleCommandEntities;
   }
@@ -326,25 +328,4 @@ public class HostEntity {
     this.hostRoleCommandEntities = hostRoleCommandEntities;
   }
 
-  //  private Collection<ServiceComponentStateEntity> serviceComponentStateEntities;
-//
-//  @OneToMany(mappedBy = "hostEntity")
-//  public Collection<ServiceComponentStateEntity> getServiceComponentStateEntities() {
-//    return serviceComponentStateEntities;
-//  }
-//
-//  public void setServiceComponentStateEntities(Collection<ServiceComponentStateEntity> serviceComponentStateEntities) {
-//    this.serviceComponentStateEntities = serviceComponentStateEntities;
-//  }
-
-//  private Collection<ServiceStateEntity> serviceStateEntities;
-//
-//  @OneToMany(mappedBy = "hostEntity")
-//  public Collection<ServiceStateEntity> getServiceStateEntities() {
-//    return serviceStateEntities;
-//  }
-//
-//  public void setServiceStateEntities(Collection<ServiceStateEntity> serviceStateEntities) {
-//    this.serviceStateEntities = serviceStateEntities;
-//  }
 }

+ 83 - 72
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java

@@ -21,20 +21,96 @@ package org.apache.ambari.server.orm.entities;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
+import org.apache.commons.lang.ArrayUtils;
 
 import javax.persistence.*;
 import java.util.Arrays;
 
-@Table(name = "host_role_command", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@Table(name = "host_role_command")
 @Entity
 @Cacheable(false)
-@SequenceGenerator(name = "ambari.host_role_command_task_id_seq", allocationSize = 50)
+@TableGenerator(name = "host_role_command_id_generator",
+    table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "value"
+    , pkColumnValue = "host_role_command_id_seq"
+    , initialValue = 1
+    , allocationSize = 50
+)
+
 public class HostRoleCommandEntity {
-  private Long taskId;
 
   @Column(name = "task_id")
   @Id
-  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ambari.host_role_command_task_id_seq")
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = "host_role_command_id_generator")
+  private Long taskId;
+
+  @Column(name = "request_id", insertable = false, updatable = false, nullable = false)
+  @Basic
+  private Long requestId;
+
+  @Column(name = "stage_id", insertable = false, updatable = false, nullable = false)
+  @Basic
+  private Long stageId;
+
+  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
+  @Basic
+  private String hostName;
+
+  @Column(name = "role")
+  @Enumerated(EnumType.STRING)
+  private Role role;
+
+  @Column(name = "event", length = 32000)
+  @Basic
+  @Lob
+  private String event = "";
+
+  @Column(name = "exitcode", nullable = false)
+  @Basic
+  private Integer exitcode = 0;
+
+  @Column(name = "status")
+  @Enumerated(EnumType.STRING)
+  private HostRoleStatus status;
+
+  @Column(name = "std_error")
+  @Lob
+  @Basic
+  private byte[] stdError = new byte[0];
+
+  @Column(name = "std_out")
+  @Lob
+  @Basic
+  private byte[] stdOut = new byte[0];
+
+  @Basic
+  @Column(name = "start_time", nullable = false)
+  private Long startTime = -1L;
+
+  @Basic
+  @Column(name = "last_attempt_time", nullable = false)
+  private Long lastAttemptTime = -1L;
+
+  @Basic
+  @Column(name = "attempt_count", nullable = false)
+  private Short attemptCount = 0;
+
+  @Column(name = "role_command")
+  @Enumerated(EnumType.STRING)
+  private RoleCommand roleCommand;
+
+  @OneToOne(mappedBy = "hostRoleCommand", cascade = CascadeType.REMOVE)
+  private ExecutionCommandEntity executionCommand;
+
+  @ManyToOne(cascade = {CascadeType.MERGE})
+  @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
+  private StageEntity stage;
+
+  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
+  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+  private HostEntity host;
+
   public Long getTaskId() {
     return taskId;
   }
@@ -43,10 +119,6 @@ public class HostRoleCommandEntity {
     this.taskId = taskId;
   }
 
-  private Long requestId;
-
-  @Column(name = "request_id", insertable = false, updatable = false, nullable = false)
-  @Basic
   public Long getRequestId() {
     return requestId;
   }
@@ -55,10 +127,6 @@ public class HostRoleCommandEntity {
     this.requestId = requestId;
   }
 
-  private Long stageId;
-
-  @Column(name = "stage_id", insertable = false, updatable = false, nullable = false)
-  @Basic
   public Long getStageId() {
     return stageId;
   }
@@ -67,10 +135,6 @@ public class HostRoleCommandEntity {
     this.stageId = stageId;
   }
 
-  private String hostName;
-
-  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
-  @Basic
   public String getHostName() {
     return hostName;
   }
@@ -79,10 +143,6 @@ public class HostRoleCommandEntity {
     this.hostName = hostName;
   }
 
-  private Role role;
-
-  @Column(name = "role")
-  @Enumerated(EnumType.STRING)
   public Role getRole() {
     return role;
   }
@@ -91,22 +151,14 @@ public class HostRoleCommandEntity {
     this.role = role;
   }
 
-  private String event = "";
-
-  @Column(name = "event", nullable = false, length = 32000)
-  @Basic
   public String getEvent() {
-    return event;
+    return defaultString(event);
   }
 
   public void setEvent(String event) {
     this.event = event;
   }
 
-  private Integer exitcode = 0;
-
-  @Column(name = "exitcode", nullable = false)
-  @Basic
   public Integer getExitcode() {
     return exitcode;
   }
@@ -115,10 +167,6 @@ public class HostRoleCommandEntity {
     this.exitcode = exitcode;
   }
 
-  private HostRoleStatus status;
-
-  @Column(name = "status")
-  @Enumerated(EnumType.STRING)
   public HostRoleStatus getStatus() {
     return status;
   }
@@ -127,36 +175,22 @@ public class HostRoleCommandEntity {
     this.status = status;
   }
 
-  private byte[] stdError = new byte[0];
-
-  @Column(name = "std_error", nullable = false)
-  @Lob
-  @Basic
   public byte[] getStdError() {
-    return stdError;
+    return ArrayUtils.nullToEmpty(stdError);
   }
 
   public void setStdError(byte[] stdError) {
     this.stdError = stdError;
   }
 
-  private byte[] stdOut = new byte[0];
-
-  @Column(name = "std_out", nullable = false)
-  @Lob
-  @Basic
   public byte[] getStdOut() {
-    return stdOut;
+    return ArrayUtils.nullToEmpty(stdOut);
   }
 
   public void setStdOut(byte[] stdOut) {
     this.stdOut = stdOut;
   }
 
-  private Long startTime = -1L;
-
-  @Column(name = "start_time", nullable = false)
-  @Basic
   public Long getStartTime() {
     return startTime;
   }
@@ -165,10 +199,6 @@ public class HostRoleCommandEntity {
     this.startTime = startTime;
   }
 
-  private Long lastAttemptTime = -1L;
-
-  @Column(name = "last_attempt_time", nullable = false)
-  @Basic
   public Long getLastAttemptTime() {
     return lastAttemptTime;
   }
@@ -177,10 +207,6 @@ public class HostRoleCommandEntity {
     this.lastAttemptTime = lastAttemptTime;
   }
 
-  private Short attemptCount = 0;
-
-  @Column(name = "attempt_count", nullable = false)
-  @Basic
   public Short getAttemptCount() {
     return attemptCount;
   }
@@ -189,10 +215,6 @@ public class HostRoleCommandEntity {
     this.attemptCount = attemptCount;
   }
 
-  private RoleCommand roleCommand;
-
-  @Column(name = "role_command")
-  @Enumerated(EnumType.STRING)
   public RoleCommand getRoleCommand() {
     return roleCommand;
   }
@@ -244,9 +266,6 @@ public class HostRoleCommandEntity {
     return result;
   }
 
-  private ExecutionCommandEntity executionCommand;
-
-  @OneToOne(mappedBy = "hostRoleCommand", cascade = CascadeType.REMOVE)
   public ExecutionCommandEntity getExecutionCommand() {
     return executionCommand;
   }
@@ -255,10 +274,6 @@ public class HostRoleCommandEntity {
     this.executionCommand = executionCommandsByTaskId;
   }
 
-  private StageEntity stage;
-
-  @ManyToOne(cascade = {CascadeType.MERGE})
-  @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
   public StageEntity getStage() {
     return stage;
   }
@@ -267,10 +282,6 @@ public class HostRoleCommandEntity {
     this.stage = stage;
   }
 
-  private HostEntity host;
-
-  @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
-  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   public HostEntity getHost() {
     return host;
   }

+ 32 - 40
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java

@@ -19,16 +19,44 @@
 package org.apache.ambari.server.orm.entities;
 
 import org.apache.ambari.server.state.HostState;
+import org.apache.commons.lang.StringUtils;
 
 import javax.persistence.*;
 
-@javax.persistence.Table(name = "hoststate", schema = "ambari", catalog = "")
+import static org.apache.commons.lang.StringUtils.defaultString;
+
+@javax.persistence.Table(name = "hoststate")
 @Entity
 public class HostStateEntity {
-  private String hostName;
-
+  
   @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
   @Id
+  private String hostName;
+
+  @Column(name = "available_mem", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Long availableMem = 0L;
+
+  @javax.persistence.Column(name = "time_in_state", nullable = false, insertable = true, updatable = true)
+  @Basic
+  private Long timeInState = 0L;
+
+  @Column(name = "health_status", insertable = true, updatable = true)
+  @Basic
+  private String healthStatus;
+
+  @Column(name = "agent_version", insertable = true, updatable = true)
+  @Basic
+  private String agentVersion = "";
+
+  @Column(name = "current_state", nullable = false, insertable = true, updatable = true)
+  @Enumerated(value = EnumType.STRING)
+  private HostState currentState = HostState.INIT;
+
+  @OneToOne
+  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+  private HostEntity hostEntity;
+
   public String getHostName() {
     return hostName;
   }
@@ -37,10 +65,6 @@ public class HostStateEntity {
     this.hostName = hostName;
   }
 
-  private Long availableMem = 0L;
-
-  @Column(name = "available_mem", nullable = false, insertable = true, updatable = true)
-  @Basic
   public Long getAvailableMem() {
     return availableMem;
   }
@@ -49,10 +73,6 @@ public class HostStateEntity {
     this.availableMem = availableMem;
   }
 
-  private Long timeInState = 0L;
-
-  @javax.persistence.Column(name = "time_in_state", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public Long getTimeInState() {
     return timeInState;
   }
@@ -61,10 +81,6 @@ public class HostStateEntity {
     this.timeInState = timeInState;
   }
 
-  private String healthStatus;
-
-  @Column(name = "health_status", insertable = true, updatable = true)
-  @Basic
   public String getHealthStatus() {
     return healthStatus;
   }
@@ -73,22 +89,14 @@ public class HostStateEntity {
     this.healthStatus = healthStatus;
   }
 
-  private String agentVersion = "";
-
-  @javax.persistence.Column(name = "agent_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getAgentVersion() {
-    return agentVersion;
+    return defaultString(agentVersion);
   }
 
   public void setAgentVersion(String agentVersion) {
     this.agentVersion = agentVersion;
   }
 
-  private HostState currentState = HostState.INIT;
-
-  @javax.persistence.Column(name = "current_state", nullable = false, insertable = true, updatable = true)
-  @Enumerated(value = EnumType.STRING)
   public HostState getCurrentState() {
     return currentState;
   }
@@ -123,22 +131,6 @@ public class HostStateEntity {
     return result;
   }
 
-//  private ClusterEntity clusterEntity;
-//
-//  @ManyToOne
-//  @javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")
-//  public ClusterEntity getClusterEntity() {
-//    return clusterEntity;
-//  }
-//
-//  public void setClusterEntity(ClusterEntity clusterEntity) {
-//    this.clusterEntity = clusterEntity;
-//  }
-
-  private HostEntity hostEntity;
-
-  @OneToOne
-  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   public HostEntity getHostEntity() {
     return hostEntity;
   }

+ 7 - 8
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KeyValueEntity.java

@@ -19,20 +19,20 @@
 package org.apache.ambari.server.orm.entities;
 
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
-@Table(name = "key_value_store", schema = "ambari", catalog = "")
+@Table(name = "key_value_store")
 @Entity
 public class KeyValueEntity {
 
+  @Column(name = "\"key\"", length = 255)
+  @Id
   private String key;
+
+  @Column(name = "\"value\"", length = 32000)
+  @Lob
   private String value;
 
-  @Column(name = "\"key\"", length = 255)
-  @Id
   public String getKey() {
     return key;
   }
@@ -41,7 +41,6 @@ public class KeyValueEntity {
     this.key = key;
   }
 
-  @Column(name = "\"value\"", length = 32000)
   public String getValue() {
     return value;
   }

+ 8 - 8
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/MetainfoEntity.java

@@ -19,20 +19,21 @@
 package org.apache.ambari.server.orm.entities;
 
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 
-@Table(name = "metainfo", schema = "ambari", catalog = "")
+@Table(name = "metainfo")
 @Entity
 public class MetainfoEntity {
 
+  @Column(name = "\"metainfo_key\"", length = 255)
+  @Id
   private String metainfoName;
+
+  @Column(name = "\"metainfo_value\"", length = 32000)
+  @Basic
+  @Lob
   private String metainfoValue;
 
-  @Column(name = "\"metainfo_key\"", length = 255)
-  @Id
   public String getMetainfoName() {
     return metainfoName;
   }
@@ -41,7 +42,6 @@ public class MetainfoEntity {
     this.metainfoName = metainfoName;
   }
 
-  @Column(name = "\"metainfo_value\"", length = 32000)
   public String getMetainfoValue() {
     return metainfoValue;
   }

+ 10 - 15
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RoleEntity.java

@@ -18,22 +18,23 @@
 
 package org.apache.ambari.server.orm.entities;
 
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
+import javax.persistence.*;
 import java.util.Set;
 
-@javax.persistence.Table(name = "roles", schema = "ambari", catalog = "")
+@javax.persistence.Table(name = "roles")
 @Entity
 public class RoleEntity {
 
+  @Column(name = "role_name")
+  @Id
   private String roleName;
 
-  @javax.persistence.Column(name = "role_name")
-  @Id
+  @JoinTable(name = "user_roles",
+      joinColumns = {@JoinColumn(name = "role_name", referencedColumnName = "role_name")},
+      inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")})
+  @ManyToMany(cascade = CascadeType.ALL)
+  private Set<UserEntity> userEntities;
+
   public String getRoleName() {
     return roleName;
   }
@@ -59,12 +60,6 @@ public class RoleEntity {
     return roleName != null ? roleName.hashCode() : 0;
   }
 
-  private Set<org.apache.ambari.server.orm.entities.UserEntity> userEntities;
-
-  @JoinTable(name = "user_roles", catalog = "", schema = "ambari",
-      joinColumns = {@JoinColumn(name = "role_name", referencedColumnName = "role_name")},
-      inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")})
-  @ManyToMany(cascade = CascadeType.ALL)
   public Set<org.apache.ambari.server.orm.entities.UserEntity> getUserEntities() {
     return userEntities;
   }

+ 20 - 19
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RoleSuccessCriteriaEntity.java

@@ -23,13 +23,31 @@ import org.apache.ambari.server.Role;
 import javax.persistence.*;
 
 @IdClass(org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntityPK.class)
-@Table(name = "role_success_criteria", schema = "ambari", catalog = "")
+@Table(name = "role_success_criteria")
 @Entity
 public class RoleSuccessCriteriaEntity {
-  private Long requestId;
 
+  @Id
   @Column(name = "request_id", insertable = false, updatable = false, nullable = false)
+  private Long requestId;
+
+  @Id
+  @Column(name = "stage_id", insertable = false, updatable = false, nullable = false)
+  private Long stageId;
+
   @Id
+  @Column(name = "role")
+  @Enumerated(EnumType.STRING)
+  private Role role;
+
+  @Basic
+  @Column(name = "success_factor", nullable = false)
+  private Double successFactor = 1d;
+
+  @ManyToOne
+  @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
+  private StageEntity stage;
+
   public Long getRequestId() {
     return requestId;
   }
@@ -38,10 +56,6 @@ public class RoleSuccessCriteriaEntity {
     this.requestId = requestId;
   }
 
-  private Long stageId;
-
-  @Column(name = "stage_id", insertable = false, updatable = false, nullable = false)
-  @Id
   public Long getStageId() {
     return stageId;
   }
@@ -50,11 +64,6 @@ public class RoleSuccessCriteriaEntity {
     this.stageId = stageId;
   }
 
-  private Role role;
-
-  @Column(name = "role")
-  @Enumerated(EnumType.STRING)
-  @Id
   public Role getRole() {
     return role;
   }
@@ -63,10 +72,6 @@ public class RoleSuccessCriteriaEntity {
     this.role = role;
   }
 
-  private Double successFactor = 1d;
-
-  @Column(name = "success_factor", nullable = false)
-  @Basic
   public Double getSuccessFactor() {
     return successFactor;
   }
@@ -99,10 +104,6 @@ public class RoleSuccessCriteriaEntity {
     return result;
   }
 
-  private StageEntity stage;
-
-  @ManyToOne
-  @JoinColumns({@JoinColumn(name = "request_id", referencedColumnName = "request_id", nullable = false), @JoinColumn(name = "stage_id", referencedColumnName = "stage_id", nullable = false)})
   public StageEntity getStage() {
     return stage;
   }

+ 36 - 31
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java

@@ -19,18 +19,51 @@
 package org.apache.ambari.server.orm.entities;
 
 import org.apache.ambari.server.state.State;
+import org.apache.commons.lang.StringUtils;
 
 import javax.persistence.*;
 import java.util.Collection;
 
+import static org.apache.commons.lang.StringUtils.defaultString;
+
 @javax.persistence.IdClass(ServiceComponentDesiredStateEntityPK.class)
-@javax.persistence.Table(name = "servicecomponentdesiredstate", schema = "ambari", catalog = "")
+@javax.persistence.Table(name = "servicecomponentdesiredstate")
 @Entity
 public class ServiceComponentDesiredStateEntity {
+
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
+  @Id
   private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
   @Id
+  private String serviceName;
+
+  @Column(name = "component_name", nullable = false, insertable = true, updatable = true)
+  @Id
+  private String componentName;
+
+  @Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
+  @Enumerated(EnumType.STRING)
+  private State desiredState = State.INIT;
+
+  @Column(name = "desired_stack_version", insertable = true, updatable = true)
+  @Basic
+  private String desiredStackVersion = "";
+
+  @ManyToOne
+  @JoinColumns({@javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false), @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)})
+  private ClusterServiceEntity clusterServiceEntity;
+
+  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
+  private Collection<HostComponentStateEntity> hostComponentStateEntities;
+
+  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
+  private Collection<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities;
+
+  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity", cascade = CascadeType.ALL)
+  private Collection<ComponentConfigMappingEntity> configMappingEntities;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -39,10 +72,6 @@ public class ServiceComponentDesiredStateEntity {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
-
-  @javax.persistence.Column(name = "service_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -51,10 +80,6 @@ public class ServiceComponentDesiredStateEntity {
     this.serviceName = serviceName;
   }
 
-  private String componentName;
-
-  @javax.persistence.Column(name = "component_name", nullable = false, insertable = true, updatable = true)
-  @Id
   public String getComponentName() {
     return componentName;
   }
@@ -63,10 +88,6 @@ public class ServiceComponentDesiredStateEntity {
     this.componentName = componentName;
   }
 
-  private State desiredState = State.INIT;
-
-  @javax.persistence.Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
-  @Enumerated(EnumType.STRING)
   public State getDesiredState() {
     return desiredState;
   }
@@ -75,12 +96,8 @@ public class ServiceComponentDesiredStateEntity {
     this.desiredState = desiredState;
   }
 
-  private String desiredStackVersion = "";
-
-  @javax.persistence.Column(name = "desired_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getDesiredStackVersion() {
-    return desiredStackVersion;
+    return defaultString(desiredStackVersion);
   }
 
   public void setDesiredStackVersion(String desiredStackVersion) {
@@ -114,10 +131,6 @@ public class ServiceComponentDesiredStateEntity {
     return result;
   }
 
-  private ClusterServiceEntity clusterServiceEntity;
-
-  @ManyToOne
-  @javax.persistence.JoinColumns({@javax.persistence.JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false), @javax.persistence.JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)})
   public ClusterServiceEntity getClusterServiceEntity() {
     return clusterServiceEntity;
   }
@@ -126,9 +139,6 @@ public class ServiceComponentDesiredStateEntity {
     this.clusterServiceEntity = clusterServiceEntity;
   }
 
-  private Collection<HostComponentStateEntity> hostComponentStateEntities;
-
-  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
   public Collection<HostComponentStateEntity> getHostComponentStateEntities() {
     return hostComponentStateEntities;
   }
@@ -137,9 +147,6 @@ public class ServiceComponentDesiredStateEntity {
     this.hostComponentStateEntities = hostComponentStateEntities;
   }
 
-  private Collection<HostComponentDesiredStateEntity> hostComponentDesiredStateEntities;
-
-  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
   public Collection<HostComponentDesiredStateEntity> getHostComponentDesiredStateEntities() {
     return hostComponentDesiredStateEntities;
   }
@@ -148,8 +155,6 @@ public class ServiceComponentDesiredStateEntity {
     this.hostComponentDesiredStateEntities = hostComponentDesiredStateEntities;
   }
 
-  private Collection<ComponentConfigMappingEntity> configMappingEntities;
-  @OneToMany(mappedBy = "serviceComponentDesiredStateEntity", cascade = CascadeType.ALL)
   public Collection<ComponentConfigMappingEntity> getComponentConfigMappingEntities() {
     return configMappingEntities;
   }

+ 26 - 19
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigMappingEntity.java

@@ -28,18 +28,41 @@ import javax.persistence.Table;
 
 @IdClass(ServiceConfigMappingEntityPK.class)
 @Entity
-@Table(name="serviceconfigmapping", schema="ambari", catalog="")
+@Table(name="serviceconfigmapping")
 public class ServiceConfigMappingEntity {
+
+  @Id
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false)
   private Long clusterId;
+
+  @Id
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
   private String serviceName;
+
+  @Id
+  @Column(name = "config_type", nullable = false, insertable = true, updatable = false)
   private String configType;
+
+  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   private String configVersion;
+
+  @Column(name = "timestamp", nullable = false, insertable = true, updatable = true)
   private Long timestamp;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false) })
   private ClusterServiceEntity serviceEntity;
+
+  @ManyToOne
+  @JoinColumns({
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
+      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
+  })
   private ClusterConfigEntity clusterConfigEntity;
 
-  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false)
-  @Id
   public Long getClusterId() {
     return clusterId;
   }
@@ -48,8 +71,6 @@ public class ServiceConfigMappingEntity {
     clusterId = id;
   }
 
-  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -58,8 +79,6 @@ public class ServiceConfigMappingEntity {
     serviceName = name;
   }
 
-  @Column(name = "config_type", nullable = false, insertable = true, updatable = false)
-  @Id
   public String getConfigType() {
     return configType;
   }
@@ -68,7 +87,6 @@ public class ServiceConfigMappingEntity {
     configType = type;
   }
 
-  @Column(name = "config_tag", nullable = false, insertable = true, updatable = true)
   public String getVersionTag() {
     return configVersion;
   }
@@ -77,7 +95,6 @@ public class ServiceConfigMappingEntity {
     configVersion = tag;
   }
 
-  @Column(name = "timestamp", nullable = false, insertable = true, updatable = true)
   public Long getTimestamp() {
     return timestamp;
   }
@@ -86,10 +103,6 @@ public class ServiceConfigMappingEntity {
     timestamp = stamp;
   }
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-      @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false) })
   public ClusterServiceEntity getServiceEntity() {
     return serviceEntity;
   }
@@ -98,12 +111,6 @@ public class ServiceConfigMappingEntity {
     serviceEntity = entity;
   }
 
-  @ManyToOne
-  @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_type", referencedColumnName = "type_name", nullable = false, insertable = false, updatable = false),
-      @JoinColumn(name = "config_tag", referencedColumnName = "version_tag", nullable = false, insertable = false, updatable = false)
-  })
   public ClusterConfigEntity getClusterConfigEntity() {
     return clusterConfigEntity;
   }

+ 29 - 27
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java

@@ -19,17 +19,43 @@
 package org.apache.ambari.server.orm.entities;
 
 import org.apache.ambari.server.state.State;
+import org.apache.commons.lang.StringUtils;
 
 import javax.persistence.*;
 
 @javax.persistence.IdClass(ServiceDesiredStateEntityPK.class)
-@javax.persistence.Table(name = "servicedesiredstate", schema = "ambari", catalog = "")
+@javax.persistence.Table(name = "servicedesiredstate")
 @Entity
 public class ServiceDesiredStateEntity {
+
+  @Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
+  @Id
   private Long clusterId;
 
-  @javax.persistence.Column(name = "cluster_id", nullable = false, insertable = false, updatable = false, length = 10)
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
   @Id
+  private String serviceName;
+
+  @Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
+  @Enumerated(value = EnumType.STRING)
+  private State desiredState = State.INIT;
+
+  @Column(name = "desired_host_role_mapping", nullable = false, insertable = true, updatable = true, length = 10)
+  @Basic
+  private int desiredHostRoleMapping = 0;
+
+  @Column(name = "desired_stack_version", insertable = true, updatable = true)
+  @Basic
+  private String desiredStackVersion = "";
+
+  @OneToOne
+  @javax.persistence.JoinColumns(
+      {
+          @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
+          @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)
+      })
+  private ClusterServiceEntity clusterServiceEntity;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -38,10 +64,6 @@ public class ServiceDesiredStateEntity {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
-
-  @javax.persistence.Column(name = "service_name", nullable = false, insertable = false, updatable = false)
-  @Id
   public String getServiceName() {
     return serviceName;
   }
@@ -50,10 +72,6 @@ public class ServiceDesiredStateEntity {
     this.serviceName = serviceName;
   }
 
-  private State desiredState = State.INIT;
-
-  @javax.persistence.Column(name = "desired_state", nullable = false, insertable = true, updatable = true)
-  @Enumerated(value = EnumType.STRING)
   public State getDesiredState() {
     return desiredState;
   }
@@ -62,10 +80,6 @@ public class ServiceDesiredStateEntity {
     this.desiredState = desiredState;
   }
 
-  private int desiredHostRoleMapping = 0;
-
-  @javax.persistence.Column(name = "desired_host_role_mapping", nullable = false, insertable = true, updatable = true, length = 10)
-  @Basic
   public int getDesiredHostRoleMapping() {
     return desiredHostRoleMapping;
   }
@@ -74,12 +88,8 @@ public class ServiceDesiredStateEntity {
     this.desiredHostRoleMapping = desiredHostRoleMapping;
   }
 
-  private String desiredStackVersion = "";
-
-  @javax.persistence.Column(name = "desired_stack_version", nullable = false, insertable = true, updatable = true)
-  @Basic
   public String getDesiredStackVersion() {
-    return desiredStackVersion;
+    return StringUtils.defaultString(desiredStackVersion);
   }
 
   public void setDesiredStackVersion(String desiredStackVersion) {
@@ -112,14 +122,6 @@ public class ServiceDesiredStateEntity {
     return result;
   }
 
-  private ClusterServiceEntity clusterServiceEntity;
-
-  @OneToOne
-  @javax.persistence.JoinColumns(
-      {
-          @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false),
-          @JoinColumn(name = "service_name", referencedColumnName = "service_name", nullable = false)
-      })
   public ClusterServiceEntity getClusterServiceEntity() {
     return clusterServiceEntity;
   }

+ 35 - 30
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/StageEntity.java

@@ -18,17 +18,48 @@
 
 package org.apache.ambari.server.orm.entities;
 
+import org.apache.commons.lang.StringUtils;
+
 import javax.persistence.*;
 import java.util.Collection;
 
+import static org.apache.commons.lang.StringUtils.defaultString;
+
 @IdClass(org.apache.ambari.server.orm.entities.StageEntityPK.class)
-@Table(name = "stage", schema = "ambari", catalog = "")
+@Table(name = "stage")
 @Entity
 public class StageEntity {
-  private Long clusterId;
 
   @Column(name = "cluster_id", insertable = false, updatable = false, nullable = false)
   @Basic
+  private Long clusterId;
+
+  @Column(name = "request_id")
+  @Id
+  private Long requestId;
+
+  @Column(name = "stage_id", nullable = false)
+  @Id
+  private Long stageId = 0L;
+
+  @Column(name = "log_info")
+  @Basic
+  private String logInfo = "";
+
+  @Column(name = "request_context")
+  @Basic
+  private String requestContext = "";
+
+  @ManyToOne(cascade = {CascadeType.MERGE})
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")
+  private ClusterEntity cluster;
+
+  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
+  private Collection<HostRoleCommandEntity> hostRoleCommands;
+
+  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
+  private Collection<RoleSuccessCriteriaEntity> roleSuccessCriterias;
+
   public Long getClusterId() {
     return clusterId;
   }
@@ -37,10 +68,6 @@ public class StageEntity {
     this.clusterId = clusterId;
   }
 
-  private Long requestId;
-
-  @Column(name = "request_id")
-  @Id
   public Long getRequestId() {
     return requestId;
   }
@@ -49,10 +76,6 @@ public class StageEntity {
     this.requestId = requestId;
   }
 
-  private Long stageId = 0L;
-
-  @Column(name = "stage_id", nullable = false)
-  @Id
   public Long getStageId() {
     return stageId;
   }
@@ -61,24 +84,16 @@ public class StageEntity {
     this.stageId = stageId;
   }
 
-  private String logInfo = "";
-
-  @Column(name = "log_info", nullable = false)
-  @Basic
   public String getLogInfo() {
-    return logInfo;
+    return defaultString(logInfo);
   }
 
   public void setLogInfo(String logInfo) {
     this.logInfo = logInfo;
   }
 
-  private String requestContext = "";
-
-  @Column(name = "request_context", nullable = true)
-  @Basic
   public String getRequestContext() {
-    return requestContext;
+    return defaultString(requestContext);
   }
 
   public void setRequestContext(String requestContext) {
@@ -112,10 +127,6 @@ public class StageEntity {
     return result;
   }
 
-  private ClusterEntity cluster;
-
-  @ManyToOne(cascade = {CascadeType.MERGE})
-  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id")
   public ClusterEntity getCluster() {
     return cluster;
   }
@@ -124,9 +135,6 @@ public class StageEntity {
     this.cluster = cluster;
   }
 
-  private Collection<HostRoleCommandEntity> hostRoleCommands;
-
-  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
   public Collection<HostRoleCommandEntity> getHostRoleCommands() {
     return hostRoleCommands;
   }
@@ -135,9 +143,6 @@ public class StageEntity {
     this.hostRoleCommands = hostRoleCommands;
   }
 
-  private Collection<RoleSuccessCriteriaEntity> roleSuccessCriterias;
-
-  @OneToMany(mappedBy = "stage", cascade = CascadeType.REMOVE)
   public Collection<RoleSuccessCriteriaEntity> getRoleSuccessCriterias() {
     return roleSuccessCriterias;
   }

+ 34 - 25
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/UserEntity.java

@@ -22,20 +22,43 @@ import javax.persistence.*;
 import java.util.Date;
 import java.util.Set;
 
-@Table(name = "users", schema = "ambari", catalog = "", uniqueConstraints = {@UniqueConstraint(columnNames = {"user_name", "ldap_user"})})
+@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"user_name", "ldap_user"})})
 @Entity
 @NamedQueries({
     @NamedQuery(name = "localUserByName", query = "SELECT user FROM UserEntity user where lower(user.userName)=:username AND user.ldapUser=false"),
     @NamedQuery(name = "ldapUserByName", query = "SELECT user FROM UserEntity user where lower(user.userName)=:username AND user.ldapUser=true")
 })
-@SequenceGenerator(name = "ambari.users_user_id_seq", allocationSize = 1)
+@TableGenerator(name = "user_id_generator",
+    table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "value"
+    , pkColumnValue = "user_id_seq"
+    , initialValue = 2
+    , allocationSize = 1
+    )
 public class UserEntity {
 
-  private Integer userId;
-
   @Id
   @Column(name = "user_id")
-  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ambari.users_user_id_seq")
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = "user_id_generator")
+  private Integer userId;
+
+  @Column(name = "user_name")
+  private String userName;
+
+  @Column(name = "ldap_user")
+  private Integer ldapUser = 0;
+
+  @Column(name = "user_password")
+  @Basic
+  private String userPassword;
+
+  @Column(name = "create_time")
+  @Basic
+  @Temporal(value = TemporalType.TIMESTAMP)
+  private Date createTime = new Date();
+
+  @ManyToMany(mappedBy = "userEntities")
+  private Set<RoleEntity> roleEntities;
+
   public Integer getUserId() {
     return userId;
   }
@@ -44,9 +67,6 @@ public class UserEntity {
     this.userId = userId;
   }
 
-  private String userName;
-
-  @Column(name = "user_name")
   public String getUserName() {
     return userName;
   }
@@ -55,21 +75,18 @@ public class UserEntity {
     this.userName = userName;
   }
 
-  private Boolean ldapUser = false;
-
-  @Column(name = "ldap_user")
   public Boolean getLdapUser() {
-    return ldapUser;
+    return ldapUser == 0 ? Boolean.FALSE : Boolean.TRUE;
   }
 
   public void setLdapUser(Boolean ldapUser) {
-    this.ldapUser = ldapUser;
+    if (ldapUser == null) {
+      this.ldapUser = null;
+    } else {
+      this.ldapUser = ldapUser ? 1 : 0;
+    }
   }
 
-  private String userPassword;
-
-  @Column(name = "user_password")
-  @Basic
   public String getUserPassword() {
     return userPassword;
   }
@@ -78,11 +95,6 @@ public class UserEntity {
     this.userPassword = userPassword;
   }
 
-  private Date createTime = new Date();
-
-  @Column(name = "create_time")
-  @Basic
-  @Temporal(value = TemporalType.TIMESTAMP)
   public Date getCreateTime() {
     return createTime;
   }
@@ -117,9 +129,6 @@ public class UserEntity {
     return result;
   }
 
-  private Set<RoleEntity> roleEntities;
-
-  @ManyToMany(mappedBy = "userEntities")
   public Set<RoleEntity> getRoleEntities() {
     return roleEntities;
   }

+ 11 - 3
ambari-server/src/main/java/org/apache/ambari/server/utils/StageUtils.java

@@ -33,10 +33,12 @@ import java.util.TreeMap;
 import javax.xml.bind.JAXBException;
 
 import com.google.gson.Gson;
+import com.google.inject.Injector;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.agent.ExecutionCommand;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.HostsMap;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.ServiceComponent;
@@ -179,7 +181,7 @@ public class StageUtils {
   }
 
 
-  public static Map<String, List<String>> getClusterHostInfo(Cluster cluster, HostsMap hostsMap) {
+  public static Map<String, List<String>> getClusterHostInfo(Cluster cluster, HostsMap hostsMap, Injector injector) {
     Map<String, List<String>> info = new HashMap<String, List<String>>();
     if (cluster.getServices() != null) {
       for (String serviceName : cluster.getServices().keySet()) {
@@ -202,8 +204,14 @@ public class StageUtils {
               }
               info.put(clusterInfoKey, hostList);
             }
-            //Add ambari db server
-            info.put("ambari_db_server_host", Arrays.asList(hostsMap.getHostMap(getHostName())));
+            //Set up ambari-rca connection properties, is this a hack?
+//            info.put("ambari_db_server_host", Arrays.asList(hostsMap.getHostMap(getHostName())));
+            Configuration configuration = injector.getInstance(Configuration.class);
+            info.put("ambari_db_rca_url", Arrays.asList(configuration.getRcaDatabaseUrl()));
+            info.put("ambari_db_rca_driver", Arrays.asList(configuration.getRcaDatabaseDriver()));
+            info.put("ambari_db_rca_username", Arrays.asList(configuration.getRcaDatabaseUser()));
+            info.put("ambari_db_rca_password", Arrays.asList(configuration.getRcaDatabasePassword()));
+
           }
         }
       }

+ 139 - 16
ambari-server/src/main/python/ambari-server.py

@@ -37,6 +37,7 @@ import getpass
 # debug settings
 VERBOSE = False
 SILENT = False
+REMOTE_DATABASE = False
 SERVER_START_DEBUG = False
 
 # action commands
@@ -117,6 +118,20 @@ PG_DEFAULT_PASSWORD = "bigdata"
 JDBC_USER_NAME_PROPERTY = "server.jdbc.user.name"
 JDBC_PASSWORD_FILE_PROPERTY = "server.jdbc.user.passwd"
 JDBC_PASSWORD_FILENAME = "password.dat"
+JDBC_RCA_PASSWORD_FILENAME = "rca_password.dat"
+
+PERSISTENCE_TYPE_PROPERTY = "server.persistence.type"
+JDBC_DRIVER_PROPERTY = "server.jdbc.driver"
+JDBC_URL_PROPERTY = "server.jdbc.url"
+
+JDBC_RCA_DRIVER_PROPERTY = "server.jdbc.rca.driver"
+JDBC_RCA_URL_PROPERTY = "server.jdbc.rca.url"
+JDBC_RCA_USER_NAME_PROPERTY = "server.jdbc.rca.user.name"
+JDBC_RCA_PASSWORD_FILE_PROPERTY = "server.jdbc.rca.user.passwd"
+
+DRIVER_NAMES = ["org.postgresql.Driver", "oracle.jdbc.driver.OracleDriver", "com.mysql.jdbc.Driver"]
+CONNECTION_STRINGS = ["jdbc:postgresql://{0}:{1}/{2}", "jdbc:oracle:thin:@{0}:{1}/{2}", "jdbc:mysql://{0}:{1}/{2}"]
+
 
 # jdk commands
 JDK_LOCAL_FILENAME = "jdk-6u31-linux-x64.bin"
@@ -255,6 +270,95 @@ def setup_db(args):
     print errdata
   return retcode
 
+def setup_remote_db(args):
+  print "WARNING! To use MySQL/Oracle database place JDBC driver to "+ get_ambari_jars()
+  print "Table structure in remote database should be created manually in this mode."
+  (driver_name, conn_url, username, password) = get_connection_properties()
+
+  write_property(PERSISTENCE_TYPE_PROPERTY, "remote")
+  write_property(JDBC_DRIVER_PROPERTY, driver_name)
+  write_property(JDBC_URL_PROPERTY, conn_url)
+  write_property(JDBC_USER_NAME_PROPERTY, username)
+  write_property(JDBC_PASSWORD_FILE_PROPERTY, store_password_file(password, JDBC_PASSWORD_FILENAME))
+
+  ok = get_YN_input("Enter separate configuration for RCA database [y/n] (n)? ", False)
+  if ok:
+    (driver_name, conn_url, username, password) = get_connection_properties()
+
+  write_property(JDBC_RCA_DRIVER_PROPERTY, driver_name)
+  write_property(JDBC_RCA_URL_PROPERTY, conn_url)
+  write_property(JDBC_RCA_USER_NAME_PROPERTY, username)
+  write_property(JDBC_RCA_PASSWORD_FILE_PROPERTY, store_password_file(password, JDBC_RCA_PASSWORD_FILENAME))
+
+  return 0
+
+def store_password_file(password, filename):
+  conf_file = search_file(AMBARI_PROPERTIES_FILE, get_conf_dir())
+  passFilePath = os.path.join(os.path.dirname(conf_file),
+    filename)
+
+  with open(passFilePath, 'w+') as passFile:
+    passFile.write(password)
+    pass
+  os.chmod(passFilePath, stat.S_IREAD | stat.S_IWRITE)
+
+  return passFilePath
+
+def get_connection_properties():
+  default_db_num="1"
+  default_host = "localhost"
+  default_schema = "ambari"
+
+  database_num = get_validated_string_input("Select database:\n1 - Postgres\n2 - Oracle\n3 - MySQL) \n["+str(default_db_num)+"]:",
+    default_db_num,
+    "^[123]$",
+    "Invalid number.",
+    False
+  )
+
+  db_host = get_validated_string_input("Hostname ["+default_host+"]:",
+    default_host,
+    "^[a-zA-Z0-9.\-]*$",
+    "Invalid hostname.",
+    False
+  )
+
+  default_port = None
+  if database_num == "1":
+    default_port = "5432"
+  elif database_num == "2":
+    default_port = "1521"
+  elif database_num == "3":
+    default_port = "3306"
+
+  db_port = get_validated_string_input("Port ["+ str(default_port) + "]:",
+    default_port,
+    "^[0-9]{1,5}$",
+    "Invalid port.",
+    False
+  )
+
+  if database_num == "2":
+    default_schema = "xe"
+
+  db_schema = get_validated_string_input("Database/schema/service name ["+ str(default_schema) + "]:",
+    default_schema,
+    "^[a-zA-z\-\"]+$",
+    "Invalid schema name.",
+    False
+  )
+
+  usernameDefault = 'ambari'
+  usernamePrompt = 'Username [' + usernameDefault + ']: '
+  usernamePattern = "^[a-zA-Z_][a-zA-Z0-9_\-]*$"
+  usernameDescr = "Invalid characters in username. Start with _ or alpha "\
+                  "followed by alphanumeric or _ or - characters"
+
+  username = get_validated_string_input(usernamePrompt, usernameDefault,
+    usernamePattern, usernameDescr, False)
+  password = configure_postgres_password()
+
+  return DRIVER_NAMES[int(database_num)-1], CONNECTION_STRINGS[int(database_num)-1].format(db_host, db_port, db_schema), username, password
 
 def execute_db_script(args, file):
   #password access to ambari-server and mapred
@@ -747,23 +851,32 @@ def setup(args):
     print_error_msg ('Failed to stop iptables. Exiting.')
     sys.exit(retcode)
 
-  print 'Checking PostgreSQL...'
-  retcode = check_postgre_up()
-  if not retcode == 0:
-    print_error_msg ('Unable to start PostgreSQL server. Exiting')
-    sys.exit(retcode)
+  if not REMOTE_DATABASE:
 
-  print 'Configuring database...'
-  retcode = setup_db(args)
-  if not retcode == 0:
-    print_error_msg  ('Running database init script was failed. Exiting.')
-    sys.exit(retcode)
-    
-  print 'Configuring PostgreSQL...'
-  retcode = configure_postgres()
-  if not retcode == 0:
-    print_error_msg ('Unable to configure PostgreSQL server. Exiting')
-    sys.exit(retcode)
+    print 'Checking PostgreSQL...'
+    retcode = check_postgre_up()
+    if not retcode == 0:
+      print_error_msg ('Unable to start PostgreSQL server. Exiting')
+      sys.exit(retcode)
+
+    print 'Configuring database...'
+    retcode = setup_db(args)
+    if not retcode == 0:
+      print_error_msg  ('Running database init script was failed. Exiting.')
+      sys.exit(retcode)
+
+    print 'Configuring PostgreSQL...'
+    retcode = configure_postgres()
+    if not retcode == 0:
+      print_error_msg ('Unable to configure PostgreSQL server. Exiting')
+      sys.exit(retcode)
+
+  else:
+    print 'Configuring remote database connection properties'
+    retcode = setup_remote_db(args)
+    if not retcode == 0:
+      print_error_msg ('Error while configuring connection properties. Exiting')
+      sys.exit(retcode)
   
   print 'Checking JDK...'
   retcode = download_jdk(args)
@@ -1135,6 +1248,10 @@ def main():
                   action="store_true", dest="silent", default=False,
                   help="Silently accepts default prompt values")
 
+  parser.add_option("-b", "--remote-database",
+      action="store_true", dest="remote_database", default=False,
+      help="Set up remote database instead of local")
+
   (options, args) = parser.parse_args()
 
   # set verbose
@@ -1145,6 +1262,12 @@ def main():
   global SILENT
   SILENT = options.silent
 
+  # skip local db setup
+  global REMOTE_DATABASE
+  REMOTE_DATABASE = options.remote_database
+
+
+
 
   
   if len(args) == 0:

+ 22 - 18
ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql

@@ -24,6 +24,8 @@ CREATE ROLE :username LOGIN ENCRYPTED PASSWORD :password;
 CREATE SCHEMA ambari
   AUTHORIZATION :username;
 
+ALTER ROLE :username SET search_path to 'ambari';
+
 CREATE TABLE ambari.clusters (cluster_id BIGINT NOT NULL, cluster_info VARCHAR(255) NOT NULL, cluster_name VARCHAR(100) NOT NULL UNIQUE, desired_cluster_state VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
 
 GRANT ALL PRIVILEGES ON TABLE ambari.clusters TO :username;
@@ -52,9 +54,9 @@ CREATE TABLE ambari.hostcomponentconfigmapping (cluster_id BIGINT NOT NULL, comp
 
 GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentconfigmapping TO :username;
 
-CREATE TABLE ambari.hostcomponentdesiredconfigmapping (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, config_type VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, config_tag VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name, config_type));
+CREATE TABLE ambari.hcdesiredconfigmapping (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, config_type VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, config_tag VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name, config_type));
 
-GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredconfigmapping TO :username;
+GRANT ALL PRIVILEGES ON TABLE ambari.hcdesiredconfigmapping TO :username;
 
 CREATE TABLE ambari.hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
 
@@ -88,7 +90,7 @@ CREATE TABLE ambari.roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_na
 
 GRANT ALL PRIVILEGES ON TABLE ambari.roles TO :username;
 
-CREATE TABLE ambari.users (user_id SERIAL, ldap_user BOOLEAN NOT NULL, user_name VARCHAR(255) NOT NULL, create_time TIMESTAMP DEFAULT NOW(), user_password VARCHAR(255), PRIMARY KEY (user_id), UNIQUE (ldap_user, user_name));
+CREATE TABLE ambari.users (user_id INTEGER, ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, create_time TIMESTAMP DEFAULT NOW(), user_password VARCHAR(255), PRIMARY KEY (user_id), UNIQUE (ldap_user, user_name));
 GRANT ALL PRIVILEGES ON TABLE ambari.users TO :username;
 
 CREATE TABLE ambari.execution_command (command bytea, task_id BIGINT NOT NULL, PRIMARY KEY (task_id));
@@ -113,11 +115,16 @@ CREATE TABLE ambari.key_value_store ("key" VARCHAR(255), "value" VARCHAR, PRIMAR
 GRANT ALL PRIVILEGES ON TABLE ambari.key_value_store TO :username;
 
 CREATE TABLE ambari.hostconfigmapping (cluster_id bigint NOT NULL, host_name VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, service_name VARCHAR(255), create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (cluster_id, host_name, type_name, create_timestamp));
+
 GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
 
 CREATE TABLE ambari.metainfo ("metainfo_key" VARCHAR(255), "metainfo_value" VARCHAR, PRIMARY KEY("metainfo_key"));
 GRANT ALL PRIVILEGES ON TABLE ambari.metainfo TO :username;
 
+CREATE TABLE ambari.ambari_sequences (sequence_name VARCHAR(255) PRIMARY KEY, "value" BIGINT NOT NULL);
+GRANT ALL PRIVILEGES ON TABLE ambari.ambari_sequences TO :username;
+
+
 ALTER TABLE ambari.clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.clusterservices ADD CONSTRAINT FK_clusterservices_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.clusterconfigmapping ADD CONSTRAINT FK_clusterconfigmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
@@ -126,8 +133,8 @@ ALTER TABLE ambari.componentconfigmapping ADD CONSTRAINT FK_componentconfigmappi
 ALTER TABLE ambari.componentconfigmapping ADD CONSTRAINT FK_componentconfigmapping_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES ambari.servicecomponentdesiredstate (component_name, cluster_id, service_name);
 ALTER TABLE ambari.hostcomponentconfigmapping ADD CONSTRAINT FK_hostcomponentconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES ambari.clusterconfig (version_tag, type_name, cluster_id);
 ALTER TABLE ambari.hostcomponentconfigmapping ADD CONSTRAINT FK_hostcomponentconfigmapping_cluster_id FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES ambari.hostcomponentstate (cluster_id, component_name, host_name, service_name);
-ALTER TABLE ambari.hostcomponentdesiredconfigmapping ADD CONSTRAINT FK_hostcomponentdesiredconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES ambari.clusterconfig (version_tag, type_name, cluster_id);
-ALTER TABLE ambari.hostcomponentdesiredconfigmapping ADD CONSTRAINT FK_hostcomponentdesiredconfigmapping_cluster_id FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES ambari.hostcomponentdesiredstate (cluster_id, component_name, host_name, service_name);
+ALTER TABLE ambari.hcdesiredconfigmapping ADD CONSTRAINT FK_hostcomponentdesiredconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES ambari.clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE ambari.hcdesiredconfigmapping ADD CONSTRAINT FK_hostcomponentdesiredconfigmapping_cluster_id FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES ambari.hostcomponentdesiredstate (cluster_id, component_name, host_name, service_name);
 ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name);
 ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES ambari.servicecomponentdesiredstate (component_name, cluster_id, service_name);
 ALTER TABLE ambari.hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES ambari.servicecomponentdesiredstate (component_name, cluster_id, service_name);
@@ -149,28 +156,25 @@ ALTER TABLE ambari.user_roles ADD CONSTRAINT FK_user_roles_role_name FOREIGN KEY
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name);
 
-CREATE SEQUENCE ambari.host_role_command_task_id_seq INCREMENT BY 50 START WITH 51;
-
-GRANT ALL PRIVILEGES ON TABLE ambari.host_role_command_task_id_seq TO :username;
-
-GRANT ALL PRIVILEGES ON TABLE ambari.users_user_id_seq TO :username;
-
-CREATE SEQUENCE ambari.clusters_cluster_id_seq START WITH 1;
-
-GRANT ALL PRIVILEGES ON TABLE ambari.clusters_cluster_id_seq TO :username;
-
 BEGIN;
 
+insert into ambari.ambari_sequences(sequence_name, "value")
+select 'cluster_id_seq', 1
+union all
+select 'user_id_seq', 2
+union all
+select 'host_role_command_id_seq', 1;
+
 insert into ambari.Roles(role_name)
 select 'admin'
 union all
 select 'user';
 
-insert into ambari.Users(user_name, user_password, ldap_user)
-select 'admin','538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00', FALSE;
+insert into ambari.Users(user_id, user_name, user_password)
+select 1,'admin','538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00';
 
 insert into ambari.user_roles(role_name, user_id)
-select 'admin',(select user_id from ambari.users where user_name='admin' and ldap_user=false);
+select 'admin',1;
 
 insert into ambari.metainfo(metainfo_key, metainfo_value)
 select 'version','1.3.0';

+ 38 - 38
ambari-server/src/main/resources/META-INF/persistence.xml

@@ -12,7 +12,7 @@
 <persistence xmlns="http://java.sun.com/xml/ns/persistence"
   version="2.0">
 
-  <persistence-unit name="ambari-postgres" transaction-type="RESOURCE_LOCAL">
+  <persistence-unit name="ambari-server" transaction-type="RESOURCE_LOCAL">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     <class>org.apache.ambari.server.orm.entities.ClusterEntity</class>
     <class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class>
@@ -40,46 +40,46 @@
     <class>org.apache.ambari.server.orm.entities.MetainfoEntity</class>
 
     <properties>
-      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/ambari" />
-      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
+      <!--<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/ambari" />-->
+      <!--<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />-->
       <property name="eclipselink.cache.size.default" value="3000" />
     </properties>
   </persistence-unit>
 
-  <persistence-unit name="ambari-javadb" transaction-type="RESOURCE_LOCAL">
-    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-    <class>org.apache.ambari.server.orm.entities.ClusterEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ClusterServiceEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ClusterStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ComponentConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostComponentConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostComponentDesiredConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostComponentStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ServiceConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity</class>
-    <class>org.apache.ambari.server.orm.entities.RoleEntity</class>
-    <class>org.apache.ambari.server.orm.entities.UserEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ExecutionCommandEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostRoleCommandEntity</class>
-    <class>org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity</class>
-    <class>org.apache.ambari.server.orm.entities.StageEntity</class>
-    <class>org.apache.ambari.server.orm.entities.KeyValueEntity</class>
-    <class>org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.HostConfigMappingEntity</class>
-    <class>org.apache.ambari.server.orm.entities.MetainfoEntity</class>
+  <!--<persistence-unit name="ambari-javadb" transaction-type="RESOURCE_LOCAL">-->
+    <!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ClusterEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ClusterConfigEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ClusterServiceEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ClusterStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ComponentConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostComponentConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostComponentDesiredConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostComponentStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ServiceConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.RoleEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.UserEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ExecutionCommandEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostRoleCommandEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.StageEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.KeyValueEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.ClusterConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.HostConfigMappingEntity</class>-->
+    <!--<class>org.apache.ambari.server.orm.entities.MetainfoEntity</class>-->
 
-    <properties>
-      <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:myDB;create=true" />
-      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
-      <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
-      <property name="eclipselink.orm.throw.exceptions" value="true" />
-      <property name="eclipselink.cache.size.default" value="3000" />
-      <!--<property name="eclipselink.logging.level" value="FINEST"/>-->
-    </properties>
-  </persistence-unit>
+    <!--<properties>-->
+      <!--<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:myDB/ambari;create=true" />-->
+      <!--<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />-->
+      <!--<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />-->
+      <!--<property name="eclipselink.orm.throw.exceptions" value="true" />-->
+      <!--<property name="eclipselink.cache.size.default" value="3000" />-->
+      <!--&lt;!&ndash;<property name="eclipselink.logging.level" value="FINEST"/>&ndash;&gt;-->
+    <!--</properties>-->
+  <!--</persistence-unit>-->
 </persistence>

+ 172 - 0
ambari-server/src/main/resources/mysql-ddl.sql

@@ -0,0 +1,172 @@
+DROP DATABASE IF EXISTS `ambari`;
+DROP DATABASE IF EXISTS `ambarirca`;
+DROP USER `ambari-server`;
+-- DROP USER `mapred`;
+
+delimiter ;
+
+CREATE DATABASE `ambari` /*!40100 DEFAULT CHARACTER SET utf8 */;
+
+CREATE USER 'ambari-server' IDENTIFIED BY 'bigdata';
+
+USE ambari;
+
+CREATE TABLE clusters (cluster_id BIGINT NOT NULL, cluster_info VARCHAR(255) NOT NULL, cluster_name VARCHAR(100) NOT NULL UNIQUE, desired_cluster_state VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
+CREATE TABLE clusterconfig (version_tag VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, config_data LONGTEXT NOT NULL, create_timestamp BIGINT NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
+CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, service_enabled INTEGER NOT NULL, PRIMARY KEY (service_name, cluster_id));
+CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id));
+CREATE TABLE componentconfigmapping (config_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, config_tag VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, service_name));
+CREATE TABLE hostcomponentconfigmapping (config_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, config_tag VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, host_name, service_name));
+CREATE TABLE hcdesiredconfigmapping (config_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, config_tag VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hosts (host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR(255) NOT NULL, discovery_status VARCHAR(2000) NOT NULL, disks_info LONGTEXT NOT NULL, host_attributes LONGTEXT, ipv4 VARCHAR(255), ipv6 VARCHAR(255), last_registration_time BIGINT NOT NULL, os_arch VARCHAR(255) NOT NULL, os_info VARCHAR(1000) NOT NULL, os_type VARCHAR(255) NOT NULL, ph_cpu_count INTEGER NOT NULL, public_host_name VARCHAR(255), rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
+CREATE TABLE serviceconfigmapping (config_type VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, config_tag VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, timestamp BIGINT NOT NULL, PRIMARY KEY (config_type, cluster_id, service_name));
+CREATE TABLE servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE roles (role_name VARCHAR(255) NOT NULL, PRIMARY KEY (role_name));
+CREATE TABLE users (user_id INTEGER NOT NULL, create_time DATETIME, ldap_user INTEGER, user_name VARCHAR(255), user_password VARCHAR(255), PRIMARY KEY (user_id));
+CREATE TABLE execution_command (task_id BIGINT NOT NULL, command LONGBLOB, PRIMARY KEY (task_id));
+CREATE TABLE host_role_command (task_id BIGINT NOT NULL, attempt_count SMALLINT NOT NULL, event LONGTEXT NOT NULL, exitcode INTEGER NOT NULL, host_name VARCHAR(255) NOT NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, role VARCHAR(255), role_command VARCHAR(255), stage_id BIGINT NOT NULL, start_time BIGINT NOT NULL, status VARCHAR(255), std_error LONGBLOB, std_out LONGBLOB, PRIMARY KEY (task_id));
+CREATE TABLE role_success_criteria (role VARCHAR(255) NOT NULL, request_id BIGINT NOT NULL, stage_id BIGINT NOT NULL, success_factor DOUBLE NOT NULL, PRIMARY KEY (role, request_id, stage_id));
+CREATE TABLE stage (stage_id BIGINT NOT NULL, request_id BIGINT NOT NULL, cluster_id BIGINT, log_info VARCHAR(255) NOT NULL, request_context VARCHAR(255), PRIMARY KEY (stage_id, request_id));
+CREATE TABLE key_value_store (`key` VARCHAR(255) NOT NULL, `value` LONGTEXT, PRIMARY KEY (`key`));
+CREATE TABLE clusterconfigmapping (type_name VARCHAR(255) NOT NULL, create_timestamp BIGINT NOT NULL, cluster_id BIGINT NOT NULL, selected INTEGER NOT NULL, version_tag VARCHAR(255) NOT NULL, PRIMARY KEY (type_name, create_timestamp, cluster_id));
+CREATE TABLE hostconfigmapping (create_timestamp BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, type_name VARCHAR(255) NOT NULL, selected INTEGER NOT NULL, service_name VARCHAR(255), version_tag VARCHAR(255) NOT NULL, PRIMARY KEY (create_timestamp, host_name, cluster_id, type_name));
+CREATE TABLE metainfo (`metainfo_key` VARCHAR(255) NOT NULL, `metainfo_value` LONGTEXT, PRIMARY KEY (`metainfo_key`));
+CREATE TABLE ClusterHostMapping (cluster_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, PRIMARY KEY (cluster_id, host_name));
+CREATE TABLE user_roles (role_name VARCHAR(255) NOT NULL, user_id INTEGER NOT NULL, PRIMARY KEY (role_name, user_id));
+CREATE TABLE ambari_sequences (sequence_name VARCHAR(50) NOT NULL, value DECIMAL(38), PRIMARY KEY (sequence_name));
+
+
+ALTER TABLE users ADD CONSTRAINT UNQ_users_0 UNIQUE (user_name, ldap_user);
+ALTER TABLE clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterservices ADD CONSTRAINT FK_clusterservices_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE componentconfigmapping ADD CONSTRAINT FK_componentconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE componentconfigmapping ADD CONSTRAINT FK_componentconfigmapping_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentconfigmapping ADD CONSTRAINT FK_hostcomponentconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE hostcomponentconfigmapping ADD CONSTRAINT FK_hostcomponentconfigmapping_cluster_id FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES hostcomponentstate (cluster_id, component_name, host_name, service_name);
+ALTER TABLE hcdesiredconfigmapping ADD CONSTRAINT FK_hcdesiredconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE hcdesiredconfigmapping ADD CONSTRAINT FK_hcdesiredconfigmapping_cluster_id FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES hostcomponentdesiredstate (cluster_id, component_name, host_name, service_name);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_component_name FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT FK_servicecomponentdesiredstate_service_name FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_serviceconfigmapping_config_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE serviceconfigmapping ADD CONSTRAINT FK_serviceconfigmapping_service_name FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE servicedesiredstate ADD CONSTRAINT FK_servicedesiredstate_service_name FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id);
+ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
+ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE role_success_criteria ADD CONSTRAINT FK_role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
+ALTER TABLE stage ADD CONSTRAINT FK_stage_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterconfigmapping ADD CONSTRAINT FK_clusterconfigmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_ClusterHostMapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_ClusterHostMapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE user_roles ADD CONSTRAINT FK_user_roles_user_id FOREIGN KEY (user_id) REFERENCES users (user_id);
+ALTER TABLE user_roles ADD CONSTRAINT FK_user_roles_role_name FOREIGN KEY (role_name) REFERENCES roles (role_name);
+
+
+INSERT INTO ambari_sequences(sequence_name, value) values ('cluster_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, value) values ('host_role_command_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, value) values ('user_id_seq', 1);
+
+insert into ambari.Roles(role_name)
+select 'admin'
+union all
+select 'user';
+
+insert into ambari.Users(user_id, user_name, user_password)
+select 1,'admin','538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00';
+
+insert into ambari.user_roles(role_name, user_id)
+select 'admin',1;
+
+insert into ambari.metainfo(`metainfo_key`, `metainfo_value`)
+select 'version','1.3.0';
+
+
+
+CREATE TABLE workflow (
+  workflowId VARCHAR(255), workflowName TEXT,
+  parentWorkflowId VARCHAR(255),  
+  workflowContext TEXT, userName TEXT,
+  startTime BIGINT, lastUpdateTime BIGINT,
+  numJobsTotal INTEGER, numJobsCompleted INTEGER,
+  inputBytes BIGINT, outputBytes BIGINT,
+  duration BIGINT,
+  PRIMARY KEY (workflowId),
+  FOREIGN KEY (parentWorkflowId) REFERENCES workflow(workflowId)
+);
+
+CREATE TABLE job (
+  jobId VARCHAR(255), workflowId VARCHAR(255), jobName TEXT, workflowEntityName TEXT,
+  userName TEXT, queue TEXT, acls TEXT, confPath TEXT, 
+  submitTime BIGINT, launchTime BIGINT, finishTime BIGINT, 
+  maps INTEGER, reduces INTEGER, status TEXT, priority TEXT, 
+  finishedMaps INTEGER, finishedReduces INTEGER, 
+  failedMaps INTEGER, failedReduces INTEGER, 
+  mapsRuntime BIGINT, reducesRuntime BIGINT,
+  mapCounters TEXT, reduceCounters TEXT, jobCounters TEXT, 
+  inputBytes BIGINT, outputBytes BIGINT,
+  PRIMARY KEY(jobId),
+  FOREIGN KEY(workflowId) REFERENCES workflow(workflowId)
+);
+
+CREATE TABLE task (
+  taskId VARCHAR(255), jobId VARCHAR(255), taskType TEXT, splits TEXT, 
+  startTime BIGINT, finishTime BIGINT, status TEXT, error TEXT, counters TEXT, 
+  failedAttempt TEXT, 
+  PRIMARY KEY(taskId), 
+  FOREIGN KEY(jobId) REFERENCES job(jobId)
+);
+
+CREATE TABLE taskAttempt (
+  taskAttemptId VARCHAR(255), taskId VARCHAR(255), jobId VARCHAR(255), taskType TEXT, taskTracker TEXT, 
+  startTime BIGINT, finishTime BIGINT, 
+  mapFinishTime BIGINT, shuffleFinishTime BIGINT, sortFinishTime BIGINT, 
+  locality TEXT, avataar TEXT, 
+  status TEXT, error TEXT, counters TEXT, 
+  inputBytes BIGINT, outputBytes BIGINT,
+  PRIMARY KEY(taskAttemptId), 
+  FOREIGN KEY(jobId) REFERENCES job(jobId), 
+  FOREIGN KEY(taskId) REFERENCES task(taskId)
+); 
+
+CREATE TABLE hdfsEvent (
+  timestamp BIGINT,
+  userName TEXT,
+  clientIP TEXT,
+  operation TEXT,
+  srcPath TEXT,
+  dstPath TEXT,
+  permissions TEXT
+);
+
+CREATE TABLE mapreduceEvent (
+  timestamp BIGINT,
+  userName TEXT,
+  clientIP TEXT,
+  operation TEXT,
+  target TEXT,
+  result TEXT,
+  description TEXT,
+  permissions TEXT
+);
+
+CREATE TABLE clusterEvent (
+  timestamp BIGINT, 
+  service TEXT, status TEXT, 
+  error TEXT, data TEXT , 
+  host TEXT, rack TEXT
+);
+
+GRANT ALL ON ambari.* TO `ambari-server`;
+
+
+
+

+ 209 - 0
ambari-server/src/main/resources/oracle-DDL.sql

@@ -0,0 +1,209 @@
+-- PL/SQL script
+DROP USER &1 CASCADE;
+CREATE USER &1 IDENTIFIED BY &2 DEFAULT TABLESPACE "USERS" TEMPORARY TABLESPACE "TEMP";
+
+GRANT UNLIMITED TABLESPACE TO &1;
+GRANT CREATE SESSION TO &1;
+GRANT CREATE TABLE TO &1;
+
+ALTER SESSION SET CURRENT_SCHEMA= &1;
+
+CREATE TABLE clusters (cluster_id NUMBER(19) NOT NULL, cluster_info VARCHAR2(255) NULL, cluster_name VARCHAR2(100) NOT NULL UNIQUE, desired_cluster_state VARCHAR2(255) NULL, desired_stack_version VARCHAR2(255) NULL, PRIMARY KEY (cluster_id));
+CREATE TABLE clusterconfig (version_tag VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_data CLOB NOT NULL, create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY (version_tag, type_name, cluster_id));
+CREATE TABLE clusterservices (service_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, service_enabled NUMBER(10) NOT NULL, PRIMARY KEY (service_name, cluster_id));
+CREATE TABLE clusterstate (cluster_id NUMBER(19) NOT NULL, current_cluster_state VARCHAR2(255) NULL, current_stack_version VARCHAR2(255) NULL, PRIMARY KEY (cluster_id));
+CREATE TABLE componentconfigmapping (config_type VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, config_tag VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, timestamp NUMBER(19) NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, service_name));
+CREATE TABLE hostcomponentconfigmapping (config_type VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, config_tag VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, timestamp NUMBER(19) NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, host_name, service_name));
+CREATE TABLE hcdesiredconfigmapping (config_type VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, config_tag VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, timestamp NUMBER(19) NOT NULL, PRIMARY KEY (config_type, cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentdesiredstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hostcomponentstate (cluster_id NUMBER(19) NOT NULL, component_name VARCHAR2(255) NOT NULL, current_stack_version VARCHAR2(255) NOT NULL, current_state VARCHAR2(255) NOT NULL, host_name VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, component_name, host_name, service_name));
+CREATE TABLE hosts (host_name VARCHAR2(255) NOT NULL, cpu_count INTEGER NOT NULL, cpu_info VARCHAR2(255) NULL, discovery_status VARCHAR2(2000) NULL, disks_info CLOB NOT NULL, host_attributes CLOB NULL, ipv4 VARCHAR2(255) NULL, ipv6 VARCHAR2(255) NULL, last_registration_time INTEGER NOT NULL, os_arch VARCHAR2(255) NULL, os_info VARCHAR2(1000) NULL, os_type VARCHAR2(255) NULL, ph_cpu_count INTEGER NOT NULL, public_host_name VARCHAR2(255) NULL, rack_info VARCHAR2(255) NOT NULL, total_mem INTEGER NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE hoststate (agent_version VARCHAR2(255) NULL, available_mem NUMBER(19) NOT NULL, current_state VARCHAR2(255) NOT NULL, health_status VARCHAR2(255) NULL, host_name VARCHAR2(255) NOT NULL, time_in_state NUMBER(19) NOT NULL, PRIMARY KEY (host_name));
+CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (component_name, cluster_id, service_name));
+CREATE TABLE serviceconfigmapping (config_type VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_tag VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, timestamp NUMBER(19) NOT NULL, PRIMARY KEY (config_type, cluster_id, service_name));
+CREATE TABLE servicedesiredstate (cluster_id NUMBER(19) NOT NULL, desired_host_role_mapping NUMBER(10) NOT NULL, desired_stack_version VARCHAR2(255) NULL, desired_state VARCHAR2(255) NOT NULL, service_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, service_name));
+CREATE TABLE roles (role_name VARCHAR2(255) NOT NULL, PRIMARY KEY (role_name));
+CREATE TABLE users (user_id NUMBER(10) NOT NULL, create_time TIMESTAMP NULL, ldap_user NUMBER(10) DEFAULT 0, user_name VARCHAR2(255) NULL, user_password VARCHAR2(255) NULL, PRIMARY KEY (user_id));
+CREATE TABLE execution_command (task_id NUMBER(19) NOT NULL, command BLOB NULL, PRIMARY KEY (task_id));
+CREATE TABLE host_role_command (task_id NUMBER(19) NOT NULL, attempt_count NUMBER(5) NOT NULL, event CLOB NULL, exitcode NUMBER(10) NOT NULL, host_name VARCHAR2(255) NOT NULL, last_attempt_time NUMBER(19) NOT NULL, request_id NUMBER(19) NOT NULL, role VARCHAR2(255) NULL, role_command VARCHAR2(255) NULL, stage_id NUMBER(19) NOT NULL, start_time NUMBER(19) NOT NULL, status VARCHAR2(255) NULL, std_error BLOB NULL, std_out BLOB NULL, PRIMARY KEY (task_id));
+CREATE TABLE role_success_criteria (role VARCHAR2(255) NOT NULL, request_id NUMBER(19) NOT NULL, stage_id NUMBER(19) NOT NULL, success_factor NUMBER(19,4) NOT NULL, PRIMARY KEY (role, request_id, stage_id));
+CREATE TABLE stage (stage_id NUMBER(19) NOT NULL, request_id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NULL, log_info VARCHAR2(255) NULL, request_context VARCHAR2(255) NULL, PRIMARY KEY (stage_id, request_id));
+CREATE TABLE key_value_store ("key" VARCHAR2(255) NOT NULL, "value" CLOB NULL, PRIMARY KEY ("key"));
+CREATE TABLE clusterconfigmapping (type_name VARCHAR2(255) NOT NULL, create_timestamp NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, selected NUMBER(10) NOT NULL, version_tag VARCHAR2(255) NOT NULL, PRIMARY KEY (type_name, create_timestamp, cluster_id));
+CREATE TABLE hostconfigmapping (create_timestamp NUMBER(19) NOT NULL, host_name VARCHAR2(255) NOT NULL, cluster_id NUMBER(19) NOT NULL, type_name VARCHAR2(255) NOT NULL, selected NUMBER(10) NOT NULL, service_name VARCHAR2(255) NULL, version_tag VARCHAR2(255) NOT NULL, PRIMARY KEY (create_timestamp, host_name, cluster_id, type_name));
+CREATE TABLE metainfo ("metainfo_key" VARCHAR2(255) NOT NULL, "metainfo_value" CLOB NULL, PRIMARY KEY ("metainfo_key"));
+CREATE TABLE ClusterHostMapping (cluster_id NUMBER(19) NOT NULL, host_name VARCHAR2(255) NOT NULL, PRIMARY KEY (cluster_id, host_name));
+CREATE TABLE user_roles (role_name VARCHAR2(255) NOT NULL, user_id NUMBER(10) NOT NULL, PRIMARY KEY (role_name, user_id));
+CREATE TABLE ambari_sequences (sequence_name VARCHAR2(50) NOT NULL, value NUMBER(38) NULL, PRIMARY KEY (sequence_name));
+
+
+ALTER TABLE users ADD CONSTRAINT UNQ_users_0 UNIQUE (user_name, ldap_user);
+ALTER TABLE clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterservices ADD CONSTRAINT FK_clusterservices_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE componentconfigmapping ADD CONSTRAINT cmponentconfigmappingconfigtag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE componentconfigmapping ADD CONSTRAINT cmpnntconfigmappingcmpnentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentconfigmapping ADD CONSTRAINT hstcmponentconfigmappingclstrd FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES hostcomponentstate (cluster_id, component_name, host_name, service_name);
+ALTER TABLE hostcomponentconfigmapping ADD CONSTRAINT hstcmponentconfigmappingcnfgtg FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE hcdesiredconfigmapping ADD CONSTRAINT hcdesiredconfigmappingcnfigtag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE hcdesiredconfigmapping ADD CONSTRAINT hcdesiredconfigmappingclsterid FOREIGN KEY (cluster_id, component_name, host_name, service_name) REFERENCES hostcomponentdesiredstate (cluster_id, component_name, host_name, service_name);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name);
+ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE serviceconfigmapping ADD CONSTRAINT srviceconfigmappingservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE serviceconfigmapping ADD CONSTRAINT serviceconfigmappingconfig_tag FOREIGN KEY (config_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id);
+ALTER TABLE servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id);
+ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id);
+ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
+ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id);
+ALTER TABLE stage ADD CONSTRAINT FK_stage_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE clusterconfigmapping ADD CONSTRAINT clusterconfigmappingcluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT ClusterHostMapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
+ALTER TABLE ClusterHostMapping ADD CONSTRAINT ClusterHostMapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name);
+ALTER TABLE user_roles ADD CONSTRAINT FK_user_roles_user_id FOREIGN KEY (user_id) REFERENCES users (user_id);
+ALTER TABLE user_roles ADD CONSTRAINT FK_user_roles_role_name FOREIGN KEY (role_name) REFERENCES roles (role_name);
+
+
+GRANT ALL ON clusters TO &1;
+GRANT ALL ON clusterconfig TO &1;
+GRANT ALL ON clusterconfigmapping TO &1;
+GRANT ALL ON clusterservices TO &1;
+GRANT ALL ON clusterstate TO &1;
+GRANT ALL ON componentconfigmapping TO &1;
+GRANT ALL ON hostcomponentconfigmapping TO &1;
+GRANT ALL ON hcdesiredconfigmapping TO &1;
+GRANT ALL ON hostcomponentdesiredstate TO &1;
+GRANT ALL ON hostcomponentstate TO &1;
+GRANT ALL ON hosts TO &1;
+GRANT ALL ON hoststate TO &1;
+GRANT ALL ON servicecomponentdesiredstate TO &1;
+GRANT ALL ON serviceconfigmapping TO &1;
+GRANT ALL ON servicedesiredstate TO &1;
+GRANT ALL ON roles TO &1;
+GRANT ALL ON users TO &1;
+GRANT ALL ON execution_command TO &1;
+GRANT ALL ON host_role_command TO &1;
+GRANT ALL ON role_success_criteria TO &1;
+GRANT ALL ON stage TO &1;
+GRANT ALL ON ClusterHostMapping TO &1;
+GRANT ALL ON user_roles TO &1;
+GRANT ALL ON key_value_store TO &1;
+GRANT ALL ON hostconfigmapping TO &1;
+GRANT ALL ON ambari_sequences TO &1;
+GRANT ALL ON metainfo TO &1;
+
+
+INSERT INTO ambari_sequences(sequence_name, value) values ('host_role_command_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, value) values ('user_id_seq', 1);
+INSERT INTO ambari_sequences(sequence_name, value) values ('cluster_id_seq', 0);
+INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', '1.3.0');
+
+insert into Roles(role_name)
+select 'admin' from dual
+union all
+select 'user' from dual;
+
+insert into Users(user_id, user_name, user_password)
+select 1,'admin','538916f8943ec225d97a9a86a2c6ec0818c1cd400e09e03b660fdaaec4af29ddbb6f2b1033b81b00' from dual;
+
+insert into user_roles(role_name, user_id)
+select 'admin',1 from dual;
+
+
+
+commit;
+
+-- ambari rca
+
+CREATE TABLE workflow (
+  workflowId VARCHAR2(4000), workflowName VARCHAR2(4000),
+  parentWorkflowId VARCHAR2(4000),  
+  workflowContext VARCHAR2(4000), userName VARCHAR2(4000),
+  startTime INTEGER, lastUpdateTime INTEGER,
+  numJobsTotal INTEGER, numJobsCompleted INTEGER,
+  inputBytes INTEGER, outputBytes INTEGER,
+  duration INTEGER,
+  PRIMARY KEY (workflowId),
+  FOREIGN KEY (parentWorkflowId) REFERENCES workflow(workflowId)
+);
+
+GRANT ALL ON workflow TO &1;
+
+CREATE TABLE job (
+  jobId VARCHAR2(4000), workflowId VARCHAR2(4000), jobName VARCHAR2(4000), workflowEntityName VARCHAR2(4000),
+  userName VARCHAR2(4000), queue CLOB, acls CLOB, confPath CLOB, 
+  submitTime INTEGER, launchTime INTEGER, finishTime INTEGER, 
+  maps INTEGER, reduces INTEGER, status VARCHAR2(4000), priority VARCHAR2(4000), 
+  finishedMaps INTEGER, finishedReduces INTEGER, 
+  failedMaps INTEGER, failedReduces INTEGER, 
+  mapsRuntime INTEGER, reducesRuntime INTEGER,
+  mapCounters VARCHAR2(4000), reduceCounters VARCHAR2(4000), jobCounters VARCHAR2(4000), 
+  inputBytes INTEGER, outputBytes INTEGER,
+  PRIMARY KEY(jobId),
+  FOREIGN KEY(workflowId) REFERENCES workflow(workflowId)
+);
+
+GRANT ALL ON job TO &1;
+
+CREATE TABLE task (
+  taskId VARCHAR2(4000), jobId VARCHAR2(4000), taskType VARCHAR2(4000), splits VARCHAR2(4000), 
+  startTime INTEGER, finishTime INTEGER, status VARCHAR2(4000), error CLOB, counters VARCHAR2(4000), 
+  failedAttempt VARCHAR2(4000), 
+  PRIMARY KEY(taskId), 
+  FOREIGN KEY(jobId) REFERENCES job(jobId)
+);
+
+GRANT ALL ON task TO &1;
+
+CREATE TABLE taskAttempt (
+  taskAttemptId VARCHAR2(4000), taskId VARCHAR2(4000), jobId VARCHAR2(4000), taskType VARCHAR2(4000), taskTracker VARCHAR2(4000), 
+  startTime INTEGER, finishTime INTEGER, 
+  mapFinishTime INTEGER, shuffleFinishTime INTEGER, sortFinishTime INTEGER, 
+  locality VARCHAR2(4000), avataar VARCHAR2(4000), 
+  status VARCHAR2(4000), error CLOB, counters VARCHAR2(4000), 
+  inputBytes INTEGER, outputBytes INTEGER,
+  PRIMARY KEY(taskAttemptId), 
+  FOREIGN KEY(jobId) REFERENCES job(jobId), 
+  FOREIGN KEY(taskId) REFERENCES task(taskId)
+); 
+
+GRANT ALL ON taskAttempt TO &1;
+
+CREATE TABLE hdfsEvent (
+  timestamp INTEGER,
+  userName VARCHAR2(4000),
+  clientIP VARCHAR2(4000),
+  operation VARCHAR2(4000),
+  srcPath CLOB,
+  dstPath CLOB,
+  permissions VARCHAR2(4000)
+);
+
+GRANT ALL ON hdfsEvent TO &1;
+
+CREATE TABLE mapreduceEvent (
+  timestamp INTEGER,
+  userName VARCHAR2(4000),
+  clientIP VARCHAR2(4000),
+  operation VARCHAR2(4000),
+  target VARCHAR2(4000),
+  result CLOB,
+  description CLOB,
+  permissions VARCHAR2(4000)
+);
+
+GRANT ALL ON mapreduceEvent TO &1;
+
+CREATE TABLE clusterEvent (
+  timestamp INTEGER, 
+  service VARCHAR2(4000), status VARCHAR2(4000), 
+  error CLOB, data CLOB , 
+  host VARCHAR2(4000), rack VARCHAR2(4000)
+);
+
+GRANT ALL ON clusterEvent TO &1;
+

+ 23 - 1
ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql

@@ -38,10 +38,32 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hostconfigmapping TO :username;
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id);
 ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfigmapping_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name);
 
+ALTER ROLE :username SET search_path to 'ambari';
+
 ALTER SEQUENCE ambari.host_role_command_task_id_seq INCREMENT BY 50;
 SELECT nextval('ambari.host_role_command_task_id_seq');
 
-ALTER TABLE ambari.stage ADD COLUMN request_context VARCHAR(255);
+ALTER TABLE ambari.stage ADD COLUMN request_context VARCHAR(255);SELECT nextval('ambari.host_role_command_task_id_seq');
+
+
+-- portability changes for MySQL/Oracle support
+alter table ambari.hostcomponentdesiredconfigmapping rename to hcdesiredconfigmapping;
+alter table ambari.users alter column user_id drop default;
+alter table ambari.users alter column ldap_user type INTEGER using case when ldap_user=true then 1 else 0 END;
+
+CREATE TABLE ambari.ambari_sequences (sequence_name VARCHAR(255) PRIMARY KEY, "value" BIGINT NOT NULL);
+GRANT ALL PRIVILEGES ON TABLE ambari.ambari_sequences TO :username;
+
+insert into ambari.ambari_sequences(sequence_name, "value")
+  select 'cluster_id_seq', nextval('ambari.clusters_cluster_id_seq')
+  union all
+  select 'user_id_seq', nextval('ambari.users_user_id_seq')
+  union all
+  select 'host_role_command_id_seq', nextval('ambari.host_role_command_task_id_seq');
+
+drop sequence ambari.host_role_command_task_id_seq;
+drop sequence ambari.users_user_id_seq;
+drop sequence ambari.clusters_cluster_id_seq;
 
 BEGIN;
 

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/agent/DummyHeartbeatConstants.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information

+ 5 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java

@@ -1474,7 +1474,8 @@ public class AmbariManagementControllerImplTest {
       @Override
       protected void configure() {
         Properties properties = new Properties();
-        properties.setProperty(Configuration.PERSISTENCE_IN_MEMORY_KEY, "true");
+        properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory");
+
         properties.setProperty(Configuration.METADETA_DIR_PATH,
             "src/main/resources/stacks");
         properties.setProperty(Configuration.SERVER_VERSION_FILE,
@@ -1532,6 +1533,7 @@ public class AmbariManagementControllerImplTest {
     );
     amc.createConfiguration(configurationRequest);
 
+
     serviceRequests.clear();
     serviceRequests.add(new ServiceRequest("c1", "HDFS",
         gson.<Map<String, String>>fromJson("{\"core-site\": \"version1\", \"hdfs-site\": \"version1\", \"global\" : \"version1\" }", confType)
@@ -1548,6 +1550,7 @@ public class AmbariManagementControllerImplTest {
 
     amc.updateServices(serviceRequests, mapRequestProps, true);
 
+
     Set<ServiceComponentRequest> serviceComponentRequests = new HashSet<ServiceComponentRequest>();
     serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null, null));
     serviceComponentRequests.add(new ServiceComponentRequest("c1", "HDFS", "SECONDARY_NAMENODE", null, null));
@@ -1570,6 +1573,7 @@ public class AmbariManagementControllerImplTest {
     componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null, null));
     componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host3", null, null));
 
+
     amc.createHostComponents(componentHostRequests);
 
     serviceRequests.clear();

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java

@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information

+ 2 - 1
ambari-server/src/test/java/org/apache/ambari/server/orm/InMemoryDefaultTestModule.java

@@ -28,7 +28,8 @@ public class InMemoryDefaultTestModule extends AbstractModule {
   @Override
   protected void configure() {
     Properties properties = new Properties();
-    properties.setProperty(Configuration.PERSISTENCE_IN_MEMORY_KEY, "true");
+    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory");
+//    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "local");
     properties.setProperty(Configuration.METADETA_DIR_PATH,
         "src/test/resources/stacks");
     properties.setProperty(Configuration.SERVER_VERSION_FILE,

+ 2 - 1
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLdapAuthenticationProviderTest.java

@@ -25,6 +25,7 @@ import com.google.inject.Injector;
 import com.google.inject.persist.jpa.JpaPersistModule;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.RoleDAO;
 import org.apache.ambari.server.orm.dao.UserDAO;
 import org.apache.ambari.server.orm.entities.RoleEntity;
@@ -57,7 +58,7 @@ public class AmbariLdapAuthenticationProviderTest{
 
   @BeforeClass
   public static void beforeClass() throws Exception{
-    injector = Guice.createInjector(new AuthorizationTestModule(), new JpaPersistModule("ambari-javadb"));
+    injector = Guice.createInjector(new AuthorizationTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
     apacheDSContainer = new ApacheDSContainer("dc=ambari,dc=apache,dc=org", "classpath:/users.ldif");

+ 2 - 1
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariLocalUserDetailsServiceTest.java

@@ -22,6 +22,7 @@ import com.google.inject.Inject;
 import com.google.inject.Injector;
 import com.google.inject.persist.jpa.JpaPersistModule;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.UserDAO;
 import org.apache.ambari.server.orm.entities.UserEntity;
@@ -49,7 +50,7 @@ public class AmbariLocalUserDetailsServiceTest {
 
   @BeforeClass
   public static void prepareData() {
-    injector = Guice.createInjector(new AuthorizationTestModule(), new JpaPersistModule("ambari-javadb"));
+    injector = Guice.createInjector(new AuthorizationTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     injector.getInstance(OrmTestHelper.class).createTestUsers();
   }

+ 11 - 13
ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AuthorizationTestModule.java

@@ -19,6 +19,7 @@ package org.apache.ambari.server.security.authorization;
 
 import com.google.inject.AbstractModule;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.ControllerModule;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.crypto.password.StandardPasswordEncoder;
 
@@ -28,23 +29,20 @@ import java.util.Properties;
 public class AuthorizationTestModule extends AbstractModule {
   @Override
   protected void configure() {
-
-    bind(PasswordEncoder.class).to(StandardPasswordEncoder.class);
-    bind(Properties.class).toInstance(buildTestProperties());
-    bind(Configuration.class).toConstructor(getConfigurationConstructor());
-  }
-
-  protected Properties buildTestProperties() {
     Properties properties = new Properties();
     properties.setProperty(Configuration.CLIENT_SECURITY_KEY, "ldap");
-    return properties;
-  }
+    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory");
+    properties.setProperty(Configuration.METADETA_DIR_PATH,
+        "src/test/resources/stacks");
+    properties.setProperty(Configuration.SERVER_VERSION_FILE,
+        "../version");
+    properties.setProperty(Configuration.OS_VERSION_KEY,
+        "centos5");
 
-  protected Constructor<Configuration> getConfigurationConstructor() {
     try {
-      return Configuration.class.getConstructor(Properties.class);
-    } catch (NoSuchMethodException e) {
-      throw new RuntimeException("Expected constructor not found in Configuration.java", e);
+      install(new ControllerModule(properties));
+    } catch (Exception e) {
+      throw new RuntimeException(e);
     }
   }
 }

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/utils/TestStageUtils.java

@@ -177,7 +177,7 @@ public class TestStageUtils {
     addHdfsService(fsm.getCluster("c1"), hostList, injector);
     addHbaseService(fsm.getCluster("c1"), hostList, injector);
     Map<String, List<String>> info = StageUtils.getClusterHostInfo(fsm
-        .getCluster("c1"), new HostsMap(injector.getInstance(Configuration.class)));
+        .getCluster("c1"), new HostsMap(injector.getInstance(Configuration.class)), injector);
     assertEquals(2, info.get("slave_hosts").size());
     assertEquals(1, info.get("hbase_master_hosts").size());
     assertEquals("h1", info.get("hbase_master_hosts").get(0));

+ 4 - 2
ambari-server/src/test/python/TestAmbaryServer.py

@@ -907,9 +907,10 @@ class TestAmbariServer(TestCase):
   @patch.object(ambari_server, "check_postgre_up")
   @patch.object(ambari_server, "check_iptables")
   @patch.object(ambari_server, "check_selinux")
-  def test_setup(self, check_selinux_mock, check_iptables_mock,
+  @patch.object(ambari_server, "setup_remote_db")
+  def test_setup(self, setup_remote_db_mock, check_selinux_mock, check_iptables_mock,
                  check_postgre_up_mock, setup_db_mock, configure_postgres_mock,
-                 download_jdk_mock, configure_os_settings_mock):
+                 download_jdk_mock, configure_os_settings_mock, ):
 
     out = StringIO.StringIO()
     sys.stdout = out
@@ -920,6 +921,7 @@ class TestAmbariServer(TestCase):
     check_iptables_mock.return_value = (0, "other")
     check_postgre_up_mock.return_value = 0
     setup_db_mock.return_value = 0
+    setup_remote_db_mock.return_value = 0
     configure_postgres_mock.return_value = 0
     download_jdk_mock.return_value = 0
     configure_os_settings_mock.return_value = 0