use of com.cloud.user.Account in project CloudStack-archive by CloudStack-extras.
the class UsageManagerImpl method createVolumeHelperEvent.
private void createVolumeHelperEvent(UsageEventVO event) {
Long doId = -1L;
long zoneId = -1L;
Long templateId = -1L;
long size = -1L;
long volId = event.getResourceId();
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
doId = event.getOfferingId();
zoneId = event.getZoneId();
templateId = event.getTemplateId();
size = event.getSize();
}
if (EventTypes.EVENT_VOLUME_CREATE.equals(event.getType())) {
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
sc.addAnd("deleted", SearchCriteria.Op.NULL);
List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
if (volumesVOs.size() > 0) {
//This is a safeguard to avoid double counting of volumes.
s_logger.error("Found duplicate usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking as deleted...");
}
for (UsageVolumeVO volumesVO : volumesVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
}
volumesVO.setDeleted(event.getCreateDate());
m_usageVolumeDao.update(volumesVO);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("create volume with id : " + volId + " for account: " + event.getAccountId());
}
Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId());
UsageVolumeVO volumeVO = new UsageVolumeVO(volId, zoneId, event.getAccountId(), acct.getDomainId(), doId, templateId, size, event.getCreateDate(), null);
m_usageVolumeDao.persist(volumeVO);
} else if (EventTypes.EVENT_VOLUME_DELETE.equals(event.getType())) {
SearchCriteria<UsageVolumeVO> sc = m_usageVolumeDao.createSearchCriteria();
sc.addAnd("accountId", SearchCriteria.Op.EQ, event.getAccountId());
sc.addAnd("id", SearchCriteria.Op.EQ, volId);
sc.addAnd("deleted", SearchCriteria.Op.NULL);
List<UsageVolumeVO> volumesVOs = m_usageVolumeDao.search(sc, null);
if (volumesVOs.size() > 1) {
s_logger.warn("More that one usage entry for volume: " + volId + " assigned to account: " + event.getAccountId() + "; marking them all as deleted...");
}
for (UsageVolumeVO volumesVO : volumesVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("deleting volume: " + volumesVO.getId() + " from account: " + volumesVO.getAccountId());
}
// there really shouldn't be more than one
volumesVO.setDeleted(event.getCreateDate());
m_usageVolumeDao.update(volumesVO);
}
}
}
use of com.cloud.user.Account in project cloudstack by apache.
the class CreateAutoScaleVmProfileCmd method getAccountId.
public long getAccountId() {
if (accountId != null) {
return accountId;
}
Account account = null;
if (autoscaleUserId != null) {
User user = _entityMgr.findById(User.class, autoscaleUserId);
account = _entityMgr.findById(Account.class, user.getAccountId());
} else {
account = CallContext.current().getCallingAccount();
}
accountId = account.getAccountId();
domainId = account.getDomainId();
return accountId;
}
use of com.cloud.user.Account in project cloudstack by apache.
the class CreateAffinityGroupCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Account caller = CallContext.current().getCallingAccount();
//For domain wide affinity groups (if the affinity group processor type allows it)
if (projectId == null && domainId != null && accountName == null && _accountService.isRootAdmin(caller.getId())) {
return Account.ACCOUNT_ID_SYSTEM;
}
Account owner = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
if (owner == null) {
return caller.getAccountId();
}
return owner.getAccountId();
}
use of com.cloud.user.Account in project cloudstack by apache.
the class DeleteAffinityGroupCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Account caller = CallContext.current().getCallingAccount();
//For domain wide affinity groups (if the affinity group processor type allows it)
if (projectId == null && domainId != null && accountName == null && _accountService.isRootAdmin(caller.getId())) {
return Account.ACCOUNT_ID_SYSTEM;
}
Account owner = _accountService.finalizeOwner(caller, accountName, domainId, projectId);
if (owner == null) {
return caller.getAccountId();
}
return owner.getAccountId();
}
use of com.cloud.user.Account in project cloudstack by apache.
the class QuotaServiceImpl method findQuotaBalanceVO.
@Override
public List<QuotaBalanceVO> findQuotaBalanceVO(Long accountId, String accountName, Long domainId, Date startDate, Date endDate) {
if ((accountId == null) && (accountName != null) && (domainId != null)) {
Account userAccount = null;
Account caller = CallContext.current().getCallingAccount();
if (_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
Filter filter = new Filter(AccountVO.class, "id", Boolean.FALSE, null, null);
List<AccountVO> accounts = _accountDao.listAccounts(accountName, domainId, filter);
if (!accounts.isEmpty()) {
userAccount = accounts.get(0);
}
if (userAccount != null) {
accountId = userAccount.getId();
} else {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
}
} else {
throw new PermissionDeniedException("Invalid Domain Id or Account");
}
}
startDate = startDate == null ? new Date() : startDate;
if (endDate == null) {
// adjust start date to end of day as there is no end date
Date adjustedStartDate = computeAdjustedTime(_respBldr.startOfNextDay(startDate));
if (s_logger.isDebugEnabled()) {
s_logger.debug("getQuotaBalance1: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", on or before " + adjustedStartDate);
}
List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.lastQuotaBalanceVO(accountId, domainId, adjustedStartDate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found records size=" + qbrecords.size());
}
if (qbrecords.isEmpty()) {
s_logger.info("Incorrect Date there are no quota records before this date " + adjustedStartDate);
return qbrecords;
} else {
return qbrecords;
}
} else {
Date adjustedStartDate = computeAdjustedTime(startDate);
if (endDate.after(_respBldr.startOfNextDay())) {
throw new InvalidParameterValueException("Incorrect Date Range. End date:" + endDate + " should not be in future. ");
} else if (startDate.before(endDate)) {
Date adjustedEndDate = computeAdjustedTime(endDate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("getQuotaBalance2: Getting quota balance records for account: " + accountId + ", domainId: " + domainId + ", between " + adjustedStartDate + " and " + adjustedEndDate);
}
List<QuotaBalanceVO> qbrecords = _quotaBalanceDao.findQuotaBalance(accountId, domainId, adjustedStartDate, adjustedEndDate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("getQuotaBalance3: Found records size=" + qbrecords.size());
}
if (qbrecords.isEmpty()) {
s_logger.info("There are no quota records between these dates start date " + adjustedStartDate + " and end date:" + endDate);
return qbrecords;
} else {
return qbrecords;
}
} else {
throw new InvalidParameterValueException("Incorrect Date Range. Start date: " + startDate + " is after end date:" + endDate);
}
}
}
Aggregations