Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B11142009F9 for ; Mon, 23 May 2016 22:21:46 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AF889160A0E; Mon, 23 May 2016 20:21:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 052BF160A05 for ; Mon, 23 May 2016 22:21:45 +0200 (CEST) Received: (qmail 52990 invoked by uid 500); 23 May 2016 20:21:45 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 52981 invoked by uid 99); 23 May 2016 20:21:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 23 May 2016 20:21:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id ED865DFBED; Mon, 23 May 2016 20:21:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: smnaha@apache.org To: commits@ambari.apache.org Message-Id: <871e614ead4149dfa097c6c2b263b124@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-16751: Refresh stale host entity reference when deleting a service Date: Mon, 23 May 2016 20:21:44 +0000 (UTC) archived-at: Mon, 23 May 2016 20:21:46 -0000 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 Authored: Thu May 19 07:24:46 2016 -0700 Committer: Nahappan Somasundaram 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();