public static void updateCsDbWithSolidFireAccountInfo(long csAccountId, SolidFireUtil.SolidFireAccount sfAccount, long storagePoolId, AccountDetailsDao accountDetailsDao) { AccountDetailVO accountDetail = new AccountDetailVO(csAccountId, SolidFireUtil.getAccountKey(storagePoolId), String.valueOf(sfAccount.getId())); accountDetailsDao.persist(accountDetail); }
@Override public Map<String, String> findDetails(long accountId) { QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class); sc.and(sc.entity().getAccountId(), Op.EQ, accountId); List<AccountDetailVO> results = sc.list(); Map<String, String> details = new HashMap<String, String>(results.size()); for (AccountDetailVO r : results) { details.put(r.getName(), r.getValue()); } return details; }
@Override public AccountDetailVO findDetail(long accountId, String name) { QueryBuilder<AccountDetailVO> sc = QueryBuilder.create(AccountDetailVO.class); sc.and(sc.entity().getAccountId(), Op.EQ, accountId); sc.and(sc.entity().getName(), Op.EQ, name); return sc.find(); }
accountDetailVO = new AccountDetailVO(resourceId, name, value); _accountDetailsDao.persist(accountDetailVO); } else { accountDetailVO.setValue(value); _accountDetailsDao.update(accountDetailVO.getId(), accountDetailVO);
@Override public String getConfigValue(long id, ConfigKey<?> key) { AccountDetailVO vo = findDetail(id, key.key()); return vo == null ? null : vo.getValue(); } }
@Override public void deleteDetails(long accountId) { SearchCriteria<AccountDetailVO> sc = accountSearch.create(); sc.setParameters("accountId", accountId); List<AccountDetailVO> results = search(sc, null); for (AccountDetailVO result : results) { remove(result.getId()); } }
protected AccountDetailsDaoImpl() { accountSearch = createSearchBuilder(); accountSearch.and("accountId", accountSearch.entity().getAccountId(), Op.EQ); accountSearch.done(); }
public static AccountDetailVO getAccountDetail(long csAccountId, long storagePoolId, AccountDetailsDao accountDetailsDao) { AccountDetailVO accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId)); if (accountDetail == null || accountDetail.getValue() == null) { accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.ACCOUNT_ID); } return accountDetail; }
@Override public long getSolidFireAccountId(String csAccountUuid, String storagePoolUuid) { long csAccountId = util.getAccountIdForAccountUuid(csAccountUuid); long storagePoolId = util.getStoragePoolIdForStoragePoolUuid(storagePoolUuid); AccountDetailVO accountDetail = accountDetailsDao.findDetail(csAccountId, SolidFireUtil.getAccountKey(storagePoolId)); if (accountDetail == null) { throw new CloudRuntimeException("Unable to find SF account for storage " + storagePoolUuid + " for CS account " + csAccountUuid); } String sfAccountId = accountDetail.getValue(); return Long.parseLong(sfAccountId); }
@Override public void persist(long accountId, Map<String, String> details) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); SearchCriteria<AccountDetailVO> sc = accountSearch.create(); sc.setParameters("accountId", accountId); expunge(sc); for (Map.Entry<String, String> detail : details.entrySet()) { AccountDetailVO vo = new AccountDetailVO(accountId, detail.getKey(), detail.getValue()); persist(vo); } txn.commit(); }
private long getCreateSolidFireAccountId(SolidFireUtil.SolidFireConnection sfConnection, long csAccountId, long storagePoolId) { AccountDetailVO accountDetail = SolidFireUtil.getAccountDetail(csAccountId, storagePoolId, accountDetailsDao); if (accountDetail == null || accountDetail.getValue() == null) { AccountVO account = accountDao.findById(csAccountId); String sfAccountName = SolidFireUtil.getSolidFireAccountName(account.getUuid(), account.getAccountId()); SolidFireUtil.SolidFireAccount sfAccount = SolidFireUtil.getAccount(sfConnection, sfAccountName); if (sfAccount == null) { sfAccount = createSolidFireAccount(sfConnection, sfAccountName); } SolidFireUtil.updateCsDbWithSolidFireAccountInfo(account.getId(), sfAccount, storagePoolId, accountDetailsDao); accountDetail = SolidFireUtil.getAccountDetail(csAccountId, storagePoolId, accountDetailsDao); } return Long.parseLong(accountDetail.getValue()); }