ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-9869 - SECONDARY_NAMENODE persist object in memory, causes HostVersion to stay in UPGRADING, so Finalize fails (tbeerbower)
Date Mon, 02 Mar 2015 23:56:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 45b47ed4a -> f18c9fa25


AMBARI-9869 - SECONDARY_NAMENODE persist object in memory, causes HostVersion to stay in UPGRADING,
so Finalize fails (tbeerbower)


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

Branch: refs/heads/trunk
Commit: f18c9fa2525bc93a20179c612d442590f7b7bbfc
Parents: 45b47ed
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Mon Mar 2 17:32:42 2015 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Mon Mar 2 17:32:54 2015 -0500

----------------------------------------------------------------------
 .../orm/dao/HostComponentDesiredStateDAO.java   |  10 ++
 .../server/orm/dao/HostComponentStateDAO.java   |  10 ++
 .../ambari/server/orm/entities/HostEntity.java  |  51 ++++++-
 .../svccomphost/ServiceComponentHostImpl.java   |   8 +-
 .../server/upgrade/UpgradeCatalog150.java       |   4 +-
 .../dao/HostComponentDesiredStateDAOTest.java   |  76 ++++++++++
 .../orm/dao/HostComponentStateDAOTest.java      |  75 ++++++++++
 .../server/orm/entities/HostEntityTest.java     | 142 +++++++++++++++++++
 .../server/upgrade/UpgradeCatalogHelper.java    |   5 +-
 9 files changed, 372 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/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 9635f30..8e92877 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
@@ -25,6 +25,7 @@ import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
+import org.apache.ambari.server.orm.entities.HostEntity;
 
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
@@ -36,6 +37,9 @@ public class HostComponentDesiredStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
+  @Inject
+  HostDAO hostDAO;
+
   @RequiresSession
   public HostComponentDesiredStateEntity findByPK(HostComponentDesiredStateEntityPK primaryKey)
{
     return entityManagerProvider.get().find(HostComponentDesiredStateEntity.class, primaryKey);
@@ -69,7 +73,13 @@ public class HostComponentDesiredStateDAO {
 
   @Transactional
   public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
+    HostEntity hostEntity = hostDAO.findByName(hostComponentDesiredStateEntity.getHostName());
+
     entityManagerProvider.get().remove(merge(hostComponentDesiredStateEntity));
+
+    // Make sure that the state entity is removed from its host entity
+    hostEntity.removeHostComponentDesiredStateEntity(hostComponentDesiredStateEntity);
+    hostDAO.merge(hostEntity);
   }
 
   @Transactional

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
index 66e91d3..e7b5c10 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
@@ -25,6 +25,7 @@ import com.google.inject.persist.Transactional;
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
+import org.apache.ambari.server.orm.entities.HostEntity;
 
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
@@ -38,6 +39,9 @@ public class HostComponentStateDAO {
   @Inject
   DaoUtils daoUtils;
 
+  @Inject
+  HostDAO hostDAO;
+
   @RequiresSession
   public HostComponentStateEntity findByPK(HostComponentStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentStateEntity.class, primaryKey);
@@ -84,7 +88,13 @@ public class HostComponentStateDAO {
 
   @Transactional
   public void remove(HostComponentStateEntity hostComponentStateEntity) {
+    HostEntity hostEntity = hostDAO.findByName(hostComponentStateEntity.getHostName());
+
     entityManagerProvider.get().remove(merge(hostComponentStateEntity));
+
+    // Make sure that the state entity is removed from its host entity
+    hostEntity.removeHostComponentStateEntity(hostComponentStateEntity);
+    hostDAO.merge(hostEntity);
   }
 
   @Transactional

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
index df22de1..3255e58 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostEntity.java
@@ -31,6 +31,7 @@ import javax.persistence.ManyToMany;
 import javax.persistence.OneToMany;
 import javax.persistence.OneToOne;
 import java.util.Collection;
+import java.util.Collections;
 
 import static org.apache.commons.lang.StringUtils.defaultString;
 
@@ -266,16 +267,62 @@ public class HostEntity implements Comparable<HostEntity> {
     return this.hostName.compareTo(other.hostName);
   }
 
+  /**
+   * Get the read-only collection of host component desired state entities associated with
this host entity.
+   *
+   * @return the read-only collection of host component desired state entities
+   */
   public Collection<HostComponentDesiredStateEntity> getHostComponentDesiredStateEntities()
{
-    return hostComponentDesiredStateEntities;
+    return Collections.unmodifiableCollection(hostComponentDesiredStateEntities);
+  }
+
+  /**
+   * Add a host component desired state entity to this host entity.
+   *
+   * @param stateEntity the host component desired state entity
+   */
+  public void addHostComponentDesiredStateEntity(HostComponentDesiredStateEntity stateEntity)
{
+    hostComponentDesiredStateEntities.add(stateEntity);
+  }
+
+  /**
+   * Remove a host component desired state entity from this host entity.
+   *
+   * @param stateEntity the host component desired state entity
+   */
+  public void removeHostComponentDesiredStateEntity(HostComponentDesiredStateEntity stateEntity)
{
+    hostComponentDesiredStateEntities.remove(stateEntity);
   }
 
   public void setHostComponentDesiredStateEntities(Collection<HostComponentDesiredStateEntity>
hostComponentDesiredStateEntities) {
     this.hostComponentDesiredStateEntities = hostComponentDesiredStateEntities;
   }
 
+  /**
+   * Get the read-only collection of host component state entities associated with this host
entity.
+   *
+   * @return the read-only collection of host component state entities
+   */
   public Collection<HostComponentStateEntity> getHostComponentStateEntities() {
-    return hostComponentStateEntities;
+    return Collections.unmodifiableCollection(hostComponentStateEntities);
+  }
+
+  /**
+   * Add a host component state entity to this host entity.
+   *
+   * @param stateEntity the host component state entity
+   */
+  public void addHostComponentStateEntity(HostComponentStateEntity stateEntity) {
+    hostComponentStateEntities.add(stateEntity);
+  }
+
+  /**
+   * Remove a host component state entity from this host entity.
+   *
+   * @param stateEntity the host component state entity
+   */
+  public void removeHostComponentStateEntity(HostComponentStateEntity stateEntity) {
+    hostComponentStateEntities.remove(stateEntity);
   }
 
   public void setHostComponentStateEntities(Collection<HostComponentStateEntity> hostComponentStateEntities)
{

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index fe5397b..8d132ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -1195,8 +1195,8 @@ public class ServiceComponentHostImpl implements ServiceComponentHost
{
   @Transactional
   protected void persistEntities() {
     HostEntity hostEntity = hostDAO.findByName(getHostName());
-    hostEntity.getHostComponentStateEntities().add(stateEntity);
-    hostEntity.getHostComponentDesiredStateEntities().add(desiredStateEntity);
+    hostEntity.addHostComponentStateEntity(stateEntity);
+    hostEntity.addHostComponentDesiredStateEntity(desiredStateEntity);
 
     ServiceComponentDesiredStateEntityPK dpk = new ServiceComponentDesiredStateEntityPK();
     dpk.setClusterId(serviceComponent.getClusterId());
@@ -1333,6 +1333,10 @@ public class ServiceComponentHostImpl implements ServiceComponentHost
{
     desiredPK.setHostName(desiredStateEntity.getHostName());
 
     hostComponentDesiredStateDAO.removeByPK(desiredPK);
+
+    // make sure that the state entities are removed from the associated (detached) host
entity
+    stateEntity.getHostEntity().removeHostComponentStateEntity(stateEntity);
+    desiredStateEntity.getHostEntity().removeHostComponentDesiredStateEntity(desiredStateEntity);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
index 4ecfe44..dd8e33e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog150.java
@@ -646,8 +646,8 @@ public class UpgradeCatalog150 extends AbstractUpgradeCatalog {
     HostDAO hostDAO = injector.getInstance(HostDAO.class);
 
     HostEntity hostEntity = hostDAO.findByName(stateEntity.getHostName());
-    hostEntity.getHostComponentStateEntities().add(stateEntity);
-    hostEntity.getHostComponentDesiredStateEntities().add(desiredStateEntity);
+    hostEntity.addHostComponentStateEntity(stateEntity);
+    hostEntity.addHostComponentDesiredStateEntity(desiredStateEntity);
 
     serviceComponentDesiredStateEntity.getHostComponentDesiredStateEntities().add(desiredStateEntity);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/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
new file mode 100644
index 0000000..7b34827
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.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.Provider;
+import junit.framework.Assert;
+import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.junit.Test;
+
+import javax.persistence.EntityManager;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * HostComponentDesiredStateDAO tests.
+ */
+public class HostComponentDesiredStateDAOTest {
+
+  @Test
+  public void testRemove() throws Exception {
+
+    Provider<EntityManager> entityManagerProvider =  createNiceMock(Provider.class);
+    EntityManager entityManager = createNiceMock(EntityManager.class);
+    HostDAO hostDAO = createNiceMock(HostDAO.class);
+    HostEntity hostEntity = createNiceMock(HostEntity.class);
+
+    HostComponentDesiredStateEntity hostComponentDesiredStateEntity = createNiceMock(HostComponentDesiredStateEntity.class);
+
+    expect(hostComponentDesiredStateEntity.getHostName()).andReturn("host1");
+    expect(hostDAO.findByName("host1")).andReturn(hostEntity);
+    expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+
+
+    expect(entityManager.merge(hostComponentDesiredStateEntity)).andReturn(hostComponentDesiredStateEntity).anyTimes();
+    entityManager.remove(hostComponentDesiredStateEntity);
+
+
+    hostEntity.removeHostComponentDesiredStateEntity(hostComponentDesiredStateEntity);
+
+    expect(hostDAO.merge(hostEntity)).andReturn(hostEntity).anyTimes();
+
+    replay(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentDesiredStateEntity);
+
+
+    HostComponentDesiredStateDAO dao = new HostComponentDesiredStateDAO();
+    dao.entityManagerProvider = entityManagerProvider;
+    dao.hostDAO = hostDAO;
+
+    dao.remove(hostComponentDesiredStateEntity);
+
+    verify(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentDesiredStateEntity);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentStateDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentStateDAOTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentStateDAOTest.java
new file mode 100644
index 0000000..7c7d0ce
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentStateDAOTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.Provider;
+import junit.framework.Assert;
+import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
+import org.apache.ambari.server.orm.entities.HostEntity;
+import org.junit.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Collection;
+import java.util.HashSet;
+
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * HostComponentStateDAO tests.
+ */
+public class HostComponentStateDAOTest {
+
+  @Test
+  public void testRemove() throws Exception {
+
+    Provider<EntityManager> entityManagerProvider =  createNiceMock(Provider.class);
+    EntityManager entityManager = createNiceMock(EntityManager.class);
+    HostDAO hostDAO = createNiceMock(HostDAO.class);
+    HostEntity hostEntity = createNiceMock(HostEntity.class);
+
+    HostComponentStateEntity hostComponentStateEntity = createNiceMock(HostComponentStateEntity.class);
+
+    expect(hostComponentStateEntity.getHostName()).andReturn("host1");
+    expect(hostDAO.findByName("host1")).andReturn(hostEntity);
+    expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes();
+
+
+    expect(entityManager.merge(hostComponentStateEntity)).andReturn(hostComponentStateEntity).anyTimes();
+    entityManager.remove(hostComponentStateEntity);
+
+
+    hostEntity.removeHostComponentStateEntity(hostComponentStateEntity);
+
+    expect(hostDAO.merge(hostEntity)).andReturn(hostEntity).anyTimes();
+
+    replay(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentStateEntity);
+
+
+    HostComponentStateDAO dao = new HostComponentStateDAO();
+    dao.entityManagerProvider = entityManagerProvider;
+    dao.hostDAO = hostDAO;
+
+    dao.remove(hostComponentStateEntity);
+
+    verify(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentStateEntity);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/HostEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/HostEntityTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/HostEntityTest.java
new file mode 100644
index 0000000..be426db
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/HostEntityTest.java
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.orm.entities;
+
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import static org.junit.Assert.*;
+
+/**
+ * HostEntity tests.
+ */
+public class HostEntityTest {
+
+  @Test
+  public void testGetHostComponentDesiredStateEntities() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentDesiredStateEntity stateEntity = new HostComponentDesiredStateEntity();
+
+    hostEntity.setHostComponentDesiredStateEntities(new HashSet<HostComponentDesiredStateEntity>());
+
+    Collection<HostComponentDesiredStateEntity> stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertTrue(stateEntities.isEmpty());
+    try {
+      stateEntities.add(stateEntity);
+      fail("Expected UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      // expected
+    }
+  }
+
+  @Test
+  public void testAddHostComponentDesiredStateEntity() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentDesiredStateEntity stateEntity = new HostComponentDesiredStateEntity();
+
+    hostEntity.setHostComponentDesiredStateEntities(new HashSet<HostComponentDesiredStateEntity>());
+
+    Collection<HostComponentDesiredStateEntity> stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertTrue(stateEntities.isEmpty());
+
+    hostEntity.addHostComponentDesiredStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertTrue(stateEntities.contains(stateEntity));
+  }
+
+  @Test
+  public void testRemoveHostComponentDesiredStateEntity() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentDesiredStateEntity stateEntity = new HostComponentDesiredStateEntity();
+
+    hostEntity.setHostComponentDesiredStateEntities(new HashSet<HostComponentDesiredStateEntity>());
+
+    Collection<HostComponentDesiredStateEntity> stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertTrue(stateEntities.isEmpty());
+
+    hostEntity.addHostComponentDesiredStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertTrue(stateEntities.contains(stateEntity));
+
+    hostEntity.removeHostComponentDesiredStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentDesiredStateEntities();
+    assertFalse(stateEntities.contains(stateEntity));
+  }
+
+  @Test
+  public void testGetHostComponentStateEntities() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentStateEntity stateEntity = new HostComponentStateEntity();
+
+    hostEntity.setHostComponentStateEntities(new HashSet<HostComponentStateEntity>());
+
+    Collection<HostComponentStateEntity> stateEntities = hostEntity.getHostComponentStateEntities();
+    assertTrue(stateEntities.isEmpty());
+    try {
+      stateEntities.add(stateEntity);
+      fail("Expected UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      // expected
+    }
+
+  }
+
+  @Test
+  public void testAddHostComponentStateEntity() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentStateEntity stateEntity = new HostComponentStateEntity();
+
+    hostEntity.setHostComponentStateEntities(new HashSet<HostComponentStateEntity>());
+
+    Collection<HostComponentStateEntity> stateEntities = hostEntity.getHostComponentStateEntities();
+    assertTrue(stateEntities.isEmpty());
+
+    hostEntity.addHostComponentStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentStateEntities();
+    assertTrue(stateEntities.contains(stateEntity));
+
+  }
+
+  @Test
+  public void testRemoveHostComponentStateEntity() throws Exception {
+    HostEntity hostEntity = new HostEntity();
+    HostComponentStateEntity stateEntity = new HostComponentStateEntity();
+
+    hostEntity.setHostComponentStateEntities(new HashSet<HostComponentStateEntity>());
+
+    Collection<HostComponentStateEntity> stateEntities = hostEntity.getHostComponentStateEntities();
+    assertTrue(stateEntities.isEmpty());
+
+    hostEntity.addHostComponentStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentStateEntities();
+    assertTrue(stateEntities.contains(stateEntity));
+
+    hostEntity.removeHostComponentStateEntity(stateEntity);
+
+    stateEntities = hostEntity.getHostComponentStateEntities();
+    assertFalse(stateEntities.contains(stateEntity));
+
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f18c9fa2/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
index 2e59db4..b5db360 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
@@ -198,9 +198,8 @@ public class UpgradeCatalogHelper {
     componentDesiredStateEntity.setHostComponentStateEntities(Collections.singletonList(hostComponentStateEntity));
     componentDesiredStateEntity.setHostComponentDesiredStateEntities(Collections.singletonList(hostComponentDesiredStateEntity));
 
-    hostEntity.getHostComponentStateEntities().add(hostComponentStateEntity);
-    hostEntity.getHostComponentDesiredStateEntities().add(
-        hostComponentDesiredStateEntity);
+    hostEntity.addHostComponentStateEntity(hostComponentStateEntity);
+    hostEntity.addHostComponentDesiredStateEntity(hostComponentDesiredStateEntity);
 
     clusterServiceEntity.getServiceComponentDesiredStateEntities().add(
         componentDesiredStateEntity);


Mime
View raw message