incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject [4/60] [abbrv] git commit: Propogate Domain and User commands
Date Thu, 27 Sep 2012 12:23:45 GMT
Propogate Domain and User commands


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

Branch: refs/heads/regions
Commit: 39d394a8e807710d92da3995b32bcfa0b41078dd
Parents: 4ea36b8
Author: Kishan Kavala <kishan@cloud.com>
Authored: Thu Sep 27 16:44:12 2012 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Thu Sep 27 16:44:12 2012 +0530

----------------------------------------------------------------------
 .../com/cloud/api/commands/CreateAccountCmd.java   |    8 -
 .../com/cloud/api/commands/CreateDomainCmd.java    |   19 +-
 api/src/com/cloud/api/commands/CreateUserCmd.java  |   17 +-
 .../com/cloud/api/commands/DeleteDomainCmd.java    |   15 +-
 api/src/com/cloud/api/commands/DeleteUserCmd.java  |   15 +-
 .../com/cloud/api/commands/DisableAccountCmd.java  |    5 +-
 api/src/com/cloud/api/commands/DisableUserCmd.java |   17 +-
 api/src/com/cloud/api/commands/EnableUserCmd.java  |   18 +-
 .../com/cloud/api/commands/UpdateDomainCmd.java    |   18 +-
 api/src/com/cloud/api/commands/UpdateUserCmd.java  |   17 +-
 api/src/com/cloud/domain/Domain.java               |    2 +
 api/src/com/cloud/region/RegionService.java        |   16 +-
 api/src/com/cloud/user/AccountService.java         |    2 +-
 api/src/com/cloud/user/DomainService.java          |    2 +-
 server/src/com/cloud/domain/DomainVO.java          |   19 +-
 server/src/com/cloud/region/RegionManager.java     |   10 +-
 server/src/com/cloud/region/RegionManagerImpl.java |  627 +++++++++++++--
 server/src/com/cloud/user/AccountManagerImpl.java  |   16 +-
 server/src/com/cloud/user/DomainManager.java       |    2 +-
 server/src/com/cloud/user/DomainManagerImpl.java   |   35 +-
 20 files changed, 767 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/CreateAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateAccountCmd.java b/api/src/com/cloud/api/commands/CreateAccountCmd.java
index 9fc7d2d..21a51a6 100755
--- a/api/src/com/cloud/api/commands/CreateAccountCmd.java
+++ b/api/src/com/cloud/api/commands/CreateAccountCmd.java
@@ -144,14 +144,6 @@ public class CreateAccountCmd extends BaseCmd {
     	return params;
     }
 
-    /*public Map<String, String> getRegionDetails() {
-    	if (regionDetails == null || regionDetails.isEmpty()) {
-    		return null;
-    	}
-    	
-		return regionDetails;
-	}*/
-    
     public String getAccountUUID() {
 		return accountUUID;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/CreateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateDomainCmd.java b/api/src/com/cloud/api/commands/CreateDomainCmd.java
index 92ee7ec..29fd050 100644
--- a/api/src/com/cloud/api/commands/CreateDomainCmd.java
+++ b/api/src/com/cloud/api/commands/CreateDomainCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.DomainResponse;
 import com.cloud.domain.Domain;
 import com.cloud.user.Account;
@@ -49,6 +50,12 @@ public class CreateDomainCmd extends BaseCmd {
     @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for networks in the domain")
     private String networkDomain;
 
+    @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.STRING, description="Domain UUID, required for adding domain from another Region")
+    private String domainUUID;
+    
+    @Parameter(name=ApiConstants.REGION_ID, type=CommandType.LONG, description="Id of the Region creating the Domain")
+    private Long regionId;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -63,8 +70,16 @@ public class CreateDomainCmd extends BaseCmd {
 
     public String getNetworkDomain() {
         return networkDomain;
-    }  
+    }
 
+    public String getDomainUUID() {
+        return domainUUID;
+    }
+    
+	public Long getRegionId() {
+		return regionId;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -82,7 +97,7 @@ public class CreateDomainCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
-        Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
+        Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID(), getRegionId());
         if (domain != null) {
             DomainResponse response = _responseGenerator.createDomainResponse(domain);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/CreateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateUserCmd.java b/api/src/com/cloud/api/commands/CreateUserCmd.java
index fc10437..66a27f0 100644
--- a/api/src/com/cloud/api/commands/CreateUserCmd.java
+++ b/api/src/com/cloud/api/commands/CreateUserCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.UserResponse;
 import com.cloud.user.Account;
 import com.cloud.user.User;
@@ -64,6 +65,12 @@ public class CreateUserCmd extends BaseCmd {
     @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required=true, description="Unique username.")
     private String username;
 
+    @Parameter(name=ApiConstants.USER_ID, type=CommandType.STRING, description="User UUID, required for adding account from another Region")
+    private String userUUID;
+    
+    @Parameter(name=ApiConstants.REGION_ID, type=CommandType.LONG, description="Id of the Region creating the User")
+    private Long regionId;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -100,6 +107,14 @@ public class CreateUserCmd extends BaseCmd {
         return username;
     }
 
+	public String getUserUUID() {
+		return userUUID;
+	}
+    
+	public Long getRegionId() {
+		return regionId;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -131,7 +146,7 @@ public class CreateUserCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("UserName: "+getUserName()+", FirstName :"+getFirstName()+", LastName: "+getLastName());
-        User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
+        User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId(), getUserUUID(), getRegionId());
         if (user != null) {
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/DeleteDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteDomainCmd.java b/api/src/com/cloud/api/commands/DeleteDomainCmd.java
index 3908256..5e371f7 100644
--- a/api/src/com/cloud/api/commands/DeleteDomainCmd.java
+++ b/api/src/com/cloud/api/commands/DeleteDomainCmd.java
@@ -25,6 +25,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.SuccessResponse;
 import com.cloud.domain.Domain;
 import com.cloud.event.EventTypes;
@@ -47,6 +48,8 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
     @Parameter(name=ApiConstants.CLEANUP, type=CommandType.BOOLEAN, description="true if all domain resources (child domains, accounts) have to be cleaned up, false otherwise")
     private Boolean cleanup;
 
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
@@ -60,6 +63,10 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
         return cleanup;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -92,7 +99,13 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Domain Id: "+getId());
-        boolean result = _domainService.deleteDomain(id, cleanup);
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false; 
+        boolean result = false;
+        if(isPopagate){
+        	result = _domainService.deleteDomain(id, cleanup);
+        } else {
+        	result = _regionService.deleteDomain(id, cleanup);
+        }
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());
             this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/DeleteUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DeleteUserCmd.java b/api/src/com/cloud/api/commands/DeleteUserCmd.java
index e436495..846e03c 100644
--- a/api/src/com/cloud/api/commands/DeleteUserCmd.java
+++ b/api/src/com/cloud/api/commands/DeleteUserCmd.java
@@ -43,6 +43,9 @@ public class DeleteUserCmd extends BaseCmd {
     @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Deletes a user")
     private Long id;
 
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -51,6 +54,10 @@ public class DeleteUserCmd extends BaseCmd {
         return id;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -73,7 +80,13 @@ public class DeleteUserCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
-        boolean result = _accountService.deleteUser(this);
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
+        boolean result = false;
+        if(isPopagate){
+        	result = _accountService.deleteUser(this);
+        } else {
+        	result = _regionService.deleteUser(this);
+        }
         if (result) {
             SuccessResponse response = new SuccessResponse(getCommandName());
             this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/DisableAccountCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DisableAccountCmd.java b/api/src/com/cloud/api/commands/DisableAccountCmd.java
index ba22166..572c509 100644
--- a/api/src/com/cloud/api/commands/DisableAccountCmd.java
+++ b/api/src/com/cloud/api/commands/DisableAccountCmd.java
@@ -124,10 +124,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
     		else
     			result = _accountService.disableAccount(getAccountName(), getDomainId(), getId());
     	} else {
-    		if(lockRequested)
-    			result = _regionService.lockAccount(getAccountName(), getDomainId(), getId());
-    		else
-    			result = _regionService.disableAccount(getAccountName(), getDomainId(), getId());
+    		result = _regionService.disableAccount(getAccountName(), getDomainId(), getId(), lockRequested);
     	}
         if (result != null){
             AccountResponse response = _responseGenerator.createAccountResponse(result);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/DisableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DisableUserCmd.java b/api/src/com/cloud/api/commands/DisableUserCmd.java
index 407042d..d068a4c 100644
--- a/api/src/com/cloud/api/commands/DisableUserCmd.java
+++ b/api/src/com/cloud/api/commands/DisableUserCmd.java
@@ -25,6 +25,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.UserResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.event.EventTypes;
@@ -46,6 +47,9 @@ public class DisableUserCmd extends BaseAsyncCmd {
     @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Disables user by user ID.")
     private Long id;
 
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -54,6 +58,10 @@ public class DisableUserCmd extends BaseAsyncCmd {
         return id;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -87,7 +95,14 @@ public class DisableUserCmd extends BaseAsyncCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
-        UserAccount user = _accountService.disableUser(getId());
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
+        UserAccount user = null;
+    	if(isPopagate){
+    		user = _accountService.disableUser(getId());
+        } else {
+        	user = _regionService.disableUser(getId());
+        }
+        
         if (user != null){
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName()); 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/EnableUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/EnableUserCmd.java b/api/src/com/cloud/api/commands/EnableUserCmd.java
index 914d59b..0b8d950 100644
--- a/api/src/com/cloud/api/commands/EnableUserCmd.java
+++ b/api/src/com/cloud/api/commands/EnableUserCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.UserResponse;
 import com.cloud.user.Account;
 import com.cloud.user.User;
@@ -43,7 +44,9 @@ public class EnableUserCmd extends BaseCmd {
     @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Enables user by user ID.")
     private Long id;
 
-
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -52,6 +55,10 @@ public class EnableUserCmd extends BaseCmd {
         return id;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -74,7 +81,14 @@ public class EnableUserCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
-        UserAccount user = _accountService.enableUser(getId());
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
+        UserAccount user = null;
+    	if(isPopagate){
+    		user = _accountService.enableUser(getId());
+        } else {
+        	user = _regionService.enableUser(getId());
+        }
+        
         if (user != null){
             UserResponse response = _responseGenerator.createUserResponse(user);
             response.setResponseName(getCommandName());   

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/api/commands/UpdateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateDomainCmd.java b/api/src/com/cloud/api/commands/UpdateDomainCmd.java
index 739ae87..20a0664 100644
--- a/api/src/com/cloud/api/commands/UpdateDomainCmd.java
+++ b/api/src/com/cloud/api/commands/UpdateDomainCmd.java
@@ -24,9 +24,11 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.DomainResponse;
 import com.cloud.domain.Domain;
 import com.cloud.user.Account;
+import com.cloud.user.UserAccount;
 import com.cloud.user.UserContext;
 
 @Implementation(description="Updates a domain with a new name", responseObject=DomainResponse.class)
@@ -48,6 +50,9 @@ public class UpdateDomainCmd extends BaseCmd {
     @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for the domain's networks; empty string will update domainName with NULL value")
     private String networkDomain;
 
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -64,6 +69,10 @@ public class UpdateDomainCmd extends BaseCmd {
         return networkDomain;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -81,7 +90,14 @@ public class UpdateDomainCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("Domain Id: "+getId());
-        Domain domain = _mgr.updateDomain(this);
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
+        Domain domain = null;
+    	if(isPopagate){
+    		domain = _mgr.updateDomain(this);
+        } else {
+        	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/39d394a8/api/src/com/cloud/api/commands/UpdateUserCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateUserCmd.java b/api/src/com/cloud/api/commands/UpdateUserCmd.java
index 634b5d6..14d383d 100644
--- a/api/src/com/cloud/api/commands/UpdateUserCmd.java
+++ b/api/src/com/cloud/api/commands/UpdateUserCmd.java
@@ -24,6 +24,7 @@ import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
 import com.cloud.api.ServerApiException;
+import com.cloud.api.BaseCmd.CommandType;
 import com.cloud.api.response.UserResponse;
 import com.cloud.user.Account;
 import com.cloud.user.User;
@@ -68,6 +69,9 @@ public class UpdateUserCmd extends BaseCmd {
     @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, description="Unique username")
     private String username;
 
+    @Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
+    private Boolean isPropagate;
+    
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -108,6 +112,10 @@ public class UpdateUserCmd extends BaseCmd {
         return username;
     }
 
+	public Boolean getIsPropagate() {
+		return isPropagate;
+	}
+    
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -130,7 +138,14 @@ public class UpdateUserCmd extends BaseCmd {
     @Override
     public void execute(){
         UserContext.current().setEventDetails("UserId: "+getId());
-        UserAccount user = _accountService.updateUser(this);
+        boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
+        UserAccount user = null;
+    	if(isPopagate){
+    		user = _accountService.updateUser(this);
+        } else {
+        	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/39d394a8/api/src/com/cloud/domain/Domain.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/domain/Domain.java b/api/src/com/cloud/domain/Domain.java
index a7b4031..5986347 100644
--- a/api/src/com/cloud/domain/Domain.java
+++ b/api/src/com/cloud/domain/Domain.java
@@ -57,4 +57,6 @@ public interface Domain extends OwnedBy {
     void setState(State state);
 
     String getNetworkDomain();
+    
+    public String getUuid();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/region/RegionService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/region/RegionService.java b/api/src/com/cloud/region/RegionService.java
index f9cfeba..8fa5058 100644
--- a/api/src/com/cloud/region/RegionService.java
+++ b/api/src/com/cloud/region/RegionService.java
@@ -18,9 +18,16 @@ package com.cloud.region;
 
 import java.util.List;
 
+import com.cloud.api.commands.DeleteUserCmd;
 import com.cloud.api.commands.ListRegionsCmd;
 import com.cloud.api.commands.UpdateAccountCmd;
+import com.cloud.api.commands.UpdateDomainCmd;
+import com.cloud.api.commands.UpdateUserCmd;
+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;
 
 
 public interface RegionService {
@@ -30,7 +37,12 @@ public interface RegionService {
 	public List<? extends Region> listRegions(ListRegionsCmd cmd);
 	boolean deleteUserAccount(long accountId);
 	Account updateAccount(UpdateAccountCmd cmd);
-	public Account lockAccount(String accountName, Long domainId, Long id);
-	public Account disableAccount(String accountName, Long domainId, Long id);
+	public Account disableAccount(String accountName, Long domainId, Long id, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException;
 	public Account enableAccount(String accountName, Long domainId, Long id);
+	public boolean deleteUser(DeleteUserCmd deleteUserCmd);
+	public boolean deleteDomain(Long id, Boolean cleanup);
+	public UserAccount updateUser(UpdateUserCmd updateUserCmd);
+	public Domain updateDomain(UpdateDomainCmd updateDomainCmd);
+	public UserAccount disableUser(Long id);
+	public UserAccount enableUser(Long id);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/user/AccountService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/AccountService.java b/api/src/com/cloud/user/AccountService.java
index 0cb36d4..15a1a5a 100755
--- a/api/src/com/cloud/user/AccountService.java
+++ b/api/src/com/cloud/user/AccountService.java
@@ -163,7 +163,7 @@ public interface AccountService {
 
     User getSystemUser();
 
-    User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId);
+    User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID, Long regionId);
 
     boolean deleteUser(DeleteUserCmd deleteUserCmd);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/api/src/com/cloud/user/DomainService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/user/DomainService.java b/api/src/com/cloud/user/DomainService.java
index 362f87e..4de14d1 100644
--- a/api/src/com/cloud/user/DomainService.java
+++ b/api/src/com/cloud/user/DomainService.java
@@ -25,7 +25,7 @@ import com.cloud.exception.PermissionDeniedException;
 
 public interface DomainService {
 
-    Domain createDomain(String name, Long parentId, String networkDomain);
+    Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID, Long regionId);
 
     Domain getDomain(long id);
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/server/src/com/cloud/domain/DomainVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/domain/DomainVO.java b/server/src/com/cloud/domain/DomainVO.java
index a5cfe1b..52b10a7 100644
--- a/server/src/com/cloud/domain/DomainVO.java
+++ b/server/src/com/cloud/domain/DomainVO.java
@@ -75,13 +75,19 @@ public class DomainVO implements Domain, Identity {
     
     public DomainVO() {}
     
-    public DomainVO(long id, String name, long owner, Long parentId, String networkDomain) {
-        this(name, owner, parentId, networkDomain);
-        this.id = id;
+    public DomainVO(String name, long owner, Long parentId, String networkDomain, Long regionId) {
+    	this.parent = parentId;
+        this.name = name;
+        this.accountId = owner;
+        this.path ="";
+        this.level = 0;
+        this.state = Domain.State.Active;
+        this.networkDomain = networkDomain;
         this.uuid = UUID.randomUUID().toString();
+        this.regionId = regionId;
     }
 
-    public DomainVO(String name, long owner, Long parentId, String networkDomain) {
+    public DomainVO(String name, long owner, Long parentId, String networkDomain, String uuid, Long regionId) {
     	this.parent = parentId;
         this.name = name;
         this.accountId = owner;
@@ -89,9 +95,10 @@ public class DomainVO implements Domain, Identity {
         this.level = 0;
         this.state = Domain.State.Active;
         this.networkDomain = networkDomain;
-        this.uuid = UUID.randomUUID().toString();
+        this.uuid = uuid;
+        this.regionId = regionId;
     }
-
+    
     @Override
     public long getId() {
         return id;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/server/src/com/cloud/region/RegionManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/RegionManager.java b/server/src/com/cloud/region/RegionManager.java
index 65b5cd6..d74633d 100644
--- a/server/src/com/cloud/region/RegionManager.java
+++ b/server/src/com/cloud/region/RegionManager.java
@@ -21,11 +21,11 @@ import java.util.Map;
 
 public interface RegionManager {
 	public boolean propogateAddAccount(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, long regionId);
-	public boolean addResource();
-	public boolean updateResource();
-	public boolean deleteResource();
-	
+            Map<String, String> details, String accountUUID, String userUUID);
 	public long getId();
 	public void setId(long id);
+	public void propogateAddUser(String userName, String password,
+			String firstName, String lastName, String email, String timeZone,
+			String accountName, String domainUUId, String userUUID);
+	public void propogateAddDomain(String name, Long parentId, String networkDomain, String uuid);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/server/src/com/cloud/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/region/RegionManagerImpl.java b/server/src/com/cloud/region/RegionManagerImpl.java
index 804c146..96ff28e 100755
--- a/server/src/com/cloud/region/RegionManagerImpl.java
+++ b/server/src/com/cloud/region/RegionManagerImpl.java
@@ -30,17 +30,30 @@ import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.log4j.Logger;
 
+import com.cloud.api.ApiConstants;
+import com.cloud.api.commands.DeleteUserCmd;
 import com.cloud.api.commands.ListRegionsCmd;
 import com.cloud.api.commands.UpdateAccountCmd;
+import com.cloud.api.commands.UpdateDomainCmd;
+import com.cloud.api.commands.UpdateUserCmd;
+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.region.dao.RegionDao;
+import com.cloud.server.ManagementServer;
 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.UserDao;
 import com.cloud.utils.component.Inject;
 import com.cloud.utils.component.Manager;
-import com.cloud.utils.exception.CloudRuntimeException;
 
 @Local(value = { RegionManager.class, RegionService.class })
 public class RegionManagerImpl implements RegionManager, RegionService, Manager{
@@ -52,10 +65,22 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
     private AccountDao _accountDao;
     @Inject
     private AccountManager _accountMgr;
+    @Inject
+    private UserDao _userDao;
+    @Inject
+    private DomainDao _domainDao;
+    @Inject
+    private ManagementServer _mgmtSrvr;
+    @Inject
+    private DomainManager _domainMgr;
+    
     
     private String _name;
     private long _id = 1; //ToDo, get this from config or db.properties
     
+    //ToDo use API constants
+    //prepare API params in advance
+    
     @Override
     public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
         _name = name;
@@ -79,33 +104,33 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 
 	@Override
 	public boolean propogateAddAccount(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, long regionId) {
+			String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
 		List<RegionVO> regions =  _regionDao.listAll();
 		StringBuffer params = new StringBuffer("/api?command=createAccount");
-		params.append("&username="+userName);
-		params.append("&password="+password);
-		params.append("&firstname="+firstName);
-		params.append("&lastname="+lastName);
-		params.append("&email="+email);
+		params.append("&"+ApiConstants.USERNAME+"="+userName);
+		params.append("&"+ApiConstants.PASSWORD+"="+password);
+		params.append("&"+ApiConstants.FIRSTNAME+"="+firstName);
+		params.append("&"+ApiConstants.LASTNAME+"="+lastName);
+		params.append("&"+ApiConstants.EMAIL+"="+email);
 		if(timezone != null){
-			params.append("&timezone="+timezone);		
+			params.append("&"+ApiConstants.TIMEZONE+"="+timezone);		
 		}
 		if(accountName != null){
-			params.append("&account="+accountName);			
+			params.append("&"+ApiConstants.ACCOUNT+"="+accountName);			
 		}
-		params.append("&accounttype="+accountType);
+		params.append("&"+ApiConstants.ACCOUNT_TYPE+"="+accountType);
 		if(domainId != null){
-			params.append("&domainid="+domainId); //use UUID			
+			params.append("&"+ApiConstants.DOMAIN_ID+"="+domainId); //use UUID			
 		}
 		if(networkDomain != null){
-			params.append("&networkdomain="+networkDomain);			
+			params.append("&"+ApiConstants.NETWORK_DOMAIN+"="+networkDomain);			
 		}
 		if(details != null){
-			params.append("&accountdetails="+details); //ToDo change to Map
+			params.append("&"+ApiConstants.ACCOUNT_DETAILS+"="+details); //ToDo change to Map
 		}
-		params.append("&accountid="+accountUUID);
-		params.append("&userid="+userUUID);
-		params.append("&regionid="+regionId);
+		params.append("&"+ApiConstants.ACCOUNT_ID+"="+accountUUID);
+		params.append("&"+ApiConstants.USER_ID+"="+userUUID);
+		params.append("&"+ApiConstants.REGION_ID+"="+getId());
 		
 		for (Region region : regions){
 			if(region.getId() == getId()){
@@ -127,10 +152,12 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 	@Override
 	public boolean deleteUserAccount(long accountId) {
 		AccountVO account = _accountDao.findById(accountId);
-		//Check null account
+		if(account == null){
+			return false;
+		}
 		String accountUUID = account.getUuid();
 		long regionId = account.getRegionId();
-		String params = "/api?command=deleteAccount&id="+accountUUID+"&ispropagate=true";
+		String params = "/api?command=deleteAccount&"+ApiConstants.ID+"="+accountUUID;
 		if(getId() == regionId){
 			if(_accountMgr.deleteUserAccount(accountId)){
 				List<RegionVO> regions =  _regionDao.listAll();
@@ -138,11 +165,11 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 					if(region.getId() == getId()){
 						continue;
 					}
-					String url = region.getEndPoint() + params;
+					String url = region.getEndPoint() + params+"&"+ApiConstants.IS_PROPAGATE+"=true";
 					if (makeAPICall(url)) {
 						s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
 					} else {
-						s_logger.error("Error while deleted account :"+accountUUID+" in Region: "+region.getId());
+						s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
 					}
 				}
 				return true;
@@ -151,14 +178,13 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 			}
 		} else {
 			//First delete in the Region where account is created
-			params = "/api?command=deleteAccount&id="+accountUUID;
 			Region region = _regionDao.findById(regionId);
 			String url = region.getEndPoint() + params;
 			if (makeAPICall(url)) {
 				s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
 				return true;
 			} else {
-				s_logger.error("Error while deleted account :"+accountUUID+" in Region: "+region.getId());
+				s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
 				return false;
 			}
 		}
@@ -168,45 +194,71 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 	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();
         Map<String, String> details = cmd.getDetails();
         
-        AccountVO account = _accountDao.findById(accountId);
-		//Check null account
-		String accountUUID = account.getUuid();
+        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);
+        }
+        
+        StringBuffer params = new StringBuffer("/api?command=updateAccount");
+        params.append("&"+ApiConstants.NEW_NAME+"="+newAccountName);
+        if(account != null){
+        	params.append("&"+ApiConstants.ID+"="+account.getUuid());
+        }
+        if(accountName != null){
+        	params.append("&"+ApiConstants.ACCOUNT+"="+accountName);
+        }
+        if(domain != null){
+        	params.append("&"+ApiConstants.DOMAIN_ID+"="+domain.getUuid());
+        }
+        if(networkDomain != null){
+        	params.append("&"+ApiConstants.NETWORK_DOMAIN+"="+networkDomain);
+        }
+        if(details != null){
+        	params.append("&"+ApiConstants.ACCOUNT_DETAILS+"="+details);
+        }
+        
 		long regionId = account.getRegionId();
 		if(getId() == regionId){
 			Account updateAccount = _accountMgr.updateAccount(cmd);
 			if(updateAccount != null){
 				List<RegionVO> regions =  _regionDao.listAll();
-				StringBuffer params = new StringBuffer("/api?command=updateAccount"+"&ispropagate=true");
 				for (Region region : regions){
 					if(region.getId() == getId()){
 						continue;
 					}
-					String url = region.getEndPoint() + params;
+					String url = region.getEndPoint() + params+"&"+ApiConstants.IS_PROPAGATE+"=true";
 					if (makeAPICall(url)) {
-						s_logger.debug("Successfully updated account :"+accountUUID+" in Region: "+region.getId());
+						s_logger.debug("Successfully updated account :"+account.getUuid()+" in Region: "+region.getId());
 					} else {
-						s_logger.error("Error while updated account :"+accountUUID+" in Region: "+region.getId());
+						s_logger.error("Error while updating account :"+account.getUuid()+" in Region: "+region.getId());
 					}
 				}
 			}
 			return updateAccount;
 		} else {
 			//First update in the Region where account is created
-			StringBuffer params = new StringBuffer("/api?command=updateAccount");
-			//add params
 			Region region = _regionDao.findById(regionId);
 			String url = region.getEndPoint() + params;
 			if (makeAPICall(url)) {
-				s_logger.debug("Successfully updated account :"+accountUUID+" in source Region: "+region.getId());
+				s_logger.debug("Successfully updated account :"+account.getUuid()+" in source Region: "+region.getId());
 				//return Account object
 				return null;
 			} else {
-				s_logger.error("Error while updated account :"+accountUUID+" in source Region: "+region.getId());
+				s_logger.error("Error while updating account :"+account.getUuid()+" in source Region: "+region.getId());
 				//throw exception;
 				return null;
 			}
@@ -234,24 +286,6 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 	}
 	
 	@Override
-	public boolean addResource() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean updateResource() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
-	public boolean deleteResource() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	@Override
 	public Region addRegion(long id, String name, String endPoint) {
 		RegionVO region = new RegionVO(id, name, endPoint);
 		return _regionDao.persist(region);
@@ -301,21 +335,494 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
 	}
 
 	@Override
-	public Account lockAccount(String accountName, Long domainId, Long id) {
-		// TODO Auto-generated method stub
-		return null;
+	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();
+		StringBuffer params = new StringBuffer("/api?command=disableAccount"+"&"+ApiConstants.LOCK+"="+lockRequested);
+		params.append("&"+ApiConstants.ID+"="+accountUUID);
+		if(accountName != null){
+			params.append("&"+ApiConstants.ACCOUNT+"="+accountName);
+		}
+        DomainVO domain = _domainDao.findById(domainId);
+		if(domain != null){
+			params.append("&"+ApiConstants.DOMAIN_ID+"="+domain.getUuid());
+		}
+		long 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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully disabled account :"+accountUUID+" in source Region: "+region.getId());
+				//return Account object
+				return null;
+			} else {
+				s_logger.error("Error while disabling account :"+accountUUID+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
+	}
+
+	@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();
+		StringBuffer params = new StringBuffer("/api?command=enableAccount");
+		params.append("&"+ApiConstants.ID+"="+accountUUID);
+		if(accountName != null){
+			params.append("&"+ApiConstants.ACCOUNT+"="+accountName);
+		}
+        DomainVO domain = _domainDao.findById(domainId);
+		if(domain != null){
+			params.append("&"+ApiConstants.DOMAIN_ID+"="+domain.getUuid());
+		}
+
+		long 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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully enabled account :"+accountUUID+" in source Region: "+region.getId());
+				//return Account object
+				return null;
+			} else {
+				s_logger.error("Error while enabling account :"+accountUUID+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
+	}
+
+	@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();
+		long regionId = user.getRegionId();
+		String params = "/api?command=deleteUser&id="+userUUID;
+		if(getId() == regionId){
+			if(_accountMgr.deleteUser(cmd)){
+				List<RegionVO> regions =  _regionDao.listAll();
+				for (Region region : regions){
+					if(region.getId() == getId()){
+						continue;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully deleted user :"+userUUID+" in Region: "+region.getId());
+				return true;
+			} else {
+				s_logger.error("Error while deleting user :"+userUUID+" in Region: "+region.getId());
+				return false;
+			}
+		}
+	}
+
+	@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();
+        StringBuffer params = new StringBuffer("/api?command=deleteDomain");
+        params.append("&"+ApiConstants.ID+"="+domainUUID);
+        params.append("&"+ApiConstants.CLEANUP+"="+cleanup);
+        long 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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				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;
+			}
+		}
+	}
+
+	@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();
+        StringBuffer params = new StringBuffer("/api?command=updateUser");
+        params.append("&"+ApiConstants.ID+"="+userUUID);
+        if(cmd.getApiKey() != null){
+        	params.append("&"+ApiConstants.API_KEY+"="+cmd.getApiKey());    
+        }
+        if(cmd.getEmail() != null){
+        	params.append("&"+ApiConstants.EMAIL+"="+cmd.getEmail());    
+        }
+        if(cmd.getFirstname() != null){
+        	params.append("&"+ApiConstants.FIRSTNAME+"="+cmd.getFirstname());    
+        }        
+        if(cmd.getLastname() != null){
+        	params.append("&"+ApiConstants.LASTNAME+"="+cmd.getLastname());    
+        }        
+        if(cmd.getPassword() != null){
+        	params.append("&"+ApiConstants.PASSWORD+"="+cmd.getPassword());    
+        }
+        if(cmd.getSecretKey() != null){
+        	params.append("&"+ApiConstants.SECRET_KEY+"="+cmd.getSecretKey());    
+        }          
+        if(cmd.getTimezone() != null){
+        	params.append("&"+ApiConstants.TIMEZONE+"="+cmd.getTimezone());    
+        } 
+        if(cmd.getUsername() != null){
+        	params.append("&"+ApiConstants.USERNAME+"="+cmd.getUsername());    
+        }         
+
+		long 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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully updated user :"+userUUID+" in source Region: "+region.getId());
+				//return object
+				return null;
+			} else {
+				s_logger.error("Error while updating user :"+userUUID+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
 	}
 
 	@Override
-	public Account disableAccount(String accountName, Long domainId, Long id) {
-		// TODO Auto-generated method stub
-		return null;
+	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();
+        StringBuffer params = new StringBuffer("/api?command=updateDomain");
+        params.append("&"+ApiConstants.ID+"="+domainUUID);
+        if(cmd.getDomainName() != null){
+        	params.append("&"+ApiConstants.NAME+"="+cmd.getDomainName());    
+        }
+        if(cmd.getNetworkDomain() != null){
+        	params.append("&"+ApiConstants.NETWORK_DOMAIN+"="+cmd.getNetworkDomain());    
+        }
+
+		long regionId = domain.getRegionId();
+		if(getId() == regionId){
+			Domain updatedDomain = _mgmtSrvr.updateDomain(cmd);
+			if(updatedDomain != null){
+				List<RegionVO> regions =  _regionDao.listAll();
+				for (Region region : regions){
+					if(region.getId() == getId()){
+						continue;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully updated user :"+domainUUID+" in source Region: "+region.getId());
+				//return object
+				return null;
+			} else {
+				s_logger.error("Error while updating user :"+domainUUID+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
 	}
 
 	@Override
-	public Account enableAccount(String accountName, Long domainId, Long id) {
-		// TODO Auto-generated method stub
-		return null;
+	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);
+        }
+        long regionId = user.getRegionId();
+        StringBuffer params = new StringBuffer("/api?command=disableUser&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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully disabled user :"+user.getUuid()+" in source Region: "+region.getId());
+				//return object
+				return null;
+			} else {
+				s_logger.error("Error while disabling user :"+user.getUuid()+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
 	}
 
+	@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);
+        }
+        long regionId = user.getRegionId();
+        StringBuffer params = new StringBuffer("/api?command=enableUser&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;
+					}
+					String url = region.getEndPoint() + params +"&"+ApiConstants.IS_PROPAGATE+"=true";
+					if (makeAPICall(url)) {
+						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);
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully enabled user :"+user.getUuid()+" in source Region: "+region.getId());
+				//return object
+				return null;
+			} else {
+				s_logger.error("Error while enabling user :"+user.getUuid()+" in source Region: "+region.getId());
+				//throw exception;
+				return null;
+			}
+		}
+	}
+
+	@Override
+	public void propogateAddUser(String userName, String password,
+			String firstName, String lastName, String email, String timezone,
+			String accountName, String domainUUId, String userUUID) {
+		
+		StringBuffer params = new StringBuffer("/api?command=createUser");
+		params.append("&"+ApiConstants.USERNAME+"="+userName);
+		params.append("&"+ApiConstants.PASSWORD+"="+password);
+		params.append("&"+ApiConstants.FIRSTNAME+"="+firstName);
+		params.append("&"+ApiConstants.LASTNAME+"="+lastName);
+		params.append("&"+ApiConstants.EMAIL+"="+email);
+		if(timezone != null){
+			params.append("&"+ApiConstants.TIMEZONE+"="+timezone);		
+		}
+		if(accountName != null){
+			params.append("&"+ApiConstants.ACCOUNT+"="+accountName);	
+		}
+		if(domainUUId != null){
+			params.append("&"+ApiConstants.DOMAIN_ID+"="+domainUUId); //use UUID			
+		}
+		params.append("&"+ApiConstants.USER_ID+"="+userUUID);
+		params.append("&"+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());
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
+			} else {
+				s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
+				//Send User delete to all Regions where account is added successfully
+				break;
+			}
+		}
+		return;		
+	}
+	
+	@Override
+	public void propogateAddDomain(String name, Long parentId, String networkDomain, String uuid) {
+		StringBuffer params = new StringBuffer("/api?command=createDomain");
+		params.append("&ApiConstants.NAME="+name);
+		String parentUUID = null;
+		if(parentId != null){
+			DomainVO domain = _domainDao.findById(parentId);
+			if(domain != null){
+				parentUUID = domain.getUuid();
+				params.append("&ApiConstants.PARENT_DOMAIN_ID="+parentUUID);
+			}
+		}
+		if(networkDomain != null){
+			params.append("&ApiConstants.NETWORK_DOMAIN="+networkDomain);
+		}
+		params.append("&ApiConstants.DOMAIN_ID="+uuid);
+		params.append("&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());
+			String url = region.getEndPoint() + params;
+			if (makeAPICall(url)) {
+				s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
+			} else {
+				s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
+				//Send User delete to all Regions where account is added successfully
+				break;
+			}
+		}
+		return;		
+		
+	}
+	
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/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 c174e5c..f603ec3 100755
--- a/server/src/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/com/cloud/user/AccountManagerImpl.java
@@ -49,6 +49,7 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.ResourceLimit;
 import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.configuration.dao.ConfigurationDaoImpl;
 import com.cloud.configuration.dao.ResourceCountDao;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.dao.DataCenterDao;
@@ -741,7 +742,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
         	txn.commit();
         	//Propogate Add account to other Regions
         	_regionMgr.propogateAddAccount(userName, password, firstName, lastName, email, timezone, accountName, accountType, domainId, 
-        			networkDomain, details, account.getUuid(), user.getUuid(), _regionMgr.getId());
+        			networkDomain, details, account.getUuid(), user.getUuid());
         	//check success
             return _userAccountDao.findById(user.getId());
         } else {
@@ -769,7 +770,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
     }
 
     @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, Long regionId) {
 
         // default domain to ROOT if not specified
         if (domainId == null) {
@@ -793,9 +794,14 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
         if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) {
             throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId);
         }
-
-        UserVO user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
-
+        UserVO user = null;
+        if(regionId == null){
+        	user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
+        	//Propogate Add user to other Regions
+        	_regionMgr.propogateAddUser(userName, password, firstName, lastName, email, timeZone, accountName, domain.getUuid(), user.getUuid());
+        } else {
+        	user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone, userUUID, regionId);
+        }
         return user;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/server/src/com/cloud/user/DomainManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManager.java b/server/src/com/cloud/user/DomainManager.java
index 9d8b75a..5183f8c 100644
--- a/server/src/com/cloud/user/DomainManager.java
+++ b/server/src/com/cloud/user/DomainManager.java
@@ -21,7 +21,7 @@ import com.cloud.domain.DomainVO;
 public interface DomainManager extends DomainService {
     Set<Long> getDomainChildrenIds(String parentDomainPath);
 
-    Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain);
+    Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, String domainUUID, Long regionId);
 
     /**
      * find the domain by its path

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/39d394a8/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 3223d8c..84ba3d9 100644
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@ -38,6 +38,7 @@ import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.projects.ProjectManager;
 import com.cloud.projects.ProjectVO;
 import com.cloud.projects.dao.ProjectDao;
+import com.cloud.region.RegionManager;
 import com.cloud.service.ServiceOfferingVO;
 import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.DiskOfferingVO;
@@ -74,7 +75,9 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
     private ProjectDao _projectDao;
     @Inject
     private ProjectManager _projectMgr;
-
+    @Inject
+    private RegionManager _regionMgr;
+    
     @Override
     public Domain getDomain(long domainId) {
         return _domainDao.findById(domainId);
@@ -124,7 +127,7 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
 
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain")
-    public Domain createDomain(String name, Long parentId, String networkDomain) {
+    public Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID, Long regionId) {
         Account caller = UserContext.current().getCaller();
 
         if (parentId == null) {
@@ -142,13 +145,13 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
 
         _accountMgr.checkAccess(caller, parentDomain);
 
-        return createDomain(name, parentId, caller.getId(), networkDomain);
+        return createDomain(name, parentId, caller.getId(), networkDomain, domainUUID, regionId);
 
     }
 
     @Override
     @DB
-    public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain) {
+    public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, String domainUUID, Long regionId) {
         // Verify network domain
         if (networkDomain != null) {
             if (!NetUtils.verifyDomainName(networkDomain)) {
@@ -167,15 +170,27 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
             throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
         }
 
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
+        if(regionId == null){
+        	Transaction txn = Transaction.currentTxn();
+        	txn.start();
 
-        DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain));
-        _resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
+        	DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, _regionMgr.getId()));
+        	_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
+        	_regionMgr.propogateAddDomain(name, parentId, networkDomain, domain.getUuid());
+        	txn.commit();
+        	return domain;
+        } else {
+        	Transaction txn = Transaction.currentTxn();
+        	txn.start();
 
-        txn.commit();
+        	DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, domainUUID, regionId));
+        	_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
 
-        return domain;
+        	txn.commit();
+        	return domain;
+        	
+        }
+        
     }
 
     @Override


Mime
View raw message