ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject [2/2] git commit: AMBARI-5167. Takes 48 seconds on 800 node cluster for HostComponent creation. (Myroslav Papirkovskyy via swagle)
Date Fri, 21 Mar 2014 22:09:17 GMT
AMBARI-5167. Takes 48 seconds on 800 node cluster for HostComponent creation. (Myroslav Papirkovskyy via swagle)


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

Branch: refs/heads/branch-1.5.0
Commit: 8bfd1659eaa12dc85718577a3902477b2f37d4ae
Parents: 982c607
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Mar 21 15:08:18 2014 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Mar 21 15:08:18 2014 -0700

----------------------------------------------------------------------
 .../persist/jpa/AmbariJpaPersistModule.java     | 198 +++++++++++++++++++
 .../persist/jpa/AmbariJpaPersistService.java    |  37 ++++
 .../AmbariManagementControllerImpl.java         |  29 ++-
 .../server/controller/ControllerModule.java     |   7 +-
 .../controller/ServiceComponentHostRequest.java |  18 +-
 .../orm/AmbariJpaLocalTxnInterceptor.java       | 160 +++++++++++++++
 .../orm/AmbariLocalSessionInterceptor.java      |  60 ++++++
 .../ambari/server/orm/RequiresSession.java      |  39 ++++
 .../ambari/server/orm/dao/BlueprintDAO.java     |   3 +
 .../ambari/server/orm/dao/ClusterDAO.java       |  19 +-
 .../server/orm/dao/ClusterServiceDAO.java       |   7 +-
 .../ambari/server/orm/dao/ClusterStateDAO.java  |   5 +-
 .../orm/dao/ConfigGroupConfigMappingDAO.java    |   7 +-
 .../ambari/server/orm/dao/ConfigGroupDAO.java   |  42 ++--
 .../orm/dao/ConfigGroupHostMappingDAO.java      |  10 +-
 .../server/orm/dao/ExecutionCommandDAO.java     |   5 +-
 .../orm/dao/HostComponentDesiredStateDAO.java   |  25 +--
 .../server/orm/dao/HostComponentStateDAO.java   |  25 +--
 .../server/orm/dao/HostConfigMappingDAO.java    |  14 +-
 .../apache/ambari/server/orm/dao/HostDAO.java   |   7 +-
 .../server/orm/dao/HostRoleCommandDAO.java      | 149 +++++++-------
 .../ambari/server/orm/dao/HostStateDAO.java     |   5 +-
 .../ambari/server/orm/dao/KeyValueDAO.java      |   5 +-
 .../ambari/server/orm/dao/MetainfoDAO.java      |   5 +-
 .../ambari/server/orm/dao/RequestDAO.java       |  15 +-
 .../orm/dao/RequestScheduleBatchRequestDAO.java |   7 +-
 .../server/orm/dao/RequestScheduleDAO.java      |   7 +-
 .../apache/ambari/server/orm/dao/RoleDAO.java   |   5 +-
 .../server/orm/dao/RoleSuccessCriteriaDAO.java  |   5 +-
 .../dao/ServiceComponentDesiredStateDAO.java    |  27 +--
 .../server/orm/dao/ServiceDesiredStateDAO.java  |  27 +--
 .../apache/ambari/server/orm/dao/StageDAO.java  |  57 +++---
 .../apache/ambari/server/orm/dao/UserDAO.java   |  13 +-
 .../server/state/ServiceComponentImpl.java      |   3 +-
 .../apache/ambari/server/state/ServiceImpl.java |   2 +-
 .../server/state/cluster/ClusterImpl.java       |   2 +-
 .../ambari/server/agent/AgentResourceTest.java  |   4 +-
 .../apache/ambari/server/orm/TestOrmImpl.java   |   6 +
 .../AmbariLocalUserDetailsServiceTest.java      |   2 -
 39 files changed, 807 insertions(+), 256 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistModule.java b/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistModule.java
new file mode 100644
index 0000000..4e4dd35
--- /dev/null
+++ b/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistModule.java
@@ -0,0 +1,198 @@
+/**
+ * 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 com.google.inject.persist.jpa;
+
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import com.google.inject.persist.PersistModule;
+import com.google.inject.persist.PersistService;
+import com.google.inject.persist.UnitOfWork;
+import com.google.inject.persist.finder.DynamicFinder;
+import com.google.inject.persist.finder.Finder;
+import com.google.inject.util.Providers;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.ambari.server.orm.AmbariJpaLocalTxnInterceptor;
+import org.apache.ambari.server.orm.AmbariLocalSessionInterceptor;
+import org.apache.ambari.server.orm.RequiresSession;
+
+import static com.google.inject.matcher.Matchers.annotatedWith;
+import static com.google.inject.matcher.Matchers.any;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Copy of guice persist module for local modifications
+ */
+public class AmbariJpaPersistModule extends PersistModule {
+  private final String jpaUnit;
+
+  public AmbariJpaPersistModule(String jpaUnit) {
+    if (null != jpaUnit && jpaUnit.length() > 0) {
+      this.jpaUnit = jpaUnit;
+    } else {
+      throw new IllegalArgumentException("jpaUnit should not be null");
+    }
+  }
+
+  private Properties properties;
+  private MethodInterceptor transactionInterceptor;
+  private MethodInterceptor sessionInterceptor;
+
+  @Override protected void configurePersistence() {
+    bindConstant().annotatedWith(Jpa.class).to(jpaUnit);
+
+    if (null != properties) {
+      bind(Properties.class).annotatedWith(Jpa.class).toInstance(properties);
+    } else {
+      bind(Properties.class).annotatedWith(Jpa.class)
+          .toProvider(Providers.<Properties>of(null));
+    }
+
+    bind(AmbariJpaPersistService.class).in(Singleton.class);
+
+    bind(PersistService.class).to(AmbariJpaPersistService.class);
+    bind(UnitOfWork.class).to(AmbariJpaPersistService.class);
+    bind(EntityManager.class).toProvider(AmbariJpaPersistService.class);
+    bind(EntityManagerFactory.class)
+        .toProvider(JpaPersistService.EntityManagerFactoryProvider.class);
+
+
+
+    transactionInterceptor = new AmbariJpaLocalTxnInterceptor();
+    requestInjection(transactionInterceptor);
+    sessionInterceptor = new AmbariLocalSessionInterceptor();
+    requestInjection(sessionInterceptor);
+
+
+    // Bind dynamic finders.
+    for (Class<?> finder : dynamicFinders) {
+      bindFinder(finder);
+    }
+
+    bindInterceptor(annotatedWith(RequiresSession.class), any(), sessionInterceptor);
+    bindInterceptor(any(), annotatedWith(RequiresSession.class), sessionInterceptor);
+  }
+
+
+
+  @Override protected MethodInterceptor getTransactionInterceptor() {
+    return transactionInterceptor;
+  }
+
+  /**
+   * Configures the JPA persistence provider with a set of properties.
+   *
+   * @param properties A set of name value pairs that configure a JPA persistence
+   * provider as per the specification.
+   */
+  public AmbariJpaPersistModule properties(Properties properties) {
+    this.properties = properties;
+    return this;
+  }
+
+  private final List<Class<?>> dynamicFinders = Lists.newArrayList();
+
+  /**
+   * Adds an interface to this module to use as a dynamic finder.
+   *
+   * @param iface Any interface type whose methods are all dynamic finders.
+   */
+  public <T> AmbariJpaPersistModule addFinder(Class<T> iface) {
+    dynamicFinders.add(iface);
+    return this;
+  }
+
+  private <T> void bindFinder(Class<T> iface) {
+    if (!isDynamicFinderValid(iface)) {
+      return;
+    }
+
+    InvocationHandler finderInvoker = new InvocationHandler() {
+      @Inject
+      JpaFinderProxy finderProxy;
+
+      public Object invoke(final Object thisObject, final Method method, final Object[] args)
+          throws Throwable {
+
+        // Don't intercept non-finder methods like equals and hashcode.
+        if (!method.isAnnotationPresent(Finder.class)) {
+          // This is not ideal, we are using the invocation handler's equals
+          // and hashcode as a proxy (!) for the proxy's equals and hashcode.
+          return method.invoke(this, args);
+        }
+
+        return finderProxy.invoke(new MethodInvocation() {
+          public Method getMethod() {
+            return method;
+          }
+
+          public Object[] getArguments() {
+            return null == args ? new Object[0] : args;
+          }
+
+          public Object proceed() throws Throwable {
+            return method.invoke(thisObject, args);
+          }
+
+          public Object getThis() {
+            throw new UnsupportedOperationException("Bottomless proxies don't expose a this.");
+          }
+
+          public AccessibleObject getStaticPart() {
+            throw new UnsupportedOperationException();
+          }
+        });
+      }
+    };
+    requestInjection(finderInvoker);
+
+    @SuppressWarnings("unchecked") // Proxy must produce instance of type given.
+        T proxy = (T) Proxy
+        .newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[] { iface },
+            finderInvoker);
+
+    bind(iface).toInstance(proxy);
+  }
+
+  private boolean isDynamicFinderValid(Class<?> iface) {
+    boolean valid = true;
+    if (!iface.isInterface()) {
+      addError(iface + " is not an interface. Dynamic Finders must be interfaces.");
+      valid = false;
+    }
+
+    for (Method method : iface.getMethods()) {
+      DynamicFinder finder = DynamicFinder.from(method);
+      if (null == finder) {
+        addError("Dynamic Finder methods must be annotated with @Finder, but " + iface
+            + "." + method.getName() + " was not");
+        valid = false;
+      }
+    }
+    return valid;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistService.java b/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistService.java
new file mode 100644
index 0000000..1f10d43
--- /dev/null
+++ b/ambari-server/src/main/java/com/google/inject/persist/jpa/AmbariJpaPersistService.java
@@ -0,0 +1,37 @@
+/**
+ * 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 com.google.inject.persist.jpa;
+
+
+import com.google.inject.Inject;
+import com.google.inject.internal.util.$Nullable;
+
+import java.util.Properties;
+
+/**
+ * Override non-public class limitations as we need non-interface method
+ */
+public class AmbariJpaPersistService extends JpaPersistService {
+
+  @Inject
+  public AmbariJpaPersistService(@Jpa String persistenceUnitName, @$Nullable @Jpa Properties persistenceProperties) {
+    super(persistenceUnitName, persistenceProperties);
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 9068282..951a619 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -498,6 +498,11 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     }
 
     // now doing actual work
+    persistServiceComponentHosts(requests);
+  }
+
+  @Transactional
+  void persistServiceComponentHosts(Set<ServiceComponentHostRequest> requests) throws AmbariException {
     for (ServiceComponentHostRequest request : requests) {
       Cluster cluster = clusters.getCluster(request.getClusterName());
       Service s = cluster.getService(request.getServiceName());
@@ -526,6 +531,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     }
   }
 
+
   @Override
   public synchronized void createConfiguration(
       ConfigurationRequest request) throws AmbariException {
@@ -645,15 +651,20 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
 
   private Set<ServiceComponentHostResponse> getHostComponents(
       ServiceComponentHostRequest request) throws AmbariException {
+    LOG.debug("Processing request {}", request);
+
     if (request.getClusterName() == null
         || request.getClusterName().isEmpty()) {
-      throw new IllegalArgumentException("Invalid arguments, cluster name should not be null");
+      IllegalArgumentException e = new IllegalArgumentException("Invalid arguments, cluster name should not be null");
+      LOG.debug("Cluster not specified in request", e);
+      throw e;
     }
 
     final Cluster cluster;
     try {
       cluster = clusters.getCluster(request.getClusterName());
     } catch (ClusterNotFoundException e) {
+      LOG.error("Cluster not found ", e);
       throw new ParentObjectNotFoundException("Parent Cluster resource doesn't exist", e);
     }
 
@@ -661,10 +672,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       try {
         if (!clusters.getClustersForHost(request.getHostname()).contains(cluster)) {
           // case where host exists but not associated with given cluster
+          LOG.error("Host doesn't belong to cluster");
           throw new ParentObjectNotFoundException("Parent Host resource doesn't exist",
               new HostNotFoundException(request.getClusterName(), request.getHostname()));
         }
       } catch (HostNotFoundException e) {
+        LOG.error("Host not found", e);
         // creating new HostNotFoundException to add cluster name
         throw new ParentObjectNotFoundException("Parent Host resource doesn't exist",
             new HostNotFoundException(request.getClusterName(), request.getHostname()));
@@ -686,6 +699,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
         }
         if (serviceName == null
             || serviceName.isEmpty()) {
+          LOG.error("Unable to find service for component {}", request.getComponentName());
           throw new ServiceComponentHostNotFoundException(
               cluster.getClusterName(), null, request.getComponentName(), request.getHostname());
         }
@@ -748,8 +762,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
           try {
             if (serviceComponentHostMap == null
                 || !serviceComponentHostMap.containsKey(request.getHostname())) {
-              throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
+              ServiceComponentHostNotFoundException e = new ServiceComponentHostNotFoundException(cluster.getClusterName(),
                 s.getName(), sc.getName(), request.getHostname());
+              throw e;
             }
 
             ServiceComponentHost sch = serviceComponentHostMap.get(request.getHostname());
@@ -779,9 +794,11 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
             response.add(r);
           } catch (ServiceComponentHostNotFoundException e) {
             if (request.getServiceName() != null && request.getComponentName() != null) {
+              LOG.error("ServiceComponentHost not found ", e);
               throw new ServiceComponentHostNotFoundException(cluster.getClusterName(),
                   request.getServiceName(), request.getComponentName(), request.getHostname());
             } else {
+              LOG.debug("Ignoring not specified host_component ", e);
               // ignore this since host_component was not specified
               // this is an artifact of how we get host_components and can happen
               // in case where we get all host_components for a host
@@ -2178,6 +2195,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   @Override
   public Set<ServiceComponentHostResponse> getHostComponents(
       Set<ServiceComponentHostRequest> requests) throws AmbariException {
+    LOG.debug("Processing requests: {}", requests);
     Set<ServiceComponentHostResponse> response =
         new HashSet<ServiceComponentHostResponse>();
     for (ServiceComponentHostRequest request : requests) {
@@ -2188,6 +2206,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
           // only throw exception if 1 request.
           // there will be > 1 request in case of OR predicate
           throw e;
+        } else {
+          LOG.debug("Ignoring not found exception due to other requests", e);
         }
       } catch (ServiceNotFoundException e) {
         if (requests.size() == 1) {
@@ -2196,6 +2216,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
           // In 'OR' case, a host_component may be included in predicate
           // that has no corresponding service
           throw e;
+        } else {
+          LOG.debug("Ignoring not found exception due to other requests", e);
         }
       } catch (ServiceComponentNotFoundException e) {
         if (requests.size() == 1) {
@@ -2204,6 +2226,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
           // In 'OR' case, a host_component may be included in predicate
           // that has no corresponding component
           throw e;
+        } else {
+          LOG.debug("Ignoring not found exception due to other requests", e);
         }
       } catch (ParentObjectNotFoundException e) {
         // If there is only one request, always throw exception.
@@ -2217,6 +2241,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
             if (r.getHostname() == null) {
               // host_name provided in query since all requests don't have host_name set
               throwException = false;
+              LOG.debug("HostNotFoundException ignored", e);
               break;
             }
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 98a7086..86c11cb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -24,7 +24,8 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
 import com.google.inject.assistedinject.FactoryModuleBuilder;
 import com.google.inject.name.Names;
-import com.google.inject.persist.jpa.JpaPersistModule;
+import com.google.inject.persist.PersistModule;
+import com.google.inject.persist.jpa.AmbariJpaPersistModule;
 import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.actionmanager.ActionDBAccessorImpl;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
@@ -153,9 +154,9 @@ public class ControllerModule extends AbstractModule {
     requestStaticInjection(ExecutionCommandWrapper.class);
   }
 
-  private JpaPersistModule buildJpaPersistModule() {
+  private PersistModule buildJpaPersistModule() {
     PersistenceType persistenceType = configuration.getPersistenceType();
-    JpaPersistModule jpaPersistModule = new JpaPersistModule(Configuration.JDBC_UNIT_NAME);
+    AmbariJpaPersistModule jpaPersistModule = new AmbariJpaPersistModule(Configuration.JDBC_UNIT_NAME);
 
     Properties properties = new Properties();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
index d9c7928..6536bd5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ServiceComponentHostRequest.java
@@ -159,16 +159,14 @@ public class ServiceComponentHostRequest {
 
   public String toString() {
     StringBuilder sb = new StringBuilder();
-    sb.append("{"
-        + " clusterName=" + clusterName
-        + ", serviceName=" + serviceName
-        + ", componentName=" + componentName
-        + ", hostname=" + hostname
-        + ", desiredState=" + desiredState
-        + ", desiredStackId=" + desiredStackId
-        + ", staleConfig=" + staleConfig
-        + ", adminState=" + adminState
-        + "}");
+    sb.append("{" + " clusterName=").append(clusterName)
+      .append(", serviceName=").append(serviceName)
+      .append(", componentName=").append(componentName)
+      .append(", hostname=").append(hostname)
+      .append(", desiredState=").append(desiredState)
+      .append(", desiredStackId=").append(desiredStackId)
+      .append(", staleConfig=").append(staleConfig)
+      .append(", adminState=").append(adminState).append("}");
     return sb.toString();
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariJpaLocalTxnInterceptor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariJpaLocalTxnInterceptor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariJpaLocalTxnInterceptor.java
new file mode 100644
index 0000000..98ca484
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariJpaLocalTxnInterceptor.java
@@ -0,0 +1,160 @@
+/*
+ * 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;
+
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
+import com.google.inject.persist.UnitOfWork;
+import com.google.inject.persist.jpa.AmbariJpaPersistService;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+import java.lang.reflect.Method;
+
+public class AmbariJpaLocalTxnInterceptor implements MethodInterceptor {
+
+  @Inject
+  private final AmbariJpaPersistService emProvider = null;
+
+  @Inject
+  private final UnitOfWork unitOfWork = null;
+
+  @Transactional
+  private static class Internal {}
+
+  // Tracks if the unit of work was begun implicitly by this transaction.
+  private final ThreadLocal<Boolean> didWeStartWork = new ThreadLocal<Boolean>();
+
+  public Object invoke(MethodInvocation methodInvocation) throws Throwable {
+
+    // Should we start a unit of work?
+    if (!emProvider.isWorking()) {
+      emProvider.begin();
+      didWeStartWork.set(true);
+    }
+
+    Transactional transactional = readTransactionMetadata(methodInvocation);
+    EntityManager em = this.emProvider.get();
+
+    // Allow 'joining' of transactions if there is an enclosing @Transactional method.
+    if (em.getTransaction().isActive()) {
+      return methodInvocation.proceed();
+    }
+
+    final EntityTransaction txn = em.getTransaction();
+    txn.begin();
+
+    Object result;
+    try {
+      result = methodInvocation.proceed();
+
+    } catch (Exception e) {
+      //commit transaction only if rollback didnt occur
+      if (rollbackIfNecessary(transactional, e, txn)) {
+        txn.commit();
+      }
+
+      //propagate whatever exception is thrown anyway
+      throw e;
+    } finally {
+      // Close the em if necessary (guarded so this code doesn't run unless catch fired).
+      if (null != didWeStartWork.get() && !txn.isActive()) {
+        didWeStartWork.remove();
+        unitOfWork.end();
+      }
+    }
+
+    //everything was normal so commit the txn (do not move into try block above as it
+    //  interferes with the advised method's throwing semantics)
+    try {
+      txn.commit();
+    } finally {
+      //close the em if necessary
+      if (null != didWeStartWork.get() ) {
+        didWeStartWork.remove();
+        unitOfWork.end();
+      }
+    }
+
+    //or return result
+    return result;
+  }
+
+  // TODO Cache this method's results.
+  private Transactional readTransactionMetadata(MethodInvocation methodInvocation) {
+    Transactional transactional;
+    Method method = methodInvocation.getMethod();
+    Class<?> targetClass = methodInvocation.getThis().getClass();
+
+    transactional = method.getAnnotation(Transactional.class);
+    if (null == transactional) {
+      // If none on method, try the class.
+      transactional = targetClass.getAnnotation(Transactional.class);
+    }
+    if (null == transactional) {
+      // If there is no transactional annotation present, use the default
+      transactional = Internal.class.getAnnotation(Transactional.class);
+    }
+
+    return transactional;
+  }
+
+  /**
+   * Returns True if rollback DID NOT HAPPEN (i.e. if commit should continue).
+   *
+   * @param transactional The metadata annotaiton of the method
+   * @param e The exception to test for rollback
+   * @param txn A JPA Transaction to issue rollbacks on
+   */
+  private boolean rollbackIfNecessary(Transactional transactional, Exception e,
+                                      EntityTransaction txn) {
+    boolean commit = true;
+
+    //check rollback clauses
+    for (Class<? extends Exception> rollBackOn : transactional.rollbackOn()) {
+
+      //if one matched, try to perform a rollback
+      if (rollBackOn.isInstance(e)) {
+        commit = false;
+
+        //check ignore clauses (supercedes rollback clause)
+        for (Class<? extends Exception> exceptOn : transactional.ignore()) {
+          //An exception to the rollback clause was found, DON'T rollback
+          // (i.e. commit and throw anyway)
+          if (exceptOn.isInstance(e)) {
+            commit = true;
+            break;
+          }
+        }
+
+        //rollback only if nothing matched the ignore check
+        if (!commit) {
+          txn.rollback();
+        }
+        //otherwise continue to commit
+
+        break;
+      }
+    }
+
+    return commit;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariLocalSessionInterceptor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariLocalSessionInterceptor.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariLocalSessionInterceptor.java
new file mode 100644
index 0000000..fde96c5
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/AmbariLocalSessionInterceptor.java
@@ -0,0 +1,60 @@
+/**
+ * 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;
+
+
+import com.google.inject.Inject;
+import com.google.inject.persist.jpa.AmbariJpaPersistService;
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+
+/**
+ * AOP interceptor to provide session borders
+ */
+public class AmbariLocalSessionInterceptor implements MethodInterceptor {
+
+  @Inject
+  private final AmbariJpaPersistService emProvider = null;
+
+  private final ThreadLocal<Boolean> didWeStartWork = new ThreadLocal<Boolean>();
+
+  @Override
+  public Object invoke(MethodInvocation invocation) throws Throwable {
+    if (!emProvider.isWorking()) {
+      emProvider.begin();
+      didWeStartWork.set(true);
+
+      try {
+        return invocation.proceed();
+      } finally {
+        if (null != didWeStartWork.get()) {
+          didWeStartWork.remove();
+          emProvider.end();
+        }
+      }
+
+    } else {
+      //if session was in progress just proceed without additional checks
+      return invocation.proceed();
+    }
+
+
+
+
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/RequiresSession.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/RequiresSession.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/RequiresSession.java
new file mode 100644
index 0000000..8ff6457
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/RequiresSession.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Any method or class marked with annotation treated as requiring Jpa session.
+ * Marking method with {@code @RequiresSession} will start session before method call and close after.
+ * If session already in progress it will be ignored.
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface RequiresSession {
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
index 3d5fe78..0cbaedc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/BlueprintDAO.java
@@ -23,6 +23,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.BlueprintEntity;
 
 import javax.persistence.EntityManager;
@@ -49,6 +50,7 @@ public class BlueprintDAO {
    *
    * @return  a matching blueprint or null
    */
+  @RequiresSession
   public BlueprintEntity findByName(String blueprint_name) {
     return entityManagerProvider.get().find(BlueprintEntity.class, blueprint_name);
   }
@@ -58,6 +60,7 @@ public class BlueprintDAO {
    *
    * @return all blueprints or an empty List
    */
+  @RequiresSession
   public List<BlueprintEntity> findAll() {
     TypedQuery<BlueprintEntity> query = entityManagerProvider.get().
         createNamedQuery("allBlueprints", BlueprintEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
index 6060edc..7f5b3ce 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterDAO.java
@@ -25,6 +25,7 @@ import javax.persistence.NoResultException;
 import javax.persistence.TypedQuery;
 
 import com.google.inject.Singleton;
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.ClusterConfigEntity;
 import org.apache.ambari.server.orm.entities.ClusterConfigEntityPK;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
@@ -44,12 +45,12 @@ public class ClusterDAO {
    * @param id ID of Cluster
    * @return Found entity or NULL
    */
-  @Transactional
+  @RequiresSession
   public ClusterEntity findById(long id) {
     return entityManagerProvider.get().find(ClusterEntity.class, id);
   }
 
-  @Transactional
+  @RequiresSession
   public ClusterEntity findByName(String clusterName) {
     TypedQuery<ClusterEntity> query = entityManagerProvider.get().createNamedQuery("clusterByName", ClusterEntity.class);
     query.setParameter("clusterName", clusterName);
@@ -60,7 +61,7 @@ public class ClusterDAO {
     }
   }
 
-  @Transactional
+  @RequiresSession
   public List<ClusterEntity> findAll() {
     TypedQuery<ClusterEntity> query = entityManagerProvider.get().createNamedQuery("allClusters", ClusterEntity.class);
     try {
@@ -70,6 +71,12 @@ public class ClusterDAO {
     return null;
   }
 
+  @RequiresSession
+  public ClusterConfigEntity findConfig(ClusterConfigEntityPK configEntityPK) {
+    return entityManagerProvider.get().find(ClusterConfigEntity.class,
+      configEntityPK);
+  }
+
   /**
    * Create Cluster entity in Database
    * @param clusterEntity entity to create
@@ -87,12 +94,6 @@ public class ClusterDAO {
     entityManagerProvider.get().persist(entity);
   }
 
-  @Transactional
-  public ClusterConfigEntity findConfig(ClusterConfigEntityPK configEntityPK) {
-    return entityManagerProvider.get().find(ClusterConfigEntity.class,
-      configEntityPK);
-  }
-
   /**
    * Retrieve entity data from DB
    * @param clusterEntity entity to refresh

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
index f264238..dcad56e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.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.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntityPK;
 
@@ -37,12 +38,12 @@ public class ClusterServiceDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public ClusterServiceEntity findByPK(ClusterServiceEntityPK clusterServiceEntityPK) {
     return entityManagerProvider.get().find(ClusterServiceEntity.class, clusterServiceEntityPK);
   }
 
-  @Transactional
+  @RequiresSession
   public ClusterServiceEntity findByClusterAndServiceNames(String  clusterName, String serviceName) {
     TypedQuery<ClusterServiceEntity> query = entityManagerProvider.get()
             .createNamedQuery("clusterServiceByClusterAndServiceNames", ClusterServiceEntity.class);
@@ -56,7 +57,7 @@ public class ClusterServiceDAO {
     }
   }
 
-  @Transactional
+  @RequiresSession
   public List<ClusterServiceEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), ClusterServiceEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java
index 88e363c..b9505e8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterStateDAO.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.ClusterStateEntity;
 
 import javax.persistence.EntityManager;
@@ -34,12 +35,12 @@ public class ClusterStateDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public ClusterStateEntity findByPK(long clusterId) {
     return entityManagerProvider.get().find(ClusterStateEntity.class, clusterId);
   }
 
-  @Transactional
+  @RequiresSession
   public List<ClusterStateEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), ClusterStateEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupConfigMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupConfigMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupConfigMappingDAO.java
index bc781c5..7502a86 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupConfigMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupConfigMappingDAO.java
@@ -21,6 +21,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.ConfigGroupConfigMappingEntity;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntityPK;
 import javax.persistence.EntityManager;
@@ -35,14 +36,14 @@ public class ConfigGroupConfigMappingDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public ConfigGroupConfigMappingEntity findByPK
     (ConfigGroupConfigMappingEntityPK configGroupConfigMappingEntityPK) {
     return entityManagerProvider.get().find(ConfigGroupConfigMappingEntity.class,
       configGroupConfigMappingEntityPK);
   }
 
-  @Transactional
+  @RequiresSession
   public List<ConfigGroupConfigMappingEntity> findByGroup(Long groupId) {
     TypedQuery<ConfigGroupConfigMappingEntity> query = entityManagerProvider
       .get().createNamedQuery("configsByGroup", ConfigGroupConfigMappingEntity.class);
@@ -55,7 +56,7 @@ public class ConfigGroupConfigMappingDAO {
     return null;
   }
 
-  @Transactional
+  @RequiresSession
   public List<ConfigGroupConfigMappingEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), ConfigGroupConfigMappingEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupDAO.java
index 01df9df..a2dd29b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupDAO.java
@@ -21,6 +21,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.ConfigGroupEntity;
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
@@ -28,6 +29,7 @@ import javax.persistence.TypedQuery;
 import java.util.List;
 
 @Singleton
+@RequiresSession
 public class ConfigGroupDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
@@ -39,7 +41,7 @@ public class ConfigGroupDAO {
    * @param groupName
    * @return ConfigGroupEntity
    */
-  @Transactional
+  @RequiresSession
   public ConfigGroupEntity findByName(String groupName) {
     TypedQuery<ConfigGroupEntity> query = entityManagerProvider.get()
       .createNamedQuery("configGroupByName", ConfigGroupEntity.class);
@@ -56,12 +58,12 @@ public class ConfigGroupDAO {
    * @param id
    * @return
    */
-  @Transactional
+  @RequiresSession
   public ConfigGroupEntity findById(Long id) {
     return entityManagerProvider.get().find(ConfigGroupEntity.class, id);
   }
 
-  @Transactional
+  @RequiresSession
   public List<ConfigGroupEntity> findAll() {
     TypedQuery<ConfigGroupEntity> query = entityManagerProvider.get()
       .createNamedQuery("allConfigGroups", ConfigGroupEntity.class);
@@ -72,6 +74,23 @@ public class ConfigGroupDAO {
     return null;
   }
 
+  /**
+   * Find config groups by service name and so on
+   * @param tag
+   * @return
+   */
+  @RequiresSession
+  public List<ConfigGroupEntity> findAllByTag(String tag) {
+    TypedQuery<ConfigGroupEntity> query = entityManagerProvider.get()
+      .createNamedQuery("configGroupsByTag", ConfigGroupEntity.class);
+    query.setParameter("tagName", tag);
+    try {
+      return query.getResultList();
+    } catch (NoResultException ignored) {
+    }
+    return null;
+  }
+
   @Transactional
   public void create(ConfigGroupEntity configGroupEntity) {
     entityManagerProvider.get().persist(configGroupEntity);
@@ -99,21 +118,4 @@ public class ConfigGroupDAO {
 
   // DAO methods on associated objects
 
-  /**
-   * Find config groups by service name and so on
-   * @param tag
-   * @return
-   */
-  @Transactional
-  public List<ConfigGroupEntity> findAllByTag(String tag) {
-    TypedQuery<ConfigGroupEntity> query = entityManagerProvider.get()
-      .createNamedQuery("configGroupsByTag", ConfigGroupEntity.class);
-    query.setParameter("tagName", tag);
-    try {
-      return query.getResultList();
-    } catch (NoResultException ignored) {
-    }
-    return null;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
index d3f7515..d597bdf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ConfigGroupHostMappingDAO.java
@@ -22,6 +22,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.cache.ConfigGroupHostMapping;
 import org.apache.ambari.server.orm.cache.ConfigGroupHostMappingImpl;
 import org.apache.ambari.server.orm.entities.ConfigGroupEntity;
@@ -45,7 +46,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -112,7 +112,7 @@ public class ConfigGroupHostMappingDAO {
    * @param configGroupHostMappingEntityPK
    * @return
    */
-  @Transactional
+  @RequiresSession
   public ConfigGroupHostMappingEntity findByPK(final ConfigGroupHostMappingEntityPK
         configGroupHostMappingEntityPK) {
     
@@ -120,7 +120,7 @@ public class ConfigGroupHostMappingDAO {
       .find(ConfigGroupHostMappingEntity.class, configGroupHostMappingEntityPK);
   }
 
-  @Transactional
+  @RequiresSession
   public Set<ConfigGroupHostMapping> findByHost(String hostname) {
     
     populateCache();
@@ -134,7 +134,7 @@ public class ConfigGroupHostMappingDAO {
     
   }
 
-  @Transactional
+  @RequiresSession
   public Set<ConfigGroupHostMapping> findByGroup(final Long groupId) {
     
     populateCache();
@@ -161,7 +161,7 @@ public class ConfigGroupHostMappingDAO {
     
   }
 
-  @Transactional
+  @RequiresSession
   public List<ConfigGroupHostMappingEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), ConfigGroupHostMappingEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java
index 47b16ac..9a40a0c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ExecutionCommandDAO.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.ExecutionCommandEntity;
 
 import javax.persistence.EntityManager;
@@ -35,12 +36,12 @@ public class ExecutionCommandDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public ExecutionCommandEntity findByPK(long taskId) {
     return entityManagerProvider.get().find(ExecutionCommandEntity.class, taskId);
   }
 
-  @Transactional
+  @RequiresSession
   public List<ExecutionCommandEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), ExecutionCommandEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/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 f8b43a8..9635f30 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
@@ -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.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK;
 
@@ -35,11 +36,22 @@ public class HostComponentDesiredStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public HostComponentDesiredStateEntity findByPK(HostComponentDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentDesiredStateEntity.class, primaryKey);
   }
 
+  @RequiresSession
+  public List<HostComponentDesiredStateEntity> findAll() {
+    TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
+      .createQuery("SELECT hcd from HostComponentDesiredStateEntity hcd", HostComponentDesiredStateEntity.class);
+    try {
+      return query.getResultList();
+    } catch (NoResultException ignored) {
+    }
+    return null;
+  }
+
   @Transactional
   public void refresh(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
     entityManagerProvider.get().refresh(hostComponentDesiredStateEntity);
@@ -64,15 +76,4 @@ public class HostComponentDesiredStateDAO {
   public void removeByPK(HostComponentDesiredStateEntityPK primaryKey) {
     remove(findByPK(primaryKey));
   }
-
-  @Transactional
-  public List<HostComponentDesiredStateEntity> findAll() {
-    TypedQuery<HostComponentDesiredStateEntity> query = entityManagerProvider.get()
-      .createQuery("SELECT hcd from HostComponentDesiredStateEntity hcd", HostComponentDesiredStateEntity.class);
-    try {
-      return query.getResultList();
-    } catch (NoResultException ignored) {
-    }
-    return null;
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/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 697d5f0..fd1ce9e 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
@@ -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.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK;
 
@@ -35,11 +36,22 @@ public class HostComponentStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public HostComponentStateEntity findByPK(HostComponentStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(HostComponentStateEntity.class, primaryKey);
   }
 
+  @RequiresSession
+  public List<HostComponentStateEntity> findAll() {
+    TypedQuery<HostComponentStateEntity> query = entityManagerProvider.get()
+      .createQuery("SELECT hsc from HostComponentStateEntity hsc", HostComponentStateEntity.class);
+    try {
+      return query.getResultList();
+    } catch (NoResultException ignored) {
+    }
+    return null;
+  }
+
   @Transactional
   public void refresh(HostComponentStateEntity hostComponentStateEntity) {
     entityManagerProvider.get().refresh(hostComponentStateEntity);
@@ -64,15 +76,4 @@ public class HostComponentStateDAO {
   public void removeByPK(HostComponentStateEntityPK primaryKey) {
     remove(findByPK(primaryKey));
   }
-
-  @Transactional
-  public List<HostComponentStateEntity> findAll() {
-    TypedQuery<HostComponentStateEntity> query = entityManagerProvider.get()
-      .createQuery("SELECT hsc from HostComponentStateEntity hsc", HostComponentStateEntity.class);
-    try {
-      return query.getResultList();
-    } catch (NoResultException ignored) {
-    }
-    return null;
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
index a6dcd63..9bc1235 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostConfigMappingDAO.java
@@ -18,7 +18,6 @@
 package org.apache.ambari.server.orm.dao;
 
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -27,6 +26,7 @@ import javax.persistence.TypedQuery;
 
 import com.google.inject.Singleton;
 
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.cache.HostConfigMapping;
 import org.apache.ambari.server.orm.cache.HostConfigMappingImpl;
 import org.apache.ambari.server.orm.entities.HostConfigMappingEntity;
@@ -134,7 +134,7 @@ public class HostConfigMappingDAO {
     return hostConfigMapping;
   }
 
-  @Transactional
+  @RequiresSession
   public Set<HostConfigMapping> findByType(final long clusterId, String hostName, final String type) {
     
     populateCache();
@@ -157,7 +157,7 @@ public class HostConfigMappingDAO {
     return set;
   }
 
-  @Transactional
+  @RequiresSession
   public HostConfigMapping findSelectedByType(final long clusterId,
       String hostName, final String type) {
     
@@ -184,7 +184,7 @@ public class HostConfigMappingDAO {
     
   }
 
-  @Transactional
+  @RequiresSession
   public Set<HostConfigMapping> findSelected(final long clusterId, String hostName) {
     
     populateCache();
@@ -207,7 +207,7 @@ public class HostConfigMappingDAO {
     return set;
   }
 
-  @Transactional
+  @RequiresSession
   public Set<HostConfigMapping> findSelectedByHosts(long clusterId, Collection<String> hostNames) {
     
     populateCache();
@@ -244,7 +244,7 @@ public class HostConfigMappingDAO {
   }
 
 
-  @Transactional
+  @RequiresSession
   public Map<String, List<HostConfigMapping>> findSelectedHostsByTypes(final long clusterId,
                                                                              Collection<String> types) {
     
@@ -282,7 +282,7 @@ public class HostConfigMappingDAO {
     return mappingsByType;
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostConfigMappingEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), HostConfigMappingEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
index fab97b0..35c795b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostDAO.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.HostEntity;
 import org.apache.ambari.server.orm.entities.StageEntity;
 
@@ -37,12 +38,12 @@ public class HostDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public HostEntity findByName(String hostName) {
     return entityManagerProvider.get().find(HostEntity.class, hostName);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostEntity> findAll() {
     TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery("SELECT host FROM HostEntity host", HostEntity.class);
     try {
@@ -52,7 +53,7 @@ public class HostDAO {
     }
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostEntity> findByStage(StageEntity stageEntity) {
     TypedQuery<HostEntity> query = entityManagerProvider.get().createQuery(
         "SELECT host FROM HostEntity host " +

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
index 6648266..66c89c0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.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.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
 import org.apache.ambari.server.orm.entities.StageEntity;
@@ -48,12 +49,12 @@ public class HostRoleCommandDAO {
   private static Logger LOG = LoggerFactory.getLogger(HostRoleCommandDAO.class);
   private static final int REQUESTS_RESULT_LIMIT = 10;
 
-  @Transactional
+  @RequiresSession
   public HostRoleCommandEntity findByPK(long taskId) {
     return entityManagerProvider.get().find(HostRoleCommandEntity.class, taskId);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostRoleCommandEntity> findByPKs(Collection<Long> taskIds) {
     if (taskIds == null || taskIds.isEmpty()) {
       return Collections.emptyList();
@@ -65,7 +66,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, taskIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostRoleCommandEntity> findByRequestIds(Collection<Long> requestIds) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
         "SELECT task FROM HostRoleCommandEntity task " +
@@ -74,7 +75,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, requestIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<Long> findTaskIdsByRequestIds(Collection<Long> requestIds) {
     TypedQuery<Long> query = entityManagerProvider.get().createQuery(
         "SELECT task.taskId FROM HostRoleCommandEntity task " +
@@ -83,7 +84,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, requestIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostRoleCommandEntity> findByRequestAndTaskIds(Collection<Long> requestIds, Collection<Long> taskIds) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
         "SELECT DISTINCT task FROM HostRoleCommandEntity task " +
@@ -93,7 +94,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, requestIds, taskIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<Long> findTaskIdsByRequestAndTaskIds(Collection<Long> requestIds, Collection<Long> taskIds) {
     TypedQuery<Long> query = entityManagerProvider.get().createQuery(
         "SELECT DISTINCT task.taskId FROM HostRoleCommandEntity task " +
@@ -103,7 +104,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, requestIds, taskIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostRoleCommandEntity> findSortedCommandsByStageAndHost(StageEntity stageEntity, HostEntity hostEntity) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand " +
         "FROM HostRoleCommandEntity hostRoleCommand " +
@@ -112,7 +113,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, stageEntity, hostEntity);
   }
 
-  @Transactional
+  @RequiresSession
   public Map<String, List<HostRoleCommandEntity>> findSortedCommandsByStage(StageEntity stageEntity) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand " +
         "FROM HostRoleCommandEntity hostRoleCommand " +
@@ -133,7 +134,7 @@ public class HostRoleCommandDAO {
     return hostCommands;
   }
 
-  @Transactional
+  @RequiresSession
   public List<Long> findTaskIdsByStage(long requestId, long stageId) {
     TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand.taskId " +
         "FROM HostRoleCommandEntity hostRoleCommand " +
@@ -144,7 +145,7 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, requestId, stageId);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostRoleCommandEntity> findByHostRole(String hostName, long requestId, long stageId, String role) {
     TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
         "FROM HostRoleCommandEntity command " +
@@ -155,7 +156,28 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query, hostName, requestId, stageId, role);
   }
 
-  @Transactional
+  @RequiresSession
+  public List<HostRoleCommandEntity> findByRequest(long requestId) {
+    TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
+      "FROM HostRoleCommandEntity command " +
+      "WHERE command.requestId=?1 ORDER BY command.taskId", HostRoleCommandEntity.class);
+    return daoUtils.selectList(query, requestId);
+  }
+
+  @RequiresSession
+  public List<Long> findTaskIdsByRequest(long requestId) {
+    TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT command.taskId " +
+      "FROM HostRoleCommandEntity command " +
+      "WHERE command.requestId=?1 ORDER BY command.taskId", Long.class);
+    return daoUtils.selectList(query, requestId);
+  }
+
+  @RequiresSession
+  public List<HostRoleCommandEntity> findAll() {
+    return daoUtils.selectAll(entityManagerProvider.get(), HostRoleCommandEntity.class);
+  }
+
+  @RequiresSession
   public List<Long> getRequests() {
     String queryStr = "SELECT DISTINCT command.requestId " +
         "FROM HostRoleCommandEntity command ORDER BY command.requestId DESC";
@@ -165,6 +187,48 @@ public class HostRoleCommandDAO {
     return daoUtils.selectList(query);
   }
 
+  @RequiresSession
+  public List<Long> getRequestsByTaskStatus(
+    Collection<HostRoleStatus> statuses, boolean match, boolean checkAllTasks) {
+    List<Long> results = null;
+    StringBuilder queryStr = new StringBuilder();
+
+    queryStr.append("SELECT DISTINCT command.requestId ").append(
+      "FROM HostRoleCommandEntity command ");
+    if (statuses != null && !statuses.isEmpty()) {
+      queryStr.append("WHERE ");
+
+      if (checkAllTasks) {
+        queryStr.append("command.requestId ");
+        if (!match) {
+          queryStr.append("NOT ");
+        }
+        queryStr.append("IN (").append("SELECT c.requestId ")
+          .append("FROM HostRoleCommandEntity c ")
+          .append("WHERE c.requestId = command.requestId ")
+          .append("AND c.status IN ?1) ");
+      } else {
+        queryStr.append("command.status ");
+        if (!match) {
+          queryStr.append("NOT ");
+        }
+        queryStr.append("IN ?1 ");
+      }
+    }
+
+    queryStr.append("ORDER BY command.requestId DESC");
+    TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr.toString(),
+      Long.class);
+    query.setMaxResults(REQUESTS_RESULT_LIMIT);
+
+    if (statuses != null && !statuses.isEmpty()) {
+      results = daoUtils.selectList(query, statuses);
+    } else {
+      results = daoUtils.selectList(query);
+    }
+    return results;
+  }
+
   @Transactional
   /**
    * NB: You cannot rely on return value if batch write is enabled
@@ -185,27 +249,6 @@ public class HostRoleCommandDAO {
   }
 
   @Transactional
-  public List<HostRoleCommandEntity> findByRequest(long requestId) {
-    TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
-        "FROM HostRoleCommandEntity command " +
-        "WHERE command.requestId=?1 ORDER BY command.taskId", HostRoleCommandEntity.class);
-    return daoUtils.selectList(query, requestId);
-  }
-  
-  @Transactional
-  public List<Long> findTaskIdsByRequest(long requestId) {
-    TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT command.taskId " +
-        "FROM HostRoleCommandEntity command " +
-        "WHERE command.requestId=?1 ORDER BY command.taskId", Long.class);
-    return daoUtils.selectList(query, requestId);
-  }
-
-  @Transactional
-  public List<HostRoleCommandEntity> findAll() {
-    return daoUtils.selectAll(entityManagerProvider.get(), HostRoleCommandEntity.class);
-  }
-
-  @Transactional
   public void create(HostRoleCommandEntity stageEntity) {
     entityManagerProvider.get().persist(stageEntity);
   }
@@ -235,46 +278,4 @@ public class HostRoleCommandDAO {
     remove(findByPK(taskId));
   }
 
-  @Transactional
-  public List<Long> getRequestsByTaskStatus(
-      Collection<HostRoleStatus> statuses, boolean match, boolean checkAllTasks) {
-    List<Long> results = null;
-    StringBuilder queryStr = new StringBuilder();
-
-    queryStr.append("SELECT DISTINCT command.requestId ").append(
-        "FROM HostRoleCommandEntity command ");
-    if (statuses != null && !statuses.isEmpty()) {
-      queryStr.append("WHERE ");
-
-      if (checkAllTasks) {
-        queryStr.append("command.requestId ");
-        if (!match) {
-          queryStr.append("NOT ");
-        }
-        queryStr.append("IN (").append("SELECT c.requestId ")
-            .append("FROM HostRoleCommandEntity c ")
-            .append("WHERE c.requestId = command.requestId ")
-            .append("AND c.status IN ?1) ");
-      } else {
-        queryStr.append("command.status ");
-        if (!match) {
-          queryStr.append("NOT ");
-        }
-        queryStr.append("IN ?1 ");
-      }
-    }
-
-    queryStr.append("ORDER BY command.requestId DESC");
-    TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr.toString(),
-        Long.class);
-    query.setMaxResults(REQUESTS_RESULT_LIMIT);
-
-    if (statuses != null && !statuses.isEmpty()) {
-      results = daoUtils.selectList(query, statuses);
-    } else {
-      results = daoUtils.selectList(query);
-    }
-    return results;
-  }
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java
index 384fbaa..f939de3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostStateDAO.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.HostStateEntity;
 
 import javax.persistence.EntityManager;
@@ -34,12 +35,12 @@ public class HostStateDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public HostStateEntity findByHostName(String hostName) {
     return entityManagerProvider.get().find(HostStateEntity.class, hostName);
   }
 
-  @Transactional
+  @RequiresSession
   public List<HostStateEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), HostStateEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KeyValueDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KeyValueDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KeyValueDAO.java
index ad0a360..b2d92b3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KeyValueDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KeyValueDAO.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.KeyValueEntity;
 
 import javax.persistence.EntityManager;
@@ -36,12 +37,12 @@ public class KeyValueDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public KeyValueEntity findByKey(String key) {
     return entityManagerProvider.get().find(KeyValueEntity.class, key);
   }
 
-  @Transactional
+  @RequiresSession
   public Collection<KeyValueEntity> findAll() {
     TypedQuery<KeyValueEntity> query =
         entityManagerProvider.get().createQuery("SELECT keyValue FROM KeyValueEntity keyValue", KeyValueEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MetainfoDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MetainfoDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MetainfoDAO.java
index dae32dd..b6f737e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MetainfoDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/MetainfoDAO.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.MetainfoEntity;
 
 import javax.persistence.EntityManager;
@@ -36,12 +37,12 @@ public class MetainfoDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public MetainfoEntity findByKey(String key) {
     return entityManagerProvider.get().find(MetainfoEntity.class, key);
   }
 
-  @Transactional
+  @RequiresSession
   public Collection<MetainfoEntity> findAll() {
     TypedQuery<MetainfoEntity> query =
         entityManagerProvider.get().createQuery("SELECT metainfo FROM MetainfoEntity metainfo", MetainfoEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
index 2c30695..241c1fd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestDAO.java
@@ -20,8 +20,10 @@ 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.actionmanager.HostRoleStatus;
+import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.RequestEntity;
 import org.apache.ambari.server.orm.entities.RequestResourceFilterEntity;
 
@@ -30,35 +32,36 @@ import javax.persistence.TypedQuery;
 import java.util.Collection;
 import java.util.List;
 
+@Singleton
 public class RequestDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public RequestEntity findByPK(Long requestId) {
     return entityManagerProvider.get().find(RequestEntity.class, requestId);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestEntity> findByPks(Collection<Long> requestIds) {
     TypedQuery<RequestEntity> query = entityManagerProvider.get().createQuery("SELECT request FROM RequestEntity request " +
         "WHERE request.requestId IN ?1", RequestEntity.class);
     return daoUtils.selectList(query, requestIds);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), RequestEntity.class);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestResourceFilterEntity> findAllResourceFilters() {
     return daoUtils.selectAll(entityManagerProvider.get(), RequestResourceFilterEntity.class);
   }
 
-  @Transactional
+  @RequiresSession
   public boolean isAllTasksCompleted(long requestId) {
     TypedQuery<Long> query = entityManagerProvider.get().createQuery(
         "SELECT task.taskId FROM HostRoleCommandEntity task WHERE task.requestId = ?1 AND " +
@@ -70,7 +73,7 @@ public class RequestDAO {
     return daoUtils.selectList(query, requestId, HostRoleStatus.getCompletedStates()).isEmpty();
   }
 
-  @Transactional
+  @RequiresSession
   public Long getLastStageId(long requestId) {
     TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT max(stage.stageId) " +
       "FROM StageEntity stage WHERE stage.requestId=?1", Long.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleBatchRequestDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleBatchRequestDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleBatchRequestDAO.java
index d0f5d79..a61b643 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleBatchRequestDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleBatchRequestDAO.java
@@ -21,6 +21,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.RequestScheduleBatchRequestEntity;
 import org.apache.ambari.server.orm.entities.RequestScheduleBatchRequestEntityPK;
 import javax.persistence.EntityManager;
@@ -35,7 +36,7 @@ public class RequestScheduleBatchRequestDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public RequestScheduleBatchRequestEntity findByPk
     (RequestScheduleBatchRequestEntityPK batchRequestEntity) {
 
@@ -43,7 +44,7 @@ public class RequestScheduleBatchRequestDAO {
       .find(RequestScheduleBatchRequestEntity.class, batchRequestEntity);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestScheduleBatchRequestEntity> findByScheduleId(Long scheduleId) {
     TypedQuery<RequestScheduleBatchRequestEntity> query = entityManagerProvider
       .get().createNamedQuery("findByScheduleId",
@@ -57,7 +58,7 @@ public class RequestScheduleBatchRequestDAO {
     return null;
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestScheduleBatchRequestEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), RequestScheduleBatchRequestEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleDAO.java
index e0b1377..259c3b2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RequestScheduleDAO.java
@@ -21,6 +21,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.RequestScheduleEntity;
 import javax.persistence.EntityManager;
 import javax.persistence.NoResultException;
@@ -32,12 +33,12 @@ public class RequestScheduleDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public RequestScheduleEntity findById(Long id) {
     return entityManagerProvider.get().find(RequestScheduleEntity.class, id);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestScheduleEntity> findByStatus(String status) {
     TypedQuery<RequestScheduleEntity> query = entityManagerProvider.get()
       .createNamedQuery("reqScheduleByStatus", RequestScheduleEntity.class);
@@ -49,7 +50,7 @@ public class RequestScheduleDAO {
     }
   }
 
-  @Transactional
+  @RequiresSession
   public List<RequestScheduleEntity> findAll() {
     TypedQuery<RequestScheduleEntity> query = entityManagerProvider.get()
       .createNamedQuery("allReqSchedules", RequestScheduleEntity.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java
index 5b37b0e..d8e17e8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleDAO.java
@@ -21,6 +21,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.RoleEntity;
 
 import javax.persistence.EntityManager;
@@ -34,12 +35,12 @@ public class RoleDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public RoleEntity findByName(String roleName) {
     return entityManagerProvider.get().find(RoleEntity.class, roleName.toLowerCase());
   }
 
-  @Transactional
+  @RequiresSession
   public List<RoleEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), RoleEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java
index 6949ee6..87649ea 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/RoleSuccessCriteriaDAO.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.RoleSuccessCriteriaEntity;
 import org.apache.ambari.server.orm.entities.RoleSuccessCriteriaEntityPK;
 
@@ -36,13 +37,13 @@ public class RoleSuccessCriteriaDAO {
   @Inject
   DaoUtils daoUtils;
 
-  @Transactional
+  @RequiresSession
   public RoleSuccessCriteriaEntity findByPK(RoleSuccessCriteriaEntityPK roleSuccessCriteriaEntityPK) {
     entityManagerProvider.get().clear();
     return entityManagerProvider.get().find(RoleSuccessCriteriaEntity.class, roleSuccessCriteriaEntityPK);
   }
 
-  @Transactional
+  @RequiresSession
   public List<RoleSuccessCriteriaEntity> findAll() {
     return daoUtils.selectAll(entityManagerProvider.get(), RoleSuccessCriteriaEntity.class);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
index d1cea2e..8cf7ec3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.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.ServiceComponentDesiredStateEntityPK;
 import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
 
@@ -35,11 +36,23 @@ public class ServiceComponentDesiredStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public ServiceComponentDesiredStateEntity findByPK(ServiceComponentDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(ServiceComponentDesiredStateEntity.class, primaryKey);
   }
 
+  @RequiresSession
+  public List<ServiceComponentDesiredStateEntity> findAll() {
+    TypedQuery<ServiceComponentDesiredStateEntity> query =
+      entityManagerProvider.get().
+        createQuery("SELECT scd from ServiceComponentDesiredStateEntity scd", ServiceComponentDesiredStateEntity.class);
+    try {
+      return query.getResultList();
+    } catch (NoResultException ignored) {
+    }
+    return null;
+  }
+
   @Transactional
   public void refresh(ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity) {
     entityManagerProvider.get().refresh(serviceComponentDesiredStateEntity);
@@ -64,16 +77,4 @@ public class ServiceComponentDesiredStateDAO {
   public void removeByPK(ServiceComponentDesiredStateEntityPK primaryKey) {
     remove(findByPK(primaryKey));
   }
-
-  @Transactional
-  public List<ServiceComponentDesiredStateEntity> findAll() {
-    TypedQuery<ServiceComponentDesiredStateEntity> query =
-      entityManagerProvider.get().
-        createQuery("SELECT scd from ServiceComponentDesiredStateEntity scd", ServiceComponentDesiredStateEntity.class);
-    try {
-      return query.getResultList();
-    } catch (NoResultException ignored) {
-    }
-    return null;
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/8bfd1659/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java
index bd47213..81e6d95 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceDesiredStateDAO.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.ServiceDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntityPK;
 
@@ -35,11 +36,23 @@ public class ServiceDesiredStateDAO {
   @Inject
   Provider<EntityManager> entityManagerProvider;
 
-  @Transactional
+  @RequiresSession
   public ServiceDesiredStateEntity findByPK(ServiceDesiredStateEntityPK primaryKey) {
     return entityManagerProvider.get().find(ServiceDesiredStateEntity.class, primaryKey);
   }
 
+  @RequiresSession
+  public List<ServiceDesiredStateEntity> findAll() {
+    TypedQuery<ServiceDesiredStateEntity> query =
+      entityManagerProvider.get().
+        createQuery("SELECT sd from ServiceDesiredStateEntity sd", ServiceDesiredStateEntity.class);
+    try {
+      return query.getResultList();
+    } catch (NoResultException ignored) {
+    }
+    return null;
+  }
+
   @Transactional
   public void refresh(ServiceDesiredStateEntity serviceDesiredStateEntity) {
     entityManagerProvider.get().refresh(serviceDesiredStateEntity);
@@ -64,16 +77,4 @@ public class ServiceDesiredStateDAO {
   public void removeByPK(ServiceDesiredStateEntityPK primaryKey) {
     remove(findByPK(primaryKey));
   }
-
-  @Transactional
-  public List<ServiceDesiredStateEntity> findAll() {
-    TypedQuery<ServiceDesiredStateEntity> query =
-      entityManagerProvider.get().
-        createQuery("SELECT sd from ServiceDesiredStateEntity sd", ServiceDesiredStateEntity.class);
-    try {
-      return query.getResultList();
-    } catch (NoResultException ignored) {
-    }
-    return null;
-  }
 }


Mime
View raw message