You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ke...@apache.org on 2013/02/01 20:38:11 UTC

[47/50] [abbrv] Sync master to javelin one more time

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/user/AccountManagerImpl.java
index 5512d3f,c5a8c75..4fc849e
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@@ -34,9 -34,9 +34,10 @@@ import javax.crypto.Mac
  import javax.crypto.SecretKey;
  import javax.crypto.spec.SecretKeySpec;
  import javax.ejb.Local;
 +import javax.inject.Inject;
  import javax.naming.ConfigurationException;
  
+ import com.cloud.event.ActionEventUtils;
  import org.apache.cloudstack.acl.ControlledEntity;
  import org.apache.cloudstack.acl.RoleType;
  import org.apache.cloudstack.acl.SecurityChecker;
@@@ -52,6 -48,13 +53,10 @@@ import org.springframework.stereotype.C
  import com.cloud.api.ApiDBUtils;
  import com.cloud.api.query.dao.UserAccountJoinDao;
  import com.cloud.api.query.vo.ControlledViewEntity;
+ 
+ 
 -import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
 -import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+ import org.apache.cloudstack.region.RegionManager;
+ 
  import com.cloud.configuration.Config;
  import com.cloud.configuration.ConfigurationManager;
  import com.cloud.configuration.ResourceLimit;
@@@ -799,29 -812,55 +805,55 @@@ public class AccountManagerImpl extend
              }
          }
  
+         if(regionId == null){
 -            Transaction txn = Transaction.currentTxn();
 -            txn.start();
 +        Transaction txn = Transaction.currentTxn();
 +        txn.start();
  
 -        	// create account
 +        // create account
-         Account account = createAccount(accountName, accountType, domainId, networkDomain, details);
+         	AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, UUID.randomUUID().toString(), _regionMgr.getId());
 -        	long accountId = account.getId();
 +        long accountId = account.getId();
  
 -        	// create the first user for the account
 -        	UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone);
 +        // create the first user for the account
 +        UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone);
  
 -        	if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
 -        		// set registration token
 -        		byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes();
 -        		String registrationToken = UUID.nameUUIDFromBytes(bytes).toString();
 -        		user.setRegistrationToken(registrationToken);
 -        	}
 +        if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
 +            // set registration token
 +            byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes();
 +            String registrationToken = UUID.nameUUIDFromBytes(bytes).toString();
 +            user.setRegistrationToken(registrationToken);
 +        }
+         	txn.commit();
+         	//Propagate Add account to other Regions
+         	_regionMgr.propagateAddAccount(userName, password, firstName, lastName, email, timezone, accountName, accountType, domainId, 
+         			networkDomain, details, account.getUuid(), user.getUuid());
+         	//check success
+             return _userAccountDao.findById(user.getId());
+         } else {
+         	// Account is propagated from another Region
+ 
+         	Transaction txn = Transaction.currentTxn();
+             txn.start();
+ 
+             // create account
+             AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, accountUUID, regionId);
+             long accountId = account.getId();
  
+             // create the first user for the account
+             UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone, userUUID, regionId);
+ 
+             if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
+                 // set registration token
+                 byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes();
+                 String registrationToken = UUID.nameUUIDFromBytes(bytes).toString();
+                 user.setRegistrationToken(registrationToken);
+             }
 -            txn.commit();
 -            return _userAccountDao.findById(user.getId());
 -        }
 +        txn.commit();
 +        return _userAccountDao.findById(user.getId());
 +    }
+     }
  
      @Override
-     public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId) {
+     public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID, Integer regionId) {
  
          // default domain to ROOT if not specified
          if (domainId == null) {
@@@ -1713,20 -1755,31 +1748,31 @@@
          if (s_logger.isDebugEnabled()) {
              s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone);
          }
 -        
 +
+         UserVO user = _userDao.persist(new UserVO(accountId, userName, password, firstName, lastName, email, timezone, UUID.randomUUID().toString(), _regionMgr.getId()));
+ 
+         return user;
+     }
+ 
+     //ToDo Add events??
+     public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String uuid, int regionId) {
+         if (s_logger.isDebugEnabled()) {
+             s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone);
+         }
+ 
          String encodedPassword = null;
 -        for (Enumeration<UserAuthenticator> en = _userAuthenticators.enumeration(); en.hasMoreElements();) {
 -            UserAuthenticator authenticator = en.nextElement();
 +        for (Iterator<UserAuthenticator> en = _userAuthenticators.iterator(); en.hasNext();) {
 +            UserAuthenticator authenticator = en.next();
              encodedPassword = authenticator.encode(password);
              if (encodedPassword != null) {
                  break;
              }
          }
          if (encodedPassword == null) {
 -        	throw new CloudRuntimeException("Failed to encode password");
 +            throw new CloudRuntimeException("Failed to encode password");
          }
 -        
 +
-         UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone));
+         UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, uuid, regionId));
  
          return user;
      }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/user/DomainManagerImpl.java
index e80da9f,6791c73..8ad9f5b
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@@ -27,8 -26,9 +27,10 @@@ import javax.naming.ConfigurationExcept
  
  import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
  import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
+ import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
+ import org.apache.cloudstack.region.RegionManager;
  import org.apache.log4j.Logger;
 +import org.springframework.stereotype.Component;
  
  import com.cloud.configuration.ResourceLimit;
  import com.cloud.configuration.dao.ResourceCountDao;
@@@ -81,7 -81,9 +83,9 @@@ public class DomainManagerImpl extends 
      private ProjectDao _projectDao;
      @Inject
      private ProjectManager _projectMgr;
+     @Inject
+     private RegionManager _regionMgr;
 -    
 +
      @Override
      public Domain getDomain(long domainId) {
          return _domainDao.findById(domainId);
@@@ -157,15 -181,28 +161,28 @@@
              throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
          }
  
+         if(regionId == null){
 -        	Transaction txn = Transaction.currentTxn();
 -        	txn.start();
 +        Transaction txn = Transaction.currentTxn();
 +        txn.start();
  
-         DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain));
+         	DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, _regionMgr.getId()));
 -        	_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
 -        	txn.commit();
 +        _resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
- 
 +        txn.commit();
+         	//Propagate domain creation to peer Regions
+         	_regionMgr.propagateAddDomain(name, parentId, networkDomain, domain.getUuid());        	
+         	return domain;
+         } else {
+         	Transaction txn = Transaction.currentTxn();
+         	txn.start();
+ 
+         	DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, domainUUID, regionId));
+         	_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
  
+         	txn.commit();
 -        	return domain;
 +        return domain;
+         	
+         }
+         
      }
  
      @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/user/dao/AccountDaoImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/user/dao/UserAccountDaoImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/user/dao/UserDaoImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmManagerImpl.java
index ad358eb,a53e132..ee06a97
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@@ -113,20 -54,9 +113,20 @@@ import com.cloud.domain.DomainVO
  import com.cloud.domain.dao.DomainDao;
  import com.cloud.event.ActionEvent;
  import com.cloud.event.EventTypes;
- import com.cloud.event.UsageEventVO;
+ import com.cloud.event.UsageEventUtils;
  import com.cloud.event.dao.UsageEventDao;
 -import com.cloud.exception.*;
 +import com.cloud.exception.AgentUnavailableException;
 +import com.cloud.exception.CloudException;
 +import com.cloud.exception.ConcurrentOperationException;
 +import com.cloud.exception.InsufficientCapacityException;
 +import com.cloud.exception.InvalidParameterValueException;
 +import com.cloud.exception.ManagementServerException;
 +import com.cloud.exception.OperationTimedoutException;
 +import com.cloud.exception.PermissionDeniedException;
 +import com.cloud.exception.ResourceAllocationException;
 +import com.cloud.exception.ResourceUnavailableException;
 +import com.cloud.exception.StorageUnavailableException;
 +import com.cloud.exception.VirtualMachineMigrationException;
  import com.cloud.ha.HighAvailabilityManager;
  import com.cloud.host.Host;
  import com.cloud.host.HostVO;
@@@ -388,8 -279,8 +386,10 @@@ public class UserVmManagerImpl extends 
      PhysicalNetworkDao _physicalNetworkDao;
      @Inject
      VpcManager _vpcMgr;
 +    @Inject 
 +    protected GuestOSCategoryDao _guestOSCategoryDao;
+     @Inject
+     UsageEventDao _usageEventDao;
  
      protected ScheduledExecutorService _executor = null;
      protected int _expungeInterval;
@@@ -1978,16 -1636,13 +1975,14 @@@
              }
  
              volume = _volsDao.findById(snapshot.getVolumeId());
 -            VolumeVO snapshotVolume = _volsDao.findByIdIncludingRemoved(snapshot.getVolumeId());
 +            VolumeVO snapshotVolume = _volsDao
 +                    .findByIdIncludingRemoved(snapshot.getVolumeId());
  
 -            //check permissions
 +            // check permissions
              _accountMgr.checkAccess(caller, null, true, snapshot);
  
-             if (snapshot.getStatus() != Snapshot.Status.BackedUp) {
-                 throw new InvalidParameterValueException("Snapshot id="
-                         + snapshotId + " is not in " + Snapshot.Status.BackedUp
-                         + " state yet and can't be used for template creation");
+             if (snapshot.getState() != Snapshot.State.BackedUp) {
+                 throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.State.BackedUp + " state yet and can't be used for template creation");
              }
  
              /*
@@@ -3396,15 -2845,11 +3387,12 @@@
          }
          UserContext.current().setEventDetails("Vm Id: " + vm.getId());
  
-         txn = Transaction.currentTxn();
-         txn.start();
-         UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE,
-                 accountId, zone.getId(), vm.getId(), vm.getHostName(),
-                 offering.getId(), template.getId(), hypervisorType.toString());
-         _usageEventDao.persist(usageEvent);
+         UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, accountId, zone.getId(), vm.getId(),
+                 vm.getHostName(), offering.getId(), template.getId(), hypervisorType.toString(),
+                 VirtualMachine.class.getName(), vm.getUuid());
  
 -        _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm);
 +        _resourceLimitMgr.incrementResourceCount(accountId,
 +                ResourceType.user_vm);
          txn.commit();
          // Assign instance to the group
          try {
@@@ -3613,12 -3030,9 +3601,9 @@@
          for (NicVO nic : nics) {
              NetworkVO network = _networkDao.findById(nic.getNetworkId());
              long isDefault = (nic.isDefaultNic()) ? 1 : 0;
-             UsageEventVO usageEvent = new UsageEventVO(
-                     EventTypes.EVENT_NETWORK_OFFERING_ASSIGN,
-                     vm.getAccountId(), vm.getDataCenterId(),
-                     vm.getId(), vm.getHostName(),
-                     network.getNetworkOfferingId(), null, isDefault);
-             _usageEventDao.persist(usageEvent);
+             UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, vm.getAccountId(),
 -                    vm.getDataCenterIdToDeployIn(), vm.getId(), vm.getHostName(), network.getNetworkOfferingId(),
++                    vm.getDataCenterId(), vm.getId(), vm.getHostName(), network.getNetworkOfferingId(),
+                     null, isDefault, VirtualMachine.class.getName(), vm.getUuid());
              if (network.getTrafficType() == TrafficType.Guest) {
                  originalIp = nic.getIp4Address();
                  guestNic = nic;
@@@ -4466,14 -3746,12 +4449,13 @@@
  
          Transaction txn = Transaction.currentTxn();
          txn.start();
-         // generate destroy vm event for usage
-         _usageEventDao.persist(new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm
-                 .getAccountId(), vm.getDataCenterId(), vm.getId(), vm
-                 .getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
-                 vm.getHypervisorType().toString()));
+         //generate destroy vm event for usage
 -        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(),
++        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
+                 vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(),
+                 VirtualMachine.class.getName(), vm.getUuid());
          // update resource counts
 -        _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(), ResourceType.user_vm);
 +        _resourceLimitMgr.decrementResourceCount(oldAccount.getAccountId(),
 +                ResourceType.user_vm);
  
          // OWNERSHIP STEP 1: update the vm owner
          vm.setAccountId(newAccount.getAccountId());
@@@ -4506,13 -3778,11 +4482,11 @@@
              }
          }
  
-         _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(),
-                 ResourceType.user_vm);
-         // generate usage events to account for this change
-         _usageEventDao.persist(new UsageEventVO(EventTypes.EVENT_VM_CREATE, vm
-                 .getAccountId(), vm.getDataCenterId(), vm.getId(), vm
-                 .getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(),
-                 vm.getHypervisorType().toString()));
+         _resourceLimitMgr.incrementResourceCount(newAccount.getAccountId(), ResourceType.user_vm);
+         //generate usage events to account for this change
 -        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterIdToDeployIn(), vm.getId(),
++        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VM_CREATE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(),
+                 vm.getHostName(), vm.getServiceOfferingId(), vm.getTemplateId(), vm.getHypervisorType().toString(),
+                 VirtualMachine.class.getName(), vm.getUuid());
  
          txn.commit();
  

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/com/cloud/vm/UserVmStateListener.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/vm/UserVmStateListener.java
index 9b475de,786387f..18f8567
--- a/server/src/com/cloud/vm/UserVmStateListener.java
+++ b/server/src/com/cloud/vm/UserVmStateListener.java
@@@ -16,24 -16,48 +16,38 @@@
  // under the License.
  package com.cloud.vm;
  
- import java.util.List;
- 
+ import com.cloud.event.EventCategory;
  import com.cloud.event.EventTypes;
- import com.cloud.event.UsageEventVO;
+ import com.cloud.event.UsageEventUtils;
  import com.cloud.event.dao.UsageEventDao;
 -import com.cloud.network.Network;
 -import com.cloud.network.NetworkVO;
  import com.cloud.network.dao.NetworkDao;
 +import com.cloud.network.dao.NetworkVO;
++import com.cloud.network.Network;
+ import com.cloud.server.ManagementServer;
 -import com.cloud.utils.component.Adapters;
 -import com.cloud.utils.component.ComponentLocator;
  import com.cloud.utils.fsm.StateListener;
  import com.cloud.vm.VirtualMachine.Event;
  import com.cloud.vm.VirtualMachine.State;
  import com.cloud.vm.dao.NicDao;
 -import org.apache.cloudstack.framework.events.EventBus;
 -import org.apache.cloudstack.framework.events.EventBusException;
 +
+ import org.apache.log4j.Logger;
+ 
+ import java.util.Enumeration;
+ import java.util.HashMap;
+ import java.util.List;
+ import java.util.Map;
+ 
++import javax.inject.Inject;
++
  public class UserVmStateListener implements StateListener<State, VirtualMachine.Event, VirtualMachine> {
  
--    protected UsageEventDao _usageEventDao;
--    protected NetworkDao _networkDao;
--    protected NicDao _nicDao;
++    @Inject protected UsageEventDao _usageEventDao;
++    @Inject protected NetworkDao _networkDao;
++    @Inject protected NicDao _nicDao;
+     private static final Logger s_logger = Logger.getLogger(UserVmStateListener.class);
+ 
+     // get the event bus provider if configured
 -    protected static EventBus _eventBus = null;
 -    static {
 -        Adapters<EventBus> eventBusImpls = ComponentLocator.getLocator(ManagementServer.Name).getAdapters(EventBus.class);
 -        if (eventBusImpls != null) {
 -            Enumeration<EventBus> eventBusenum = eventBusImpls.enumeration();
 -            if (eventBusenum != null && eventBusenum.hasMoreElements()) {
 -                _eventBus = eventBusenum.nextElement(); // configure event bus if configured
 -            }
 -        }
 -    }
 -
++    @Inject protected org.apache.cloudstack.framework.events.EventBus _eventBus = null;
 +    
      public UserVmStateListener(UsageEventDao usageEventDao, NetworkDao networkDao, NicDao nicDao) {
          this._usageEventDao = usageEventDao;
          this._networkDao = networkDao;
@@@ -54,29 -79,62 +69,62 @@@
          if(vo.getType() != VirtualMachine.Type.User){
              return true;
          }
 -
 +        
+         pubishOnEventBus(event.name(), "postStateTransitionEvent", vo, oldState, newState);
+ 
          if (VirtualMachine.State.isVmCreated(oldState, event, newState)) {
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(), 
 -            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_CREATE, vo.getAccountId(), vo.getDataCenterIdToDeployIn(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
++            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_CREATE, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
                      vo.getTemplateId(), vo.getHypervisorType().toString());
-             _usageEventDao.persist(usageEvent);
          } else if (VirtualMachine.State.isVmStarted(oldState, event, newState)) {
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_START, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(), 
 -            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_START, vo.getAccountId(), vo.getDataCenterIdToDeployIn(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
++            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_START, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
                      vo.getTemplateId(), vo.getHypervisorType().toString());
-             _usageEventDao.persist(usageEvent);
          } else if (VirtualMachine.State.isVmStopped(oldState, event, newState)) {
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_STOP, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName());
-             _usageEventDao.persist(usageEvent);
 -            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_STOP, vo.getAccountId(), vo.getDataCenterIdToDeployIn(), vo.getId(), vo.getHostName());
++            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_STOP, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName());
              List<NicVO> nics = _nicDao.listByVmId(vo.getId());
              for (NicVO nic : nics) {
                  NetworkVO network = _networkDao.findById(nic.getNetworkId());
-                 usageEvent = new UsageEventVO(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), null, network.getNetworkOfferingId(), null, 0L);
-                 _usageEventDao.persist(usageEvent);
 -                UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vo.getAccountId(), vo.getDataCenterIdToDeployIn(), vo.getId(), null, network.getNetworkOfferingId(), null, 0L);
++                UsageEventUtils.saveUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), null, network.getNetworkOfferingId(), null, 0L);
              }
          } else if (VirtualMachine.State.isVmDestroyed(oldState, event, newState)) {
-             UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(), 
 -            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_DESTROY, vo.getAccountId(), vo.getDataCenterIdToDeployIn(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
++            UsageEventUtils.saveUsageEvent(EventTypes.EVENT_VM_DESTROY, vo.getAccountId(), vo.getDataCenterId(), vo.getId(), vo.getHostName(), vo.getServiceOfferingId(),
                      vo.getTemplateId(), vo.getHypervisorType().toString());
          } 
          return true;
      }
+ 
+     private void pubishOnEventBus(String event, String status, VirtualMachine vo, VirtualMachine.State oldState, VirtualMachine.State newState) {
+ 
+         if (_eventBus == null) {
+             return; // no provider is configured to provide events bus, so just return
+         }
+ 
+         String resourceName = getEntityFromClassName(Network.class.getName());
+         org.apache.cloudstack.framework.events.Event eventMsg =  new org.apache.cloudstack.framework.events.Event(
+                 ManagementServer.Name,
+                 EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(),
+                 event,
+                 resourceName,
+                 vo.getUuid());
+         Map<String, String> eventDescription = new HashMap<String, String>();
+         eventDescription.put("resource", resourceName);
+         eventDescription.put("id", vo.getUuid());
+         eventDescription.put("old-state", oldState.name());
+         eventDescription.put("new-state", newState.name());
+         eventMsg.setDescription(eventDescription);
+         try {
+             _eventBus.publish(eventMsg);
 -        } catch (EventBusException e) {
++        } catch (org.apache.cloudstack.framework.events.EventBusException e) {
+             s_logger.warn("Failed to publish state change event on the the event bus.");
+         }
+ 
+     }
+ 
+     private String getEntityFromClassName(String entityClassName) {
+         int index = entityClassName.lastIndexOf(".");
+         String entityName = entityClassName;
+         if (index != -1) {
+             entityName = entityClassName.substring(index+1);
+         }
+         return entityName;
+     }
  }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/region/RegionManagerImpl.java
index 0000000,cac5a68..190c69c
mode 000000,100755..100755
--- a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
@@@ -1,0 -1,876 +1,877 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ package org.apache.cloudstack.region;
+ 
+ import java.util.ArrayList;
+ import java.util.List;
+ import java.util.Map;
+ 
+ import javax.ejb.Local;
++import javax.inject.Inject;
+ import javax.naming.ConfigurationException;
+ 
+ import org.apache.cloudstack.api.ApiConstants;
+ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
+ import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
+ import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+ import org.apache.cloudstack.region.dao.RegionDao;
+ import org.apache.cloudstack.region.dao.RegionSyncDao;
+ import org.apache.commons.httpclient.NameValuePair;
+ import org.apache.log4j.Logger;
+ 
+ import com.cloud.domain.Domain;
+ import com.cloud.domain.DomainVO;
+ import com.cloud.domain.dao.DomainDao;
+ import com.cloud.exception.ConcurrentOperationException;
+ import com.cloud.exception.InvalidParameterValueException;
+ import com.cloud.exception.ResourceUnavailableException;
+ import com.cloud.user.Account;
+ import com.cloud.user.AccountManager;
+ import com.cloud.user.AccountVO;
+ import com.cloud.user.DomainManager;
+ import com.cloud.user.UserAccount;
+ import com.cloud.user.UserVO;
+ import com.cloud.user.dao.AccountDao;
+ import com.cloud.user.dao.UserAccountDao;
+ import com.cloud.user.dao.UserDao;
 -import com.cloud.utils.component.Inject;
+ import com.cloud.utils.component.Manager;
++import com.cloud.utils.component.ManagerBase;
+ import com.cloud.utils.exception.CloudRuntimeException;
+ import com.cloud.uuididentity.dao.IdentityDao;
+ 
+ @Local(value = { RegionManager.class })
 -public class RegionManagerImpl implements RegionManager, Manager{
++public class RegionManagerImpl extends ManagerBase implements RegionManager, Manager{
+     public static final Logger s_logger = Logger.getLogger(RegionManagerImpl.class);
+     
+     @Inject
+     RegionDao _regionDao;
+     @Inject
+     AccountDao _accountDao;
+     @Inject
+     private AccountManager _accountMgr;
+     @Inject
+     private UserDao _userDao;
+     @Inject
+     private DomainDao _domainDao;
+     @Inject
+     private DomainManager _domainMgr;
+     @Inject
+     private UserAccountDao _userAccountDao;    
+     @Inject
+     private IdentityDao _identityDao;
+     @Inject
+     private RegionSyncDao _regionSyncDao;
+     
+     private String _name;
+     private int _id; 
+     
+     @Override
+     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+         _name = name;
+         _id = _regionDao.getRegionId();
+         return true;
+     }
+     
+     @Override
+     public boolean start() {
+         return true;
+     }
+ 
+     @Override
+     public boolean stop() {
+         return true;
+     }
+ 
+     @Override
+     public String getName() {
+         return _name;
+     }
+ 
+ 	public int getId() {
+ 		return _id;
+ 	}
+ 
+ 	/* 
+ 	 * Propagates Account creation to peer Regions
+ 	 * Adds an entry in region_sync table on failure
+ 	 */
+ 	@Override
+ 	public boolean propagateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone, 
+ 			String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
+ 		String command = "createAccount";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.USERNAME, userName));
+ 		params.add(new NameValuePair(ApiConstants.PASSWORD, password));
+ 		params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
+ 		params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
+ 		params.add(new NameValuePair(ApiConstants.EMAIL, email));
+ 		params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT_TYPE, ""+accountType));
+ 		//ToDo: use domain UUID
+ 		params.add(new NameValuePair(ApiConstants.DOMAIN_ID, ((domainId != null) ? domainId.toString() : "")));
+ 		params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, (details != null) ? details.toString() : ""));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT_ID, accountUUID));
+ 		params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
+ 		params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
+ 
+ 		List<RegionVO> regions =  _regionDao.listAll();
+ 		for (Region region : regions){
+ 			if(region.getId() == getId()){
+ 				continue;
+ 			}
+ 			s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully added account :"+accountName+" to Region: "+region.getId());
+ 			} else {
+ 				// api call failed. Add entry in region_sync table
+ 				addRegionSyncItem(region.getId(), command, params);
+ 				s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
+ 			}
+ 		}
+ 		return true;
+ 	}
+ 
+ 	/* 
+ 	 * Propagates User creation to peer Regions
+ 	 * Adds an entry in region_sync table on failure
+ 	 */
+ 	@Override
+ 	public void propagateAddUser(String userName, String password,
+ 			String firstName, String lastName, String email, String timezone,
+ 			String accountName, String domainUUId, String userUUID) {
+ 		
+         String command = "createUser";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.USERNAME, userName));
+ 		params.add(new NameValuePair(ApiConstants.PASSWORD, password));
+ 		params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
+ 		params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
+ 		params.add(new NameValuePair(ApiConstants.EMAIL, email));
+ 		params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));		
+ 		params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domainUUId));
+ 		params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
+ 		params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
+ 		
+ 		List<RegionVO> regions =  _regionDao.listAll();
+ 		for (Region region : regions){
+ 			if(region.getId() == getId()){
+ 				continue;
+ 			}
+ 			s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
+ 			} else {
+ 				// api call failed. Add entry in region_sync table				
+ 				addRegionSyncItem(region.getId(), command, params);
+ 				s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
+ 			}
+ 		}
+ 		return;		
+ 	}
+ 	
+ 	/* 
+ 	 * Propagates Domain creation details to peer Regions
+ 	 * Adds an entry in region_sync table on failure
+ 	 */
+ 	@Override
+ 	public void propagateAddDomain(String name, Long parentId, String networkDomain, String uuid) {
+ 		
+         String command = "createDomain";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.NAME, name));
+ 		if(parentId != null){
+ 			DomainVO domain = _domainDao.findById(parentId);
+ 			if(domain != null){
+ 				params.add(new NameValuePair(ApiConstants.PARENT_DOMAIN_ID, domain.getUuid()));
+ 			}
+ 		}
+ 		params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
+ 		params.add(new NameValuePair(ApiConstants.DOMAIN_ID, uuid));
+ 		params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
+ 		
+ 		List<RegionVO> regions =  _regionDao.listAll();
+ 		for (Region region : regions){
+ 			if(region.getId() == getId()){
+ 				continue;
+ 			}
+ 			s_logger.debug("Adding domain :"+name+" to Region: "+region.getId());
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
+ 			} else {
+ 				// api call failed. Add entry in region_sync table				
+ 				addRegionSyncItem(region.getId(), command, params);
+ 				s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
+ 			}
+ 		}
+ 		return;		
+ 	}
+ 	
+ 	/**
+ 	 * Adds an entry to region_sync table
+ 	 * Entry contains region Id along with failed api
+ 	 * @param regionId
+ 	 * @param command
+ 	 * @param params
+ 	 */
+ 	private void addRegionSyncItem(int regionId, String command, List<NameValuePair> params){
+ 		String api = RegionsApiUtil.buildParams(command, params);
+ 		RegionSyncVO sync = new RegionSyncVO(regionId, api);
+ 		if(_regionSyncDao.persist(sync) == null){
+ 			s_logger.error("Failed to add Region Sync Item. RegionId: "+regionId + "API command: "+api);
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
+ 		//Region Id should be unique
+ 		if( _regionDao.findById(id) != null ){
+ 			throw new InvalidParameterValueException("Region with id: "+id+" already exists");
+ 		}
+ 		//Region Name should be unique
+ 		if( _regionDao.findByName(name) != null ){
+ 			throw new InvalidParameterValueException("Region with name: "+name+" already exists");
+ 		}
+ 		RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
+ 		return _regionDao.persist(region);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
+ 		RegionVO region = _regionDao.findById(id);
+ 		
+ 		if(region == null){
+ 			throw new InvalidParameterValueException("Region with id: "+id+" does not exist");
+ 		}
+ 		
+ 		//Ensure region name is unique
+ 		if(name != null){
+ 			RegionVO region1 = _regionDao.findByName(name);
+ 			if(region1 != null && id != region1.getId()){
+ 				throw new InvalidParameterValueException("Region with name: "+name+" already exists");	
+ 			}
+ 		}
+ 		
+ 		if(name != null){
+ 			region.setName(name);
+ 		}
+ 		
+ 		if(endPoint != null){
+ 			region.setEndPoint(endPoint);
+ 		}
+ 		
+ 		if(apiKey != null){
+ 			region.setApiKey(apiKey);
+ 		}
+ 		
+ 		if(secretKey != null){
+ 			region.setSecretKey(secretKey);
+ 		}
+ 		
+ 		_regionDao.update(id, region);
+ 		return _regionDao.findById(id);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean removeRegion(int id) {
+ 		RegionVO region = _regionDao.findById(id);
+ 		if(region == null){
+ 			throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
+ 		}		
+ 		return _regionDao.remove(id);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public List<RegionVO> listRegions(Integer id, String name) {
+ 		List<RegionVO> regions = new ArrayList<RegionVO>();
+ 		if(id != null){
+ 			RegionVO region = _regionDao.findById(id);
+ 			if(region != null){
+ 				regions.add(region);
+ 			} 
+ 			return regions;
+ 		}
+ 		if(name != null){
+ 			RegionVO region = _regionDao.findByName(name);
+ 			if(region != null){
+ 				regions.add(region);
+ 			} 
+ 			return regions;
+ 		}
+ 		return _regionDao.listAll();
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean deleteUserAccount(long accountId) {
+ 		AccountVO account = _accountDao.findById(accountId);
+ 		if(account == null){
+ 			throw new InvalidParameterValueException("The specified account does not exist in the system");
+ 		}
+ 		String accountUUID = account.getUuid();
+ 		int regionId = account.getRegionId();
+ 		
+ 		String command = "deleteAccount";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, accountUUID));
+ 
+ 		if(getId() == regionId){
+ 			if(_accountMgr.deleteUserAccount(accountId)){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 				return true;
+ 			} else {
+ 				return false;
+ 			}
+ 		} else {
+ 			//First delete in the Region where account is created
+ 			Region region = _regionDao.findById(regionId);
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
+ 				return true;
+ 			} else {
+ 				s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
+ 				return false;
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Account updateAccount(UpdateAccountCmd cmd) {
+         Long accountId = cmd.getId();
+         Long domainId = cmd.getDomainId();
+         DomainVO domain = _domainDao.findById(domainId);
+         String accountName = cmd.getAccountName();
+         String newAccountName = cmd.getNewName();
+         String networkDomain = cmd.getNetworkDomain();
+         //ToDo send details
+         Map<String, String> details = cmd.getDetails();		
+         
+         Account account = null;
+         if (accountId != null) {
+             account = _accountDao.findById(accountId);
+         } else {
+             account = _accountDao.findEnabledAccount(accountName, domainId);
+         }
+         
+         // Check if account exists
+         if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+             s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
+             throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
+         }	
+ 
+         String command = "updateAccount";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
+ 		params.add(new NameValuePair(ApiConstants.ID, account.getUuid()));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
+ 		params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
+ 		params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
+ 		params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
+ 		if(details != null){
+ 			params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, details.toString()));
+ 		}
+ 		int regionId = account.getRegionId();
+ 		if(getId() == regionId){
+ 			Account updatedAccount = _accountMgr.updateAccount(cmd);
+ 			if(updatedAccount != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully updated account :"+account.getUuid()+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while updating account :"+account.getUuid()+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return updatedAccount;
+ 		} else {
+ 			//First update in the Region where account is created
+ 			Region region = _regionDao.findById(regionId);
+ 			RegionAccount updatedAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
+ 			if (updatedAccount != null) {
+ 				Long id = _identityDao.getIdentityId("account", updatedAccount.getUuid());
+ 				updatedAccount.setId(id);
+ 				Long domainID = _identityDao.getIdentityId("domain", updatedAccount.getDomainUuid());
+ 				updatedAccount.setDomainId(domainID);
+ 				s_logger.debug("Successfully updated account :"+account.getUuid()+" in source Region: "+region.getId());
+ 				return updatedAccount;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while updating account :"+account.getUuid()+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Account disableAccount(String accountName, Long domainId, Long accountId, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException {
+ 		Account account = null;
+         if (accountId != null) {
+             account = _accountDao.findById(accountId);
+         } else {
+             account = _accountDao.findActiveAccount(accountName, domainId);
+         }
+ 
+         if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+             throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
+         }	
+         
+ 		String accountUUID = account.getUuid();
+ 		
+ 		String command = "disableAccount";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.LOCK, lockRequested.toString()));
+ 		params.add(new NameValuePair(ApiConstants.ID, accountUUID));
+ 		DomainVO domain = _domainDao.findById(domainId);
+ 		if(domain != null){		
+ 			params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
+ 		}
+ 		
+ 		int regionId = account.getRegionId();
+ 		if(getId() == regionId){
+ 			Account retAccount = null;
+ 			if(lockRequested){
+ 				retAccount = _accountMgr.lockAccount(accountName, domainId, accountId);
+ 			} else {
+ 				retAccount = _accountMgr.disableAccount(accountName, domainId, accountId);
+ 			}
+ 			if(retAccount != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully disabled account :"+accountUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while disabling account :"+accountUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return retAccount;
+ 		} else {
+ 			//First disable account in the Region where account is created
+ 			Region region = _regionDao.findById(regionId);
+ 			Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
+ 			if (retAccount != null) {
+ 				s_logger.debug("Successfully disabled account :"+accountUUID+" in source Region: "+region.getId());
+ 				return retAccount;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while disabling account :"+accountUUID+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Account enableAccount(String accountName, Long domainId, Long accountId) {
+         // Check if account exists
+         Account account = null;
+         if (accountId != null) {
+             account = _accountDao.findById(accountId);
+         } else {
+             account = _accountDao.findActiveAccount(accountName, domainId);
+         }
+ 
+         if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+             throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
+         }	
+         
+         String accountUUID = account.getUuid();
+         
+         String command = "enableAccount";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, accountUUID));
+ 		params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
+         DomainVO domain = _domainDao.findById(domainId);
+ 		if(domain != null){
+ 			params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
+ 		}
+ 		
+ 		int regionId = account.getRegionId();
+ 		if(getId() == regionId){
+ 			Account retAccount = _accountMgr.enableAccount(accountName, domainId, accountId);
+ 			if(retAccount != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully enabled account :"+accountUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while enabling account :"+accountUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return retAccount;
+ 		} else {
+ 			//First disable account in the Region where account is created
+ 			Region region = _regionDao.findById(regionId);
+ 			Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
+ 			if (retAccount != null) {
+ 				s_logger.debug("Successfully enabled account :"+accountUUID+" in source Region: "+region.getId());
+ 				return retAccount;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while enabling account :"+accountUUID+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public boolean deleteUser(DeleteUserCmd cmd) {
+         long id = cmd.getId();
+ 
+         UserVO user = _userDao.findById(id);
+ 
+         if (user == null) {
+             throw new InvalidParameterValueException("The specified user doesn't exist in the system");
+         }	
+         
+ 		String userUUID = user.getUuid();
+ 		int regionId = user.getRegionId();
+ 		
+ 		String command = "deleteUser";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, userUUID));
+ 		
+ 		if(getId() == regionId){
+ 			if(_accountMgr.deleteUser(cmd)){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully deleted user :"+userUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while deleting account :"+userUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 				return true;
+ 			} else {
+ 				return false;
+ 			}
+ 		} else {
+ 			//First delete in the Region where account is created
+ 			Region region = _regionDao.findById(regionId);
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully deleted user :"+userUUID+" in source Region: "+region.getId());
+ 				return true;
+ 			} else {
+ 				s_logger.error("Error while deleting user :"+userUUID+" in source Region: "+region.getId());
+ 				return false;
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public Domain updateDomain(UpdateDomainCmd cmd) {
+ 		long id = cmd.getId();
+ 		DomainVO domain = _domainDao.findById(id);
+ 		if(domain == null){
+ 			throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
+ 		}	
+ 		
+ 		String domainUUID = domain.getUuid();
+ 		
+ 		String command = "updateDomain";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, domainUUID));
+ 		params.add(new NameValuePair(ApiConstants.NAME, cmd.getDomainName()));
+ 		params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, cmd.getNetworkDomain()));
+ 		
+ 		int regionId = domain.getRegionId();
+ 		if(getId() == regionId){
+ 			Domain updatedDomain = _domainMgr.updateDomain(cmd);
+ 			if(updatedDomain != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully updated updatedDomain :"+domainUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while updating updatedDomain :"+domainUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return updatedDomain;
+ 		} else {
+ 			//First update in the Region where domain was created
+ 			Region region = _regionDao.findById(regionId);
+ 			RegionDomain updatedDomain = RegionsApiUtil.makeDomainAPICall(region, command, params);
+ 			if (updatedDomain != null) {
+ 				Long parentId = _identityDao.getIdentityId("domain", updatedDomain.getParentUuid());
+ 				updatedDomain.setParent(parentId);
+ 				s_logger.debug("Successfully updated user :"+domainUUID+" in source Region: "+region.getId());
+ 				return (DomainVO)updatedDomain;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while updating user :"+domainUUID+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 	
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean deleteDomain(Long id, Boolean cleanup) {
+ 		DomainVO domain = _domainDao.findById(id);
+ 		if(domain == null){
+ 			throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
+ 		}	
+ 		
+ 		String domainUUID = domain.getUuid();
+ 		
+ 		String command = "deleteDomain";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, domainUUID));
+ 		params.add(new NameValuePair(ApiConstants.CLEANUP, cleanup.toString()));
+ 		
+         int regionId = domain.getRegionId();
+ 		if(getId() == regionId){
+ 			if(_domainMgr.deleteDomain(id, cleanup)){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully deleted domain :"+domainUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while deleting domain :"+domainUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 				return true;
+ 			} else {
+ 				return false;
+ 			}
+ 		} else {
+ 			//First delete in the Region where domain is created
+ 			Region region = _regionDao.findById(regionId);
+ 			if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 				s_logger.debug("Successfully deleted domain :"+domainUUID+" in Region: "+region.getId());
+ 				return true;
+ 			} else {
+ 				s_logger.error("Error while deleting domain :"+domainUUID+" in Region: "+region.getId());
+ 				return false;
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public UserAccount updateUser(UpdateUserCmd cmd) {
+         long id = cmd.getId();
+ 
+         UserVO user = _userDao.findById(id);
+         if (user == null) {
+             throw new InvalidParameterValueException("The specified user doesn't exist in the system");
+         }	
+         
+ 		String userUUID = user.getUuid();
+ 		
+ 		String command = "updateUser";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, userUUID));
+ 		params.add(new NameValuePair(ApiConstants.API_KEY, cmd.getApiKey()));
+ 		params.add(new NameValuePair(ApiConstants.EMAIL, cmd.getEmail()));
+ 		params.add(new NameValuePair(ApiConstants.FIRSTNAME, cmd.getFirstname()));
+ 		params.add(new NameValuePair(ApiConstants.LASTNAME, cmd.getLastname()));
+ 		params.add(new NameValuePair(ApiConstants.PASSWORD, cmd.getPassword()));
+ 		params.add(new NameValuePair(ApiConstants.SECRET_KEY, cmd.getSecretKey()));
+ 		params.add(new NameValuePair(ApiConstants.TIMEZONE, cmd.getTimezone()));
+ 		params.add(new NameValuePair(ApiConstants.USERNAME, cmd.getUsername()));
+ 		
+ 		int regionId = user.getRegionId();
+ 		if(getId() == regionId){
+ 			UserAccount updateUser = _accountMgr.updateUser(cmd);
+ 			if(updateUser != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully updated user :"+userUUID+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while updating user :"+userUUID+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return updateUser;
+ 		} else {
+ 			//First update in the Region where user was created
+ 			Region region = _regionDao.findById(regionId);
+ 			UserAccount updateUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
+ 			if (updateUser != null) {
+ 				s_logger.debug("Successfully updated user :"+userUUID+" in source Region: "+region.getId());
+ 				return updateUser;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while updating user :"+userUUID+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public UserAccount disableUser(Long userId) {
+         UserVO user = _userDao.findById(userId);
+         if (user == null || user.getRemoved() != null) {
+             throw new InvalidParameterValueException("Unable to find active user by id " + userId);
+         }        
+         
+         int regionId = user.getRegionId();
+         
+         String command = "disableUser";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
+         
+ 		if(getId() == regionId){
+ 			UserAccount disabledUser = _accountMgr.disableUser(userId);
+ 			if(disabledUser != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully disabled user :"+user.getUuid()+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while disabling user :"+user.getUuid()+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return disabledUser;
+ 		} else {
+ 			//First disable in the Region where user was created
+ 			Region region = _regionDao.findById(regionId);
+ 			UserAccount disabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
+ 			if (disabledUser != null) {
+ 				s_logger.debug("Successfully disabled user :"+user.getUuid()+" in source Region: "+region.getId());
+ 				return disabledUser;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while disabling user :"+user.getUuid()+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public UserAccount enableUser(long userId) {
+         UserVO user = _userDao.findById(userId);
+         if (user == null || user.getRemoved() != null) {
+             throw new InvalidParameterValueException("Unable to find active user by id " + userId);
+         }		        
+         
+         int regionId = user.getRegionId();
+         
+         String command = "enableUser";
+ 		List<NameValuePair> params = new ArrayList<NameValuePair>();
+ 		params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
+         
+ 		if(getId() == regionId){
+ 			UserAccount enabledUser = _accountMgr.enableUser(userId);
+ 			if(enabledUser != null){
+ 				List<RegionVO> regions =  _regionDao.listAll();
+ 				for (Region region : regions){
+ 					if(region.getId() == getId()){
+ 						continue;
+ 					}
+ 					params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
+ 					if (RegionsApiUtil.makeAPICall(region, command, params)) {
+ 						s_logger.debug("Successfully enabled user :"+user.getUuid()+" in Region: "+region.getId());
+ 					} else {
+ 						s_logger.error("Error while disabling user :"+user.getUuid()+" in Region: "+region.getId());
+ 					}
+ 				}
+ 			}
+ 			return enabledUser;
+ 		} else {
+ 			//First enable in the Region where user was created
+ 			Region region = _regionDao.findById(regionId);
+ 			UserAccount enabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
+ 			if (enabledUser != null) {
+ 				s_logger.debug("Successfully enabled user :"+user.getUuid()+" in source Region: "+region.getId());
+ 				return enabledUser;
+ 			} else {
+ 				throw new CloudRuntimeException("Error while enabling user :"+user.getUuid()+" in source Region: "+region.getId());
+ 			}
+ 		}
+ 	}
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/region/RegionServiceImpl.java
index 0000000,f5a0a80..f10f638
mode 000000,100755..100755
--- a/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
@@@ -1,0 -1,298 +1,299 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ package org.apache.cloudstack.region;
+ 
+ import java.util.List;
+ import java.util.Map;
+ 
+ import javax.ejb.Local;
++import javax.inject.Inject;
+ import javax.naming.ConfigurationException;
+ 
+ import org.apache.cloudstack.api.command.admin.account.DeleteAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.EnableAccountCmd;
+ import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
+ import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
+ import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
+ import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.DisableUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.EnableUserCmd;
+ import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
+ import org.apache.cloudstack.api.command.user.region.ListRegionsCmd;
+ import org.apache.cloudstack.region.dao.RegionDao;
+ import org.apache.log4j.Logger;
+ 
+ import com.cloud.domain.Domain;
+ import com.cloud.domain.dao.DomainDao;
+ import com.cloud.exception.ConcurrentOperationException;
+ import com.cloud.exception.PermissionDeniedException;
+ import com.cloud.exception.ResourceUnavailableException;
+ import com.cloud.user.Account;
+ import com.cloud.user.AccountManager;
+ import com.cloud.user.DomainManager;
+ import com.cloud.user.UserAccount;
+ import com.cloud.user.UserContext;
+ import com.cloud.user.dao.AccountDao;
+ import com.cloud.user.dao.UserDao;
 -import com.cloud.utils.component.Inject;
+ import com.cloud.utils.component.Manager;
++import com.cloud.utils.component.ManagerBase;
+ 
+ @Local(value = { RegionService.class })
 -public class RegionServiceImpl implements RegionService, Manager {
++public class RegionServiceImpl extends ManagerBase implements RegionService, Manager {
+     public static final Logger s_logger = Logger.getLogger(RegionServiceImpl.class);
+     
+     @Inject
+     private RegionDao _regionDao;
+     @Inject
+     private AccountDao _accountDao;
+     @Inject
+     private UserDao _userDao;
+     @Inject
+     private DomainDao _domainDao;    
+     @Inject
+     private RegionManager _regionMgr;
+     @Inject
+     private AccountManager _accountMgr;
+     @Inject
+     private DomainManager _domainMgr;
+     
+     private String _name;
+     
+     @Override
+     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
+         _name = name;
+         return true;
+     }
+     
+     @Override
+     public boolean start() {
+         return true;
+     }
+ 
+     @Override
+     public boolean stop() {
+         return true;
+     }
+ 
+     @Override
+     public String getName() {
+         return _name;
+     }
+ 
+     /**
+      * {@inheritDoc}
+      */    
+ 	@Override
+ 	public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
+ 		//Check for valid Name
+ 		//Check valid end_point url
+ 		return _regionMgr.addRegion(id, name, endPoint, apiKey, secretKey);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
+ 		//Check for valid Name
+ 		//Check valid end_point url		
+ 		return _regionMgr.updateRegion(id, name, endPoint, apiKey, secretKey);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean removeRegion(int id) {
+ 		return _regionMgr.removeRegion(id);
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public List<? extends Region> listRegions(ListRegionsCmd cmd) {
+ 		return _regionMgr.listRegions(cmd.getId(), cmd.getName());
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean deleteUserAccount(DeleteAccountCmd cmd) {
+         boolean result = false;
+         if(checkIsPropagate(cmd.getIsPropagate())){
+         	result = _accountMgr.deleteUserAccount(cmd.getId());
+         } else {
+         	result = _regionMgr.deleteUserAccount(cmd.getId());
+         }
+ 		return result;
+ 	}
+ 	
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public Account updateAccount(UpdateAccountCmd cmd) {
+     	Account result = null;
+     	if(checkIsPropagate(cmd.getIsPropagate())){
+     		result = _accountMgr.updateAccount(cmd);
+         } else {
+         	result = _regionMgr.updateAccount(cmd);
+         }
+ 		
+ 		return result;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public Account disableAccount(DisableAccountCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException {
+     	Account result = null;
+     	if(checkIsPropagate(cmd.getIsPropagate())){
+     		if(cmd.getLockRequested())
+     			result = _accountMgr.lockAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
+     		else
+     			result = _accountMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
+     	} else {
+     		result = _regionMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId(), cmd.getLockRequested());
+     	}
+ 		return result;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public Account enableAccount(EnableAccountCmd cmd) {
+     	Account result = null;
+     	if(checkIsPropagate(cmd.getIsPropagate())){
+     		result = _accountMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
+     	} else {
+     		result = _regionMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
+     	}
+ 		return result;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean deleteUser(DeleteUserCmd cmd) {
+         boolean result = false;
+         if(checkIsPropagate(cmd.getIsPropagate())){
+         	result = _accountMgr.deleteUser(cmd);
+         } else {
+         	result = _regionMgr.deleteUser(cmd);
+         }		
+ 		return result;
+ 	}
+ 	
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public Domain updateDomain(UpdateDomainCmd cmd) {
+         Domain domain = null;
+         if(checkIsPropagate(cmd.getIsPropagate())){
+         	domain = _domainMgr.updateDomain(cmd);
+         } else {
+         	domain = _regionMgr.updateDomain(cmd);
+         }		
+ 		return domain;
+ 	}	
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public boolean deleteDomain(DeleteDomainCmd cmd) {
+ 		boolean result = false;
+ 		if(checkIsPropagate(cmd.isPropagate())){
+ 			result = _domainMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
+ 		} else {
+ 			result = _regionMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
+ 		}
+ 		return result;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 	
+ 	@Override
+ 	public UserAccount updateUser(UpdateUserCmd cmd){
+         UserAccount user = null;
+         if(checkIsPropagate(cmd.getIsPropagate())){
+         	user = _accountMgr.updateUser(cmd);
+         } else {
+         	user = _regionMgr.updateUser(cmd);
+         }		
+ 		return user;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public UserAccount disableUser(DisableUserCmd cmd) {
+         UserAccount user = null;
+         if(checkIsPropagate(cmd.getIsPropagate())){
+     		user = _accountMgr.disableUser(cmd.getId());
+         } else {
+         	user = _regionMgr.disableUser(cmd.getId());
+         }
+ 		return user;
+ 	}
+ 
+     /**
+      * {@inheritDoc}
+      */ 
+ 	@Override
+ 	public UserAccount enableUser(EnableUserCmd cmd) {
+ 		UserAccount user = null;
+ 		if(checkIsPropagate(cmd.getIsPropagate())){
+ 			user = _accountMgr.enableUser(cmd.getId());
+ 		} else {
+ 			user = _regionMgr.enableUser(cmd.getId());
+ 		}		
+ 		return user;
+ 	}
+ 	
+     private boolean isRootAdmin(short accountType) {
+         return (accountType == Account.ACCOUNT_TYPE_ADMIN);
+     }
+     
+     /**
+      * Check isPopagate flag, Only ROOT Admin can use this param
+      * @param isPopagate
+      * @return
+      */
+     private boolean checkIsPropagate(Boolean isPopagate){
+     	if(isPopagate == null || !isPopagate){
+     		return false;
+     	}
+ 		// Only Admin can use isPopagate flag
+     	UserContext ctx = UserContext.current();
+     	Account caller = ctx.getCaller();
+     	if(!isRootAdmin(caller.getType())){
+     		throw new PermissionDeniedException("isPropagate param cannot be used by non ROOT Admin");
+     	}          	
+     	return true;
+     }
+ 
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
index 0000000,4099835..8f50f93
mode 000000,100644..100644
--- a/server/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
+++ b/server/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
@@@ -1,0 -1,46 +1,48 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ package org.apache.cloudstack.region.dao;
+ 
+ import javax.ejb.Local;
+ 
+ import org.apache.cloudstack.region.RegionVO;
+ import org.apache.log4j.Logger;
++import org.springframework.stereotype.Component;
+ 
+ import com.cloud.utils.db.GenericDaoBase;
+ import com.cloud.utils.db.SearchBuilder;
+ import com.cloud.utils.db.SearchCriteria;
+ 
++@Component
+ @Local(value={RegionDao.class})
+ public class RegionDaoImpl extends GenericDaoBase<RegionVO, Integer> implements RegionDao {
+     private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class);
+     protected SearchBuilder<RegionVO> NameSearch;
+     protected SearchBuilder<RegionVO> AllFieldsSearch;
+     
+     public RegionDaoImpl(){
+     	NameSearch = createSearchBuilder();
+     	NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
+     	NameSearch.done();
+     }
+     
+ 	@Override
+ 	public RegionVO findByName(String name) {
+         SearchCriteria<RegionVO> sc = NameSearch.create();
+         sc.setParameters("name", name);
+         return findOneBy(sc);
+ 	}
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/src/org/apache/cloudstack/region/dao/RegionSyncDaoImpl.java
----------------------------------------------------------------------
diff --cc server/src/org/apache/cloudstack/region/dao/RegionSyncDaoImpl.java
index 0000000,a8fa33f..9cd9b0d
mode 000000,100644..100644
--- a/server/src/org/apache/cloudstack/region/dao/RegionSyncDaoImpl.java
+++ b/server/src/org/apache/cloudstack/region/dao/RegionSyncDaoImpl.java
@@@ -1,0 -1,33 +1,35 @@@
+ // Licensed to the Apache Software Foundation (ASF) under one
+ // or more contributor license agreements.  See the NOTICE file
+ // distributed with this work for additional information
+ // regarding copyright ownership.  The ASF licenses this file
+ // to you under the Apache License, Version 2.0 (the
+ // "License"); you may not use this file except in compliance
+ // with the License.  You may obtain a copy of the License at
+ //
+ //   http://www.apache.org/licenses/LICENSE-2.0
+ //
+ // Unless required by applicable law or agreed to in writing,
+ // software distributed under the License is distributed on an
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ // KIND, either express or implied.  See the License for the
+ // specific language governing permissions and limitations
+ // under the License.
+ package org.apache.cloudstack.region.dao;
+ 
+ import javax.ejb.Local;
+ 
+ import org.apache.cloudstack.region.RegionSyncVO;
+ import org.apache.log4j.Logger;
++import org.springframework.stereotype.Component;
+ 
+ import com.cloud.utils.db.GenericDaoBase;
+ 
++@Component
+ @Local(value={RegionSyncDao.class})
+ public class RegionSyncDaoImpl extends GenericDaoBase<RegionSyncVO, Integer> implements RegionSyncDao {
+     private static final Logger s_logger = Logger.getLogger(RegionSyncDaoImpl.class);
+     
+     public RegionSyncDaoImpl(){
+     	
+     }
+ }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/async/TestAsyncJobManager.java
----------------------------------------------------------------------
diff --cc server/test/com/cloud/async/TestAsyncJobManager.java
index 7cb24dd,9b154ff..e323393
--- a/server/test/com/cloud/async/TestAsyncJobManager.java
+++ b/server/test/com/cloud/async/TestAsyncJobManager.java
@@@ -178,75 -178,75 +178,75 @@@ public class TestAsyncJobManager extend
  		if(i % 2 == 0)
  			return 1L;
  		return 2L;
 -		*/
 -	}
 -	
 -	public void tstLocking() {
 -		
 -		int testThreads = 20;
 -		Thread[] threads = new Thread[testThreads];
 -		
 -		for(int i = 0; i < testThreads; i++) {
 -			final int current = i;
 -			threads[i] = new Thread(new Runnable() {
 -				public void run() {
 -					
 -					final HostDao hostDao = new HostDaoImpl();
 -					while(true) {
 -						Transaction txn = Transaction.currentTxn();
 -						try {
 -							HostVO host = hostDao.acquireInLockTable(getRandomLockId(), 10);
 -							if(host != null) {
 -								s_logger.info("Thread " + (current + 1) + " acquired lock");
 -								
 -								try { Thread.sleep(getRandomMilliseconds(1000, 5000)); } catch (InterruptedException e) {}
 -								
 -								s_logger.info("Thread " + (current + 1) + " released lock");
 -								hostDao.releaseFromLockTable(host.getId());
 -								
 -								try { Thread.sleep(getRandomMilliseconds(1000, 5000)); } catch (InterruptedException e) {}
 -							} else {
 -								s_logger.info("Thread " + (current + 1) + " is not able to acquire lock");
 -							}
 -						} finally {
 -							txn.close();
 -						}
 -					}
 -				}
 -			});
 -			threads[i].start();
 -		}
 -		
 -		try {
 -			for(int i = 0; i < testThreads; i++)
 -				threads[i].join();
 -		} catch(InterruptedException e) {
 -		}
 -	}
 -	
 -	public void testDomain() {
 -		getRandomMilliseconds(1, 100);		
 -		DomainDao domainDao = new DomainDaoImpl();
 -		
 +         */
 +    }
 +
 +    public void tstLocking() {
 +
 +        int testThreads = 20;
 +        Thread[] threads = new Thread[testThreads];
 +
 +        for(int i = 0; i < testThreads; i++) {
 +            final int current = i;
 +            threads[i] = new Thread(new Runnable() {
 +                @Override
 +                public void run() {
 +
 +                    final HostDao hostDao = new HostDaoImpl();
 +                    while(true) {
 +                        Transaction txn = Transaction.currentTxn();
 +                        try {
 +                            HostVO host = hostDao.acquireInLockTable(getRandomLockId(), 10);
 +                            if(host != null) {
 +                                s_logger.info("Thread " + (current + 1) + " acquired lock");
 +
 +                                try { Thread.sleep(1000); } catch (InterruptedException e) {}
 +
 +                                s_logger.info("Thread " + (current + 1) + " released lock");
 +                                hostDao.releaseFromLockTable(host.getId());
 +
 +                                try { Thread.sleep(1000); } catch (InterruptedException e) {}
 +                            } else {
 +                                s_logger.info("Thread " + (current + 1) + " is not able to acquire lock");
 +                            }
 +                        } finally {
 +                            txn.close();
 +                        }
 +                    }
 +                }
 +            });
 +            threads[i].start();
 +        }
 +
 +        try {
 +            for(int i = 0; i < testThreads; i++)
 +                threads[i].join();
 +        } catch(InterruptedException e) {
 +        }
 +    }
 +
 +    public void testDomain() {
 +        DomainDao domainDao = new DomainDaoImpl();
 +
-         DomainVO domain1 = new DomainVO("d1", 2L, 1L, null);
+ 		DomainVO domain1 = new DomainVO("d1", 2L, 1L, null, 1);
 -		domainDao.create(domain1);
 -		
 +        domainDao.create(domain1);
 +
-         DomainVO domain2 = new DomainVO("d2", 2L, 1L, null);
+ 		DomainVO domain2 = new DomainVO("d2", 2L, 1L, null, 1);
 -		domainDao.create(domain2);
 -		
 +        domainDao.create(domain2);
 +
-         DomainVO domain3 = new DomainVO("d3", 2L, 1L, null);
+ 		DomainVO domain3 = new DomainVO("d3", 2L, 1L, null, 1);
 -		domainDao.create(domain3);
 +        domainDao.create(domain3);
  
-         DomainVO domain11 = new DomainVO("d11", 2L, domain1.getId(), null);
+ 		DomainVO domain11 = new DomainVO("d11", 2L, domain1.getId(), null, 1);
 -		domainDao.create(domain11);
 -		
 -		domainDao.remove(domain11.getId());
 -		
 +        domainDao.create(domain11);
 +
 +        domainDao.remove(domain11.getId());
 +
-         DomainVO domain12 = new DomainVO("d12", 2L, domain1.getId(), null);
+ 		DomainVO domain12 = new DomainVO("d12", 2L, domain1.getId(), null, 1);
 -		domainDao.create(domain12);
 -		
 -		domainDao.remove(domain3.getId());
 +        domainDao.create(domain12);
 +
 +        domainDao.remove(domain3.getId());
-         DomainVO domain4 = new DomainVO("d4", 2L, 1L, null);
+ 		DomainVO domain4 = new DomainVO("d4", 2L, 1L, null, 1);
 -		domainDao.create(domain4);
 -	}
 +        domainDao.create(domain4);
 +    }
  }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/snapshot/SnapshotDaoTest.java
----------------------------------------------------------------------
diff --cc server/test/com/cloud/snapshot/SnapshotDaoTest.java
index c84778d,5dc9b91..099b21a
--- a/server/test/com/cloud/snapshot/SnapshotDaoTest.java
+++ b/server/test/com/cloud/snapshot/SnapshotDaoTest.java
@@@ -35,21 -23,16 +35,22 @@@ import com.cloud.utils.component.Compon
  import junit.framework.Assert;
  import junit.framework.TestCase;
  
 -import java.util.List;
+ 
 +@RunWith(SpringJUnit4ClassRunner.class)
 +@ContextConfiguration(locations = "classpath:/SnapshotDaoTestContext.xml")
  public class SnapshotDaoTest extends TestCase {
 -	
 +    @Inject SnapshotDaoImpl dao;
 +
 +    @Before
 +    public void setup() throws Exception {
 +        ComponentContext.initComponentsLifeCycle();
 +    }
 +
 +    @Test
      public void testListBy() {
-         List<SnapshotVO> snapshots = dao.listByInstanceId(3, Snapshot.Status.BackedUp);
 -        SnapshotDaoImpl dao = ComponentLocator.inject(SnapshotDaoImpl.class);
 -        
+         List<SnapshotVO> snapshots = dao.listByInstanceId(3, Snapshot.State.BackedUp);
          for(SnapshotVO snapshot : snapshots) {
-             Assert.assertTrue(snapshot.getStatus() == Snapshot.Status.BackedUp);
+             Assert.assertTrue(snapshot.getState() == Snapshot.State.BackedUp);
          }
      }
  }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/user/MockAccountManagerImpl.java
----------------------------------------------------------------------
diff --cc server/test/com/cloud/user/MockAccountManagerImpl.java
index 1893d67,b5433ba..5632070
--- a/server/test/com/cloud/user/MockAccountManagerImpl.java
+++ b/server/test/com/cloud/user/MockAccountManagerImpl.java
@@@ -284,28 -276,11 +278,11 @@@ public class MockAccountManagerImpl ext
          return true;
      }
  
- 
-     @Override
-     public UserAccount createUserAccount(String userName, String password,
-             String firstName, String lastName, String email, String timezone,
-             String accountName, short accountType, Long domainId,
-             String networkDomain, Map<String, String> details) {
-         // TODO Auto-generated method stub
-         return null;
-     }
- 
-     @Override
-     public Account createAccount(String accountName, short accountType,
-             Long domainId, String networkDomain, Map details) {
-         // TODO Auto-generated method stub
-         return null;
-     }
- 
 -	@Override
 -	public boolean enableAccount(long accountId) {
 -		// TODO Auto-generated method stub
 -		return false;
 -	}
 +    @Override
 +    public boolean enableAccount(long accountId) {
 +        // TODO Auto-generated method stub
 +        return false;
 +    }
  
      @Override
      public void buildACLSearchBuilder(SearchBuilder<? extends ControlledEntity> sb, Long domainId, boolean isRecursive, List<Long> permittedAccounts,
@@@ -347,7 -322,32 +324,32 @@@
          return null;
      }
  
 -	@Override
 +    @Override
+ 	public UserAccount createUserAccount(String userName, String password,
+ 			String firstName, String lastName, String email, String timezone,
+ 			String accountName, short accountType, Long domainId,
+ 			String networkDomain, Map<String, String> details,
+ 			String accountUUID, String userUUID, Integer regionId) {
+ 		// TODO Auto-generated method stub
+ 		return null;
+ 	}
+ 
+ 	@Override
+ 	public User createUser(String userName, String password, String firstName,
+ 			String lastName, String email, String timeZone, String accountName,
+ 			Long domainId, String userUUID, Integer regionId) {
+ 		// TODO Auto-generated method stub
+ 		return null;
+ 	}
+ 
+ 	@Override
+ 	public Account createAccount(String accountName, short accountType,
+ 			Long domainId, String networkDomain, Map details, String uuid,
+ 			int regionId) {
+ 		// TODO Auto-generated method stub
+ 		return null;
+ 	}
+     @Override
      public RoleType getRoleType(Account account) {
          return null;
      }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/user/MockDomainManagerImpl.java
----------------------------------------------------------------------
diff --cc server/test/com/cloud/user/MockDomainManagerImpl.java
index d249c80,4f134a0..b791f4c
--- a/server/test/com/cloud/user/MockDomainManagerImpl.java
+++ b/server/test/com/cloud/user/MockDomainManagerImpl.java
@@@ -25,26 -25,18 +25,21 @@@ import javax.naming.ConfigurationExcept
  
  import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
  import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
 +import org.springframework.stereotype.Component;
+ import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
  
  import com.cloud.domain.Domain;
  import com.cloud.domain.DomainVO;
  import com.cloud.exception.PermissionDeniedException;
 -import com.cloud.utils.component.Manager;
  import com.cloud.utils.Pair;
 +import com.cloud.utils.component.Manager;
 +import com.cloud.utils.component.ManagerBase;
  
 +@Component
  @Local(value = { DomainManager.class, DomainService.class })
 -public class MockDomainManagerImpl implements  Manager, DomainManager, DomainService {
 +public class MockDomainManagerImpl extends ManagerBase implements DomainManager, DomainService {
  
      @Override
-     public Domain createDomain(String name, Long parentId, String networkDomain) {
-         // TODO Auto-generated method stub
-         return null;
-     }
- 
-     @Override
      public Domain getDomain(long id) {
          // TODO Auto-generated method stub
          return null;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7b75f0d9/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
----------------------------------------------------------------------
diff --cc server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
index de1bbb9,f0e4b54..a483291
--- a/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
+++ b/server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java
@@@ -16,17 -16,12 +16,12 @@@
  // under the License.
  package com.cloud.vpc.dao;
  
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- 
- import javax.ejb.Local;
- 
+ import com.cloud.network.Network;
  import com.cloud.network.Network.GuestType;
 -import com.cloud.network.NetworkAccountVO;
 -import com.cloud.network.NetworkVO;
  import com.cloud.network.Networks.TrafficType;
 +import com.cloud.network.dao.NetworkAccountVO;
  import com.cloud.network.dao.NetworkDao;
 +import com.cloud.network.dao.NetworkVO;
  import com.cloud.utils.db.DB;
  import com.cloud.utils.db.GenericDaoBase;
  import com.cloud.utils.db.SearchBuilder;