- Separated RegionServiceImpl and RegionManagerImpl

- Added comments
- Changed package name to org.apache.cloudstack.region
This commit is contained in:
Kishan Kavala 2013-01-31 18:08:20 +05:30
parent e848a937df
commit 8b1a5b1de2
49 changed files with 1247 additions and 554 deletions

View File

@ -1,49 +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 com.cloud.region;
import java.util.List;
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.api.command.user.region.ListRegionsCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserAccount;
public interface RegionService {
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey);
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey);
public boolean removeRegion(int id);
public List<? extends Region> listRegions(ListRegionsCmd cmd);
boolean deleteUserAccount(long accountId);
Account updateAccount(UpdateAccountCmd cmd);
public Account disableAccount(String accountName, Long domainId, Long id, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException;
public Account enableAccount(String accountName, Long domainId, Long id);
public boolean deleteUser(DeleteUserCmd deleteUserCmd);
public boolean deleteDomain(Long id, Boolean cleanup);
public UserAccount updateUser(UpdateUserCmd updateUserCmd);
public Domain updateDomain(UpdateDomainCmd updateDomainCmd);
public UserAccount disableUser(Long id);
public UserAccount enableUser(Long id);
}

View File

@ -23,15 +23,10 @@ import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.RegisterCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.utils.Pair;
public interface AccountService {
@ -65,34 +60,6 @@ public interface AccountService {
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);
/**
* Deletes a user by userId
*
* @param accountId
* - id of the account do delete
*
* @return true if delete was successful, false otherwise
*/
boolean deleteUserAccount(long accountId);
/**
* Disables a user by userId
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount disableUser(long userId);
/**
* Enables a user
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount enableUser(long userId);
/**
* Locks a user by userId. A locked user cannot access the API, but will still have running VMs/IP addresses
* allocated/etc.
@ -102,72 +69,12 @@ public interface AccountService {
*/
UserAccount lockUser(long userId);
/**
* Update a user by userId
*
* @param userId
* @return UserAccount object
*/
UserAccount updateUser(UpdateUserCmd cmd);
/**
* Disables an account by accountName and domainId
*
* @param accountName
* TODO
* @param domainId
* TODO
* @param accountId
* @param disabled
* account if success
* @return true if disable was successful, false otherwise
*/
Account disableAccount(String accountName, Long domainId, Long accountId) 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);
/**
* Locks an account by accountId. A locked account cannot access the API, but will still have running VMs/IP
* addresses
* allocated/etc.
*
* @param accountName
* - the LockAccount command defining the accountId to be locked.
* @param domainId
* TODO
* @param accountId
* @return account object
*/
Account lockAccount(String accountName, Long domainId, Long accountId);
/**
* Updates an account name
*
* @param cmd
* - the parameter containing accountId
* @return updated account object
*/
Account updateAccount(UpdateAccountCmd cmd);
Account getSystemAccount();
User getSystemUser();
User createUser(String userName, String password, String firstName, String lastName, String email, String timeZone, String accountName, Long domainId, String userUUID, Integer regionId);
boolean deleteUser(DeleteUserCmd deleteUserCmd);
boolean isAdmin(short accountType);
Account finalizeOwner(Account caller, String accountName, Long domainId, Long projectId);

View File

@ -20,7 +20,6 @@ import java.util.List;
import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.PermissionDeniedException;
@ -42,21 +41,11 @@ public interface DomainService {
*/
boolean isChildDomain(Long parentId, Long childId);
boolean deleteDomain(long domainId, Boolean cleanup);
Pair<List<? extends Domain>, Integer> searchForDomains(ListDomainsCmd cmd)
throws PermissionDeniedException;
Pair<List<? extends Domain>, Integer> searchForDomainChildren(ListDomainChildrenCmd cmd)
throws PermissionDeniedException;
/**
* update an existing domain
*
* @param cmd
* - the command containing domainId and new domainName
* @return Domain object if the command succeeded
*/
Domain updateDomain(UpdateDomainCmd cmd);
/**
* find the domain by its path

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.regex.Pattern;
import org.apache.cloudstack.query.QueryService;
import org.apache.cloudstack.region.RegionService;
import org.apache.log4j.Logger;
import com.cloud.configuration.ConfigurationService;
@ -53,7 +54,6 @@ import com.cloud.network.vpn.RemoteAccessVpnService;
import com.cloud.network.vpn.Site2SiteVpnService;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectService;
import com.cloud.region.RegionService;
import com.cloud.resource.ResourceService;
import com.cloud.server.ManagementService;
import com.cloud.server.TaggedResourceService;

View File

@ -93,6 +93,7 @@ import org.apache.cloudstack.api.response.VpcOfferingResponse;
import org.apache.cloudstack.api.response.VpcResponse;
import org.apache.cloudstack.api.response.VpnUsersResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.region.Region;
import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
@ -143,7 +144,6 @@ import com.cloud.org.Cluster;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
import com.cloud.region.Region;
import com.cloud.server.ResourceTag;
import com.cloud.storage.GuestOS;
import com.cloud.storage.S3;

View File

@ -94,13 +94,8 @@ public class DeleteAccountCmd extends BaseAsyncCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("Account Id: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
boolean result = false;
if(isPopagate){
result = _accountService.deleteUserAccount(getId());
} else {
result = _regionService.deleteUserAccount(getId());
}
boolean result = _regionService.deleteUserAccount(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);

View File

@ -74,12 +74,16 @@ public class DisableAccountCmd extends BaseAsyncCmd {
public Boolean getIsPropagate() {
return isPropagate;
}
public Boolean getLockRequested() {
return lockRequested;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
@Override
public String getCommandName() {
return s_name;
}
@ -112,16 +116,7 @@ public class DisableAccountCmd extends BaseAsyncCmd {
@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException{
UserContext.current().setEventDetails("Account Name: "+getAccountName()+", Domain Id:"+getDomainId());
Account result = null;
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
if(isPopagate){
if(lockRequested)
result = _accountService.lockAccount(getAccountName(), getDomainId(), getId());
else
result = _accountService.disableAccount(getAccountName(), getDomainId(), getId());
} else {
result = _regionService.disableAccount(getAccountName(), getDomainId(), getId(), lockRequested);
}
Account result = _regionService.disableAccount(this);
if (result != null){
AccountResponse response = _responseGenerator.createAccountResponse(result);
response.setResponseName(getCommandName());

View File

@ -97,13 +97,7 @@ public class EnableAccountCmd extends BaseCmd {
@Override
public void execute(){
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
Account result = null;
if(isPopagate){
result = _accountService.enableAccount(getAccountName(), getDomainId(), getId());
} else {
result = _regionService.enableAccount(getAccountName(), getDomainId(), getId());
}
Account result = _regionService.enableAccount(this);
if (result != null){
AccountResponse response = _responseGenerator.createAccountResponse(result);
response.setResponseName(getCommandName());

View File

@ -127,13 +127,7 @@ public class UpdateAccountCmd extends BaseCmd{
@Override
public void execute(){
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
Account result = null;
if(isPopagate){
result = _accountService.updateAccount(this);
} else {
result = _regionService.updateAccount(this);
}
Account result = _regionService.updateAccount(this);
if (result != null){
AccountResponse response = _responseGenerator.createAccountResponse(result);
response.setResponseName(getCommandName());

View File

@ -95,12 +95,7 @@ public class DeleteDomainCmd extends BaseAsyncCmd {
public void execute(){
UserContext.current().setEventDetails("Domain Id: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
boolean result = false;
if(isPopagate){
result = _domainService.deleteDomain(id, cleanup);
} else {
result = _regionService.deleteDomain(id, cleanup);
}
boolean result = _regionService.deleteDomain(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);

View File

@ -85,13 +85,7 @@ public class UpdateDomainCmd extends BaseCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("Domain Id: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
Domain domain = null;
if(isPopagate){
domain = _domainService.updateDomain(this);
} else {
domain = _regionService.updateDomain(this);
}
Domain domain = _regionService.updateDomain(this);
if (domain != null) {
DomainResponse response = _responseGenerator.createDomainResponse(domain);

View File

@ -23,9 +23,9 @@ import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.RegionResponse;
import org.apache.cloudstack.region.Region;
import org.apache.log4j.Logger;
import com.cloud.region.Region;
import com.cloud.user.Account;
@APICommand(name = "addRegion", description="Adds a Region", responseObject=RegionResponse.class)
@ -40,16 +40,16 @@ public class AddRegionCmd extends BaseCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.INTEGER, required=true, description="Id of the Region")
private Integer id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="adds Region with this name")
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="Name of the region")
private String regionName;
@Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, required=true, description="end_point of the Region")
@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")
@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")
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="Secret Key of Admin user")
private String secretKey;
/////////////////////////////////////////////////////

View File

@ -23,9 +23,9 @@ import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.RegionResponse;
import org.apache.cloudstack.region.Region;
import org.apache.log4j.Logger;
import com.cloud.region.Region;
import com.cloud.user.Account;
@APICommand(name = "updateRegion", description="Updates a region", responseObject=RegionResponse.class)
@ -37,7 +37,7 @@ public class UpdateRegionCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ID, type=CommandType.INTEGER, required=true, description="ID of region to update")
@Parameter(name=ApiConstants.ID, type=CommandType.INTEGER, required=true, description="Id of region to update")
private Integer id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="updates region with this name")
@ -46,10 +46,10 @@ 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="API key")
@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="Secret Key")
@Parameter(name=ApiConstants.SECRET_KEY, type=CommandType.STRING, description="new Secret Key for the Region")
private String secretKey;
/////////////////////////////////////////////////////

View File

@ -79,13 +79,7 @@ public class DeleteUserCmd extends BaseCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("UserId: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
boolean result = false;
if(isPopagate){
result = _accountService.deleteUser(this);
} else {
result = _regionService.deleteUser(this);
}
boolean result = _regionService.deleteUser(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);

View File

@ -93,13 +93,7 @@ public class DisableUserCmd extends BaseAsyncCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("UserId: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
UserAccount user = null;
if(isPopagate){
user = _accountService.disableUser(getId());
} else {
user = _regionService.disableUser(getId());
}
UserAccount user = _regionService.disableUser(this);
if (user != null){
UserResponse response = _responseGenerator.createUserResponse(user);

View File

@ -76,13 +76,7 @@ public class EnableUserCmd extends BaseCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("UserId: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
UserAccount user = null;
if(isPopagate){
user = _accountService.enableUser(getId());
} else {
user = _regionService.enableUser(getId());
}
UserAccount user = _regionService.enableUser(this);
if (user != null){
UserResponse response = _responseGenerator.createUserResponse(user);

View File

@ -133,13 +133,7 @@ public class UpdateUserCmd extends BaseCmd {
@Override
public void execute(){
UserContext.current().setEventDetails("UserId: "+getId());
boolean isPopagate = (getIsPropagate() != null ) ? getIsPropagate() : false;
UserAccount user = null;
if(isPopagate){
user = _accountService.updateUser(this);
} else {
user = _regionService.updateUser(this);
}
UserAccount user = _regionService.updateUser(this);
if (user != null){
UserResponse response = _responseGenerator.createUserResponse(user);

View File

@ -25,10 +25,9 @@ import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.RegionResponse;
import org.apache.cloudstack.region.Region;
import org.apache.log4j.Logger;
import com.cloud.region.Region;
@APICommand(name = "listRegions", description="Lists Regions", responseObject=RegionResponse.class)
public class ListRegionsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListRegionsCmd.class.getName());
@ -43,7 +42,7 @@ public class ListRegionsCmd extends BaseListCmd {
private Integer id;
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="List Region by region name.")
private String domainName;
private String name;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -53,8 +52,8 @@ public class ListRegionsCmd extends BaseListCmd {
return id;
}
public String getRegionName() {
return domainName;
public String getName() {
return name;
}
/////////////////////////////////////////////////////

View File

@ -18,10 +18,13 @@ package org.apache.cloudstack.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import org.apache.cloudstack.region.Region;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@EntityReference(value = Region.class)
public class RegionResponse extends BaseResponse {
@SerializedName(ApiConstants.ID) @Param(description="the ID of the region")
private Integer id;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
/**
*

View File

@ -0,0 +1,157 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.region;
import java.util.List;
import org.apache.cloudstack.api.command.admin.account.DeleteAccountCmd;
import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd;
import org.apache.cloudstack.api.command.admin.account.EnableAccountCmd;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import org.apache.cloudstack.api.command.admin.domain.DeleteDomainCmd;
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.DisableUserCmd;
import org.apache.cloudstack.api.command.admin.user.EnableUserCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import org.apache.cloudstack.api.command.user.region.ListRegionsCmd;
import com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserAccount;
public interface RegionService {
/**
* 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
* @param cmd
*
* @return true if delete was successful, false otherwise
*/
boolean deleteUserAccount(DeleteAccountCmd cmd);
/**
* 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 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
* @param deleteUserCmd
* @return true if delete was successful, false otherwise
*/
boolean deleteUser(DeleteUserCmd deleteUserCmd);
/**
* update an existing domain
*
* @param cmd
* - 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);
/**
* Update a user by userId
*
* @param userId
* @return UserAccount object
*/
public UserAccount updateUser(UpdateUserCmd updateUserCmd);
/**
* Disables a user by userId
*
* @param cmd
* @return UserAccount object
*/
public UserAccount disableUser(DisableUserCmd cmd);
/**
* Enables a user
*
* @param cmd
* @return UserAccount object
*/
public UserAccount enableUser(EnableUserCmd cmd);
}

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import java.util.Date;

View File

@ -271,7 +271,7 @@ under the License.
<dao name="Site2SiteCustomerGatewayDao" class="com.cloud.network.dao.Site2SiteCustomerGatewayDaoImpl" singleton="false"/>
<dao name="Site2SiteVpnGatewayDao" class="com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl" singleton="false"/>
<dao name="Site2SiteVpnConnectionDao" class="com.cloud.network.dao.Site2SiteVpnConnectionDaoImpl" singleton="false"/>
<dao name="RegionDao" class="com.cloud.region.dao.RegionDaoImpl" singleton="false"/>
<dao name="RegionDao" class="org.apache.cloudstack.region.dao.RegionDaoImpl" singleton="false"/>
</configuration-server>
<awsapi-ec2server class="com.cloud.bridge.service.EC2MainServlet">

View File

@ -136,6 +136,8 @@ import org.apache.cloudstack.api.response.VpnUsersResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.api.response.S3Response;
import org.apache.cloudstack.region.Region;
import com.cloud.async.AsyncJob;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
@ -205,7 +207,6 @@ import com.cloud.org.Cluster;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
import com.cloud.region.Region;
import com.cloud.server.Criteria;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.TaggedResourceType;

View File

@ -105,6 +105,7 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import com.cloud.api.response.ApiResponseSerializer;
import org.apache.cloudstack.api.response.ExceptionResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.region.RegionManager;
import com.cloud.async.AsyncCommandQueued;
import com.cloud.async.AsyncJob;
@ -122,7 +123,6 @@ import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.region.RegionManager;
import com.cloud.exception.RequestLimitException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;

View File

@ -21,6 +21,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.region.RegionManagerImpl;
import org.apache.cloudstack.region.dao.RegionDaoImpl;
import org.apache.cloudstack.region.dao.RegionSyncDaoImpl;
import com.cloud.agent.manager.ClusteredAgentManagerImpl;
import com.cloud.alert.AlertManagerImpl;
import com.cloud.alert.dao.AlertDaoImpl;
@ -158,9 +162,6 @@ import com.cloud.projects.ProjectManagerImpl;
import com.cloud.projects.dao.ProjectAccountDaoImpl;
import com.cloud.projects.dao.ProjectDaoImpl;
import com.cloud.projects.dao.ProjectInvitationDaoImpl;
import com.cloud.region.RegionManagerImpl;
import com.cloud.region.dao.RegionDaoImpl;
import com.cloud.region.dao.RegionSyncDaoImpl;
import com.cloud.resource.ResourceManagerImpl;
import com.cloud.resourcelimit.ResourceLimitManagerImpl;
import com.cloud.service.dao.ServiceOfferingDaoImpl;

View File

@ -29,7 +29,6 @@ import org.apache.log4j.Logger;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.region.RegionManager;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;

View File

@ -1,30 +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 com.cloud.region;
import java.util.Map;
public interface RegionManager {
public boolean propogateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone, String accountName, short accountType, Long domainId, String networkDomain,
Map<String, String> details, String accountUUID, String userUUID);
public int getId();
public void setId(int id);
public void propogateAddUser(String userName, String password,
String firstName, String lastName, String email, String timeZone,
String accountName, String domainUUId, String userUUID);
public void propogateAddDomain(String name, Long parentId, String networkDomain, String uuid);
}

View File

@ -1,33 +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 com.cloud.region.dao;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.region.RegionVO;
import com.cloud.utils.db.GenericDaoBase;
@Local(value={RegionDao.class})
public class RegionDaoImpl extends GenericDaoBase<RegionVO, Integer> implements RegionDao {
private static final Logger s_logger = Logger.getLogger(RegionDaoImpl.class);
public RegionDaoImpl(){
}
}

View File

@ -52,8 +52,6 @@ import com.cloud.offerings.NetworkOfferingServiceMapVO;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.region.RegionVO;
import com.cloud.region.dao.RegionDao;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
@ -74,6 +72,8 @@ import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
import com.cloud.uuididentity.dao.IdentityDao;
import org.apache.cloudstack.region.RegionVO;
import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
@ -1252,7 +1252,6 @@ public class ConfigurationServerImpl implements ConfigurationServer {
private void createDefaultRegion(){
//Get Region name and URL from db.properties
_regionDao.persist(new RegionVO(_regionDao.getRegionId(), "Local", "http://localhost:8080/client/api", "", ""));
//Default account, user and domain should share same uuid
}
}

View File

@ -20,6 +20,10 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import com.cloud.api.query.vo.ControlledViewEntity;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
@ -102,5 +106,94 @@ public interface AccountManager extends AccountService {
void buildACLSearchParameters(Account caller, Long id,
String accountName, Long projectId, List<Long> permittedAccounts, Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject, boolean listAll, boolean forProjectInvitation);
/**
* Deletes a user by userId
*
* @param accountId
* - id of the account do delete
*
* @return true if delete was successful, false otherwise
*/
boolean deleteUserAccount(long accountId);
/**
* Updates an account
*
* @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
*
* @param accountName
* @param domainId
* @param accountId
* @param disabled
* account if success
* @return true if disable was successful, false otherwise
*/
Account disableAccount(String accountName, Long domainId, Long accountId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Enables an account by accountId
*
* @param accountName
* - the enableAccount command defining the accountId to be deleted.
* @param domainId
* TODO
* @param accountId
* @return account object
*/
Account enableAccount(String accountName, Long domainId, Long accountId);
/**
* Deletes user by Id
* @param deleteUserCmd
* @return
*/
boolean deleteUser(DeleteUserCmd deleteUserCmd);
/**
* Update a user by userId
*
* @param userId
* @return UserAccount object
*/
UserAccount updateUser(UpdateUserCmd cmd);
/**
* Disables a user by userId
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount disableUser(long userId);
/**
* Enables a user
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount enableUser(long userId);
/**
* Locks an account by accountId. A locked account cannot access the API, but will still have running VMs/IP
* addresses
* allocated/etc.
*
* @param accountName
* - the LockAccount command defining the accountId to be locked.
* @param domainId
* TODO
* @param accountId
* @return account object
*/
Account lockAccount(String accountName, Long domainId, Long accountId);
}

View File

@ -52,11 +52,12 @@ import com.cloud.api.query.vo.ControlledViewEntity;
import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
import org.apache.cloudstack.region.RegionManager;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ResourceLimit;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ConfigurationDaoImpl;
import com.cloud.configuration.dao.ResourceCountDao;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
@ -97,7 +98,6 @@ import com.cloud.projects.ProjectManager;
import com.cloud.projects.ProjectVO;
import com.cloud.projects.dao.ProjectAccountDao;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.region.RegionManager;
import com.cloud.server.auth.UserAuthenticator;
import com.cloud.storage.StorageManager;
import com.cloud.storage.VMTemplateVO;
@ -830,13 +830,13 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
user.setRegistrationToken(registrationToken);
}
txn.commit();
//Propogate Add account to other Regions
_regionMgr.propogateAddAccount(userName, password, firstName, lastName, email, timezone, accountName, accountType, domainId,
//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 propogated from another Region
// Account is propagated from another Region
Transaction txn = Transaction.currentTxn();
txn.start();
@ -891,8 +891,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
UserVO user = null;
if(regionId == null){
user = createUser(account.getId(), userName, password, firstName, lastName, email, timeZone);
//Propogate Add user to other Regions
_regionMgr.propogateAddUser(userName, password, firstName, lastName, email, timeZone, accountName, domain.getUuid(), user.getUuid());
//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);
}
@ -1744,7 +1744,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
// Create default security group
_networkGroupMgr.createDefaultSecurityGroup(accountId);
//_regionMgr.propogateAddResource();
txn.commit();
return account;

View File

@ -19,6 +19,8 @@ package com.cloud.user;
import java.util.List;
import java.util.Set;
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
@ -34,5 +36,15 @@ public interface DomainManager extends DomainService {
List<? extends Domain> findInactiveDomains();
boolean deleteDomain(DomainVO domain, Boolean cleanup);
boolean deleteDomain(long domainId, Boolean cleanup);
/**
* update an existing domain
*
* @param cmd
* - the command containing domainId and new domainName
* @return Domain object if the command succeeded
*/
Domain updateDomain(UpdateDomainCmd cmd);
}

View File

@ -27,6 +27,7 @@ import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.command.admin.domain.ListDomainChildrenCmd;
import org.apache.cloudstack.api.command.admin.domain.ListDomainsCmd;
import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
import org.apache.cloudstack.region.RegionManager;
import org.apache.log4j.Logger;
import com.cloud.configuration.ResourceLimit;
@ -43,7 +44,6 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.projects.ProjectManager;
import com.cloud.projects.ProjectVO;
import com.cloud.projects.dao.ProjectDao;
import com.cloud.region.RegionManager;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.DiskOfferingVO;
@ -187,8 +187,9 @@ public class DomainManagerImpl implements DomainManager, DomainService, Manager
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, _regionMgr.getId()));
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
_regionMgr.propogateAddDomain(name, parentId, networkDomain, domain.getUuid());
txn.commit();
//Propagate domain creation to peer Regions
_regionMgr.propagateAddDomain(name, parentId, networkDomain, domain.getUuid());
return domain;
} else {
Transaction txn = Transaction.currentTxn();

View File

@ -20,10 +20,7 @@ import java.util.List;
import javax.ejb.Local;
import com.cloud.region.RegionManager;
import com.cloud.user.UserVO;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import com.cloud.user.AccountVO;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import com.cloud.domain.DomainVO;

View File

@ -0,0 +1,216 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.region;
import java.util.List;
import java.util.Map;
import 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 com.cloud.domain.Domain;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.user.Account;
import com.cloud.user.UserAccount;
public interface 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
* @return
*/
boolean deleteUser(DeleteUserCmd deleteUserCmd);
/**
* update an existing domain
*
* @param cmd
* - the command containing domainId and new domainName
* @return Domain object if the command succeeded
*/
Domain updateDomain(UpdateDomainCmd updateDomainCmd);
/**
* Deletes domain by Id
* @param id
* @param cleanup
* @return true if delete was successful, false otherwise
*/
boolean deleteDomain(Long id, Boolean cleanup);
/**
* Update a user by userId
*
* @param userId
* @return UserAccount object
*/
UserAccount updateUser(UpdateUserCmd updateUserCmd);
/**
* Disables a user by userId
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount disableUser(Long id);
/**
* Enables a user
*
* @param userId
* - the userId
* @return UserAccount object
*/
UserAccount enableUser(long userId);
}

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import java.util.ArrayList;
import java.util.List;
@ -28,7 +28,8 @@ 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.api.command.user.region.ListRegionsCmd;
import org.apache.cloudstack.region.dao.RegionDao;
import org.apache.cloudstack.region.dao.RegionSyncDao;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.log4j.Logger;
@ -38,8 +39,6 @@ import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.region.dao.RegionDao;
import com.cloud.region.dao.RegionSyncDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
@ -54,8 +53,8 @@ import com.cloud.utils.component.Manager;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.uuididentity.dao.IdentityDao;
@Local(value = { RegionManager.class, RegionService.class })
public class RegionManagerImpl implements RegionManager, RegionService, Manager{
@Local(value = { RegionManager.class })
public class RegionManagerImpl implements RegionManager, Manager{
public static final Logger s_logger = Logger.getLogger(RegionManagerImpl.class);
@Inject
@ -102,16 +101,163 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
return _name;
}
public int getId() {
return _id;
}
/*
* Propagates Account creation to peer Regions
* Adds an entry in region_sync table on failure
*/
@Override
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
if( _regionDao.findById(id) == null ){
RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
return _regionDao.persist(region);
} else {
throw new InvalidParameterValueException("Region with id: "+id+" already exists");
public boolean propagateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone,
String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
String command = "createAccount";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair(ApiConstants.USERNAME, userName));
params.add(new NameValuePair(ApiConstants.PASSWORD, password));
params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
params.add(new NameValuePair(ApiConstants.EMAIL, email));
params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
params.add(new NameValuePair(ApiConstants.ACCOUNT_TYPE, ""+accountType));
//ToDo: use domain UUID
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, ((domainId != null) ? domainId.toString() : "")));
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
params.add(new NameValuePair(ApiConstants.ACCOUNT_DETAILS, (details != null) ? details.toString() : ""));
params.add(new NameValuePair(ApiConstants.ACCOUNT_ID, accountUUID));
params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
List<RegionVO> regions = _regionDao.listAll();
for (Region region : regions){
if(region.getId() == getId()){
continue;
}
s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added account :"+accountName+" to Region: "+region.getId());
} else {
// api call failed. Add entry in region_sync table
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
}
}
return true;
}
/*
* Propagates User creation to peer Regions
* Adds an entry in region_sync table on failure
*/
@Override
public void propagateAddUser(String userName, String password,
String firstName, String lastName, String email, String timezone,
String accountName, String domainUUId, String userUUID) {
String command = "createUser";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair(ApiConstants.USERNAME, userName));
params.add(new NameValuePair(ApiConstants.PASSWORD, password));
params.add(new NameValuePair(ApiConstants.FIRSTNAME, firstName));
params.add(new NameValuePair(ApiConstants.LASTNAME, lastName));
params.add(new NameValuePair(ApiConstants.EMAIL, email));
params.add(new NameValuePair(ApiConstants.TIMEZONE, timezone));
params.add(new NameValuePair(ApiConstants.ACCOUNT, accountName));
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, domainUUId));
params.add(new NameValuePair(ApiConstants.USER_ID, userUUID));
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
List<RegionVO> regions = _regionDao.listAll();
for (Region region : regions){
if(region.getId() == getId()){
continue;
}
s_logger.debug("Adding account :"+accountName+" to Region: "+region.getId());
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added user :"+userName+" to Region: "+region.getId());
} else {
// api call failed. Add entry in region_sync table
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
}
}
return;
}
/*
* Propagates Domain creation details to peer Regions
* Adds an entry in region_sync table on failure
*/
@Override
public void propagateAddDomain(String name, Long parentId, String networkDomain, String uuid) {
String command = "createDomain";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair(ApiConstants.NAME, name));
if(parentId != null){
DomainVO domain = _domainDao.findById(parentId);
if(domain != null){
params.add(new NameValuePair(ApiConstants.PARENT_DOMAIN_ID, domain.getUuid()));
}
}
params.add(new NameValuePair(ApiConstants.NETWORK_DOMAIN, networkDomain));
params.add(new NameValuePair(ApiConstants.DOMAIN_ID, uuid));
params.add(new NameValuePair(ApiConstants.REGION_ID, ""+getId()));
List<RegionVO> regions = _regionDao.listAll();
for (Region region : regions){
if(region.getId() == getId()){
continue;
}
s_logger.debug("Adding domain :"+name+" to Region: "+region.getId());
if (RegionsApiUtil.makeAPICall(region, command, params)) {
s_logger.debug("Successfully added domain :"+name+" to Region: "+region.getId());
} else {
// api call failed. Add entry in region_sync table
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
}
}
return;
}
/**
* Adds an entry to region_sync table
* Entry contains region Id along with failed api
* @param regionId
* @param command
* @param params
*/
private void addRegionSyncItem(int regionId, String command, List<NameValuePair> params){
String api = RegionsApiUtil.buildParams(command, params);
RegionSyncVO sync = new RegionSyncVO(regionId, api);
if(_regionSyncDao.persist(sync) == null){
s_logger.error("Failed to add Region Sync Item. RegionId: "+regionId + "API command: "+api);
}
}
/**
* {@inheritDoc}
*/
@Override
public Region addRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
//Region Id should be unique
if( _regionDao.findById(id) != null ){
throw new InvalidParameterValueException("Region with id: "+id+" already exists");
}
//Region Name should be unique
if( _regionDao.findByName(name) != null ){
throw new InvalidParameterValueException("Region with name: "+name+" already exists");
}
RegionVO region = new RegionVO(id, name, endPoint, apiKey, secretKey);
return _regionDao.persist(region);
}
/**
* {@inheritDoc}
*/
@Override
public Region updateRegion(int id, String name, String endPoint, String apiKey, String secretKey) {
RegionVO region = _regionDao.findById(id);
@ -120,6 +266,14 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
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);
}
@ -140,76 +294,34 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
return _regionDao.findById(id);
}
/**
* {@inheritDoc}
*/
@Override
public boolean removeRegion(int id) {
RegionVO region = _regionDao.findById(id);
if(region != null){
return _regionDao.remove(id);
} else {
if(region == null){
throw new InvalidParameterValueException("Failed to delete Region: " + id + ", Region not found");
}
}
return _regionDao.remove(id);
}
/**
* {@inheritDoc}
*/
@Override
public List<RegionVO> listRegions(ListRegionsCmd cmd) {
if(cmd.getId() != null){
List<RegionVO> regions = new ArrayList<RegionVO>();
regions.add(_regionDao.findById(cmd.getId()));
return regions;
}
return _regionDao.listAll();
}
public int getId() {
return _id;
}
public void setId(int _id) {
this._id = _id;
}
@Override
public boolean propogateAddAccount(String userName, String password, String firstName, String lastName, String email, String timezone,
String accountName, short accountType, Long domainId, String networkDomain, Map<String, String> details, String accountUUID, String userUUID) {
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));
//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 {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding account :"+accountName+" to Region: "+region.getId());
}
}
return true;
public List<RegionVO> listRegions(Integer id, String name) {
return _regionDao.listByNameAndId(id, name);
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteUserAccount(long accountId) {
AccountVO account = _accountDao.findById(accountId);
if(account == null){
return false;
throw new InvalidParameterValueException("The specified account does not exist in the system");
}
String accountUUID = account.getUuid();
int regionId = account.getRegionId();
@ -248,7 +360,10 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
}
/**
* {@inheritDoc}
*/
@Override
public Account updateAccount(UpdateAccountCmd cmd) {
Long accountId = cmd.getId();
@ -258,7 +373,7 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
String newAccountName = cmd.getNewName();
String networkDomain = cmd.getNetworkDomain();
//ToDo send details
Map<String, String> details = cmd.getDetails();
Map<String, String> details = cmd.getDetails();
Account account = null;
if (accountId != null) {
@ -266,13 +381,13 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
} else {
account = _accountDao.findEnabledAccount(accountName, domainId);
}
// Check if account exists
if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
s_logger.error("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
}
}
String command = "updateAccount";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair(ApiConstants.NEW_NAME, newAccountName));
@ -319,6 +434,9 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public Account disableAccount(String accountName, Long domainId, Long accountId, Boolean lockRequested) throws ConcurrentOperationException, ResourceUnavailableException {
Account account = null;
@ -330,7 +448,8 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
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";
@ -378,6 +497,9 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public Account enableAccount(String accountName, Long domainId, Long accountId) {
// Check if account exists
@ -390,7 +512,8 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
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";
@ -434,6 +557,9 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteUser(DeleteUserCmd cmd) {
long id = cmd.getId();
@ -442,8 +568,8 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
if (user == null) {
throw new InvalidParameterValueException("The specified user doesn't exist in the system");
}
}
String userUUID = user.getUuid();
int regionId = user.getRegionId();
@ -482,13 +608,68 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean deleteDomain(Long id, Boolean cleanup) {
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";
@ -528,15 +709,18 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public UserAccount updateUser(UpdateUserCmd cmd){
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";
@ -582,60 +766,16 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
@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 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";
@ -672,12 +812,16 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
/**
* {@inheritDoc}
*/
@Override
public UserAccount enableUser(Long userId) {
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";
@ -714,78 +858,4 @@ public class RegionManagerImpl implements RegionManager, RegionService, Manager{
}
}
@Override
public void propogateAddUser(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 {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding user :"+userName+" to Region: "+region.getId());
}
}
return;
}
@Override
public void propogateAddDomain(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 {
addRegionSyncItem(region.getId(), command, params);
s_logger.error("Error while Adding domain :"+name+" to Region: "+region.getId());
}
}
return;
}
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);
}
}
}

View File

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

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import java.util.Date;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import com.cloud.user.UserVO;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import javax.persistence.Column;
import javax.persistence.Entity;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region;
package org.apache.cloudstack.region;
import java.io.IOException;
import java.io.InputStream;
@ -44,9 +44,20 @@ 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);
@ -67,6 +78,14 @@ public class RegionsApiUtil {
}
}
/**
* 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);
@ -74,6 +93,7 @@ public class RegionsApiUtil {
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);
@ -101,6 +121,14 @@ public class RegionsApiUtil {
}
}
/**
* 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);
@ -109,6 +137,7 @@ public class RegionsApiUtil {
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");
@ -130,6 +159,14 @@ public class RegionsApiUtil {
}
}
/**
* 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);
@ -157,6 +194,12 @@ public class RegionsApiUtil {
}
}
/**
* 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();
@ -175,6 +218,13 @@ public class RegionsApiUtil {
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();

View File

@ -14,10 +14,17 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region.dao;
package org.apache.cloudstack.region.dao;
import java.util.List;
import org.apache.cloudstack.region.RegionVO;
import com.cloud.region.RegionVO;
import com.cloud.utils.db.GenericDao;
public interface RegionDao extends GenericDao<RegionVO, Integer> {
RegionVO findByName(String name);
List<RegionVO> listByNameAndId(Integer id, String name);
}

View File

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

View File

@ -14,9 +14,10 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region.dao;
package org.apache.cloudstack.region.dao;
import org.apache.cloudstack.region.RegionSyncVO;
import com.cloud.region.RegionSyncVO;
import com.cloud.utils.db.GenericDao;
public interface RegionSyncDao extends GenericDao<RegionSyncVO, Integer> {

View File

@ -14,13 +14,13 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.region.dao;
package org.apache.cloudstack.region.dao;
import javax.ejb.Local;
import org.apache.cloudstack.region.RegionSyncVO;
import org.apache.log4j.Logger;
import com.cloud.region.RegionSyncVO;
import com.cloud.utils.db.GenericDaoBase;
@Local(value={RegionSyncDao.class})

View File

@ -2259,7 +2259,7 @@ CREATE TABLE `cloud`.`netscaler_pod_ref` (
CREATE TABLE `cloud`.`region` (
`id` int unsigned NOT NULL UNIQUE,
`name` varchar(255) NOT NULL,
`name` varchar(255) NOT NULL UNIQUE,
`end_point` varchar(255) NOT NULL,
`api_key` varchar(255),
`secret_key` varchar(255),