cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject [33/50] [abbrv] git commit: refs/heads/gslb-wip - CLOUDSTACK-241: Remove API sync. Merge changes from 4.1 branch. Converted tabs to spaces.
Date Mon, 18 Mar 2013 10:14:48 GMT
CLOUDSTACK-241: Remove API sync. Merge changes from 4.1 branch. Converted tabs to spaces.


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

Branch: refs/heads/gslb-wip
Commit: a1fdb0c2d4da633c455253e7c790f61accf4b5de
Parents: 8b5c1b2
Author: Kishan Kavala <kishan@cloud.com>
Authored: Fri Mar 8 18:54:36 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Fri Mar 8 19:02:41 2013 +0530

----------------------------------------------------------------------
 .../command/admin/account/CreateAccountCmd.java    |    4 +-
 .../command/admin/account/DeleteAccountCmd.java    |    4 +-
 .../command/admin/account/DisableAccountCmd.java   |    2 +-
 .../command/admin/account/EnableAccountCmd.java    |    3 +-
 .../command/admin/account/UpdateAccountCmd.java    |    3 +-
 .../api/command/admin/domain/DeleteDomainCmd.java  |    2 +-
 .../api/command/admin/domain/UpdateDomainCmd.java  |    4 +-
 .../api/command/admin/user/DeleteUserCmd.java      |    2 +-
 .../api/command/admin/user/DisableUserCmd.java     |    4 +-
 .../api/command/admin/user/EnableUserCmd.java      |    4 +-
 .../api/command/admin/user/UpdateUserCmd.java      |    4 +-
 .../apache/cloudstack/region/RegionService.java    |  136 +++---
 core/src/com/cloud/user/AccountVO.java             |   40 +-
 core/src/com/cloud/user/UserVO.java                |   23 +-
 .../src/com/cloud/projects/ProjectManagerImpl.java |    2 +-
 server/src/com/cloud/user/AccountManager.java      |   14 +-
 server/src/com/cloud/user/AccountManagerImpl.java  |   71 ++-
 server/src/com/cloud/user/DomainManagerImpl.java   |    9 +-
 server/src/com/cloud/user/dao/AccountDaoImpl.java  |   90 ++--
 .../apache/cloudstack/region/RegionManager.java    |   94 ++++
 .../cloudstack/region/RegionManagerImpl.java       |  432 ++++++++++++++-
 .../cloudstack/region/RegionServiceImpl.java       |   72 +--
 .../apache/cloudstack/region/RegionsApiUtil.java   |  306 ++++++++++
 .../cloudstack/region/dao/RegionSyncDao.java       |   24 -
 .../cloudstack/region/dao/RegionSyncDaoImpl.java   |   35 --
 .../com/cloud/user/MockAccountManagerImpl.java     |    3 +-
 .../cloudstack/region/RegionManagerTest.java       |   35 +-
 setup/db/db/schema-40to410.sql                     |    1 +
 28 files changed, 1083 insertions(+), 340 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
index 57789c9..4121651 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/CreateAccountCmd.java
@@ -78,6 +78,7 @@ public class CreateAccountCmd extends BaseCmd {
     @Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
     private Map<String, String> details;
 
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -149,7 +150,8 @@ public class CreateAccountCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
-        UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(), getDomainId(), getNetworkDomain(), getDetails());
+        UserAccount userAccount = _accountService.createUserAccount(getUsername(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimeZone(), getAccountName(), getAccountType(),
+                getDomainId(), getNetworkDomain(), getDetails());
         if (userAccount != null) {
             AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
index ff6d0d2..9895da1 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/DeleteAccountCmd.java
@@ -49,7 +49,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
     private Long id;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -96,7 +96,7 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Account Id: "+getId());
- 
+
         boolean	result = _regionService.deleteUserAccount(this);
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
index fceb192..1f9b821 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/DisableAccountCmd.java
@@ -59,7 +59,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
     private Boolean lockRequested;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
index d07ea79..b9a9f6d 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/EnableAccountCmd.java
@@ -51,7 +51,7 @@ public class EnableAccountCmd extends BaseCmd {
     private Long domainId;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -68,7 +68,6 @@ public class EnableAccountCmd extends BaseCmd {
         return domainId;
     }
 
-    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
index 6aa853f..60d1a97 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/account/UpdateAccountCmd.java
@@ -64,7 +64,7 @@ public class UpdateAccountCmd extends BaseCmd{
     private Map details;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -99,7 +99,6 @@ public class UpdateAccountCmd extends BaseCmd{
         return params;
     }
 
-
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
index 97e7afa..488a758 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/DeleteDomainCmd.java
@@ -51,7 +51,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
     private Boolean cleanup;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
index 91c8346..e658f49 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/domain/UpdateDomainCmd.java
@@ -53,7 +53,7 @@ public class UpdateDomainCmd extends BaseCmd {
     private String networkDomain;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -88,7 +88,7 @@ public class UpdateDomainCmd extends BaseCmd {
     public void execute(){
         UserContext.current().setEventDetails("Domain Id: "+getId());
         Domain domain =  _regionService.updateDomain(this);
-        
+
         if (domain != null) {
             DomainResponse response = _responseGenerator.createDomainResponse(domain);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java
index 68ddbe7..bb37d08 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/user/DeleteUserCmd.java
@@ -46,7 +46,7 @@ public class DeleteUserCmd extends BaseCmd {
     private Long id;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java
index a7008af..6eaa46b 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/user/DisableUserCmd.java
@@ -50,7 +50,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
     private Long id;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -93,7 +93,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
         UserAccount user = _regionService.disableUser(this);
-        
+
         if (user != null){
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java
index c51b310..382f67c 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/user/EnableUserCmd.java
@@ -47,7 +47,7 @@ public class EnableUserCmd extends BaseCmd {
     private Long id;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -79,7 +79,7 @@ public class EnableUserCmd extends BaseCmd {
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
         UserAccount user = _regionService.enableUser(this);
-        
+
         if (user != null){
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java b/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java
index 1212cd9..1f31662 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/user/UpdateUserCmd.java
@@ -72,7 +72,7 @@ public class UpdateUserCmd extends BaseCmd {
     private String username;
 
     @Inject RegionService _regionService;
-    
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -136,7 +136,7 @@ public class UpdateUserCmd extends BaseCmd {
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
         UserAccount user = _regionService.updateUser(this);
-        
+
         if (user != null){
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/api/src/org/apache/cloudstack/region/RegionService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/region/RegionService.java b/api/src/org/apache/cloudstack/region/RegionService.java
index ec7876e..8679ca9 100644
--- a/api/src/org/apache/cloudstack/region/RegionService.java
+++ b/api/src/org/apache/cloudstack/region/RegionService.java
@@ -38,41 +38,41 @@ import com.cloud.user.UserAccount;
 
 
 public interface RegionService {
-    /**
-     * Adds a Region to the local Region
-     * @param id
-     * @param name
-     * @param endPoint
-     * @param apiKey
-     * @param secretKey
-     * @return Return added Region object
-     */
-    public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey);
-
-    /**
-     * Update details of the Region with specified Id
-     * @param id
-     * @param name
-     * @param endPoint
-     * @param apiKey
-     * @param secretKey
-     * @return Return updated Region object
-     */
-    public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
-
-    /**
-     * @param id
-     * @return True if region is successfully removed
-     */
-    public boolean removeRegion(int id);
-
-    /** List all Regions or by Id/Name
-     * @param id
-     * @param name
-     * @return List of Regions
-     */
-    public List<? extends Region> listRegions(ListRegionsCmd cmd);
-
+	/**
+	 * Adds a Region to the local Region
+	 * @param id
+	 * @param name
+	 * @param endPoint
+	 * @param apiKey
+	 * @param secretKey
+	 * @return Return added Region object
+	 */
+	public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey);
+	
+	/**
+	 * Update details of the Region with specified Id
+	 * @param id
+	 * @param name
+	 * @param endPoint
+	 * @param apiKey
+	 * @param secretKey
+	 * @return Return updated Region object
+	 */
+	public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
+	
+	/**
+	 * @param id
+	 * @return True if region is successfully removed
+	 */
+	public boolean removeRegion(int id);
+	
+	/** List all Regions or by Id/Name
+	 * @param id
+	 * @param name
+	 * @return List of Regions
+	 */
+	public List<? extends Region> listRegions(ListRegionsCmd cmd);
+	
     /**
      * Deletes a user by userId
      * isPopagate flag is set to true if sent from peer Region
@@ -80,8 +80,8 @@ public interface RegionService {
      *
      * @return true if delete was successful, false otherwise
      */
-    boolean deleteUserAccount(DeleteAccountCmd cmd);
-
+	boolean deleteUserAccount(DeleteAccountCmd cmd);
+	
     /**
      * Updates an account
      * isPopagate falg is set to true if sent from peer Region 
@@ -91,22 +91,22 @@ public interface RegionService {
      * @return updated account object
      */
     Account updateAccount(UpdateAccountCmd cmd);
-
-    /**
-     * Disables an account by accountName and domainId or accountId
-     * @param cmd
-     * @return
-     * @throws ResourceUnavailableException
-     * @throws ConcurrentOperationException
-     */
-    Account disableAccount(DisableAccountCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException;
-
-    /**
-     * Enables an account by accountId
-     * @param cmd
-     * @return
-     */
-    Account enableAccount(EnableAccountCmd cmd);
+	
+	/**
+	 * Disables an account by accountName and domainId or accountId
+	 * @param cmd
+	 * @return
+	 * @throws ResourceUnavailableException 
+	 * @throws ConcurrentOperationException 
+	 */
+	Account disableAccount(DisableAccountCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException;
+	
+	/**
+	 * Enables an account by accountId
+	 * @param cmd
+	 * @return
+	 */
+	Account enableAccount(EnableAccountCmd cmd);
 
     /**
      * Deletes user by Id
@@ -114,7 +114,7 @@ public interface RegionService {
      * @return true if delete was successful, false otherwise
      */
     boolean deleteUser(DeleteUserCmd deleteUserCmd); 	
-
+    
     /**
      * update an existing domain
      * 
@@ -122,36 +122,36 @@ public interface RegionService {
      *            - the command containing domainId and new domainName
      * @return Domain object if the command succeeded
      */
-    public Domain updateDomain(UpdateDomainCmd updateDomainCmd);
-
-    /**
-     * Deletes domain
-     * @param cmd
-     * @return true if delete was successful, false otherwise
-     */
-    public boolean deleteDomain(DeleteDomainCmd cmd);
-
+	public Domain updateDomain(UpdateDomainCmd updateDomainCmd);    
+    
+	/**
+	 * Deletes domain
+	 * @param cmd
+	 * @return true if delete was successful, false otherwise
+	 */
+	public boolean deleteDomain(DeleteDomainCmd cmd);
+	
     /**
      * Update a user by userId
      *
      * @param userId
      * @return UserAccount object
      */
-    public UserAccount updateUser(UpdateUserCmd updateUserCmd);
-
+	public UserAccount updateUser(UpdateUserCmd updateUserCmd);
+	
     /**
      * Disables a user by userId
      *
      * @param cmd
      * @return UserAccount object
      */
-    public UserAccount disableUser(DisableUserCmd cmd);
-
+	public UserAccount disableUser(DisableUserCmd cmd);
+	
     /**
      * Enables a user
      *
      * @param cmd
      * @return UserAccount object
      */
-    public UserAccount enableUser(EnableUserCmd cmd);
+	public UserAccount enableUser(EnableUserCmd cmd);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/core/src/com/cloud/user/AccountVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/user/AccountVO.java b/core/src/com/cloud/user/AccountVO.java
index 3711179..fd37c77 100644
--- a/core/src/com/cloud/user/AccountVO.java
+++ b/core/src/com/cloud/user/AccountVO.java
@@ -68,32 +68,32 @@ public class AccountVO implements Account {
 
     @Column(name="region_id")
     private int regionId;
-
+    
     public AccountVO() {
-        this.uuid = UUID.randomUUID().toString();
+    	this.uuid = UUID.randomUUID().toString();
     }
 
     public AccountVO(long id) {
         this.id = id;
-        this.uuid = UUID.randomUUID().toString();
+    	this.uuid = UUID.randomUUID().toString();
     }
-
-    public AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId) {
+    
+    public AccountVO(String accountName, long domainId, String networkDomain, short type, String uuid, int regionId) {
         this.accountName = accountName;
         this.domainId = domainId;
         this.networkDomain = networkDomain;
         this.type = type;
         this.state = State.enabled;
-        this.uuid = UUID.randomUUID().toString();
+        this.uuid = uuid;
         this.regionId = regionId;
     }
 
     public void setNeedsCleanup(boolean value) {
-        needsCleanup = value;
+    	needsCleanup = value;
     }
 
     public boolean getNeedsCleanup() {
-        return needsCleanup;
+    	return needsCleanup;
     }
 
     @Override
@@ -102,10 +102,10 @@ public class AccountVO implements Account {
     }
 
     public void setId(long id) {
-        this.id = id;
-    }
+		this.id = id;
+	}
 
-    @Override
+	@Override
     public String getAccountName() {
         return accountName;
     }
@@ -134,11 +134,11 @@ public class AccountVO implements Account {
 
     @Override
     public Long getDefaultZoneId() {
-        return defaultZoneId;
+    	return defaultZoneId;
     }
 
     public void setDefaultZoneId(Long defaultZoneId) {
-        this.defaultZoneId = defaultZoneId;
+    	this.defaultZoneId = defaultZoneId;
     }
 
     @Override
@@ -176,14 +176,18 @@ public class AccountVO implements Account {
 
     @Override
     public String getUuid() {
-        return this.uuid;
+    	return this.uuid;
     }
 
     public void setUuid(String uuid) {
-        this.uuid = uuid;
+    	this.uuid = uuid;
     }
 
-    public int getRegionId() {
-        return regionId;
-    }
+	public int getRegionId() {
+		return regionId;
+	}
+
+	public void setRegionId(int regionId) {
+		this.regionId = regionId;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/core/src/com/cloud/user/UserVO.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/user/UserVO.java b/core/src/com/cloud/user/UserVO.java
index 1780db4..de7f31b 100644
--- a/core/src/com/cloud/user/UserVO.java
+++ b/core/src/com/cloud/user/UserVO.java
@@ -95,7 +95,7 @@ public class UserVO implements User, Identity, InternalIdentity {
 
     @Column(name="region_id")
     private int regionId;
-
+    
     public UserVO() {
         this.uuid = UUID.randomUUID().toString();
     }
@@ -104,8 +104,8 @@ public class UserVO implements User, Identity, InternalIdentity {
         this.id = id;
         this.uuid = UUID.randomUUID().toString();
     }
-
-    public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, int regionId) {
+    
+    public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, String uuid, int regionId) {
         this.accountId = accountId;
         this.username = username;
         this.password = password;
@@ -114,10 +114,10 @@ public class UserVO implements User, Identity, InternalIdentity {
         this.email = email;
         this.timezone = timezone;
         this.state = State.enabled;
-        this.uuid = UUID.randomUUID().toString();
-        this.regionId = regionId;
+    	this.uuid = uuid;
+    	this.regionId = regionId;
     }
-
+    
     @Override
     public long getId() {
         return id;
@@ -265,9 +265,12 @@ public class UserVO implements User, Identity, InternalIdentity {
     public void setUuid(String uuid) {
         this.uuid = uuid;
     }
+    
+	public int getRegionId() {
+		return regionId;
+	}
 
-    public int getRegionId() {
-        return regionId;
-    }
-
+	public void setRegionId(int regionId) {
+		this.regionId = regionId;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/com/cloud/projects/ProjectManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/projects/ProjectManagerImpl.java b/server/src/com/cloud/projects/ProjectManagerImpl.java
index 72ed940..45a9a24 100755
--- a/server/src/com/cloud/projects/ProjectManagerImpl.java
+++ b/server/src/com/cloud/projects/ProjectManagerImpl.java
@@ -204,7 +204,7 @@ public class ProjectManagerImpl extends ManagerBase implements ProjectManager {
         StringBuilder acctNm = new StringBuilder("PrjAcct-");
         acctNm.append(name).append("-").append(owner.getDomainId());
 
-        Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null);
+        Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null, "", 0);
 
         Project project = _projectDao.persist(new ProjectVO(name, displayText, owner.getDomainId(), projectAccount.getId()));
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/com/cloud/user/AccountManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManager.java b/server/src/com/cloud/user/AccountManager.java
index ff9f168..4b3a601 100755
--- a/server/src/com/cloud/user/AccountManager.java
+++ b/server/src/com/cloud/user/AccountManager.java
@@ -47,14 +47,14 @@ public interface AccountManager extends AccountService {
     
     boolean deleteAccount(AccountVO account, long callerUserId, Account caller);
 
-    boolean cleanupAccount(AccountVO account, long callerUserId, Account caller);
-
-    Long checkAccessAndSpecifyAuthority(Account caller, Long zoneId);
-
-    Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details);
-
-    UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone);
+	boolean cleanupAccount(AccountVO account, long callerUserId, Account caller);
 
+	Long checkAccessAndSpecifyAuthority(Account caller, Long zoneId);
+	
+	Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details, String uuid, int regionId);
+	
+	UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone);
+	
     /**
      * Logs out a user
      * @param userId

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/com/cloud/user/AccountManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/AccountManagerImpl.java b/server/src/com/cloud/user/AccountManagerImpl.java
index b1f8146..9b91602 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -763,8 +763,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
     @Override
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_CREATE, eventDescription = "creating Account")
-    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) {
+    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) {
 
         if (accountName == null) {
             accountName = userName;
@@ -806,27 +806,26 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
             }
         }
 
+        Transaction txn = Transaction.currentTxn();
+        txn.start();
 
-            Transaction txn = Transaction.currentTxn();
-            txn.start();
-
-            // create account
-            AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details);
-            long accountId = account.getId();
+        // create account
+        AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, UUID.randomUUID().toString(), _regionMgr.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);
-            }
-            txn.commit();
-            //check success
-            return _userAccountDao.findById(user.getId());
+        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();
 
+        //check success
+        return _userAccountDao.findById(user.getId());
     }
 
     @Override
@@ -858,8 +857,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
         if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) {
             throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId);
         }
-
-        return createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
+        UserVO user = null;
+        user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
+        return user;
     }
 
     @Override
@@ -1646,7 +1646,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
 
     @Override
     @DB
-    public AccountVO createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details) {
+    public AccountVO createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details, String uuid, int regionId) {
         // Validate domain
         Domain domain = _domainMgr.getDomain(domainId);
         if (domain == null) {
@@ -1690,7 +1690,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
         Transaction txn = Transaction.currentTxn();
         txn.start();
 
-        AccountVO account = _accountDao.persist(new AccountVO(accountName, domainId, networkDomain, accountType, _accountDao.getRegionId()));
+        AccountVO account = _accountDao.persist(new AccountVO(accountName, domainId, networkDomain, accountType, uuid, regionId));
 
         if (account == null) {
             throw new CloudRuntimeException("Failed to create account name " + accountName + " in domain id=" + domainId);
@@ -1730,7 +1730,30 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
             throw new CloudRuntimeException("Failed to encode password");
         }
 
-        UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, _userDao.getRegionId()));
+        UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, 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 (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");
+        }
+
+        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/a1fdb0c2/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManagerImpl.java b/server/src/com/cloud/user/DomainManagerImpl.java
index d7967d5..9f0ad53 100644
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@ -161,7 +161,6 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
             throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
         }
 
-
         Transaction txn = Transaction.currentTxn();
         txn.start();
 
@@ -471,8 +470,8 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
         // check if domain exists in the system
         DomainVO domain = _domainDao.findById(domainId);
         if (domain == null) {
-        	InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
-        	ex.addProxyObject(domain, domainId, "domainId");            
+            InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find domain with specified domain id");
+            ex.addProxyObject(domain, domainId, "domainId");
             throw ex;
         } else if (domain.getParent() == null && domainName != null) {
             // check if domain is ROOT domain - and deny to edit it with the new name
@@ -494,7 +493,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
             if (!domains.isEmpty() && !sameDomain) {
                 InvalidParameterValueException ex = new InvalidParameterValueException("Failed to update specified domain id with name '" + domainName + "' since it already exists in the system");
                 ex.addProxyObject(domain, domainId, "domainId");                
-            	throw ex;
+                throw ex;
             }
         }
 
@@ -552,5 +551,5 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
             _domainDao.update(dom.getId(), dom);
         }
     }
-    
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/com/cloud/user/dao/AccountDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/dao/AccountDaoImpl.java b/server/src/com/cloud/user/dao/AccountDaoImpl.java
index 3ffc1db..892fdcd 100755
--- a/server/src/com/cloud/user/dao/AccountDaoImpl.java
+++ b/server/src/com/cloud/user/dao/AccountDaoImpl.java
@@ -44,17 +44,17 @@ import com.cloud.utils.db.Transaction;
 public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements AccountDao {
     private static final Logger s_logger = Logger.getLogger(AccountDaoImpl.class);
     private final String FIND_USER_ACCOUNT_BY_API_KEY = "SELECT u.id, u.username, u.account_id, u.secret_key, u.state, " +
-                                                  "a.id, a.account_name, a.type, a.domain_id, a.state " +
-                                                  "FROM `cloud`.`user` u, `cloud`.`account` a " +
-                                                  "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL";
-
+    		                                      "a.id, a.account_name, a.type, a.domain_id, a.state " +
+    		                                      "FROM `cloud`.`user` u, `cloud`.`account` a " +
+    		                                      "WHERE u.account_id = a.id AND u.api_key = ? and u.removed IS NULL";
+    
     protected final SearchBuilder<AccountVO> AllFieldsSearch;
     protected final SearchBuilder<AccountVO> AccountTypeSearch;
     protected final SearchBuilder<AccountVO> DomainAccountsSearch;
     protected final SearchBuilder<AccountVO> CleanupForRemovedAccountsSearch;
     protected final SearchBuilder<AccountVO> CleanupForDisabledAccountsSearch;
     protected final SearchBuilder<AccountVO> NonProjectAccountSearch;
-
+    
     public AccountDaoImpl() {
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("accountName", AllFieldsSearch.entity().getAccountName(), SearchCriteria.Op.EQ);
@@ -62,7 +62,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
         AllFieldsSearch.and("type", AllFieldsSearch.entity().getType(), SearchCriteria.Op.EQ);
         AllFieldsSearch.done();
-
+        
         AccountTypeSearch = createSearchBuilder();
         AccountTypeSearch.and("domainId", AccountTypeSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
         AccountTypeSearch.and("type", AccountTypeSearch.entity().getType(), SearchCriteria.Op.EQ);
@@ -72,19 +72,19 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         DomainAccountsSearch.and("domainId", DomainAccountsSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
         DomainAccountsSearch.and("removed", DomainAccountsSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
         DomainAccountsSearch.done();
-
+        
         CleanupForRemovedAccountsSearch = createSearchBuilder();
         CleanupForRemovedAccountsSearch.and("cleanup", CleanupForRemovedAccountsSearch.entity().getNeedsCleanup(), SearchCriteria.Op.EQ);
         CleanupForRemovedAccountsSearch.and("removed", CleanupForRemovedAccountsSearch.entity().getRemoved(), SearchCriteria.Op.NNULL);
         CleanupForRemovedAccountsSearch.and("domainid", CleanupForRemovedAccountsSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
         CleanupForRemovedAccountsSearch.done();
-
+        
         CleanupForDisabledAccountsSearch = createSearchBuilder();
         CleanupForDisabledAccountsSearch.and("cleanup", CleanupForDisabledAccountsSearch.entity().getNeedsCleanup(), SearchCriteria.Op.EQ);
         CleanupForDisabledAccountsSearch.and("removed", CleanupForDisabledAccountsSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
         CleanupForDisabledAccountsSearch.and("state", CleanupForDisabledAccountsSearch.entity().getState(), SearchCriteria.Op.EQ);
         CleanupForDisabledAccountsSearch.done();
-
+        
         NonProjectAccountSearch = createSearchBuilder();
         NonProjectAccountSearch.and("accountName", NonProjectAccountSearch.entity().getAccountName(), SearchCriteria.Op.EQ);
         NonProjectAccountSearch.and("domainId", NonProjectAccountSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
@@ -92,28 +92,28 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         NonProjectAccountSearch.and("type", NonProjectAccountSearch.entity().getType(), SearchCriteria.Op.NEQ);
         NonProjectAccountSearch.done();
     }
-
+    
     @Override
     public List<AccountVO> findCleanupsForRemovedAccounts(Long domainId) {
-        SearchCriteria<AccountVO> sc = CleanupForRemovedAccountsSearch.create();
-        sc.setParameters("cleanup", true);
-
-        if (domainId != null) {
-            sc.setParameters("domainid", domainId);
-        }
-
-        return searchIncludingRemoved(sc, null, null, false);
+    	SearchCriteria<AccountVO> sc = CleanupForRemovedAccountsSearch.create();
+    	sc.setParameters("cleanup", true);
+    	
+    	if (domainId != null) {
+    	    sc.setParameters("domainid", domainId);
+    	}
+    	
+    	return searchIncludingRemoved(sc, null, null, false);
     }
-
+    
     @Override
     public List<AccountVO> findCleanupsForDisabledAccounts() {
         SearchCriteria<AccountVO> sc = CleanupForDisabledAccountsSearch.create();
         sc.setParameters("cleanup", true);
         sc.setParameters("state", State.disabled);
-
+        
         return listBy(sc);
     }
-
+    
     @Override
     public Pair<User, Account> findUserAccountByApiKey(String apiKey) {
         Transaction txn = Transaction.currentTxn();
@@ -160,7 +160,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         sc.setParameters("state", State.enabled);
         return findOneBy(sc);
     }
-
+    
     @Override
     public Account findEnabledNonProjectAccount(String accountName, Long domainId) {
         SearchCriteria<AccountVO> sc = NonProjectAccountSearch.create("accountName", accountName);
@@ -170,15 +170,15 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         return findOneBy(sc);
     }
 
-    @Override
-    public Account findActiveAccount(String accountName, Long domainId) {
+	@Override
+	public Account findActiveAccount(String accountName, Long domainId) {
         SearchCriteria<AccountVO> sc = AllFieldsSearch.create("accountName", accountName);
         sc.setParameters("domainId", domainId);
         return findOneBy(sc);
     }
-
-    @Override
-    public Account findActiveNonProjectAccount(String accountName, Long domainId) {
+	
+	@Override
+	public Account findActiveNonProjectAccount(String accountName, Long domainId) {
         SearchCriteria<AccountVO> sc = NonProjectAccountSearch.create("accountName", accountName);
         sc.setParameters("domainId", domainId);
         sc.setParameters("type", Account.ACCOUNT_TYPE_PROJECT);
@@ -191,7 +191,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         sc.setParameters("domainId", domainId);
         return findOneIncludingRemovedBy(sc);
     }
-
+    
     @Override
     public Account findNonProjectAccountIncludingRemoved(String accountName, Long domainId) {
         SearchCriteria<AccountVO> sc = NonProjectAccountSearch.create("accountName", accountName);
@@ -199,7 +199,7 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         sc.setParameters("type", Account.ACCOUNT_TYPE_PROJECT);
         return findOneIncludingRemovedBy(sc);
     }
-
+    
     @Override
     public List<AccountVO> listAccounts(String accountName, Long domainId, Filter filter) {
         SearchCriteria<AccountVO> sc = AllFieldsSearch.create("accountName", accountName);
@@ -246,22 +246,22 @@ public class AccountDaoImpl extends GenericDaoBase<AccountVO, Long> implements A
         return listIncludingRemovedBy(sc, filter);
     }
 
-    @Override
-    public List<AccountVO> findActiveAccountsForDomain(Long domain) {
+	@Override
+	public List<AccountVO> findActiveAccountsForDomain(Long domain) {
         SearchCriteria<AccountVO> sc = DomainAccountsSearch.create();
         sc.setParameters("domainId", domain);
-        return listBy(sc);
-    }
-
-    @Override
-    public void markForCleanup(long accountId) {
-        AccountVO account = findByIdIncludingRemoved(accountId);
-        if (!account.getNeedsCleanup()) {
-            account.setNeedsCleanup(true);
-            if (!update(accountId, account)) {
-                s_logger.warn("Failed to mark account id=" + accountId + " for cleanup");
-            }
-        }
-    }
-
+		return listBy(sc);
+	}
+	
+	@Override
+	public void markForCleanup(long accountId) {
+		AccountVO account = findByIdIncludingRemoved(accountId);
+		if (!account.getNeedsCleanup()) {
+			account.setNeedsCleanup(true);
+        	if (!update(accountId, account)) {
+        	    s_logger.warn("Failed to mark account id=" + accountId + " for cleanup");
+        	}
+		}
+	}
+	
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/org/apache/cloudstack/region/RegionManager.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionManager.java b/server/src/org/apache/cloudstack/region/RegionManager.java
index 40fda70..4cbd664 100644
--- a/server/src/org/apache/cloudstack/region/RegionManager.java
+++ b/server/src/org/apache/cloudstack/region/RegionManager.java
@@ -73,4 +73,98 @@ public interface RegionManager {
      * @return List of Regions
      */
     List<RegionVO> listRegions(Integer id, String name);
+
+    /**
+     * Deletes a user by userId and propagates the change to peer Regions
+     *
+     * @param accountId
+     *            - id of the account do delete
+     *
+     * @return true if delete was successful, false otherwise
+     */
+    boolean deleteUserAccount(long accountId);
+
+    /**
+     * Updates an account
+     * isPopagate falg is set to true if sent from peer Region 
+     *
+     * @param cmd
+     *            - the parameter containing accountId or account nameand domainId
+     * @return updated account object
+     */
+    Account updateAccount(UpdateAccountCmd cmd);
+
+    /**
+     * Disables an account by accountName and domainId or accountId
+     * @param accountName
+     * @param domainId
+     * @param id
+     * @param lockRequested
+     * @return
+     * @throws ConcurrentOperationException
+     * @throws ResourceUnavailableException
+     */
+    Account disableAccount(String accountName, Long domainId, Long id, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException;
+
+    /**
+     * Enables an account by accountId
+     *
+     * @param accountName
+     *            - the enableAccount command defining the accountId to be deleted.
+     * @param domainId
+     *            TODO
+     * @param accountId
+     * @return account object
+     */
+    Account enableAccount(String accountName, Long domainId, Long accountId); 	
+
+    /**
+     * Deletes user by Id
+     * @param deleteUserCmd
+     * @return
+     */
+    boolean deleteUser(DeleteUserCmd deleteUserCmd);
+
+    /**
+     * update an existing domain
+     * 
+     * @param cmd
+     *            - the command containing domainId and new domainName
+     * @return Domain object if the command succeeded
+     */
+    Domain updateDomain(UpdateDomainCmd updateDomainCmd);
+
+    /**
+     * Deletes domain by Id
+     * @param id
+     * @param cleanup
+     * @return true if delete was successful, false otherwise
+     */
+    boolean deleteDomain(Long id, Boolean cleanup);
+
+    /**
+     * Update a user by userId
+     *
+     * @param userId
+     * @return UserAccount object
+     */
+    UserAccount updateUser(UpdateUserCmd updateUserCmd);
+
+    /**
+     * Disables a user by userId
+     *
+     * @param userId
+     *            - the userId
+     * @return UserAccount object
+     */	
+    UserAccount disableUser(Long id);
+
+    /**
+     * Enables a user
+     *
+     * @param userId
+     *            - the userId
+     * @return UserAccount object
+     */
+    UserAccount enableUser(long userId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
index c1a0cc5..b4b55fd 100755
--- a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
@@ -16,25 +16,6 @@
 // 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 org.springframework.stereotype.Component;
-
 import com.cloud.domain.Domain;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
@@ -48,12 +29,27 @@ 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.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.uuididentity.dao.IdentityDao;
+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.commons.httpclient.NameValuePair;
+import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 @Component
 @Local(value = { RegionManager.class })
@@ -73,11 +69,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
     @Inject
     private DomainManager _domainMgr;
     @Inject
-    private UserAccountDao _userAccountDao;    
-    @Inject
     private IdentityDao _identityDao;
-    @Inject
-    private RegionSyncDao _regionSyncDao;
 
     private String _name;
     private int _id; 
@@ -198,4 +190,396 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
         }
         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){
+            return _accountMgr.deleteUserAccount(accountId);
+        } 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){
+            return _accountMgr.updateAccount(cmd);
+        } 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);
+            }
+            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){
+            return _accountMgr.enableAccount(accountName, domainId, accountId);
+        } 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){
+            return _accountMgr.deleteUser(cmd);
+        } else {
+            //First delete in the Region where user 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){
+            return _domainMgr.updateDomain(cmd);
+        } 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){
+            return _domainMgr.deleteDomain(id, cleanup);
+        } 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){
+            return _accountMgr.updateUser(cmd);
+        } 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){
+            return _accountMgr.disableUser(userId);
+        } 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){
+            return _accountMgr.enableUser(userId);
+        } 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/a1fdb0c2/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionServiceImpl.java b/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
index 62bf423..0662c32 100755
--- a/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionServiceImpl.java
@@ -16,13 +16,13 @@
 // 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 com.cloud.domain.Domain;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.user.Account;
+import com.cloud.user.UserAccount;
+import com.cloud.utils.component.Manager;
+import com.cloud.utils.component.ManagerBase;
 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;
@@ -34,24 +34,14 @@ 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 org.springframework.stereotype.Component;
 
-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.Manager;
-import com.cloud.utils.component.ManagerBase;
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+import java.util.List;
+import java.util.Map;
 
 @Component
 @Local(value = { RegionService.class })
@@ -59,19 +49,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
     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;
 
@@ -137,7 +115,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public boolean deleteUserAccount(DeleteAccountCmd cmd) {
-        return _accountMgr.deleteUserAccount(cmd.getId());
+        return _regionMgr.deleteUserAccount(cmd.getId());
     }
 
     /**
@@ -145,7 +123,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */
     @Override
     public Account updateAccount(UpdateAccountCmd cmd) {
-        return _accountMgr.updateAccount(cmd);
+        return _regionMgr.updateAccount(cmd);
     }
 
     /**
@@ -153,12 +131,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public Account disableAccount(DisableAccountCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException {
-        Account result = null;
-        if(cmd.getLockRequested())
-            result = _accountMgr.lockAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
-        else
-            result = _accountMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
-        return result;
+        return _regionMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId(), cmd.getLockRequested());
     }
 
     /**
@@ -166,7 +139,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */
     @Override
     public Account enableAccount(EnableAccountCmd cmd) {
-        return _accountMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
+        return _regionMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
     }
 
     /**
@@ -174,7 +147,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public boolean deleteUser(DeleteUserCmd cmd) {
-        return _accountMgr.deleteUser(cmd);
+        return _regionMgr.deleteUser(cmd);
     }
 
     /**
@@ -182,7 +155,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */
     @Override
     public Domain updateDomain(UpdateDomainCmd cmd) {
-        return _domainMgr.updateDomain(cmd);
+        return _regionMgr.updateDomain(cmd);
     }
 
     /**
@@ -190,7 +163,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public boolean deleteDomain(DeleteDomainCmd cmd) {
-        return _domainMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
+        return _regionMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
     }
 
     /**
@@ -198,7 +171,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */
     @Override
     public UserAccount updateUser(UpdateUserCmd cmd){
-        return _accountMgr.updateUser(cmd);
+        return _regionMgr.updateUser(cmd);
     }
 
     /**
@@ -206,7 +179,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public UserAccount disableUser(DisableUserCmd cmd) {
-        return _accountMgr.disableUser(cmd.getId());
+        return _regionMgr.disableUser(cmd.getId());
     }
 
     /**
@@ -214,6 +187,7 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
      */ 
     @Override
     public UserAccount enableUser(EnableUserCmd cmd) {
-        return _accountMgr.enableUser(cmd.getId());
+        return _regionMgr.enableUser(cmd.getId());
     }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a1fdb0c2/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionsApiUtil.java b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
new file mode 100644
index 0000000..2ace4f9
--- /dev/null
+++ b/server/src/org/apache/cloudstack/region/RegionsApiUtil.java
@@ -0,0 +1,306 @@
+// 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.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.log4j.Logger;
+
+import com.cloud.domain.DomainVO;
+import com.cloud.user.UserAccount;
+import com.cloud.user.UserAccountVO;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.io.xml.DomDriver;
+
+/**
+ * Utility class for making API calls between peer Regions
+ *
+ */
+public class RegionsApiUtil {
+    public static final Logger s_logger = Logger.getLogger(RegionsApiUtil.class);
+
+    /**
+     * Makes an api call using region service end_point, api command and params
+     * @param region
+     * @param command
+     * @param params
+     * @return True, if api is successful
+     */
+    protected static boolean makeAPICall(Region region, String command, List<NameValuePair> params){
+        try {
+            String apiParams = buildParams(command, params);
+            String url = buildUrl(apiParams, region);
+            HttpClient client = new HttpClient();
+            HttpMethod method = new GetMethod(url);
+            if( client.executeMethod(method) == 200){
+                return true;
+            } else {
+                return false;
+            }
+        } catch (HttpException e) {
+            s_logger.error(e.getMessage());
+            return false;
+        } catch (IOException e) {
+            s_logger.error(e.getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * Makes an api call using region service end_point, api command and params
+     * Returns Account object on success
+     * @param region
+     * @param command
+     * @param params
+     * @return
+     */
+    protected static RegionAccount makeAccountAPICall(Region region, String command, List<NameValuePair> params){
+        try {
+            String url = buildUrl(buildParams(command, params), region);
+            HttpClient client = new HttpClient();
+            HttpMethod method = new GetMethod(url);
+            if( client.executeMethod(method) == 200){
+                InputStream is = method.getResponseBodyAsStream();
+                //Translate response to Account object
+                XStream xstream = new XStream(new DomDriver());
+                xstream.alias("account", RegionAccount.class);
+                xstream.alias("user", RegionUser.class);
+                xstream.aliasField("id", RegionAccount.class, "uuid");
+                xstream.aliasField("name", RegionAccount.class, "accountName");
+                xstream.aliasField("accounttype", RegionAccount.class, "type");
+                xstream.aliasField("domainid", RegionAccount.class, "domainUuid");
+                xstream.aliasField("networkdomain", RegionAccount.class, "networkDomain");
+                xstream.aliasField("id", RegionUser.class, "uuid");
+                xstream.aliasField("accountId", RegionUser.class, "accountUuid");
+                ObjectInputStream in = xstream.createObjectInputStream(is);
+                return (RegionAccount)in.readObject();
+            } else {
+                return null;
+            }
+        } catch (HttpException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (IOException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (ClassNotFoundException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * Makes an api call using region service end_point, api command and params
+     * Returns Domain object on success
+     * @param region
+     * @param command
+     * @param params
+     * @return
+     */
+    protected static RegionDomain makeDomainAPICall(Region region, String command, List<NameValuePair> params){
+        try {
+            String url = buildUrl(buildParams(command, params), region);
+            HttpClient client = new HttpClient();
+            HttpMethod method = new GetMethod(url);
+            if( client.executeMethod(method) == 200){
+                InputStream is = method.getResponseBodyAsStream();
+                XStream xstream = new XStream(new DomDriver());
+                //Translate response to Domain object
+                xstream.alias("domain", RegionDomain.class);
+                xstream.aliasField("id", RegionDomain.class, "uuid");
+                xstream.aliasField("parentdomainid", RegionDomain.class, "parentUuid");
+                xstream.aliasField("networkdomain", DomainVO.class, "networkDomain");
+                ObjectInputStream in = xstream.createObjectInputStream(is);
+                return (RegionDomain)in.readObject();
+            } else {
+                return null;
+            }
+        } catch (HttpException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (IOException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (ClassNotFoundException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * Makes an api call using region service end_point, api command and params
+     * Returns UserAccount object on success
+     * @param region
+     * @param command
+     * @param params
+     * @return
+     */
+    protected static UserAccount makeUserAccountAPICall(Region region, String command, List<NameValuePair> params){
+        try {
+            String url = buildUrl(buildParams(command, params), region);
+            HttpClient client = new HttpClient();
+            HttpMethod method = new GetMethod(url);
+            if( client.executeMethod(method) == 200){
+                InputStream is = method.getResponseBodyAsStream();
+                XStream xstream = new XStream(new DomDriver());
+                xstream.alias("useraccount", UserAccountVO.class);
+                xstream.aliasField("id", UserAccountVO.class, "uuid");
+                ObjectInputStream in = xstream.createObjectInputStream(is);
+                return (UserAccountVO)in.readObject();
+            } else {
+                return null;
+            }
+        } catch (HttpException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (IOException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        } catch (ClassNotFoundException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * Builds parameters string with command and encoded param values
+     * @param command
+     * @param params
+     * @return
+     */
+    protected static String buildParams(String command, List<NameValuePair> params) {
+        StringBuffer paramString = new StringBuffer("command="+command);
+        Iterator<NameValuePair> iter = params.iterator();
+        try {
+            while(iter.hasNext()){
+                NameValuePair param = iter.next();
+                if(param.getValue() != null && !(param.getValue().isEmpty())){
+                    paramString.append("&"+param.getName()+"="+URLEncoder.encode(param.getValue(), "UTF-8"));
+                }
+            }
+        }
+        catch (UnsupportedEncodingException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        }
+        return paramString.toString();
+    }
+
+    /**
+     * Build URL for api call using region end_point
+     * Parameters are sorted and signed using secret_key
+     * @param apiParams
+     * @param region
+     * @return
+     */
+    private static String buildUrl(String apiParams, Region region) {
+
+        String apiKey = region.getApiKey();
+        String secretKey = region.getSecretKey();
+
+
+        if (apiKey == null || secretKey == null) {
+            return region.getEndPoint() +"?"+ apiParams;
+        }
+
+        String encodedApiKey;
+        try {
+            encodedApiKey = URLEncoder.encode(apiKey, "UTF-8");
+
+            List<String> sortedParams = new ArrayList<String>();
+            sortedParams.add("apikey=" + encodedApiKey.toLowerCase());
+            StringTokenizer st = new StringTokenizer(apiParams, "&");
+            String url = null;
+            boolean first = true;
+            while (st.hasMoreTokens()) {
+                String paramValue = st.nextToken();
+                String param = paramValue.substring(0, paramValue.indexOf("="));
+                String value = paramValue.substring(paramValue.indexOf("=") + 1, paramValue.length());
+                if (first) {
+                    url = param + "=" + value;
+                    first = false;
+                } else {
+                    url = url + "&" + param + "=" + value;
+                }
+                sortedParams.add(param.toLowerCase() + "=" + value.toLowerCase());
+            }
+            Collections.sort(sortedParams);
+
+
+            //Construct the sorted URL and sign and URL encode the sorted URL with your secret key
+            String sortedUrl = null;
+            first = true;
+            for (String param : sortedParams) {
+                if (first) {
+                    sortedUrl = param;
+                    first = false;
+                } else {
+                    sortedUrl = sortedUrl + "&" + param;
+                }
+            }
+            String encodedSignature = signRequest(sortedUrl, secretKey);
+
+            String finalUrl = region.getEndPoint() +"?"+apiParams+ "&apiKey=" + apiKey + "&signature=" + encodedSignature;
+
+            return finalUrl;
+
+        } catch (UnsupportedEncodingException e) {
+            s_logger.error(e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * 1. Signs a string with a secret key using SHA-1 2. Base64 encode the result 3. URL encode the final result
+     *
+     * @param request
+     * @param key
+     * @return
+     */
+    private static String signRequest(String request, String key) {
+        try {
+            Mac mac = Mac.getInstance("HmacSHA1");
+            SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
+            mac.init(keySpec);
+            mac.update(request.getBytes());
+            byte[] encryptedBytes = mac.doFinal();
+            return URLEncoder.encode(Base64.encodeBase64String(encryptedBytes), "UTF-8");
+        } catch (Exception ex) {
+            s_logger.error(ex.getMessage());
+            return null;
+        }
+    }
+
+}
\ No newline at end of file


Mime
View raw message