You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/05/31 00:14:32 UTC

svn commit: r1488039 [2/10] - in /incubator/ambari/branches/branch-1.2.4: ./ ambari-agent/ ambari-agent/src/main/puppet/modules/hdp-ganglia/manifests/ ambari-agent/src/main/puppet/modules/hdp-ganglia/templates/ ambari-agent/src/main/puppet/modules/hdp-...

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java?rev=1488039&r1=1488038&r2=1488039&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java Thu May 30 22:14:29 2013
@@ -20,8 +20,6 @@ package org.apache.ambari.server.state;
 
 import java.util.*;
 import java.util.Map.Entry;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import com.google.gson.Gson;
 import com.google.inject.Inject;
@@ -43,8 +41,6 @@ public class ServiceComponentImpl implem
 
   private final static Logger LOG =
       LoggerFactory.getLogger(ServiceComponentImpl.class);
-  
-  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 
   private final Service service;
 
@@ -158,374 +154,260 @@ public class ServiceComponentImpl implem
   }
 
   @Override
-  public String getName() {
-    readWriteLock.readLock().lock();
-    try {
-      return desiredStateEntity.getComponentName();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized String getName() {
+    return desiredStateEntity.getComponentName();
   }
 
   @Override
-  public String getServiceName() {
-    readWriteLock.readLock().lock();
-    try {
-      return service.getName();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized String getServiceName() {
+    return service.getName();
   }
 
   @Override
-  public long getClusterId() {
-    readWriteLock.readLock().lock();
-    try {
-      return this.service.getClusterId();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized long getClusterId() {
+    return this.service.getClusterId();
   }
 
   @Override
-  public Map<String, ServiceComponentHost>
+  public synchronized Map<String, ServiceComponentHost>
       getServiceComponentHosts() {
-    readWriteLock.readLock().lock();
-    try {
-      return Collections.unmodifiableMap(hostComponents);
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+    return Collections.unmodifiableMap(hostComponents);
   }
 
   @Override
-  public void addServiceComponentHosts(
+  public synchronized void addServiceComponentHosts(
       Map<String, ServiceComponentHost> hostComponents) throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      // TODO validation
-      for (Entry<String, ServiceComponentHost> entry :
-          hostComponents.entrySet()) {
-        if (!entry.getKey().equals(entry.getValue().getHostName())) {
-          throw new AmbariException("Invalid arguments in map"
-              + ", hostname does not match the key in map");
-        }
+    // TODO validation
+    for (Entry<String, ServiceComponentHost> entry :
+      hostComponents.entrySet()) {
+      if (!entry.getKey().equals(entry.getValue().getHostName())) {
+        throw new AmbariException("Invalid arguments in map"
+            + ", hostname does not match the key in map");
       }
-      for (ServiceComponentHost sch : hostComponents.values()) {
-        addServiceComponentHost(sch);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
     }
-
+    for (ServiceComponentHost sch : hostComponents.values()) {
+      addServiceComponentHost(sch);
+    }
   }
 
   @Override
-  public void addServiceComponentHost(
+  public synchronized void addServiceComponentHost(
       ServiceComponentHost hostComponent) throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      // TODO validation
-      // TODO ensure host belongs to cluster
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Adding a ServiceComponentHost to ServiceComponent"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", hostname=" + hostComponent.getHostName());
-      }
-      if (hostComponents.containsKey(hostComponent.getHostName())) {
-        throw new AmbariException("Cannot add duplicate ServiceComponentHost"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", hostname=" + hostComponent.getHostName());
-      }
-      // FIXME need a better approach of caching components by host
-      ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
-      clusterImpl.addServiceComponentHost(hostComponent);
-      this.hostComponents.put(hostComponent.getHostName(), hostComponent);
-    } finally {
-      readWriteLock.writeLock().unlock();
+    // TODO validation
+    // TODO ensure host belongs to cluster
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Adding a ServiceComponentHost to ServiceComponent"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", hostname=" + hostComponent.getHostName());
     }
-
+    if (hostComponents.containsKey(hostComponent.getHostName())) {
+      throw new AmbariException("Cannot add duplicate ServiceComponentHost"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", hostname=" + hostComponent.getHostName());
+    }
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.addServiceComponentHost(hostComponent);
+    this.hostComponents.put(hostComponent.getHostName(), hostComponent);
   }
 
   @Override
-  public ServiceComponentHost addServiceComponentHost(
+  public synchronized ServiceComponentHost addServiceComponentHost(
       String hostName) throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      // TODO validation
-      // TODO ensure host belongs to cluster
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Adding a ServiceComponentHost to ServiceComponent"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", hostname=" + hostName);
-      }
-      if (hostComponents.containsKey(hostName)) {
-        throw new AmbariException("Cannot add duplicate ServiceComponentHost"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", hostname=" + hostName);
-      }
-      ServiceComponentHost hostComponent =
-          serviceComponentHostFactory.createNew(this, hostName, this.isClientComponent());
-      // FIXME need a better approach of caching components by host
-      ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
-      clusterImpl.addServiceComponentHost(hostComponent);
-
-      this.hostComponents.put(hostComponent.getHostName(), hostComponent);
-
-      return hostComponent;
-    } finally {
-      readWriteLock.writeLock().unlock();
+    // TODO validation
+    // TODO ensure host belongs to cluster
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Adding a ServiceComponentHost to ServiceComponent"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", hostname=" + hostName);
+    }
+    if (hostComponents.containsKey(hostName)) {
+      throw new AmbariException("Cannot add duplicate ServiceComponentHost"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", hostname=" + hostName);
     }
+    ServiceComponentHost hostComponent =
+        serviceComponentHostFactory.createNew(this, hostName, this.isClientComponent());
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.addServiceComponentHost(hostComponent);
+
+    this.hostComponents.put(hostComponent.getHostName(), hostComponent);
 
+    return hostComponent;
   }
 
   @Override
   public ServiceComponentHost getServiceComponentHost(String hostname)
     throws AmbariException {
-    readWriteLock.readLock().lock();
-    try {
-      if (!hostComponents.containsKey(hostname)) {
-        throw new ServiceComponentHostNotFoundException(getClusterName(),
-            getServiceName(), getName(), hostname);
-      }
-      return this.hostComponents.get(hostname);
-    } finally {
-      readWriteLock.readLock().unlock();
+    if (!hostComponents.containsKey(hostname)) {
+      throw new ServiceComponentHostNotFoundException(getClusterName(),
+          getServiceName(), getName(), hostname);
     }
-
+    return this.hostComponents.get(hostname);
   }
 
   @Override
-  public State getDesiredState() {
-    readWriteLock.readLock().lock();
-    try {
-      return desiredStateEntity.getDesiredState();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized State getDesiredState() {
+    return desiredStateEntity.getDesiredState();
   }
 
   @Override
-  public void setDesiredState(State state) {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredState of Service"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", oldDesiredState=" + getDesiredState()
-            + ", newDesiredState=" + state);
-      }
-      desiredStateEntity.setDesiredState(state);
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void setDesiredState(State state) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredState of Service"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", oldDesiredState=" + getDesiredState()
+          + ", newDesiredState=" + state);
     }
-
+    desiredStateEntity.setDesiredState(state);
+    saveIfPersisted();
   }
 
   @Override
-  public Map<String, Config> getDesiredConfigs() {
-    readWriteLock.readLock().lock();
-    try {
-      Map<String, Config> map = new HashMap<String, Config>();
-      for (Entry<String, String> entry : desiredConfigs.entrySet()) {
-        Config config = service.getCluster().getConfig(entry.getKey(), entry.getValue());
-        if (null != config) {
-          map.put(entry.getKey(), config);
-        }
+  public synchronized Map<String, Config> getDesiredConfigs() {
+    Map<String, Config> map = new HashMap<String, Config>();
+    for (Entry<String, String> entry : desiredConfigs.entrySet()) {
+      Config config = service.getCluster().getConfig(entry.getKey(), entry.getValue());
+      if (null != config) {
+        map.put(entry.getKey(), config);
       }
+    }
 
-      Map<String, Config> svcConfigs = service.getDesiredConfigs();
-      for (Entry<String, Config> entry : svcConfigs.entrySet()) {
-        if (!map.containsKey(entry.getKey())) {
-          map.put(entry.getKey(), entry.getValue());
-        }
+    Map<String, Config> svcConfigs = service.getDesiredConfigs();
+    for (Entry<String, Config> entry : svcConfigs.entrySet()) {
+      if (!map.containsKey(entry.getKey())) {
+        map.put(entry.getKey(), entry.getValue());
       }
-
-      return Collections.unmodifiableMap(map);
-    } finally {
-      readWriteLock.readLock().unlock();
     }
 
+    return Collections.unmodifiableMap(map);
   }
 
   @Override
-  public void updateDesiredConfigs(Map<String, Config> configs) {
+  public synchronized void updateDesiredConfigs(Map<String, Config> configs) {
 
-    readWriteLock.writeLock().lock();
-    try {
-      for (Entry<String, Config> entry : configs.entrySet()) {
-        boolean contains = false;
+    for (Entry<String,Config> entry : configs.entrySet()) {
+      boolean contains = false;
 
-        for (ComponentConfigMappingEntity componentConfigMappingEntity : desiredStateEntity.getComponentConfigMappingEntities()) {
-          if (entry.getKey().equals(componentConfigMappingEntity.getConfigType())) {
-            contains = true;
-            componentConfigMappingEntity.setTimestamp(new Date().getTime());
-            componentConfigMappingEntity.setVersionTag(entry.getValue().getVersionTag());
-            if (persisted) {
-              componentConfigMappingDAO.merge(componentConfigMappingEntity);
-            }
+      for (ComponentConfigMappingEntity componentConfigMappingEntity : desiredStateEntity.getComponentConfigMappingEntities()) {
+        if (entry.getKey().equals(componentConfigMappingEntity.getConfigType())) {
+          contains = true;
+          componentConfigMappingEntity.setTimestamp(new Date().getTime());
+          componentConfigMappingEntity.setVersionTag(entry.getValue().getVersionTag());
+          if (persisted) {
+            componentConfigMappingDAO.merge(componentConfigMappingEntity);
           }
         }
+      }
 
-        if (!contains) {
-          ComponentConfigMappingEntity newEntity = new ComponentConfigMappingEntity();
-          newEntity.setClusterId(desiredStateEntity.getClusterId());
-          newEntity.setServiceName(desiredStateEntity.getServiceName());
-          newEntity.setComponentName(desiredStateEntity.getComponentName());
-          newEntity.setConfigType(entry.getKey());
-          newEntity.setVersionTag(entry.getValue().getVersionTag());
-          newEntity.setTimestamp(new Date().getTime());
-          newEntity.setServiceComponentDesiredStateEntity(desiredStateEntity);
-          desiredStateEntity.getComponentConfigMappingEntities().add(newEntity);
-
-        }
-
+      if (!contains) {
+        ComponentConfigMappingEntity newEntity = new ComponentConfigMappingEntity();
+        newEntity.setClusterId(desiredStateEntity.getClusterId());
+        newEntity.setServiceName(desiredStateEntity.getServiceName());
+        newEntity.setComponentName(desiredStateEntity.getComponentName());
+        newEntity.setConfigType(entry.getKey());
+        newEntity.setVersionTag(entry.getValue().getVersionTag());
+        newEntity.setTimestamp(new Date().getTime());
+        newEntity.setServiceComponentDesiredStateEntity(desiredStateEntity);
+        desiredStateEntity.getComponentConfigMappingEntities().add(newEntity);
 
-        this.desiredConfigs.put(entry.getKey(), entry.getValue().getVersionTag());
       }
 
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+
+      this.desiredConfigs.put(entry.getKey(), entry.getValue().getVersionTag());
     }
 
+    saveIfPersisted();
   }
 
   @Override
-  public StackId getDesiredStackVersion() {
-    readWriteLock.readLock().lock();
-    try {
-      return gson.fromJson(desiredStateEntity.getDesiredStackVersion(), StackId.class);
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized StackId getDesiredStackVersion() {
+    return gson.fromJson(desiredStateEntity.getDesiredStackVersion(), StackId.class);
   }
 
   @Override
-  public void setDesiredStackVersion(StackId stackVersion) {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredStackVersion of Service"
-            + ", clusterName=" + service.getCluster().getClusterName()
-            + ", clusterId=" + service.getCluster().getClusterId()
-            + ", serviceName=" + service.getName()
-            + ", serviceComponentName=" + getName()
-            + ", oldDesiredStackVersion=" + getDesiredStackVersion()
-            + ", newDesiredStackVersion=" + stackVersion);
-      }
-      desiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
-    }
-
+  public synchronized void setDesiredStackVersion(StackId stackVersion) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredStackVersion of Service"
+          + ", clusterName=" + service.getCluster().getClusterName()
+          + ", clusterId=" + service.getCluster().getClusterId()
+          + ", serviceName=" + service.getName()
+          + ", serviceComponentName=" + getName()
+          + ", oldDesiredStackVersion=" + getDesiredStackVersion()
+          + ", newDesiredStackVersion=" + stackVersion);
+    }
+    desiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
+    saveIfPersisted();
   }
 
   @Override
-  public ServiceComponentResponse convertToResponse() {
-    readWriteLock.readLock().lock();
-    try {
-      ServiceComponentResponse r = new ServiceComponentResponse(
-          getClusterId(), service.getCluster().getClusterName(),
-          service.getName(), getName(), this.desiredConfigs,
-          getDesiredStackVersion().getStackId(),
-          getDesiredState().toString());
-      return r;
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized ServiceComponentResponse convertToResponse() {
+    ServiceComponentResponse r  = new ServiceComponentResponse(
+        getClusterId(), service.getCluster().getClusterName(),
+        service.getName(), getName(), this.desiredConfigs,
+        getDesiredStackVersion().getStackId(),
+        getDesiredState().toString());
+    return r;
   }
 
   @Override
   public String getClusterName() {
-    readWriteLock.readLock().lock();
-    try {
-      return service.getCluster().getClusterName();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+    return service.getCluster().getClusterName();
   }
 
   @Override
-  public void debugDump(StringBuilder sb) {
-    readWriteLock.readLock().lock();
-    try {
-      sb.append("ServiceComponent={ serviceComponentName=" + getName()
-          + ", clusterName=" + service.getCluster().getClusterName()
-          + ", clusterId=" + service.getCluster().getClusterId()
-          + ", serviceName=" + service.getName()
-          + ", desiredStackVersion=" + getDesiredStackVersion()
-          + ", desiredState=" + getDesiredState().toString()
-          + ", hostcomponents=[ ");
-      boolean first = true;
-      for (ServiceComponentHost sch : hostComponents.values()) {
-        if (!first) {
-          sb.append(" , ");
-          first = false;
-        }
-        sb.append("\n        ");
-        sch.debugDump(sb);
-        sb.append(" ");
+  public synchronized void debugDump(StringBuilder sb) {
+    sb.append("ServiceComponent={ serviceComponentName=" + getName()
+        + ", clusterName=" + service.getCluster().getClusterName()
+        + ", clusterId=" + service.getCluster().getClusterId()
+        + ", serviceName=" + service.getName()
+        + ", desiredStackVersion=" + getDesiredStackVersion()
+        + ", desiredState=" + getDesiredState().toString()
+        + ", hostcomponents=[ ");
+    boolean first = true;
+    for(ServiceComponentHost sch : hostComponents.values()) {
+      if (!first) {
+        sb.append(" , ");
+        first = false;
       }
-      sb.append(" ] }");
-    } finally {
-      readWriteLock.readLock().unlock();
+      sb.append("\n        ");
+      sch.debugDump(sb);
+      sb.append(" ");
     }
-
+    sb.append(" ] }");
   }
 
   @Override
-  public boolean isPersisted() {
-    readWriteLock.readLock().lock();
-    try {
+  public synchronized boolean isPersisted() {
       return persisted;
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
   }
 
   @Override
-  public void persist() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (!persisted) {
-        persistEntities();
-        refresh();
-        service.refresh();
-        persisted = true;
-      } else {
-        saveIfPersisted();
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void persist() {
+    if (!persisted) {
+      persistEntities();
+      refresh();
+      service.refresh();
+      persisted = true;
+    } else {
+      saveIfPersisted();
     }
-
   }
 
   @Transactional
@@ -542,35 +424,23 @@ public class ServiceComponentImpl implem
 
   @Override
   @Transactional
-  public void refresh() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (isPersisted()) {
-        ServiceComponentDesiredStateEntityPK pk = new ServiceComponentDesiredStateEntityPK();
-        pk.setComponentName(getName());
-        pk.setClusterId(getClusterId());
-        pk.setServiceName(getServiceName());
-        // TODO: desiredStateEntity is assigned in unway, may be a bug
-        desiredStateEntity = serviceComponentDesiredStateDAO.findByPK(pk);
-        serviceComponentDesiredStateDAO.refresh(desiredStateEntity);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void refresh() {
+    if (isPersisted()) {
+      ServiceComponentDesiredStateEntityPK pk = new ServiceComponentDesiredStateEntityPK();
+      pk.setComponentName(getName());
+      pk.setClusterId(getClusterId());
+      pk.setServiceName(getServiceName());
+      // TODO: desiredStateEntity is assigned in unsynchronized way, may be a bug
+      desiredStateEntity = serviceComponentDesiredStateDAO.findByPK(pk);
+      serviceComponentDesiredStateDAO.refresh(desiredStateEntity);
     }
-
   }
 
   @Transactional
-  private void saveIfPersisted() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (isPersisted()) {
-        serviceComponentDesiredStateDAO.merge(desiredStateEntity);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+  private synchronized void saveIfPersisted() {
+    if (isPersisted()) {
+      serviceComponentDesiredStateDAO.merge(desiredStateEntity);
     }
-
   }
 
   @Override
@@ -579,125 +449,95 @@ public class ServiceComponentImpl implem
   }
 
   @Override
-  public boolean canBeRemoved() {
-    readWriteLock.readLock().lock();
-    try {
-      if (!getDesiredState().isRemovableState()) {
-        return false;
-      }
+  public synchronized boolean canBeRemoved() {
+    if (!getDesiredState().isRemovableState()) {
+      return false;
+    }
 
-      for (ServiceComponentHost sch : hostComponents.values()) {
-        if (!sch.canBeRemoved()) {
-          LOG.warn("Found non removable hostcomponent when trying to"
-              + " delete service component"
-              + ", clusterName=" + getClusterName()
-              + ", serviceName=" + getServiceName()
-              + ", componentName=" + getName()
-              + ", hostname=" + sch.getHostName());
-          return false;
-        }
+    for (ServiceComponentHost sch : hostComponents.values()) {
+      if (!sch.canBeRemoved()) {
+        LOG.warn("Found non removable hostcomponent when trying to"
+            + " delete service component"
+            + ", clusterName=" + getClusterName()
+            + ", serviceName=" + getServiceName()
+            + ", componentName=" + getName()
+            + ", hostname=" + sch.getHostName());
+        return false;
       }
-      return true;
-    } finally {
-      readWriteLock.readLock().unlock();
     }
-
+    return true;
   }
 
   @Override
   @Transactional
-  public void deleteAllServiceComponentHosts()
+  public synchronized void deleteAllServiceComponentHosts()
       throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      LOG.info("Deleting all servicecomponenthosts for component"
-          + ", clusterName=" + getClusterName()
-          + ", serviceName=" + getServiceName()
-          + ", componentName=" + getName());
-      for (ServiceComponentHost sch : hostComponents.values()) {
-        if (!sch.canBeRemoved()) {
-          throw new AmbariException("Found non removable hostcomponent "
-              + " when trying to delete"
-              + " all hostcomponents from servicecomponent"
-              + ", clusterName=" + getClusterName()
-              + ", serviceName=" + getServiceName()
-              + ", componentName=" + getName()
-              + ", hostname=" + sch.getHostName());
-        }
-      }
-
-      for (ServiceComponentHost serviceComponentHost : hostComponents.values()) {
-        serviceComponentHost.delete();
+    LOG.info("Deleting all servicecomponenthosts for component"
+        + ", clusterName=" + getClusterName()
+        + ", serviceName=" + getServiceName()
+        + ", componentName=" + getName());
+    for (ServiceComponentHost sch : hostComponents.values()) {
+      if (!sch.canBeRemoved()) {
+        throw new AmbariException("Found non removable hostcomponent "
+            + " when trying to delete"
+            + " all hostcomponents from servicecomponent"
+            + ", clusterName=" + getClusterName()
+            + ", serviceName=" + getServiceName()
+            + ", componentName=" + getName()
+            + ", hostname=" + sch.getHostName());
       }
+    }
 
-      hostComponents.clear();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    for (ServiceComponentHost serviceComponentHost : hostComponents.values()) {
+      serviceComponentHost.delete();
     }
 
+    hostComponents.clear();
   }
 
   @Override
-  public void deleteServiceComponentHosts(String hostname)
+  public synchronized void deleteServiceComponentHosts(String hostname)
       throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      ServiceComponentHost sch = getServiceComponentHost(hostname);
-      LOG.info("Deleting servicecomponenthost for cluster"
+    ServiceComponentHost sch = getServiceComponentHost(hostname);
+    LOG.info("Deleting servicecomponenthost for cluster"
+        + ", clusterName=" + getClusterName()
+        + ", serviceName=" + getServiceName()
+        + ", componentName=" + getName()
+        + ", hostname=" + sch.getHostName());
+    if (!sch.canBeRemoved()) {
+      throw new AmbariException("Could not delete hostcomponent from cluster"
           + ", clusterName=" + getClusterName()
           + ", serviceName=" + getServiceName()
           + ", componentName=" + getName()
           + ", hostname=" + sch.getHostName());
-      if (!sch.canBeRemoved()) {
-        throw new AmbariException("Could not delete hostcomponent from cluster"
-            + ", clusterName=" + getClusterName()
-            + ", serviceName=" + getServiceName()
-            + ", componentName=" + getName()
-            + ", hostname=" + sch.getHostName());
-      }
-      sch.delete();
-      hostComponents.remove(hostname);
-
-      // FIXME need a better approach of caching components by host
-      ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
-      clusterImpl.removeServiceComponentHost(sch);
-    } finally {
-      readWriteLock.writeLock().unlock();
     }
+    sch.delete();
+    hostComponents.remove(hostname);
 
+    // FIXME need a better approach of caching components by host
+    ClusterImpl clusterImpl = (ClusterImpl) service.getCluster();
+    clusterImpl.removeServiceComponentHost(sch);
   }
 
   @Override
-  public void deleteDesiredConfigs(Set<String> configTypes) {
-    readWriteLock.writeLock().lock();
-    try {
-      componentConfigMappingDAO.removeByType(configTypes);
-      for (String configType : configTypes) {
-        desiredConfigs.remove(configType);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void deleteDesiredConfigs(Set<String> configTypes) {
+    componentConfigMappingDAO.removeByType(configTypes);
+    for (String configType : configTypes) {
+      desiredConfigs.remove(configType);
     }
-
   }
 
   @Override
   @Transactional
-  public void delete() throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      deleteAllServiceComponentHosts();
-
-      if (persisted) {
-        removeEntities();
-        persisted = false;
-      }
+  public synchronized void delete() throws AmbariException {
+    deleteAllServiceComponentHosts();
 
-      desiredConfigs.clear();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (persisted) {
+      removeEntities();
+      persisted = false;
     }
 
+    desiredConfigs.clear();
   }
 
   @Transactional

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java?rev=1488039&r1=1488038&r2=1488039&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceImpl.java Thu May 30 22:14:29 2013
@@ -20,8 +20,6 @@ package org.apache.ambari.server.state;
 
 import java.util.*;
 import java.util.Map.Entry;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ServiceComponentNotFoundException;
@@ -41,7 +39,6 @@ import com.google.inject.persist.Transac
 
 
 public class ServiceImpl implements Service {
-  private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
 
   private ClusterServiceEntity serviceEntity;
   private ServiceDesiredStateEntity serviceDesiredStateEntity;
@@ -144,7 +141,7 @@ public class ServiceImpl implements Serv
 
   @Override
   public String getName() {
-    return serviceEntity.getServiceName();
+      return serviceEntity.getServiceName();
   }
 
   @Override
@@ -153,244 +150,172 @@ public class ServiceImpl implements Serv
   }
 
   @Override
-  public Map<String, ServiceComponent> getServiceComponents() {
-    readWriteLock.readLock().lock();
-    try {
-      return Collections.unmodifiableMap(components);
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized Map<String, ServiceComponent> getServiceComponents() {
+    return Collections.unmodifiableMap(components);
   }
 
   @Override
-  public void addServiceComponents(
+  public synchronized void addServiceComponents(
       Map<String, ServiceComponent> components) throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      for (ServiceComponent sc : components.values()) {
-        addServiceComponent(sc);
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+    for (ServiceComponent sc : components.values()) {
+      addServiceComponent(sc);
     }
-
   }
 
   @Override
-  public void addServiceComponent(ServiceComponent component)
+  public synchronized void addServiceComponent(ServiceComponent component)
       throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      // TODO validation
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Adding a ServiceComponent to Service"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", clusterId=" + cluster.getClusterId()
-            + ", serviceName=" + getName()
-            + ", serviceComponentName=" + component.getName());
-      }
-      if (components.containsKey(component.getName())) {
-        throw new AmbariException("Cannot add duplicate ServiceComponent"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", clusterId=" + cluster.getClusterId()
-            + ", serviceName=" + getName()
-            + ", serviceComponentName=" + component.getName());
-      }
-      this.components.put(component.getName(), component);
-    } finally {
-      readWriteLock.writeLock().unlock();
+    // TODO validation
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Adding a ServiceComponent to Service"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", serviceComponentName=" + component.getName());
     }
-
+    if (components.containsKey(component.getName())) {
+      throw new AmbariException("Cannot add duplicate ServiceComponent"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", serviceComponentName=" + component.getName());
+    }
+    this.components.put(component.getName(), component);
   }
 
   @Override
-  public ServiceComponent addServiceComponent(
+  public synchronized ServiceComponent addServiceComponent(
       String serviceComponentName) throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Adding a ServiceComponent to Service"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", clusterId=" + cluster.getClusterId()
-            + ", serviceName=" + getName()
-            + ", serviceComponentName=" + serviceComponentName);
-      }
-      if (components.containsKey(serviceComponentName)) {
-        throw new AmbariException("Cannot add duplicate ServiceComponent"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", clusterId=" + cluster.getClusterId()
-            + ", serviceName=" + getName()
-            + ", serviceComponentName=" + serviceComponentName);
-      }
-      ServiceComponent component = serviceComponentFactory.createNew(this, serviceComponentName);
-      this.components.put(component.getName(), component);
-      return component;
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Adding a ServiceComponent to Service"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", serviceComponentName=" + serviceComponentName);
     }
-
+    if (components.containsKey(serviceComponentName)) {
+      throw new AmbariException("Cannot add duplicate ServiceComponent"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", serviceComponentName=" + serviceComponentName);
+    }
+    ServiceComponent component = serviceComponentFactory.createNew(this, serviceComponentName);
+    this.components.put(component.getName(), component);
+    return component;
   }
 
   @Override
   public ServiceComponent getServiceComponent(String componentName)
       throws AmbariException {
-    readWriteLock.readLock().lock();
-    try {
-      if (!components.containsKey(componentName)) {
-        throw new ServiceComponentNotFoundException(cluster.getClusterName(),
-            getName(),
-            componentName);
-      }
-      return this.components.get(componentName);
-    } finally {
-      readWriteLock.readLock().unlock();
+    if (!components.containsKey(componentName)) {
+      throw new ServiceComponentNotFoundException(cluster.getClusterName(),
+          getName(),
+          componentName);
     }
-
+    return this.components.get(componentName);
   }
 
   @Override
-  public State getDesiredState() {
-    readWriteLock.readLock().lock();
-    try {
-      return this.serviceDesiredStateEntity.getDesiredState();
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized State getDesiredState() {
+    return this.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=" + this.getDesiredState()
-            + ", newDesiredState=" + state);
-      }
-      this.serviceDesiredStateEntity.setDesiredState(state);
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void setDesiredState(State state) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredState of Service"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", oldDesiredState=" + this.getDesiredState()
+          + ", newDesiredState=" + state);
     }
-
+    this.serviceDesiredStateEntity.setDesiredState(state);
+    saveIfPersisted();
   }
 
   @Override
-  public Map<String, Config> getDesiredConfigs() {
-    readWriteLock.readLock().lock();
-    try {
-      Map<String, Config> map = new HashMap<String, Config>();
-      for (Entry<String, String> entry : desiredConfigs.entrySet()) {
-        Config config = cluster.getConfig(entry.getKey(), entry.getValue());
-        if (null != config) {
-          map.put(entry.getKey(), config);
-        } else {
-          // FIXME this is an error - should throw a proper exception
-          throw new RuntimeException("Found an invalid config"
-              + ", clusterName=" + getCluster().getClusterName()
-              + ", serviceName=" + getName()
-              + ", configType=" + entry.getKey()
-              + ", configVersionTag=" + entry.getValue());
-        }
+  public synchronized Map<String, Config> getDesiredConfigs() {
+    Map<String, Config> map = new HashMap<String, Config>();
+    for (Entry<String, String> entry : desiredConfigs.entrySet()) {
+      Config config = cluster.getConfig(entry.getKey(), entry.getValue());
+      if (null != config) {
+        map.put(entry.getKey(), config);
+      } else {
+        // FIXME this is an error - should throw a proper exception
+        throw new RuntimeException("Found an invalid config"
+            + ", clusterName=" + getCluster().getClusterName()
+            + ", serviceName=" + getName()
+            + ", configType=" + entry.getKey()
+            + ", configVersionTag=" + entry.getValue());
       }
-      return Collections.unmodifiableMap(map);
-    } finally {
-      readWriteLock.readLock().unlock();
     }
-
+    return Collections.unmodifiableMap(map);
   }
 
   @Override
-  public void updateDesiredConfigs(Map<String, Config> configs) {
-
-    readWriteLock.writeLock().lock();
-    try {
-      for (Entry<String, Config> entry : configs.entrySet()) {
-        boolean contains = false;
+  public synchronized void updateDesiredConfigs(Map<String, Config> configs) {
 
-        for (ServiceConfigMappingEntity serviceConfigMappingEntity : serviceEntity.getServiceConfigMappings()) {
-          if (entry.getKey().equals(serviceConfigMappingEntity.getConfigType())) {
-            contains = true;
-            serviceConfigMappingEntity.setTimestamp(new Date().getTime());
-            serviceConfigMappingEntity.setVersionTag(entry.getValue().getVersionTag());
-          }
-        }
-
-        if (!contains) {
-          ServiceConfigMappingEntity newEntity = new ServiceConfigMappingEntity();
-          newEntity.setClusterId(serviceEntity.getClusterId());
-          newEntity.setServiceName(serviceEntity.getServiceName());
-          newEntity.setConfigType(entry.getKey());
-          newEntity.setVersionTag(entry.getValue().getVersionTag());
-          newEntity.setTimestamp(new Date().getTime());
-          newEntity.setServiceEntity(serviceEntity);
-          serviceEntity.getServiceConfigMappings().add(newEntity);
+    for (Entry<String,Config> entry : configs.entrySet()) {
+      boolean contains = false;
 
+      for (ServiceConfigMappingEntity serviceConfigMappingEntity : serviceEntity.getServiceConfigMappings()) {
+        if (entry.getKey().equals(serviceConfigMappingEntity.getConfigType())) {
+          contains = true;
+          serviceConfigMappingEntity.setTimestamp(new Date().getTime());
+          serviceConfigMappingEntity.setVersionTag(entry.getValue().getVersionTag());
         }
+      }
 
+      if (!contains) {
+        ServiceConfigMappingEntity newEntity = new ServiceConfigMappingEntity();
+        newEntity.setClusterId(serviceEntity.getClusterId());
+        newEntity.setServiceName(serviceEntity.getServiceName());
+        newEntity.setConfigType(entry.getKey());
+        newEntity.setVersionTag(entry.getValue().getVersionTag());
+        newEntity.setTimestamp(new Date().getTime());
+        newEntity.setServiceEntity(serviceEntity);
+        serviceEntity.getServiceConfigMappings().add(newEntity);
 
-        this.desiredConfigs.put(entry.getKey(), entry.getValue().getVersionTag());
       }
 
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+
+      this.desiredConfigs.put(entry.getKey(), entry.getValue().getVersionTag());
     }
 
+    saveIfPersisted();
 
   }
 
   @Override
-  public StackId getDesiredStackVersion() {
-    readWriteLock.readLock().lock();
-    try {
-      return gson.fromJson(serviceDesiredStateEntity.getDesiredStackVersion(), StackId.class);
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized StackId getDesiredStackVersion() {
+    return gson.fromJson(serviceDesiredStateEntity.getDesiredStackVersion(), StackId.class);
   }
 
   @Override
-  public void setDesiredStackVersion(StackId stackVersion) {
-    readWriteLock.writeLock().lock();
-    try {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Setting DesiredStackVersion of Service"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", clusterId=" + cluster.getClusterId()
-            + ", serviceName=" + getName()
-            + ", oldDesiredStackVersion=" + getDesiredStackVersion()
-            + ", newDesiredStackVersion=" + stackVersion);
-      }
-      serviceDesiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
-      saveIfPersisted();
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void setDesiredStackVersion(StackId stackVersion) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("Setting DesiredStackVersion of Service"
+          + ", clusterName=" + cluster.getClusterName()
+          + ", clusterId=" + cluster.getClusterId()
+          + ", serviceName=" + getName()
+          + ", oldDesiredStackVersion=" + getDesiredStackVersion()
+          + ", newDesiredStackVersion=" + stackVersion);
     }
-
+    serviceDesiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
+    saveIfPersisted();
   }
 
   @Override
-  public ServiceResponse convertToResponse() {
-    readWriteLock.readLock().lock();
-    try {
-      ServiceResponse r = new ServiceResponse(cluster.getClusterId(),
-          cluster.getClusterName(),
-          getName(),
-          desiredConfigs,
-          getDesiredStackVersion().getStackId(),
-          getDesiredState().toString());
-      return r;
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
+  public synchronized ServiceResponse convertToResponse() {
+    ServiceResponse r = new ServiceResponse(cluster.getClusterId(),
+        cluster.getClusterName(),
+        getName(),
+        desiredConfigs,
+        getDesiredStackVersion().getStackId(),
+        getDesiredState().toString());
+    return r;
   }
 
   @Override
@@ -399,72 +324,54 @@ public class ServiceImpl implements Serv
   }
 
   @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()
-          + ", configs=[");
-      boolean first = true;
-      if (desiredConfigs != null) {
-        for (Entry<String, String> entry : desiredConfigs.entrySet()) {
-          if (!first) {
-            sb.append(" , ");
-          }
-          first = false;
-          sb.append("{ Config type=" + entry.getKey()
-              + ", versionTag=" + entry.getValue() + "}");
-        }
-      }
-      sb.append("], components=[ ");
-
-      first = true;
-      for (ServiceComponent sc : components.values()) {
+  public synchronized void debugDump(StringBuilder sb) {
+    sb.append("Service={ serviceName=" + getName()
+        + ", clusterName=" + cluster.getClusterName()
+        + ", clusterId=" + cluster.getClusterId()
+        + ", desiredStackVersion=" + getDesiredStackVersion()
+        + ", desiredState=" + getDesiredState().toString()
+        + ", configs=[");
+    boolean first = true;
+    if (desiredConfigs != null) {
+      for (Entry<String, String> entry : desiredConfigs.entrySet()) {
         if (!first) {
           sb.append(" , ");
         }
         first = false;
-        sb.append("\n      ");
-        sc.debugDump(sb);
-        sb.append(" ");
+        sb.append("{ Config type=" + entry.getKey()
+            + ", versionTag=" + entry.getValue() + "}");
       }
-      sb.append(" ] }");
-    } finally {
-      readWriteLock.readLock().unlock();
     }
+    sb.append("], components=[ ");
 
+    first = true;
+    for(ServiceComponent sc : components.values()) {
+      if (!first) {
+        sb.append(" , ");
+      }
+      first = false;
+      sb.append("\n      ");
+      sc.debugDump(sb);
+      sb.append(" ");
+    }
+    sb.append(" ] }");
   }
 
   @Override
-  public boolean isPersisted() {
-    readWriteLock.readLock().lock();
-    try {
+  public synchronized boolean isPersisted() {
       return persisted;
-    } finally {
-      readWriteLock.readLock().unlock();
-    }
-
   }
 
   @Override
-  public void persist() {
-    readWriteLock.writeLock().lock();
-    try {
-      if (!persisted) {
-        persistEntities();
-        refresh();
-        cluster.refresh();
-        persisted = true;
-      } else {
-        saveIfPersisted();
-      }
-    } finally {
-      readWriteLock.writeLock().unlock();
+  public synchronized void persist() {
+    if (!persisted) {
+      persistEntities();
+      refresh();
+      cluster.refresh();
+      persisted = true;
+    } else {
+      saveIfPersisted();
     }
-
   }
 
   @Transactional
@@ -491,102 +398,78 @@ public class ServiceImpl implements Serv
 
   @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();
+  public synchronized void refresh() {
+    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);
     }
-
   }
 
   @Override
-  public boolean canBeRemoved() {
-    readWriteLock.readLock().lock();
-    try {
-      if (!getDesiredState().isRemovableState()) {
-        return false;
-      }
+  public synchronized boolean canBeRemoved() {
+    if (!getDesiredState().isRemovableState()) {
+      return false;
+    }
 
-      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;
-        }
+    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;
   }
 
   @Override
   @Transactional
-  public void deleteAllComponents() throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      LOG.info("Deleting all components for service"
-          + ", clusterName=" + cluster.getClusterName()
-          + ", serviceName=" + getName());
-      // FIXME check dependencies from meta layer
-      for (ServiceComponent component : components.values()) {
-        if (!component.canBeRemoved()) {
-          throw new AmbariException("Found non removable component when trying to"
-              + " delete all components from service"
-              + ", clusterName=" + cluster.getClusterName()
-              + ", serviceName=" + getName()
-              + ", componentName=" + component.getName());
-        }
-      }
-
-      for (ServiceComponent serviceComponent : components.values()) {
-        serviceComponent.delete();
+  public synchronized void deleteAllComponents() throws AmbariException {
+    LOG.info("Deleting all components for service"
+        + ", clusterName=" + cluster.getClusterName()
+        + ", serviceName=" + getName());
+    // FIXME check dependencies from meta layer
+    for (ServiceComponent component : components.values()) {
+      if (!component.canBeRemoved()) {
+        throw new AmbariException("Found non removable component when trying to"
+            + " delete all components from service"
+            + ", clusterName=" + cluster.getClusterName()
+            + ", serviceName=" + getName()
+            + ", componentName=" + component.getName());
       }
+    }
 
-      components.clear();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    for (ServiceComponent serviceComponent : components.values()) {
+      serviceComponent.delete();
     }
 
+    components.clear();
   }
 
   @Override
-  public void deleteServiceComponent(String componentName)
+  public synchronized void deleteServiceComponent(String componentName)
       throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      ServiceComponent component = getServiceComponent(componentName);
-      LOG.info("Deleting servicecomponent for cluster"
+    ServiceComponent component = getServiceComponent(componentName);
+    LOG.info("Deleting servicecomponent for cluster"
+        + ", clusterName=" + cluster.getClusterName()
+        + ", serviceName=" + getName()
+        + ", componentName=" + componentName);
+    // FIXME check dependencies from meta layer
+    if (!component.canBeRemoved()) {
+      throw new AmbariException("Could not delete component from cluster"
           + ", clusterName=" + cluster.getClusterName()
           + ", serviceName=" + getName()
           + ", componentName=" + componentName);
-      // FIXME check dependencies from meta layer
-      if (!component.canBeRemoved()) {
-        throw new AmbariException("Could not delete component from cluster"
-            + ", clusterName=" + cluster.getClusterName()
-            + ", serviceName=" + getName()
-            + ", componentName=" + componentName);
-      }
-
-      component.delete();
-      components.remove(componentName);
-    } finally {
-      readWriteLock.writeLock().unlock();
     }
 
+    component.delete();
+    components.remove(componentName);
   }
 
   @Override
@@ -596,21 +479,15 @@ public class ServiceImpl implements Serv
 
   @Override
   @Transactional
-  public void delete() throws AmbariException {
-    readWriteLock.writeLock().lock();
-    try {
-      deleteAllComponents();
-
-      if (persisted) {
-        removeEntities();
-        persisted = false;
-      }
+  public synchronized void delete() throws AmbariException {
+    deleteAllComponents();
 
-      desiredConfigs.clear();
-    } finally {
-      readWriteLock.writeLock().unlock();
+    if (persisted) {
+      removeEntities();
+      persisted = false;
     }
 
+    desiredConfigs.clear();
   }
 
   @Transactional

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java?rev=1488039&r1=1488038&r2=1488039&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java Thu May 30 22:14:29 2013
@@ -355,9 +355,6 @@ public class HostImpl implements Host {
     }
   }
 
-  /**
-   * @param hostInfo
-   */
   @Override
   public void importHostInfo(HostInfo hostInfo) {
     try {
@@ -460,26 +457,17 @@ public class HostImpl implements Host {
     }
   }
 
+  /**
+   * @param hostInfo
+   */
   @Override
   public void setLastAgentEnv(AgentEnv env) {
-    writeLock.lock();
-    try {
-      lastAgentEnv = env;
-    } finally {
-      writeLock.unlock();
-    }
-
+    lastAgentEnv = env;
   }
   
   @Override
   public AgentEnv getLastAgentEnv() {
-    readLock.lock();
-    try {
-      return lastAgentEnv;
-    } finally {
-      readLock.unlock();
-    }
-
+    return lastAgentEnv;
   }
 
   @Override

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java?rev=1488039&r1=1488038&r2=1488039&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java Thu May 30 22:14:29 2013
@@ -64,9 +64,8 @@ public class ServiceComponentHostImpl im
 
   // FIXME need more debug logs
 
-  private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
-  private final Lock readLock = readWriteLock.readLock();
-  private final Lock writeLock = readWriteLock.writeLock();
+  private final Lock readLock;
+  private final Lock writeLock;
 
   private final ServiceComponent serviceComponent;
   private final Host host;
@@ -601,6 +600,9 @@ public class ServiceComponentHostImpl im
       this.stateMachine = daemonStateMachineFactory.make(this);
     }
 
+    ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    this.readLock = rwLock.readLock();
+    this.writeLock = rwLock.writeLock();
     this.serviceComponent = serviceComponent;
 
     stateEntity = new HostComponentStateEntity();
@@ -639,6 +641,9 @@ public class ServiceComponentHostImpl im
                                   @Assisted HostComponentDesiredStateEntity desiredStateEntity,
                                   Injector injector) {
     injector.injectMembers(this);
+    ReadWriteLock rwLock = new ReentrantReadWriteLock();
+    this.readLock = rwLock.readLock();
+    this.writeLock = rwLock.writeLock();
     this.serviceComponent = serviceComponent;
 
 
@@ -673,8 +678,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public State getState() {
-    readLock.lock();
     try {
+      readLock.lock();
       return stateMachine.getCurrentState();
     }
     finally {
@@ -684,8 +689,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void setState(State state) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       stateMachine.setCurrentState(state);
       stateEntity.setCurrentState(state);
       saveIfPersisted();
@@ -741,32 +746,20 @@ public class ServiceComponentHostImpl im
 
   @Override
   public String getServiceComponentName() {
-    readLock.lock();
-    try {
-      return serviceComponent.getName();
-    } finally {
-      readLock.unlock();
-    }
-
+    return serviceComponent.getName();
   }
 
   @Override
   public String getHostName() {
-    readLock.lock();
-    try {
-      return host.getHostName();
-    } finally {
-      readLock.unlock();
-    }
-
+    return host.getHostName();
   }
 
   /**
    * @return the lastOpStartTime
    */
   public long getLastOpStartTime() {
-    readLock.lock();
     try {
+      readLock.lock();
       return lastOpStartTime;
     }
     finally {
@@ -778,8 +771,8 @@ public class ServiceComponentHostImpl im
    * @param lastOpStartTime the lastOpStartTime to set
    */
   public void setLastOpStartTime(long lastOpStartTime) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       this.lastOpStartTime = lastOpStartTime;
     }
     finally {
@@ -791,8 +784,8 @@ public class ServiceComponentHostImpl im
    * @return the lastOpEndTime
    */
   public long getLastOpEndTime() {
-    readLock.lock();
     try {
+      readLock.lock();
       return lastOpEndTime;
     }
     finally {
@@ -804,8 +797,8 @@ public class ServiceComponentHostImpl im
    * @param lastOpEndTime the lastOpEndTime to set
    */
   public void setLastOpEndTime(long lastOpEndTime) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       this.lastOpEndTime = lastOpEndTime;
     }
     finally {
@@ -817,8 +810,8 @@ public class ServiceComponentHostImpl im
    * @return the lastOpLastUpdateTime
    */
   public long getLastOpLastUpdateTime() {
-    readLock.lock();
     try {
+      readLock.lock();
       return lastOpLastUpdateTime;
     }
     finally {
@@ -830,8 +823,8 @@ public class ServiceComponentHostImpl im
    * @param lastOpLastUpdateTime the lastOpLastUpdateTime to set
    */
   public void setLastOpLastUpdateTime(long lastOpLastUpdateTime) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       this.lastOpLastUpdateTime = lastOpLastUpdateTime;
     }
     finally {
@@ -841,29 +834,17 @@ public class ServiceComponentHostImpl im
 
   @Override
   public long getClusterId() {
-    readLock.lock();
-    try {
-      return serviceComponent.getClusterId();
-    } finally {
-      readLock.unlock();
-    }
-
+    return serviceComponent.getClusterId();
   }
 
   @Override
   public String getServiceName() {
-    readLock.lock();
-    try {
-      return serviceComponent.getServiceName();
-    } finally {
-      readLock.unlock();
-    }
-
+    return serviceComponent.getServiceName();
   }
 
   Map<String, String> getConfigVersions() {
-    readLock.lock();
     try {
+      readLock.lock();
       if (this.configs != null) {
         return Collections.unmodifiableMap(configs);
       } else {
@@ -878,8 +859,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public Map<String, Config> getConfigs() throws AmbariException {
-    readLock.lock();
     try {
+      readLock.lock();
       Map<String, Config> map = new HashMap<String, Config>();
       Cluster cluster = clusters.getClusterById(getClusterId());
       for (Entry<String, String> entry : configs.entrySet()) {
@@ -898,8 +879,8 @@ public class ServiceComponentHostImpl im
 
   @Transactional
   void setConfigs(Map<String, String> configs) {
-    writeLock.lock();
     try {
+      writeLock.lock();
 
       Set<String> deletedTypes = new HashSet<String>();
       for (String type : this.configs.keySet()) {
@@ -990,8 +971,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public StackId getStackVersion() {
-    readLock.lock();
     try {
+      readLock.lock();
       return gson.fromJson(stateEntity.getCurrentStackVersion(), StackId.class);
     }
     finally {
@@ -1001,8 +982,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void setStackVersion(StackId stackVersion) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       stateEntity.setCurrentStackVersion(gson.toJson(stackVersion));
       saveIfPersisted();
     }
@@ -1014,8 +995,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public State getDesiredState() {
-    readLock.lock();
     try {
+      readLock.lock();
       return desiredStateEntity.getDesiredState();
     }
     finally {
@@ -1025,8 +1006,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void setDesiredState(State state) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       desiredStateEntity.setDesiredState(state);
       saveIfPersisted();
     }
@@ -1037,8 +1018,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public Map<String, String> getDesiredConfigVersionsRecursive() {
-    readLock.lock();
     try {
+      readLock.lock();
       Map<String, String> fullDesiredConfigVersions =
           new HashMap<String, String>();
       Map<String, Config> desiredConfs = getDesiredConfigs();
@@ -1056,8 +1037,8 @@ public class ServiceComponentHostImpl im
   @Override
   public Map<String, Config> getDesiredConfigs() {
     Map<String, Config> map = new HashMap<String, Config>();
-    readLock.lock();
     try {
+      readLock.lock();
       for (Entry<String, String> entry : desiredConfigs.entrySet()) {
         Config config = clusters.getClusterById(getClusterId()).getConfig(
             entry.getKey(), entry.getValue());
@@ -1086,8 +1067,8 @@ public class ServiceComponentHostImpl im
   @Override
   @Transactional
   public void updateDesiredConfigs(Map<String, Config> configs) {
-    writeLock.lock();
     try {
+      writeLock.lock();
 
       for (Entry<String,Config> entry : configs.entrySet()) {
 
@@ -1128,8 +1109,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public StackId getDesiredStackVersion() {
-    readLock.lock();
     try {
+      readLock.lock();
       return gson.fromJson(desiredStateEntity.getDesiredStackVersion(), StackId.class);
     }
     finally {
@@ -1139,8 +1120,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void setDesiredStackVersion(StackId stackVersion) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       desiredStateEntity.setDesiredStackVersion(gson.toJson(stackVersion));
       saveIfPersisted();
     }
@@ -1151,8 +1132,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public ServiceComponentHostResponse convertToResponse() {
-    readLock.lock();
     try {
+      readLock.lock();
       ServiceComponentHostResponse r = new ServiceComponentHostResponse(
           serviceComponent.getClusterName(),
           serviceComponent.getServiceName(),
@@ -1176,19 +1157,13 @@ public class ServiceComponentHostImpl im
 
   @Override
   public String getClusterName() {
-    readLock.lock();
-    try {
-      return serviceComponent.getClusterName();
-    } finally {
-      readLock.unlock();
-    }
-
+    return serviceComponent.getClusterName();
   }
 
   @Override
   public void debugDump(StringBuilder sb) {
-    readLock.lock();
     try {
+      readLock.lock();
       sb.append("ServiceComponentHost={ hostname=" + getHostName()
           + ", serviceComponentName=" + serviceComponent.getName()
           + ", clusterName=" + serviceComponent.getClusterName()
@@ -1206,8 +1181,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public boolean isPersisted() {
-    readLock.lock();
     try {
+      readLock.lock();
       return persisted;
     } finally {
       readLock.unlock();
@@ -1216,8 +1191,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void persist() {
-    writeLock.lock();
     try {
+      writeLock.lock();
       if (!persisted) {
         persistEntities();
         refresh();
@@ -1260,29 +1235,23 @@ public class ServiceComponentHostImpl im
 
   @Override
   @Transactional
-  public void refresh() {
-    writeLock.lock();
-    try {
-      if (isPersisted()) {
-        HostComponentStateEntityPK pk = new HostComponentStateEntityPK();
-        HostComponentDesiredStateEntityPK dpk = new HostComponentDesiredStateEntityPK();
-        pk.setClusterId(getClusterId());
-        pk.setComponentName(getServiceComponentName());
-        pk.setServiceName(getServiceName());
-        pk.setHostName(getHostName());
-        dpk.setClusterId(getClusterId());
-        dpk.setComponentName(getServiceComponentName());
-        dpk.setServiceName(getServiceName());
-        dpk.setHostName(getHostName());
-        stateEntity = hostComponentStateDAO.findByPK(pk);
-        desiredStateEntity = hostComponentDesiredStateDAO.findByPK(dpk);
-        hostComponentStateDAO.refresh(stateEntity);
-        hostComponentDesiredStateDAO.refresh(desiredStateEntity);
-      }
-    } finally {
-      writeLock.unlock();
+  public synchronized void refresh() {
+    if (isPersisted()) {
+      HostComponentStateEntityPK pk = new HostComponentStateEntityPK();
+      HostComponentDesiredStateEntityPK dpk = new HostComponentDesiredStateEntityPK();
+      pk.setClusterId(getClusterId());
+      pk.setComponentName(getServiceComponentName());
+      pk.setServiceName(getServiceName());
+      pk.setHostName(getHostName());
+      dpk.setClusterId(getClusterId());
+      dpk.setComponentName(getServiceComponentName());
+      dpk.setServiceName(getServiceName());
+      dpk.setHostName(getHostName());
+      stateEntity = hostComponentStateDAO.findByPK(pk);
+      desiredStateEntity = hostComponentDesiredStateDAO.findByPK(dpk);
+      hostComponentStateDAO.refresh(stateEntity);
+      hostComponentDesiredStateDAO.refresh(desiredStateEntity);
     }
-
   }
 
   @Transactional
@@ -1294,9 +1263,9 @@ public class ServiceComponentHostImpl im
   }
 
   @Override
-  public boolean canBeRemoved() {
-    readLock.lock();
+  public synchronized boolean canBeRemoved() {
     try {
+      readLock.lock();
 
       return (getDesiredState().isRemovableState() &&
               getState().isRemovableState());
@@ -1308,8 +1277,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void deleteDesiredConfigs(Set<String> configTypes) {
-    writeLock.lock();
     try {
+      writeLock.lock();
       hostComponentDesiredConfigMappingDAO.removeByType(configTypes);
       for (String configType : configTypes) {
         desiredConfigs.remove(configType);
@@ -1321,8 +1290,8 @@ public class ServiceComponentHostImpl im
 
   @Override
   public void delete() {
-    writeLock.lock();
     try {
+      writeLock.lock();
       if (persisted) {
         removeEntities();
         persisted = false;
@@ -1355,53 +1324,35 @@ public class ServiceComponentHostImpl im
   
   @Override
   public void updateActualConfigs(Map<String, Map<String, String>> configTags) {
-    writeLock.lock();
-    try {
-      actualConfigs = new HashMap<String, DesiredConfig>();
-
-      String hostName = getHostName();
-
-      for (Entry<String, Map<String, String>> entry : configTags.entrySet()) {
-        String type = entry.getKey();
-        Map<String, String> values = entry.getValue();
-
-        String tag = values.get("tag");
-        String hostTag = values.get("host_override_tag");
-
-        DesiredConfig dc = new DesiredConfig();
-        dc.setVersion(tag);
-        actualConfigs.put(type, dc);
-        if (null != hostTag && null != hostName) {
-          List<HostOverride> list = new ArrayList<HostOverride>();
-          list.add(new HostOverride(hostName, hostTag));
-          dc.setHostOverrides(list);
-        }
+    actualConfigs = new HashMap<String, DesiredConfig>();
+    
+    String hostName = getHostName();
+    
+    for (Entry<String, Map<String,String>> entry : configTags.entrySet()) {
+      String type = entry.getKey();
+      Map<String, String> values = entry.getValue();
+      
+      String tag = values.get("tag");
+      String hostTag = values.get("host_override_tag");
+      
+      DesiredConfig dc = new DesiredConfig();
+      dc.setVersion(tag);
+      actualConfigs.put(type, dc);
+      if (null != hostTag && null != hostName) {
+        List<HostOverride> list = new ArrayList<HostOverride>();
+        list.add (new HostOverride(hostName, hostTag));
+        dc.setHostOverrides(list);
       }
-    } finally {
-      writeLock.unlock();
     }
-
   }
   
   @Override
   public Map<String, DesiredConfig> getActualConfigs() {
-    readLock.lock();
-    try {
-      return actualConfigs;
-    } finally {
-      readLock.unlock();
-    }
-
+    return actualConfigs;
   }
 
   @Override
   public HostState getHostState() {
-    readLock.lock();
-    try {
-      return host.getState();
-    } finally {
-      readLock.unlock();
-    }
-
+    return host.getState();
   }
 }

Modified: incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql?rev=1488039&r1=1488038&r2=1488039&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql (original)
+++ incubator/ambari/branches/branch-1.2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql Thu May 30 22:14:29 2013
@@ -177,7 +177,7 @@ insert into ambari.user_roles(role_name,
 select 'admin',1;
 
 insert into ambari.metainfo(metainfo_key, metainfo_value)
-select 'version','${ambariVersion}';
+select 'version','1.3.0';
 
 COMMIT;