ofri masad has posted comments on this change.

Change subject: core: Quota refactor - QuotaManager
......................................................................


Patch Set 20: (8 inline comments)

....................................................
File 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/quota/QuotaManager.java
Line 27: public class QuotaManager {
Line 28:     private final static QuotaManager INSTANCE = new QuotaManager();
Line 29:     private final static ReentrantReadWriteLock lock = new 
ReentrantReadWriteLock();
Line 30:     private final static Log log = 
LogFactory.getLog(QuotaManager.class);
Line 31:     private static final HashMap<Guid, Map<Guid, Quota>> 
storagePoolQuotaMap = new HashMap<Guid, Map<Guid, Quota>>();
Done
Line 32:     private static final HashMap<Guid, Quota> directQuotaMap = new 
HashMap<Guid, Quota>();
Line 33: 
Line 34:     // The logger is not final in order to allow mocking
Line 35:     private static QuotaManagerAuditLogger quotaManagerAuditLogger = 
new QuotaManagerAuditLogger();


Line 31:     private static final HashMap<Guid, Map<Guid, Quota>> 
storagePoolQuotaMap = new HashMap<Guid, Map<Guid, Quota>>();
Line 32:     private static final HashMap<Guid, Quota> directQuotaMap = new 
HashMap<Guid, Quota>();
Line 33: 
Line 34:     // The logger is not final in order to allow mocking
Line 35:     private static QuotaManagerAuditLogger quotaManagerAuditLogger = 
new QuotaManagerAuditLogger();
Done
Line 36: 
Line 37:     public static QuotaManager getInstance() {
Line 38:         return INSTANCE;
Line 39:     }


Line 665:             }
Line 666:         }
Line 667: 
Line 668:     }
Line 669: 
Done
Line 670:     public boolean 
validateAndSetClusterQuota(QuotaConsumptionParametersWrapper parameters) {
Line 671: 
Line 672:         Pair<AuditLogType, AuditLogableBase> auditLogPair = new 
Pair<AuditLogType, AuditLogableBase>();
Line 673:         auditLogPair.setSecond(parameters.getAuditLogable());


Line 674:         lock.readLock().lock();
Line 675:         try {
Line 676:             if 
(storagePoolQuotaMap.get(parameters.getStoragePoolId()) == null) {
Line 677:                 return false;
Line 678:             }
Done.
Line 679:             synchronized 
(storagePoolQuotaMap.get(parameters.getStoragePoolId())) {
Line 680:                 for (QuotaConsumptionParameter parameter : 
parameters.getParameters()) {
Line 681:                     QuotaVdsGroupConsumptionParameter 
vdsGroupConsumptionParameter;
Line 682:                     if (parameter.getParameterType() != 
QuotaConsumptionParameter.ParameterType.VDS_GROUP) {


Line 701:                         parameters.getCanDoActionMessages()
Line 702:                                 
.add(VdcBllMessages.ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID.toString());
Line 703:                         return false;
Line 704:                     }
Line 705: 
Done
Line 706:                     boolean success =
Line 707:                             
checkQuotaClusterLimits(parameters.getAuditLogable()
Line 708:                                     .getStoragePool()
Line 709:                                     .getQuotaEnforcementType(),


Line 975: 
Line 976:         boolean hardEnforcement =
Line 977:                 QuotaEnforcementTypeEnum.HARD_ENFORCEMENT == 
parameters.getAuditLogable().getStoragePool().getQuotaEnforcementType();
Line 978: 
Line 979:         // for each parameter - check and complete
Done
Line 980:         for (QuotaConsumptionParameter param : 
parameters.getParameters()) {
Line 981:             // check that quota id is valid and fetch the quota from 
db (or cache). add the quota to the param
Line 982:             boolean validQuotaId = checkAndFetchQuota(parameters, 
param);
Line 983: 


Line 1102:      * Get Quota by Id. If in cache - get from cache. else get from 
DAO and add to cache.
Line 1103:      * Notice!!! This method apply read/write locks.
Line 1104:      * @param quotaId - quota id
Line 1105:      * @return - found quota. null if not found.
Line 1106:      */
Done
Line 1107:     private Quota fetchQuotaFromCache(Guid quotaId) {
Line 1108:         Quota quota = null;
Line 1109:         lock.readLock().lock();
Line 1110:         try {


Line 1119:         if (quota == null) {
Line 1120:             try {
Line 1121:                 lock.writeLock().lock();
Line 1122:                 // cache in direct quota map
Line 1123:                 quota = getQuotaDAO().getById(quotaId);
Done
Line 1124:                 if (quota != null) {
Line 1125:                     directQuotaMap.put(quotaId, quota);
Line 1126:                     // cache in storage-pool->quota map
Line 1127:                     if 
(!storagePoolQuotaMap.containsKey(quota.getStoragePoolId())) {


--
To view, visit http://gerrit.ovirt.org/8776
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: Ibb100467a55b26e4219d1a2562da86b81ffdc032
Gerrit-PatchSet: 20
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: ofri masad <oma...@redhat.com>
Gerrit-Reviewer: Allon Mureinik <amure...@redhat.com>
Gerrit-Reviewer: Doron Fediuck <dfedi...@redhat.com>
Gerrit-Reviewer: Gilad Chaplik <gchap...@redhat.com>
Gerrit-Reviewer: Laszlo Hornyak <lhorn...@redhat.com>
Gerrit-Reviewer: Michael Kublin <mkub...@redhat.com>
Gerrit-Reviewer: Sharad Mishra <snmis...@linux.vnet.ibm.com>
Gerrit-Reviewer: Yair Zaslavsky <yzasl...@redhat.com>
Gerrit-Reviewer: ofri masad <oma...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to