@Override public void beforeDeliveryMessage(Message msg) { if (msg instanceof NeedQuotaCheckMessage) { if (((NeedQuotaCheckMessage) msg).getAccountUuid() == null || ((NeedQuotaCheckMessage) msg).getAccountUuid().equals("")) { // skip admin scheduler return; } List<Quota> quotas = acntMgr.getMessageQuotaMap().get(msg.getClass()); if (quotas == null || quotas.size() == 0) { return; } Map<String, Quota.QuotaPair> pairs = new QuotaUtil(). makeQuotaPairs(((NeedQuotaCheckMessage) msg).getAccountUuid()); for (Quota quota : quotas) { quota.getOperator().checkQuota((NeedQuotaCheckMessage) msg, pairs); } } } }, VolumeCreateSnapshotMsg.class, CreateVolumeSnapshotMsg.class);
@Override public void check(RBACEntity entity) { if (acntMgr.isAdmin(entity.getApiMessage().getSession())) { return; } List<Quota> quotas = acntMgr.getMessageQuotaMap().get(entity.getApiMessage().getClass()); if (quotas == null || quotas.isEmpty()) { return; } quotas.forEach(quota -> { Map<String, Quota.QuotaPair> pairs = new QuotaUtil().makeQuotaPairs(entity.getApiMessage().getSession().getAccountUuid()); quota.getOperator().checkQuota(entity.getApiMessage(), pairs); if (quota.getQuotaValidators() != null) { for (Quota.QuotaValidator q : quota.getQuotaValidators()) { q.checkQuota(entity.getApiMessage(), pairs); } } }); } }
private void check(APIMessage msg, Quota quota) { Map<String, QuotaPair> pairs = new QuotaUtil().makeQuotaPairs(msg.getSession().getAccountUuid()); quota.getOperator().checkQuota(msg, pairs); if (quota.getQuotaValidators() != null) { for (Quota.QuotaValidator q : quota.getQuotaValidators()) { q.checkQuota(msg, pairs); } } } }
@Override public void allocate() { throwExceptionIfIAmTheFirstFlow(); final String vmInstanceUuid = spec.getVmInstance().getUuid(); final String accountUuid = Account.getAccountUuidOfResource(vmInstanceUuid); if (accountUuid == null || AccountConstant.isAdminPermission(accountUuid)) { next(candidates); return; } if (!spec.isFullAllocate()) { new VmQuotaOperator().checkVmCupAndMemoryCapacity(accountUuid, accountUuid, spec.getCpuCapacity(), spec.getMemoryCapacity(), new QuotaUtil().makeQuotaPairs(accountUuid)); next(candidates); return; } new VmQuotaOperator().checkVmInstanceQuota( accountUuid, accountUuid, vmInstanceUuid, new QuotaUtil().makeQuotaPairs(accountUuid)); next(candidates); } }
private void checkQuotaForChangeResourceOwner(APIChangeResourceOwnerMsg msg) { String currentAccountUuid = msg.getSession().getAccountUuid(); String resourceTargetOwnerAccountUuid = msg.getAccountUuid(); if (new QuotaUtil().isAdminAccount(resourceTargetOwnerAccountUuid)) { return; } // check if change resource owner to self SimpleQuery<AccountResourceRefVO> queryAccResRefVO = dbf.createQuery(AccountResourceRefVO.class); queryAccResRefVO.add(AccountResourceRefVO_.resourceUuid, Op.EQ, msg.getResourceUuid()); AccountResourceRefVO accResRefVO = queryAccResRefVO.find(); String resourceOriginalOwnerAccountUuid = accResRefVO.getOwnerAccountUuid(); if (resourceTargetOwnerAccountUuid.equals(resourceOriginalOwnerAccountUuid)) { throw new ApiMessageInterceptionException(err(IdentityErrors.QUOTA_INVALID_OP, "Invalid ChangeResourceOwner operation." + "Original owner is the same as target owner." + "Current account is [uuid: %s]." + "The resource target owner account[uuid: %s]." + "The resource original owner account[uuid:%s].", currentAccountUuid, resourceTargetOwnerAccountUuid, resourceOriginalOwnerAccountUuid )); } // check quota Map<String, QuotaPair> pairs = new QuotaUtil().makeQuotaPairs(msg.getAccountUuid()); for (Quota quota : messageQuotaMap.get(APIChangeResourceOwnerMsg.class)) { quota.getOperator().checkQuota(msg, pairs); } }