@Override public void run(Map tokens, Object data) { // as a foreign key would clean SessionVO after account deleted, just clean memory sessions here removeMemorySessionsAccordingToDB(tokens, data); removeMemorySessionsAccordingToAccountUuid(tokens, data); }
private void checkTotalVMQuota(String currentAccountUuid, String resourceTargetOwnerAccountUuid, String vmInstanceUuid, long totalVmNumQuota, long totalVmNum) { if (Q.New(VmInstanceVO.class) .eq(VmInstanceVO_.uuid, vmInstanceUuid) .notNull(VmInstanceVO_.lastHostUuid) .isExists()) { // Dirty hack - VM with last host UUID means existing VM. return; } QuotaUtil.QuotaCompareInfo quotaCompareInfo; quotaCompareInfo = new QuotaUtil.QuotaCompareInfo(); quotaCompareInfo.currentAccountUuid = currentAccountUuid; quotaCompareInfo.resourceTargetOwnerAccountUuid = resourceTargetOwnerAccountUuid; quotaCompareInfo.quotaName = VmQuotaConstant.VM_TOTAL_NUM; quotaCompareInfo.quotaValue = totalVmNumQuota; quotaCompareInfo.currentUsed = totalVmNum; quotaCompareInfo.request = 1; new QuotaUtil().CheckQuota(quotaCompareInfo); }
private void checkStartVmInstance(String currentAccountUuid, String vmInstanceUuid, Map<String, Quota.QuotaPair> pairs) { String resourceTargetOwnerAccountUuid = new QuotaUtil().getResourceOwnerAccountUuid(vmInstanceUuid); checkVmInstanceQuota(currentAccountUuid, resourceTargetOwnerAccountUuid, vmInstanceUuid, pairs); }
protected static String getAccountUuidOfResource(String resourceUuid) { if (acntMgr == null) { acntMgr = Platform.getComponentLoader().getComponent(AccountManager.class); } return acntMgr.getOwnerAccountUuidOfResource(resourceUuid); }
@Override @MessageSafe public void handleMessage(Message msg) { if (msg instanceof AccountMessage) { passThrough((AccountMessage) msg); } else if (msg instanceof APIMessage) { handleApiMessage((APIMessage) msg); } else { handleLocalMessage(msg); } }
@Override protected SessionInventory scripts() { Timestamp expiredDate = new Timestamp(TimeUnit.SECONDS.toMillis(finalExtendPeriod) + getCurrentSqlDate().getTime()); SessionInventory s = getSession(uuid); s.setExpiredDate(expiredDate); sql(SessionVO.class).eq(SessionVO_.uuid, uuid).set(SessionVO_.expiredDate, expiredDate).update(); return s; } }.execute();
public boolean isAdminAccount(String accountUuid) { return getAccountType(accountUuid) == AccountType.SystemAdmin; }
@Override public void run() { List<String> uuids = deleteExpiredSessions(); for (String uuid : uuids) { sessions.remove(uuid); } deleteExpiredCachedSessions(); }
@Override @MessageSafe public void handleMessage(Message msg) { if (msg instanceof APIMessage) { handleApiMessage((APIMessage) msg); } else { handleLocalMessage(msg); } }
@Override public void prepareDbInitialValue() { try { makeReadAPIsForNormalAccountJSONStatement(); new SQLBatch() { @Override protected void scripts() { if (!q(AccountVO.class) .eq(AccountVO_.name, AccountConstant.INITIAL_SYSTEM_ADMIN_NAME) .eq(AccountVO_.type, AccountType.SystemAdmin).isExists()) { AccountVO vo = new AccountVO(); vo.setUuid(AccountConstant.INITIAL_SYSTEM_ADMIN_UUID); vo.setName(AccountConstant.INITIAL_SYSTEM_ADMIN_NAME); vo.setPassword(AccountConstant.INITIAL_SYSTEM_ADMIN_PASSWORD); vo.setType(AccountType.SystemAdmin); persist(vo); flush(); logger.debug(String.format("Created initial system admin account[name:%s]", AccountConstant.INITIAL_SYSTEM_ADMIN_NAME)); } sql(PolicyVO.class).eq(PolicyVO_.name, "DEFAULT-READ").set(PolicyVO_.data, readAPIsForNormalAccountJSONStatement).update(); } }.execute(); } catch (Exception e) { throw new CloudRuntimeException("Unable to create default system admin account", e); } }
public static AccountBuilder New() { return new AccountBuilder(); }
private void validate(APIChangeResourceOwnerMsg msg) { checkQuotaForChangeResourceOwner(msg); }
public static void logout(String uuid) { new SQLBatch() { @Override protected void scripts() { SessionInventory s = sessions.remove(uuid); if (s == null) { SessionVO vo = findByUuid(uuid, SessionVO.class); s = vo == null ? null : SessionInventory.valueOf(vo); } if (s == null) { return; } SessionInventory finalS = s; Platform.getComponentLoader().getComponent(PluginRegistry.class) .getExtensionList(SessionLogoutExtensionPoint.class) .forEach(ext -> ext.sessionLogout(finalS)); sql(SessionVO.class).eq(SessionVO_.uuid, uuid).hardDelete(); } }.execute(); }
@Override public void postHardDelete(Collection entityIds, Class entityClass) { if (resourceTypes.contains(entityClass)) { postSoftDelete(entityIds, entityClass); } }
private void handle(DeleteAccountMsg msg) { DeleteAccountReply reply = new DeleteAccountReply(); deleteAccount(new Completion(msg) { @Override public void success() { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); bus.reply(msg, reply); } }); }