Create DB view for Account to speed up ListAccountsCmd, and add missing async job information for some response objects.

Signed-off-by: Min Chen <min.chen@citrix.com>
This commit is contained in:
Min Chen 2013-01-02 17:38:58 -08:00
parent bc8e0af0a3
commit ebfb90e217
38 changed files with 1398 additions and 341 deletions

View File

@ -192,10 +192,6 @@ public interface AccountService {
public String[] createApiKeyAndSecretKey(RegisterCmd cmd);
Pair<List<? extends Account>, Integer> searchForAccounts(ListAccountsCmd cmd);
UserAccount getUserByApiKey(String apiKey);
void checkAccess(Account account, Domain domain) throws PermissionDeniedException;

View File

@ -80,6 +80,16 @@ public interface ResourceLimitService {
*/
public long findCorrectResourceLimitForAccount(Account account, ResourceType type);
/**
* This call should be used when we have already queried resource limit for an account. This is to handle
* some corner cases where queried limit may be null.
* @param accountType
* @param limit
* @param type
* @return
*/
public long findCorrectResourceLimitForAccount(short accountType, Long limit, ResourceType type);
/**
* Finds the resource limit for a specified domain and type. If the domain has an infinite limit, will check
* up the domain hierarchy

View File

@ -27,6 +27,8 @@ import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UserResponse;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
@ -91,17 +93,8 @@ public class ListAccountsCmd extends BaseListDomainResourcesCmd {
@Override
public void execute(){
Pair<List<? extends Account>, Integer> accounts = _accountService.searchForAccounts(this);
ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
List<AccountResponse> accountResponses = new ArrayList<AccountResponse>();
for (Account account : accounts.first()) {
AccountResponse acctResponse = _responseGenerator.createAccountResponse(account);
acctResponse.setObjectName("account");
accountResponses.add(acctResponse);
}
response.setResponses(accountResponses, accounts.second());
ListResponse<AccountResponse> response = _queryService.searchForAccounts(this);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -19,6 +19,7 @@ package org.apache.cloudstack.query;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
@ -28,6 +29,7 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -76,4 +78,6 @@ public interface QueryService {
public ListResponse<HostResponse> searchForServers(ListHostsCmd cmd);
public ListResponse<VolumeResponse> searchForVolumes(ListVolumesCmd cmd);
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd);
}

View File

@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -37,6 +38,7 @@ import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import com.cloud.api.query.dao.AccountJoinDao;
import com.cloud.api.query.dao.DomainRouterJoinDao;
import com.cloud.api.query.dao.HostJoinDao;
import com.cloud.api.query.dao.InstanceGroupJoinDao;
@ -45,8 +47,10 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao;
import com.cloud.api.query.dao.ProjectJoinDao;
import com.cloud.api.query.dao.ResourceTagJoinDao;
import com.cloud.api.query.dao.SecurityGroupJoinDao;
import com.cloud.api.query.dao.UserAccountJoinDao;
import com.cloud.api.query.dao.UserVmJoinDao;
import com.cloud.api.query.dao.VolumeJoinDao;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -213,7 +217,6 @@ import com.cloud.user.UserStatisticsVO;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.SSHKeyPairDao;
import com.cloud.user.dao.UserAccountJoinDao;
import com.cloud.user.dao.UserDao;
import com.cloud.user.dao.UserStatisticsDao;
import com.cloud.uservm.UserVm;
@ -318,6 +321,7 @@ public class ApiDBUtils {
private static ProjectInvitationJoinDao _projectInvitationJoinDao;
private static HostJoinDao _hostJoinDao;
private static VolumeJoinDao _volJoinDao;
private static AccountJoinDao _accountJoinDao;
private static PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
private static PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@ -406,6 +410,7 @@ public class ApiDBUtils {
_projectInvitationJoinDao = locator.getDao(ProjectInvitationJoinDao.class);
_hostJoinDao = locator.getDao(HostJoinDao.class);
_volJoinDao = locator.getDao(VolumeJoinDao.class);
_accountJoinDao = locator.getDao(AccountJoinDao.class);
_physicalNetworkTrafficTypeDao = locator.getDao(PhysicalNetworkTrafficTypeDao.class);
_physicalNetworkServiceProviderDao = locator.getDao(PhysicalNetworkServiceProviderDao.class);
@ -491,6 +496,10 @@ public class ApiDBUtils {
return _resourceLimitMgr.findCorrectResourceLimitForAccount(account, type);
}
public static long findCorrectResourceLimit(Long limit, short accountType, ResourceType type) {
return _resourceLimitMgr.findCorrectResourceLimitForAccount(accountType, limit, type);
}
public static AsyncJobVO findInstancePendingAsyncJob(String instanceType, long instanceId) {
return _asyncMgr.findInstancePendingAsyncJob(instanceType, instanceId);
}
@ -589,7 +598,7 @@ public class ApiDBUtils {
public static DomainVO findDomainByIdIncludingRemoved(Long domainId) {
return _domainDao.findByIdIncludingRemoved(domainId);
}
public static boolean isChildDomain(long parentId, long childId) {
return _domainDao.isChildDomain(parentId, childId);
}
@ -1344,4 +1353,15 @@ public class ApiDBUtils {
return _volJoinDao.newVolumeView(vr);
}
public static AccountResponse newAccountResponse(AccountJoinVO ve) {
return _accountJoinDao.newAccountResponse(ve);
}
public static AccountJoinVO newAccountView(Account e){
return _accountJoinDao.newAccountView(e);
}
public static AccountJoinVO findAccountViewById(Long accountId) {
return _accountJoinDao.findByIdIncludingRemoved(accountId);
}
}

View File

@ -45,6 +45,7 @@ import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import com.cloud.api.query.ViewResponseHelper;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.ControlledViewEntity;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
@ -275,162 +276,13 @@ public class ApiResponseHelper implements ResponseGenerator {
// this method is used for response generation via createAccount (which creates an account + user)
@Override
public AccountResponse createUserAccountResponse(UserAccount user) {
return createAccountResponse(ApiDBUtils.findAccountById(user.getAccountId()));
return ApiDBUtils.newAccountResponse(ApiDBUtils.findAccountViewById(user.getAccountId()));
}
@Override
public AccountResponse createAccountResponse(Account account) {
boolean accountIsAdmin = (account.getType() == Account.ACCOUNT_TYPE_ADMIN);
AccountResponse accountResponse = new AccountResponse();
accountResponse.setId(account.getUuid());
accountResponse.setName(account.getAccountName());
accountResponse.setAccountType(account.getType());
Domain domain = ApiDBUtils.findDomainById(account.getDomainId());
if (domain != null) {
accountResponse.setDomainId(domain.getUuid());
accountResponse.setDomainName(domain.getName());
}
accountResponse.setState(account.getState().toString());
accountResponse.setNetworkDomain(account.getNetworkDomain());
DataCenter dc = ApiDBUtils.findZoneById(account.getDefaultZoneId());
if (dc != null) {
accountResponse.setDefaultZone(dc.getUuid());
}
// get network stat
List<UserStatisticsVO> stats = ApiDBUtils.listUserStatsBy(account.getId());
if (stats == null) {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error searching for user stats");
}
Long bytesSent = 0L;
Long bytesReceived = 0L;
for (UserStatisticsVO stat : stats) {
Long rx = stat.getNetBytesReceived() + stat.getCurrentBytesReceived();
Long tx = stat.getNetBytesSent() + stat.getCurrentBytesSent();
bytesReceived = bytesReceived + Long.valueOf(rx);
bytesSent = bytesSent + Long.valueOf(tx);
}
accountResponse.setBytesReceived(bytesReceived);
accountResponse.setBytesSent(bytesSent);
// Get resource limits and counts
Long vmLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.user_vm, account.getId());
String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
Long vmTotal = ApiDBUtils.getResourceCount(ResourceType.user_vm, account.getId());
String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
accountResponse.setVmLimit(vmLimitDisplay);
accountResponse.setVmTotal(vmTotal);
accountResponse.setVmAvailable(vmAvail);
Long ipLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.public_ip, account.getId());
String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
Long ipTotal = ApiDBUtils.getResourceCount(ResourceType.public_ip, account.getId());
Long ips = ipLimit - ipTotal;
// check how many free ips are left, and if it's less than max allowed number of ips from account - use this
// value
Long ipsLeft = ApiDBUtils.countFreePublicIps();
boolean unlimited = true;
if (ips.longValue() > ipsLeft.longValue()) {
ips = ipsLeft;
unlimited = false;
}
String ipAvail = ((accountIsAdmin || ipLimit == -1) && unlimited) ? "Unlimited" : String.valueOf(ips);
accountResponse.setIpLimit(ipLimitDisplay);
accountResponse.setIpTotal(ipTotal);
accountResponse.setIpAvailable(ipAvail);
Long volumeLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.volume, account.getId());
String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
Long volumeTotal = ApiDBUtils.getResourceCount(ResourceType.volume, account.getId());
String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
accountResponse.setVolumeLimit(volumeLimitDisplay);
accountResponse.setVolumeTotal(volumeTotal);
accountResponse.setVolumeAvailable(volumeAvail);
Long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.snapshot, account.getId());
String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
Long snapshotTotal = ApiDBUtils.getResourceCount(ResourceType.snapshot, account.getId());
String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
accountResponse.setSnapshotLimit(snapshotLimitDisplay);
accountResponse.setSnapshotTotal(snapshotTotal);
accountResponse.setSnapshotAvailable(snapshotAvail);
Long templateLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.template, account.getId());
String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
Long templateTotal = ApiDBUtils.getResourceCount(ResourceType.template, account.getId());
String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
accountResponse.setTemplateLimit(templateLimitDisplay);
accountResponse.setTemplateTotal(templateTotal);
accountResponse.setTemplateAvailable(templateAvail);
// Get stopped and running VMs
int vmStopped = 0;
int vmRunning = 0;
List<Long> permittedAccounts = new ArrayList<Long>();
permittedAccounts.add(account.getId());
List<UserVmJoinVO> virtualMachines = ApiDBUtils.searchForUserVMs(new Criteria(), permittedAccounts);
// get Running/Stopped VMs
for (Iterator<UserVmJoinVO> iter = virtualMachines.iterator(); iter.hasNext();) {
// count how many stopped/running vms we have
UserVmJoinVO vm = iter.next();
if (vm.getState() == State.Stopped) {
vmStopped++;
} else if (vm.getState() == State.Running) {
vmRunning++;
}
}
accountResponse.setVmStopped(vmStopped);
accountResponse.setVmRunning(vmRunning);
accountResponse.setObjectName("account");
//get resource limits for projects
Long projectLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.project, account.getId());
String projectLimitDisplay = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
Long projectTotal = ApiDBUtils.getResourceCount(ResourceType.project, account.getId());
String projectAvail = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
accountResponse.setProjectLimit(projectLimitDisplay);
accountResponse.setProjectTotal(projectTotal);
accountResponse.setProjectAvailable(projectAvail);
//get resource limits for networks
Long networkLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.network, account.getId());
String networkLimitDisplay = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
Long networkTotal = ApiDBUtils.getResourceCount(ResourceType.network, account.getId());
String networkAvail = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
accountResponse.setNetworkLimit(networkLimitDisplay);
accountResponse.setNetworkTotal(networkTotal);
accountResponse.setNetworkAvailable(networkAvail);
//get resource limits for vpcs
Long vpcLimit = ApiDBUtils.findCorrectResourceLimit(ResourceType.vpc, account.getId());
String vpcLimitDisplay = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
Long vpcTotal = ApiDBUtils.getResourceCount(ResourceType.vpc, account.getId());
String vpcAvail = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
accountResponse.setNetworkLimit(vpcLimitDisplay);
accountResponse.setNetworkTotal(vpcTotal);
accountResponse.setNetworkAvailable(vpcAvail);
// adding all the users for an account as part of the response obj
List<UserVO> usersForAccount = ApiDBUtils.listUsersByAccount(account.getAccountId());
List<UserResponse> userResponseList = new ArrayList<UserResponse>();
for (UserVO user : usersForAccount) {
UserResponse userResponse = createUserResponse(user);
userResponseList.add(userResponse);
}
accountResponse.setUsers(userResponseList);
accountResponse.setDetails(ApiDBUtils.getAccountDetails(account.getId()));
return accountResponse;
AccountJoinVO vUser = ApiDBUtils.newAccountView(account);
return ApiDBUtils.newAccountResponse(vUser);
}

View File

@ -51,6 +51,7 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
@ -88,6 +89,7 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
@ -466,7 +468,10 @@ public class ApiServer implements HttpRequestHandler {
&& !(cmdObj instanceof ListProjectAccountsCmd)
&& !(cmdObj instanceof ListProjectInvitationsCmd)
&& !(cmdObj instanceof ListHostsCmd)
&& !(cmdObj instanceof ListVolumesCmd)) {
&& !(cmdObj instanceof ListVolumesCmd)
&& !(cmdObj instanceof ListUsersCmd)
&& !(cmdObj instanceof ListAccountsCmd)
) {
buildAsyncListResponse((BaseListCmd) cmdObj, caller);
}

View File

@ -31,6 +31,7 @@ import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
@ -40,6 +41,7 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -56,8 +58,10 @@ import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.query.QueryService;
import org.apache.log4j.Logger;
import com.cloud.acl.ControlledEntity;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.dao.AccountJoinDao;
import com.cloud.api.query.dao.DomainRouterJoinDao;
import com.cloud.api.query.dao.HostJoinDao;
import com.cloud.api.query.dao.InstanceGroupJoinDao;
@ -66,8 +70,10 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDao;
import com.cloud.api.query.dao.ProjectJoinDao;
import com.cloud.api.query.dao.ResourceTagJoinDao;
import com.cloud.api.query.dao.SecurityGroupJoinDao;
import com.cloud.api.query.dao.UserAccountJoinDao;
import com.cloud.api.query.dao.UserVmJoinDao;
import com.cloud.api.query.dao.VolumeJoinDao;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -92,11 +98,13 @@ import com.cloud.host.Host;
import com.cloud.host.HostTagVO;
import com.cloud.host.HostVO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IPAddressVO;
import com.cloud.network.security.SecurityGroupVMMapVO;
import com.cloud.network.security.dao.SecurityGroupVMMapDao;
import com.cloud.projects.ProjectInvitation;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectInvitationVO;
import com.cloud.projects.ProjectManager;
import com.cloud.projects.ProjectService;
import com.cloud.projects.dao.ProjectAccountDao;
@ -115,7 +123,7 @@ import com.cloud.user.AccountService;
import com.cloud.user.AccountVO;
import com.cloud.user.DomainManager;
import com.cloud.user.UserContext;
import com.cloud.user.dao.UserAccountJoinDao;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.DateUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
@ -202,6 +210,12 @@ public class QueryManagerImpl implements QueryService, Manager {
@Inject
private VolumeJoinDao _volumeJoinDao;
@Inject
private AccountDao _accountDao;
@Inject
private AccountJoinDao _accountJoinDao;
@Inject
private HighAvailabilityManager _haMgr;
@ -1458,8 +1472,8 @@ public class QueryManagerImpl implements QueryService, Manager {
Pair<List<VolumeJoinVO>, Integer> result = searchForVolumesInternal(cmd);
ListResponse<VolumeResponse> response = new ListResponse<VolumeResponse>();
List<VolumeResponse> routerResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray(new VolumeJoinVO[result.first().size()]));
response.setResponses(routerResponses, result.second());
List<VolumeResponse> volumeResponses = ViewResponseHelper.createVolumeResponse(result.first().toArray(new VolumeJoinVO[result.first().size()]));
response.setResponses(volumeResponses, result.second());
return response;
}
@ -1590,5 +1604,133 @@ public class QueryManagerImpl implements QueryService, Manager {
return new Pair<List<VolumeJoinVO>, Integer>(vrs, count);
}
@Override
public ListResponse<AccountResponse> searchForAccounts(ListAccountsCmd cmd) {
Pair<List<AccountJoinVO>, Integer> result = searchForAccountsInternal(cmd);
ListResponse<AccountResponse> response = new ListResponse<AccountResponse>();
List<AccountResponse> accountResponses = ViewResponseHelper.createAccountResponse(result.first().toArray(new AccountJoinVO[result.first().size()]));
response.setResponses(accountResponses, result.second());
return response;
}
public Pair<List<AccountJoinVO>, Integer> searchForAccountsInternal(ListAccountsCmd cmd) {
Account caller = UserContext.current().getCaller();
Long domainId = cmd.getDomainId();
Long accountId = cmd.getId();
String accountName = cmd.getSearchName();
boolean isRecursive = cmd.isRecursive();
boolean listAll = cmd.listAll();
Boolean listForDomain = false;
if (accountId != null) {
Account account = _accountDao.findById(accountId);
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by id " + accountId);
}
_accountMgr.checkAccess(caller, null, true, account);
}
if (domainId != null) {
Domain domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
}
_accountMgr.checkAccess(caller, domain);
if (accountName != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId);
}
_accountMgr.checkAccess(caller, null, true, account);
}
}
if (accountId == null) {
if (_accountMgr.isAdmin(caller.getType()) && listAll && domainId == null) {
listForDomain = true;
isRecursive = true;
if (domainId == null) {
domainId = caller.getDomainId();
}
} else if (_accountMgr.isAdmin(caller.getType()) && domainId != null) {
listForDomain = true;
} else {
accountId = caller.getAccountId();
}
}
Filter searchFilter = new Filter(AccountJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Object type = cmd.getAccountType();
Object state = cmd.getState();
Object isCleanupRequired = cmd.isCleanupRequired();
Object keyword = cmd.getKeyword();
SearchBuilder<AccountJoinVO> sb = _accountJoinDao.createSearchBuilder();
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.EQ);
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("needsCleanup", sb.entity().isNeedsCleanup(), SearchCriteria.Op.EQ);
sb.and("typeNEQ", sb.entity().getType(), SearchCriteria.Op.NEQ);
sb.and("idNEQ", sb.entity().getId(), SearchCriteria.Op.NEQ);
if (listForDomain && isRecursive) {
sb.and("path", sb.entity().getDomainPath(), SearchCriteria.Op.LIKE);
}
SearchCriteria<AccountJoinVO> sc = sb.create();
sc.setParameters("idNEQ", Account.ACCOUNT_ID_SYSTEM);
if (keyword != null) {
SearchCriteria<AccountJoinVO> ssc = _accountJoinDao.createSearchCriteria();
ssc.addOr("accountName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("accountName", SearchCriteria.Op.SC, ssc);
}
if (type != null) {
sc.setParameters("type", type);
}
if (state != null) {
sc.setParameters("state", state);
}
if (isCleanupRequired != null) {
sc.setParameters("needsCleanup", isCleanupRequired);
}
if (accountName != null) {
sc.setParameters("accountName", accountName);
}
// don't return account of type project to the end user
sc.setParameters("typeNEQ", 5);
if (accountId != null) {
sc.setParameters("id", accountId);
}
if (listForDomain) {
if (isRecursive) {
Domain domain = _domainDao.findById(domainId);
sc.setParameters("path", domain.getPath() + "%");
} else {
sc.setParameters("domainId", domainId);
}
}
Pair<List<AccountJoinVO>, Integer> result = _accountJoinDao.searchAndCount(sc, searchFilter);
return new Pair<List<AccountJoinVO>, Integer>(result.first(), result.second());
}
}

View File

@ -23,6 +23,7 @@ import java.util.List;
import org.apache.cloudstack.api.ApiConstants.HostDetails;
import org.apache.cloudstack.api.ApiConstants.VMDetails;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.DomainRouterResponse;
import org.apache.cloudstack.api.response.EventResponse;
import org.apache.cloudstack.api.response.HostResponse;
@ -38,6 +39,7 @@ import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.DomainRouterJoinVO;
import com.cloud.api.query.vo.EventJoinVO;
import com.cloud.api.query.vo.HostJoinVO;
@ -233,4 +235,12 @@ public class ViewResponseHelper {
}
return new ArrayList<VolumeResponse>(vrDataList.values());
}
public static List<AccountResponse> createAccountResponse(AccountJoinVO... accounts) {
List<AccountResponse> respList = new ArrayList<AccountResponse>();
for (AccountJoinVO vt : accounts){
respList.add(ApiDBUtils.newAccountResponse(vt));
}
return respList;
}
}

View File

@ -0,0 +1,33 @@
// 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.api.query.dao;
import java.util.List;
import org.apache.cloudstack.api.response.AccountResponse;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.user.Account;
import com.cloud.utils.db.GenericDao;
public interface AccountJoinDao extends GenericDao<AccountJoinVO, Long> {
AccountResponse newAccountResponse(AccountJoinVO vol);
AccountJoinVO newAccountView(Account vol);
List<AccountJoinVO> searchByIds(Long... ids);
}

View File

@ -0,0 +1,227 @@
// 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.api.query.dao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiResponseHelper;
import com.cloud.api.query.ViewResponseHelper;
import com.cloud.api.query.vo.AccountJoinVO;
import com.cloud.api.query.vo.InstanceGroupJoinVO;
import com.cloud.api.query.vo.ResourceTagJoinVO;
import com.cloud.api.query.vo.UserAccountJoinVO;
import com.cloud.api.query.vo.UserVmJoinVO;
import com.cloud.api.query.vo.VolumeJoinVO;
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.dc.DataCenter;
import com.cloud.domain.Domain;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import com.cloud.offering.ServiceOffering;
import com.cloud.server.Criteria;
import com.cloud.storage.Storage;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.Volume;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.user.UserStatisticsVO;
import com.cloud.user.UserVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.vm.VirtualMachine.State;
@Local(value={AccountJoinDao.class})
public class AccountJoinDaoImpl extends GenericDaoBase<AccountJoinVO, Long> implements AccountJoinDao {
public static final Logger s_logger = Logger.getLogger(AccountJoinDaoImpl.class);
private SearchBuilder<AccountJoinVO> acctSearch;
private SearchBuilder<AccountJoinVO> acctIdSearch;
protected AccountJoinDaoImpl() {
acctSearch = createSearchBuilder();
acctSearch.and("idIN", acctSearch.entity().getId(), SearchCriteria.Op.IN);
acctSearch.done();
acctIdSearch = createSearchBuilder();
acctIdSearch.and("id", acctIdSearch.entity().getId(), SearchCriteria.Op.EQ);
acctIdSearch.done();
this._count = "select count(distinct id) from account_view WHERE ";
}
@Override
public AccountResponse newAccountResponse(AccountJoinVO account) {
boolean accountIsAdmin = (account.getType() == Account.ACCOUNT_TYPE_ADMIN);
AccountResponse accountResponse = new AccountResponse();
accountResponse.setId(account.getUuid());
accountResponse.setName(account.getAccountName());
accountResponse.setAccountType(account.getType());
accountResponse.setDomainId(account.getDomainUuid());
accountResponse.setDomainName(account.getDomainName());
accountResponse.setState(account.getState().toString());
accountResponse.setNetworkDomain(account.getNetworkDomain());
accountResponse.setDefaultZone(account.getDataCenterUuid());
// get network stat
accountResponse.setBytesReceived(account.getBytesReceived());
accountResponse.setBytesSent(account.getBytesSent());
// Get resource limits and counts
long vmLimit = ApiDBUtils.findCorrectResourceLimit(account.getVmLimit(), account.getType(), ResourceType.user_vm);
String vmLimitDisplay = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit);
long vmTotal = (account.getVmTotal() == null) ? 0 : account.getVmTotal();
String vmAvail = (accountIsAdmin || vmLimit == -1) ? "Unlimited" : String.valueOf(vmLimit - vmTotal);
accountResponse.setVmLimit(vmLimitDisplay);
accountResponse.setVmTotal(vmTotal);
accountResponse.setVmAvailable(vmAvail);
long ipLimit = ApiDBUtils.findCorrectResourceLimit(account.getIpLimit(), account.getType(), ResourceType.public_ip);
String ipLimitDisplay = (accountIsAdmin || ipLimit == -1) ? "Unlimited" : String.valueOf(ipLimit);
long ipTotal = (account.getIpTotal() == null) ? 0 : account.getIpTotal();
Long ips = ipLimit - ipTotal;
// check how many free ips are left, and if it's less than max allowed number of ips from account - use this
// value
Long ipsLeft = account.getIpFree();
boolean unlimited = true;
if (ips.longValue() > ipsLeft.longValue()) {
ips = ipsLeft;
unlimited = false;
}
String ipAvail = ((accountIsAdmin || ipLimit == -1) && unlimited) ? "Unlimited" : String.valueOf(ips);
accountResponse.setIpLimit(ipLimitDisplay);
accountResponse.setIpTotal(ipTotal);
accountResponse.setIpAvailable(ipAvail);
long volumeLimit = ApiDBUtils.findCorrectResourceLimit(account.getVolumeLimit(), account.getType(), ResourceType.volume);
String volumeLimitDisplay = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit);
long volumeTotal = (account.getVolumeTotal() == 0) ? 0 : account.getVolumeTotal();
String volumeAvail = (accountIsAdmin || volumeLimit == -1) ? "Unlimited" : String.valueOf(volumeLimit - volumeTotal);
accountResponse.setVolumeLimit(volumeLimitDisplay);
accountResponse.setVolumeTotal(volumeTotal);
accountResponse.setVolumeAvailable(volumeAvail);
long snapshotLimit = ApiDBUtils.findCorrectResourceLimit(account.getSnapshotLimit(), account.getType(), ResourceType.snapshot);
String snapshotLimitDisplay = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit);
long snapshotTotal = (account.getSnapshotTotal() == null) ? 0 : account.getSnapshotTotal();
String snapshotAvail = (accountIsAdmin || snapshotLimit == -1) ? "Unlimited" : String.valueOf(snapshotLimit - snapshotTotal);
accountResponse.setSnapshotLimit(snapshotLimitDisplay);
accountResponse.setSnapshotTotal(snapshotTotal);
accountResponse.setSnapshotAvailable(snapshotAvail);
Long templateLimit = ApiDBUtils.findCorrectResourceLimit(account.getTemplateLimit(), account.getType(), ResourceType.template);
String templateLimitDisplay = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit);
Long templateTotal = (account.getTemplateTotal() == null) ? 0 : account.getTemplateTotal();
String templateAvail = (accountIsAdmin || templateLimit == -1) ? "Unlimited" : String.valueOf(templateLimit - templateTotal);
accountResponse.setTemplateLimit(templateLimitDisplay);
accountResponse.setTemplateTotal(templateTotal);
accountResponse.setTemplateAvailable(templateAvail);
// Get stopped and running VMs
accountResponse.setVmStopped(account.getVmStopped());
accountResponse.setVmRunning(account.getVmRunning());
//get resource limits for projects
long projectLimit = ApiDBUtils.findCorrectResourceLimit(account.getProjectLimit(), account.getType(), ResourceType.project);
String projectLimitDisplay = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit);
long projectTotal = (account.getProjectTotal() == null) ? 0 : account.getProjectTotal();
String projectAvail = (accountIsAdmin || projectLimit == -1) ? "Unlimited" : String.valueOf(projectLimit - projectTotal);
accountResponse.setProjectLimit(projectLimitDisplay);
accountResponse.setProjectTotal(projectTotal);
accountResponse.setProjectAvailable(projectAvail);
//get resource limits for networks
long networkLimit = ApiDBUtils.findCorrectResourceLimit(account.getNetworkLimit(), account.getType(), ResourceType.network);
String networkLimitDisplay = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit);
long networkTotal = (account.getNetworkTotal() == null) ? 0 : account.getNetworkTotal();
String networkAvail = (accountIsAdmin || networkLimit == -1) ? "Unlimited" : String.valueOf(networkLimit - networkTotal);
accountResponse.setNetworkLimit(networkLimitDisplay);
accountResponse.setNetworkTotal(networkTotal);
accountResponse.setNetworkAvailable(networkAvail);
//get resource limits for vpcs
long vpcLimit = ApiDBUtils.findCorrectResourceLimit(account.getVpcLimit(), account.getType(), ResourceType.vpc);
String vpcLimitDisplay = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit);
long vpcTotal = (account.getVpcTotal() == null) ? 0 : account.getVpcTotal();
String vpcAvail = (accountIsAdmin || vpcLimit == -1) ? "Unlimited" : String.valueOf(vpcLimit - vpcTotal);
accountResponse.setNetworkLimit(vpcLimitDisplay);
accountResponse.setNetworkTotal(vpcTotal);
accountResponse.setNetworkAvailable(vpcAvail);
// adding all the users for an account as part of the response obj
List<UserAccountJoinVO> usersForAccount = ApiDBUtils.findUserViewByAccountId(account.getId());
List<UserResponse> userResponses = ViewResponseHelper.createUserResponse(usersForAccount.toArray(new UserAccountJoinVO[usersForAccount.size()]));
accountResponse.setUsers(userResponses);
// set details
accountResponse.setDetails(ApiDBUtils.getAccountDetails(account.getId()));
accountResponse.setObjectName("account");
// set async job
accountResponse.setJobId(account.getJobUuid());
accountResponse.setJobStatus(account.getJobStatus());
return accountResponse;
}
@Override
public AccountJoinVO newAccountView(Account acct) {
SearchCriteria<AccountJoinVO> sc = acctIdSearch.create();
sc.setParameters("id", acct.getId());
List<AccountJoinVO> accounts = searchIncludingRemoved(sc, null, null, false);
assert accounts != null && accounts.size() == 1 : "No account found for account id " + acct.getId();
return accounts.get(0);
}
@Override
public List<AccountJoinVO> searchByIds(Long... ids) {
SearchCriteria<AccountJoinVO> sc = acctSearch.create();
sc.setParameters("idIN", ids);
return searchIncludingRemoved(sc, null, null, false);
}
}

View File

@ -145,6 +145,10 @@ public class DomainRouterJoinDaoImpl extends GenericDaoBase<DomainRouterJoinVO,
routerResponse.setVpcId(router.getVpcUuid());
// set async job
routerResponse.setJobId(router.getJobUuid());
routerResponse.setJobStatus(router.getJobStatus());
routerResponse.setObjectName("router");
return routerResponse;

View File

@ -173,6 +173,11 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
}
hostResponse.setResourceState(host.getResourceState().toString());
// set async job
hostResponse.setJobId(host.getJobUuid());
hostResponse.setJobStatus(host.getJobStatus());
hostResponse.setObjectName("host");
return hostResponse;

View File

@ -109,6 +109,11 @@ public class SecurityGroupJoinDaoImpl extends GenericDaoBase<SecurityGroupJoinVO
sgResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
// set async job
sgResponse.setJobId(vsg.getJobUuid());
sgResponse.setJobStatus(vsg.getJobStatus());
sgResponse.setObjectName("securitygroup");
return sgResponse;

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.user.dao;
package com.cloud.api.query.dao;
import java.util.List;

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.user.dao;
package com.cloud.api.query.dao;
import java.util.List;
@ -88,6 +88,11 @@ public class UserAccountJoinDaoImpl extends GenericDaoBase<UserAccountJoinVO, Lo
userResponse.setUsername(usr.getUsername());
userResponse.setApiKey(usr.getApiKey());
userResponse.setSecretKey(usr.getSecretKey());
// set async job
userResponse.setJobId(usr.getJobUuid());
userResponse.setJobStatus(usr.getJobStatus());
userResponse.setObjectName("user");
return userResponse;

View File

@ -187,6 +187,11 @@ public class VolumeJoinDaoImpl extends GenericDaoBase<VolumeJoinVO, Long> implem
}
volResponse.setExtractable(isExtractable);
// set async job
volResponse.setJobId(volume.getJobUuid());
volResponse.setJobStatus(volume.getJobStatus());
volResponse.setObjectName("volume");
return volResponse;
}

View File

@ -0,0 +1,569 @@
// 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.api.query.vo;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import com.cloud.user.Account.State;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="account_view")
public class AccountJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Column(name="id")
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="account_name")
private String accountName = null;
@Column(name="type")
private short type;
@Column(name="state")
@Enumerated(value=EnumType.STRING)
private State state;
@Column(name=GenericDao.REMOVED_COLUMN)
private Date removed;
@Column(name="cleanup_needed")
private boolean needsCleanup = false;
@Column(name="network_domain")
private String networkDomain;
@Column(name="domain_id")
private long domainId;
@Column(name="domain_uuid")
private String domainUuid;
@Column(name="domain_name")
private String domainName = null;
@Column(name="domain_path")
private String domainPath = null;
@Column(name="data_center_id")
private long dataCenterId;
@Column(name="data_center_uuid")
private String dataCenterUuid;
@Column(name="data_center_name")
private String dataCenterName;
@Column(name="bytesReceived")
private Long bytesReceived;
@Column(name="bytesSent")
private Long bytesSent;
@Column(name="vmLimit")
private Long vmLimit;
@Column(name="vmTotal")
private Long vmTotal;
@Column(name="ipLimit")
private Long ipLimit;
@Column(name="ipTotal")
private Long ipTotal;
@Column(name="ipFree")
private Long ipFree;
@Column(name="volumeLimit")
private Long volumeLimit;
@Column(name="volumeTotal")
private Long volumeTotal;
@Column(name="snapshotLimit")
private Long snapshotLimit;
@Column(name="snapshotTotal")
private Long snapshotTotal;
@Column(name="templateLimit")
private Long templateLimit;
@Column(name="templateTotal")
private Long templateTotal;
@Column(name="stoppedVms")
private Integer vmStopped;
@Column(name="runningVms")
private Integer vmRunning;
@Column(name="projectLimit")
private Long projectLimit;
@Column(name="projectTotal")
private Long projectTotal;
@Column(name="networkLimit")
private Long networkLimit;
@Column(name="networkTotal")
private Long networkTotal;
@Column(name="vpcLimit")
private Long vpcLimit;
@Column(name="vpcTotal")
private Long vpcTotal;
@Column(name="job_id")
private long jobId;
@Column(name="job_uuid")
private String jobUuid;
@Column(name="job_status")
private int jobStatus;
public AccountJoinVO() {
}
@Override
public long getId() {
return id;
}
@Override
public void setId(long id) {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public short getType() {
return type;
}
public void setType(short type) {
this.type = type;
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public Date getRemoved() {
return removed;
}
public void setRemoved(Date removed) {
this.removed = removed;
}
public boolean isNeedsCleanup() {
return needsCleanup;
}
public void setNeedsCleanup(boolean needsCleanup) {
this.needsCleanup = needsCleanup;
}
public String getNetworkDomain() {
return networkDomain;
}
public void setNetworkDomain(String networkDomain) {
this.networkDomain = networkDomain;
}
public long getDomainId() {
return domainId;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
public String getDomainUuid() {
return domainUuid;
}
public void setDomainUuid(String domainUuid) {
this.domainUuid = domainUuid;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public String getDomainPath() {
return domainPath;
}
public void setDomainPath(String domainPath) {
this.domainPath = domainPath;
}
public long getDataCenterId() {
return dataCenterId;
}
public void setDataCenterId(long dataCenterId) {
this.dataCenterId = dataCenterId;
}
public String getDataCenterUuid() {
return dataCenterUuid;
}
public void setDataCenterUuid(String dataCenterUuid) {
this.dataCenterUuid = dataCenterUuid;
}
public String getDataCenterName() {
return dataCenterName;
}
public void setDataCenterName(String dataCenterName) {
this.dataCenterName = dataCenterName;
}
public Long getBytesReceived() {
return bytesReceived;
}
public void setBytesReceived(Long bytesReceived) {
this.bytesReceived = bytesReceived;
}
public Long getBytesSent() {
return bytesSent;
}
public void setBytesSent(Long bytesSent) {
this.bytesSent = bytesSent;
}
public Long getVmTotal() {
return vmTotal;
}
public void setVmTotal(Long vmTotal) {
this.vmTotal = vmTotal;
}
public Long getIpTotal() {
return ipTotal;
}
public void setIpTotal(Long ipTotal) {
this.ipTotal = ipTotal;
}
public Long getIpFree() {
return ipFree;
}
public void setIpFree(Long ipFree) {
this.ipFree = ipFree;
}
public Long getVolumeTotal() {
return volumeTotal;
}
public void setVolumeTotal(Long volumeTotal) {
this.volumeTotal = volumeTotal;
}
public Long getSnapshotTotal() {
return snapshotTotal;
}
public void setSnapshotTotal(Long snapshotTotal) {
this.snapshotTotal = snapshotTotal;
}
public Long getTemplateTotal() {
return templateTotal;
}
public void setTemplateTotal(Long templateTotal) {
this.templateTotal = templateTotal;
}
public Integer getVmStopped() {
return vmStopped;
}
public void setVmStopped(Integer vmStopped) {
this.vmStopped = vmStopped;
}
public Integer getVmRunning() {
return vmRunning;
}
public void setVmRunning(Integer vmRunning) {
this.vmRunning = vmRunning;
}
public Long getProjectTotal() {
return projectTotal;
}
public void setProjectTotal(Long projectTotal) {
this.projectTotal = projectTotal;
}
public Long getNetworkTotal() {
return networkTotal;
}
public void setNetworkTotal(Long networkTotal) {
this.networkTotal = networkTotal;
}
public Long getVpcTotal() {
return vpcTotal;
}
public void setVpcTotal(Long vpcTotal) {
this.vpcTotal = vpcTotal;
}
public Long getVmLimit() {
return vmLimit;
}
public void setVmLimit(Long vmLimit) {
this.vmLimit = vmLimit;
}
public Long getIpLimit() {
return ipLimit;
}
public void setIpLimit(Long ipLimit) {
this.ipLimit = ipLimit;
}
public Long getVolumeLimit() {
return volumeLimit;
}
public void setVolumeLimit(Long volumeLimit) {
this.volumeLimit = volumeLimit;
}
public Long getSnapshotLimit() {
return snapshotLimit;
}
public void setSnapshotLimit(Long snapshotLimit) {
this.snapshotLimit = snapshotLimit;
}
public Long getTemplateLimit() {
return templateLimit;
}
public void setTemplateLimit(Long templateLimit) {
this.templateLimit = templateLimit;
}
public Long getProjectLimit() {
return projectLimit;
}
public void setProjectLimit(Long projectLimit) {
this.projectLimit = projectLimit;
}
public Long getNetworkLimit() {
return networkLimit;
}
public void setNetworkLimit(Long networkLimit) {
this.networkLimit = networkLimit;
}
public Long getVpcLimit() {
return vpcLimit;
}
public void setVpcLimit(Long vpcLimit) {
this.vpcLimit = vpcLimit;
}
public long getJobId() {
return jobId;
}
public void setJobId(long jobId) {
this.jobId = jobId;
}
public String getJobUuid() {
return jobUuid;
}
public void setJobUuid(String jobUuid) {
this.jobUuid = jobUuid;
}
public int getJobStatus() {
return jobStatus;
}
public void setJobStatus(int jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -17,6 +17,8 @@
package com.cloud.api.query.vo;
import com.cloud.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
/**
@ -25,7 +27,7 @@ import org.apache.cloudstack.api.InternalIdentity;
* @author minc
*
*/
public interface ControlledViewEntity extends ControlledEntity, InternalIdentity {
public interface ControlledViewEntity extends ControlledEntity, InternalIdentity, Identity {
public String getDomainPath();

View File

@ -30,11 +30,10 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.router.VirtualRouter.RedundantState;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="domain_router_view")
public class DomainRouterJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class DomainRouterJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -243,6 +242,7 @@ public class DomainRouterJoinVO extends BaseViewVO implements ControlledViewEnti
@Override
public String getUuid() {
return uuid;
}

View File

@ -26,11 +26,10 @@ import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
import com.cloud.event.Event.State;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="event_view")
public class EventJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class EventJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -119,6 +118,7 @@ public class EventJoinVO extends BaseViewVO implements ControlledViewEntity, Int
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -32,6 +32,8 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Cluster;
import com.cloud.resource.ResourceState;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
/**
@ -41,7 +43,7 @@ import org.apache.cloudstack.api.InternalIdentity;
*/
@Entity
@Table(name="host_view")
public class HostJoinVO extends BaseViewVO implements InternalIdentity {
public class HostJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Column(name="id")
private long id;
@ -188,6 +190,7 @@ public class HostJoinVO extends BaseViewVO implements InternalIdentity {
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -23,11 +23,10 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="instance_group_view")
public class InstanceGroupJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class InstanceGroupJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -96,6 +95,7 @@ public class InstanceGroupJoinVO extends BaseViewVO implements ControlledViewEnt
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -26,11 +26,10 @@ import javax.persistence.Table;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="project_invitation_view")
public class ProjectInvitationJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class ProjectInvitationJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -96,6 +95,7 @@ public class ProjectInvitationJoinVO extends BaseViewVO implements ControlledVie
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -27,11 +27,13 @@ import javax.persistence.Table;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="project_view")
public class ProjectJoinVO extends BaseViewVO implements InternalIdentity {
public class ProjectJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -120,6 +122,7 @@ public class ProjectJoinVO extends BaseViewVO implements InternalIdentity {
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -23,11 +23,10 @@ import javax.persistence.Enumerated;
import javax.persistence.Table;
import com.cloud.server.ResourceTag.TaggedResourceType;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="resource_tag_view")
public class ResourceTagJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class ResourceTagJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -95,6 +94,7 @@ public class ResourceTagJoinVO extends BaseViewVO implements ControlledViewEntit
public ResourceTagJoinVO() {
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -24,11 +24,10 @@ import javax.persistence.Table;
import com.cloud.network.security.SecurityRule.SecurityRuleType;
import com.cloud.server.ResourceTag.TaggedResourceType;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="security_group_view")
public class SecurityGroupJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class SecurityGroupJoinVO extends BaseViewVO implements ControlledViewEntity{
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -152,6 +151,7 @@ public class SecurityGroupJoinVO extends BaseViewVO implements ControlledViewEnt
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -24,11 +24,13 @@ import javax.persistence.Table;
import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="user_view")
public class UserAccountJoinVO extends BaseViewVO implements InternalIdentity {
public class UserAccountJoinVO extends BaseViewVO implements InternalIdentity, Identity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -104,6 +106,14 @@ public class UserAccountJoinVO extends BaseViewVO implements InternalIdentity {
@Column(name="domain_path")
private String domainPath = null;
@Column(name="job_id")
private long jobId;
@Column(name="job_uuid")
private String jobUuid;
@Column(name="job_status")
private int jobStatus;
public UserAccountJoinVO() {
}
@ -118,6 +128,7 @@ public class UserAccountJoinVO extends BaseViewVO implements InternalIdentity {
this.id = id;
}
@Override
public String getUuid() {
return uuid;
}
@ -308,6 +319,30 @@ public class UserAccountJoinVO extends BaseViewVO implements InternalIdentity {
this.loginAttempts = loginAttempts;
}
public long getJobId() {
return jobId;
}
public void setJobId(long jobId) {
this.jobId = jobId;
}
public String getJobUuid() {
return jobUuid;
}
public void setJobUuid(String jobUuid) {
this.jobUuid = jobUuid;
}
public int getJobStatus() {
return jobStatus;
}
public void setJobStatus(int jobStatus) {
this.jobStatus = jobStatus;
}
}

View File

@ -37,11 +37,10 @@ import com.cloud.utils.db.Encrypt;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="user_vm_view")
public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id", updatable=false, nullable = false)
private long id;
@ -378,6 +377,7 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity, In
}
@Override
public String getUuid() {
return uuid;
}

View File

@ -31,12 +31,10 @@ import com.cloud.storage.Volume;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
import com.cloud.utils.db.GenericDao;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.Type;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="volume_view")
public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity, InternalIdentity {
public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity {
@Column(name="id")
private long id;
@ -263,6 +261,7 @@ public class VolumeJoinVO extends BaseViewVO implements ControlledViewEntity, In
@Override
public String getUuid() {
return uuid;
}

View File

@ -25,6 +25,7 @@ import com.cloud.agent.manager.ClusteredAgentManagerImpl;
import com.cloud.alert.AlertManagerImpl;
import com.cloud.alert.dao.AlertDaoImpl;
import com.cloud.api.query.QueryManagerImpl;
import com.cloud.api.query.dao.AccountJoinDaoImpl;
import com.cloud.api.query.dao.DomainRouterJoinDaoImpl;
import com.cloud.api.query.dao.InstanceGroupJoinDaoImpl;
import com.cloud.api.query.dao.ProjectAccountJoinDaoImpl;
@ -32,6 +33,7 @@ import com.cloud.api.query.dao.ProjectInvitationJoinDaoImpl;
import com.cloud.api.query.dao.ProjectJoinDaoImpl;
import com.cloud.api.query.dao.ResourceTagJoinDaoImpl;
import com.cloud.api.query.dao.SecurityGroupJoinDaoImpl;
import com.cloud.api.query.dao.UserAccountJoinDaoImpl;
import com.cloud.api.query.dao.UserVmJoinDaoImpl;
import com.cloud.api.query.dao.HostJoinDaoImpl;
import com.cloud.api.query.dao.VolumeJoinDaoImpl;
@ -195,7 +197,6 @@ import com.cloud.user.DomainManagerImpl;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.user.dao.SSHKeyPairDaoImpl;
import com.cloud.user.dao.UserAccountDaoImpl;
import com.cloud.user.dao.UserAccountJoinDaoImpl;
import com.cloud.user.dao.UserDaoImpl;
import com.cloud.user.dao.UserStatisticsDaoImpl;
import com.cloud.user.dao.UserStatsLogDaoImpl;
@ -244,6 +245,7 @@ public class DefaultComponentLibrary extends ComponentLibraryBase implements Com
addDao("ProjectInvitationJoinDao", ProjectInvitationJoinDaoImpl.class);
addDao("HostJoinDao", HostJoinDaoImpl.class);
addDao("VolumeJoinDao", VolumeJoinDaoImpl.class);
addDao("AccountJoinDao", AccountJoinDaoImpl.class);
ComponentInfo<? extends GenericDao<?, ? extends Serializable>> info = addDao("ServiceOfferingDao", ServiceOfferingDaoImpl.class);
info.addParameter("cache.size", "50");
info.addParameter("cache.time.to.live", "600");

View File

@ -242,6 +242,36 @@ public class ResourceLimitManagerImpl implements ResourceLimitService, Manager {
return max;
}
@Override
public long findCorrectResourceLimitForAccount(short accountType, Long limit, ResourceType type) {
long max = Resource.RESOURCE_UNLIMITED; // if resource limit is not found, then we treat it as unlimited
// No limits for Root Admin accounts
if (_accountMgr.isRootAdmin(accountType)) {
return max;
}
// Check if limit is configured for account
if (limit != null) {
max = limit.longValue();
} else {
// If the account has an no limit set, then return global default account limits
Long value = null;
if (accountType == Account.ACCOUNT_TYPE_PROJECT) {
value = projectResourceLimitMap.get(type);
} else {
value = accountResourceLimitMap.get(type);
}
if (value != null) {
return value;
}
}
return max;
}
@Override
public long findCorrectResourceLimitForDomain(Domain domain, ResourceType type) {
long max = Resource.RESOURCE_UNLIMITED;

View File

@ -46,6 +46,7 @@ import com.cloud.acl.ControlledEntity;
import com.cloud.acl.SecurityChecker;
import com.cloud.acl.SecurityChecker.AccessType;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.dao.UserAccountJoinDao;
import com.cloud.api.query.vo.ControlledViewEntity;
@ -110,7 +111,6 @@ import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account.State;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserAccountDao;
import com.cloud.user.dao.UserAccountJoinDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
@ -2021,125 +2021,6 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
return null;
}
@Override
public Pair<List<? extends Account>, Integer> searchForAccounts(ListAccountsCmd cmd) {
Account caller = UserContext.current().getCaller();
Long domainId = cmd.getDomainId();
Long accountId = cmd.getId();
String accountName = cmd.getSearchName();
boolean isRecursive = cmd.isRecursive();
boolean listAll = cmd.listAll();
Boolean listForDomain = false;
if (accountId != null) {
Account account = _accountDao.findById(accountId);
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by id " + accountId);
}
checkAccess(caller, null, true, account);
}
if (domainId != null) {
Domain domain = _domainMgr.getDomain(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
}
checkAccess(caller, domain);
if (accountName != null) {
Account account = _accountDao.findActiveAccount(accountName, domainId);
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId);
}
checkAccess(caller, null, true, account);
}
}
if (accountId == null) {
if (isAdmin(caller.getType()) && listAll && domainId == null) {
listForDomain = true;
isRecursive = true;
if (domainId == null) {
domainId = caller.getDomainId();
}
} else if (isAdmin(caller.getType()) && domainId != null) {
listForDomain = true;
} else {
accountId = caller.getAccountId();
}
}
Filter searchFilter = new Filter(AccountVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
Object type = cmd.getAccountType();
Object state = cmd.getState();
Object isCleanupRequired = cmd.isCleanupRequired();
Object keyword = cmd.getKeyword();
SearchBuilder<AccountVO> sb = _accountDao.createSearchBuilder();
sb.and("accountName", sb.entity().getAccountName(), SearchCriteria.Op.EQ);
sb.and("domainId", sb.entity().getDomainId(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
sb.and("needsCleanup", sb.entity().getNeedsCleanup(), SearchCriteria.Op.EQ);
sb.and("typeNEQ", sb.entity().getType(), SearchCriteria.Op.NEQ);
sb.and("idNEQ", sb.entity().getId(), SearchCriteria.Op.NEQ);
if (listForDomain && isRecursive) {
SearchBuilder<DomainVO> domainSearch = _domainDao.createSearchBuilder();
domainSearch.and("path", domainSearch.entity().getPath(), SearchCriteria.Op.LIKE);
sb.join("domainSearch", domainSearch, sb.entity().getDomainId(), domainSearch.entity().getId(), JoinBuilder.JoinType.INNER);
}
SearchCriteria<AccountVO> sc = sb.create();
sc.setParameters("idNEQ", Account.ACCOUNT_ID_SYSTEM);
if (keyword != null) {
SearchCriteria<AccountVO> ssc = _accountDao.createSearchCriteria();
ssc.addOr("accountName", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("state", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("accountName", SearchCriteria.Op.SC, ssc);
}
if (type != null) {
sc.setParameters("type", type);
}
if (state != null) {
sc.setParameters("state", state);
}
if (isCleanupRequired != null) {
sc.setParameters("needsCleanup", isCleanupRequired);
}
if (accountName != null) {
sc.setParameters("accountName", accountName);
}
// don't return account of type project to the end user
sc.setParameters("typeNEQ", 5);
if (accountId != null) {
sc.setParameters("id", accountId);
}
if (listForDomain) {
DomainVO domain = _domainDao.findById(domainId);
if (isRecursive) {
sc.setJoinParameters("domainSearch", "path", domain.getPath() + "%");
} else {
sc.setParameters("domainId", domainId);
}
}
Pair<List<AccountVO>, Integer> result = _accountDao.searchAndCount(sc, searchFilter);
return new Pair<List<? extends Account>, Integer>(result.first(), result.second());
}
@Override

View File

@ -109,7 +109,7 @@ public class ListPerfTest extends APITest {
@Test
public void testListVolumes(){
// issue list Hosts calls
// issue list Volumes calls
HashMap<String, String> params = new HashMap<String, String>();
params.put("response", "json");
params.put("listAll", "true");
@ -120,4 +120,32 @@ public class ListPerfTest extends APITest {
System.out.println("Time taken to list Volumes: " + (after - before) + " ms");
}
@Test
public void testListAccounts(){
// issue list Accounts calls
HashMap<String, String> params = new HashMap<String, String>();
params.put("response", "json");
params.put("listAll", "true");
params.put("sessionkey", sessionKey);
long before = System.currentTimeMillis();
String result = this.sendRequest("listAccounts", params);
long after = System.currentTimeMillis();
System.out.println("Time taken to list Accounts: " + (after - before) + " ms");
}
@Test
public void testListUsers(){
// issue list Users calls
HashMap<String, String> params = new HashMap<String, String>();
params.put("response", "json");
params.put("listAll", "true");
params.put("sessionkey", sessionKey);
long before = System.currentTimeMillis();
String result = this.sendRequest("listUsers", params);
long after = System.currentTimeMillis();
System.out.println("Time taken to list Users: " + (after - before) + " ms");
}
}

View File

@ -301,13 +301,6 @@ public class MockAccountManagerImpl implements Manager, AccountManager, AccountS
return null;
}
@Override
public Pair<List<? extends Account>, Integer> searchForAccounts(ListAccountsCmd cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean enableAccount(long accountId) {
// TODO Auto-generated method stub

View File

@ -70,6 +70,13 @@ public class MockResourceLimitManagerImpl implements ResourceLimitService, Manag
return 0;
}
@Override
public long findCorrectResourceLimitForAccount(short accountType, Long limit, ResourceType type) {
// TODO Auto-generated method stub
return 0;
}
/* (non-Javadoc)
* @see com.cloud.user.ResourceLimitService#findCorrectResourceLimitForDomain(com.cloud.domain.Domain, com.cloud.configuration.Resource.ResourceType)
*/
@ -85,7 +92,7 @@ public class MockResourceLimitManagerImpl implements ResourceLimitService, Manag
@Override
public void incrementResourceCount(long accountId, ResourceType type, Long... delta) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
@ -94,7 +101,7 @@ public class MockResourceLimitManagerImpl implements ResourceLimitService, Manag
@Override
public void decrementResourceCount(long accountId, ResourceType type, Long... delta) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
@ -103,7 +110,7 @@ public class MockResourceLimitManagerImpl implements ResourceLimitService, Manag
@Override
public void checkResourceLimit(Account account, ResourceType type, long... count) throws ResourceAllocationException {
// TODO Auto-generated method stub
}
/* (non-Javadoc)

View File

@ -2900,7 +2900,7 @@ left join projects on projects.project_account_id = instance_group.account_id;
DROP VIEW IF EXISTS `cloud`.`user_view`;
CREATE VIEW user_view AS
select
select
user.id,
user.uuid,
user.username,
@ -2917,17 +2917,25 @@ user.timezone,
user.registration_token,
user.is_registered,
user.incorrect_login_attempts,
account.id account_id,
account.id account_id,
account.uuid account_uuid,
account.account_name account_name,
account.type account_type,
domain.id domain_id,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path
from user
domain.name domain_name,
domain.path domain_path,
async_job.id job_id,
async_job.uuid job_uuid,
async_job.job_status job_status,
async_job.account_id job_account_id
from user
inner join account on user.account_id = account.id
inner join domain on account.domain_id=domain.id;
inner join domain on account.domain_id=domain.id
left join async_job on async_job.instance_id = user.id and async_job.instance_type = "User" and async_job.job_status = 0;
DROP VIEW IF EXISTS `cloud`.`project_view`;
CREATE VIEW project_view AS
@ -3145,3 +3153,91 @@ left join vm_template on volumes.template_id = vm_template.id
left join resource_tags on resource_tags.resource_id = volumes.id and resource_tags.resource_type = "Volume"
left join async_job on async_job.instance_id = volumes.id and async_job.instance_type = "Volume" and async_job.job_status = 0;
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;
CREATE VIEW account_netstats_view AS
SELECT account_id,
sum(net_bytes_received)+ sum(current_bytes_received) as bytesReceived,
sum(net_bytes_sent)+ sum(current_bytes_sent) as bytesSent
FROM user_statistics
group by account_id;
DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`;
CREATE VIEW account_vmstats_view AS
SELECT account_id, state, count(*) as vmcount
from vm_instance
group by account_id, state;
DROP VIEW IF EXISTS `cloud`.`free_ip_view`;
CREATE VIEW free_ip_view AS
select count(user_ip_address.id) free_ip
from user_ip_address
inner join vlan on vlan.id = user_ip_address.vlan_db_id and vlan.vlan_type = "VirtualNetwork"
where state = "Free"
DROP VIEW IF EXISTS `cloud`.`account_view`;
CREATE VIEW account_view AS
select
account.id,
account.uuid,
account.account_name,
account.type,
account.state,
account.removed,
account.cleanup_needed,
account.network_domain,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path,
data_center.id data_center_id,
data_center.uuid data_center_uuid,
data_center.name data_center_name,
account_netstats_view.bytesReceived,
account_netstats_view.bytesSent,
vmlimit.max vmLimit,
vmcount.count vmTotal,
runningvm.vmcount runningVms,
stoppedvm.vmcount stoppedVms,
iplimit.max ipLimit,
ipcount.count ipTotal,
free_ip_view.free_ip ipFree,
volumelimit.max volumeLimit,
volumecount.count volumeTotal,
snapshotlimit.max snapshotLimit,
snapshotcount.count snapshotTotal,
templatelimit.max templateLimit,
templatecount.count templateTotal,
vpclimit.max vpcLimit,
vpccount.count vpcTotal,
projectlimit.max projectLimit,
projectcount.count projectTotal,
networklimit.max networkLimit,
networkcount.count networkTotal,
async_job.id job_id,
async_job.uuid job_uuid,
async_job.job_status job_status,
async_job.account_id job_account_id
from free_ip_view, account
inner join domain on account.domain_id=domain.id
left join data_center on account.default_zone_id = data_center.id
left join account_netstats_view on account.id = account_netstats_view.account_id
left join resource_limit vmlimit on account.id = vmlimit.account_id and vmlimit.type = "user_vm"
left join resource_count vmcount on account.id = vmcount.account_id and vmcount.type = "user_vm"
left join account_vmstats_view runningvm on account.id = runningvm.account_id and runningvm.state = "Running"
left join account_vmstats_view stoppedvm on account.id = stoppedvm.account_id and stoppedvm.state = "Stopped"
left join resource_limit iplimit on account.id = iplimit.account_id and iplimit.type = "public_ip"
left join resource_count ipcount on account.id = ipcount.account_id and ipcount.type = "public_ip"
left join resource_limit volumelimit on account.id = volumelimit.account_id and volumelimit.type = "volume"
left join resource_count volumecount on account.id = volumecount.account_id and volumecount.type = "volume"
left join resource_limit snapshotlimit on account.id = snapshotlimit.account_id and snapshotlimit.type = "snapshot"
left join resource_count snapshotcount on account.id = snapshotcount.account_id and snapshotcount.type = "snapshot"
left join resource_limit templatelimit on account.id = templatelimit.account_id and templatelimit.type = "template"
left join resource_count templatecount on account.id = templatecount.account_id and templatecount.type = "template"
left join resource_limit vpclimit on account.id = vpclimit.account_id and vpclimit.type = "vpc"
left join resource_count vpccount on account.id = vpccount.account_id and vpccount.type = "vpc"
left join resource_limit projectlimit on account.id = projectlimit.account_id and projectlimit.type = "project"
left join resource_count projectcount on account.id = projectcount.account_id and projectcount.type = "project"
left join resource_limit networklimit on account.id = networklimit.account_id and networklimit.type = "network"
left join resource_count networkcount on account.id = networkcount.account_id and networkcount.type = "network"
left join async_job on async_job.instance_id = account.id and async_job.instance_type = "Account" and async_job.job_status = 0;

View File

@ -482,7 +482,7 @@ left join projects on projects.project_account_id = instance_group.account_id;
DROP VIEW IF EXISTS `cloud`.`user_view`;
CREATE VIEW user_view AS
select
select
user.id,
user.uuid,
user.username,
@ -499,17 +499,23 @@ user.timezone,
user.registration_token,
user.is_registered,
user.incorrect_login_attempts,
account.id account_id,
account.id account_id,
account.uuid account_uuid,
account.account_name account_name,
account.type account_type,
domain.id domain_id,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path
from user
domain.name domain_name,
domain.path domain_path,
async_job.id job_id,
async_job.uuid job_uuid,
async_job.job_status job_status,
async_job.account_id job_account_id
from user
inner join account on user.account_id = account.id
inner join domain on account.domain_id=domain.id;
inner join domain on account.domain_id=domain.id
left join async_job on async_job.instance_id = user.id and async_job.instance_type = "User" and async_job.job_status = 0;
DROP VIEW IF EXISTS `cloud`.`project_view`;
CREATE VIEW project_view AS
@ -727,4 +733,91 @@ left join vm_template on volumes.template_id = vm_template.id
left join resource_tags on resource_tags.resource_id = volumes.id and resource_tags.resource_type = "Volume"
left join async_job on async_job.instance_id = volumes.id and async_job.instance_type = "Volume" and async_job.job_status = 0;
DROP VIEW IF EXISTS `cloud`.`account_netstats_view`;
CREATE VIEW account_netstats_view AS
SELECT account_id,
sum(net_bytes_received)+ sum(current_bytes_received) as bytesReceived,
sum(net_bytes_sent)+ sum(current_bytes_sent) as bytesSent
FROM user_statistics
group by account_id;
DROP VIEW IF EXISTS `cloud`.`account_vmstats_view`;
CREATE VIEW account_vmstats_view AS
SELECT account_id, state, count(*) as vmcount
from vm_instance
group by account_id, state;
DROP VIEW IF EXISTS `cloud`.`free_ip_view`;
CREATE VIEW free_ip_view AS
select count(user_ip_address.id) free_ip
from user_ip_address
inner join vlan on vlan.id = user_ip_address.vlan_db_id and vlan.vlan_type = "VirtualNetwork"
where state = "Free"
DROP VIEW IF EXISTS `cloud`.`account_view`;
CREATE VIEW account_view AS
select
account.id,
account.uuid,
account.account_name,
account.type,
account.state,
account.removed,
account.cleanup_needed,
account.network_domain,
domain.id domain_id,
domain.uuid domain_uuid,
domain.name domain_name,
domain.path domain_path,
data_center.id data_center_id,
data_center.uuid data_center_uuid,
data_center.name data_center_name,
account_netstats_view.bytesReceived,
account_netstats_view.bytesSent,
vmlimit.max vmLimit,
vmcount.count vmTotal,
runningvm.vmcount runningVms,
stoppedvm.vmcount stoppedVms,
iplimit.max ipLimit,
ipcount.count ipTotal,
free_ip_view.free_ip ipFree,
volumelimit.max volumeLimit,
volumecount.count volumeTotal,
snapshotlimit.max snapshotLimit,
snapshotcount.count snapshotTotal,
templatelimit.max templateLimit,
templatecount.count templateTotal,
vpclimit.max vpcLimit,
vpccount.count vpcTotal,
projectlimit.max projectLimit,
projectcount.count projectTotal,
networklimit.max networkLimit,
networkcount.count networkTotal,
async_job.id job_id,
async_job.uuid job_uuid,
async_job.job_status job_status,
async_job.account_id job_account_id
from free_ip_view, account
inner join domain on account.domain_id=domain.id
left join data_center on account.default_zone_id = data_center.id
left join account_netstats_view on account.id = account_netstats_view.account_id
left join resource_limit vmlimit on account.id = vmlimit.account_id and vmlimit.type = "user_vm"
left join resource_count vmcount on account.id = vmcount.account_id and vmcount.type = "user_vm"
left join account_vmstats_view runningvm on account.id = runningvm.account_id and runningvm.state = "Running"
left join account_vmstats_view stoppedvm on account.id = stoppedvm.account_id and stoppedvm.state = "Stopped"
left join resource_limit iplimit on account.id = iplimit.account_id and iplimit.type = "public_ip"
left join resource_count ipcount on account.id = ipcount.account_id and ipcount.type = "public_ip"
left join resource_limit volumelimit on account.id = volumelimit.account_id and volumelimit.type = "volume"
left join resource_count volumecount on account.id = volumecount.account_id and volumecount.type = "volume"
left join resource_limit snapshotlimit on account.id = snapshotlimit.account_id and snapshotlimit.type = "snapshot"
left join resource_count snapshotcount on account.id = snapshotcount.account_id and snapshotcount.type = "snapshot"
left join resource_limit templatelimit on account.id = templatelimit.account_id and templatelimit.type = "template"
left join resource_count templatecount on account.id = templatecount.account_id and templatecount.type = "template"
left join resource_limit vpclimit on account.id = vpclimit.account_id and vpclimit.type = "vpc"
left join resource_count vpccount on account.id = vpccount.account_id and vpccount.type = "vpc"
left join resource_limit projectlimit on account.id = projectlimit.account_id and projectlimit.type = "project"
left join resource_count projectcount on account.id = projectcount.account_id and projectcount.type = "project"
left join resource_limit networklimit on account.id = networklimit.account_id and networklimit.type = "network"
left join resource_count networkcount on account.id = networkcount.account_id and networkcount.type = "network"
left join async_job on async_job.instance_id = account.id and async_job.instance_type = "Account" and async_job.job_status = 0;