AMBARI-10889. Create data access layer for new Ambari Topology Manager state. 
(swagle)


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

Branch: refs/heads/trunk
Commit: 89711d74312553a8f6f16f745d7542b40081c5d1
Parents: 77e4d50
Author: Siddharth Wagle <swa...@hortonworks.com>
Authored: Fri May 1 12:59:13 2015 -0700
Committer: Siddharth Wagle <swa...@hortonworks.com>
Committed: Fri May 1 13:00:57 2015 -0700

----------------------------------------------------------------------
 .../server/orm/dao/TopologyHostGroupDAO.java    |  62 +++++++
 .../server/orm/dao/TopologyHostRequestDAO.java  |  62 +++++++
 .../orm/dao/TopologyLogicalRequestDAO.java      |  61 +++++++
 .../server/orm/dao/TopologyRequestDAO.java      |  76 +++++++++
 .../orm/entities/HostRoleCommandEntity.java     |  11 ++
 .../orm/entities/TopologyHostGroupEntity.java   | 128 ++++++++++++++
 .../orm/entities/TopologyHostInfoEntity.java    | 114 +++++++++++++
 .../orm/entities/TopologyHostRequestEntity.java | 133 +++++++++++++++
 .../orm/entities/TopologyHostTaskEntity.java    | 107 ++++++++++++
 .../entities/TopologyLogicalRequestEntity.java  | 114 +++++++++++++
 .../orm/entities/TopologyLogicalTaskEntity.java | 109 ++++++++++++
 .../orm/entities/TopologyRequestEntity.java     | 167 +++++++++++++++++++
 .../server/upgrade/UpgradeCatalog210.java       |  98 ++++++++++-
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  76 +++++++++
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  76 +++++++++
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  84 +++++++++-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  91 +++++++++-
 .../src/main/resources/META-INF/persistence.xml |   7 +
 .../apache/ambari/server/orm/OrmTestHelper.java |   4 +-
 .../orm/dao/TopologyLogicalRequestDAOTest.java  | 155 +++++++++++++++++
 .../server/orm/dao/TopologyRequestDAOTest.java  | 119 +++++++++++++
 21 files changed, 1847 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostGroupDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostGroupDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostGroupDAO.java
new file mode 100644
index 0000000..a11ec33
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostGroupDAO.java
@@ -0,0 +1,62 @@
+/**
+ * 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.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.TopologyHostGroupEntity;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+
+@Singleton
+public class TopologyHostGroupDAO {
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  DaoUtils daoUtils;
+
+  @RequiresSession
+  public TopologyHostGroupEntity findById(Long id) {
+    return entityManagerProvider.get().find(TopologyHostGroupEntity.class, id);
+  }
+
+  @RequiresSession
+  public List<TopologyHostGroupEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), 
TopologyHostGroupEntity.class);
+  }
+
+  @Transactional
+  public void create(TopologyHostGroupEntity hostGroupEntity) {
+    entityManagerProvider.get().persist(hostGroupEntity);
+  }
+
+  @Transactional
+  public TopologyHostGroupEntity merge(TopologyHostGroupEntity 
hostGroupEntity) {
+    return entityManagerProvider.get().merge(hostGroupEntity);
+  }
+
+  @Transactional
+  public void remove(TopologyHostGroupEntity hostGroupEntity) {
+    entityManagerProvider.get().remove(hostGroupEntity);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostRequestDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostRequestDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostRequestDAO.java
new file mode 100644
index 0000000..216e6f9
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyHostRequestDAO.java
@@ -0,0 +1,62 @@
+/**
+ * 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.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.TopologyHostRequestEntity;
+
+import javax.persistence.EntityManager;
+import java.util.List;
+
+@Singleton
+public class TopologyHostRequestDAO {
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  DaoUtils daoUtils;
+
+  @RequiresSession
+  public TopologyHostRequestEntity findById(Long id) {
+    return entityManagerProvider.get().find(TopologyHostRequestEntity.class, 
id);
+  }
+
+  @RequiresSession
+  public List<TopologyHostRequestEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), 
TopologyHostRequestEntity.class);
+  }
+
+  @Transactional
+  public void create(TopologyHostRequestEntity requestEntity) {
+    entityManagerProvider.get().persist(requestEntity);
+  }
+
+  @Transactional
+  public TopologyHostRequestEntity merge(TopologyHostRequestEntity 
requestEntity) {
+    return entityManagerProvider.get().merge(requestEntity);
+  }
+
+  @Transactional
+  public void remove(TopologyHostRequestEntity requestEntity) {
+    entityManagerProvider.get().remove(requestEntity);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAO.java
new file mode 100644
index 0000000..e6dcb69
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAO.java
@@ -0,0 +1,61 @@
+/**
+ * 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.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.TopologyLogicalRequestEntity;
+import javax.persistence.EntityManager;
+import java.util.List;
+
+@Singleton
+public class TopologyLogicalRequestDAO {
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  DaoUtils daoUtils;
+
+  @RequiresSession
+  public TopologyLogicalRequestEntity findById(Long id) {
+    return 
entityManagerProvider.get().find(TopologyLogicalRequestEntity.class, id);
+  }
+
+  @RequiresSession
+  public List<TopologyLogicalRequestEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), 
TopologyLogicalRequestEntity.class);
+  }
+
+  @Transactional
+  public void create(TopologyLogicalRequestEntity requestEntity) {
+    entityManagerProvider.get().persist(requestEntity);
+  }
+
+  @Transactional
+  public TopologyLogicalRequestEntity merge(TopologyLogicalRequestEntity 
requestEntity) {
+    return entityManagerProvider.get().merge(requestEntity);
+  }
+
+  @Transactional
+  public void remove(TopologyLogicalRequestEntity requestEntity) {
+    entityManagerProvider.get().remove(requestEntity);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
new file mode 100644
index 0000000..b58129d
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
@@ -0,0 +1,76 @@
+/**
+ * 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.Provider;
+import com.google.inject.Singleton;
+import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.orm.RequiresSession;
+import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
+import javax.persistence.EntityManager;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+@Singleton
+public class TopologyRequestDAO {
+  @Inject
+  Provider<EntityManager> entityManagerProvider;
+
+  @Inject
+  DaoUtils daoUtils;
+
+  @RequiresSession
+  public TopologyRequestEntity findById(Long id) {
+    return entityManagerProvider.get().find(TopologyRequestEntity.class, id);
+  }
+
+  @RequiresSession
+  public List<TopologyRequestEntity> findByCluster(String clusterName) {
+    TypedQuery<TopologyRequestEntity> query = entityManagerProvider.get()
+      .createNamedQuery("TopologyRequestEntity.findByCluster", 
TopologyRequestEntity.class);
+
+    query.setParameter("clusterName", clusterName);
+    return daoUtils.selectList(query);
+  }
+
+  @RequiresSession
+  public List<TopologyRequestEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), 
TopologyRequestEntity.class);
+  }
+
+  @Transactional
+  public void create(TopologyRequestEntity requestEntity) {
+    entityManagerProvider.get().persist(requestEntity);
+  }
+
+  @Transactional
+  public TopologyRequestEntity merge(TopologyRequestEntity requestEntity) {
+    return entityManagerProvider.get().merge(requestEntity);
+  }
+
+  @Transactional
+  public void remove(TopologyRequestEntity requestEntity) {
+    entityManagerProvider.get().remove(requestEntity);
+  }
+
+  @Transactional
+  public void removeByPK(Long requestId) {
+    remove(findById(requestId));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
index 3919555..061f436 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
@@ -163,6 +163,9 @@ public class HostRoleCommandEntity {
   @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = 
false)
   private HostEntity hostEntity;
 
+  @OneToOne(mappedBy = "hostRoleCommandEntity", cascade = CascadeType.REMOVE)
+  private TopologyLogicalTaskEntity topologyLogicalTaskEntity;
+
   public Long getTaskId() {
     return taskId;
   }
@@ -446,4 +449,12 @@ public class HostRoleCommandEntity {
   public void setHostEntity(HostEntity hostEntity) {
     this.hostEntity = hostEntity;
   }
+
+  public TopologyLogicalTaskEntity getTopologyLogicalTaskEntity() {
+    return topologyLogicalTaskEntity;
+  }
+
+  public void setTopologyLogicalTaskEntity(TopologyLogicalTaskEntity 
topologyLogicalTaskEntity) {
+    this.topologyLogicalTaskEntity = topologyLogicalTaskEntity;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
new file mode 100644
index 0000000..3448b65
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostGroupEntity.java
@@ -0,0 +1,128 @@
+/**
+ * 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.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.Lob;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import java.util.Collection;
+
+@Entity
+@Table(name = "topology_hostgroup")
+public class TopologyHostGroupEntity {
+  @Id
+  @Column(name = "name", length = 255, nullable = false)
+  private String name;
+
+  @Column(name = "group_properties")
+  @Basic(fetch = FetchType.LAZY)
+  @Lob
+  private String groupProperties;
+
+  @Column(name = "group_attributes")
+  @Basic(fetch = FetchType.LAZY)
+  @Lob
+  private String groupAttributes;
+
+  @ManyToOne
+  @JoinColumn(name = "request_id", referencedColumnName = "id", nullable = 
false)
+  private TopologyRequestEntity topologyRequestEntity;
+
+  @OneToMany(mappedBy = "topologyHostGroupEntity", cascade = CascadeType.ALL)
+  private Collection<TopologyHostInfoEntity> topologyHostInfoEntities;
+
+  @OneToMany(mappedBy = "topologyHostGroupEntity", cascade = CascadeType.ALL)
+  private Collection<TopologyHostRequestEntity> topologyHostRequestEntities;
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getGroupProperties() {
+    return groupProperties;
+  }
+
+  public void setGroupProperties(String groupProperties) {
+    this.groupProperties = groupProperties;
+  }
+
+  public String getGroupAttributes() {
+    return groupAttributes;
+  }
+
+  public void setGroupAttributes(String groupAttributes) {
+    this.groupAttributes = groupAttributes;
+  }
+
+  public Long getRequestId() {
+    return topologyRequestEntity != null ? topologyRequestEntity.getId() : 
null;
+  }
+
+  public TopologyRequestEntity getTopologyRequestEntity() {
+    return topologyRequestEntity;
+  }
+
+  public void setTopologyRequestEntity(TopologyRequestEntity 
topologyRequestEntity) {
+    this.topologyRequestEntity = topologyRequestEntity;
+  }
+
+  public Collection<TopologyHostInfoEntity> getTopologyHostInfoEntities() {
+    return topologyHostInfoEntities;
+  }
+
+  public void setTopologyHostInfoEntities(Collection<TopologyHostInfoEntity> 
topologyHostInfoEntities) {
+    this.topologyHostInfoEntities = topologyHostInfoEntities;
+  }
+
+  public Collection<TopologyHostRequestEntity> 
getTopologyHostRequestEntities() {
+    return topologyHostRequestEntities;
+  }
+
+  public void 
setTopologyHostRequestEntities(Collection<TopologyHostRequestEntity> 
topologyHostRequestEntities) {
+    this.topologyHostRequestEntities = topologyHostRequestEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyHostGroupEntity that = (TopologyHostGroupEntity) o;
+
+    if (!name.equals(that.name)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return name.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.java
new file mode 100644
index 0000000..36c2782
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostInfoEntity.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.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+@Entity
+@Table(name = "topology_host_info")
+@TableGenerator(name = "topology_host_info_id_generator", table = 
"ambari_sequences",
+  pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+  pkColumnValue = "topology_host_info_id_seq", initialValue = 0)
+public class TopologyHostInfoEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_host_info_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "fqdn", length = 255)
+  private String fqdn;
+
+  @Column(name = "host_count", length = 10)
+  private Integer hostCount;
+
+  @Column(name = "predicate", length = 2048)
+  private String predicate;
+
+  @ManyToOne
+  @JoinColumn(name = "group_name", referencedColumnName = "name", nullable = 
false)
+  private TopologyHostGroupEntity topologyHostGroupEntity;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public String getGroupName() {
+    return topologyHostGroupEntity != null ? topologyHostGroupEntity.getName() 
: null;
+  }
+
+  public String getFqdn() {
+    return fqdn;
+  }
+
+  public void setFqdn(String fqdn) {
+    this.fqdn = fqdn;
+  }
+
+  public Integer getHostCount() {
+    return hostCount;
+  }
+
+  public void setHostCount(Integer hostCount) {
+    this.hostCount = hostCount;
+  }
+
+  public String getPredicate() {
+    return predicate;
+  }
+
+  public void setPredicate(String predicate) {
+    this.predicate = predicate;
+  }
+
+  public TopologyHostGroupEntity getTopologyHostGroupEntity() {
+    return topologyHostGroupEntity;
+  }
+
+  public void setTopologyHostGroupEntity(TopologyHostGroupEntity 
topologyHostGroupEntity) {
+    this.topologyHostGroupEntity = topologyHostGroupEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyHostInfoEntity that = (TopologyHostInfoEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostRequestEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostRequestEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostRequestEntity.java
new file mode 100644
index 0000000..2f42d80
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostRequestEntity.java
@@ -0,0 +1,133 @@
+/**
+ * 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.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import java.util.Collection;
+
+@Entity
+@Table(name = "topology_host_request")
+@TableGenerator(name = "topology_host_request_id_generator", table = 
"ambari_sequences",
+  pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+  pkColumnValue = "topology_host_request_id_seq", initialValue = 0)
+public class TopologyHostRequestEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_request_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "stage_id", length = 10, nullable = false)
+  private Long stageId;
+
+  @Column(name = "host_name", length = 255)
+  private String hostName;
+
+  @ManyToOne
+  @JoinColumn(name = "logical_request_id", referencedColumnName = "id", 
nullable = false)
+  private TopologyLogicalRequestEntity topologyLogicalRequestEntity;
+
+  @ManyToOne
+  @JoinColumn(name = "group_name", referencedColumnName = "name", nullable = 
false)
+  private TopologyHostGroupEntity topologyHostGroupEntity;
+
+  @OneToMany(mappedBy = "topologyHostRequestEntity", cascade = 
CascadeType.ALL, orphanRemoval = true)
+  private Collection<TopologyHostTaskEntity> topologyHostTaskEntities;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getLogicalRequestId() {
+    return topologyLogicalRequestEntity != null ? 
topologyLogicalRequestEntity.getTopologyRequestId() : null;
+  }
+
+  public String getHostGroupName() {
+    return topologyHostGroupEntity != null ? topologyHostGroupEntity.getName() 
: null;
+  }
+
+  public Long getStageId() {
+    return stageId;
+  }
+
+  public void setStageId(Long stageId) {
+    this.stageId = stageId;
+  }
+
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
+  public TopologyLogicalRequestEntity getTopologyLogicalRequestEntity() {
+    return topologyLogicalRequestEntity;
+  }
+
+  public void setTopologyLogicalRequestEntity(TopologyLogicalRequestEntity 
topologyLogicalRequestEntity) {
+    this.topologyLogicalRequestEntity = topologyLogicalRequestEntity;
+  }
+
+  public TopologyHostGroupEntity getTopologyHostGroupEntity() {
+    return topologyHostGroupEntity;
+  }
+
+  public void setTopologyHostGroupEntity(TopologyHostGroupEntity 
topologyHostGroupEntity) {
+    this.topologyHostGroupEntity = topologyHostGroupEntity;
+  }
+
+  public Collection<TopologyHostTaskEntity> getTopologyHostTaskEntities() {
+    return topologyHostTaskEntities;
+  }
+
+  public void setTopologyHostTaskEntities(Collection<TopologyHostTaskEntity> 
topologyHostTaskEntities) {
+    this.topologyHostTaskEntities = topologyHostTaskEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyHostRequestEntity that = (TopologyHostRequestEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostTaskEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostTaskEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostTaskEntity.java
new file mode 100644
index 0000000..2c31bb5
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyHostTaskEntity.java
@@ -0,0 +1,107 @@
+/**
+ * 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.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import java.util.Collection;
+
+@Entity
+@Table(name = "topology_host_task")
+@TableGenerator(name = "topology_host_task_id_generator", table = 
"ambari_sequences",
+  pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+  pkColumnValue = "topology_host_task_id_seq", initialValue = 0)
+public class TopologyHostTaskEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_host_task_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "type", length = 255, nullable = false)
+  private String type;
+
+  @ManyToOne
+  @JoinColumn(name = "host_request_id", referencedColumnName = "id", nullable 
= false)
+  private TopologyHostRequestEntity topologyHostRequestEntity;
+
+  @OneToMany(mappedBy = "topologyHostTaskEntity", cascade = CascadeType.ALL)
+  private Collection<TopologyLogicalTaskEntity> topologyLogicalTaskEntities;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getHostRequestId() {
+    return topologyHostRequestEntity != null ? 
topologyHostRequestEntity.getId() : null;
+  }
+
+  public String getType() {
+    return type;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+  public TopologyHostRequestEntity getTopologyHostRequestEntity() {
+    return topologyHostRequestEntity;
+  }
+
+  public void setTopologyHostRequestEntity(TopologyHostRequestEntity 
topologyHostRequestEntity) {
+    this.topologyHostRequestEntity = topologyHostRequestEntity;
+  }
+
+  public Collection<TopologyLogicalTaskEntity> 
getTopologyLogicalTaskEntities() {
+    return topologyLogicalTaskEntities;
+  }
+
+  public void 
setTopologyLogicalTaskEntities(Collection<TopologyLogicalTaskEntity> 
topologyLogicalTaskEntities) {
+    this.topologyLogicalTaskEntities = topologyLogicalTaskEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyHostTaskEntity that = (TopologyHostTaskEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalRequestEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalRequestEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalRequestEntity.java
new file mode 100644
index 0000000..023a058
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalRequestEntity.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.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import java.util.Collection;
+
+@Entity
+@Table(name = "topology_logical_request")
+@TableGenerator(name = "topology_logical_request_id_generator", table = 
"ambari_sequences",
+  pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+  pkColumnValue = "topology_logical_request_id_seq", initialValue = 0)
+public class TopologyLogicalRequestEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_logical_request_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "request_id", nullable = false, insertable = false, updatable 
= false, length = 10)
+  private Long topologyRequestId;
+
+  @Column(name = "description", length = 1024, nullable = false)
+  private String description;
+
+  @OneToOne
+  @JoinColumn(name = "request_id", referencedColumnName = "id", nullable = 
false)
+  private TopologyRequestEntity topologyRequestEntity;
+
+  @OneToMany(mappedBy = "topologyLogicalRequestEntity", cascade = 
CascadeType.ALL)
+  private Collection<TopologyHostRequestEntity> topologyHostRequestEntities;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getTopologyRequestId() {
+    return topologyRequestId;
+  }
+
+  public void setTopologyRequestId(Long topologyRequestId) {
+    this.topologyRequestId = topologyRequestId;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public TopologyRequestEntity getTopologyRequestEntity() {
+    return topologyRequestEntity;
+  }
+
+  public void setTopologyRequestEntity(TopologyRequestEntity 
topologyRequestEntity) {
+    this.topologyRequestEntity = topologyRequestEntity;
+  }
+
+  public Collection<TopologyHostRequestEntity> 
getTopologyHostRequestEntities() {
+    return topologyHostRequestEntities;
+  }
+
+  public void 
setTopologyHostRequestEntities(Collection<TopologyHostRequestEntity> 
topologyHostRequestEntities) {
+    this.topologyHostRequestEntities = topologyHostRequestEntities;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyLogicalRequestEntity that = (TopologyLogicalRequestEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalTaskEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalTaskEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalTaskEntity.java
new file mode 100644
index 0000000..c71d4e4
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyLogicalTaskEntity.java
@@ -0,0 +1,109 @@
+/**
+ * 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.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+@Entity
+@Table(name = "topology_logical_task")
+@TableGenerator(name = "topology_logical_task_id_generator", table = 
"ambari_sequences",
+  pkColumnName = "sequence_name", valueColumnName = "sequence_value",
+  pkColumnValue = "topology_logical_task_id_seq", initialValue = 0)
+public class TopologyLogicalTaskEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_logical_task_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "component", length = 255)
+  private String componentName;
+
+  @ManyToOne
+  @JoinColumn(name = "host_task_id", referencedColumnName = "id", nullable = 
false)
+  private TopologyHostTaskEntity topologyHostTaskEntity;
+
+  @OneToOne
+  @JoinColumn(name = "physical_task_id", referencedColumnName = "task_id")
+  private HostRoleCommandEntity hostRoleCommandEntity;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getHostTaskId() {
+    return topologyHostTaskEntity != null ? topologyHostTaskEntity.getId() : 
null;
+  }
+
+  public Long getPhysicalTaskId() {
+    return hostRoleCommandEntity != null ? hostRoleCommandEntity.getTaskId() : 
null;
+  }
+
+  public String getComponentName() {
+    return componentName;
+  }
+
+  public void setComponentName(String componentName) {
+    this.componentName = componentName;
+  }
+
+  public TopologyHostTaskEntity getTopologyHostTaskEntity() {
+    return topologyHostTaskEntity;
+  }
+
+  public void setTopologyHostTaskEntity(TopologyHostTaskEntity 
topologyHostTaskEntity) {
+    this.topologyHostTaskEntity = topologyHostTaskEntity;
+  }
+
+  public HostRoleCommandEntity getHostRoleCommandEntity() {
+    return hostRoleCommandEntity;
+  }
+
+  public void setHostRoleCommandEntity(HostRoleCommandEntity 
hostRoleCommandEntity) {
+    this.hostRoleCommandEntity = hostRoleCommandEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyLogicalTaskEntity that = (TopologyLogicalTaskEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
new file mode 100644
index 0000000..8535ed8
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
@@ -0,0 +1,167 @@
+/**
+ * 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.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import java.util.Collection;
+
+@Entity
+@Table(name = "topology_request")
+@TableGenerator(name = "topology_request_id_generator", table = 
"ambari_sequences",
+                pkColumnName = "sequence_name", valueColumnName = 
"sequence_value",
+                pkColumnValue = "topology_request_id_seq", initialValue = 0)
+@NamedQueries({
+  @NamedQuery(name = "TopologyRequestEntity.findByCluster", query = "SELECT 
req FROM TopologyRequestEntity req WHERE req.clusterName = :clusterName")
+})
+public class TopologyRequestEntity {
+  @Id
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"topology_request_id_generator")
+  @Column(name = "id", nullable = false, updatable = false)
+  private Long id;
+
+  @Column(name = "action", length = 255, nullable = false)
+  private String action;
+
+  @Column(name = "cluster_name", length = 100, nullable = false)
+  private String clusterName;
+
+  @Column(name = "bp_name", length = 100, nullable = false)
+  private String blueprintName;
+
+  @Column(name = "cluster_properties")
+  @Basic(fetch = FetchType.LAZY)
+  @Lob
+  private String clusterProperties;
+
+  @Column(name = "cluster_attributes")
+  @Basic(fetch = FetchType.LAZY)
+  @Lob
+  private String clusterAttributes;
+
+  @Column(name = "description", length = 1024, nullable = false)
+  private String description;
+
+  @OneToMany(mappedBy = "topologyRequestEntity", cascade = CascadeType.ALL)
+  private Collection<TopologyHostGroupEntity> topologyHostGroupEntities;
+
+  @OneToOne(mappedBy = "topologyRequestEntity", cascade = CascadeType.ALL)
+  private TopologyLogicalRequestEntity topologyLogicalRequestEntity;
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public String getAction() {
+    return action;
+  }
+
+  public void setAction(String action) {
+    this.action = action;
+  }
+
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  public String getBlueprintName() {
+    return blueprintName;
+  }
+
+  public void setBlueprintName(String blueprintName) {
+    this.blueprintName = blueprintName;
+  }
+
+  public String getClusterProperties() {
+    return clusterProperties;
+  }
+
+  public void setClusterProperties(String clusterProperties) {
+    this.clusterProperties = clusterProperties;
+  }
+
+  public String getClusterAttributes() {
+    return clusterAttributes;
+  }
+
+  public void setClusterAttributes(String clusterAttributes) {
+    this.clusterAttributes = clusterAttributes;
+  }
+
+  public String getDescription() {
+    return description;
+  }
+
+  public void setDescription(String description) {
+    this.description = description;
+  }
+
+  public Collection<TopologyHostGroupEntity> getTopologyHostGroupEntities() {
+    return topologyHostGroupEntities;
+  }
+
+  public void setTopologyHostGroupEntities(Collection<TopologyHostGroupEntity> 
topologyHostGroupEntities) {
+    this.topologyHostGroupEntities = topologyHostGroupEntities;
+  }
+
+  public TopologyLogicalRequestEntity getTopologyLogicalRequestEntity() {
+    return topologyLogicalRequestEntity;
+  }
+
+  public void setTopologyLogicalRequestEntity(TopologyLogicalRequestEntity 
topologyLogicalRequestEntity) {
+    this.topologyLogicalRequestEntity = topologyLogicalRequestEntity;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (o == null || getClass() != o.getClass()) return false;
+
+    TopologyRequestEntity that = (TopologyRequestEntity) o;
+
+    if (!id.equals(that.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
index f80b7ee..dc7f7a9 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
@@ -76,10 +76,16 @@ public class UpgradeCatalog210 extends 
AbstractUpgradeCatalog {
   private static final String STACK_TABLE = "stack";
   private static final String REPO_VERSION_TABLE = "repo_version";
   private static final String ALERT_HISTORY_TABLE = "alert_history";
-
   private static final String HOST_ID_COL = "host_id";
   private static final String HOST_NAME_COL = "host_name";
   private static final String PUBLIC_HOST_NAME_COL = "public_host_name";
+  private static final String TOPOLOGY_REQUEST_TABLE = "topology_request";
+  private static final String TOPOLOGY_HOST_GROUP_TABLE = "topology_hostgroup";
+  private static final String TOPOLOGY_HOST_INFO_TABLE = "topology_host_info";
+  private static final String TOPOLOGY_LOGICAL_REQUEST_TABLE = 
"topology_logical_request";
+  private static final String TOPOLOGY_HOST_REQUEST_TABLE = 
"topology_host_request";
+  private static final String TOPOLOGY_HOST_TASK_TABLE = "topology_host_task";
+  private static final String TOPOLOGY_LOGICAL_TASK_TABLE = 
"topology_logical_task";
 
   // constants for stack table changes
   private static final String STACK_ID_COLUMN_NAME = "stack_id";
@@ -144,6 +150,86 @@ public class UpgradeCatalog210 extends 
AbstractUpgradeCatalog {
     executeHostsDDLUpdates();
     executeWidgetDDLUpdates();
     executeStackDDLUpdates();
+    executeTopologyDDLUpdates();
+  }
+
+  private void executeTopologyDDLUpdates() throws AmbariException, 
SQLException {
+    List<DBColumnInfo> columns = new ArrayList<DBColumnInfo>();
+
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("action", String.class, 255, null, false));
+    columns.add(new DBColumnInfo("cluster_name", String.class, 100, null, 
false));
+    columns.add(new DBColumnInfo("bp_name", String.class, 100, null, false));
+    columns.add(new DBColumnInfo("cluster_properties", byte[].class, null, 
null, false));
+    columns.add(new DBColumnInfo("cluster_attributes", byte[].class, null, 
null, false));
+    columns.add(new DBColumnInfo("description", String.class, 1024, null, 
false));
+
+    dbAccessor.createTable(TOPOLOGY_REQUEST_TABLE, columns, "id");
+
+    columns.clear();
+    columns.add(new DBColumnInfo("name", String.class, 255, null, false));
+    columns.add(new DBColumnInfo("group_properties", byte[].class, null, null, 
false));
+    columns.add(new DBColumnInfo("group_attributes", byte[].class, null, null, 
false));
+    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
+
+    dbAccessor.createTable(TOPOLOGY_HOST_GROUP_TABLE, columns, "name");
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_GROUP_TABLE, 
"FK_hostgroup_req_id", "request_id", TOPOLOGY_REQUEST_TABLE, "id", true, false);
+
+    columns.clear();
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("group_name", String.class, 255, null, 
false));
+    columns.add(new DBColumnInfo("fqdn", String.class, 255, null, true));
+    columns.add(new DBColumnInfo("host_count", Integer.class, null, null, 
true));
+    columns.add(new DBColumnInfo("predicate", String.class, 2048, null, true));
+
+    dbAccessor.createTable(TOPOLOGY_HOST_INFO_TABLE, columns, "id");
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_INFO_TABLE, 
"FK_hostinfo_group_name", "group_name", TOPOLOGY_HOST_GROUP_TABLE, "name", 
true, false);
+
+    columns.clear();
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("request_id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("description", String.class, 1024, null, 
false));
+
+    dbAccessor.createTable(TOPOLOGY_LOGICAL_REQUEST_TABLE, columns, "id");
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_GROUP_TABLE, 
"FK_logicalreq_req_id", "request_id", TOPOLOGY_REQUEST_TABLE, "id", true, 
false);
+
+    columns.clear();
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("logical_request_id", Long.class, null, null, 
false));
+    columns.add(new DBColumnInfo("group_name", String.class, 255, null, 
false));
+    columns.add(new DBColumnInfo("stage_id", Integer.class, null, null, 
false));
+    columns.add(new DBColumnInfo("host_name", String.class, 255, null, true));
+
+    dbAccessor.createTable(TOPOLOGY_HOST_REQUEST_TABLE, columns, "id");
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_REQUEST_TABLE, 
"FK_hostreq_logicalreq_id", "logical_request_id", 
TOPOLOGY_LOGICAL_REQUEST_TABLE, "id", true, false);
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_REQUEST_TABLE, 
"FK_hostreq_group_name", "group_name", TOPOLOGY_HOST_GROUP_TABLE, "name", true, 
false);
+
+    columns.clear();
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("host_request_id", Long.class, null, null, 
false));
+    columns.add(new DBColumnInfo("logical_request_id", Long.class, null, null, 
false));
+    columns.add(new DBColumnInfo("type", String.class, 255, null, false));
+    dbAccessor.createTable(TOPOLOGY_HOST_TASK_TABLE, columns, "id");
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_TASK_TABLE, "FK_hosttask_req_id", 
"host_request_id", TOPOLOGY_HOST_REQUEST_TABLE, "id", true, false);
+    dbAccessor.addFKConstraint(TOPOLOGY_HOST_TASK_TABLE, 
"FK_hosttask_lreq_id", "logical_request_id", TOPOLOGY_LOGICAL_REQUEST_TABLE, 
"id", true, false);
+
+    columns.clear();
+    columns.add(new DBColumnInfo("id", Long.class, null, null, false));
+    columns.add(new DBColumnInfo("host_task_id", Long.class, null, null, 
false));
+    columns.add(new DBColumnInfo("physical_task_id", Long.class, null, null, 
false));
+    columns.add(new DBColumnInfo("component", String.class, 255, null, false));
+    dbAccessor.createTable(TOPOLOGY_LOGICAL_TASK_TABLE, columns, "id");
+    dbAccessor.addFKConstraint(TOPOLOGY_LOGICAL_TASK_TABLE, 
"FK_ltask_hosttask_id", "host_task_id", TOPOLOGY_HOST_TASK_TABLE, "id", true, 
false);
+    dbAccessor.addFKConstraint(TOPOLOGY_LOGICAL_TASK_TABLE, "FK_ltask_hrc_id", 
"physical_task_id", "host_role_command", "task_id", false, false);
+
+    // Sequence updates
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_host_info_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_host_request_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_host_task_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_logical_request_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_logical_task_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('topology_request_id_seq', 0);", false);
   }
 
   /**
@@ -413,21 +499,21 @@ public class UpgradeCatalog210 extends 
AbstractUpgradeCatalog {
     columns.add(new DBColumnInfo("widget_name", String.class,  255,   null, 
false));
     columns.add(new DBColumnInfo("widget_type", String.class,  255,   null, 
false));
     columns.add(new DBColumnInfo("metrics", String.class,  32672,   null, 
true));
-    columns.add(new DBColumnInfo("time_created", Long.class,  255,   null, 
false));
+    columns.add(new DBColumnInfo("time_created", Long.class,  null,   null, 
false));
     columns.add(new DBColumnInfo("author", String.class,  255,   null, true));
     columns.add(new DBColumnInfo("description", String.class,  255,   null, 
true));
     columns.add(new DBColumnInfo("display_name", String.class,  255,   null, 
true));
     columns.add(new DBColumnInfo("scope", String.class,  255,   null, true));
     columns.add(new DBColumnInfo("widget_values", String.class,  4000,   null, 
true));
     columns.add(new DBColumnInfo("properties", String.class,  4000,   null, 
true));
-    columns.add(new DBColumnInfo("cluster_id", Long.class,  255,   null, 
false));
+    columns.add(new DBColumnInfo("cluster_id", Long.class,  null,   null, 
false));
     dbAccessor.createTable(WIDGET_TABLE, columns, "id");
 
     columns = new ArrayList<DBColumnInfo>();
     columns.add(new DBColumnInfo("id", Long.class,    null,  null, false));
     columns.add(new DBColumnInfo("layout_name", String.class,  255,   null, 
false));
     columns.add(new DBColumnInfo("section_name", String.class,  255,   null, 
false));
-    columns.add(new DBColumnInfo("cluster_id", Long.class,  255,   null, 
false));
+    columns.add(new DBColumnInfo("cluster_id", Long.class,  null,   null, 
false));
     columns.add(new DBColumnInfo("scope", String.class,  255,   null, false));
     columns.add(new DBColumnInfo("user_name", String.class,  255,   null, 
false));
     columns.add(new DBColumnInfo("display_name", String.class,  255,   null, 
true));
@@ -444,6 +530,10 @@ public class UpgradeCatalog210 extends 
AbstractUpgradeCatalog {
 
     //Alter users to store active widget layouts
     dbAccessor.addColumn("users", new DBColumnInfo("active_widget_layouts", 
String.class, 1024, null, true));
+
+    // Sequence updates
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('widget_id_seq', 0);", false);
+    dbAccessor.executeQuery("INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('widget_layout_id_seq', 0);", false);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 28be510..7f00b10 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -581,6 +581,67 @@ CREATE TABLE artifact (
   artifact_data LONGTEXT NOT NULL,
   PRIMARY KEY(artifact_name, foreign_keys));
 
+CREATE TABLE topology_request (
+  id BIGINT NOT NULL,
+  action VARCHAR(255) NOT NULL,
+  cluster_name VARCHAR(100) NOT NULL,
+  bp_name VARCHAR(100) NOT NULL,
+  cluster_properties TEXT,
+  cluster_attributes TEXT,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_hostgroup (
+  name VARCHAR(255) NOT NULL,
+  group_properties TEXT,
+  group_attributes TEXT,
+  request_id BIGINT NOT NULL,
+  PRIMARY KEY (name)
+);
+
+CREATE TABLE topology_host_info (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  fqdn VARCHAR(255),
+  host_count INTEGER,
+  predicate VARCHAR(2048),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_request (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_request (
+  id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  stage_id BIGINT NOT NULL,
+  host_name VARCHAR(255),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_task (
+  id BIGINT NOT NULL,
+  host_request_id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_task (
+  id BIGINT NOT NULL,
+  host_task_id BIGINT NOT NULL,
+  physical_task_id BIGINT NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
 -- altering tables by creating unique constraints----------
 ALTER TABLE users ADD CONSTRAINT UNQ_users_0 UNIQUE (user_name, ldap_user);
 ALTER TABLE groups ADD CONSTRAINT UNQ_groups_0 UNIQUE (group_name, ldap_group);
@@ -659,6 +720,15 @@ ALTER TABLE groups ADD CONSTRAINT FK_groups_principal_id 
FOREIGN KEY (principal_
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id 
FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_req_id FOREIGN KEY 
(host_request_id) REFERENCES topology_host_request (id);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_lreq_id FOREIGN KEY 
(logical_request_id) REFERENCES topology_logical_request (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hosttask_id FOREIGN 
KEY (host_task_id) REFERENCES topology_host_task (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hrc_id FOREIGN KEY 
(physical_task_id) REFERENCES host_role_command (task_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (
@@ -860,6 +930,12 @@ INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('upgrade_ite
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('stack_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('widget_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('widget_layout_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_info_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_request_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_task_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_logical_request_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_logical_task_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_request_id_seq', 0);
 
 insert into adminresourcetype (resource_type_id, resource_type_name)
   select 1, 'AMBARI'

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 31a645c..c0313e5 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -571,6 +571,67 @@ CREATE TABLE artifact (
   artifact_data CLOB NOT NULL,
   PRIMARY KEY(artifact_name, foreign_keys));
 
+CREATE TABLE topology_request (
+  id NUMBER(19) NOT NULL,
+  action VARCHAR(255) NOT NULL,
+  cluster_name VARCHAR(100) NOT NULL,
+  bp_name VARCHAR(100) NOT NULL,
+  cluster_properties CLOB,
+  cluster_attributes CLOB,
+  description VARCHAR(1024),
+  PRIMARY KEY(id)
+);
+
+CREATE TABLE topology_hostgroup (
+  name VARCHAR(255) NOT NULL,
+  group_properties CLOB,
+  group_attributes CLOB,
+  request_id NUMBER(19) NOT NULL,
+  PRIMARY KEY(name)
+);
+
+CREATE TABLE topology_host_info (
+  id NUMBER(19) NOT NULL,
+  request_id NUMBER(19) NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  fqdn VARCHAR(255),
+  host_count INTEGER,
+  predicate VARCHAR(2048),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_request (
+  id NUMBER(19) NOT NULL,
+  request_id NUMBER(19) NOT NULL,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_request (
+  id NUMBER(19) NOT NULL,
+  logical_request_id NUMBER(19) NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  stage_id NUMBER(19) NOT NULL,
+  host_name VARCHAR(255),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_task (
+  id NUMBER(19) NOT NULL,
+  host_request_id NUMBER(19) NOT NULL,
+  logical_request_id NUMBER(19) NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_task (
+  id NUMBER(19) NOT NULL,
+  host_task_id NUMBER(19) NOT NULL,
+  physical_task_id NUMBER(19) NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
 --------altering tables by creating unique constraints----------
 ALTER TABLE users ADD CONSTRAINT UNQ_users_0 UNIQUE (user_name, ldap_user);
 ALTER TABLE groups ADD CONSTRAINT UNQ_groups_0 UNIQUE (group_name, ldap_group);
@@ -649,6 +710,15 @@ ALTER TABLE groups ADD CONSTRAINT FK_groups_principal_id 
FOREIGN KEY (principal_
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id 
FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_req_id FOREIGN KEY 
(host_request_id) REFERENCES topology_host_request (id);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_lreq_id FOREIGN KEY 
(logical_request_id) REFERENCES topology_logical_request (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hosttask_id FOREIGN 
KEY (host_task_id) REFERENCES topology_host_task (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hrc_id FOREIGN KEY 
(physical_task_id) REFERENCES host_role_command (task_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (
@@ -851,6 +921,12 @@ INSERT INTO ambari_sequences(sequence_name, 
sequence_value) values ('upgrade_ite
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('stack_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('widget_id_seq', 0);
 INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('widget_layout_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_info_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_request_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_host_task_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_logical_request_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_logical_task_id_seq', 0);
+INSERT INTO ambari_sequences(sequence_name, sequence_value) values 
('topology_request_id_seq', 0);
 
 INSERT INTO metainfo("metainfo_key", "metainfo_value") values ('version', 
'${ambariVersion}');
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index e46f5bf..94e4884 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -580,6 +580,67 @@ CREATE TABLE artifact (
   foreign_keys VARCHAR(255) NOT NULL,
   PRIMARY KEY (artifact_name, foreign_keys));
 
+CREATE TABLE topology_request (
+  id BIGINT NOT NULL,
+  action VARCHAR(255) NOT NULL,
+  cluster_name VARCHAR(100) NOT NULL,
+  bp_name VARCHAR(100) NOT NULL,
+  cluster_properties TEXT,
+  cluster_attributes TEXT,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_hostgroup (
+  name VARCHAR(255) NOT NULL,
+  group_properties TEXT,
+  group_attributes TEXT,
+  request_id BIGINT NOT NULL,
+  PRIMARY KEY (name)
+);
+
+CREATE TABLE topology_host_info (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  fqdn VARCHAR(255),
+  host_count INTEGER,
+  predicate VARCHAR(2048),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_request (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_request (
+  id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  stage_id BIGINT NOT NULL,
+  host_name VARCHAR(255),
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_host_task (
+  id BIGINT NOT NULL,
+  host_request_id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE topology_logical_task (
+  id BIGINT NOT NULL,
+  host_task_id BIGINT NOT NULL,
+  physical_task_id BIGINT NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+
 --------altering tables by creating unique constraints----------
 ALTER TABLE clusterconfig ADD CONSTRAINT UQ_config_type_tag UNIQUE 
(cluster_id, type_name, version_tag);
 ALTER TABLE clusterconfig ADD CONSTRAINT UQ_config_type_version UNIQUE 
(cluster_id, type_name, version);
@@ -655,6 +716,15 @@ ALTER TABLE serviceconfighosts ADD CONSTRAINT 
FK_scvhosts_host_id FOREIGN KEY (h
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_logicalreq_id 
FOREIGN KEY (logical_request_id) REFERENCES topology_logical_request(id);
+ALTER TABLE topology_host_request ADD CONSTRAINT FK_hostreq_group_name FOREIGN 
KEY (group_name) REFERENCES topology_hostgroup(name);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_req_id FOREIGN KEY 
(host_request_id) REFERENCES topology_host_request (id);
+ALTER TABLE topology_host_task ADD CONSTRAINT FK_hosttask_lreq_id FOREIGN KEY 
(logical_request_id) REFERENCES topology_logical_request (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hosttask_id FOREIGN 
KEY (host_task_id) REFERENCES topology_host_task (id);
+ALTER TABLE topology_logical_task ADD CONSTRAINT FK_ltask_hrc_id FOREIGN KEY 
(physical_task_id) REFERENCES host_role_command (task_id);
 
 -- Kerberos
 CREATE TABLE kerberos_principal (
@@ -892,7 +962,19 @@ INSERT INTO ambari_sequences (sequence_name, 
sequence_value)
   union all
   select 'upgrade_item_id_seq', 0
   union all
-  select 'stack_id_seq', 0;  
+  select 'stack_id_seq', 0
+  union all
+  select 'topology_host_info_id_seq', 0
+  union all
+  select 'topology_host_request_id_seq', 0
+  union all
+  select 'topology_host_task_id_seq', 0
+  union all
+    select 'topology_logical_request_id_seq', 0
+  union all
+  select 'topology_logical_task_id_seq', 0
+  union all
+  select 'topology_request_id_seq', 0;
 
 INSERT INTO adminresourcetype (resource_type_id, resource_type_name)
   SELECT 1, 'AMBARI'

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 05189bd..54c8c40 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -653,6 +653,74 @@ CREATE TABLE ambari.widget_layout_user_widget (
 );
 GRANT ALL PRIVILEGES ON TABLE ambari.widget_layout_user_widget TO :username;
 
+CREATE TABLE ambari.topology_request (
+  id BIGINT NOT NULL,
+  action VARCHAR(255) NOT NULL,
+  cluster_name VARCHAR(100) NOT NULL,
+  bp_name VARCHAR(100) NOT NULL,
+  cluster_properties TEXT,
+  cluster_attributes TEXT,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_request TO :username;
+
+CREATE TABLE ambari.topology_hostgroup (
+  name VARCHAR(255) NOT NULL,
+  group_properties TEXT,
+  group_attributes TEXT,
+  request_id BIGINT NOT NULL,
+  PRIMARY KEY(name)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_hostgroup TO :username;
+
+CREATE TABLE ambari.topology_host_info (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  fqdn VARCHAR(255),
+  host_count INTEGER,
+  predicate VARCHAR(2048),
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_info TO :username;
+
+CREATE TABLE ambari.topology_logical_request (
+  id BIGINT NOT NULL,
+  request_id BIGINT NOT NULL,
+  description VARCHAR(1024),
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_logical_request TO :username;
+
+CREATE TABLE ambari.topology_host_request (
+  id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  group_name VARCHAR(255) NOT NULL,
+  stage_id BIGINT NOT NULL,
+  host_name VARCHAR(255),
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_request TO :username;
+
+CREATE TABLE ambari.topology_host_task (
+  id BIGINT NOT NULL,
+  host_request_id BIGINT NOT NULL,
+  logical_request_id BIGINT NOT NULL,
+  type VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_host_task TO :username;
+
+CREATE TABLE ambari.topology_logical_task (
+  id BIGINT NOT NULL,
+  host_task_id BIGINT NOT NULL,
+  physical_task_id BIGINT NOT NULL,
+  component VARCHAR(255) NOT NULL,
+  PRIMARY KEY (id)
+);
+GRANT ALL PRIVILEGES ON TABLE ambari.topology_logical_task TO :username;
+
 --------altering tables by creating unique constraints----------
 ALTER TABLE ambari.clusterconfig ADD CONSTRAINT UQ_config_type_tag UNIQUE 
(cluster_id, type_name, version_tag);
 ALTER TABLE ambari.clusterconfig ADD CONSTRAINT UQ_config_type_version UNIQUE 
(cluster_id, type_name, version);
@@ -728,6 +796,15 @@ ALTER TABLE ambari.groups ADD CONSTRAINT 
FK_groups_principal_id FOREIGN KEY (pri
 ALTER TABLE ambari.clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES ambari.adminresource(resource_id);
 ALTER TABLE ambari.widget_layout_user_widget ADD CONSTRAINT 
FK_widget_layout_id FOREIGN KEY (widget_layout_id) REFERENCES 
ambari.widget_layout(id);
 ALTER TABLE ambari.widget_layout_user_widget ADD CONSTRAINT FK_widget_id 
FOREIGN KEY (widget_id) REFERENCES ambari.widget(id);
+ALTER TABLE ambari.topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id 
FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id);
+ALTER TABLE ambari.topology_host_info ADD CONSTRAINT FK_hostinfo_group_name 
FOREIGN KEY (group_name) REFERENCES ambari.topology_hostgroup(name);
+ALTER TABLE ambari.topology_logical_request ADD CONSTRAINT 
FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES 
ambari.topology_request(id);
+ALTER TABLE ambari.topology_host_request ADD CONSTRAINT 
FK_hostreq_logicalreq_id FOREIGN KEY (logical_request_id) REFERENCES 
ambari.topology_logical_request(id);
+ALTER TABLE ambari.topology_host_request ADD CONSTRAINT FK_hostreq_group_name 
FOREIGN KEY (group_name) REFERENCES ambari.topology_hostgroup(name);
+ALTER TABLE ambari.topology_host_task ADD CONSTRAINT FK_hosttask_req_id 
FOREIGN KEY (host_request_id) REFERENCES ambari.topology_host_request (id);
+ALTER TABLE ambari.topology_host_task ADD CONSTRAINT FK_hosttask_lreq_id 
FOREIGN KEY (logical_request_id) REFERENCES ambari.topology_logical_request 
(id);
+ALTER TABLE ambari.topology_logical_task ADD CONSTRAINT FK_ltask_hosttask_id 
FOREIGN KEY (host_task_id) REFERENCES ambari.topology_host_task (id);
+ALTER TABLE ambari.topology_logical_task ADD CONSTRAINT FK_ltask_hrc_id 
FOREIGN KEY (physical_task_id) REFERENCES ambari.host_role_command (task_id);
 
 -- Kerberos
 CREATE TABLE ambari.kerberos_principal (
@@ -981,7 +1058,19 @@ INSERT INTO ambari.ambari_sequences (sequence_name, 
sequence_value)
   union all
   select 'upgrade_item_id_seq', 0
   union all
-  select 'stack_id_seq', 0;
+  select 'stack_id_seq', 0
+  union all
+  select 'topology_host_info_id_seq', 0
+  union all
+  select 'topology_host_request_id_seq', 0
+  union all
+  select 'topology_host_task_id_seq', 0
+  union all
+  select 'topology_logical_request_id_seq', 0
+  union all
+  select 'topology_logical_task_id_seq', 0
+  union all
+  select 'topology_request_id_seq', 0;
 
 INSERT INTO ambari.adminresourcetype (resource_type_id, resource_type_name)
   SELECT 1, 'AMBARI'

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/META-INF/persistence.xml 
b/ambari-server/src/main/resources/META-INF/persistence.xml
index b864c59..4b30c0c 100644
--- a/ambari-server/src/main/resources/META-INF/persistence.xml
+++ b/ambari-server/src/main/resources/META-INF/persistence.xml
@@ -82,6 +82,13 @@
     <class>org.apache.ambari.server.orm.entities.ViewResourceEntity</class>
     <class>org.apache.ambari.server.orm.entities.WidgetLayoutEntity</class>
     
<class>org.apache.ambari.server.orm.entities.WidgetLayoutUserWidgetEntity</class>
+    <class>org.apache.ambari.server.orm.entities.TopologyRequestEntity</class>
+    
<class>org.apache.ambari.server.orm.entities.TopologyLogicalRequestEntity</class>
+    
<class>org.apache.ambari.server.orm.entities.TopologyHostRequestEntity</class>
+    
<class>org.apache.ambari.server.orm.entities.TopologyHostGroupEntity</class>
+    <class>org.apache.ambari.server.orm.entities.TopologyHostInfoEntity</class>
+    <class>org.apache.ambari.server.orm.entities.TopologyHostTaskEntity</class>
+    
<class>org.apache.ambari.server.orm.entities.TopologyLogicalTaskEntity</class>
 
     <properties>      
       <property name="eclipselink.cache.size.default" value="10000" />

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index a84635e..aee0a55 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -125,6 +125,8 @@ public class OrmTestHelper {
   @Inject
   private StackDAO stackDAO;
 
+  public static final String CLUSTER_NAME = "test_cluster1";
+
   public EntityManager getEntityManager() {
     return entityManagerProvider.get();
   }
@@ -303,7 +305,7 @@ public class OrmTestHelper {
    */
   @Transactional
   public Long createCluster() {
-    return createCluster("test_cluster1");
+    return createCluster(CLUSTER_NAME);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/89711d74/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
new file mode 100644
index 0000000..bba45eb
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
@@ -0,0 +1,155 @@
+/**
+ * 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.Guice;
+import com.google.inject.Injector;
+import com.google.inject.persist.PersistService;
+import junit.framework.Assert;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.orm.GuiceJpaInitializer;
+import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.TopologyHostGroupEntity;
+import org.apache.ambari.server.orm.entities.TopologyHostInfoEntity;
+import org.apache.ambari.server.orm.entities.TopologyHostRequestEntity;
+import org.apache.ambari.server.orm.entities.TopologyHostTaskEntity;
+import org.apache.ambari.server.orm.entities.TopologyLogicalRequestEntity;
+import org.apache.ambari.server.orm.entities.TopologyLogicalTaskEntity;
+import org.apache.ambari.server.orm.entities.TopologyRequestEntity;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import static org.apache.ambari.server.orm.OrmTestHelper.CLUSTER_NAME;
+
+public class TopologyLogicalRequestDAOTest {
+  private Injector injector;
+  private TopologyRequestDAO requestDAO;
+  private TopologyLogicalRequestDAO logicalRequestDAO;
+  private TopologyHostGroupDAO hostGroupDAO;
+  OrmTestHelper helper;
+  Long clusterId;
+
+  @Before
+  public void setup() throws Exception {
+    injector = Guice.createInjector(new InMemoryDefaultTestModule());
+    injector.getInstance(GuiceJpaInitializer.class);
+    requestDAO = injector.getInstance(TopologyRequestDAO.class);
+    logicalRequestDAO = injector.getInstance(TopologyLogicalRequestDAO.class);
+    hostGroupDAO = injector.getInstance(TopologyHostGroupDAO.class);
+    helper = injector.getInstance(OrmTestHelper.class);
+    clusterId = helper.createCluster();
+  }
+
+  @After
+  public void teardown() throws AmbariException {
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  private void create() {
+    TopologyRequestEntity requestEntity = new TopologyRequestEntity();
+    requestEntity.setAction("a1");
+    requestEntity.setBlueprintName("bp1");
+    requestEntity.setClusterAttributes("attributes");
+    requestEntity.setClusterProperties("properties");
+    requestEntity.setClusterName(CLUSTER_NAME);
+    requestEntity.setDescription("description");
+    requestDAO.create(requestEntity);
+    List<TopologyRequestEntity> requestEntities = requestDAO.findAll();
+    Assert.assertEquals(1, requestEntities.size());
+    requestEntity = requestEntities.iterator().next();
+
+    TopologyHostGroupEntity hostGroupEntity = new TopologyHostGroupEntity();
+    hostGroupEntity.setName("hg1");
+    hostGroupEntity.setGroupProperties("test");
+    hostGroupEntity.setGroupAttributes("test");
+    hostGroupEntity.setTopologyRequestEntity(requestEntity);
+
+    TopologyHostInfoEntity hostInfoEntity = new TopologyHostInfoEntity();
+    hostInfoEntity.setHostCount(1);
+    hostInfoEntity.setPredicate("test");
+    hostInfoEntity.setFqdn("fqdn");
+    hostInfoEntity.setTopologyHostGroupEntity(hostGroupEntity);
+    hostGroupDAO.create(hostGroupEntity);
+    List<TopologyHostGroupEntity> hostGroupEntities = hostGroupDAO.findAll();
+    Assert.assertEquals(1, hostGroupEntities.size());
+    hostGroupEntity = hostGroupEntities.iterator().next();
+
+    TopologyLogicalRequestEntity logicalRequestEntity = new 
TopologyLogicalRequestEntity();
+    logicalRequestEntity.setDescription("description");
+    logicalRequestEntity.setTopologyRequestEntity(requestEntity);
+    logicalRequestEntity.setTopologyRequestId(requestEntity.getId());
+
+    TopologyHostRequestEntity hostRequestEntity = new 
TopologyHostRequestEntity();
+    hostRequestEntity.setHostName("h1");
+    hostRequestEntity.setStageId(1L);
+    hostRequestEntity.setTopologyLogicalRequestEntity(logicalRequestEntity);
+    hostRequestEntity.setTopologyHostGroupEntity(hostGroupEntity);
+
+    TopologyHostTaskEntity hostTaskEntity = new TopologyHostTaskEntity();
+    hostTaskEntity.setType("type");
+    hostTaskEntity.setTopologyHostRequestEntity(hostRequestEntity);
+
+    TopologyLogicalTaskEntity logicalTaskEntity = new 
TopologyLogicalTaskEntity();
+    logicalTaskEntity.setComponentName("NAMENODE");
+    logicalTaskEntity.setHostRoleCommandEntity(null);
+    logicalTaskEntity.setTopologyHostTaskEntity(hostTaskEntity);
+
+
+    
hostGroupEntity.setTopologyHostRequestEntities(Collections.singletonList(hostRequestEntity));
+
+    
hostRequestEntity.setTopologyHostTaskEntities(Collections.singletonList(hostTaskEntity));
+    hostRequestEntity.setTopologyHostGroupEntity(hostGroupEntity);
+    
hostTaskEntity.setTopologyLogicalTaskEntities(Collections.singletonList(logicalTaskEntity));
+    
logicalRequestEntity.setTopologyHostRequestEntities(Collections.singletonList(hostRequestEntity));
+
+    logicalRequestDAO.create(logicalRequestEntity);
+  }
+
+  @Test
+  public void testFindAll() throws Exception {
+    create();
+    List<TopologyLogicalRequestEntity> logicalRequestEntities = 
logicalRequestDAO.findAll();
+    Assert.assertEquals(1, logicalRequestEntities.size());
+
+    TopologyLogicalRequestEntity logicalRequestEntity = 
logicalRequestEntities.iterator().next();
+    Assert.assertNotNull(logicalRequestEntity.getTopologyRequestId());
+    Assert.assertNotNull(logicalRequestEntity.getId());
+    Assert.assertEquals("description", logicalRequestEntity.getDescription());
+    Assert.assertNotNull(logicalRequestEntity.getTopologyRequestEntity());
+
+    Collection<TopologyHostRequestEntity> hostRequestEntities = 
logicalRequestEntity.getTopologyHostRequestEntities();
+    Assert.assertEquals(1, hostRequestEntities.size());
+    TopologyHostRequestEntity hostRequestEntity = 
hostRequestEntities.iterator().next();
+    Assert.assertNotNull(hostRequestEntity.getTopologyHostGroupEntity());
+    Assert.assertEquals("hg1", hostRequestEntity.getHostGroupName());
+
+    Collection<TopologyHostTaskEntity> taskEntities = 
hostRequestEntity.getTopologyHostTaskEntities();
+    Assert.assertEquals(1, taskEntities.size());
+    TopologyHostTaskEntity taskEntity = taskEntities.iterator().next();
+    Assert.assertNotNull(taskEntity.getTopologyHostRequestEntity());
+    Assert.assertNotNull(taskEntity.getTopologyLogicalTaskEntities());
+    Assert.assertEquals(1, taskEntity.getTopologyLogicalTaskEntities().size());
+    
Assert.assertNotNull(taskEntity.getTopologyLogicalTaskEntities().iterator().next().getTopologyHostTaskEntity());
+  }
+}

Reply via email to