ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpapirkovs...@apache.org
Subject ambari git commit: AMBARI-11116. Upgrade to 2.0.1, unable to RU (can't get installed). (mpapirkovskyy)
Date Fri, 15 May 2015 14:41:29 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.maint f4777363e -> b66a5bcd9


AMBARI-11116. Upgrade to 2.0.1, unable to RU (can't get installed). (mpapirkovskyy)


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

Branch: refs/heads/branch-2.0.maint
Commit: b66a5bcd9d5c5c652f4129253d273a44dcc89ea9
Parents: f477736
Author: Myroslav Papirkovskyy <mpapyrkovskyy@hortonworks.com>
Authored: Thu May 14 23:38:43 2015 +0300
Committer: Myroslav Papirkovskyy <mpapyrkovskyy@hortonworks.com>
Committed: Fri May 15 17:41:13 2015 +0300

----------------------------------------------------------------------
 .../DistributeRepositoriesActionListener.java   |  1 +
 .../server/orm/dao/AlertDefinitionDAO.java      | 12 +++++++++++-
 .../ambari/server/orm/dao/AlertDispatchDAO.java | 19 +++++++++++++++++++
 .../apache/ambari/server/orm/dao/AlertsDAO.java |  6 ++++++
 .../apache/ambari/server/orm/dao/GroupDAO.java  |  2 ++
 .../orm/dao/KerberosPrincipalHostDAO.java       |  1 +
 .../apache/ambari/server/orm/dao/MemberDAO.java |  1 +
 .../ambari/server/orm/dao/PermissionDAO.java    |  4 ++++
 .../ambari/server/orm/dao/PrincipalDAO.java     |  4 ++++
 .../ambari/server/orm/dao/PrincipalTypeDAO.java |  3 +++
 .../ambari/server/orm/dao/PrivilegeDAO.java     |  6 ++++++
 .../ambari/server/orm/dao/UpgradeDAO.java       |  2 ++
 .../apache/ambari/server/orm/dao/UserDAO.java   |  2 ++
 .../apache/ambari/server/orm/dao/ViewDAO.java   |  3 +++
 .../ambari/server/orm/dao/ViewInstanceDAO.java  |  1 +
 .../AmbariManagementControllerImplTest.java     | 20 ++++++++++++++++++--
 .../HostVersionOutOfSyncListenerTest.java       |  4 ++++
 .../server/orm/dao/AlertDefinitionDAOTest.java  |  5 +++++
 .../server/orm/dao/AlertDispatchDAOTest.java    |  5 +++++
 .../ambari/server/orm/dao/AlertsDAOTest.java    |  6 ++++++
 .../state/cluster/AlertDataManagerTest.java     |  5 +++++
 .../server/state/cluster/ClusterTest.java       |  6 ++++++
 22 files changed, 115 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
index e4b26b1..bb508b5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java
@@ -162,6 +162,7 @@ public class DistributeRepositoriesActionListener {
       // If we know exact host stack version, there will be single execution of a code below
       if (hostVersion.getState() == RepositoryVersionState.INSTALLING) {
         hostVersion.setState(newHostState);
+        hostVersionDAO.get().merge(hostVersion);
 
         // Update state of a cluster stack version
         try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
index 659fb21..680bc2a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
@@ -31,6 +31,7 @@ import org.apache.ambari.server.events.AlertDefinitionChangedEvent;
 import org.apache.ambari.server.events.AlertDefinitionDeleteEvent;
 import org.apache.ambari.server.events.AlertDefinitionRegistrationEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
 import org.apache.ambari.server.state.alert.AlertDefinition;
@@ -105,9 +106,10 @@ public class AlertDefinitionDAO {
    *          the ID of the definition to retrieve.
    * @return the alert definition or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertDefinitionEntity findById(long definitionId) {
     return entityManagerProvider.get().find(AlertDefinitionEntity.class,
-        definitionId);
+      definitionId);
   }
 
   /**
@@ -120,6 +122,7 @@ public class AlertDefinitionDAO {
    *          the name of the definition (not {@code null}).
    * @return the alert definition or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertDefinitionEntity findByName(long clusterId, String definitionName) {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertDefinitionEntity.findByName", AlertDefinitionEntity.class);
@@ -136,6 +139,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions or an empty list if none exist (never
    *         {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findAll() {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertDefinitionEntity.findAll", AlertDefinitionEntity.class);
@@ -149,6 +153,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions or empty list if none exist (never
    *         {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findAll(long clusterId) {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertDefinitionEntity.findAllInCluster", AlertDefinitionEntity.class);
@@ -165,6 +170,7 @@ public class AlertDefinitionDAO {
    *          the IDs of the definitions to retrieve.
    * @return the definition or an empty list (never {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findByIds(List<Long> definitionIds) {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertDefinitionEntity.findByIds", AlertDefinitionEntity.class);
@@ -185,6 +191,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions for the service or empty list if none exist
    *         (never {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findByService(long clusterId,
       String serviceName) {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
@@ -208,6 +215,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions for the services or empty list if none exist
    *         (never {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findByServiceMaster(long clusterId,
       Set<String> services) {
     if (null == services || services.size() == 0) {
@@ -238,6 +246,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions that are not bound to a service or an empty
    *         list (never {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findByServiceComponent(long clusterId,
       String serviceName, String componentName) {
     if (null == serviceName || null == componentName) {
@@ -264,6 +273,7 @@ public class AlertDefinitionDAO {
    * @return all alert definitions that are not bound to a service or an empty
    *         list (never {@code null}).
    */
+  @RequiresSession
   public List<AlertDefinitionEntity> findAgentScoped(long clusterId) {
     TypedQuery<AlertDefinitionEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertDefinitionEntity.findByServiceAndComponent",

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
index 85973b1..22fb76f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDispatchDAO.java
@@ -36,6 +36,7 @@ import org.apache.ambari.server.controller.AlertNoticeRequest;
 import org.apache.ambari.server.controller.RootServiceResponseFactory.Services;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.utilities.PredicateHelper;
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
 import org.apache.ambari.server.orm.entities.AlertNoticeEntity;
@@ -91,6 +92,7 @@ public class AlertDispatchDAO {
    *          the ID of the group to retrieve.
    * @return the group or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertGroupEntity findGroupById(long groupId) {
     return entityManagerProvider.get().find(AlertGroupEntity.class, groupId);
   }
@@ -102,6 +104,7 @@ public class AlertDispatchDAO {
    *          the IDs of the groups to retrieve.
    * @return the groups or an empty list (never {@code null}).
    */
+  @RequiresSession
   public List<AlertGroupEntity> findGroupsById(List<Long> groupIds) {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertGroupEntity.findByIds", AlertGroupEntity.class);
@@ -118,6 +121,7 @@ public class AlertDispatchDAO {
    *          the ID of the target to retrieve.
    * @return the target or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertTargetEntity findTargetById(long targetId) {
     return entityManagerProvider.get().find(AlertTargetEntity.class, targetId);
   }
@@ -129,6 +133,7 @@ public class AlertDispatchDAO {
    *          the IDs of the targets to retrieve.
    * @return the targets or an empty list (never {@code null}).
    */
+  @RequiresSession
   public List<AlertTargetEntity> findTargetsById(List<Long> targetIds) {
     TypedQuery<AlertTargetEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertTargetEntity.findByIds", AlertTargetEntity.class);
@@ -145,6 +150,7 @@ public class AlertDispatchDAO {
    *          the ID of the notification to retrieve.
    * @return the notification or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertNoticeEntity findNoticeById(long noticeId) {
     return entityManagerProvider.get().find(AlertNoticeEntity.class, noticeId);
   }
@@ -156,6 +162,7 @@ public class AlertDispatchDAO {
    *          the UUID of the notification to retrieve.
    * @return the notification or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertNoticeEntity findNoticeByUuid(String uuid) {
     TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertNoticeEntity.findByUuid", AlertNoticeEntity.class);
@@ -172,6 +179,7 @@ public class AlertDispatchDAO {
    * @return the notices that are waiting to be dispatched, or an empty list
    *         (never {@code null}).
    */
+  @RequiresSession
   public List<AlertNoticeEntity> findPendingNotices() {
     TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertNoticeEntity.findByState", AlertNoticeEntity.class);
@@ -188,6 +196,7 @@ public class AlertDispatchDAO {
    *          the name of the group (not {@code null}).
    * @return the alert group or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertGroupEntity findGroupByName(String groupName) {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertGroupEntity.findByName", AlertGroupEntity.class);
@@ -207,6 +216,7 @@ public class AlertDispatchDAO {
    *          the name of the group (not {@code null}).
    * @return the alert group or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertGroupEntity findGroupByName(long clusterId, String groupName) {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertGroupEntity.findByNameInCluster", AlertGroupEntity.class);
@@ -225,6 +235,7 @@ public class AlertDispatchDAO {
    *          the name of the target (not {@code null}).
    * @return the alert target or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertTargetEntity findTargetByName(String targetName) {
     TypedQuery<AlertTargetEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertTargetEntity.findByName", AlertTargetEntity.class);
@@ -239,6 +250,7 @@ public class AlertDispatchDAO {
    *
    * @return all alert groups or empty list if none exist (never {@code null}).
    */
+  @RequiresSession
   public List<AlertGroupEntity> findAllGroups() {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertGroupEntity.findAll", AlertGroupEntity.class);
@@ -252,6 +264,7 @@ public class AlertDispatchDAO {
    * @return all alert groups in the specified cluster or empty list if none
    *         exist (never {@code null}).
    */
+  @RequiresSession
   public List<AlertGroupEntity> findAllGroups(long clusterId) {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertGroupEntity.findAllInCluster", AlertGroupEntity.class);
@@ -266,6 +279,7 @@ public class AlertDispatchDAO {
    *
    * @return all alert targets or empty list if none exist (never {@code null}).
    */
+  @RequiresSession
   public List<AlertTargetEntity> findAllTargets() {
     TypedQuery<AlertTargetEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertTargetEntity.findAll", AlertTargetEntity.class);
@@ -279,6 +293,7 @@ public class AlertDispatchDAO {
    * @return all global alert targets or empty list if none exist (never
    *         {@code null}).
    */
+  @RequiresSession
   public List<AlertTargetEntity> findAllGlobalTargets() {
     TypedQuery<AlertTargetEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertTargetEntity.findAllGlobal", AlertTargetEntity.class);
@@ -296,6 +311,7 @@ public class AlertDispatchDAO {
    *         definition and the definition's service default group or empty list
    *         if none exist (never {@code null}).
    */
+  @RequiresSession
   public List<AlertGroupEntity> findGroupsByDefinition(
       AlertDefinitionEntity definitionEntity) {
 
@@ -319,6 +335,7 @@ public class AlertDispatchDAO {
    *         for an installed service; otherwise {@code null} should not be
    *         possible.
    */
+  @RequiresSession
   public AlertGroupEntity findDefaultServiceGroup(long clusterId,
       String serviceName) {
     TypedQuery<AlertGroupEntity> query = entityManagerProvider.get().createNamedQuery(
@@ -335,6 +352,7 @@ public class AlertDispatchDAO {
    * @return all alert notifications or empty list if none exist (never
    *         {@code null}).
    */
+  @RequiresSession
   public List<AlertNoticeEntity> findAllNotices() {
     TypedQuery<AlertNoticeEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertNoticeEntity.findAll", AlertNoticeEntity.class);
@@ -350,6 +368,7 @@ public class AlertDispatchDAO {
    * @return all alert notifications or empty list if none exist (never
    *         {@code null}).
    */
+  @RequiresSession
   public List<AlertNoticeEntity> findAllNotices(AlertNoticeRequest request) {
     EntityManager entityManager = entityManagerProvider.get();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
index 5435982..94a5660 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertsDAO.java
@@ -95,6 +95,7 @@ public class AlertsDAO {
    *          the ID of the alert to retrieve.
    * @return the alert or {@code null} if none exists.
    */
+  @RequiresSession
   public AlertHistoryEntity findById(long alertId) {
     return entityManagerProvider.get().find(AlertHistoryEntity.class, alertId);
   }
@@ -104,6 +105,7 @@ public class AlertsDAO {
    *
    * @return all alerts or an empty list if none exist (never {@code null}).
    */
+  @RequiresSession
   public List<AlertHistoryEntity> findAll() {
     TypedQuery<AlertHistoryEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertHistoryEntity.findAll", AlertHistoryEntity.class);
@@ -119,6 +121,7 @@ public class AlertsDAO {
    * @return all alerts in the specified cluster or an empty list if none exist
    *         (never {@code null}).
    */
+  @RequiresSession
   public List<AlertHistoryEntity> findAll(long clusterId) {
     TypedQuery<AlertHistoryEntity> query = entityManagerProvider.get().createNamedQuery(
         "AlertHistoryEntity.findAllInCluster", AlertHistoryEntity.class);
@@ -139,6 +142,7 @@ public class AlertsDAO {
    * @return the alerts matching the specified states and cluster, or an empty
    *         list if none.
    */
+  @RequiresSession
   public List<AlertHistoryEntity> findAll(long clusterId,
       List<AlertState> alertStates) {
     if (null == alertStates || alertStates.size() == 0) {
@@ -172,6 +176,7 @@ public class AlertsDAO {
    *          start date.
    * @return the alerts matching the specified date range.
    */
+  @RequiresSession
   public List<AlertHistoryEntity> findAll(long clusterId, Date startDate,
       Date endDate) {
     if (null == startDate && null == endDate) {
@@ -223,6 +228,7 @@ public class AlertsDAO {
    * @param request
    * @return
    */
+  @RequiresSession
   public List<AlertHistoryEntity> findAll(AlertHistoryRequest request) {
     EntityManager entityManager = entityManagerProvider.get();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java
index bd5defb..255c5e6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/GroupDAO.java
@@ -72,6 +72,7 @@ public class GroupDAO {
    *
    * @return the list of groups matching the query
    */
+  @RequiresSession
   public List<GroupEntity> findGroupsByPrincipal(List<PrincipalEntity> principalList) {
     if (principalList == null || principalList.isEmpty()) {
       return Collections.emptyList();
@@ -88,6 +89,7 @@ public class GroupDAO {
    *
    * @return the matching gropu entity
    */
+  @RequiresSession
   public GroupEntity findGroupByPrincipal(PrincipalEntity principal) {
     if (principal == null) {
       return null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
index 64e18bb..26f55a5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
@@ -219,6 +219,7 @@ public class KerberosPrincipalHostDAO {
    *
    * @param entities a collection of KerberosPrincipalHostEntity items to remove
    */
+  @Transactional
   private void remove(List<KerberosPrincipalHostEntity> entities) {
     if (entities != null) {
       for (KerberosPrincipalHostEntity entity : entities) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MemberDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MemberDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MemberDAO.java
index e831db2..15b2995 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MemberDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MemberDAO.java
@@ -65,6 +65,7 @@ public class MemberDAO {
     return daoUtils.selectList(query);
   }
 
+  @RequiresSession
   public List<MemberEntity> findAllMembersByUser(UserEntity userEntity) {
     TypedQuery<MemberEntity> query = entityManagerProvider.get().createQuery("SELECT m FROM MemberEntity m WHERE m.user = :userEntity", MemberEntity.class);
     query.setParameter("userEntity", userEntity);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PermissionDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PermissionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PermissionDAO.java
index 939c32b..4108e7e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PermissionDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PermissionDAO.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
 
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 
@@ -63,6 +64,7 @@ public class PermissionDAO {
    *
    * @return  a matching permission entity or null
    */
+  @RequiresSession
   public PermissionEntity findById(Integer id) {
     return entityManagerProvider.get().find(PermissionEntity.class, id);
   }
@@ -72,6 +74,7 @@ public class PermissionDAO {
    *
    * @return all entities or an empty List
    */
+  @RequiresSession
   public List<PermissionEntity> findAll() {
     TypedQuery<PermissionEntity> query = entityManagerProvider.get().createQuery("SELECT p FROM PermissionEntity p", PermissionEntity.class);
     return daoUtils.selectList(query);
@@ -85,6 +88,7 @@ public class PermissionDAO {
    *
    * @return a matching permission entity or null
    */
+  @RequiresSession
   public PermissionEntity findPermissionByNameAndType(String name, ResourceTypeEntity resourceType) {
     if (name.equals(PermissionEntity.VIEW_USE_PERMISSION_NAME)) {
       // VIEW.USE permission should be available for any type of views

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalDAO.java
index 7ac4f05..3d09227 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalDAO.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
 
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.PrincipalEntity;
 
 import com.google.inject.Inject;
@@ -50,6 +51,7 @@ public class PrincipalDAO {
    *
    * @return  a matching principal type  or null
    */
+  @RequiresSession
   public PrincipalEntity findById(Long id) {
     return entityManagerProvider.get().find(PrincipalEntity.class, id);
   }
@@ -59,6 +61,7 @@ public class PrincipalDAO {
    *
    * @return all principals or an empty List
    */
+  @RequiresSession
   public List<PrincipalEntity> findAll() {
     TypedQuery<PrincipalEntity> query = entityManagerProvider.get().createQuery("SELECT principal FROM PrincipalEntity principal", PrincipalEntity.class);
     return daoUtils.selectList(query);
@@ -70,6 +73,7 @@ public class PrincipalDAO {
    * @param id permission id
    * @return all principals having specified permission
    */
+  @RequiresSession
   public List<PrincipalEntity> findByPermissionId(Integer id) {
     TypedQuery<PrincipalEntity> query = entityManagerProvider.get().createNamedQuery("principalByPrivilegeId", PrincipalEntity.class);
     query.setParameter("permission_id", id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java
index 046345a..1e4f3d8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java
@@ -23,6 +23,7 @@ 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.PrincipalTypeEntity;
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
@@ -53,6 +54,7 @@ public class PrincipalTypeDAO {
    *
    * @return  a matching principal type  or null
    */
+  @RequiresSession
   public PrincipalTypeEntity findById(Integer id) {
     return entityManagerProvider.get().find(PrincipalTypeEntity.class, id);
   }
@@ -62,6 +64,7 @@ public class PrincipalTypeDAO {
    *
    * @return all principal types or an empty List
    */
+  @RequiresSession
   public List<PrincipalTypeEntity> findAll() {
     TypedQuery<PrincipalTypeEntity> query = entityManagerProvider.get().createQuery("SELECT principalType FROM PrincipalTypeEntity principalType", PrincipalTypeEntity.class);
     return daoUtils.selectList(query);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java
index 4fda7bc..772d538 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrivilegeDAO.java
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
 
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.PermissionEntity;
 import org.apache.ambari.server.orm.entities.PrincipalEntity;
 import org.apache.ambari.server.orm.entities.PrivilegeEntity;
@@ -54,6 +55,7 @@ public class PrivilegeDAO {
    *
    * @return a matching privilege or null
    */
+  @RequiresSession
   public PrivilegeEntity findById(Integer id) {
     return entityManagerProvider.get().find(PrivilegeEntity.class, id);
   }
@@ -63,6 +65,7 @@ public class PrivilegeDAO {
    *
    * @return all privileges or an empty List
    */
+  @RequiresSession
   public List<PrivilegeEntity> findAll() {
     TypedQuery<PrivilegeEntity> query = entityManagerProvider.get().createQuery("SELECT privilege FROM PrivilegeEntity privilege", PrivilegeEntity.class);
     return daoUtils.selectList(query);
@@ -74,6 +77,7 @@ public class PrivilegeDAO {
    * @param id ID of the resource
    * @return all resource privileges or an empty list
    */
+  @RequiresSession
   public List<PrivilegeEntity> findByResourceId(Long id) {
     TypedQuery<PrivilegeEntity> query = entityManagerProvider.get().createQuery("SELECT privilege FROM PrivilegeEntity privilege WHERE privilege.resource.id = :resource_id", PrivilegeEntity.class);
     query.setParameter("resource_id", id);
@@ -101,6 +105,7 @@ public class PrivilegeDAO {
    *
    * @return true if the privilege entity already exists
    */
+  @RequiresSession
   public boolean exists(PrincipalEntity principalEntity, ResourceEntity resourceEntity, PermissionEntity permissionEntity) {
     TypedQuery<PrivilegeEntity> query = entityManagerProvider.get().createQuery(
         "SELECT privilege FROM PrivilegeEntity privilege WHERE privilege.principal = :principal AND privilege.resource = :resource AND privilege.permission = :permission", PrivilegeEntity.class);
@@ -120,6 +125,7 @@ public class PrivilegeDAO {
    *
    * @return the list of privileges matching the query
    */
+  @RequiresSession
   public List<PrivilegeEntity> findAllByPrincipal(List<PrincipalEntity> principalList) {
     if (principalList == null || principalList.isEmpty()) {
       return Collections.emptyList();

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
index a9b913f..e6ba152 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UpgradeDAO.java
@@ -126,6 +126,7 @@ public class UpgradeDAO {
    * @param itemId the item id
    * @return the upgrade item entity, or {@code null} if not found
    */
+  @RequiresSession
   public UpgradeItemEntity findUpgradeItem(long itemId) {
     TypedQuery<UpgradeItemEntity> query = entityManagerProvider.get().createQuery(
         "SELECT p FROM UpgradeItemEntity p WHERE p.upgradeItemId = :itemId", UpgradeItemEntity.class);
@@ -141,6 +142,7 @@ public class UpgradeDAO {
    * @param stageId the stage id
    * @return the upgrade entity, or {@code null} if not found
    */
+  @RequiresSession
   public UpgradeItemEntity findUpgradeItemByRequestAndStage(Long requestId, Long stageId) {
     TypedQuery<UpgradeItemEntity> query = entityManagerProvider.get().createQuery(
         "SELECT p FROM UpgradeItemEntity p WHERE p.stageId = :stageId AND p.upgradeGroupEntity.upgradeEntity.requestId = :requestId",

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java
index 2fcb087..12f975e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/UserDAO.java
@@ -95,6 +95,7 @@ public class UserDAO {
    *
    * @return the matching list of user entities
    */
+  @RequiresSession
   public List<UserEntity> findUsersByPrincipal(List<PrincipalEntity> principalList) {
     if (principalList == null || principalList.isEmpty()) {
       return Collections.emptyList();
@@ -111,6 +112,7 @@ public class UserDAO {
    *
    * @return the matching user entity
    */
+  @RequiresSession
   public UserEntity findUserByPrincipal(PrincipalEntity principal) {
     if (principal == null) {
       return null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewDAO.java
index bbbab63..cdc107c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewDAO.java
@@ -22,6 +22,7 @@ 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.ViewEntity;
 
 import javax.persistence.EntityManager;
@@ -46,6 +47,7 @@ public class ViewDAO {
    *
    * @return  a matching view or null
    */
+  @RequiresSession
   public ViewEntity findByName(String viewName) {
     return entityManagerProvider.get().find(ViewEntity.class, viewName);
   }
@@ -73,6 +75,7 @@ public class ViewDAO {
    *
    * @return all views or an empty List
    */
+  @RequiresSession
   public List<ViewEntity> findAll() {
     TypedQuery<ViewEntity> query = entityManagerProvider.get().
         createNamedQuery("allViews", ViewEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewInstanceDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewInstanceDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewInstanceDAO.java
index 91a2e72..6e1d863 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewInstanceDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ViewInstanceDAO.java
@@ -37,6 +37,7 @@ import com.google.inject.persist.Transactional;
  * View Instance Data Access Object.
  */
 @Singleton
+@RequiresSession
 public class ViewInstanceDAO {
   /**
    * JPA entity manager

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index 208218c..e96568f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -23,6 +23,7 @@ import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Module;
+import com.google.inject.persist.UnitOfWork;
 import com.google.inject.util.Modules;
 import junit.framework.Assert;
 import org.apache.ambari.server.AmbariException;
@@ -39,7 +40,10 @@ import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.internal.RequestStageContainer;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.LdapSyncSpecEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.security.authorization.Users;
 import org.apache.ambari.server.security.ldap.AmbariLdapDataPopulator;
 import org.apache.ambari.server.security.ldap.LdapBatchDto;
@@ -1678,15 +1682,20 @@ public class AmbariManagementControllerImplTest {
     String JCE_NAME = "jceName";
     String OJDBC_JAR_NAME = "OjdbcJarName";
     String SERVER_DB_NAME = "ServerDBName";
+    String clusterName = "test_cluster";
 
     ActionManager manager = createNiceMock(ActionManager.class);
     StackId stackId = createNiceMock(StackId.class);
     Cluster cluster = createNiceMock(Cluster.class);
     Injector injector = createNiceMock(Injector.class);
     Configuration configuration = createNiceMock(Configuration.class);
+    ClusterVersionDAO clusterVersionDAO = createNiceMock(ClusterVersionDAO.class);
+    ClusterVersionEntity clusterVersionEntity = createNiceMock(ClusterVersionEntity.class);
+    RepositoryVersionEntity repositoryVersionEntity = createNiceMock(RepositoryVersionEntity.class);
 
 
     expect(cluster.getDesiredStackVersion()).andReturn(stackId);
+    expect(cluster.getClusterName()).andReturn(clusterName);
     expect(stackId.getStackName()).andReturn(SOME_STACK_NAME).anyTimes();
     expect(stackId.getStackVersion()).andReturn(SOME_STACK_VERSION).anyTimes();
     expect(configuration.getMySQLJarName()).andReturn(MYSQL_JAR);
@@ -1695,8 +1704,11 @@ public class AmbariManagementControllerImplTest {
     expect(configuration.getJCEName()).andReturn(JCE_NAME);
     expect(configuration.getOjdbcJarName()).andReturn(OJDBC_JAR_NAME);
     expect(configuration.getServerDBName()).andReturn(SERVER_DB_NAME);
+    expect(clusterVersionDAO.findByClusterAndStateCurrent(eq(clusterName))).andReturn(clusterVersionEntity);
+    expect(clusterVersionEntity.getRepositoryVersion()).andReturn(repositoryVersionEntity);
+    expect(repositoryVersionEntity.getVersion()).andReturn("stub");
 
-    replay(manager, clusters, cluster, injector, stackId, configuration);
+    replay(manager, clusters, cluster, injector, stackId, configuration, clusterVersionDAO, clusterVersionEntity, repositoryVersionEntity);
 
     AmbariManagementControllerImpl ambariManagementControllerImpl =
             createMockBuilder(AmbariManagementControllerImpl.class)
@@ -1723,9 +1735,13 @@ public class AmbariManagementControllerImplTest {
     f.setAccessible(true);
     f.set(helper, configuration);
 
+    f = helperClass.getDeclaredField("clusterVersionDAO");
+    f.setAccessible(true);
+    f.set(helper, clusterVersionDAO);
+
     Map<String, String> defaultHostParams = helper.createDefaultHostParams(cluster);
 
-    assertEquals(defaultHostParams.size(), 10);
+    assertEquals(defaultHostParams.size(), 11);
     assertEquals(defaultHostParams.get(DB_DRIVER_FILENAME), MYSQL_JAR);
     assertEquals(defaultHostParams.get(STACK_NAME), SOME_STACK_NAME);
     assertEquals(defaultHostParams.get(STACK_VERSION), SOME_STACK_VERSION);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index f2417bd..c54aaf3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -39,6 +39,7 @@ import javax.persistence.RollbackException;
 import com.google.inject.AbstractModule;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
+import com.google.inject.persist.UnitOfWork;
 import com.google.inject.util.Modules;
 
 import org.apache.ambari.server.AmbariException;
@@ -87,6 +88,8 @@ public class HostVersionOutOfSyncListenerTest {
   public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
+    //TODO unit tests rely on single session for all operations - probably should be fixed - testOnServiceEvent()
+    injector.getInstance(UnitOfWork.class).begin();
     clusters = injector.getInstance(Clusters.class);
     metaInfo = injector.getInstance(AmbariMetaInfo.class);
     helper = injector.getInstance(OrmTestHelper.class);
@@ -107,6 +110,7 @@ public class HostVersionOutOfSyncListenerTest {
 
   @After
   public void teardown() {
+    injector.getInstance(UnitOfWork.class).end();
     injector.getInstance(PersistService.class).stop();
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
index acf25d2..5d23a00 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAOTest.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.TimeZone;
 import java.util.UUID;
 
+import com.google.inject.persist.UnitOfWork;
 import org.apache.ambari.server.controller.RootServiceResponseFactory;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -76,6 +77,8 @@ public class AlertDefinitionDAOTest {
   public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
+    //TODO unit tests rely on single session for all operations - probably should be fixed
+    injector.getInstance(UnitOfWork.class).begin();
 
     dispatchDao = injector.getInstance(AlertDispatchDAO.class);
     dao = injector.getInstance(AlertDefinitionDAO.class);
@@ -156,6 +159,8 @@ public class AlertDefinitionDAOTest {
 
   @After
   public void teardown() {
+    injector.getInstance(UnitOfWork.class).end();
+
     injector.getInstance(PersistService.class).stop();
     injector = null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
index 92866d7..1e30a0e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.UUID;
 
+import com.google.inject.persist.UnitOfWork;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.AlertNoticeRequest;
 import org.apache.ambari.server.controller.internal.AlertNoticeResourceProvider;
@@ -97,6 +98,9 @@ public class AlertDispatchDAOTest {
   public void setup() throws Exception {
     m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
     m_injector.getInstance(GuiceJpaInitializer.class);
+    //TODO unit tests rely on single session for all operations - probably should be fixed
+    m_injector.getInstance(UnitOfWork.class).begin();
+
     m_dao = m_injector.getInstance(AlertDispatchDAO.class);
     m_alertsDao = m_injector.getInstance(AlertsDAO.class);
     m_definitionDao = m_injector.getInstance(AlertDefinitionDAO.class);
@@ -133,6 +137,7 @@ public class AlertDispatchDAOTest {
    */
   @After
   public void teardown() throws Exception {
+    m_injector.getInstance(UnitOfWork.class).end();
     m_injector.getInstance(PersistService.class).stop();
     m_injector = null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
index e6a95ae..5d5642e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertsDAOTest.java
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.TimeZone;
 import java.util.UUID;
 
+import com.google.inject.persist.UnitOfWork;
 import org.apache.ambari.server.controller.AlertCurrentRequest;
 import org.apache.ambari.server.controller.AlertHistoryRequest;
 import org.apache.ambari.server.controller.internal.AlertHistoryResourceProvider;
@@ -100,6 +101,10 @@ public class AlertsDAOTest {
   public void setup() throws Exception {
     m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
     m_injector.getInstance(GuiceJpaInitializer.class);
+
+    //TODO unit tests rely on single session for all operations - probably should be fixed - setup() method
+    m_injector.getInstance(UnitOfWork.class).begin();
+
     m_helper = m_injector.getInstance(OrmTestHelper.class);
     m_dao = m_injector.getInstance(AlertsDAO.class);
     m_definitionDao = m_injector.getInstance(AlertDefinitionDAO.class);
@@ -194,6 +199,7 @@ public class AlertsDAOTest {
    */
   @After
   public void teardown() {
+    m_injector.getInstance(UnitOfWork.class).end();
     m_injector.getInstance(PersistService.class).stop();
     m_injector = null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
index c289bcc..156e441 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/AlertDataManagerTest.java
@@ -29,6 +29,7 @@ import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicReference;
 
+import com.google.inject.persist.UnitOfWork;
 import org.apache.ambari.server.events.AlertEvent;
 import org.apache.ambari.server.events.AlertReceivedEvent;
 import org.apache.ambari.server.events.AlertStateChangeEvent;
@@ -105,6 +106,9 @@ public class AlertDataManagerTest {
   public void setup() throws Exception {
     m_injector = Guice.createInjector(new InMemoryDefaultTestModule());
     m_injector.getInstance(GuiceJpaInitializer.class);
+    //TODO unit tests rely on single session for all operations - probably should be fixed - testAlertNotices()
+    m_injector.getInstance(UnitOfWork.class).begin();
+
     m_helper = m_injector.getInstance(OrmTestHelper.class);
     m_dao = m_injector.getInstance(AlertsDAO.class);
     m_dispatchDao = m_injector.getInstance(AlertDispatchDAO.class);
@@ -140,6 +144,7 @@ public class AlertDataManagerTest {
 
   @After
   public void teardown() {
+    m_injector.getInstance(UnitOfWork.class).end();
     m_injector.getInstance(PersistService.class).stop();
     m_injector = null;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b66a5bcd/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index e444828..b3ece82 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -42,6 +42,7 @@ import java.util.Set;
 import javax.persistence.EntityManager;
 import javax.persistence.RollbackException;
 
+import com.google.inject.persist.UnitOfWork;
 import junit.framework.Assert;
 
 import org.apache.ambari.server.AmbariException;
@@ -1432,6 +1433,9 @@ public class ClusterTest {
    */
   @Test
   public void testTransitionHostVersionAdvanced() throws Exception {
+    //TODO unit tests rely on single session for all operations - probably should be fixed - this test only
+    injector.getInstance(UnitOfWork.class).begin();
+
     String clusterName = "c1";
     String v1 = "2.2.0-123";
     StackId stackId = new StackId("HDP-2.2.0");
@@ -1605,6 +1609,8 @@ public class ClusterTest {
         Assert.assertEquals(hve.getState(), RepositoryVersionState.UPGRADED);
       }
     }
+
+    injector.getInstance(UnitOfWork.class).end();
   }
 
   @Test


Mime
View raw message