1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

Feature #1288: Clean quotas that reach 0 usage and limit

This commit is contained in:
Carlos Martín 2012-06-19 17:41:42 +02:00
parent 8f809df025
commit e2f59f0cbb
3 changed files with 84 additions and 7 deletions

View File

@ -124,9 +124,40 @@ protected:
/** /**
* Gets a quota identified by its ID. * Gets a quota identified by its ID.
* @param id of the quota * @param id of the quota
* @return a pointer to the quota or 0 if not found * @param va The quota, if it is found
* @return 0 on success, -1 if not found
*/ */
virtual int get_quota(const string& id, VectorAttribute **va); virtual int get_quota(const string& id, VectorAttribute **va)
{
map<string, Attribute *>::iterator it;
return get_quota(id, va, it);
}
/**
* Gets a quota identified by its ID.
*
* @param id of the quota
* @param va The quota, if it is found
* @param it The quota iterator, if it is found
*
* @return 0 on success, -1 if not found
*/
virtual int get_quota(
const string& id,
VectorAttribute **va,
map<string, Attribute *>::iterator& it);
/**
* Deletes a quota from the index. The quota pointer is freed.
* @param it The quota iterator, as returned by Quota::get_quota
*/
virtual void del(map<string, Attribute *>::iterator& it)
{
Attribute * attr = it->second;
delete attr;
attributes.erase(it);
}
private: private:
/** /**

View File

@ -62,15 +62,41 @@ public:
/** /**
* Gets a quota, overrides base to not to use ID. * Gets a quota, overrides base to not to use ID.
* @param id of the quota * @param id of the quota, ignored
* @param va The quota
*
* @return a pointer to the quota or 0 if not found * @return a pointer to the quota or 0 if not found
*/ */
int get_quota(const string& id, VectorAttribute **va); int get_quota(const string& id, VectorAttribute **va);
/**
* Gets a quota, overrides base to not to use ID.
*
* @param id of the quota, ignored
* @param va The quota
* @param it The quota iterator, if it is found
*
* @return 0 on success, -1 if not found
*/
int get_quota(
const string& id,
VectorAttribute **va,
map<string, Attribute *>::iterator& it)
{
it = attributes.end();
return get_quota(id, va);
}
/**
* Overrides base to not delete anything
* @param it The quota iterator, ignored
*/
void del(map<string, Attribute *>::iterator& it){}
protected: protected:
static const char * VM_METRICS[]; static const char * VM_METRICS[];
static const int NUM_VM_METRICS; static const int NUM_VM_METRICS;
}; };
#endif /*QUOTA_VIRTUALMACHINE_H_*/ #endif /*QUOTA_VIRTUALMACHINE_H_*/

View File

@ -19,9 +19,11 @@
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int Quota::get_quota(const string& id, VectorAttribute ** va) int Quota::get_quota(
const string& id,
VectorAttribute ** va,
map<string, Attribute *>::iterator& it)
{ {
map<string, Attribute *>::iterator it;
VectorAttribute * q; VectorAttribute * q;
istringstream iss(id); istringstream iss(id);
@ -269,8 +271,12 @@ void Quota::del_quota(const string& qid, map<string, int>& usage_req)
{ {
VectorAttribute * q; VectorAttribute * q;
map<string, int>::iterator it; map<string, int>::iterator it;
map<string, Attribute *>::iterator q_it;
if ( get_quota(qid, &q) == -1) int limit, limit_tmp;
int usage, usage_tmp;
if ( get_quota(qid, &q, q_it) == -1)
{ {
return; return;
} }
@ -280,6 +286,9 @@ void Quota::del_quota(const string& qid, map<string, int>& usage_req)
return; return;
} }
limit = 0;
usage = 0;
for (int i=0; i < num_metrics; i++) for (int i=0; i < num_metrics; i++)
{ {
string metrics_used = metrics[i]; string metrics_used = metrics[i];
@ -294,6 +303,17 @@ void Quota::del_quota(const string& qid, map<string, int>& usage_req)
} }
add_to_quota(q, metrics_used, -it->second); add_to_quota(q, metrics_used, -it->second);
q->vector_value(metrics[i], limit_tmp);
q->vector_value(metrics_used.c_str(), usage_tmp);
limit += limit_tmp;
usage += usage_tmp;
}
if ( limit == 0 && usage == 0 )
{
del(q_it);
} }
} }