@Override public AccountVO getSystemAccount() { if (_systemAccount == null) { _systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM); } return _systemAccount; }
@Override public Account getAccount(long accountId) { return _accountDao.findByIdIncludingRemoved(accountId); }
public static Account findAccountByNameDomain(String accountName, Long domainId) { return s_accountDao.findActiveAccount(accountName, domainId); }
private long getNewAccountId(long domainId, String accountName, Long accountId) { Account newAccount = null; if (StringUtils.isNotBlank(accountName)) { if (s_logger.isDebugEnabled()) { s_logger.debug("Getting id for account by name '" + accountName + "' in domain " + domainId); } newAccount = _accountDao.findEnabledAccount(accountName, domainId); } if (newAccount == null && accountId != null) { newAccount = _accountDao.findById(accountId); } if (newAccount == null) { throw new CloudRuntimeException("no account name or account id. this should have been caught before this point"); } checkIfNotMovingAcrossDomains(domainId, newAccount); return newAccount.getAccountId(); }
@Override public List<QuotaSummaryResponse> createQuotaSummaryResponse(Boolean listAll) { List<QuotaSummaryResponse> result = new ArrayList<QuotaSummaryResponse>(); if (listAll) { for (final AccountVO account : _accountDao.listAll()) { QuotaSummaryResponse qr = getQuotaSummaryResponse(account); result.add(qr); } } else { for (final QuotaAccountVO quotaAccount : _quotaAccountDao.listAllQuotaAccount()) { AccountVO account = _accountDao.findById(quotaAccount.getId()); if (account == null) { continue; } QuotaSummaryResponse qr = getQuotaSummaryResponse(account); result.add(qr); } } return result; }
protected boolean lockAccount(long accountId) { boolean success = false; Account account = _accountDao.findById(accountId); if (account != null) { if (account.getState().equals(State.locked)) { return true; // already locked, no-op } else if (account.getState().equals(State.enabled)) { AccountVO acctForUpdate = _accountDao.createForUpdate(); acctForUpdate.setState(State.locked); success = _accountDao.update(Long.valueOf(accountId), acctForUpdate); } else { if (s_logger.isInfoEnabled()) { s_logger.info("Attempting to lock a non-enabled account, current state is " + account.getState() + " (accountId: " + accountId + "), locking failed."); } } } else { s_logger.warn("Failed to lock account " + accountId + ", account not found."); } return success; }
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "disabling account", async = true) public AccountVO disableAccount(String accountName, Long domainId, Long accountId) throws ConcurrentOperationException, ResourceUnavailableException { Account caller = getCurrentCallingAccount(); Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new PermissionDeniedException("Account id : " + accountId + " is a system account, disable is not allowed"); } checkAccess(caller, AccessType.OperateEntry, true, account); if (disableAccount(account.getId())) { CallContext.current().putContextParameter(Account.class, account.getUuid()); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } }
Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findEnabledAccount(accountName, domainId); final AccountVO acctForUpdate = _accountDao.findById(account.getId()); Account existingAccount = _accountDao.findActiveAccount(newAccountName, domainId); if (existingAccount != null && existingAccount.getId() != account.getId()) { throw new InvalidParameterValueException("The account with the proposed name '" + boolean success1 = _accountDao.update(accountFinal.getId(), acctForUpdate); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_MARK_DEFAULT_ZONE, eventDescription = "Marking account with the " + "default zone", async = true) public AccountVO markDefaultZone(final String accountName, final long domainId, final long defaultZoneId) { // Check if the account exists final Account account = _accountDao.findEnabledAccount(accountName, domainId); if (account == null) { s_logger.error("Unable to find account by name: " + accountName + " in domain " + domainId); throw new InvalidParameterValueException("Account by name: " + accountName + " doesn't exist in domain " + domainId); } // Don't allow modification of system account if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new InvalidParameterValueException("Can not modify system account"); } final AccountVO acctForUpdate = _accountDao.findById(account.getId()); acctForUpdate.setDefaultZoneId(defaultZoneId); if (_accountDao.update(account.getId(), acctForUpdate)) { CallContext.current().setEventDetails("Default zone id= " + defaultZoneId); return _accountDao.findById(account.getId()); } else { return null; } }
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); account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccountById(accountId, domainId);
@DB private InstanceGroupVO createVmGroup(String groupName, long accountId) { Account account = null; try { account = _accountDao.acquireInLockTable(accountId); // to ensure // duplicate // vm group // names are // not // created. if (account == null) { s_logger.warn("Failed to acquire lock on account"); return null; } InstanceGroupVO group = _vmGroupDao.findByAccountAndName(accountId, groupName); if (group == null) { group = new InstanceGroupVO(groupName, accountId); group = _vmGroupDao.persist(group); } return group; } finally { if (account != null) { _accountDao.releaseFromLockTable(accountId); } } }
Filter filter = new Filter(AccountVO.class, "id", true, offset, limit); accounts = _accountDao.findActiveAccounts(lastAccountId, filter); Filter filter = new Filter(AccountVO.class, "id", true, offset, limit); accounts = _accountDao.findRecentlyDeletedAccounts(lastAccountId, startDate, filter); Filter filter = new Filter(AccountVO.class, "id", true, offset, limit); accounts = _accountDao.findNewAccounts(lastAccountId, filter); accounts = _accountDao.listAll(filter); if ((accounts != null) && !accounts.isEmpty()) { for (AccountVO account : accounts) { Filter filter = new Filter(AccountVO.class, "id", true, offset, limit); accounts = _accountDao.findRecentlyDeletedAccounts(null, recentlyDeletedDate, filter);
@Override public LinkAccountToLdapResponse linkAccountToLdap(LinkAccountToLdapCmd cmd) { Validate.notNull(_ldapConfiguration.getBaseDn(cmd.getDomainId()), "can not link an account to ldap in a domain for which no basdn is configured"); Validate.notNull(cmd.getDomainId(), "domainId cannot be null."); Validate.notEmpty(cmd.getAccountName(), "accountName cannot be empty."); Validate.notEmpty(cmd.getLdapDomain(), "ldapDomain cannot be empty, please supply a GROUP or OU name"); Validate.notNull(cmd.getType(), "type cannot be null. It should either be GROUP or OU"); Validate.notEmpty(cmd.getLdapDomain(), "GROUP or OU name cannot be empty"); LinkType linkType = LdapManager.LinkType.valueOf(cmd.getType().toUpperCase()); Account account = accountDao.findActiveAccount(cmd.getAccountName(),cmd.getDomainId()); if (account == null) { account = new AccountVO(cmd.getAccountName(), cmd.getDomainId(), null, cmd.getAccountType(), UUID.randomUUID().toString()); accountDao.persist((AccountVO)account); } Long accountId = account.getAccountId(); LdapTrustMapVO vo = _ldapTrustMapDao.persist(new LdapTrustMapVO(cmd.getDomainId(), linkType, cmd.getLdapDomain(), cmd.getAccountType(), accountId)); DomainVO domain = domainDao.findById(vo.getDomainId()); String domainUuid = "<unknown>"; if (domain == null) { s_logger.error("no domain in database for id " + vo.getDomainId()); } else { domainUuid = domain.getUuid(); } LinkAccountToLdapResponse response = new LinkAccountToLdapResponse(domainUuid, vo.getType().toString(), vo.getName(), vo.getAccountType(), account.getUuid(), cmd.getAccountName()); return response; } }
@Override public boolean calculateQuotaUsage() { List<AccountVO> accounts = _accountDao.listAll(); for (AccountVO account : accounts) { Pair<List<? extends UsageVO>, Integer> usageRecords = _usageDao.getUsageRecordsPendingQuotaAggregation(account.getAccountId(), account.getDomainId()); if (s_logger.isDebugEnabled()) { s_logger.debug("Usage entries size = " + usageRecords.second().intValue() + ", accId" + account.getAccountId() + ", domId" + account.getDomainId()); } List<QuotaUsageVO> quotaListForAccount = aggregatePendingQuotaRecordsForAccount(account, usageRecords); if (s_logger.isDebugEnabled()) { s_logger.debug("Quota entries size = " + quotaListForAccount.size() + ", accId" + account.getAccountId() + ", domId" + account.getDomainId()); } processQuotaBalanceForAccount(account, quotaListForAccount); } return true; }
@Override public AccountVO doInTransaction(TransactionStatus status) { AccountVO account = _accountDao.persist(new AccountVO(accountName, domainId, networkDomain, accountType, roleId, uuid)); if (account == null) { throw new CloudRuntimeException("Failed to create account name " + accountName + " in domain id=" + domainId); } Long accountId = account.getId(); if (details != null) { _accountDetailsDao.persist(accountId, details); } // Create resource count records for the account _resourceCountDao.createResourceCounts(accountId, ResourceLimit.ResourceOwnerType.Account); // Create default security group _networkGroupMgr.createDefaultSecurityGroup(accountId); return account; } });
@Override public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException { Account owner = _accountDao.acquireInLockTable(ownerId); if (owner == null) { // this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class // to get the table name and field name that is queried to fill this ownerid. ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account"); throw ex; } if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); } boolean displayIp = true; if (guestNtwkId != null) { Network ntwk = _networksDao.findById(guestNtwkId); displayIp = ntwk.getDisplayNetwork(); } else if (vpcId != null) { VpcVO vpc = _vpcDao.findById(vpcId); displayIp = vpc.isDisplay(); } return fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, true, null, false, vpcId, displayIp, false); } });
_accountDao.releaseFromLockTable(ownerId);
@Override @ActionEvent(eventType = EventTypes.EVENT_ACCOUNT_DISABLE, eventDescription = "locking account", async = true) public AccountVO lockAccount(String accountName, Long domainId, Long accountId) { Account caller = getCurrentCallingAccount(); Account account = null; if (accountId != null) { account = _accountDao.findById(accountId); } else { account = _accountDao.findActiveAccount(accountName, domainId); } if (account == null || account.getType() == Account.ACCOUNT_TYPE_PROJECT) { throw new InvalidParameterValueException("Unable to find active account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } if (account.getId() == Account.ACCOUNT_ID_SYSTEM) { throw new PermissionDeniedException("Account id : " + accountId + " is a system account, lock is not allowed"); } checkAccess(caller, AccessType.OperateEntry, true, account); if (lockAccount(account.getId())) { CallContext.current().putContextParameter(Account.class, account.getUuid()); return _accountDao.findById(account.getId()); } else { throw new CloudRuntimeException("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId); } }
public LoadBalancer handleCreateLoadBalancerRule(final CreateLoadBalancerRuleCmd lb, Account account, final long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException { //this part of code is executed when the LB provider is Elastic Load Balancer vm if (!_networkModel.isProviderSupportServiceInNetwork(lb.getNetworkId(), Service.Lb, Provider.ElasticLoadBalancerVm)) { return null; } final Long ipId = lb.getSourceIpAddressId(); if (ipId != null) { return null; } account = _accountDao.acquireInLockTable(account.getId()); if (account == null) { s_logger.warn("ELB: CreateLoadBalancer: Failed to acquire lock on account"); throw new CloudRuntimeException("Failed to acquire lock on account"); } try { return handleCreateLoadBalancerRuleWithLock(lb, account, networkId); } finally { if (account != null) { _accountDao.releaseFromLockTable(account.getId()); } } }
@DB public void updateResourceCount() { ResourceType[] resourceTypes = Resource.ResourceType.values(); List<AccountVO> accounts = _accountDao.listAll(); List<DomainVO> domains = _domainDao.listAll(); List<ResourceCountVO> domainResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Domain);