ソースを参照

AMBARI-726. ORM-based data access layer for new design (Contributed by Jaimin Jetly)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1384149 13f79535-47bb-0310-9956-ffa450edef68
Hitesh Shah 12 年 前
コミット
897e5fd8b8
45 ファイル変更4292 行追加0 行削除
  1. 2 0
      AMBARI-666-CHANGES.txt
  2. 26 0
      ambari-project/pom.xml
  3. 16 0
      ambari-server/pom.xml
  4. 34 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/GuiceJpaInitializer.java
  5. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionStatusDAO.java
  6. 58 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
  7. 63 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
  8. 55 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java
  9. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ComponentHostDesiredStateDAO.java
  10. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java
  11. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
  12. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
  13. 55 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java
  14. 55 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java
  15. 55 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java
  16. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentStateDAO.java
  17. 73 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java
  18. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java
  19. 56 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceStateDAO.java
  20. 208 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionStatusEntity.java
  21. 112 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionStatusEntityPK.java
  22. 180 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java
  23. 165 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
  24. 70 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
  25. 83 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterStateEntity.java
  26. 153 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentHostDesiredStateEntity.java
  27. 84 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentHostDesiredStateEntityPK.java
  28. 114 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentMappingEntity.java
  29. 85 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentMappingEntityPK.java
  30. 153 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
  31. 84 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java
  32. 331 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
  33. 137 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
  34. 139 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentConfigEntity.java
  35. 165 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHostConfigEntity.java
  36. 123 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentStateEntity.java
  37. 84 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentStateEntityPK.java
  38. 125 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java
  39. 98 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
  40. 70 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
  41. 123 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceStateEntity.java
  42. 84 0
      ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceStateEntityPK.java
  43. 72 0
      ambari-server/src/main/resources/META-INF/persistence.xml
  44. 122 0
      ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
  45. 188 0
      ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-726. ORM-based data access layer for new design (Jaimin Jetly via hitesh)
+
   AMBARI-728. Initial work on ServiceComponentNode FSM. (hitesh)
 
   AMBARI-724. Add tabs, dynamic form generation, validation errors, and info

+ 26 - 0
ambari-project/pom.xml

@@ -38,6 +38,12 @@
       <url>http://download.java.net/maven/glassfish/</url>
     </pluginRepository>
   </pluginRepositories>
+  <repositories>
+    <repository>
+      <id>EclipseLink</id>
+      <url>http://download.eclipse.org/rt/eclipselink/maven.repo</url>
+    </repository>
+  </repositories>
   <profiles>
     <profile>
       <id>dist</id>
@@ -88,6 +94,26 @@
         <artifactId>guice-assistedinject</artifactId>
         <version>3.0</version>
       </dependency>
+      <dependency>
+        <groupId>com.google.inject.extensions</groupId>
+        <artifactId>guice-persist</artifactId>
+        <version>3.0</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.derby</groupId>
+        <artifactId>derby</artifactId>
+        <version>10.9.1.0</version>
+      </dependency>
+      <dependency>
+        <groupId>org.eclipse.persistence</groupId>
+        <artifactId>eclipselink</artifactId>
+        <version>2.4.0</version>
+      </dependency>
+      <dependency>
+        <groupId>postgresql</groupId>
+        <artifactId>postgresql</artifactId>
+        <version>9.1-901.jdbc4</version>
+      </dependency>
       <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>

+ 16 - 0
ambari-server/pom.xml

@@ -64,6 +64,22 @@
       <groupId>com.google.inject.extensions</groupId>
       <artifactId>guice-assistedinject</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.google.inject.extensions</groupId>
+      <artifactId>guice-persist</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.derby</groupId>
+      <artifactId>derby</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.persistence</groupId>
+      <artifactId>eclipselink</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>postgresql</groupId>
+      <artifactId>postgresql</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>

+ 34 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/GuiceJpaInitializer.java

@@ -0,0 +1,34 @@
+/**
+ * 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;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.PersistService;
+
+/**
+ * This class needs to be instantiated with guice to initialize Guice-persist
+ */
+public class GuiceJpaInitializer {
+
+  @Inject
+  public GuiceJpaInitializer(PersistService service) {
+    service.start();
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionStatusDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ActionStatusEntity;
+import org.apache.ambari.server.orm.entities.ActionStatusEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ActionStatusDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ActionStatusEntity findByPK(ActionStatusEntityPK actionStatusEntityPK) {
+    return entityManager.find(ActionStatusEntity.class, actionStatusEntityPK);
+  }
+
+  @Transactional
+  public void create(ActionStatusEntity actionStatusEntity) {
+    entityManager.persist(actionStatusEntity);
+  }
+
+  @Transactional
+  public ActionStatusEntity merge(ActionStatusEntity actionStatusEntity) {
+    return entityManager.merge(actionStatusEntity);
+  }
+
+  @Transactional
+  public void remove(ActionStatusEntity actionStatusEntity) {
+    entityManager.remove(actionStatusEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ActionStatusEntityPK actionStatusEntityPK) {
+    remove(findByPK(actionStatusEntityPK));
+  }
+
+}

+ 58 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.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.server.orm.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.persistence.EntityManager;
+
+public class ClusterDAO {
+  private static final Log log = LogFactory.getLog(ClusterDAO.class);
+
+  @Inject
+  EntityManager entityManager;
+
+  public ClusterEntity findByName(String clusterName) {
+    return entityManager.find(ClusterEntity.class, clusterName);
+  }
+
+  public void create(ClusterEntity clusterEntity) {
+    entityManager.persist(clusterEntity);
+  }
+
+  @Transactional
+  public ClusterEntity merge(ClusterEntity clusterEntity) {
+    return entityManager.merge(clusterEntity);
+  }
+
+  @Transactional
+  public void remove(ClusterEntity clusterEntity) {
+    entityManager.remove(clusterEntity);
+  }
+
+  @Transactional
+  public void removeByName(String clusterName) {
+    remove(findByName(clusterName));
+  }
+
+}

+ 63 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java

@@ -0,0 +1,63 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ClusterServiceDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ClusterServiceEntity findByPK(ClusterServiceEntityPK clusterServiceEntityPK) {
+    return entityManager.find(ClusterServiceEntity.class, clusterServiceEntityPK);
+  }
+
+  public ClusterServiceEntity findByClusterAndServiceNames(String clusterName, String serviceName) {
+    ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
+    pk.setClusterName(clusterName);
+    pk.setServiceName(serviceName);
+    return findByPK(pk);
+  }
+
+  @Transactional
+  public void create(ClusterServiceEntity clusterServiceEntity) {
+    entityManager.persist(clusterServiceEntity);
+  }
+
+  @Transactional
+  public ClusterServiceEntity merge(ClusterServiceEntity clusterServiceEntity) {
+    return entityManager.merge(clusterServiceEntity);
+  }
+
+  @Transactional
+  public void remove(ClusterServiceEntity clusterServiceEntity) {
+    entityManager.remove(clusterServiceEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ClusterServiceEntityPK clusterServiceEntityPK) {
+    remove(findByPK(clusterServiceEntityPK));
+  }
+
+}

+ 55 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java

@@ -0,0 +1,55 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ClusterStateEntity;
+
+import javax.persistence.EntityManager;
+
+public class ClusterStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ClusterStateEntity findByPK(String clusterName) {
+    return entityManager.find(ClusterStateEntity.class, clusterName);
+  }
+
+  @Transactional
+  public void create(ClusterStateEntity clusterStateEntity) {
+    entityManager.persist(clusterStateEntity);
+  }
+
+  @Transactional
+  public ClusterStateEntity merge(ClusterStateEntity clusterStateEntity) {
+    return entityManager.merge(clusterStateEntity);
+  }
+
+  @Transactional
+  public void remove(ClusterStateEntity clusterStateEntity) {
+    entityManager.remove(clusterStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(String clusterName) {
+    remove(findByPK(clusterName));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ComponentHostDesiredStateDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ComponentHostDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.ComponentHostDesiredStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ComponentHostDesiredStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ComponentHostDesiredStateEntity findByPK(ComponentHostDesiredStateEntityPK primaryKey) {
+    return entityManager.find(ComponentHostDesiredStateEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ComponentHostDesiredStateEntity componentHostDesiredStateEntity) {
+    entityManager.persist(componentHostDesiredStateEntity);
+  }
+
+  @Transactional
+  public ComponentHostDesiredStateEntity merge(ComponentHostDesiredStateEntity componentHostDesiredStateEntity) {
+    return entityManager.merge(componentHostDesiredStateEntity);
+  }
+
+  @Transactional
+  public void remove(ComponentHostDesiredStateEntity componentHostDesiredStateEntity) {
+    entityManager.remove(componentHostDesiredStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ComponentHostDesiredStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentMappingDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.HostComponentMappingEntity;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class HostComponentMappingDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public HostComponentMappingEntity findByPK(HostComponentStateEntityPK primaryKey) {
+    return entityManager.find(HostComponentMappingEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(HostComponentMappingEntity hostComponentMappingEntity) {
+    entityManager.persist(hostComponentMappingEntity);
+  }
+
+  @Transactional
+  public HostComponentMappingEntity merge(HostComponentMappingEntity hostComponentMappingEntity) {
+    return entityManager.merge(hostComponentMappingEntity);
+  }
+
+  @Transactional
+  public void remove(HostComponentMappingEntity hostComponentMappingEntity) {
+    entityManager.remove(hostComponentMappingEntity);
+  }
+
+  @Transactional
+  public void removeByPK(HostComponentStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class HostComponentStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public HostComponentStateEntity findByPK(HostComponentStateEntityPK primaryKey) {
+    return entityManager.find(HostComponentStateEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(HostComponentStateEntity hostComponentStateEntity) {
+    entityManager.persist(hostComponentStateEntity);
+  }
+
+  @Transactional
+  public HostComponentStateEntity merge(HostComponentStateEntity hostComponentStateEntity) {
+    return entityManager.merge(hostComponentStateEntity);
+  }
+
+  @Transactional
+  public void remove(HostComponentStateEntity hostComponentStateEntity) {
+    entityManager.remove(hostComponentStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(HostComponentStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.HostEntity;
+
+import javax.persistence.EntityManager;
+
+public class HostDAO {
+
+  @Inject
+  EntityManager entityManager;
+
+  public HostEntity findByName(String hostName) {
+    return entityManager.find(HostEntity.class, hostName);
+  }
+
+  @Transactional
+  public void create(HostEntity hostEntity) {
+    entityManager.persist(hostEntity);
+  }
+
+  @Transactional
+  public HostEntity merge(HostEntity hostEntity) {
+    return entityManager.merge(hostEntity);
+  }
+
+  @Transactional
+  public void remove(HostEntity hostEntity) {
+    entityManager.remove(hostEntity);
+  }
+
+  @Transactional
+  public void removeByName(String hostName) {
+    remove(findByName(hostName));
+  }
+
+}

+ 55 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java

@@ -0,0 +1,55 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.HostStateEntity;
+
+import javax.persistence.EntityManager;
+
+public class HostStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public HostStateEntity findByHostName(String hostName) {
+    return entityManager.find(HostStateEntity.class, hostName);
+  }
+
+  @Transactional
+  public void create(HostStateEntity hostStateEntity) {
+    entityManager.persist(hostStateEntity);
+  }
+
+  @Transactional
+  public HostStateEntity merge(HostStateEntity hostStateEntity) {
+    return entityManager.merge(hostStateEntity);
+  }
+
+  @Transactional
+  public void remove(HostStateEntity hostStateEntity) {
+    entityManager.remove(hostStateEntity);
+  }
+
+  @Transactional
+  public void removeByHostName(String hostName) {
+    remove(findByHostName(hostName));
+  }
+
+}

+ 55 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentConfigDAO.java

@@ -0,0 +1,55 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ServiceComponentConfigEntity;
+
+import javax.persistence.EntityManager;
+
+public class ServiceComponentConfigDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceComponentConfigEntity findByPK(Integer primaryKey) {
+    return entityManager.find(ServiceComponentConfigEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ServiceComponentConfigEntity serviceComponentConfigEntity) {
+    entityManager.persist(serviceComponentConfigEntity);
+  }
+
+  @Transactional
+  public ServiceComponentConfigEntity merge(ServiceComponentConfigEntity serviceComponentConfigEntity) {
+    return entityManager.merge(serviceComponentConfigEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceComponentConfigEntity serviceComponentConfigEntity) {
+    entityManager.remove(serviceComponentConfigEntity);
+  }
+
+  @Transactional
+  public void removeByPK(Integer primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 55 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentHostConfigDAO.java

@@ -0,0 +1,55 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ServiceComponentHostConfigEntity;
+
+import javax.persistence.EntityManager;
+
+public class ServiceComponentHostConfigDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceComponentHostConfigEntity findByPK(Integer primaryKey) {
+    return entityManager.find(ServiceComponentHostConfigEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ServiceComponentHostConfigEntity serviceComponentHostConfigEntity) {
+    entityManager.persist(serviceComponentHostConfigEntity);
+  }
+
+  @Transactional
+  public ServiceComponentHostConfigEntity merge(ServiceComponentHostConfigEntity serviceComponentHostConfigEntity) {
+    return entityManager.merge(serviceComponentHostConfigEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceComponentHostConfigEntity serviceComponentHostConfigEntity) {
+    entityManager.remove(serviceComponentHostConfigEntity);
+  }
+
+  @Transactional
+  public void removeByPK(Integer primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentStateDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ServiceComponentStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceComponentStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ServiceComponentStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceComponentStateEntity findByPK(ServiceComponentStateEntityPK primaryKey) {
+    return entityManager.find(ServiceComponentStateEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ServiceComponentStateEntity serviceComponentStateEntity) {
+    entityManager.persist(serviceComponentStateEntity);
+  }
+
+  @Transactional
+  public ServiceComponentStateEntity merge(ServiceComponentStateEntity serviceComponentStateEntity) {
+    return entityManager.merge(serviceComponentStateEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceComponentStateEntity serviceComponentStateEntity) {
+    entityManager.remove(serviceComponentStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ServiceComponentStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 73 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceConfigDAO.java

@@ -0,0 +1,73 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
+
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+public class ServiceConfigDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceConfigEntity findByPK(Integer primaryKey) {
+    return entityManager.find(ServiceConfigEntity.class, primaryKey);
+  }
+
+  public List<ServiceConfigEntity> findByClusterService(ClusterServiceEntity clusterServiceEntity) {
+    TypedQuery<ServiceConfigEntity> query = entityManager.createQuery("select config " +
+            "from ServiceConfigEntity config " +
+            "join config.clusterServiceEntity clusterService " +
+            "where clusterService = :service", ServiceConfigEntity.class);
+    query.setParameter("service", clusterServiceEntity);
+    return query.getResultList();
+  }
+
+  public List<ServiceConfigEntity> findAll() {
+    TypedQuery<ServiceConfigEntity> query = entityManager.createQuery("select c from ServiceConfigEntity c"
+            , ServiceConfigEntity.class);
+    return query.getResultList();
+  }
+
+  @Transactional
+  public void create(ServiceConfigEntity serviceConfigEntity) {
+    entityManager.persist(serviceConfigEntity);
+  }
+
+  @Transactional
+  public ServiceConfigEntity merge(ServiceConfigEntity serviceConfigEntity) {
+    return entityManager.merge(serviceConfigEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceConfigEntity serviceConfigEntity) {
+    entityManager.remove(serviceConfigEntity);
+  }
+
+  @Transactional
+  public void removeByPK(Integer primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ServiceDesiredStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceDesiredStateEntity findByPK(ServiceDesiredStateEntityPK primaryKey) {
+    return entityManager.find(ServiceDesiredStateEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ServiceDesiredStateEntity serviceDesiredStateEntity) {
+    entityManager.persist(serviceDesiredStateEntity);
+  }
+
+  @Transactional
+  public ServiceDesiredStateEntity merge(ServiceDesiredStateEntity serviceDesiredStateEntity) {
+    return entityManager.merge(serviceDesiredStateEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceDesiredStateEntity serviceDesiredStateEntity) {
+    entityManager.remove(serviceDesiredStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ServiceDesiredStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 56 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceStateDAO.java

@@ -0,0 +1,56 @@
+/**
+ * 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.dao;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.entities.ServiceStateEntity;
+import org.apache.ambari.server.orm.entities.ServiceStateEntityPK;
+
+import javax.persistence.EntityManager;
+
+public class ServiceStateDAO {
+  @Inject
+  EntityManager entityManager;
+
+  public ServiceStateEntity findByPK(ServiceStateEntityPK primaryKey) {
+    return entityManager.find(ServiceStateEntity.class, primaryKey);
+  }
+
+  @Transactional
+  public void create(ServiceStateEntity serviceStateEntity) {
+    entityManager.persist(serviceStateEntity);
+  }
+
+  @Transactional
+  public ServiceStateEntity merge(ServiceStateEntity serviceStateEntity) {
+    return entityManager.merge(serviceStateEntity);
+  }
+
+  @Transactional
+  public void remove(ServiceStateEntity serviceStateEntity) {
+    entityManager.remove(serviceStateEntity);
+  }
+
+  @Transactional
+  public void removeByPK(ServiceStateEntityPK primaryKey) {
+    remove(findByPK(primaryKey));
+  }
+
+}

+ 208 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionStatusEntity.java

@@ -0,0 +1,208 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.Arrays;
+
+@javax.persistence.IdClass(ActionStatusEntityPK.class)
+@javax.persistence.Table(name = "actionstatus", schema = "ambari", catalog = "")
+@Entity
+public class ActionStatusEntity {
+
+  private String clusterName = "";
+
+  @javax.persistence.Column(name = "cluster_name", nullable = true, insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName = "";
+
+  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String role = "";
+
+  @javax.persistence.Column(name = "role", nullable = false)
+  @Id
+  public String getRole() {
+    return role;
+  }
+
+  public void setRole(String role) {
+    this.role = role;
+  }
+
+  private Integer requestId = 0;
+
+  @javax.persistence.Column(name = "request_id", nullable = false)
+  @Id
+  public Integer getRequestId() {
+    return requestId;
+  }
+
+  public void setRequestId(Integer requestId) {
+    this.requestId = requestId;
+  }
+
+  private Integer stageId = 0;
+
+  @javax.persistence.Column(name = "stage_id", nullable = false)
+  @Id
+  public Integer getStageId() {
+    return stageId;
+  }
+
+  public void setStageId(Integer stageId) {
+    this.stageId = stageId;
+  }
+
+  private String event = "";
+
+  @javax.persistence.Column(name = "event", nullable = false)
+  @Basic
+  public String getEvent() {
+    return event;
+  }
+
+  public void setEvent(String event) {
+    this.event = event;
+  }
+
+  private Integer taskId = 0;
+
+  @javax.persistence.Column(name = "task_id", nullable = false)
+  @Basic
+  public Integer getTaskId() {
+    return taskId;
+  }
+
+  public void setTaskId(Integer taskId) {
+    this.taskId = taskId;
+  }
+
+  private String status = "";
+
+  @javax.persistence.Column(name = "status", nullable = false)
+  @Basic
+  public String getStatus() {
+    return status;
+  }
+
+  public void setStatus(String status) {
+    this.status = status;
+  }
+
+  private String logInfo;
+
+  @javax.persistence.Column(name = "log_info")
+  @Basic
+  public String getLogInfo() {
+    return logInfo;
+  }
+
+  public void setLogInfo(String logInfo) {
+    this.logInfo = logInfo;
+  }
+
+  private byte[] continueCriteria;
+
+  @javax.persistence.Column(name = "continue_criteria")
+  @Basic
+  public byte[] getContinueCriteria() {
+    return continueCriteria;
+  }
+
+  public void setContinueCriteria(byte[] continueCriteria) {
+    this.continueCriteria = continueCriteria;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ActionStatusEntity that = (ActionStatusEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (!Arrays.equals(continueCriteria, that.continueCriteria)) return false;
+    if (event != null ? !event.equals(that.event) : that.event != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (logInfo != null ? !logInfo.equals(that.logInfo) : that.logInfo != null) return false;
+    if (requestId != null ? !requestId.equals(that.requestId) : that.requestId != null) return false;
+    if (role != null ? !role.equals(that.role) : that.role != null) return false;
+    if (stageId != null ? !stageId.equals(that.stageId) : that.stageId != null) return false;
+    if (status != null ? !status.equals(that.status) : that.status != null) return false;
+    if (taskId != null ? !taskId.equals(that.taskId) : that.taskId != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (role != null ? role.hashCode() : 0);
+    result = 31 * result + (requestId != null ? requestId.hashCode() : 0);
+    result = 31 * result + (stageId != null ? stageId.hashCode() : 0);
+    result = 31 * result + (event != null ? event.hashCode() : 0);
+    result = 31 * result + (taskId != null ? taskId.hashCode() : 0);
+    result = 31 * result + (status != null ? status.hashCode() : 0);
+    result = 31 * result + (logInfo != null ? logInfo.hashCode() : 0);
+    result = 31 * result + (continueCriteria != null ? Arrays.hashCode(continueCriteria) : 0);
+    return result;
+  }
+}

+ 112 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionStatusEntityPK.java

@@ -0,0 +1,112 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ActionStatusEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Id
+  @Column(name = "host_name")
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String role;
+
+  @Id
+  @Column(name = "role")
+  public String getRole() {
+    return role;
+  }
+
+  public void setRole(String role) {
+    this.role = role;
+  }
+
+  private Integer requestId;
+
+  @Id
+  @Column(name = "request_id")
+  public Integer getRequestId() {
+    return requestId;
+  }
+
+  public void setRequestId(Integer requestId) {
+    this.requestId = requestId;
+  }
+
+  private Integer stageId;
+
+  @Id
+  @Column(name = "stage_id")
+  public Integer getStageId() {
+    return stageId;
+  }
+
+  public void setStageId(Integer stageId) {
+    this.stageId = stageId;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ActionStatusEntityPK that = (ActionStatusEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (requestId != null ? !requestId.equals(that.requestId) : that.requestId != null) return false;
+    if (role != null ? !role.equals(that.role) : that.role != null) return false;
+    if (stageId != null ? !stageId.equals(that.stageId) : that.stageId != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (role != null ? role.hashCode() : 0);
+    result = 31 * result + (requestId != null ? requestId.hashCode() : 0);
+    result = 31 * result + (stageId != null ? stageId.hashCode() : 0);
+    return result;
+  }
+}

+ 180 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterEntity.java

@@ -0,0 +1,180 @@
+/**
+ * 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.entities;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.persistence.*;
+import java.util.List;
+
+@Table(name = "clusters", schema = "ambari", catalog = "")
+@Entity
+public class ClusterEntity {
+
+  private static final Log log = LogFactory.getLog(ClusterEntity.class);
+
+  private String clusterName;
+
+  @Column(name = "cluster_name")
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String desiredClusterState = "";
+
+  @Column(name = "desired_cluster_state", nullable = false)
+  @Basic
+  public String getDesiredClusterState() {
+    return desiredClusterState;
+  }
+
+  public void setDesiredClusterState(String desiredClusterState) {
+    this.desiredClusterState = desiredClusterState;
+  }
+
+  private String clusterInfo = "";
+
+  @Column(name = "cluster_info", nullable = false)
+  @Basic
+  public String getClusterInfo() {
+    return clusterInfo;
+  }
+
+  public void setClusterInfo(String clusterInfo) {
+    this.clusterInfo = clusterInfo;
+  }
+
+  List<HostEntity> hostEntities;
+
+  @OneToMany(cascade = CascadeType.ALL, mappedBy = "clusterEntity")
+  public List<HostEntity> getHostEntities() {
+    return hostEntities;
+  }
+
+  public void setHostEntities(List<HostEntity> hostEntities) {
+    this.hostEntities = hostEntities;
+  }
+
+  List<ClusterServiceEntity> clusterServiceEntities;
+
+  @OneToMany(cascade = CascadeType.ALL, mappedBy = "clusterEntity")
+  public List<ClusterServiceEntity> getClusterServiceEntities() {
+    return clusterServiceEntities;
+  }
+
+  public void setClusterServiceEntities(List<ClusterServiceEntity> clusterServiceEntities) {
+    this.clusterServiceEntities = clusterServiceEntities;
+  }
+
+  List<ActionStatusEntity> actionStatusEntities;
+
+  @OneToMany(mappedBy = "clusterEntity")
+  public List<ActionStatusEntity> getActionStatusEntities() {
+    return actionStatusEntities;
+  }
+
+  public void setActionStatusEntities(List<ActionStatusEntity> actionStatusEntities) {
+    this.actionStatusEntities = actionStatusEntities;
+  }
+
+  List<ComponentHostDesiredStateEntity> componentHostDesiredStateEntities;
+
+  @OneToMany(mappedBy = "clusterEntity")
+  public List<ComponentHostDesiredStateEntity> getComponentHostDesiredStateEntities() {
+    return componentHostDesiredStateEntities;
+  }
+
+  public void setComponentHostDesiredStateEntities(List<ComponentHostDesiredStateEntity> componentHostDesiredStateEntities) {
+    this.componentHostDesiredStateEntities = componentHostDesiredStateEntities;
+  }
+
+  private ClusterStateEntity clusterStateEntity;
+
+  @OneToOne(mappedBy = "clusterEntity")
+  public ClusterStateEntity getClusterStateEntity() {
+    return clusterStateEntity;
+  }
+
+  public void setClusterStateEntity(ClusterStateEntity clusterStateEntity) {
+    this.clusterStateEntity = clusterStateEntity;
+  }
+
+  private List<HostStateEntity> hostStateEntities;
+
+  @OneToMany(mappedBy = "clusterEntity")
+  public List<HostStateEntity> getHostStateEntities() {
+    return hostStateEntities;
+  }
+
+  public void setHostStateEntities(List<HostStateEntity> hostStateEntities) {
+    this.hostStateEntities = hostStateEntities;
+  }
+
+  private List<HostComponentStateEntity> hostComponentStateEntities;
+
+  @OneToMany(mappedBy = "clusterEntity")
+  public List<HostComponentStateEntity> getHostComponentStateEntities() {
+    return hostComponentStateEntities;
+  }
+
+  public void setHostComponentStateEntities(List<HostComponentStateEntity> hostComponentStateEntities) {
+    this.hostComponentStateEntities = hostComponentStateEntities;
+  }
+
+  private List<ServiceComponentStateEntity> serviceComponentStateEntities;
+
+  @OneToMany(mappedBy = "clusterEntity")
+  public List<ServiceComponentStateEntity> getServiceComponentStateEntities() {
+    return serviceComponentStateEntities;
+  }
+
+  public void setServiceComponentStateEntities(List<ServiceComponentStateEntity> serviceComponentStateEntities) {
+    this.serviceComponentStateEntities = serviceComponentStateEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterEntity that = (ClusterEntity) o;
+
+    if (clusterInfo != null ? !clusterInfo.equals(that.clusterInfo) : that.clusterInfo != null) return false;
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (desiredClusterState != null ? !desiredClusterState.equals(that.desiredClusterState) : that.desiredClusterState != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (desiredClusterState != null ? desiredClusterState.hashCode() : 0);
+    result = 31 * result + (clusterInfo != null ? clusterInfo.hashCode() : 0);
+    return result;
+  }
+
+}

+ 165 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java

@@ -0,0 +1,165 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.List;
+
+@IdClass(ClusterServiceEntityPK.class)
+@Table(name = "clusterservices", schema = "ambari", catalog = "")
+@Entity
+public class ClusterServiceEntity {
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", nullable = false, insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Column(name = "service_name")
+  @Id
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private Integer serviceEnabled = 0;
+
+  @Column(name = "service_enabled", nullable = false)
+  @Basic
+  public Integer getServiceEnabled() {
+    return serviceEnabled;
+  }
+
+  public void setServiceEnabled(Integer serviceEnabled) {
+    this.serviceEnabled = serviceEnabled;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private List<ServiceConfigEntity> serviceConfigEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<ServiceConfigEntity> getServiceConfigEntities() {
+    return serviceConfigEntities;
+  }
+
+  public void setServiceConfigEntities(List<ServiceConfigEntity> serviceConfigEntities) {
+    this.serviceConfigEntities = serviceConfigEntities;
+  }
+
+  private List<ServiceComponentConfigEntity> serviceComponentConfigEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<ServiceComponentConfigEntity> getServiceComponentConfigEntities() {
+    return serviceComponentConfigEntities;
+  }
+
+  public void setServiceComponentConfigEntities(List<ServiceComponentConfigEntity> serviceComponentConfigEntities) {
+    this.serviceComponentConfigEntities = serviceComponentConfigEntities;
+  }
+
+  private List<ServiceComponentHostConfigEntity> serviceComponentHostConfigEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<ServiceComponentHostConfigEntity> getServiceComponentHostConfigEntities() {
+    return serviceComponentHostConfigEntities;
+  }
+
+  public void setServiceComponentHostConfigEntities(List<ServiceComponentHostConfigEntity> serviceComponentHostConfigEntities) {
+    this.serviceComponentHostConfigEntities = serviceComponentHostConfigEntities;
+  }
+
+  private List<ServiceDesiredStateEntity> serviceDesiredStateEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<ServiceDesiredStateEntity> getServiceDesiredStateEntities() {
+    return serviceDesiredStateEntities;
+  }
+
+  public void setServiceDesiredStateEntities(List<ServiceDesiredStateEntity> serviceDesiredStateEntities) {
+    this.serviceDesiredStateEntities = serviceDesiredStateEntities;
+  }
+
+  private List<HostComponentMappingEntity> hostComponentMappingEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<HostComponentMappingEntity> getHostComponentMappingEntities() {
+    return hostComponentMappingEntities;
+  }
+
+  public void setHostComponentMappingEntities(List<HostComponentMappingEntity> hostComponentMappingEntities) {
+    this.hostComponentMappingEntities = hostComponentMappingEntities;
+  }
+
+  private List<ServiceStateEntity> serviceStateEntities;
+
+  @OneToMany(mappedBy = "clusterServiceEntity")
+  public List<ServiceStateEntity> getServiceStateEntities() {
+    return serviceStateEntities;
+  }
+
+  public void setServiceStateEntities(List<ServiceStateEntity> serviceStateEntities) {
+    this.serviceStateEntities = serviceStateEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterServiceEntity that = (ClusterServiceEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (serviceEnabled != null ? !serviceEnabled.equals(that.serviceEnabled) : that.serviceEnabled != null)
+      return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (serviceEnabled != null ? serviceEnabled.hashCode() : 0);
+    return result;
+  }
+}

+ 70 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java

@@ -0,0 +1,70 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ClusterServiceEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Id
+  @Column(name = "service_name")
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterServiceEntityPK that = (ClusterServiceEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    return result;
+  }
+}

+ 83 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterStateEntity.java

@@ -0,0 +1,83 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.Table(name = "clusterstate", schema = "ambari", catalog = "")
+@Entity
+public class ClusterStateEntity {
+
+  private String clusterName;
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String currentClusterState = "";
+
+  @javax.persistence.Column(name = "current_cluster_state", nullable = false)
+  @Basic
+  public String getCurrentClusterState() {
+    return currentClusterState;
+  }
+
+  public void setCurrentClusterState(String currentClusterState) {
+    this.currentClusterState = currentClusterState;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @OneToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ClusterStateEntity that = (ClusterStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (currentClusterState != null ? !currentClusterState.equals(that.currentClusterState) : that.currentClusterState != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (currentClusterState != null ? currentClusterState.hashCode() : 0);
+    return result;
+  }
+}

+ 153 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentHostDesiredStateEntity.java

@@ -0,0 +1,153 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.IdClass(ComponentHostDesiredStateEntityPK.class)
+@javax.persistence.Table(name = "componenthostdesiredstate", schema = "ambari", catalog = "")
+@Entity
+public class ComponentHostDesiredStateEntity {
+
+  private String clusterName = "";
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName = "";
+
+  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName = "";
+
+  @javax.persistence.Column(name = "component_name", nullable = false)
+  @Id
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  private String desiredState = "";
+
+  @javax.persistence.Column(name = "desired_state", nullable = false)
+  @Basic
+  public String getDesiredState() {
+    return desiredState;
+  }
+
+  public void setDesiredState(String desiredState) {
+    this.desiredState = desiredState;
+  }
+
+  private String desiredConfigVersion = "";
+
+  @javax.persistence.Column(name = "desired_config_version", nullable = false)
+  @Basic
+  public String getDesiredConfigVersion() {
+    return desiredConfigVersion;
+  }
+
+  public void setDesiredConfigVersion(String desiredConfigVersion) {
+    this.desiredConfigVersion = desiredConfigVersion;
+  }
+
+  private String desiredStackVersion = "";
+
+  @javax.persistence.Column(name = "desired_stack_version", nullable = false)
+  @Basic
+  public String getDesiredStackVersion() {
+    return desiredStackVersion;
+  }
+
+  public void setDesiredStackVersion(String desiredStackVersion) {
+    this.desiredStackVersion = desiredStackVersion;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ComponentHostDesiredStateEntity that = (ComponentHostDesiredStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (desiredConfigVersion != null ? !desiredConfigVersion.equals(that.desiredConfigVersion) : that.desiredConfigVersion != null)
+      return false;
+    if (desiredStackVersion != null ? !desiredStackVersion.equals(that.desiredStackVersion) : that.desiredStackVersion != null)
+      return false;
+    if (desiredState != null ? !desiredState.equals(that.desiredState) : that.desiredState != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    result = 31 * result + (desiredState != null ? desiredState.hashCode() : 0);
+    result = 31 * result + (desiredConfigVersion != null ? desiredConfigVersion.hashCode() : 0);
+    result = 31 * result + (desiredStackVersion != null ? desiredStackVersion.hashCode() : 0);
+    return result;
+  }
+}

+ 84 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ComponentHostDesiredStateEntityPK.java

@@ -0,0 +1,84 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ComponentHostDesiredStateEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Id
+  @Column(name = "host_name")
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName;
+
+  @Id
+  @Column(name = "component_name")
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ComponentHostDesiredStateEntityPK that = (ComponentHostDesiredStateEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    return result;
+  }
+}

+ 114 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentMappingEntity.java

@@ -0,0 +1,114 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@IdClass(HostComponentMappingEntityPK.class)
+@Table(name = "hostcomponentmapping", schema = "ambari", catalog = "")
+@Entity
+public class HostComponentMappingEntity {
+
+  private String clusterName = "";
+
+  @Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName = "";
+
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  @Id
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private Integer hostComponentMappingId;
+
+  @Column(name = "host_component_mapping_id")
+  @Id
+  @GeneratedValue(strategy = GenerationType.AUTO)
+  public Integer getHostComponentMappingId() {
+    return hostComponentMappingId;
+  }
+
+  public void setHostComponentMappingId(Integer hostComponentMappingId) {
+    this.hostComponentMappingId = hostComponentMappingId;
+  }
+
+  private String hostComponentMappingSnapshot;
+
+  @Column(name = "host_component_mapping_snapshot")
+  @Basic
+  public String getHostComponentMappingSnapshot() {
+    return hostComponentMappingSnapshot;
+  }
+
+  public void setHostComponentMappingSnapshot(String hostComponentMappingSnapshot) {
+    this.hostComponentMappingSnapshot = hostComponentMappingSnapshot;
+  }
+
+  ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostComponentMappingEntity that = (HostComponentMappingEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (hostComponentMappingId != null ? !hostComponentMappingId.equals(that.hostComponentMappingId) : that.hostComponentMappingId != null)
+      return false;
+    if (hostComponentMappingSnapshot != null ? !hostComponentMappingSnapshot.equals(that.hostComponentMappingSnapshot) : that.hostComponentMappingSnapshot != null)
+      return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (hostComponentMappingId != null ? hostComponentMappingId.hashCode() : 0);
+    result = 31 * result + (hostComponentMappingSnapshot != null ? hostComponentMappingSnapshot.hashCode() : 0);
+    return result;
+  }
+}

+ 85 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentMappingEntityPK.java

@@ -0,0 +1,85 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class HostComponentMappingEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Id
+  @Column(name = "service_name")
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private Integer hostComponentMappingId;
+
+  @Id
+  @Column(name = "host_component_mapping_id")
+  public Integer getHostComponentMappingId() {
+    return hostComponentMappingId;
+  }
+
+  public void setHostComponentMappingId(Integer hostComponentMappingId) {
+    this.hostComponentMappingId = hostComponentMappingId;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostComponentMappingEntityPK that = (HostComponentMappingEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (hostComponentMappingId != null ? !hostComponentMappingId.equals(that.hostComponentMappingId) : that.hostComponentMappingId != null)
+      return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (hostComponentMappingId != null ? hostComponentMappingId.hashCode() : 0);
+    return result;
+  }
+}

+ 153 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java

@@ -0,0 +1,153 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.IdClass(HostComponentStateEntityPK.class)
+@javax.persistence.Table(name = "hostcomponentstate", schema = "ambari", catalog = "")
+@Entity
+public class HostComponentStateEntity {
+
+  private String clusterName;
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @javax.persistence.Column(name = "host_name", insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName;
+
+  @javax.persistence.Column(name = "component_name")
+  @Id
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  private String currentState;
+
+  @javax.persistence.Column(name = "current_state")
+  @Basic
+  public String getCurrentState() {
+    return currentState;
+  }
+
+  public void setCurrentState(String currentState) {
+    this.currentState = currentState;
+  }
+
+  private String currentConfigVersion;
+
+  @javax.persistence.Column(name = "current_config_version")
+  @Basic
+  public String getCurrentConfigVersion() {
+    return currentConfigVersion;
+  }
+
+  public void setCurrentConfigVersion(String currentConfigVersion) {
+    this.currentConfigVersion = currentConfigVersion;
+  }
+
+  private String currentStackVersion;
+
+  @javax.persistence.Column(name = "current_stack_version")
+  @Basic
+  public String getCurrentStackVersion() {
+    return currentStackVersion;
+  }
+
+  public void setCurrentStackVersion(String currentStackVersion) {
+    this.currentStackVersion = currentStackVersion;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostComponentStateEntity that = (HostComponentStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (currentConfigVersion != null ? !currentConfigVersion.equals(that.currentConfigVersion) : that.currentConfigVersion != null)
+      return false;
+    if (currentStackVersion != null ? !currentStackVersion.equals(that.currentStackVersion) : that.currentStackVersion != null)
+      return false;
+    if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
+    result = 31 * result + (currentConfigVersion != null ? currentConfigVersion.hashCode() : 0);
+    result = 31 * result + (currentStackVersion != null ? currentStackVersion.hashCode() : 0);
+    return result;
+  }
+}

+ 84 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntityPK.java

@@ -0,0 +1,84 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class HostComponentStateEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Id
+  @Column(name = "host_name")
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName;
+
+  @Id
+  @Column(name = "component_name")
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostComponentStateEntityPK that = (HostComponentStateEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    return result;
+  }
+}

+ 331 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java

@@ -0,0 +1,331 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.List;
+
+@Table(name = "hosts", schema = "ambari", catalog = "")
+@Entity
+public class HostEntity {
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", insertable = false, updatable = false)
+  @Basic
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Column(name = "host_name", nullable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String ip;
+
+  @Column(name = "ip", unique = true, nullable = false)
+  @Basic
+  public String getIp() {
+    return ip;
+  }
+
+  public void setIp(String ip) {
+    this.ip = ip;
+  }
+
+  private Integer totalMem = 0;
+
+  @Column(name = "total_mem", nullable = false)
+  @Basic
+  public Integer getTotalMem() {
+    return totalMem;
+  }
+
+  public void setTotalMem(Integer totalMem) {
+    this.totalMem = totalMem;
+  }
+
+  private Integer cpuCount = 0;
+
+  @Column(name = "cpu_count", nullable = false)
+  @Basic
+  public Integer getCpuCount() {
+    return cpuCount;
+  }
+
+  public void setCpuCount(Integer cpuCount) {
+    this.cpuCount = cpuCount;
+  }
+
+  private String cpuInfo = "";
+
+  @Column(name = "cpu_info", nullable = false)
+  @Basic
+  public String getCpuInfo() {
+    return cpuInfo;
+  }
+
+  public void setCpuInfo(String cpuInfo) {
+    this.cpuInfo = cpuInfo;
+  }
+
+  private String osArch = "";
+
+  @Column(name = "os_arch", nullable = false)
+  @Basic
+  public String getOsArch() {
+    return osArch;
+  }
+
+  public void setOsArch(String osArch) {
+    this.osArch = osArch;
+  }
+
+  private String disksInfo = "";
+
+  @Column(name = "disks_info", nullable = false)
+  @Basic
+  public String getDisksInfo() {
+    return disksInfo;
+  }
+
+  public void setDisksInfo(String disksInfo) {
+    this.disksInfo = disksInfo;
+  }
+
+  private String osInfo = "";
+
+  @Column(name = "os_info", nullable = false)
+  @Basic
+  public String getOsInfo() {
+    return osInfo;
+  }
+
+  public void setOsInfo(String osInfo) {
+    this.osInfo = osInfo;
+  }
+
+  private String osType = "";
+
+  @Column(name = "os_type", nullable = false)
+  @Basic
+  public String getOsType() {
+    return osType;
+  }
+
+  public void setOsType(String osType) {
+    this.osType = osType;
+  }
+
+  private String discoveryStatus = "";
+
+  @Column(name = "discovery_status", nullable = false)
+  @Basic
+  public String getDiscoveryStatus() {
+    return discoveryStatus;
+  }
+
+  public void setDiscoveryStatus(String discoveryStatus) {
+    this.discoveryStatus = discoveryStatus;
+  }
+
+  private Integer lastRegistrationTime = 0;
+
+  @Column(name = "last_registration_time", nullable = false)
+  @Basic
+  public Integer getLastRegistrationTime() {
+    return lastRegistrationTime;
+  }
+
+  public void setLastRegistrationTime(Integer lastRegistrationTime) {
+    this.lastRegistrationTime = lastRegistrationTime;
+  }
+
+  private String rackInfo = "/default-rack";
+
+  @Column(name = "rack_info", nullable = false)
+  @Basic
+  public String getRackInfo() {
+    return rackInfo;
+  }
+
+  public void setRackInfo(String rackInfo) {
+    this.rackInfo = rackInfo;
+  }
+
+  private String hostAttributes = "";
+
+  @Column(name = "host_attributes", nullable = false)
+  @Basic
+  public String getHostAttributes() {
+    return hostAttributes;
+  }
+
+  public void setHostAttributes(String hostAttributes) {
+    this.hostAttributes = hostAttributes;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private HostStateEntity hostStateEntity;
+
+  @OneToOne(cascade = CascadeType.ALL, mappedBy = "hostEntity")
+  public HostStateEntity getHostStateEntity() {
+    return hostStateEntity;
+  }
+
+  public void setHostStateEntity(HostStateEntity hostStateEntity) {
+    this.hostStateEntity = hostStateEntity;
+  }
+
+  private List<ActionStatusEntity> actionStatusEntity;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<ActionStatusEntity> getActionStatusEntity() {
+    return actionStatusEntity;
+  }
+
+  public void setActionStatusEntity(List<ActionStatusEntity> actionStatusEntity) {
+    this.actionStatusEntity = actionStatusEntity;
+  }
+
+  private List<ServiceComponentHostConfigEntity> serviceComponentHostConfigEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<ServiceComponentHostConfigEntity> getServiceComponentHostConfigEntities() {
+    return serviceComponentHostConfigEntities;
+  }
+
+  public void setServiceComponentHostConfigEntities(List<ServiceComponentHostConfigEntity> serviceComponentHostConfigEntities) {
+    this.serviceComponentHostConfigEntities = serviceComponentHostConfigEntities;
+  }
+
+  private List<ComponentHostDesiredStateEntity> componentHostDesiredStateEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<ComponentHostDesiredStateEntity> getComponentHostDesiredStateEntities() {
+    return componentHostDesiredStateEntities;
+  }
+
+  public void setComponentHostDesiredStateEntities(List<ComponentHostDesiredStateEntity> componentHostDesiredStateEntities) {
+    this.componentHostDesiredStateEntities = componentHostDesiredStateEntities;
+  }
+
+  private List<HostComponentStateEntity> hostComponentStateEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<HostComponentStateEntity> getHostComponentStateEntities() {
+    return hostComponentStateEntities;
+  }
+
+  public void setHostComponentStateEntities(List<HostComponentStateEntity> hostComponentStateEntities) {
+    this.hostComponentStateEntities = hostComponentStateEntities;
+  }
+
+  private List<ServiceStateEntity> serviceStateEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<ServiceStateEntity> getServiceStateEntities() {
+    return serviceStateEntities;
+  }
+
+  public void setServiceStateEntities(List<ServiceStateEntity> serviceStateEntities) {
+    this.serviceStateEntities = serviceStateEntities;
+  }
+
+  private List<ServiceComponentStateEntity> serviceComponentStateEntities;
+
+  @OneToMany(mappedBy = "hostEntity")
+  public List<ServiceComponentStateEntity> getServiceComponentStateEntities() {
+    return serviceComponentStateEntities;
+  }
+
+  public void setServiceComponentStateEntities(List<ServiceComponentStateEntity> serviceComponentStateEntities) {
+    this.serviceComponentStateEntities = serviceComponentStateEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostEntity that = (HostEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (cpuCount != null ? !cpuCount.equals(that.cpuCount) : that.cpuCount != null) return false;
+    if (cpuInfo != null ? !cpuInfo.equals(that.cpuInfo) : that.cpuInfo != null) return false;
+    if (discoveryStatus != null ? !discoveryStatus.equals(that.discoveryStatus) : that.discoveryStatus != null)
+      return false;
+    if (disksInfo != null ? !disksInfo.equals(that.disksInfo) : that.disksInfo != null) return false;
+    if (hostAttributes != null ? !hostAttributes.equals(that.hostAttributes) : that.hostAttributes != null)
+      return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (ip != null ? !ip.equals(that.ip) : that.ip != null) return false;
+    if (lastRegistrationTime != null ? !lastRegistrationTime.equals(that.lastRegistrationTime) : that.lastRegistrationTime != null)
+      return false;
+    if (osArch != null ? !osArch.equals(that.osArch) : that.osArch != null) return false;
+    if (osInfo != null ? !osInfo.equals(that.osInfo) : that.osInfo != null) return false;
+    if (osType != null ? !osType.equals(that.osType) : that.osType != null) return false;
+    if (rackInfo != null ? !rackInfo.equals(that.rackInfo) : that.rackInfo != null) return false;
+    if (totalMem != null ? !totalMem.equals(that.totalMem) : that.totalMem != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (ip != null ? ip.hashCode() : 0);
+    result = 31 * result + (totalMem != null ? totalMem.hashCode() : 0);
+    result = 31 * result + (cpuCount != null ? cpuCount.hashCode() : 0);
+    result = 31 * result + (cpuInfo != null ? cpuInfo.hashCode() : 0);
+    result = 31 * result + (osArch != null ? osArch.hashCode() : 0);
+    result = 31 * result + (disksInfo != null ? disksInfo.hashCode() : 0);
+    result = 31 * result + (osInfo != null ? osInfo.hashCode() : 0);
+    result = 31 * result + (osType != null ? osType.hashCode() : 0);
+    result = 31 * result + (discoveryStatus != null ? discoveryStatus.hashCode() : 0);
+    result = 31 * result + (lastRegistrationTime != null ? lastRegistrationTime.hashCode() : 0);
+    result = 31 * result + (rackInfo != null ? rackInfo.hashCode() : 0);
+    result = 31 * result + (hostAttributes != null ? hostAttributes.hashCode() : 0);
+    return result;
+  }
+}

+ 137 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java

@@ -0,0 +1,137 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@Table(name = "hoststate", schema = "ambari", catalog = "")
+@Entity
+public class HostStateEntity {
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", insertable = false, updatable = false)
+  @Basic
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Column(name = "host_name", insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private Integer lastHeartbeatTime = 0;
+
+  @Column(name = "last_heartbeat_time")
+  @Basic
+  public Integer getLastHeartbeatTime() {
+    return lastHeartbeatTime;
+  }
+
+  public void setLastHeartbeatTime(Integer lastHeartbeatTime) {
+    this.lastHeartbeatTime = lastHeartbeatTime;
+  }
+
+  private String agentVersion = "";
+
+  @Column(name = "agent_version")
+  @Basic
+  public String getAgentVersion() {
+    return agentVersion;
+  }
+
+  public void setAgentVersion(String agentVersion) {
+    this.agentVersion = agentVersion;
+  }
+
+  private String currentState;
+
+  @Column(name = "current_state")
+  @Basic
+  public String getCurrentState() {
+    return currentState;
+  }
+
+  public void setCurrentState(String currentState) {
+    this.currentState = currentState;
+  }
+
+  private HostEntity hostEntity;
+
+  @OneToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    HostStateEntity that = (HostStateEntity) o;
+
+    if (agentVersion != null ? !agentVersion.equals(that.agentVersion) : that.agentVersion != null) return false;
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (lastHeartbeatTime != null ? !lastHeartbeatTime.equals(that.lastHeartbeatTime) : that.lastHeartbeatTime != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (lastHeartbeatTime != null ? lastHeartbeatTime.hashCode() : 0);
+    result = 31 * result + (agentVersion != null ? agentVersion.hashCode() : 0);
+    result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
+    return result;
+  }
+}

+ 139 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentConfigEntity.java

@@ -0,0 +1,139 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Table(name = "servicecomponentconfig", schema = "ambari", catalog = "")
+@Entity
+public class ServiceComponentConfigEntity {
+
+  private Integer configVersion;
+
+  @Column(name = "config_version")
+  @Id
+  @GeneratedValue(strategy = GenerationType.AUTO)
+  public Integer getConfigVersion() {
+    return configVersion;
+  }
+
+  public void setConfigVersion(Integer configVersion) {
+    this.configVersion = configVersion;
+  }
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private String componentName;
+
+  @Column(name = "component_name", nullable = false)
+  @Basic
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  private String configSnapshot= "";
+
+  @Column(name = "config_snapshot", nullable = false)
+  @Basic
+  public String getConfigSnapshot() {
+    return configSnapshot;
+  }
+
+  public void setConfigSnapshot(String configSnapshot) {
+    this.configSnapshot = configSnapshot;
+  }
+
+  private Date configSnapshotTime;
+
+  @Column(name = "config_snapshot_time", nullable = false)
+  @Temporal(TemporalType.TIMESTAMP)
+  public Date getConfigSnapshotTime() {
+    return configSnapshotTime;
+  }
+
+  public void setConfigSnapshotTime(Date configSnapshotTime) {
+    this.configSnapshotTime = configSnapshotTime;
+  }
+
+  ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceComponentConfigEntity that = (ServiceComponentConfigEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (configSnapshot != null ? !configSnapshot.equals(that.configSnapshot) : that.configSnapshot != null)
+      return false;
+    if (configVersion != null ? !configVersion.equals(that.configVersion) : that.configVersion != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = configVersion != null ? configVersion.hashCode() : 0;
+    result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    result = 31 * result + (configSnapshot != null ? configSnapshot.hashCode() : 0);
+    return result;
+  }
+}

+ 165 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentHostConfigEntity.java

@@ -0,0 +1,165 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Table(name = "servicecomponenthostconfig", schema = "ambari", catalog = "")
+@Entity
+public class ServiceComponentHostConfigEntity {
+
+  private Integer configVersion;
+
+  @Column(name = "config_version")
+  @Id
+  @GeneratedValue(strategy = GenerationType.AUTO)
+  public Integer getConfigVersion() {
+    return configVersion;
+  }
+
+  public void setConfigVersion(Integer configVersion) {
+    this.configVersion = configVersion;
+  }
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private String componentName;
+
+  @Column(name = "component_name", nullable = false)
+  @Basic
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  private String hostName;
+
+  @Column(name = "host_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String configSnapshot = "";
+
+  @Column(name = "config_snapshot", nullable = false)
+  @Basic
+  public String getConfigSnapshot() {
+    return configSnapshot;
+  }
+
+  public void setConfigSnapshot(String configSnapshot) {
+    this.configSnapshot = configSnapshot;
+  }
+
+  private Date configSnapshotTime;
+
+  @Column(name = "config_snapshot_time", nullable = false)
+  @Temporal(TemporalType.TIMESTAMP)
+  public Date getConfigSnapshotTime() {
+    return configSnapshotTime;
+  }
+
+  public void setConfigSnapshotTime(Date configSnapshotTime) {
+    this.configSnapshotTime = configSnapshotTime;
+  }
+
+  private ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceComponentHostConfigEntity that = (ServiceComponentHostConfigEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (configSnapshot != null ? !configSnapshot.equals(that.configSnapshot) : that.configSnapshot != null)
+      return false;
+    if (configVersion != null ? !configVersion.equals(that.configVersion) : that.configVersion != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = configVersion != null ? configVersion.hashCode() : 0;
+    result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (configSnapshot != null ? configSnapshot.hashCode() : 0);
+    return result;
+  }
+}

+ 123 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentStateEntity.java

@@ -0,0 +1,123 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.IdClass(ServiceComponentStateEntityPK.class)
+@javax.persistence.Table(name = "servicecomponentstate", schema = "ambari", catalog = "")
+@Entity
+public class ServiceComponentStateEntity {
+
+  private String clusterName;
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @javax.persistence.Column(name = "host_name", insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName;
+
+  @javax.persistence.Column(name = "component_name")
+  @Id
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  private String currentState;
+
+  @javax.persistence.Column(name = "current_state")
+  @Basic
+  public String getCurrentState() {
+    return currentState;
+  }
+
+  public void setCurrentState(String currentState) {
+    this.currentState = currentState;
+  }
+
+  private ClusterEntity clusterEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "cluster_name")
+  public ClusterEntity getClusterEntity() {
+    return clusterEntity;
+  }
+
+  public void setClusterEntity(ClusterEntity clusterEntity) {
+    this.clusterEntity = clusterEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceComponentStateEntity that = (ServiceComponentStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
+    return result;
+  }
+}

+ 84 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentStateEntityPK.java

@@ -0,0 +1,84 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ServiceComponentStateEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Id
+  @Column(name = "host_name")
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String componentName;
+
+  @Id
+  @Column(name = "component_name")
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceComponentStateEntityPK that = (ServiceComponentStateEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (componentName != null ? !componentName.equals(that.componentName) : that.componentName != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 0);
+    return result;
+  }
+}

+ 125 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceConfigEntity.java

@@ -0,0 +1,125 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+import java.util.Date;
+
+@Table(name = "serviceconfig", schema = "ambari", catalog = "")
+@Entity
+public class ServiceConfigEntity {
+
+  private Integer configVersion;
+
+  @Column(name = "config_version")
+  @Id
+  @GeneratedValue(strategy = GenerationType.AUTO)
+  public Integer getConfigVersion() {
+    return configVersion;
+  }
+
+  public void setConfigVersion(Integer configVersion) {
+    this.configVersion = configVersion;
+  }
+
+  private String clusterName;
+
+  @Column(name = "cluster_name", nullable = false, insertable = false, updatable = false)
+  @Basic
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Column(name = "service_name", nullable = false, insertable = false,updatable = false)
+  @Basic
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private String configSnapshot = "";
+
+  @Column(name = "config_snapshot", nullable = false)
+  @Basic
+  public String getConfigSnapshot() {
+    return configSnapshot;
+  }
+
+  public void setConfigSnapshot(String configSnapshot) {
+    this.configSnapshot = configSnapshot;
+  }
+
+  private Date configSnapshotTime;
+
+  @Column(name = "config_snapshot_time", nullable = false)
+  @Temporal(TemporalType.TIMESTAMP)
+  public Date getConfigSnapshotTime() {
+    return configSnapshotTime;
+  }
+
+  public void setConfigSnapshotTime(Date configSnapshotTime) {
+    this.configSnapshotTime = configSnapshotTime;
+  }
+
+  ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceConfigEntity that = (ServiceConfigEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (configSnapshot != null ? !configSnapshot.equals(that.configSnapshot) : that.configSnapshot != null)
+      return false;
+    if (configVersion != null ? !configVersion.equals(that.configVersion) : that.configVersion != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = configVersion != null ? configVersion.hashCode() : 0;
+    result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (configSnapshot != null ? configSnapshot.hashCode() : 0);
+    return result;
+  }
+}

+ 98 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java

@@ -0,0 +1,98 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.IdClass(ServiceDesiredStateEntityPK.class)
+@javax.persistence.Table(name = "servicedesiredstate", schema = "ambari", catalog = "")
+@Entity
+public class ServiceDesiredStateEntity {
+
+  private String clusterName = "";
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName = "";
+
+  @javax.persistence.Column(name = "service_name", nullable = false, insertable = false, updatable = false)
+  @Id
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private Integer desiredHostRoleMapping = 0;
+
+  @javax.persistence.Column(name = "desired_host_role_mapping", nullable = false)
+  @Basic
+  public Integer getDesiredHostRoleMapping() {
+    return desiredHostRoleMapping;
+  }
+
+  public void setDesiredHostRoleMapping(Integer desiredHostRoleMapping) {
+    this.desiredHostRoleMapping = desiredHostRoleMapping;
+  }
+
+  ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceDesiredStateEntity that = (ServiceDesiredStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (desiredHostRoleMapping != null ? !desiredHostRoleMapping.equals(that.desiredHostRoleMapping) : that.desiredHostRoleMapping != null)
+      return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (desiredHostRoleMapping != null ? desiredHostRoleMapping.hashCode() : 0);
+    return result;
+  }
+}

+ 70 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java

@@ -0,0 +1,70 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ServiceDesiredStateEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String serviceName;
+
+  @Id
+  @Column(name = "service_name")
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceDesiredStateEntityPK that = (ServiceDesiredStateEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    return result;
+  }
+}

+ 123 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceStateEntity.java

@@ -0,0 +1,123 @@
+/**
+ * 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.entities;
+
+import javax.persistence.*;
+
+@javax.persistence.IdClass(ServiceStateEntityPK.class)
+@javax.persistence.Table(name = "servicestate", schema = "ambari", catalog = "")
+@Entity
+public class ServiceStateEntity {
+
+  private String clusterName;
+
+  @javax.persistence.Column(name = "cluster_name", insertable = false, updatable = false)
+  @Id
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @javax.persistence.Column(name = "host_name", insertable = false, updatable = false)
+  @Id
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String serviceName;
+
+  @javax.persistence.Column(name = "service_name", insertable = false, updatable = false)
+  @Id
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  private String currentState;
+
+  @javax.persistence.Column(name = "current_state")
+  @Basic
+  public String getCurrentState() {
+    return currentState;
+  }
+
+  public void setCurrentState(String currentState) {
+    this.currentState = currentState;
+  }
+
+  ClusterServiceEntity clusterServiceEntity;
+
+  @ManyToOne
+  @JoinColumns(value = {@JoinColumn(name = "cluster_name", referencedColumnName = "cluster_name"), @JoinColumn(name = "service_name", referencedColumnName = "service_name")})
+  public ClusterServiceEntity getClusterServiceEntity() {
+    return clusterServiceEntity;
+  }
+
+  public void setClusterServiceEntity(ClusterServiceEntity clusterServiceEntity) {
+    this.clusterServiceEntity = clusterServiceEntity;
+  }
+
+  private HostEntity hostEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "host_name")
+  public HostEntity getHostEntity() {
+    return hostEntity;
+  }
+
+  public void setHostEntity(HostEntity hostEntity) {
+    this.hostEntity = hostEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceStateEntity that = (ServiceStateEntity) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (currentState != null ? !currentState.equals(that.currentState) : that.currentState != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
+    return result;
+  }
+}

+ 84 - 0
ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceStateEntityPK.java

@@ -0,0 +1,84 @@
+/**
+ * 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.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+public class ServiceStateEntityPK implements Serializable {
+
+  private String clusterName;
+
+  @Id
+  @Column(name = "cluster_name")
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  private String hostName;
+
+  @Id
+  @Column(name = "host_name")
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  private String serviceName;
+
+  @Id
+  @Column(name = "service_name")
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public void setServiceName(String serviceName) {
+    this.serviceName = serviceName;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    ServiceStateEntityPK that = (ServiceStateEntityPK) o;
+
+    if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
+    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return false;
+    if (serviceName != null ? !serviceName.equals(that.serviceName) : that.serviceName != null) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = clusterName != null ? clusterName.hashCode() : 0;
+    result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
+    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    return result;
+  }
+}

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

@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
+
+  <persistence-unit name="ambari-postgres">
+    <class>org.apache.ambari.server.orm.entities.ActionStatusEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ClusterEntity</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.ComponentHostDesiredStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.HostComponentStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.HostComponentMappingEntity</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.ServiceComponentConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceComponentHostConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceComponentStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceStateEntity</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.user" value="ambari-server"/>
+      <property name="javax.persistence.jdbc.password" value="bigdata"/>
+    </properties>
+  </persistence-unit>
+
+  <persistence-unit name="ambari-javadb">
+    <class>org.apache.ambari.server.orm.entities.ActionStatusEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ClusterEntity</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.ComponentHostDesiredStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.HostComponentStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.HostComponentMappingEntity</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.ServiceComponentConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceComponentHostConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceComponentStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceConfigEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity</class>
+    <class>org.apache.ambari.server.orm.entities.ServiceStateEntity</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="javax.persistence.jdbc.user" value="ambari-server"/>-->
+      <!--<property name="javax.persistence.jdbc.password" value="bigdata"/>-->
+    </properties>
+  </persistence-unit>
+
+
+</persistence>

+ 122 - 0
ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java

@@ -0,0 +1,122 @@
+/**
+ * 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;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.HostStateEntity;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class OrmTestHelper {
+
+  @Inject
+  EntityManager entityManager;
+  @Inject
+  Injector injector;
+
+  public EntityManager getEntityManager() {
+    return entityManager;
+  }
+
+  /**
+   * creates some test data
+    */
+  @Transactional
+  public void createDefaultData() {
+
+    ClusterEntity clusterEntity = new ClusterEntity();
+    clusterEntity.setClusterName("test_cluster1");
+    clusterEntity.setClusterInfo("test_cluster_info1");
+
+    HostEntity host1 = new HostEntity();
+    HostEntity host2 = new HostEntity();
+    HostEntity host3 = new HostEntity();
+
+    host1.setHostName("test_host1");
+    host2.setHostName("test_host2");
+    host3.setHostName("test_host3");
+    host1.setIp("192.168.0.1");
+    host2.setIp("192.168.0.2");
+    host3.setIp("192.168.0.3");
+
+    List<HostEntity> hostEntities = new ArrayList<HostEntity>();
+    hostEntities.add(host1);
+    hostEntities.add(host2);
+
+    clusterEntity.setHostEntities(hostEntities);
+
+    //both sides of relation should be set when modifying in runtime
+    host1.setClusterEntity(clusterEntity);
+    host2.setClusterEntity(clusterEntity);
+
+    HostStateEntity hostStateEntity1 = new HostStateEntity();
+    hostStateEntity1.setCurrentState("TEST_STATE1");
+    hostStateEntity1.setHostEntity(host1);
+    HostStateEntity hostStateEntity2 = new HostStateEntity();
+    hostStateEntity2.setCurrentState("TEST_STATE2");
+    hostStateEntity2.setHostEntity(host2);
+    host1.setHostStateEntity(hostStateEntity1);
+    host2.setHostStateEntity(hostStateEntity2);
+
+    ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity();
+    clusterServiceEntity.setServiceName("HDFS");
+    clusterServiceEntity.setClusterEntity(clusterEntity);
+    List<ClusterServiceEntity> clusterServiceEntities = new ArrayList<ClusterServiceEntity>();
+    clusterServiceEntities.add(clusterServiceEntity);
+    clusterEntity.setClusterServiceEntities(clusterServiceEntities);
+
+
+    entityManager.persist(host1);
+    entityManager.persist(host2);
+    entityManager.persist(clusterEntity);
+    entityManager.persist(hostStateEntity1);
+    entityManager.persist(hostStateEntity2);
+    entityManager.persist(clusterServiceEntity);
+
+  }
+
+  @Transactional
+  public void performTransactionMarkedForRollback() {
+    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
+    clusterDAO.removeByName("test_cluster1");
+    entityManager.getTransaction().setRollbackOnly();
+  }
+
+  public int getClusterSizeByHostName(String hostName) {
+
+    Query query = entityManager.createQuery(
+            "SELECT host2 from HostEntity host join host.clusterEntity cluster join cluster.hostEntities host2 where host.hostName=:hostName");
+    query.setParameter("hostName", hostName);
+
+    Collection hosts = query.getResultList();
+
+    return hosts.size();
+  }
+
+}

+ 188 - 0
ambari-server/src/test/java/org/apache/ambari/server/orm/TestOrmImpl.java

@@ -0,0 +1,188 @@
+/**
+ * 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;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.jpa.JpaPersistModule;
+import org.apache.ambari.server.orm.dao.ClusterDAO;
+import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
+import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
+import org.apache.ambari.server.orm.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
+import org.apache.ambari.server.orm.entities.ServiceConfigEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.persistence.EntityManager;
+import javax.persistence.RollbackException;
+import java.util.Date;
+import java.util.List;
+
+public class TestOrmImpl extends Assert {
+  private final static Log log = LogFactory.getLog(TestOrmImpl.class);
+
+  private static Injector injector;
+
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    injector = Guice.createInjector(new JpaPersistModule("ambari-javadb")); //used for injecting in-memory DB EntityManager
+//    injector = Guice.createInjector(new JpaPersistModule("ambari-postgres")); //for injecting
+    injector.getInstance(GuiceJpaInitializer.class); //needed by Guice-persist to work
+    injector.getInstance(OrmTestHelper.class).createDefaultData();
+  }
+
+  /**
+   * persistence provider is responsible for returning empty collection if relation doesn't exists
+   */
+  @Test
+  public void testEmptyPersistentCollection() {
+    String testClusterName = "test_cluster2";
+
+    ClusterEntity clusterEntity = new ClusterEntity();
+    clusterEntity.setClusterName(testClusterName);
+    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
+    clusterDAO.create(clusterEntity);
+    clusterEntity = clusterDAO.findByName(clusterEntity.getClusterName());
+
+    assertTrue("empty relation wasn't instantiated", clusterEntity.getHostEntities() != null);
+  }
+
+  /**
+   * Transaction marked for rollback should not be allowed for commit
+   * @throws Throwable
+   */
+  @Test(expected = RollbackException.class)
+  public void testRollbackException() throws Throwable{
+    injector.getInstance(OrmTestHelper.class).performTransactionMarkedForRollback();
+  }
+
+  /**
+   * Rollback test
+   */
+  @Test
+  public void testSafeRollback() {
+    String testClusterName = "don't save";
+
+    EntityManager entityManager = injector.getInstance(OrmTestHelper.class).getEntityManager();
+    entityManager.getTransaction().begin();
+    ClusterEntity clusterEntity = new ClusterEntity();
+    clusterEntity.setClusterName(testClusterName);
+    entityManager.persist(clusterEntity);
+    entityManager.getTransaction().rollback();
+
+    assertNull("transaction was not rolled back", entityManager.find(ClusterEntity.class, testClusterName));
+  }
+
+  /**
+   * Test auto incremented field and custom query example
+   */
+  @Test
+  public void testAutoIncrementedField() {
+    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
+    ServiceConfigDAO serviceConfigDAO = injector.getInstance(ServiceConfigDAO.class);
+    Date currentTime = new Date();
+    String serviceName = "MapReduce1";
+    String clusterName = "test_cluster1";
+
+    createServiceAndConfig(currentTime, serviceName, clusterName);
+
+
+
+    List<ServiceConfigEntity> result = serviceConfigDAO.findAll();
+    assertNotNull("inserted config not found", result);
+    assertFalse(result.isEmpty());
+    ClusterServiceEntity clusterServiceEntity = clusterServiceDAO.findByClusterAndServiceNames(clusterName, serviceName);
+
+    result = serviceConfigDAO.findByClusterService(clusterServiceEntity);
+
+    assertNotNull("config by ClusterService not found", result);
+    assertEquals("wrong number of configs", 1, result.size());
+
+    ServiceConfigEntity serviceConfigEntity = result.iterator().next();
+
+    log.info("config version = " + serviceConfigEntity.getConfigVersion());
+    assertNotNull("config version is null", serviceConfigEntity.getConfigVersion());
+
+    serviceConfigDAO.remove(serviceConfigEntity);
+
+    result = serviceConfigDAO.findAll();
+
+
+    assertTrue(result.isEmpty());
+
+    clusterServiceDAO.remove(clusterServiceEntity);
+
+    assertNull(clusterServiceDAO
+            .findByClusterAndServiceNames(clusterName, serviceName));
+
+  }
+
+  private void createServiceAndConfig(Date currentTime, String serviceName, String clusterName) {
+    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
+    ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
+    ClusterEntity cluster = clusterDAO.findByName(clusterName);
+
+    ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity();
+    clusterServiceEntity.setClusterEntity(cluster);
+    clusterServiceEntity.setServiceName(serviceName);
+
+    cluster.getClusterServiceEntities().add(clusterServiceEntity);
+
+    clusterServiceDAO.create(clusterServiceEntity);
+    clusterDAO.merge(cluster);
+
+    clusterServiceEntity = clusterServiceDAO
+            .findByClusterAndServiceNames(clusterName, serviceName);
+    assertNotNull(clusterServiceEntity);
+
+    ServiceConfigEntity serviceConfigEntity = new ServiceConfigEntity();
+    serviceConfigEntity.setConfigSnapshotTime(currentTime);
+    serviceConfigEntity.setClusterServiceEntity(clusterServiceEntity);
+
+    List<ServiceConfigEntity> list = clusterServiceEntity.getServiceConfigEntities();
+    list.add(serviceConfigEntity);
+    clusterServiceEntity.setServiceConfigEntities(list);
+
+    ServiceConfigDAO serviceConfigDAO = injector.getInstance(ServiceConfigDAO.class);
+
+    serviceConfigDAO.create(serviceConfigEntity);
+    clusterServiceDAO.merge(clusterServiceEntity);
+  }
+
+  /**
+   * to clarify: are cascade operations allowed?
+   */
+  @Test(expected = RollbackException.class)
+  public void testCascadeRemoveFail() {
+    ClusterServiceDAO clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class);
+    Date currentTime = new Date();
+    String serviceName = "MapReduce2";
+    String clusterName = "test_cluster1";
+
+    createServiceAndConfig(currentTime, serviceName, clusterName);
+
+    ClusterServiceEntity clusterServiceEntity = clusterServiceDAO.findByClusterAndServiceNames(clusterName, serviceName);
+    clusterServiceDAO.remove(clusterServiceEntity);
+  }
+
+}