You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2016/05/23 20:21:44 UTC
ambari git commit: AMBARI-16751: Refresh stale host entity reference
when deleting a service
Repository: ambari
Updated Branches:
refs/heads/trunk 5835a4299 -> 9b4e80cde
AMBARI-16751: Refresh stale host entity reference when deleting a service
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9b4e80cd
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9b4e80cd
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9b4e80cd
Branch: refs/heads/trunk
Commit: 9b4e80cde2a4fe126751fd0d91f97a37f77955df
Parents: 5835a42
Author: Nahappan Somasundaram <ns...@hortonworks.com>
Authored: Thu May 19 07:24:46 2016 -0700
Committer: Nahappan Somasundaram <ns...@hortonworks.com>
Committed: Mon May 23 13:20:37 2016 -0700
----------------------------------------------------------------------
.../ambari/server/orm/dao/HostComponentDesiredStateDAO.java | 7 ++++++-
.../server/orm/dao/HostComponentDesiredStateDAOTest.java | 4 +++-
2 files changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4e80cd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
index 46da9da..176e15b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -95,7 +95,12 @@ public class HostComponentDesiredStateDAO {
@Transactional
public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
- HostEntity hostEntity = hostComponentDesiredStateEntity.getHostEntity();
+ HostEntity hostEntity = hostDAO.findById(hostComponentDesiredStateEntity.getHostId());
+
+ if (hostEntity == null) {
+ throw new IllegalStateException(String.format("Missing hostEntity for host id %1d",
+ hostComponentDesiredStateEntity.getHostId()));
+ }
entityManagerProvider.get().remove(merge(hostComponentDesiredStateEntity));
http://git-wip-us.apache.org/repos/asf/ambari/blob/9b4e80cd/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java
index b7a0677..28adb8c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java
@@ -48,7 +48,7 @@ public class HostComponentDesiredStateDAOTest {
HostEntity hostEntity = createNiceMock(HostEntity.class);
HostComponentDesiredStateEntity hostComponentDesiredStateEntity = createNiceMock(HostComponentDesiredStateEntity.class);
- expect(hostComponentDesiredStateEntity.getHostEntity()).andReturn(hostEntity);
+ expect(hostComponentDesiredStateEntity.getHostId()).andReturn(1L).anyTimes();
expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
expect(entityManager.merge(hostComponentDesiredStateEntity)).andReturn(hostComponentDesiredStateEntity).anyTimes();
@@ -58,6 +58,8 @@ public class HostComponentDesiredStateDAOTest {
expect(hostDAO.merge(hostEntity)).andReturn(hostEntity).anyTimes();
+ expect(hostDAO.findById(1L)).andReturn(hostEntity).anyTimes();
+
replay(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentDesiredStateEntity);
HostComponentDesiredStateDAO dao = new HostComponentDesiredStateDAO();