mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
CLOUDSTACK-241: Removed API based account sync. Removed all the related API changes and RegionsAPIUtil.
Converted tabs to spaces in the related files. Verified account, user and domain APIs.
This commit is contained in:
parent
0383803188
commit
e37fdce125
@ -62,7 +62,7 @@ public interface AccountService {
|
||||
* @return the user if created successfully, null otherwise
|
||||
*/
|
||||
UserAccount createUserAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain,
|
||||
Map<String, String> details, String accountUUID, String userUUID, Integer regionId);
|
||||
Map<String, String> details);
|
||||
|
||||
/**
|
||||
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses
|
||||
@ -77,7 +77,7 @@ public interface AccountService {
|
||||
|
||||
User getSystemUser();
|
||||
|
||||
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID, Integer regionId);
|
||||
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId);
|
||||
|
||||
boolean isAdmin(short accountType);
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ import com.cloud.utils.Pair;
|
||||
|
||||
public interface DomainService {
|
||||
|
||||
Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID, Integer regionId);
|
||||
Domain createDomain(String name, Long parentId, String networkDomain);
|
||||
|
||||
Domain getDomain(long id);
|
||||
|
||||
|
||||
@ -379,9 +379,8 @@ public class ApiConstants {
|
||||
public static final String VSM_CONFIG_STATE = "vsmconfigstate";
|
||||
public static final String VSM_DEVICE_STATE = "vsmdevicestate";
|
||||
public static final String ADD_VSM_FLAG = "addvsmflag";
|
||||
public static final String END_POINT = "endpoint";
|
||||
public static final String REGION_ID = "regionid";
|
||||
public static final String IS_PROPAGATE = "ispropagate";
|
||||
public static final String END_POINT = "endpoint";
|
||||
public static final String REGION_ID = "regionid";
|
||||
public static final String VPC_OFF_ID = "vpcofferingid";
|
||||
public static final String NETWORK = "network";
|
||||
public static final String VPC_ID = "vpcid";
|
||||
|
||||
@ -78,19 +78,6 @@ 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;
|
||||
|
||||
//@Parameter(name = ApiConstants.REGION_DETAILS, type = CommandType.MAP, description = "details for account used to store region specific parameters")
|
||||
//private Map<String, String> regionDetails;
|
||||
|
||||
@Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.STRING, description="Account UUID, required for adding account from another Region")
|
||||
private String accountUUID;
|
||||
|
||||
@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.INTEGER, description="Id of the Region creating the account")
|
||||
private Integer regionId;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -145,18 +132,6 @@ public class CreateAccountCmd extends BaseCmd {
|
||||
return params;
|
||||
}
|
||||
|
||||
public String getAccountUUID() {
|
||||
return accountUUID;
|
||||
}
|
||||
|
||||
public String getUserUUID() {
|
||||
return userUUID;
|
||||
}
|
||||
|
||||
public Integer getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -174,8 +149,7 @@ 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(),
|
||||
getAccountUUID(), getUserUUID(), getRegionId());
|
||||
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());
|
||||
|
||||
@ -48,9 +48,6 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
|
||||
required=true, description="Account id")
|
||||
private Long id;
|
||||
|
||||
@Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
|
||||
private Boolean isPropagate;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -62,10 +59,6 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -58,9 +58,6 @@ public class DisableAccountCmd extends BaseAsyncCmd {
|
||||
@Parameter(name=ApiConstants.LOCK, type=CommandType.BOOLEAN, required=true, description="If true, only lock the account; else disable the account")
|
||||
private Boolean lockRequested;
|
||||
|
||||
@Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
|
||||
private Boolean isPropagate;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -79,14 +76,10 @@ public class DisableAccountCmd extends BaseAsyncCmd {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
public Boolean getLockRequested() {
|
||||
return lockRequested;
|
||||
}
|
||||
|
||||
return lockRequested;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -124,7 +117,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
|
||||
@Override
|
||||
public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
|
||||
UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
|
||||
Account result = _regionService.disableAccount(this);
|
||||
Account result = _regionService.disableAccount(this);
|
||||
if (result != null){
|
||||
AccountResponse response = _responseGenerator.createAccountResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -50,9 +50,6 @@ public class EnableAccountCmd extends BaseCmd {
|
||||
description="Enables specified account in this domain.")
|
||||
private Long domainId;
|
||||
|
||||
@Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
|
||||
private Boolean isPropagate;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -71,9 +68,6 @@ public class EnableAccountCmd extends BaseCmd {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
@ -101,7 +95,7 @@ public class EnableAccountCmd extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Account result = _regionService.enableAccount(this);
|
||||
Account result = _regionService.enableAccount(this);
|
||||
if (result != null){
|
||||
AccountResponse response = _responseGenerator.createAccountResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -63,9 +63,6 @@ public class UpdateAccountCmd extends BaseCmd{
|
||||
@Parameter(name = ApiConstants.ACCOUNT_DETAILS, type = CommandType.MAP, description = "details for account used to store specific parameters")
|
||||
private Map details;
|
||||
|
||||
@Parameter(name=ApiConstants.IS_PROPAGATE, type=CommandType.BOOLEAN, description="True if command is sent from another Region")
|
||||
private Boolean isPropagate;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -102,10 +99,7 @@ public class UpdateAccountCmd extends BaseCmd{
|
||||
return params;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -131,7 +125,7 @@ public class UpdateAccountCmd extends BaseCmd{
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
Account result = _regionService.updateAccount(this);
|
||||
Account result = _regionService.updateAccount(this);
|
||||
if (result != null){
|
||||
AccountResponse response = _responseGenerator.createAccountResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -49,12 +49,6 @@ 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.INTEGER, description="Id of the Region creating the Domain")
|
||||
private Integer regionId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -71,14 +65,6 @@ public class CreateDomainCmd extends BaseCmd {
|
||||
return networkDomain;
|
||||
}
|
||||
|
||||
public String getDomainUUID() {
|
||||
return domainUUID;
|
||||
}
|
||||
|
||||
public Integer getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -96,7 +82,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(), getDomainUUID(), getRegionId());
|
||||
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
|
||||
if (domain != null) {
|
||||
DomainResponse response = _responseGenerator.createDomainResponse(domain);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -50,9 +50,6 @@ 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 propagate;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -67,10 +64,6 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
|
||||
return cleanup;
|
||||
}
|
||||
|
||||
public Boolean isPropagate() {
|
||||
return propagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -52,9 +52,6 @@ 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;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -73,10 +70,6 @@ public class UpdateDomainCmd extends BaseCmd {
|
||||
return networkDomain;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -65,12 +65,6 @@ 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.INTEGER, description="Id of the Region creating the User")
|
||||
private Integer regionId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -107,14 +101,6 @@ public class CreateUserCmd extends BaseCmd {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getUserUUID() {
|
||||
return userUUID;
|
||||
}
|
||||
|
||||
public Integer getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
@ -146,7 +132,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(), getUserUUID(), getRegionId());
|
||||
User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
|
||||
if (user != null) {
|
||||
UserResponse response = _responseGenerator.createUserResponse(user);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
@ -45,9 +45,6 @@ public class DeleteUserCmd extends BaseCmd {
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=UserResponse.class, 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;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -58,10 +55,6 @@ public class DeleteUserCmd extends BaseCmd {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -49,9 +49,6 @@ public class DisableUserCmd extends BaseAsyncCmd {
|
||||
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;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -62,10 +59,6 @@ public class DisableUserCmd extends BaseAsyncCmd {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -46,9 +46,6 @@ public class EnableUserCmd extends BaseCmd {
|
||||
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;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -59,10 +56,6 @@ public class EnableUserCmd extends BaseCmd {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -71,9 +71,6 @@ 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;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
@ -116,10 +113,6 @@ public class UpdateUserCmd extends BaseCmd {
|
||||
return username;
|
||||
}
|
||||
|
||||
public Boolean getIsPropagate() {
|
||||
return isPropagate;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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, String uuid, int regionId) {
|
||||
|
||||
public AccountVO(String accountName, long domainId, String networkDomain, short type, int regionId) {
|
||||
this.accountName = accountName;
|
||||
this.domainId = domainId;
|
||||
this.networkDomain = networkDomain;
|
||||
this.type = type;
|
||||
this.state = State.enabled;
|
||||
this.uuid = uuid;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
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,18 +176,14 @@ 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 void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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, String uuid, int regionId) {
|
||||
|
||||
public UserVO(long accountId, String username, String password, String firstName, String lastName, String email, String timezone, 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;
|
||||
this.regionId = regionId;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
@ -265,12 +265,9 @@ public class UserVO implements User, Identity, InternalIdentity {
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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, "", 0);
|
||||
Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null);
|
||||
|
||||
Project project = _projectDao.persist(new ProjectVO(name, displayText, owner.getDomainId(), projectAccount.getId()));
|
||||
|
||||
|
||||
@ -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);
|
||||
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);
|
||||
|
||||
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
|
||||
|
||||
@ -764,7 +764,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
@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, String accountUUID, String userUUID, Integer regionId) {
|
||||
Map<String, String> details) {
|
||||
|
||||
if (accountName == null) {
|
||||
accountName = userName;
|
||||
@ -806,41 +806,16 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
}
|
||||
|
||||
if(regionId == null){
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
// 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);
|
||||
|
||||
if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// set registration token
|
||||
byte[] bytes = (domainId + accountName + userName + System.currentTimeMillis()).getBytes();
|
||||
String registrationToken = UUID.nameUUIDFromBytes(bytes).toString();
|
||||
user.setRegistrationToken(registrationToken);
|
||||
}
|
||||
txn.commit();
|
||||
//Propagate Add account to other Regions
|
||||
_regionMgr.propagateAddAccount(userName, password, firstName, lastName, email, timezone, accountName, accountType, domainId,
|
||||
networkDomain, details, account.getUuid(), user.getUuid());
|
||||
//check success
|
||||
return _userAccountDao.findById(user.getId());
|
||||
} else {
|
||||
// Account is propagated from another Region
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
// create account
|
||||
AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, accountUUID, regionId);
|
||||
AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details);
|
||||
long accountId = account.getId();
|
||||
|
||||
// create the first user for the account
|
||||
UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone, userUUID, regionId);
|
||||
UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone);
|
||||
|
||||
if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// set registration token
|
||||
@ -849,12 +824,13 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
user.setRegistrationToken(registrationToken);
|
||||
}
|
||||
txn.commit();
|
||||
//check success
|
||||
return _userAccountDao.findById(user.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID, Integer regionId) {
|
||||
public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId) {
|
||||
|
||||
// default domain to ROOT if not specified
|
||||
if (domainId == null) {
|
||||
@ -882,15 +858,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
if (!_userAccountDao.validateUsernameInDomain(userName, domainId)) {
|
||||
throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId);
|
||||
}
|
||||
UserVO user = null;
|
||||
if(regionId == null){
|
||||
user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
|
||||
//Propagate Add user to peer Regions
|
||||
_regionMgr.propagateAddUser(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;
|
||||
|
||||
return createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -975,7 +944,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
}
|
||||
if (encodedPassword == null) {
|
||||
throw new CloudRuntimeException("Failed to encode password");
|
||||
throw new CloudRuntimeException("Failed to encode password");
|
||||
}
|
||||
user.setPassword(encodedPassword);
|
||||
}
|
||||
@ -1297,7 +1266,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
String newAccountName = cmd.getNewName();
|
||||
String networkDomain = cmd.getNetworkDomain();
|
||||
Map<String, String> details = cmd.getDetails();
|
||||
|
||||
|
||||
boolean success = false;
|
||||
Account account = null;
|
||||
if (accountId != null) {
|
||||
@ -1677,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, String uuid, int regionId) {
|
||||
public AccountVO createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details) {
|
||||
// Validate domain
|
||||
Domain domain = _domainMgr.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
@ -1721,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, uuid, regionId));
|
||||
AccountVO account = _accountDao.persist(new AccountVO(accountName, domainId, networkDomain, accountType, _accountDao.getRegionId()));
|
||||
|
||||
if (account == null) {
|
||||
throw new CloudRuntimeException("Failed to create account name " + accountName + " in domain id=" + domainId);
|
||||
@ -1749,7 +1718,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone);
|
||||
}
|
||||
|
||||
|
||||
String encodedPassword = null;
|
||||
for (UserAuthenticator authenticator : _userAuthenticators) {
|
||||
encodedPassword = authenticator.encode(password);
|
||||
@ -1758,33 +1727,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
}
|
||||
if (encodedPassword == null) {
|
||||
throw new CloudRuntimeException("Failed to encode password");
|
||||
}
|
||||
|
||||
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);
|
||||
throw new CloudRuntimeException("Failed to encode password");
|
||||
}
|
||||
|
||||
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));
|
||||
UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, _userDao.getRegionId()));
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -2014,7 +1960,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
|
||||
@Override @DB
|
||||
public String[] createApiKeyAndSecretKey(RegisterCmd cmd) {
|
||||
//Send keys to other Regions
|
||||
//Send keys to other Regions
|
||||
Long userId = cmd.getId();
|
||||
|
||||
User user = getUserIncludingRemoved(userId);
|
||||
@ -2243,7 +2189,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public void buildACLViewSearchBuilder(SearchBuilder<? extends ControlledViewEntity> sb, Long domainId,
|
||||
boolean isRecursive, List<Long> permittedAccounts, ListProjectResourcesCriteria listProjectResourcesCriteria) {
|
||||
|
||||
|
||||
@ -27,7 +27,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, String domainUUID, Integer regionId);
|
||||
Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain);
|
||||
|
||||
Set<Long> getDomainParentIds(long domainId);
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_DOMAIN_CREATE, eventDescription = "creating Domain")
|
||||
public Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID, Integer regionId) {
|
||||
public Domain createDomain(String name, Long parentId, String networkDomain) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
if (parentId == null) {
|
||||
@ -136,13 +136,13 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
|
||||
_accountMgr.checkAccess(caller, parentDomain);
|
||||
|
||||
return createDomain(name, parentId, caller.getId(), networkDomain, domainUUID, regionId);
|
||||
return createDomain(name, parentId, caller.getId(), networkDomain);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, String domainUUID, Integer regionId) {
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain) {
|
||||
// Verify network domain
|
||||
if (networkDomain != null) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
@ -161,28 +161,14 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
|
||||
}
|
||||
|
||||
if(regionId == null){
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, _regionMgr.getId()));
|
||||
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, _regionMgr.getId()));
|
||||
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
|
||||
txn.commit();
|
||||
//Propagate domain creation to peer Regions
|
||||
_regionMgr.propagateAddDomain(name, parentId, networkDomain, domain.getUuid());
|
||||
return domain;
|
||||
} else {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, domainUUID, regionId));
|
||||
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
|
||||
|
||||
txn.commit();
|
||||
return domain;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -31,186 +31,46 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.UserAccount;
|
||||
|
||||
public interface RegionManager {
|
||||
|
||||
/**
|
||||
* Propagates Account details to peer Regions
|
||||
* @param userName
|
||||
* @param password
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param email
|
||||
* @param timezone
|
||||
* @param accountName
|
||||
* @param accountType
|
||||
* @param domainId
|
||||
* @param networkDomain
|
||||
* @param details
|
||||
* @param accountUUID
|
||||
* @param userUUID
|
||||
* @return
|
||||
*/
|
||||
public boolean propagateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain,
|
||||
Map<String, String> details, String accountUUID, String userUUID);
|
||||
|
||||
/**
|
||||
* Returns the Id of local Region
|
||||
* @return
|
||||
*/
|
||||
public int getId();
|
||||
|
||||
/**
|
||||
* Propagates User details to peer Regions
|
||||
* @param userName
|
||||
* @param password
|
||||
* @param firstName
|
||||
* @param lastName
|
||||
* @param email
|
||||
* @param timeZone
|
||||
* @param accountName
|
||||
* @param domainUUId
|
||||
* @param userUUID
|
||||
*/
|
||||
public void propagateAddUser(String userName, String password,
|
||||
String firstName, String lastName, String email, String timeZone,
|
||||
String accountName, String domainUUId, String userUUID);
|
||||
|
||||
/**
|
||||
* Propagates Domain details to peer Regions
|
||||
* @param name
|
||||
* @param parentId
|
||||
* @param networkDomain
|
||||
* @param uuid
|
||||
*/
|
||||
public void propagateAddDomain(String name, Long parentId, String networkDomain, String uuid);
|
||||
|
||||
|
||||
/**
|
||||
* Adds a peer Region to the local Region
|
||||
* @param id
|
||||
* @param name
|
||||
* @param endPoint
|
||||
* @param apiKey
|
||||
* @param secretKey
|
||||
* @return Returns added Region object
|
||||
*/
|
||||
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 Returns update Region object
|
||||
*/
|
||||
Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @return True if region is successfully removed
|
||||
*/
|
||||
boolean removeRegion(int id);
|
||||
|
||||
/** List all Regions or by Id/Name
|
||||
* @param id
|
||||
* @param name
|
||||
* @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
|
||||
* Returns the Id of local Region
|
||||
* @return
|
||||
*/
|
||||
boolean deleteUser(DeleteUserCmd deleteUserCmd);
|
||||
|
||||
public int getId();
|
||||
|
||||
/**
|
||||
* update an existing domain
|
||||
*
|
||||
* @param cmd
|
||||
* - the command containing domainId and new domainName
|
||||
* @return Domain object if the command succeeded
|
||||
* Adds a peer Region to the local Region
|
||||
* @param id
|
||||
* @param name
|
||||
* @param endPoint
|
||||
* @param apiKey
|
||||
* @param secretKey
|
||||
* @return Returns added Region object
|
||||
*/
|
||||
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);
|
||||
|
||||
Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey);
|
||||
|
||||
/**
|
||||
* Update a user by userId
|
||||
* Update details of the Region with specified Id
|
||||
* @param id
|
||||
* @param name
|
||||
* @param endPoint
|
||||
*
|
||||
* @param userId
|
||||
* @return UserAccount object
|
||||
* @param apiKey
|
||||
* @param secretKey
|
||||
* @return Returns update Region object
|
||||
*/
|
||||
UserAccount updateUser(UpdateUserCmd updateUserCmd);
|
||||
|
||||
Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param id
|
||||
* @return True if region is successfully removed
|
||||
*/
|
||||
UserAccount enableUser(long userId);
|
||||
boolean removeRegion(int id);
|
||||
|
||||
/** List all Regions or by Id/Name
|
||||
* @param id
|
||||
* @param name
|
||||
* @return List of Regions
|
||||
*/
|
||||
List<RegionVO> listRegions(Integer id, String name);
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@ import com.cloud.uuididentity.dao.IdentityDao;
|
||||
@Local(value = { RegionManager.class })
|
||||
public class RegionManagerImpl extends ManagerBase implements RegionManager, Manager{
|
||||
public static final Logger s_logger = Logger.getLogger(RegionManagerImpl.class);
|
||||
|
||||
|
||||
@Inject
|
||||
RegionDao _regionDao;
|
||||
@Inject
|
||||
@ -78,17 +78,17 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
||||
private IdentityDao _identityDao;
|
||||
@Inject
|
||||
private RegionSyncDao _regionSyncDao;
|
||||
|
||||
|
||||
private String _name;
|
||||
private int _id;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
_id = _regionDao.getRegionId();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
@ -104,776 +104,98 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
||||
return _name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Propagates Account creation to peer Regions
|
||||
* Adds an entry in region_sync table on failure
|
||||
*/
|
||||
@Override
|
||||
public boolean propagateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone,
|
||||
String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
|
||||
String command = "createAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.USERNAME, userName));
|
||||
params.add(new NameValuePair(ApiConstants.PASSWORD, password));
|
||||
params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
|
||||
params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
|
||||
params.add(new NameValuePair(ApiConstants.EMAIL, email));
|
||||
params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT_TYPE, ""+accountType));
|
||||
//ToDo: use domain UUID
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, ((domainId != null) ? domainId.toString() : "")));
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, (details != null) ? details.toString() : ""));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT_ID, accountUUID));
|
||||
params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
|
||||
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
|
||||
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully added account :"+accountName+" to Region: "+region.getId());
|
||||
} else {
|
||||
// api call failed. Add entry in region_sync table
|
||||
addRegionSyncItem(region.getId(), command, params);
|
||||
s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Propagates User creation to peer Regions
|
||||
* Adds an entry in region_sync table on failure
|
||||
*/
|
||||
@Override
|
||||
public void propagateAddUser(String userName, String password,
|
||||
String firstName, String lastName, String email, String timezone,
|
||||
String accountName, String domainUUId, String userUUID) {
|
||||
|
||||
String command = "createUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.USERNAME, userName));
|
||||
params.add(new NameValuePair(ApiConstants.PASSWORD, password));
|
||||
params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
|
||||
params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
|
||||
params.add(new NameValuePair(ApiConstants.EMAIL, email));
|
||||
params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domainUUId));
|
||||
params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
|
||||
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
|
||||
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
|
||||
} else {
|
||||
// api call failed. Add entry in region_sync table
|
||||
addRegionSyncItem(region.getId(), command, params);
|
||||
s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Propagates Domain creation details to peer Regions
|
||||
* Adds an entry in region_sync table on failure
|
||||
*/
|
||||
@Override
|
||||
public void propagateAddDomain(String name, Long parentId, String networkDomain, String uuid) {
|
||||
|
||||
String command = "createDomain";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.NAME, name));
|
||||
if(parentId != null){
|
||||
DomainVO domain = _domainDao.findById(parentId);
|
||||
if(domain != null){
|
||||
params.add(new NameValuePair(ApiConstants.PARENT_DOMAIN_ID, domain.getUuid()));
|
||||
}
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, uuid));
|
||||
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
|
||||
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
s_logger.debug("Adding domain :"+name+" to Region: "+region.getId());
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
|
||||
} else {
|
||||
// api call failed. Add entry in region_sync table
|
||||
addRegionSyncItem(region.getId(), command, params);
|
||||
s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entry to region_sync table
|
||||
* Entry contains region Id along with failed api
|
||||
* @param regionId
|
||||
* @param command
|
||||
* @param params
|
||||
*/
|
||||
private void addRegionSyncItem(int regionId, String command, List<NameValuePair> params){
|
||||
String api = RegionsApiUtil.buildParams(command, params);
|
||||
RegionSyncVO sync = new RegionSyncVO(regionId, api);
|
||||
if(_regionSyncDao.persist(sync) == null){
|
||||
s_logger.error("Failed to add Region Sync Item. RegionId: "+regionId + "API command: "+api);
|
||||
}
|
||||
}
|
||||
public int getId() {
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Region Id should be unique
|
||||
if( _regionDao.findById(id) != null ){
|
||||
throw new InvalidParameterValueException("Region with id: "+id+" already exists");
|
||||
}
|
||||
//Region Name should be unique
|
||||
if( _regionDao.findByName(name) != null ){
|
||||
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
|
||||
}
|
||||
RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
|
||||
return _regionDao.persist(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
|
||||
if(region == null){
|
||||
throw new InvalidParameterValueException("Region with id: "+id+" does not exist");
|
||||
}
|
||||
|
||||
//Ensure region name is unique
|
||||
if(name != null){
|
||||
RegionVO region1 = _regionDao.findByName(name);
|
||||
if(region1 != null && id != region1.getId()){
|
||||
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
|
||||
}
|
||||
}
|
||||
|
||||
if(name != null){
|
||||
region.setName(name);
|
||||
}
|
||||
|
||||
if(endPoint != null){
|
||||
region.setEndPoint(endPoint);
|
||||
}
|
||||
|
||||
if(apiKey != null){
|
||||
region.setApiKey(apiKey);
|
||||
}
|
||||
|
||||
if(secretKey != null){
|
||||
region.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
_regionDao.update(id, region);
|
||||
return _regionDao.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean removeRegion(int id) {
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
if(region == null){
|
||||
throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
|
||||
}
|
||||
return _regionDao.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<RegionVO> listRegions(Integer id, String name) {
|
||||
List<RegionVO> regions = new ArrayList<RegionVO>();
|
||||
if(id != null){
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
if(region != null){
|
||||
regions.add(region);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
if(name != null){
|
||||
RegionVO region = _regionDao.findByName(name);
|
||||
if(region != null){
|
||||
regions.add(region);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
return _regionDao.listAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserAccount(long accountId) {
|
||||
AccountVO account = _accountDao.findById(accountId);
|
||||
if(account == null){
|
||||
throw new InvalidParameterValueException("The specified account does not exist in the system");
|
||||
}
|
||||
String accountUUID = account.getUuid();
|
||||
int regionId = account.getRegionId();
|
||||
|
||||
String command = "deleteAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
|
||||
if(getId() == regionId){
|
||||
if(_accountMgr.deleteUserAccount(accountId)){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//First delete in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account updateAccount(UpdateAccountCmd cmd) {
|
||||
Long accountId = cmd.getId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
String accountName = cmd.getAccountName();
|
||||
String newAccountName = cmd.getNewName();
|
||||
String networkDomain = cmd.getNetworkDomain();
|
||||
//ToDo send details
|
||||
Map<String, String> details = cmd.getDetails();
|
||||
|
||||
Account account = null;
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
} else {
|
||||
account = _accountDao.findEnabledAccount(accountName, domainId);
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Region Id should be unique
|
||||
if( _regionDao.findById(id) != null ){
|
||||
throw new InvalidParameterValueException("Region with id: "+id+" already exists");
|
||||
}
|
||||
|
||||
// Check if account exists
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String command = "updateAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
|
||||
params.add(new NameValuePair(ApiConstants.ID, account.getUuid()));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
|
||||
params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
|
||||
if(details != null){
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, details.toString()));
|
||||
}
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
Account updatedAccount = _accountMgr.updateAccount(cmd);
|
||||
if(updatedAccount != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated account :"+account.getUuid()+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while updating account :"+account.getUuid()+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return updatedAccount;
|
||||
} else {
|
||||
//First update in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
RegionAccount updatedAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
|
||||
if (updatedAccount != null) {
|
||||
Long id = _identityDao.getIdentityId("account", updatedAccount.getUuid());
|
||||
updatedAccount.setId(id);
|
||||
Long domainID = _identityDao.getIdentityId("domain", updatedAccount.getDomainUuid());
|
||||
updatedAccount.setDomainId(domainID);
|
||||
s_logger.debug("Successfully updated account :"+account.getUuid()+" in source Region: "+region.getId());
|
||||
return updatedAccount;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating account :"+account.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
//Region Name should be unique
|
||||
if( _regionDao.findByName(name) != null ){
|
||||
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
|
||||
}
|
||||
RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
|
||||
return _regionDao.persist(region);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public 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);
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
|
||||
if(region == null){
|
||||
throw new InvalidParameterValueException("Region with id: "+id+" does not exist");
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String accountUUID = account.getUuid();
|
||||
|
||||
String command = "disableAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.LOCK, lockRequested.toString()));
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if(domain != null){
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
}
|
||||
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
Account retAccount = null;
|
||||
if(lockRequested){
|
||||
retAccount = _accountMgr.lockAccount(accountName, domainId, accountId);
|
||||
} else {
|
||||
retAccount = _accountMgr.disableAccount(accountName, domainId, accountId);
|
||||
}
|
||||
if(retAccount != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully disabled account :"+accountUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while disabling account :"+accountUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return retAccount;
|
||||
} else {
|
||||
//First disable account in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
|
||||
if (retAccount != null) {
|
||||
s_logger.debug("Successfully disabled account :"+accountUUID+" in source Region: "+region.getId());
|
||||
return retAccount;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while disabling account :"+accountUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account enableAccount(String accountName, Long domainId, Long accountId) {
|
||||
// Check if account exists
|
||||
Account account = null;
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
//Ensure region name is unique
|
||||
if(name != null){
|
||||
RegionVO region1 = _regionDao.findByName(name);
|
||||
if(region1 != null && id != region1.getId()){
|
||||
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
|
||||
}
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String accountUUID = account.getUuid();
|
||||
|
||||
String command = "enableAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if(domain != null){
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
}
|
||||
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
Account retAccount = _accountMgr.enableAccount(accountName, domainId, accountId);
|
||||
if(retAccount != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
if(name != null){
|
||||
region.setName(name);
|
||||
}
|
||||
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully enabled account :"+accountUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while enabling account :"+accountUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return retAccount;
|
||||
} else {
|
||||
//First disable account in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
Account retAccount = RegionsApiUtil.makeAccountAPICall(region, command, params);
|
||||
if (retAccount != null) {
|
||||
s_logger.debug("Successfully enabled account :"+accountUUID+" in source Region: "+region.getId());
|
||||
return retAccount;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while enabling account :"+accountUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
if(endPoint != null){
|
||||
region.setEndPoint(endPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUser(DeleteUserCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
if(apiKey != null){
|
||||
region.setApiKey(apiKey);
|
||||
}
|
||||
|
||||
UserVO user = _userDao.findById(id);
|
||||
if(secretKey != null){
|
||||
region.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
|
||||
}
|
||||
|
||||
String userUUID = user.getUuid();
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "deleteUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, userUUID));
|
||||
|
||||
if(getId() == regionId){
|
||||
if(_accountMgr.deleteUser(cmd)){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted user :"+userUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while deleting account :"+userUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//First delete in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted user :"+userUUID+" in source Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting user :"+userUUID+" in source Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_regionDao.update(id, region);
|
||||
return _regionDao.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
DomainVO domain = _domainDao.findById(id);
|
||||
if(domain == null){
|
||||
throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
|
||||
}
|
||||
|
||||
String domainUUID = domain.getUuid();
|
||||
|
||||
String command = "updateDomain";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, domainUUID));
|
||||
params.add(new NameValuePair(ApiConstants.NAME, cmd.getDomainName()));
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, cmd.getNetworkDomain()));
|
||||
|
||||
int regionId = domain.getRegionId();
|
||||
if(getId() == regionId){
|
||||
Domain updatedDomain = _domainMgr.updateDomain(cmd);
|
||||
if(updatedDomain != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated updatedDomain :"+domainUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while updating updatedDomain :"+domainUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return updatedDomain;
|
||||
} else {
|
||||
//First update in the Region where domain was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
RegionDomain updatedDomain = RegionsApiUtil.makeDomainAPICall(region, command, params);
|
||||
if (updatedDomain != null) {
|
||||
Long parentId = _identityDao.getIdentityId("domain", updatedDomain.getParentUuid());
|
||||
updatedDomain.setParent(parentId);
|
||||
s_logger.debug("Successfully updated user :"+domainUUID+" in source Region: "+region.getId());
|
||||
return (DomainVO)updatedDomain;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating user :"+domainUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteDomain(Long id, Boolean cleanup) {
|
||||
DomainVO domain = _domainDao.findById(id);
|
||||
if(domain == null){
|
||||
throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
|
||||
}
|
||||
|
||||
String domainUUID = domain.getUuid();
|
||||
|
||||
String command = "deleteDomain";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, domainUUID));
|
||||
params.add(new NameValuePair(ApiConstants.CLEANUP, cleanup.toString()));
|
||||
|
||||
int regionId = domain.getRegionId();
|
||||
if(getId() == regionId){
|
||||
if(_domainMgr.deleteDomain(id, cleanup)){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted domain :"+domainUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while deleting domain :"+domainUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
//First delete in the Region where domain is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted domain :"+domainUUID+" in Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting domain :"+domainUUID+" in Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean removeRegion(int id) {
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
if(region == null){
|
||||
throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
|
||||
}
|
||||
return _regionDao.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount updateUser(UpdateUserCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
|
||||
UserVO user = _userDao.findById(id);
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
|
||||
}
|
||||
|
||||
String userUUID = user.getUuid();
|
||||
|
||||
String command = "updateUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, userUUID));
|
||||
params.add(new NameValuePair(ApiConstants.API_KEY, cmd.getApiKey()));
|
||||
params.add(new NameValuePair(ApiConstants.EMAIL, cmd.getEmail()));
|
||||
params.add(new NameValuePair(ApiConstants.FIRSTNAME, cmd.getFirstname()));
|
||||
params.add(new NameValuePair(ApiConstants.LASTNAME, cmd.getLastname()));
|
||||
params.add(new NameValuePair(ApiConstants.PASSWORD, cmd.getPassword()));
|
||||
params.add(new NameValuePair(ApiConstants.SECRET_KEY, cmd.getSecretKey()));
|
||||
params.add(new NameValuePair(ApiConstants.TIMEZONE, cmd.getTimezone()));
|
||||
params.add(new NameValuePair(ApiConstants.USERNAME, cmd.getUsername()));
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
if(getId() == regionId){
|
||||
UserAccount updateUser = _accountMgr.updateUser(cmd);
|
||||
if(updateUser != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated user :"+userUUID+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while updating user :"+userUUID+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return updateUser;
|
||||
} else {
|
||||
//First update in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
UserAccount updateUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
|
||||
if (updateUser != null) {
|
||||
s_logger.debug("Successfully updated user :"+userUUID+" in source Region: "+region.getId());
|
||||
return updateUser;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating user :"+userUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount disableUser(Long userId) {
|
||||
UserVO user = _userDao.findById(userId);
|
||||
if (user == null || user.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||
}
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "disableUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
|
||||
|
||||
if(getId() == regionId){
|
||||
UserAccount disabledUser = _accountMgr.disableUser(userId);
|
||||
if(disabledUser != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully disabled user :"+user.getUuid()+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while disabling user :"+user.getUuid()+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return disabledUser;
|
||||
} else {
|
||||
//First disable in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
UserAccount disabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
|
||||
if (disabledUser != null) {
|
||||
s_logger.debug("Successfully disabled user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
return disabledUser;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while disabling user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount enableUser(long userId) {
|
||||
UserVO user = _userDao.findById(userId);
|
||||
if (user == null || user.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||
}
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "enableUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
|
||||
|
||||
if(getId() == regionId){
|
||||
UserAccount enabledUser = _accountMgr.enableUser(userId);
|
||||
if(enabledUser != null){
|
||||
List<RegionVO> regions = _regionDao.listAll();
|
||||
for (Region region : regions){
|
||||
if(region.getId() == getId()){
|
||||
continue;
|
||||
}
|
||||
params.add(new NameValuePair(ApiConstants.IS_PROPAGATE, "true"));
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully enabled user :"+user.getUuid()+" in Region: "+region.getId());
|
||||
} else {
|
||||
s_logger.error("Error while disabling user :"+user.getUuid()+" in Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return enabledUser;
|
||||
} else {
|
||||
//First enable in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
UserAccount enabledUser = RegionsApiUtil.makeUserAccountAPICall(region, command, params);
|
||||
if (enabledUser != null) {
|
||||
s_logger.debug("Successfully enabled user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
return enabledUser;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while enabling user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@Override
|
||||
public List<RegionVO> listRegions(Integer id, String name) {
|
||||
List<RegionVO> regions = new ArrayList<RegionVO>();
|
||||
if(id != null){
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
if(region != null){
|
||||
regions.add(region);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
if(name != null){
|
||||
RegionVO region = _regionDao.findByName(name);
|
||||
if(region != null){
|
||||
regions.add(region);
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
return _regionDao.listAll();
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ import com.cloud.utils.component.ManagerBase;
|
||||
@Local(value = { RegionService.class })
|
||||
public class RegionServiceImpl extends ManagerBase implements RegionService, Manager {
|
||||
public static final Logger s_logger = Logger.getLogger(RegionServiceImpl.class);
|
||||
|
||||
|
||||
@Inject
|
||||
private RegionDao _regionDao;
|
||||
@Inject
|
||||
@ -72,15 +72,15 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
|
||||
private AccountManager _accountMgr;
|
||||
@Inject
|
||||
private DomainManager _domainMgr;
|
||||
|
||||
|
||||
private String _name;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
_name = name;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
@ -99,203 +99,121 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.addRegion(id, name, endPoint, apiKey, secretKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.updateRegion(id, name, endPoint, apiKey, secretKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean removeRegion(int id) {
|
||||
return _regionMgr.removeRegion(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<? extends Region> listRegions(ListRegionsCmd cmd) {
|
||||
return _regionMgr.listRegions(cmd.getId(), cmd.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserAccount(DeleteAccountCmd cmd) {
|
||||
boolean result = false;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
result = _accountMgr.deleteUserAccount(cmd.getId());
|
||||
} else {
|
||||
result = _regionMgr.deleteUserAccount(cmd.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account updateAccount(UpdateAccountCmd cmd) {
|
||||
Account result = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
result = _accountMgr.updateAccount(cmd);
|
||||
} else {
|
||||
result = _regionMgr.updateAccount(cmd);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account disableAccount(DisableAccountCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
Account result = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
if(cmd.getLockRequested())
|
||||
result = _accountMgr.lockAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
|
||||
else
|
||||
result = _accountMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
|
||||
} else {
|
||||
result = _regionMgr.disableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId(), cmd.getLockRequested());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account enableAccount(EnableAccountCmd cmd) {
|
||||
Account result = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
result = _accountMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
|
||||
} else {
|
||||
result = _regionMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUser(DeleteUserCmd cmd) {
|
||||
boolean result = false;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
result = _accountMgr.deleteUser(cmd);
|
||||
} else {
|
||||
result = _regionMgr.deleteUser(cmd);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
Domain domain = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
domain = _domainMgr.updateDomain(cmd);
|
||||
} else {
|
||||
domain = _regionMgr.updateDomain(cmd);
|
||||
}
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteDomain(DeleteDomainCmd cmd) {
|
||||
boolean result = false;
|
||||
if(checkIsPropagate(cmd.isPropagate())){
|
||||
result = _domainMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
|
||||
} else {
|
||||
result = _regionMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount updateUser(UpdateUserCmd cmd){
|
||||
UserAccount user = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
user = _accountMgr.updateUser(cmd);
|
||||
} else {
|
||||
user = _regionMgr.updateUser(cmd);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount disableUser(DisableUserCmd cmd) {
|
||||
UserAccount user = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
user = _accountMgr.disableUser(cmd.getId());
|
||||
} else {
|
||||
user = _regionMgr.disableUser(cmd.getId());
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount enableUser(EnableUserCmd cmd) {
|
||||
UserAccount user = null;
|
||||
if(checkIsPropagate(cmd.getIsPropagate())){
|
||||
user = _accountMgr.enableUser(cmd.getId());
|
||||
} else {
|
||||
user = _regionMgr.enableUser(cmd.getId());
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
private boolean isRootAdmin(short accountType) {
|
||||
return (accountType == Account.ACCOUNT_TYPE_ADMIN);
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.addRegion(id, name, endPoint, apiKey, secretKey);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check isPopagate flag, Only ROOT Admin can use this param
|
||||
* @param isPopagate
|
||||
* @return
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.updateRegion(id, name, endPoint, apiKey, secretKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean removeRegion(int id) {
|
||||
return _regionMgr.removeRegion(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public List<? extends Region> listRegions(ListRegionsCmd cmd) {
|
||||
return _regionMgr.listRegions(cmd.getId(), cmd.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserAccount(DeleteAccountCmd cmd) {
|
||||
return _accountMgr.deleteUserAccount(cmd.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
private boolean checkIsPropagate(Boolean isPopagate){
|
||||
if(isPopagate == null || !isPopagate){
|
||||
return false;
|
||||
}
|
||||
// Only Admin can use isPopagate flag
|
||||
UserContext ctx = UserContext.current();
|
||||
Account caller = ctx.getCaller();
|
||||
if(!isRootAdmin(caller.getType())){
|
||||
throw new PermissionDeniedException("isPropagate param cannot be used by non ROOT Admin");
|
||||
}
|
||||
return true;
|
||||
@Override
|
||||
public Account updateAccount(UpdateAccountCmd cmd) {
|
||||
return _accountMgr.updateAccount(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Account enableAccount(EnableAccountCmd cmd) {
|
||||
return _accountMgr.enableAccount(cmd.getAccountName(), cmd.getDomainId(), cmd.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUser(DeleteUserCmd cmd) {
|
||||
return _accountMgr.deleteUser(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
return _domainMgr.updateDomain(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteDomain(DeleteDomainCmd cmd) {
|
||||
return _domainMgr.deleteDomain(cmd.getId(), cmd.getCleanup());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount updateUser(UpdateUserCmd cmd){
|
||||
return _accountMgr.updateUser(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount disableUser(DisableUserCmd cmd) {
|
||||
return _accountMgr.disableUser(cmd.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UserAccount enableUser(EnableUserCmd cmd) {
|
||||
return _accountMgr.enableUser(cmd.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,306 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -325,30 +325,28 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserAccount createUserAccount(String userName, String password,
|
||||
String firstName, String lastName, String email, String timezone,
|
||||
String accountName, short accountType, Long domainId,
|
||||
String networkDomain, Map<String, String> details,
|
||||
String accountUUID, String userUUID, Integer regionId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public UserAccount createUserAccount(String userName, String password,
|
||||
String firstName, String lastName, String email, String timezone,
|
||||
String accountName, short accountType, Long domainId,
|
||||
String networkDomain, Map<String, String> details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User createUser(String userName, String password, String firstName,
|
||||
String lastName, String email, String timeZone, String accountName,
|
||||
Long domainId, String userUUID, Integer regionId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public User createUser(String userName, String password, String firstName,
|
||||
String lastName, String email, String timeZone, String accountName,
|
||||
Long domainId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account createAccount(String accountName, short accountType,
|
||||
Long domainId, String networkDomain, Map details, String uuid,
|
||||
int regionId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Account createAccount(String accountName, short accountType,
|
||||
Long domainId, String networkDomain, Map details) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public RoleType getRoleType(Account account) {
|
||||
return null;
|
||||
|
||||
@ -137,24 +137,24 @@ public class MockDomainManagerImpl extends ManagerBase implements DomainManager,
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId,
|
||||
String networkDomain, String domainUUID, Integer regionId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId,
|
||||
String networkDomain) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId,
|
||||
String networkDomain, String domainUUID, Integer regionId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId,
|
||||
String networkDomain) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -43,32 +43,19 @@ public class RegionManagerTest extends TestCase {
|
||||
protected void setUp() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUniqueName() {
|
||||
RegionManagerImpl regionMgr = new RegionManagerImpl();
|
||||
RegionDao regionDao = Mockito.mock(RegionDao.class);
|
||||
RegionVO region = new RegionVO(2, "APAC", "", null, null);
|
||||
Mockito.when(regionDao.findByName(Mockito.anyString())).thenReturn(region);
|
||||
regionMgr._regionDao = regionDao;
|
||||
try {
|
||||
regionMgr.addRegion(2, "APAC", "", null, null);
|
||||
} catch (InvalidParameterValueException e){
|
||||
Assert.assertEquals("Region with name: APAC already exists", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserDelete() {
|
||||
RegionManagerImpl regionMgr = new RegionManagerImpl();
|
||||
AccountDao accountDao = Mockito.mock(AccountDao.class);
|
||||
Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(null);
|
||||
regionMgr._accountDao = accountDao;
|
||||
try {
|
||||
regionMgr.deleteUserAccount(5);
|
||||
} catch (InvalidParameterValueException e){
|
||||
Assert.assertEquals("The specified account does not exist in the system", e.getMessage());
|
||||
}
|
||||
RegionManagerImpl regionMgr = new RegionManagerImpl();
|
||||
RegionDao regionDao = Mockito.mock(RegionDao.class);
|
||||
RegionVO region = new RegionVO(2, "APAC", "", null, null);
|
||||
Mockito.when(regionDao.findByName(Mockito.anyString())).thenReturn(region);
|
||||
regionMgr._regionDao = regionDao;
|
||||
try {
|
||||
regionMgr.addRegion(2, "APAC", "", null, null);
|
||||
} catch (InvalidParameterValueException e){
|
||||
Assert.assertEquals("Region with name: APAC already exists", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -260,15 +260,6 @@ CREATE TABLE `cloud`.`region` (
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `cloud`.`region_sync` (
|
||||
`id` bigint unsigned NOT NULL auto_increment,
|
||||
`region_id` int unsigned NOT NULL,
|
||||
`api` varchar(1024) NOT NULL,
|
||||
`created` datetime NOT NULL COMMENT 'date created',
|
||||
`processed` tinyint NOT NULL default '0',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','','');
|
||||
ALTER TABLE `cloud`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
ALTER TABLE `cloud`.`user` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user