mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1636: Removed the concept of owner region.
Removed region_id from user/account and domain tables. Removed forwarding of api calls to owner region. Removed api_key and secret_key from region table. Included related DB upgrade changes.
This commit is contained in:
parent
c9082c9126
commit
2dd31f331d
|
|
@ -62,5 +62,4 @@ public interface Domain extends OwnedBy, Identity, InternalIdentity {
|
|||
|
||||
public String getUuid();
|
||||
|
||||
int getRegionId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,5 @@ public interface Account extends ControlledEntity, InternalIdentity, Identity {
|
|||
|
||||
public Long getDefaultZoneId();
|
||||
|
||||
public int getRegionId();
|
||||
|
||||
public String getUuid();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
Map<String, String> details, String accountUUID, String userUUID);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID);
|
||||
|
||||
boolean isAdmin(short accountType);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import com.cloud.utils.Pair;
|
|||
|
||||
public interface DomainService {
|
||||
|
||||
Domain createDomain(String name, Long parentId, String networkDomain);
|
||||
Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID);
|
||||
|
||||
Domain getDomain(long id);
|
||||
|
||||
|
|
|
|||
|
|
@ -73,5 +73,4 @@ public interface User extends OwnedBy, InternalIdentity {
|
|||
|
||||
boolean isRegistered();
|
||||
|
||||
public int getRegionId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ 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.ACCOUNT_ID, type=CommandType.STRING, description="Account UUID, required for adding account from external provisioning system")
|
||||
private String accountUUID;
|
||||
|
||||
@Parameter(name=ApiConstants.USER_ID, type=CommandType.STRING, description="User UUID, required for adding account from external provisioning system")
|
||||
private String userUUID;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -133,6 +138,14 @@ public class CreateAccountCmd extends BaseCmd {
|
|||
return params;
|
||||
}
|
||||
|
||||
public String getAccountUUID() {
|
||||
return accountUUID;
|
||||
}
|
||||
|
||||
public String getUserUUID() {
|
||||
return userUUID;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -151,7 +164,7 @@ public class CreateAccountCmd extends BaseCmd {
|
|||
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());
|
||||
getDomainId(), getNetworkDomain(), getDetails(), getAccountUUID(), getUserUUID());
|
||||
if (userAccount != null) {
|
||||
AccountResponse response = _responseGenerator.createUserAccountResponse(userAccount);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ 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;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -65,6 +68,10 @@ public class CreateDomainCmd extends BaseCmd {
|
|||
return networkDomain;
|
||||
}
|
||||
|
||||
public String getDomainUUID() {
|
||||
return domainUUID;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -82,7 +89,7 @@ public class CreateDomainCmd extends BaseCmd {
|
|||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
|
||||
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
|
||||
Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain(), getDomainUUID());
|
||||
if (domain != null) {
|
||||
DomainResponse response = _responseGenerator.createDomainResponse(domain);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -49,12 +49,6 @@ public class AddRegionCmd extends BaseCmd {
|
|||
@Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, required=true, description="Region service endpoint")
|
||||
private String endPoint;
|
||||
|
||||
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="API key of Admin user")
|
||||
private String apiKey;
|
||||
|
||||
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="Secret Key of Admin user")
|
||||
private String secretKey;
|
||||
|
||||
@Inject public RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -73,14 +67,6 @@ public class AddRegionCmd extends BaseCmd {
|
|||
return endPoint;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -97,7 +83,7 @@ public class AddRegionCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public void execute(){
|
||||
Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint(), getApiKey(), getSecretKey());
|
||||
Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint());
|
||||
if (region != null) {
|
||||
RegionResponse response = _responseGenerator.createRegionResponse(region);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -49,12 +49,6 @@ public class UpdateRegionCmd extends BaseCmd {
|
|||
@Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, description="updates region with this end point")
|
||||
private String endPoint;
|
||||
|
||||
@Parameter(name=ApiConstants.API_KEY, type=CommandType.STRING, description="new API key for the Region")
|
||||
private String apiKey;
|
||||
|
||||
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="new Secret Key for the Region")
|
||||
private String secretKey;
|
||||
|
||||
@Inject RegionService _regionService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -73,13 +67,6 @@ public class UpdateRegionCmd extends BaseCmd {
|
|||
return endPoint;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -96,7 +83,7 @@ public class UpdateRegionCmd extends BaseCmd {
|
|||
|
||||
@Override
|
||||
public void execute(){
|
||||
Region region = _regionService.updateRegion(getId(), getRegionName(), getEndPoint(), getApiKey(), getSecretKey());
|
||||
Region region = _regionService.updateRegion(getId(), getRegionName(), getEndPoint());
|
||||
if (region != null) {
|
||||
RegionResponse response = _responseGenerator.createRegionResponse(region);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -65,6 +65,9 @@ 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 external provisioning system")
|
||||
private String userUUID;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -101,6 +104,10 @@ public class CreateUserCmd extends BaseCmd {
|
|||
return username;
|
||||
}
|
||||
|
||||
public String getUserUUID() {
|
||||
return userUUID;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -132,7 +139,7 @@ public class CreateUserCmd extends BaseCmd {
|
|||
@Override
|
||||
public void execute(){
|
||||
UserContext.current().setEventDetails("UserName: "+getUserName()+", FirstName :"+getFirstName()+", LastName: "+getLastName());
|
||||
User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId());
|
||||
User user = _accountService.createUser(getUserName(), getPassword(), getFirstName(), getLastName(), getEmail(), getTimezone(), getAccountName(), getDomainId(), getUserUUID());
|
||||
if (user != null) {
|
||||
UserResponse response = _responseGenerator.createUserResponse(user);
|
||||
response.setResponseName(getCommandName());
|
||||
|
|
|
|||
|
|
@ -29,7 +29,4 @@ public interface Region {
|
|||
|
||||
public String getEndPoint();
|
||||
|
||||
public String getApiKey();
|
||||
|
||||
public String getSecretKey();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,22 +43,18 @@ public interface RegionService {
|
|||
* @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);
|
||||
public Region addRegion(int id, String name, String endPoint);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
public Region updateRegion(int id, String name, String endPoint);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class RegionCmdTest extends TestCase {
|
|||
|
||||
Region region = Mockito.mock(Region.class);
|
||||
Mockito.when(
|
||||
regionService.addRegion(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
regionService.addRegion(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn(region);
|
||||
|
||||
addRegionCmd._regionService = regionService;
|
||||
|
|
@ -87,7 +87,7 @@ public class RegionCmdTest extends TestCase {
|
|||
|
||||
Region region = Mockito.mock(Region.class);
|
||||
Mockito.when(
|
||||
regionService.addRegion(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
regionService.addRegion(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn(null);
|
||||
|
||||
addRegionCmd._regionService = regionService;
|
||||
|
|
|
|||
|
|
@ -66,9 +66,6 @@ public class AccountVO implements Account {
|
|||
@Column(name="default_zone_id")
|
||||
private Long defaultZoneId = null;
|
||||
|
||||
@Column(name="region_id")
|
||||
private int regionId;
|
||||
|
||||
public AccountVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
|
@ -78,14 +75,13 @@ public class AccountVO implements Account {
|
|||
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, String uuid) {
|
||||
this.accountName = accountName;
|
||||
this.domainId = domainId;
|
||||
this.networkDomain = networkDomain;
|
||||
this.type = type;
|
||||
this.state = State.enabled;
|
||||
this.uuid = uuid;
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
public void setNeedsCleanup(boolean value) {
|
||||
|
|
@ -183,11 +179,4 @@ public class AccountVO implements Account {
|
|||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,9 +93,6 @@ public class UserVO implements User, Identity, InternalIdentity {
|
|||
@Column(name="uuid")
|
||||
private String uuid;
|
||||
|
||||
@Column(name="region_id")
|
||||
private int regionId;
|
||||
|
||||
public UserVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
|
@ -105,7 +102,7 @@ public class UserVO implements User, Identity, InternalIdentity {
|
|||
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, String uuid) {
|
||||
this.accountId = accountId;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
|
|
@ -115,7 +112,6 @@ public class UserVO implements User, Identity, InternalIdentity {
|
|||
this.timezone = timezone;
|
||||
this.state = State.enabled;
|
||||
this.uuid = uuid;
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -266,11 +262,4 @@ public class UserVO implements User, Identity, InternalIdentity {
|
|||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,12 +75,9 @@ public class DomainVO implements Domain {
|
|||
@Column(name="uuid")
|
||||
private String uuid;
|
||||
|
||||
@Column(name="region_id")
|
||||
private int regionId;
|
||||
|
||||
public DomainVO() {}
|
||||
|
||||
public DomainVO(String name, long owner, Long parentId, String networkDomain, int regionId) {
|
||||
public DomainVO(String name, long owner, Long parentId, String networkDomain) {
|
||||
this.parent = parentId;
|
||||
this.name = name;
|
||||
this.accountId = owner;
|
||||
|
|
@ -89,10 +86,9 @@ public class DomainVO implements Domain {
|
|||
this.state = Domain.State.Active;
|
||||
this.networkDomain = networkDomain;
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
public DomainVO(String name, long owner, Long parentId, String networkDomain, String uuid, int regionId) {
|
||||
public DomainVO(String name, long owner, Long parentId, String networkDomain, String uuid) {
|
||||
this.parent = parentId;
|
||||
this.name = name;
|
||||
this.accountId = owner;
|
||||
|
|
@ -101,7 +97,6 @@ public class DomainVO implements Domain {
|
|||
this.state = Domain.State.Active;
|
||||
this.networkDomain = networkDomain;
|
||||
this.uuid = uuid;
|
||||
this.regionId = regionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -216,12 +211,5 @@ public class DomainVO implements Domain {
|
|||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public int getRegionId() {
|
||||
return regionId;
|
||||
}
|
||||
|
||||
public void setRegionId(int regionId) {
|
||||
this.regionId = regionId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,7 +205,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, UUID.randomUUID().toString(), 0);
|
||||
Account projectAccount = _accountMgr.createAccount(acctNm.toString(), Account.ACCOUNT_TYPE_PROJECT, domainId, null, null, UUID.randomUUID().toString());
|
||||
|
||||
Project project = _projectDao.persist(new ProjectVO(name, displayText, owner.getDomainId(), projectAccount.getId()));
|
||||
|
||||
|
|
|
|||
|
|
@ -88,30 +88,6 @@ public class Upgrade40to41 implements DbUpgrade {
|
|||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in account table
|
||||
s_logger.debug("Updating account table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`account` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in user table
|
||||
s_logger.debug("Updating user table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`user` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in domain table
|
||||
s_logger.debug("Updating domain table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`domain` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in cloud_usage account table
|
||||
s_logger.debug("Updating cloud_usage account table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud_usage`.`account` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Successfully updated region entries with regionId: "+region_id);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Error while updating region entries", e);
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ public interface AccountManager extends AccountService {
|
|||
|
||||
Long checkAccessAndSpecifyAuthority(Account caller, Long zoneId);
|
||||
|
||||
Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details, String uuid, int regionId);
|
||||
Account createAccount(String accountName, short accountType, Long domainId, String networkDomain, Map details, String uuid);
|
||||
|
||||
UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone);
|
||||
UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID);
|
||||
|
||||
/**
|
||||
* Logs out a user
|
||||
|
|
|
|||
|
|
@ -54,9 +54,6 @@ import com.cloud.api.ApiDBUtils;
|
|||
import com.cloud.api.query.dao.UserAccountJoinDao;
|
||||
import com.cloud.api.query.vo.ControlledViewEntity;
|
||||
|
||||
|
||||
import org.apache.cloudstack.region.RegionManager;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.ResourceLimit;
|
||||
|
|
@ -217,8 +214,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
@Inject
|
||||
private IPAddressDao _ipAddressDao;
|
||||
@Inject
|
||||
private RegionManager _regionMgr;
|
||||
@Inject
|
||||
private VpcManager _vpcMgr;
|
||||
@Inject
|
||||
private DomainRouterDao _routerDao;
|
||||
|
|
@ -764,7 +759,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) {
|
||||
Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
|
||||
|
||||
if (accountName == null) {
|
||||
accountName = userName;
|
||||
|
|
@ -810,11 +805,14 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
txn.start();
|
||||
|
||||
// create account
|
||||
AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, UUID.randomUUID().toString(), _regionMgr.getId());
|
||||
if(accountUUID == null){
|
||||
accountUUID = UUID.randomUUID().toString();
|
||||
}
|
||||
AccountVO account = createAccount(accountName, accountType, domainId, networkDomain, details, accountUUID);
|
||||
long accountId = account.getId();
|
||||
|
||||
// create the first user for the account
|
||||
UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone);
|
||||
UserVO user = createUser(accountId, userName, password, firstName, lastName, email, timezone, userUUID);
|
||||
|
||||
if (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
|
||||
// set registration token
|
||||
|
|
@ -829,7 +827,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
}
|
||||
|
||||
@Override
|
||||
public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId) {
|
||||
public UserVO createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID) {
|
||||
|
||||
// default domain to ROOT if not specified
|
||||
if (domainId == null) {
|
||||
|
|
@ -858,7 +856,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
throw new CloudRuntimeException("The user " + userName + " already exists in domain " + domainId);
|
||||
}
|
||||
UserVO user = null;
|
||||
user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
|
||||
user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone, userUUID);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
|
@ -1646,7 +1644,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, String uuid) {
|
||||
// Validate domain
|
||||
Domain domain = _domainMgr.getDomain(domainId);
|
||||
if (domain == null) {
|
||||
|
|
@ -1690,7 +1688,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, uuid));
|
||||
|
||||
if (account == null) {
|
||||
throw new CloudRuntimeException("Failed to create account name " + accountName + " in domain id=" + domainId);
|
||||
|
|
@ -1714,7 +1712,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_USER_CREATE, eventDescription = "creating User")
|
||||
public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone) {
|
||||
public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Creating user: " + userName + ", accountId: " + accountId + " timezone:" + timezone);
|
||||
}
|
||||
|
|
@ -1730,30 +1728,10 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
throw new CloudRuntimeException("Failed to encode password");
|
||||
}
|
||||
|
||||
UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, 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);
|
||||
if(userUUID == null){
|
||||
userUUID = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
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, userUUID));
|
||||
|
||||
return user;
|
||||
}
|
||||
|
|
@ -1983,7 +1961,6 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
|||
|
||||
@Override @DB
|
||||
public String[] createApiKeyAndSecretKey(RegisterCmd cmd) {
|
||||
//Send keys to other Regions
|
||||
Long userId = cmd.getId();
|
||||
|
||||
User user = getUserIncludingRemoved(userId);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, String domainUUID);
|
||||
|
||||
Set<Long> getDomainParentIds(long domainId);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@
|
|||
// under the License.
|
||||
package com.cloud.user;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -118,7 +115,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) {
|
||||
public Domain createDomain(String name, Long parentId, String networkDomain, String domainUUID) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
if (parentId == null) {
|
||||
|
|
@ -136,13 +133,13 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||
|
||||
_accountMgr.checkAccess(caller, parentDomain);
|
||||
|
||||
return createDomain(name, parentId, caller.getId(), networkDomain);
|
||||
return createDomain(name, parentId, caller.getId(), networkDomain, domainUUID);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain) {
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId, String networkDomain, String domainUUID) {
|
||||
// Verify network domain
|
||||
if (networkDomain != null) {
|
||||
if (!NetUtils.verifyDomainName(networkDomain)) {
|
||||
|
|
@ -161,10 +158,13 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||
throw new InvalidParameterValueException("Domain with name " + name + " already exists for the parent id=" + parentId);
|
||||
}
|
||||
|
||||
if(domainUUID == null){
|
||||
domainUUID = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
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, domainUUID));
|
||||
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
|
||||
txn.commit();
|
||||
return domain;
|
||||
|
|
|
|||
|
|
@ -43,11 +43,9 @@ public interface RegionManager {
|
|||
* @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);
|
||||
Region addRegion(int id, String name, String endPoint);
|
||||
|
||||
/**
|
||||
* Update details of the Region with specified Id
|
||||
|
|
@ -59,7 +57,7 @@ public interface RegionManager {
|
|||
* @param secretKey
|
||||
* @return Returns update Region object
|
||||
*/
|
||||
Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
|
||||
Region updateRegion(int id, String name, String endPoint);
|
||||
|
||||
/**
|
||||
* @param id
|
||||
|
|
|
|||
|
|
@ -17,30 +17,22 @@
|
|||
package org.apache.cloudstack.region;
|
||||
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.domain.dao.DomainDao;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.DomainManager;
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.user.UserVO;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserAccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
|
||||
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
|
||||
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
|
||||
import org.apache.cloudstack.region.dao.RegionDao;
|
||||
import org.apache.commons.httpclient.NameValuePair;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -63,13 +55,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
@Inject
|
||||
private AccountManager _accountMgr;
|
||||
@Inject
|
||||
private UserDao _userDao;
|
||||
@Inject
|
||||
private DomainDao _domainDao;
|
||||
@Inject
|
||||
private DomainManager _domainMgr;
|
||||
@Inject
|
||||
private UserAccountDao _userAccountDao;
|
||||
|
||||
private String _name;
|
||||
private int _id;
|
||||
|
|
@ -104,7 +90,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
public Region addRegion(int id, String name, String endPoint) {
|
||||
//Region Id should be unique
|
||||
if( _regionDao.findById(id) != null ){
|
||||
throw new InvalidParameterValueException("Region with id: "+id+" already exists");
|
||||
|
|
@ -113,7 +99,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
if( _regionDao.findByName(name) != null ){
|
||||
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
|
||||
}
|
||||
RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
|
||||
RegionVO region = new RegionVO(id, name, endPoint);
|
||||
return _regionDao.persist(region);
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +107,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
public Region updateRegion(int id, String name, String endPoint) {
|
||||
RegionVO region = _regionDao.findById(id);
|
||||
|
||||
if(region == null){
|
||||
|
|
@ -144,14 +130,6 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
region.setEndPoint(endPoint);
|
||||
}
|
||||
|
||||
if(apiKey != null){
|
||||
region.setApiKey(apiKey);
|
||||
}
|
||||
|
||||
if(secretKey != null){
|
||||
region.setSecretKey(secretKey);
|
||||
}
|
||||
|
||||
_regionDao.update(id, region);
|
||||
return _regionDao.findById(id);
|
||||
}
|
||||
|
|
@ -196,30 +174,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public boolean deleteUserAccount(long accountId) {
|
||||
AccountVO account = _accountDao.findById(accountId);
|
||||
if(account == null){
|
||||
throw new InvalidParameterValueException("The specified account does not exist in the system");
|
||||
}
|
||||
String accountUUID = account.getUuid();
|
||||
int regionId = account.getRegionId();
|
||||
|
||||
String command = "deleteAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.deleteUserAccount(accountId);
|
||||
} else {
|
||||
//First delete in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted account :"+accountUUID+" in Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting account :"+accountUUID+" in Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return _accountMgr.deleteUserAccount(accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -227,51 +182,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public Account updateAccount(UpdateAccountCmd cmd) {
|
||||
Long accountId = cmd.getId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
String accountName = cmd.getAccountName();
|
||||
String newAccountName = cmd.getNewName();
|
||||
String networkDomain = cmd.getNetworkDomain();
|
||||
//ToDo send details
|
||||
Map<String, String> details = cmd.getDetails();
|
||||
|
||||
Account account = null;
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
} else {
|
||||
account = _accountDao.findEnabledAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
// Check if account exists
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String command = "updateAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, account.getUuid()));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
|
||||
params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
|
||||
if(details != null){
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, details.toString()));
|
||||
}
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.updateAccount(cmd);
|
||||
} else {
|
||||
//First update in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated account :"+account.getUuid()+" in source Region: "+region.getId());
|
||||
return account;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating account :"+account.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _accountMgr.updateAccount(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -280,46 +191,12 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
@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);
|
||||
if(lockRequested){
|
||||
account = _accountMgr.lockAccount(accountName, domainId, accountId);
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String accountUUID = account.getUuid();
|
||||
|
||||
String command = "disableAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.LOCK, lockRequested.toString()));
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if(domain != null){
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
}
|
||||
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
Account retAccount = null;
|
||||
if(lockRequested){
|
||||
retAccount = _accountMgr.lockAccount(accountName, domainId, accountId);
|
||||
} else {
|
||||
retAccount = _accountMgr.disableAccount(accountName, domainId, accountId);
|
||||
}
|
||||
return retAccount;
|
||||
} else {
|
||||
//First disable account in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully disabled account :"+accountUUID+" in source Region: "+region.getId());
|
||||
return account;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while disabling account :"+accountUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
account = _accountMgr.disableAccount(accountName, domainId, accountId);
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -327,42 +204,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public Account enableAccount(String accountName, Long domainId, Long accountId) {
|
||||
// Check if account exists
|
||||
Account account = null;
|
||||
if (accountId != null) {
|
||||
account = _accountDao.findById(accountId);
|
||||
} else {
|
||||
account = _accountDao.findActiveAccount(accountName, domainId);
|
||||
}
|
||||
|
||||
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
|
||||
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
}
|
||||
|
||||
String accountUUID = account.getUuid();
|
||||
|
||||
String command = "enableAccount";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, accountUUID));
|
||||
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
|
||||
DomainVO domain = _domainDao.findById(domainId);
|
||||
if(domain != null){
|
||||
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domain.getUuid()));
|
||||
}
|
||||
|
||||
int regionId = account.getRegionId();
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.enableAccount(accountName, domainId, accountId);
|
||||
} else {
|
||||
//First disable account in the Region where account is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully enabled account :"+accountUUID+" in source Region: "+region.getId());
|
||||
return account;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while enabling account :"+accountUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _accountMgr.enableAccount(accountName, domainId, accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -370,34 +212,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public boolean deleteUser(DeleteUserCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
|
||||
UserVO user = _userDao.findById(id);
|
||||
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
|
||||
}
|
||||
|
||||
String userUUID = user.getUuid();
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "deleteUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, userUUID));
|
||||
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.deleteUser(cmd);
|
||||
} else {
|
||||
//First delete in the Region where user is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted user :"+userUUID+" in source Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting user :"+userUUID+" in source Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return _accountMgr.deleteUser(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -405,33 +220,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public Domain updateDomain(UpdateDomainCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
DomainVO domain = _domainDao.findById(id);
|
||||
if(domain == null){
|
||||
throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
|
||||
}
|
||||
|
||||
String domainUUID = domain.getUuid();
|
||||
|
||||
String command = "updateDomain";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, domainUUID));
|
||||
params.add(new NameValuePair(ApiConstants.NAME, cmd.getDomainName()));
|
||||
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, cmd.getNetworkDomain()));
|
||||
|
||||
int regionId = domain.getRegionId();
|
||||
if(getId() == regionId){
|
||||
return _domainMgr.updateDomain(cmd);
|
||||
} else {
|
||||
//First update in the Region where domain was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated user :"+domainUUID+" in source Region: "+region.getId());
|
||||
return domain;
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating user :"+domainUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _domainMgr.updateDomain(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -439,32 +228,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public boolean deleteDomain(Long id, Boolean cleanup) {
|
||||
DomainVO domain = _domainDao.findById(id);
|
||||
if(domain == null){
|
||||
throw new InvalidParameterValueException("The specified domain doesn't exist in the system");
|
||||
}
|
||||
|
||||
String domainUUID = domain.getUuid();
|
||||
|
||||
String command = "deleteDomain";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, domainUUID));
|
||||
params.add(new NameValuePair(ApiConstants.CLEANUP, cleanup.toString()));
|
||||
|
||||
int regionId = domain.getRegionId();
|
||||
if(getId() == regionId){
|
||||
return _domainMgr.deleteDomain(id, cleanup);
|
||||
} else {
|
||||
//First delete in the Region where domain is created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully deleted domain :"+domainUUID+" in Region: "+region.getId());
|
||||
return true;
|
||||
} else {
|
||||
s_logger.error("Error while deleting domain :"+domainUUID+" in Region: "+region.getId());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return _domainMgr.deleteDomain(id, cleanup);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -472,40 +236,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public UserAccount updateUser(UpdateUserCmd cmd) {
|
||||
long id = cmd.getId();
|
||||
|
||||
UserVO user = _userDao.findById(id);
|
||||
if (user == null) {
|
||||
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
|
||||
}
|
||||
|
||||
String userUUID = user.getUuid();
|
||||
|
||||
String command = "updateUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, userUUID));
|
||||
params.add(new NameValuePair(ApiConstants.API_KEY, cmd.getApiKey()));
|
||||
params.add(new NameValuePair(ApiConstants.EMAIL, cmd.getEmail()));
|
||||
params.add(new NameValuePair(ApiConstants.FIRSTNAME, cmd.getFirstname()));
|
||||
params.add(new NameValuePair(ApiConstants.LASTNAME, cmd.getLastname()));
|
||||
params.add(new NameValuePair(ApiConstants.PASSWORD, cmd.getPassword()));
|
||||
params.add(new NameValuePair(ApiConstants.SECRET_KEY, cmd.getSecretKey()));
|
||||
params.add(new NameValuePair(ApiConstants.TIMEZONE, cmd.getTimezone()));
|
||||
params.add(new NameValuePair(ApiConstants.USERNAME, cmd.getUsername()));
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.updateUser(cmd);
|
||||
} else {
|
||||
//First update in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully updated user :"+userUUID+" in source Region: "+region.getId());
|
||||
return _userAccountDao.findById(id);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while updating user :"+userUUID+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _accountMgr.updateUser(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -513,29 +244,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public UserAccount disableUser(Long userId) {
|
||||
UserVO user = _userDao.findById(userId);
|
||||
if (user == null || user.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||
}
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "disableUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
|
||||
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.disableUser(userId);
|
||||
} else {
|
||||
//First disable in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully disabled user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
return _userAccountDao.findById(userId);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while disabling user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _accountMgr.disableUser(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -543,29 +252,7 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager, Man
|
|||
*/
|
||||
@Override
|
||||
public UserAccount enableUser(long userId) {
|
||||
UserVO user = _userDao.findById(userId);
|
||||
if (user == null || user.getRemoved() != null) {
|
||||
throw new InvalidParameterValueException("Unable to find active user by id " + userId);
|
||||
}
|
||||
|
||||
int regionId = user.getRegionId();
|
||||
|
||||
String command = "enableUser";
|
||||
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
params.add(new NameValuePair(ApiConstants.ID, user.getUuid()));
|
||||
|
||||
if(getId() == regionId){
|
||||
return _accountMgr.enableUser(userId);
|
||||
} else {
|
||||
//First enable in the Region where user was created
|
||||
Region region = _regionDao.findById(regionId);
|
||||
if (RegionsApiUtil.makeAPICall(region, command, params)) {
|
||||
s_logger.debug("Successfully enabled user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
return _userAccountDao.findById(userId);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error while enabling user :"+user.getUuid()+" in source Region: "+region.getId());
|
||||
}
|
||||
}
|
||||
return _accountMgr.enableUser(userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,20 +78,20 @@ public class RegionServiceImpl extends ManagerBase implements RegionService, Man
|
|||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
public Region addRegion(int id, String name, String endPoint) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.addRegion(id, name, endPoint, apiKey, secretKey);
|
||||
return _regionMgr.addRegion(id, name, endPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
public Region updateRegion(int id, String name, String endPoint) {
|
||||
//Check for valid Name
|
||||
//Check valid end_point url
|
||||
return _regionMgr.updateRegion(id, name, endPoint, apiKey, secretKey);
|
||||
return _regionMgr.updateRegion(id, name, endPoint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,21 +36,13 @@ public class RegionVO implements Region{
|
|||
@Column(name="end_point")
|
||||
private String endPoint;
|
||||
|
||||
@Column(name="api_key")
|
||||
private String apiKey;
|
||||
|
||||
@Column(name="secret_key")
|
||||
private String secretKey;
|
||||
|
||||
public RegionVO() {
|
||||
}
|
||||
|
||||
public RegionVO(int id, String name, String endPoint, String apiKey, String secretKey) {
|
||||
public RegionVO(int id, String name, String endPoint) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.endPoint = endPoint;
|
||||
this.apiKey = apiKey;
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
|
@ -73,21 +65,4 @@ public class RegionVO implements Region{
|
|||
this.endPoint = endPoint;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,8 +227,8 @@ public class RegionsApiUtil {
|
|||
*/
|
||||
private static String buildUrl(String apiParams, Region region) {
|
||||
|
||||
String apiKey = region.getApiKey();
|
||||
String secretKey = region.getSecretKey();
|
||||
String apiKey = "";
|
||||
String secretKey = "";
|
||||
|
||||
|
||||
if (apiKey == null || secretKey == null) {
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
|||
}
|
||||
|
||||
@Override
|
||||
public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone) {
|
||||
public UserVO createUser(long accountId, String userName, String password, String firstName, String lastName, String email, String timezone, String userUUID) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -328,7 +328,7 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
|||
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 networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
@ -336,15 +336,14 @@ public class MockAccountManagerImpl extends ManagerBase implements Manager, Acco
|
|||
@Override
|
||||
public User createUser(String userName, String password, String firstName,
|
||||
String lastName, String email, String timeZone, String accountName,
|
||||
Long domainId) {
|
||||
Long domainId, String userUUID) {
|
||||
// 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) {
|
||||
Long domainId, String networkDomain, Map details, String uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ public class MockDomainManagerImpl extends ManagerBase implements DomainManager,
|
|||
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId,
|
||||
String networkDomain) {
|
||||
String networkDomain, String domainUUID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ public class MockDomainManagerImpl extends ManagerBase implements DomainManager,
|
|||
|
||||
@Override
|
||||
public Domain createDomain(String name, Long parentId, Long ownerId,
|
||||
String networkDomain) {
|
||||
String networkDomain, String domainUUID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,27 +48,14 @@ public class RegionManagerTest extends TestCase {
|
|||
public void testUniqueName() {
|
||||
RegionManagerImpl regionMgr = new RegionManagerImpl();
|
||||
RegionDao regionDao = Mockito.mock(RegionDao.class);
|
||||
RegionVO region = new RegionVO(2, "APAC", "", null, null);
|
||||
RegionVO region = new RegionVO(2, "APAC", "");
|
||||
Mockito.when(regionDao.findByName(Mockito.anyString())).thenReturn(region);
|
||||
regionMgr._regionDao = regionDao;
|
||||
try {
|
||||
regionMgr.addRegion(2, "APAC", "", null, null);
|
||||
regionMgr.addRegion(2, "APAC", "");
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,17 +258,10 @@ CREATE TABLE `cloud`.`region` (
|
|||
`id` int unsigned NOT NULL UNIQUE,
|
||||
`name` varchar(255) NOT NULL UNIQUE,
|
||||
`end_point` varchar(255) NOT NULL,
|
||||
`api_key` varchar(255),
|
||||
`secret_key` varchar(255),
|
||||
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';
|
||||
ALTER TABLE `cloud`.`domain` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api');
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Account Defaults', 'DEFAULT', 'management-server', 'max.account.cpus', '40', 'The default maximum number of cpu cores that can be used for an account');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue