ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [17/36] ambari git commit: AMBARI-18556 - Remove Unnecessary Locks Inside Of Service Business Object Implementations (jonathanhurley)
Date Wed, 19 Oct 2016 16:58:27 GMT
AMBARI-18556 - Remove Unnecessary Locks Inside Of Service Business Object Implementations (jonathanhurley)


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 0de69e10b30a1dadf6f508170548cd347095193a
Parents: fbfcf98
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Fri Oct 7 15:59:42 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Sat Oct 8 21:19:35 2016 -0400

----------------------------------------------------------------------
 .../ambari/server/api/services/BaseRequest.java |  49 +-
 .../controller/AmbariManagementController.java  |   8 -
 .../AmbariManagementControllerImpl.java         |   5 -
 .../internal/ServiceResourceProvider.java       |  38 +-
 .../orm/dao/HostComponentDesiredStateDAO.java   |   7 +-
 .../server/orm/dao/HostComponentStateDAO.java   |   9 +-
 .../apache/ambari/server/orm/dao/HostDAO.java   |   2 +-
 .../orm/entities/ClusterServiceEntity.java      |   2 +-
 .../HostComponentDesiredStateEntity.java        |  11 +
 .../orm/entities/HostComponentStateEntity.java  |  11 +
 .../org/apache/ambari/server/state/Host.java    |   2 -
 .../org/apache/ambari/server/state/Service.java |   6 -
 .../apache/ambari/server/state/ServiceImpl.java | 448 +++++++------------
 .../server/state/cluster/ClustersImpl.java      |   4 -
 .../ambari/server/state/host/HostImpl.java      |  15 -
 .../svccomphost/ServiceComponentHostImpl.java   |  18 +-
 .../apache/ambari/server/utils/RetryHelper.java |   1 +
 .../server/agent/HeartbeatProcessorTest.java    |  12 -
 .../server/agent/TestHeartbeatHandler.java      |  10 -
 .../server/agent/TestHeartbeatMonitor.java      |   5 -
 .../server/api/services/AmbariMetaInfoTest.java |   3 +
 .../configuration/RecoveryConfigHelperTest.java |   6 -
 .../AmbariManagementControllerTest.java         |  43 --
 .../PreUpgradeCheckResourceProviderTest.java    |  52 +--
 .../internal/ServiceResourceProviderTest.java   |  63 ++-
 .../UpgradeResourceProviderHDP22Test.java       |   1 -
 .../internal/UpgradeResourceProviderTest.java   |   2 -
 .../UpgradeSummaryResourceProviderTest.java     |   1 -
 .../GeneralServiceCalculatedStateTest.java      |  47 +-
 .../apache/ambari/server/events/EventsTest.java |   1 -
 .../apache/ambari/server/orm/OrmTestHelper.java |   2 -
 .../dao/HostComponentDesiredStateDAOTest.java   |  27 +-
 .../orm/dao/HostComponentStateDAOTest.java      |  28 +-
 .../ComponentVersionCheckActionTest.java        |   1 -
 .../upgrades/ConfigureActionTest.java           |   1 -
 .../upgrades/UpgradeActionTest.java             |   1 -
 .../server/state/ServiceComponentTest.java      |   1 -
 .../apache/ambari/server/state/ServiceTest.java |   4 -
 .../state/alerts/AlertEventPublisherTest.java   |   7 +-
 .../state/alerts/InitialAlertEventTest.java     |   3 +-
 .../state/cluster/ClusterDeadlockTest.java      |   1 -
 .../server/state/cluster/ClusterImplTest.java   |   2 -
 .../server/state/cluster/ClusterTest.java       |  22 +-
 .../state/cluster/ClustersDeadlockTest.java     |   1 -
 .../server/state/cluster/ClustersTest.java      |   1 -
 .../ConcurrentServiceConfigVersionTest.java     |   1 -
 ...omponentHostConcurrentWriteDeadlockTest.java |   1 -
 .../svccomphost/ServiceComponentHostTest.java   |   1 -
 48 files changed, 340 insertions(+), 647 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
index 9f7b949..73af2c8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseRequest.java
@@ -18,40 +18,39 @@
 
 package org.apache.ambari.server.api.services;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.UriInfo;
+
 import org.apache.ambari.server.api.handlers.RequestHandler;
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
 import org.apache.ambari.server.api.predicate.PredicateCompiler;
 import org.apache.ambari.server.api.predicate.QueryLexer;
 import org.apache.ambari.server.api.query.render.Renderer;
 import org.apache.ambari.server.api.resources.ResourceInstance;
-import org.apache.ambari.server.controller.internal.SortRequestImpl;
 import org.apache.ambari.server.controller.internal.PageRequestImpl;
+import org.apache.ambari.server.controller.internal.SortRequestImpl;
 import org.apache.ambari.server.controller.internal.TemporalInfoImpl;
-import org.apache.ambari.server.controller.spi.SortRequest;
 import org.apache.ambari.server.controller.spi.PageRequest;
 import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.SortRequest;
 import org.apache.ambari.server.controller.spi.SortRequestProperty;
 import org.apache.ambari.server.controller.spi.TemporalInfo;
 import org.apache.ambari.server.utils.RequestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.UriInfo;
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collection;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
  * Request implementation.
@@ -144,11 +143,13 @@ public abstract class BaseRequest implements Request {
       parseQueryPredicate();
       result = getRequestHandler().handleRequest(this);
     } catch (InvalidQueryException e) {
-      result =  new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST,
-          "Unable to compile query predicate: " + e.getMessage()));
+      String message = "Unable to compile query predicate: " + e.getMessage();
+      LOG.error(message, e);
+      result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, message));
     } catch (IllegalArgumentException e) {
-      result =  new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST,
-          "Invalid Request: " + e.getMessage()));
+      String message = "Invalid Request: " + e.getMessage();
+      LOG.error(message, e);
+      result = new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, message));
     }
 
     if (! result.getStatus().isErrorState()) {
@@ -322,7 +323,7 @@ public abstract class BaseRequest implements Request {
     if (queryString != null) {
       try {
         Collection<String> ignoredProperties = null;
-        switch (this.getRequestType()) {
+        switch (getRequestType()) {
           case PUT:
             ignoredProperties = m_resource.getResourceDefinition().getUpdateDirectives();
             break;

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
index 746bca4..7418c1b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java
@@ -54,7 +54,6 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.State;
@@ -550,13 +549,6 @@ public interface AmbariManagementController {
   AmbariMetaInfo getAmbariMetaInfo();
 
   /**
-   * Get the service factory for this management controller.
-   *
-   * @return the service factory
-   */
-  ServiceFactory getServiceFactory();
-
-  /**
    * Get the service component factory for this management controller.
    *
    * @return the service component factory

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/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 ac680a5..9390a45 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
@@ -4705,11 +4705,6 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   }
 
   @Override
-  public ServiceFactory getServiceFactory() {
-    return serviceFactory;
-  }
-
-  @Override
   public ServiceComponentFactory getServiceComponentFactory() {
     return serviceComponentFactory;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
index 56196c1..13f822e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java
@@ -17,9 +17,18 @@
  */
 package org.apache.ambari.server.controller.internal;
 
-import com.google.inject.Inject;
-import com.google.inject.assistedinject.Assisted;
-import com.google.inject.assistedinject.AssistedInject;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
 import org.apache.ambari.server.DuplicateResourceException;
@@ -60,23 +69,14 @@ import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.Validate;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import com.google.inject.assistedinject.AssistedInject;
 
 /**
  * Resource provider for service resources.
@@ -344,18 +344,12 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
     // do all validation checks
     validateCreateRequests(requests, clusters);
 
-    ServiceFactory serviceFactory = getManagementController().getServiceFactory();
     for (ServiceRequest request : requests) {
       Cluster cluster = clusters.getCluster(request.getClusterName());
 
-      State state = State.INIT;
-
       // Already checked that service does not exist
-      Service s = serviceFactory.createNew(cluster, request.getServiceName());
+      Service s = cluster.addService(request.getServiceName());
 
-      s.setDesiredState(state);
-      s.setDesiredStackVersion(cluster.getDesiredStackVersion());
-      s.persist();
       // Initialize service widgets
       getManagementController().initializeWidgetsAndLayouts(cluster, s);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/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 176e15b..876b1cf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -95,17 +95,16 @@ public class HostComponentDesiredStateDAO {
 
   @Transactional
   public void remove(HostComponentDesiredStateEntity hostComponentDesiredStateEntity) {
-    HostEntity hostEntity = hostDAO.findById(hostComponentDesiredStateEntity.getHostId());
+    HostEntity hostEntity = hostComponentDesiredStateEntity.getHostEntity();
 
     if (hostEntity == null) {
       throw new IllegalStateException(String.format("Missing hostEntity for host id %1d",
               hostComponentDesiredStateEntity.getHostId()));
     }
 
-    entityManagerProvider.get().remove(merge(hostComponentDesiredStateEntity));
-
-    // Make sure that the state entity is removed from its host entity
     hostEntity.removeHostComponentDesiredStateEntity(hostComponentDesiredStateEntity);
+
+    entityManagerProvider.get().remove(hostComponentDesiredStateEntity);
     hostDAO.merge(hostEntity);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/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 2eefe09..cc7b503 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
@@ -27,7 +27,6 @@ import javax.persistence.TypedQuery;
 
 import org.apache.ambari.server.orm.RequiresSession;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
-import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.state.UpgradeState;
 
 import com.google.inject.Inject;
@@ -177,13 +176,7 @@ public class HostComponentStateDAO {
 
   @Transactional
   public void remove(HostComponentStateEntity hostComponentStateEntity) {
-    HostEntity hostEntity = hostDAO.findByName(hostComponentStateEntity.getHostName());
-
-    entityManagerProvider.get().remove(merge(hostComponentStateEntity));
-
-    // Make sure that the state entity is removed from its host entity
-    hostEntity.removeHostComponentStateEntity(hostComponentStateEntity);
-    hostDAO.merge(hostEntity);
+    entityManagerProvider.get().remove(hostComponentStateEntity);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/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 d367eb3..0d20fd3 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
@@ -112,7 +112,7 @@ public class HostDAO {
 
   @Transactional
   public void remove(HostEntity hostEntity) {
-    entityManagerProvider.get().remove(merge(hostEntity));
+    entityManagerProvider.get().remove(hostEntity);
   }
 
   public List<String> getHostNamesByHostIds(List<Long> hostIds) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
index 320c1be..5c76356 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
@@ -49,7 +49,7 @@ public class ClusterServiceEntity {
   @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", nullable = false)
   private ClusterEntity clusterEntity;
 
-  @OneToOne(mappedBy = "clusterServiceEntity")
+  @OneToOne(mappedBy = "clusterServiceEntity", cascade = { CascadeType.PERSIST, CascadeType.MERGE })
   private ServiceDesiredStateEntity serviceDesiredStateEntity;
 
   @OneToMany(mappedBy = "clusterServiceEntity")

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index fd15200..274a1e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
@@ -37,6 +37,8 @@ import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.SecurityState;
 import org.apache.ambari.server.state.State;
 
+import com.google.common.base.Objects;
+
 @javax.persistence.IdClass(HostComponentDesiredStateEntityPK.class)
 @javax.persistence.Table(name = "hostcomponentdesiredstate")
 @Entity
@@ -255,4 +257,13 @@ public class HostComponentDesiredStateEntity {
   public void setRestartRequired(boolean restartRequired) {
     this.restartRequired = (restartRequired == false ? 0 : 1);
   }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String toString() {
+    return Objects.toStringHelper(this).add("serviceName", serviceName).add("componentName",
+        componentName).add("hostId", hostId).add("desiredState", desiredState).toString();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
index 1555321..9d35e2a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
@@ -38,6 +38,8 @@ import org.apache.ambari.server.state.SecurityState;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.UpgradeState;
 
+import com.google.common.base.Objects;
+
 @Entity
 @Table(name = "hostcomponentstate")
 @TableGenerator(
@@ -283,4 +285,13 @@ public class HostComponentStateEntity {
     this.hostEntity = hostEntity;
   }
 
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String toString() {
+    return Objects.toStringHelper(this).add("serviceName", serviceName).add("componentName",
+        componentName).add("hostId", hostId).add("state", currentState).toString();
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
index 0a9c82a..bd6cc0d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Host.java
@@ -333,8 +333,6 @@ public interface Host extends Comparable {
 
   HostResponse convertToResponse();
 
-  void refresh();
-
   void importHostInfo(HostInfo hostInfo);
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
index 48ab252..df3cfd8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
@@ -72,12 +72,6 @@ public interface Service {
 
   void debugDump(StringBuilder sb);
 
-  boolean isPersisted();
-
-  void persist();
-
-  void refresh();
-
   ServiceComponent addServiceComponent(String serviceComponentName)
       throws AmbariException;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
index 36d4902..e4adc97 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
@@ -22,8 +22,10 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 import org.apache.ambari.annotations.Experimental;
 import org.apache.ambari.annotations.ExperimentalFeature;
@@ -37,7 +39,6 @@ import org.apache.ambari.server.events.ServiceRemovedEvent;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
-import org.apache.ambari.server.orm.dao.ConfigGroupDAO;
 import org.apache.ambari.server.orm.dao.ServiceConfigDAO;
 import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
@@ -55,7 +56,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.inject.Inject;
-import com.google.inject.Injector;
 import com.google.inject.ProvisionException;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
@@ -63,96 +63,98 @@ import com.google.inject.persist.Transactional;
 
 
 public class ServiceImpl implements Service {
-  private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
-  // Cached entity has only 1 getter for name
-  private ClusterServiceEntity serviceEntity;
-  private ServiceDesiredStateEntity serviceDesiredStateEntity;
+  private final Lock lock = new ReentrantLock();
   private ServiceDesiredStateEntityPK serviceDesiredStateEntityPK;
   private ClusterServiceEntityPK serviceEntityPK;
 
   private static final Logger LOG = LoggerFactory.getLogger(ServiceImpl.class);
 
-  private volatile boolean persisted = false;
   private final Cluster cluster;
-  private Map<String, ServiceComponent> components;
+  private final ConcurrentMap<String, ServiceComponent> components = new ConcurrentHashMap<>();
   private final boolean isClientOnlyService;
 
   @Inject
   private ServiceConfigDAO serviceConfigDAO;
-  @Inject
-  private ClusterServiceDAO clusterServiceDAO;
-  @Inject
-  private ServiceDesiredStateDAO serviceDesiredStateDAO;
-  @Inject
-  private ClusterDAO clusterDAO;
-  @Inject
-  private ServiceComponentFactory serviceComponentFactory;
-  @Inject
-  private AmbariMetaInfo ambariMetaInfo;
-  @Inject
-  private ConfigGroupDAO configGroupDAO;
+
+  private final ClusterServiceDAO clusterServiceDAO;
+  private final ServiceDesiredStateDAO serviceDesiredStateDAO;
+  private final ClusterDAO clusterDAO;
+  private final ServiceComponentFactory serviceComponentFactory;
 
   /**
    * Data access object for retrieving stack instances.
    */
-  @Inject
-  private StackDAO stackDAO;
+  private final StackDAO stackDAO;
 
   /**
    * Used to publish events relating to service CRUD operations.
    */
-  @Inject
-  private AmbariEventPublisher eventPublisher;
+  private final AmbariEventPublisher eventPublisher;
 
-  private void init() {
-    // TODO load from DB during restart?
-  }
+  /**
+   * The name of the service.
+   */
+  private final String serviceName;
 
   @AssistedInject
-  public ServiceImpl(@Assisted Cluster cluster, @Assisted String serviceName,
-      Injector injector) throws AmbariException {
-    injector.injectMembers(this);
-    serviceEntity = new ClusterServiceEntity();
+  ServiceImpl(@Assisted Cluster cluster, @Assisted String serviceName, ClusterDAO clusterDAO,
+      ClusterServiceDAO clusterServiceDAO, ServiceDesiredStateDAO serviceDesiredStateDAO,
+      ServiceComponentFactory serviceComponentFactory, StackDAO stackDAO,
+      AmbariMetaInfo ambariMetaInfo, AmbariEventPublisher eventPublisher)
+      throws AmbariException {
+    this.cluster = cluster;
+    this.clusterDAO = clusterDAO;
+    this.clusterServiceDAO = clusterServiceDAO;
+    this.serviceDesiredStateDAO = serviceDesiredStateDAO;
+    this.serviceComponentFactory = serviceComponentFactory;
+    this.stackDAO = stackDAO;
+    this.eventPublisher = eventPublisher;
+    this.serviceName = serviceName;
+
+    ClusterServiceEntity serviceEntity = new ClusterServiceEntity();
     serviceEntity.setClusterId(cluster.getClusterId());
     serviceEntity.setServiceName(serviceName);
-    serviceDesiredStateEntity = new ServiceDesiredStateEntity();
+    ServiceDesiredStateEntity serviceDesiredStateEntity = new ServiceDesiredStateEntity();
     serviceDesiredStateEntity.setServiceName(serviceName);
     serviceDesiredStateEntity.setClusterId(cluster.getClusterId());
-
     serviceDesiredStateEntityPK = getServiceDesiredStateEntityPK(serviceDesiredStateEntity);
     serviceEntityPK = getServiceEntityPK(serviceEntity);
 
     serviceDesiredStateEntity.setClusterServiceEntity(serviceEntity);
     serviceEntity.setServiceDesiredStateEntity(serviceDesiredStateEntity);
 
-    this.cluster = cluster;
-
-    components = new HashMap<String, ServiceComponent>();
-
     StackId stackId = cluster.getDesiredStackVersion();
-    setDesiredStackVersion(stackId);
+    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
+    serviceDesiredStateEntity.setDesiredStack(stackEntity);
 
     ServiceInfo sInfo = ambariMetaInfo.getService(stackId.getStackName(),
         stackId.getStackVersion(), serviceName);
+
     isClientOnlyService = sInfo.isClientOnlyService();
 
-    init();
+    persist(serviceEntity);
   }
 
   @AssistedInject
-  public ServiceImpl(@Assisted Cluster cluster, @Assisted ClusterServiceEntity
-      serviceEntity, Injector injector) throws AmbariException {
-    injector.injectMembers(this);
-    this.serviceEntity = serviceEntity;
+  ServiceImpl(@Assisted Cluster cluster, @Assisted ClusterServiceEntity serviceEntity,
+      ClusterDAO clusterDAO, ClusterServiceDAO clusterServiceDAO,
+      ServiceDesiredStateDAO serviceDesiredStateDAO,
+      ServiceComponentFactory serviceComponentFactory, StackDAO stackDAO,
+      AmbariMetaInfo ambariMetaInfo, AmbariEventPublisher eventPublisher)
+      throws AmbariException {
     this.cluster = cluster;
-
-    //TODO check for null states?
-    serviceDesiredStateEntity = serviceEntity.getServiceDesiredStateEntity();
+    this.clusterDAO = clusterDAO;
+    this.clusterServiceDAO = clusterServiceDAO;
+    this.serviceDesiredStateDAO = serviceDesiredStateDAO;
+    this.serviceComponentFactory = serviceComponentFactory;
+    this.stackDAO = stackDAO;
+    this.eventPublisher = eventPublisher;
+    serviceName = serviceEntity.getServiceName();
+
+    ServiceDesiredStateEntity serviceDesiredStateEntity = serviceEntity.getServiceDesiredStateEntity();
     serviceDesiredStateEntityPK = getServiceDesiredStateEntityPK(serviceDesiredStateEntity);
     serviceEntityPK = getServiceEntityPK(serviceEntity);
 
-    components = new HashMap<String, ServiceComponent>();
-
     if (!serviceEntity.getServiceComponentDesiredStateEntities().isEmpty()) {
       for (ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity
           : serviceEntity.getServiceComponentDesiredStateEntities()) {
@@ -174,13 +176,11 @@ public class ServiceImpl implements Service {
     ServiceInfo sInfo = ambariMetaInfo.getService(stackId.getStackName(),
         stackId.getStackVersion(), getName());
     isClientOnlyService = sInfo.isClientOnlyService();
-
-    persisted = true;
   }
 
   @Override
   public String getName() {
-    return serviceEntity.getServiceName();
+    return serviceName;
   }
 
   @Override
@@ -190,12 +190,7 @@ public class ServiceImpl implements Service {
 
   @Override
   public Map<String, ServiceComponent> getServiceComponents() {
-    readWriteLock.readLock().lock();
-    try {
-      return new HashMap<String, ServiceComponent>(components);
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
+    return new HashMap<String, ServiceComponent>(components);
   }
 
   @Override
@@ -217,7 +212,7 @@ public class ServiceImpl implements Service {
           + ", serviceName=" + getName()
           + ", serviceComponentName=" + component.getName());
     }
-    
+
     components.put(component.getName(), component);
   }
 
@@ -233,54 +228,40 @@ public class ServiceImpl implements Service {
   @Override
   public ServiceComponent getServiceComponent(String componentName)
       throws AmbariException {
-    readWriteLock.readLock().lock();
-    try {
-      if (!components.containsKey(componentName)) {
-        throw new ServiceComponentNotFoundException(cluster.getClusterName(),
-            getName(), componentName);
-      }
-      return components.get(componentName);
-    } finally {
-      readWriteLock.readLock().unlock();
+    ServiceComponent serviceComponent = components.get(componentName);
+    if (null == serviceComponent) {
+      throw new ServiceComponentNotFoundException(cluster.getClusterName(),
+          getName(), componentName);
     }
+
+    return serviceComponent;
   }
 
   @Override
   public State getDesiredState() {
-    readWriteLock.readLock().lock();
-    try {
-      return getServiceDesiredStateEntity().getDesiredState();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    return serviceDesiredStateEntity.getDesiredState();
   }
 
   @Override
   public void setDesiredState(State state) {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredState of Service" + ", clusterName="
-            + cluster.getClusterName() + ", clusterId="
-            + cluster.getClusterId() + ", serviceName=" + getName()
-            + ", oldDesiredState=" + getDesiredState() + ", newDesiredState="
-            + state + ", persisted = " + isPersisted());
-      }
-      getServiceDesiredStateEntity().setDesiredState(state);
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredState of Service" + ", clusterName="
+          + cluster.getClusterName() + ", clusterId="
+          + cluster.getClusterId() + ", serviceName=" + getName()
+          + ", oldDesiredState=" + getDesiredState() + ", newDesiredState="
+          + state);
     }
+
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    serviceDesiredStateEntity.setDesiredState(state);
+    serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
   }
 
   @Override
   public SecurityState getSecurityState() {
-    readWriteLock.readLock().lock();
-    try {
-      return getServiceDesiredStateEntity().getSecurityState();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    return serviceDesiredStateEntity.getSecurityState();
   }
 
   @Override
@@ -289,70 +270,52 @@ public class ServiceImpl implements Service {
       throw new AmbariException("The security state must be an endpoint state");
     }
 
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredSecurityState of Service" + ", clusterName="
-            + cluster.getClusterName() + ", clusterId="
-            + cluster.getClusterId() + ", serviceName=" + getName()
-            + ", oldDesiredSecurityState=" + getSecurityState()
-            + ", newDesiredSecurityState=" + securityState);
-      }
-      getServiceDesiredStateEntity().setSecurityState(securityState);
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredSecurityState of Service" + ", clusterName="
+          + cluster.getClusterName() + ", clusterId="
+          + cluster.getClusterId() + ", serviceName=" + getName()
+          + ", oldDesiredSecurityState=" + getSecurityState()
+          + ", newDesiredSecurityState=" + securityState);
     }
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    serviceDesiredStateEntity.setSecurityState(securityState);
+    serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
   }
 
   @Override
   public StackId getDesiredStackVersion() {
-    readWriteLock.readLock().lock();
-    try {
-      StackEntity desiredStackEntity = getServiceDesiredStateEntity().getDesiredStack();
-      if( null != desiredStackEntity ) {
-        return new StackId(desiredStackEntity);
-      } else {
-        return null;
-      }
-    } finally {
-      readWriteLock.readLock().unlock();
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    StackEntity desiredStackEntity = serviceDesiredStateEntity.getDesiredStack();
+    if( null != desiredStackEntity ) {
+      return new StackId(desiredStackEntity);
+    } else {
+      return null;
     }
   }
 
   @Override
   public void setDesiredStackVersion(StackId stack) {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredStackVersion of Service" + ", clusterName="
-            + cluster.getClusterName() + ", clusterId="
-            + cluster.getClusterId() + ", serviceName=" + getName()
-            + ", oldDesiredStackVersion=" + getDesiredStackVersion()
-            + ", newDesiredStackVersion=" + stack);
-      }
-
-      StackEntity stackEntity = stackDAO.find(stack.getStackName(), stack.getStackVersion());
-      getServiceDesiredStateEntity().setDesiredStack(stackEntity);
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredStackVersion of Service" + ", clusterName="
+          + cluster.getClusterName() + ", clusterId="
+          + cluster.getClusterId() + ", serviceName=" + getName()
+          + ", oldDesiredStackVersion=" + getDesiredStackVersion()
+          + ", newDesiredStackVersion=" + stack);
     }
+
+    StackEntity stackEntity = stackDAO.find(stack.getStackName(), stack.getStackVersion());
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    serviceDesiredStateEntity.setDesiredStack(stackEntity);
+    serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
   }
 
   @Override
   public ServiceResponse convertToResponse() {
-    readWriteLock.readLock().lock();
-    try {
-      ServiceResponse r = new ServiceResponse(cluster.getClusterId(),
-          cluster.getClusterName(), getName(),
-          getDesiredStackVersion().getStackId(), getDesiredState().toString());
+    ServiceResponse r = new ServiceResponse(cluster.getClusterId(), cluster.getClusterName(),
+        getName(), getDesiredStackVersion().getStackId(), getDesiredState().toString());
 
-      r.setMaintenanceState(getMaintenanceState().name());
-      return r;
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
+    r.setMaintenanceState(getMaintenanceState().name());
+    return r;
   }
 
   @Override
@@ -362,138 +325,79 @@ public class ServiceImpl implements Service {
 
   @Override
   public void debugDump(StringBuilder sb) {
-    readWriteLock.readLock().lock();
-    try {
-      sb.append("Service={ serviceName=" + getName() + ", clusterName="
-          + cluster.getClusterName() + ", clusterId=" + cluster.getClusterId()
-          + ", desiredStackVersion=" + getDesiredStackVersion()
-          + ", desiredState=" + getDesiredState().toString()
-          + ", components=[ ");
-      boolean first = true;
-      for (ServiceComponent sc : components.values()) {
-        if (!first) {
-          sb.append(" , ");
-        }
-        first = false;
-        sb.append("\n      ");
-        sc.debugDump(sb);
-        sb.append(" ");
+    sb.append("Service={ serviceName=" + getName() + ", clusterName=" + cluster.getClusterName()
+        + ", clusterId=" + cluster.getClusterId() + ", desiredStackVersion="
+        + getDesiredStackVersion() + ", desiredState=" + getDesiredState().toString()
+        + ", components=[ ");
+    boolean first = true;
+    for (ServiceComponent sc : components.values()) {
+      if (!first) {
+        sb.append(" , ");
       }
-      sb.append(" ] }");
-    } finally {
-      readWriteLock.readLock().unlock();
+      first = false;
+      sb.append("\n      ");
+      sc.debugDump(sb);
+      sb.append(" ");
     }
+    sb.append(" ] }");
   }
 
   /**
-   * {@inheritDoc}
-   */
-  @Override
-  public boolean isPersisted() {
-    // a lock around this internal state variable is not required since we
-    // have appropriate locks in the persist() method and this member is
-    // only ever false under the condition that the object is new
-    return persisted;
-  }
-
-  /**
-   * {@inheritDoc}
-   * <p/>
-   * This method uses Java locks and then delegates to internal methods which
-   * perform the JPA merges inside of a transaction. Because of this, a
-   * transaction is not necessary before this calling this method.
+   *
    */
-  @Override
   @Experimental(feature = ExperimentalFeature.CLUSTER_GLOBAL_LOCK_REMOVAL)
-  public void persist() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (!persisted) {
-        persistEntities();
-        refresh();
-
-        persisted = true;
+  private void persist(ClusterServiceEntity serviceEntity) {
+    persistEntities(serviceEntity);
+    refresh();
 
-        // publish the service installed event
-        StackId stackId = cluster.getDesiredStackVersion();
-        cluster.addService(this);
+    // publish the service installed event
+    StackId stackId = cluster.getDesiredStackVersion();
+    cluster.addService(this);
 
-        ServiceInstalledEvent event = new ServiceInstalledEvent(
-            getClusterId(), stackId.getStackName(),
-            stackId.getStackVersion(), getName());
+    ServiceInstalledEvent event = new ServiceInstalledEvent(getClusterId(), stackId.getStackName(),
+        stackId.getStackVersion(), getName());
 
-        eventPublisher.publish(event);
-      } else {
-        saveIfPersisted();
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
-    }
+    eventPublisher.publish(event);
   }
 
   @Transactional
-  protected void persistEntities() {
+  private void persistEntities(ClusterServiceEntity serviceEntity) {
     long clusterId = cluster.getClusterId();
-
     ClusterEntity clusterEntity = clusterDAO.findById(clusterId);
     serviceEntity.setClusterEntity(clusterEntity);
     clusterServiceDAO.create(serviceEntity);
-    serviceDesiredStateDAO.create(serviceDesiredStateEntity);
     clusterEntity.getClusterServiceEntities().add(serviceEntity);
     clusterDAO.merge(clusterEntity);
     clusterServiceDAO.merge(serviceEntity);
-    serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
-  }
-
-  @Transactional
-  void saveIfPersisted() {
-    if (isPersisted()) {
-      clusterServiceDAO.merge(serviceEntity);
-      serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
-    }
   }
 
-  @Override
   @Transactional
   public void refresh() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (isPersisted()) {
-        ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
-        pk.setClusterId(getClusterId());
-        pk.setServiceName(getName());
-        serviceEntity = clusterServiceDAO.findByPK(pk);
-        serviceDesiredStateEntity = serviceEntity.getServiceDesiredStateEntity();
-        clusterServiceDAO.refresh(serviceEntity);
-        serviceDesiredStateDAO.refresh(serviceDesiredStateEntity);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
-    }
+    ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
+    pk.setClusterId(getClusterId());
+    pk.setServiceName(getName());
+    ClusterServiceEntity serviceEntity = getServiceEntity();
+    clusterServiceDAO.refresh(serviceEntity);
+    serviceDesiredStateDAO.refresh(serviceEntity.getServiceDesiredStateEntity());
   }
 
   @Override
   @Experimental(feature = ExperimentalFeature.CLUSTER_GLOBAL_LOCK_REMOVAL)
   public boolean canBeRemoved() {
-    readWriteLock.readLock().lock();
-    try {
-      //
-      // A service can be deleted if all it's components
-      // can be removed, irrespective of the state of
-      // the service itself.
-      //
-      for (ServiceComponent sc : components.values()) {
-        if (!sc.canBeRemoved()) {
-          LOG.warn("Found non removable component when trying to delete service" + ", clusterName="
-              + cluster.getClusterName() + ", serviceName=" + getName() + ", componentName="
-              + sc.getName());
-          return false;
-        }
+    //
+    // A service can be deleted if all it's components
+    // can be removed, irrespective of the state of
+    // the service itself.
+    //
+    for (ServiceComponent sc : components.values()) {
+      if (!sc.canBeRemoved()) {
+        LOG.warn("Found non removable component when trying to delete service" + ", clusterName="
+            + cluster.getClusterName() + ", serviceName=" + getName() + ", componentName="
+            + sc.getName());
+        return false;
       }
-      return true;
-    } finally {
-      readWriteLock.readLock().unlock();
     }
+    return true;
   }
 
   @Transactional
@@ -537,7 +441,7 @@ public class ServiceImpl implements Service {
   @Transactional
   @Experimental(feature = ExperimentalFeature.CLUSTER_GLOBAL_LOCK_REMOVAL)
   public void deleteAllComponents() throws AmbariException {
-    readWriteLock.writeLock().lock();
+    lock.lock();
     try {
       LOG.info("Deleting all components for service" + ", clusterName=" + cluster.getClusterName()
           + ", serviceName=" + getName());
@@ -556,7 +460,7 @@ public class ServiceImpl implements Service {
 
       components.clear();
     } finally {
-      readWriteLock.writeLock().unlock();
+      lock.unlock();
     }
   }
 
@@ -564,7 +468,7 @@ public class ServiceImpl implements Service {
   @Experimental(feature = ExperimentalFeature.CLUSTER_GLOBAL_LOCK_REMOVAL)
   public void deleteServiceComponent(String componentName)
       throws AmbariException {
-    readWriteLock.writeLock().lock();
+    lock.lock();
     try {
       ServiceComponent component = getServiceComponent(componentName);
       LOG.info("Deleting servicecomponent for cluster" + ", clusterName=" + cluster.getClusterName()
@@ -580,7 +484,7 @@ public class ServiceImpl implements Service {
       component.delete();
       components.remove(componentName);
     } finally {
-      readWriteLock.writeLock().unlock();
+      lock.unlock();
     }
   }
 
@@ -593,26 +497,18 @@ public class ServiceImpl implements Service {
   @Transactional
   @Experimental(feature = ExperimentalFeature.CLUSTER_GLOBAL_LOCK_REMOVAL)
   public void delete() throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      deleteAllComponents();
-      deleteAllServiceConfigs();
+    deleteAllComponents();
+    deleteAllServiceConfigs();
 
-      if (persisted) {
-        removeEntities();
-        persisted = false;
+    removeEntities();
 
-        // publish the service removed event
-        StackId stackId = cluster.getDesiredStackVersion();
+    // publish the service removed event
+    StackId stackId = cluster.getDesiredStackVersion();
 
-        ServiceRemovedEvent event = new ServiceRemovedEvent(getClusterId(), stackId.getStackName(),
-            stackId.getStackVersion(), getName());
+    ServiceRemovedEvent event = new ServiceRemovedEvent(getClusterId(), stackId.getStackName(),
+        stackId.getStackVersion(), getName());
 
-        eventPublisher.publish(event);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
-    }
+    eventPublisher.publish(event);
   }
 
   @Transactional
@@ -628,17 +524,13 @@ public class ServiceImpl implements Service {
 
   @Override
   public void setMaintenanceState(MaintenanceState state) {
-    readWriteLock.writeLock().lock();
-    try {
-      getServiceDesiredStateEntity().setMaintenanceState(state);
-      saveIfPersisted();
+    ServiceDesiredStateEntity serviceDesiredStateEntity = getServiceDesiredStateEntity();
+    serviceDesiredStateEntity.setMaintenanceState(state);
+    serviceDesiredStateDAO.merge(serviceDesiredStateEntity);
 
-      // broadcast the maintenance mode change
-      MaintenanceModeEvent event = new MaintenanceModeEvent(state, this);
-      eventPublisher.publish(event);
-    } finally {
-      readWriteLock.writeLock().unlock();
-    }
+    // broadcast the maintenance mode change
+    MaintenanceModeEvent event = new MaintenanceModeEvent(state, this);
+    eventPublisher.publish(event);
   }
 
   @Override
@@ -647,10 +539,7 @@ public class ServiceImpl implements Service {
   }
 
   private ClusterServiceEntity getServiceEntity() {
-    if (isPersisted()) {
-      serviceEntity = clusterServiceDAO.findByPK(serviceEntityPK);
-    }
-    return serviceEntity;
+    return clusterServiceDAO.findByPK(serviceEntityPK);
   }
 
   private ClusterServiceEntityPK getServiceEntityPK(ClusterServiceEntity serviceEntity) {
@@ -669,9 +558,6 @@ public class ServiceImpl implements Service {
 
   // Refresh the cached reference on setters
   private ServiceDesiredStateEntity getServiceDesiredStateEntity() {
-    if (isPersisted()) {
-      serviceDesiredStateEntity = serviceDesiredStateDAO.findByPK(serviceDesiredStateEntityPK);
-    }
-    return serviceDesiredStateEntity;
+    return serviceDesiredStateDAO.findByPK(serviceDesiredStateEntityPK);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index aff3a3b..bed33d9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -464,8 +464,6 @@ public class ClustersImpl implements Clusters {
         host.setHostAttributes(attributes);
       }
 
-      host.refresh();
-
       Set<String> hostClusterNames = hostClusters.get(hostname);
       for (String clusterName : hostClusterNames) {
         if (clusterName != null && !clusterName.isEmpty()) {
@@ -554,7 +552,6 @@ public class ClustersImpl implements Clusters {
     clusterHostMap.get(clusterName).add(host);
 
     cluster.refresh();
-    host.refresh();
   }
 
   /**
@@ -673,7 +670,6 @@ public class ClustersImpl implements Clusters {
     unmapHostFromClusters(host, Sets.newHashSet(cluster));
 
     cluster.refresh();
-    host.refresh();
   }
 
   @Transactional

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index ec8873a..286b5ca 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
@@ -108,7 +108,6 @@ public class HostImpl implements Host {
       new TypeToken<Map<Long, MaintenanceState>>() {}.getType();
 
   ReadWriteLock rwLock;
-  private final Lock readLock;
   private final Lock writeLock;
 
   @Inject
@@ -257,7 +256,6 @@ public class HostImpl implements Host {
 
     stateMachine = stateMachineFactory.make(this);
     rwLock = new ReentrantReadWriteLock();
-    readLock = rwLock.readLock();
     writeLock = rwLock.writeLock();
 
     HostStateEntity hostStateEntity = hostEntity.getHostStateEntity();
@@ -274,8 +272,6 @@ public class HostImpl implements Host {
     if (null == hostEntity.getHostId()) {
       persistEntities(hostEntity);
 
-      refresh();
-
       for (ClusterEntity clusterEntity : hostEntity.getClusterEntities()) {
         try {
           clusters.getClusterById(clusterEntity.getClusterId()).refresh();
@@ -963,17 +959,6 @@ public class HostImpl implements Host {
 
   @Override
   @Transactional
-  public void refresh() {
-    writeLock.lock();
-    try {
-      getHostEntity();
-    } finally {
-      writeLock.unlock();
-    }
-  }
-
-  @Override
-  @Transactional
   public boolean addDesiredConfig(long clusterId, boolean selected, String user, Config config) {
     if (null == user) {
       throw new NullPointerException("User must be specified.");

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 7e345e5..a575456 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -1563,12 +1563,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
     try {
       if (persisted) {
         removeEntities();
-
-        // host must be re-loaded from db to refresh the cached JPA HostEntity
-        // that references HostComponentDesiredStateEntity
-        // and HostComponentStateEntity JPA entities
-        host.refresh();
-
         persisted = false;
         fireRemovalEvent = true;
       }
@@ -1604,14 +1598,16 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
   protected void removeEntities() {
     HostComponentStateEntity stateEntity = getStateEntity();
     if (stateEntity != null) {
-      // make sure that the state entities are removed from the associated (detached) host entity
-      // Also refresh before delete
-      stateEntity.getHostEntity().removeHostComponentStateEntity(stateEntity);
+      HostEntity hostEntity = stateEntity.getHostEntity();
       HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity();
-      desiredStateEntity.getHostEntity().removeHostComponentDesiredStateEntity(desiredStateEntity);
 
-      hostComponentDesiredStateDAO.remove(desiredStateEntity);
+      // Make sure that the state entity is removed from its host entity
+      hostEntity.removeHostComponentStateEntity(stateEntity);
+      hostEntity.removeHostComponentDesiredStateEntity(desiredStateEntity);
 
+      hostDAO.merge(hostEntity);
+
+      hostComponentDesiredStateDAO.remove(desiredStateEntity);
       hostComponentStateDAO.remove(stateEntity);
     }
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/main/java/org/apache/ambari/server/utils/RetryHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/utils/RetryHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/utils/RetryHelper.java
index 17f1447..d732edf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/utils/RetryHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/utils/RetryHelper.java
@@ -86,6 +86,7 @@ public class RetryHelper {
   public static void invalidateAffectedClusters() {
     for (Cluster cluster : affectedClusters.get()) {
       s_clusters.invalidate(cluster);
+      affectedClusters.get().remove(cluster);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index dd93374..64305ff 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -159,7 +159,6 @@ public class HeartbeatProcessorTest {
   public void testHeartbeatWithConfigs() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -229,7 +228,6 @@ public class HeartbeatProcessorTest {
   public void testRestartRequiredAfterInstallClient() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(HDFS_CLIENT).persist();
     hdfs.getServiceComponent(HDFS_CLIENT).addServiceComponentHost(DummyHostname1).persist();
 
@@ -295,7 +293,6 @@ public class HeartbeatProcessorTest {
   public void testHeartbeatCustomCommandWithConfigs() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -380,7 +377,6 @@ public class HeartbeatProcessorTest {
   public void testHeartbeatCustomStartStop() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -465,7 +461,6 @@ public class HeartbeatProcessorTest {
   public void testStatusHeartbeat() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -595,7 +590,6 @@ public class HeartbeatProcessorTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
 
@@ -715,7 +709,6 @@ public class HeartbeatProcessorTest {
   public void testUpgradeSpecificHandling() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
 
@@ -810,7 +803,6 @@ public class HeartbeatProcessorTest {
   public void testCommandStatusProcesses() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED);
@@ -892,7 +884,6 @@ public class HeartbeatProcessorTest {
   public void testComponentUpgradeCompleteReport() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -977,7 +968,6 @@ public class HeartbeatProcessorTest {
   public void testComponentUpgradeFailReport() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -1098,7 +1088,6 @@ public class HeartbeatProcessorTest {
   public void testComponentUpgradeInProgressReport() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -1305,7 +1294,6 @@ public class HeartbeatProcessorTest {
   public void testComponentInProgressStatusSafeAfterStatusReport() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).
         addServiceComponentHost(DummyHostname1).persist();

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index 0f48cf6..6205f59 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -221,7 +221,6 @@ public class TestHeartbeatHandler {
   public void testStatusHeartbeatWithAnnotation() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
     hdfs.addServiceComponent(SECONDARY_NAMENODE).persist();
@@ -273,7 +272,6 @@ public class TestHeartbeatHandler {
   public void testLiveStatusUpdateAfterStopFailed() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).
             addServiceComponentHost(DummyHostname1).persist();
@@ -385,7 +383,6 @@ public class TestHeartbeatHandler {
                                                     injector);
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -449,7 +446,6 @@ public class TestHeartbeatHandler {
             injector);
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     /**
      * Add three service components enabled for auto start.
@@ -784,7 +780,6 @@ public class TestHeartbeatHandler {
   public void testTaskInProgressHandling() throws Exception, InvalidStateTransitionException {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -842,7 +837,6 @@ public class TestHeartbeatHandler {
   public void testOPFailedEventForAbortedTask() throws Exception, InvalidStateTransitionException {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -917,7 +911,6 @@ public class TestHeartbeatHandler {
   public void testStatusHeartbeatWithVersion() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -995,7 +988,6 @@ public class TestHeartbeatHandler {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Host hostObject = clusters.getHost(DummyHostname1);
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -1077,7 +1069,6 @@ public class TestHeartbeatHandler {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Host hostObject = clusters.getHost(DummyHostname1);
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.addServiceComponent(NAMENODE).persist();
@@ -1412,7 +1403,6 @@ public class TestHeartbeatHandler {
   public void testCommandStatusProcesses_empty() throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
     hdfs.addServiceComponent(DATANODE).persist();
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1).persist();
     hdfs.getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1).setState(State.STARTED);

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 503c8e5..e6a3ee6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -168,7 +168,6 @@ public class TestHeartbeatMonitor {
 
     clusters.mapHostsToCluster(hostNames, clusterName);
     Service hdfs = cluster.addService(serviceName);
-    hdfs.persist();
     hdfs.addServiceComponent(Role.DATANODE.name()).persist();
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -261,7 +260,6 @@ public class TestHeartbeatMonitor {
 
     clusters.mapHostsToCluster(hostNames, clusterName);
     Service hdfs = cluster.addService(serviceName);
-    hdfs.persist();
     hdfs.addServiceComponent(Role.DATANODE.name()).persist();
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost
       (hostname1).persist();
@@ -370,7 +368,6 @@ public class TestHeartbeatMonitor {
     clusters.mapHostsToCluster(hostNames, clusterName);
 
     Service hdfs = cluster.addService(serviceName);
-    hdfs.persist();
     hdfs.addServiceComponent(Role.DATANODE.name()).persist();
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -453,7 +450,6 @@ public class TestHeartbeatMonitor {
     clusters.mapHostsToCluster(hostNames, clusterName);
 
     Service hdfs = cluster.addService(serviceName);
-    hdfs.persist();
     hdfs.addServiceComponent(Role.DATANODE.name()).persist();
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -573,7 +569,6 @@ public class TestHeartbeatMonitor {
     clusters.mapHostsToCluster(hostNames, clusterName);
 
     Service hdfs = cluster.addService(serviceName);
-    hdfs.persist();
 
     hdfs.addServiceComponent(Role.DATANODE.name()).persist();
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1).persist();

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
index 9f79a32..4641dfc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/AmbariMetaInfoTest.java
@@ -87,6 +87,7 @@ import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptorFactory;
 import org.apache.ambari.server.state.stack.Metric;
 import org.apache.ambari.server.state.stack.MetricDefinition;
 import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.utils.EventBusSynchronizer;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.easymock.Capture;
@@ -1899,6 +1900,8 @@ public class AmbariMetaInfoTest {
     Injector injector = Guice.createInjector(Modules.override(
         new InMemoryDefaultTestModule()).with(new MockModule()));
 
+    EventBusSynchronizer.synchronizeAmbariEventPublisher(injector);
+
     injector.getInstance(GuiceJpaInitializer.class);
     injector.getInstance(EntityManager.class);
     long clusterId = injector.getInstance(OrmTestHelper.class).createCluster(

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
index 50f5abe..351d473 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
@@ -135,7 +135,6 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -171,7 +170,6 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -209,7 +207,6 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -250,7 +247,6 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -287,7 +283,6 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();
@@ -330,7 +325,6 @@ public class RecoveryConfigHelperTest {
 
     // Add HDFS service with DATANODE component to the cluster
     Service hdfs = cluster.addService(HDFS);
-    hdfs.persist();
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).persist();

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index a3521fd..d61a3e7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -1006,8 +1006,6 @@ public class AmbariManagementControllerTest {
     Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
     c1.addService(s1);
     c1.addService(s2);
-    s1.persist();
-    s2.persist();
 
     set1.clear();
     ServiceComponentRequest valid1 =
@@ -1311,8 +1309,6 @@ public class AmbariManagementControllerTest {
     Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
     c1.addService(s1);
     c1.addService(s2);
-    s1.persist();
-    s2.persist();
 
     Set<ServiceComponentRequest> set1 = new HashSet<ServiceComponentRequest>();
     ServiceComponentRequest valid1 =
@@ -1622,13 +1618,10 @@ public class AmbariManagementControllerTest {
 
     Service s1 = serviceFactory.createNew(foo, "HDFS");
     foo.addService(s1);
-    s1.persist();
     Service s2 = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s2);
-    s2.persist();
     Service s3 = serviceFactory.createNew(c2, "HDFS");
     c2.addService(s3);
-    s3.persist();
 
 
     try {
@@ -2268,8 +2261,6 @@ public class AmbariManagementControllerTest {
     s1.setDesiredStackVersion(new StackId("HDP-0.1"));
     s1.setDesiredState(State.INSTALLED);
 
-    s1.persist();
-
     ServiceRequest r = new ServiceRequest(cluster1, null, null);
     Set<ServiceResponse> resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
 
@@ -2314,12 +2305,6 @@ public class AmbariManagementControllerTest {
     s2.setDesiredState(State.INSTALLED);
     s4.setDesiredState(State.INSTALLED);
 
-    s1.persist();
-    s2.persist();
-    s3.persist();
-    s4.persist();
-    s5.persist();
-
     ServiceRequest r = new ServiceRequest(null, null, null);
     Set<ServiceResponse> resp;
 
@@ -2378,7 +2363,6 @@ public class AmbariManagementControllerTest {
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s1);
     s1.setDesiredState(State.INSTALLED);
-    s1.persist();
     ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE");
     s1.addServiceComponent(sc1);
     sc1.persist();
@@ -2430,12 +2414,6 @@ public class AmbariManagementControllerTest {
     s2.setDesiredState(State.INSTALLED);
     s4.setDesiredState(State.INSTALLED);
 
-    s1.persist();
-    s2.persist();
-    s3.persist();
-    s4.persist();
-    s5.persist();
-
     ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE");
     ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE");
     ServiceComponent sc3 = serviceComponentFactory.createNew(s3,
@@ -2548,7 +2526,6 @@ public class AmbariManagementControllerTest {
     Cluster c1 = setupClusterWithHosts(cluster1, "HDP-0.1", Lists.newArrayList(host1), "centos5");
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s1);
-    s1.persist();
     ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE");
     s1.addServiceComponent(sc1);
     sc1.setDesiredState(State.UNINSTALLED);
@@ -2964,10 +2941,6 @@ public class AmbariManagementControllerTest {
     s1.setDesiredState(State.INSTALLED);
     s2.setDesiredState(State.INSTALLED);
 
-    s1.persist();
-    s2.persist();
-    s3.persist();
-
     ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "DATANODE");
     ServiceComponent sc2 = serviceComponentFactory.createNew(s1, "NAMENODE");
     ServiceComponent sc3 = serviceComponentFactory.createNew(s3,
@@ -4285,10 +4258,7 @@ public class AmbariManagementControllerTest {
     cluster.addConfig(config3);
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
-
     Service mapred = cluster.addService("YARN");
-    mapred.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -4454,7 +4424,6 @@ public class AmbariManagementControllerTest {
     cluster.addConfig(config2);
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -4564,10 +4533,7 @@ public class AmbariManagementControllerTest {
     cluster.addDesiredConfig("_test", Collections.singleton(config2));
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
-
     Service hive = cluster.addService("HIVE");
-    hive.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -4852,8 +4818,6 @@ public class AmbariManagementControllerTest {
 
     Service hdfs = cluster.addService("HDFS");
     Service mapReduce = cluster.addService("MAPREDUCE");
-    hdfs.persist();
-    mapReduce.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     mapReduce.addServiceComponent(Role.MAPREDUCE_CLIENT.name()).persist();
@@ -6532,10 +6496,7 @@ public class AmbariManagementControllerTest {
     cluster.addConfig(config2);
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
-
     Service mapred = cluster.addService("YARN");
-    mapred.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -6641,10 +6602,7 @@ public class AmbariManagementControllerTest {
     cluster.addConfig(config2);
 
     Service hdfs = cluster.addService("HDFS");
-    hdfs.persist();
-
     Service mapred = cluster.addService("YARN");
-    mapred.persist();
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name()).persist();
     hdfs.addServiceComponent(Role.NAMENODE.name()).persist();
@@ -10101,7 +10059,6 @@ public class AmbariManagementControllerTest {
       "centos5");
 
     Service hdfs = c1.addService("HDFS");
-    hdfs.persist();
     createServiceComponent(cluster1, "HDFS", "NAMENODE", State.INIT);
     createServiceComponent(cluster1, "HDFS", "DATANODE", State.INIT);
     createServiceComponent(cluster1, "HDFS", "HDFS_CLIENT", State.INIT);

http://git-wip-us.apache.org/repos/asf/ambari/blob/0de69e10/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
index 6a0fa12..e09b9c5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/PreUpgradeCheckResourceProviderTest.java
@@ -18,32 +18,40 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+
 import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.ActionDBAccessor;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.checks.AbstractCheckDescriptor;
 import org.apache.ambari.server.checks.UpgradeCheckRegistry;
 import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.KerberosHelper;
-import org.apache.ambari.server.controller.MaintenanceStateHelper;
-import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
-import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.events.jpa.EntityManagerCacheInvalidationEvent;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
-import org.apache.ambari.server.scheduler.ExecutionScheduler;
 import org.apache.ambari.server.stack.StackManagerFactory;
 import org.apache.ambari.server.state.CheckHelper;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
-import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceFactory;
 import org.apache.ambari.server.state.ServiceInfo;
@@ -56,41 +64,14 @@ import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.UpgradePack.PrerequisiteCheckConfig;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
-import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.io.File;
-import java.lang.reflect.Field;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.persistence.EntityManager;
-
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Provider;
 
-import static org.easymock.EasyMock.anyBoolean;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.createStrictMock;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.isNull;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-
 /**
  * PreUpgradeCheckResourceProvider tests.
  */
@@ -126,7 +107,6 @@ public class PreUpgradeCheckResourceProviderTest {
     // set expectations
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
-    expect(managementController.getServiceFactory()).andReturn(serviceFactory).anyTimes();
 
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
     expect(cluster.getServices()).andReturn(allServiceMap).anyTimes();


Mime
View raw message