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

Bug #3832: Cleanup xpath calls in scheduler

This commit is contained in:
Carlos Martín 2015-07-29 18:51:33 +02:00
parent 17f38ea37e
commit 29045fd1a6
4 changed files with 42 additions and 129 deletions

View File

@ -45,7 +45,7 @@ private:
void init_attributes()
{
oid = atoi(((*this)["/CLUSTER/ID"] )[0].c_str() );
xpath(oid, "/CLUSTER/ID", -1);
};
};

View File

@ -35,20 +35,21 @@ const char * DatastoreXML::ds_paths[] = {
void DatastoreXML::init_attributes()
{
oid = atoi(((*this)["/DATASTORE/ID"] )[0].c_str() );
cluster_id = atoi(((*this)["/DATASTORE/CLUSTER_ID"] )[0].c_str() );
free_mb = atoll(((*this)["/DATASTORE/FREE_MB"])[0].c_str());
xpath(oid, "/DATASTORE/ID", -1);
xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1);
xpath(free_mb, "/DATASTORE/FREE_MB", 0);
long long total_mb = atoll(((*this)["/DATASTORE/TOTAL_MB"])[0].c_str());
long long used_mb = atoll(((*this)["/DATASTORE/USED_MB"])[0].c_str());
long long total_mb, used_mb, limit_mb;
xpath(total_mb, "/DATASTORE/TOTAL_MB", 0);
xpath(used_mb, "/DATASTORE/USED_MB", 0);
monitored = (free_mb != 0 || total_mb != 0 || used_mb != 0);
vector<string> strings = ((*this)["/DATASTORE/TEMPLATE/LIMIT_MB"]);
int rc = xpath(limit_mb, "/DATASTORE/TEMPLATE/LIMIT_MB", 0);
if (!strings.empty())
if (rc == 0)
{
long long limit_mb = atoll(strings[0].c_str());
long long free_limited = limit_mb - used_mb;
if (free_limited < 0)

View File

@ -36,31 +36,19 @@ const char *HostXML::host_paths[] = {
void HostXML::init_attributes()
{
oid = atoi(((*this)["/HOST/ID"] )[0].c_str() );
cluster_id = atoi(((*this)["/HOST/CLUSTER_ID"] )[0].c_str() );
xpath(oid, "/HOST/ID", -1);
xpath(cluster_id, "/HOST/CLUSTER_ID", -1);
xpath(mem_usage, "/HOST/HOST_SHARE/MEM_USAGE", 0);
xpath(cpu_usage, "/HOST/HOST_SHARE/CPU_USAGE", 0);
xpath(max_mem, "/HOST/HOST_SHARE/MAX_MEM", 0);
xpath(max_cpu, "/HOST/HOST_SHARE/MAX_CPU", 0);
xpath(free_disk, "/HOST/HOST_SHARE/FREE_DISK", 0);
xpath(running_vms, "/HOST/HOST_SHARE/RUNNING_VMS", 0);
mem_usage = atoll(((*this)["/HOST/HOST_SHARE/MEM_USAGE"])[0].c_str());
cpu_usage = atoll(((*this)["/HOST/HOST_SHARE/CPU_USAGE"])[0].c_str());
string public_cloud_st;
max_mem = atoll(((*this)["/HOST/HOST_SHARE/MAX_MEM"])[0].c_str());
max_cpu = atoll(((*this)["/HOST/HOST_SHARE/MAX_CPU"])[0].c_str());
free_disk = atoll(((*this)["/HOST/HOST_SHARE/FREE_DISK"])[0].c_str());
running_vms = atoll(((*this)["/HOST/HOST_SHARE/RUNNING_VMS"])[0].c_str());
public_cloud = false;
vector<string> public_cloud_vector = (*this)["/HOST/TEMPLATE/PUBLIC_CLOUD"];
if (public_cloud_vector.size() > 0)
{
string pc = public_cloud_vector[0];
one_util::toupper(pc);
public_cloud = pc == "YES";
}
xpath(public_cloud_st, "/HOST/TEMPLATE/PUBLIC_CLOUD", "");
public_cloud = (one_util::toupper(public_cloud_st) == "YES");
vector<string> ds_ids = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/ID"];
vector<string> ds_free_mb = (*this)["/HOST/HOST_SHARE/DATASTORES/DS/FREE_MB"];

View File

@ -24,92 +24,48 @@
void VirtualMachineXML::init_attributes()
{
vector<string> result;
vector<xmlNodePtr> nodes;
int rc;
int action;
string automatic_requirements;
oid = atoi(((*this)["/VM/ID"] )[0].c_str());
uid = atoi(((*this)["/VM/UID"])[0].c_str());
gid = atoi(((*this)["/VM/GID"])[0].c_str());
xpath(oid, "/VM/ID", -1);
xpath(uid, "/VM/UID", -1);
xpath(gid, "/VM/GID", -1);
result = ((*this)["/VM/TEMPLATE/MEMORY"]);
if (result.size() > 0)
{
memory = atoi(result[0].c_str());
}
else
{
memory = 0;
}
result = ((*this)["/VM/TEMPLATE/CPU"]);
if (result.size() > 0)
{
istringstream iss;
iss.str( result[0] );
iss >> cpu;
}
else
{
cpu = 0;
}
xpath(memory, "/VM/TEMPLATE/MEMORY", 0);
xpath(cpu, "/VM/TEMPLATE/CPU", 0);
// ------------------------ RANK & DS_RANK ---------------------------------
result = ((*this)["/VM/USER_TEMPLATE/SCHED_RANK"]);
rc = xpath(rank, "/VM/USER_TEMPLATE/SCHED_RANK", "");
if (result.size() > 0)
{
rank = result[0];
}
else
if (rc != 0)
{
// Compatibility with previous versions
result = ((*this)["/VM/USER_TEMPLATE/RANK"]);
if (result.size() > 0)
{
rank = result[0];
}
xpath(rank, "/VM/USER_TEMPLATE/RANK", "");
}
result = ((*this)["/VM/USER_TEMPLATE/SCHED_DS_RANK"]);
if (result.size() > 0)
{
ds_rank = result[0];
}
xpath(ds_rank, "/VM/USER_TEMPLATE/SCHED_DS_RANK", "");
// ------------------- HOST REQUIREMENTS -----------------------------------
result = ((*this)["/VM/TEMPLATE/AUTOMATIC_REQUIREMENTS"]);
xpath(automatic_requirements, "/VM/TEMPLATE/AUTOMATIC_REQUIREMENTS", "");
if (result.size() > 0)
{
automatic_requirements = result[0];
}
rc = xpath(requirements, "/VM/USER_TEMPLATE/SCHED_REQUIREMENTS", "");
result = ((*this)["/VM/USER_TEMPLATE/SCHED_REQUIREMENTS"]);
if (result.size() > 0)
if (rc == 0)
{
if ( !automatic_requirements.empty() )
{
ostringstream oss;
oss << automatic_requirements << " & ( " << result[0] << " )";
oss << automatic_requirements << " & ( " << requirements << " )";
requirements = oss.str();
}
else
{
requirements = result[0];
}
}
else if ( !automatic_requirements.empty() )
{
@ -118,22 +74,18 @@ void VirtualMachineXML::init_attributes()
// ------------------- DS REQUIREMENTS -------------------------------------
result = ((*this)["/VM/USER_TEMPLATE/SCHED_DS_REQUIREMENTS"]);
rc = xpath(ds_requirements, "/VM/USER_TEMPLATE/SCHED_DS_REQUIREMENTS", "");
if (result.size() > 0)
if (rc == 0)
{
if ( !automatic_requirements.empty() )
{
ostringstream oss;
oss << automatic_requirements << " & ( " << result[0] << " )";
oss << automatic_requirements << " & ( " << ds_requirements << " )";
ds_requirements = oss.str();
}
else
{
ds_requirements = result[0];
}
}
else if ( !automatic_requirements.empty() )
{
@ -142,40 +94,12 @@ void VirtualMachineXML::init_attributes()
// ---------------- HISTORY HID, DSID, RESCHED & TEMPLATE ------------------
result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/HID"]);
xpath(hid, "/VM/HISTORY_RECORDS/HISTORY/HID", -1);
xpath(dsid, "/VM/HISTORY_RECORDS/HISTORY/DS_ID", -1);
if (result.size() > 0)
{
hid = atoi(result[0].c_str());
}
else
{
hid = -1;
}
xpath(resched, "/VM/RESCHED", 0);
result = ((*this)["/VM/HISTORY_RECORDS/HISTORY/DS_ID"]);
if (result.size() > 0)
{
dsid = atoi(result[0].c_str());
}
else
{
dsid = -1;
}
result = ((*this)["/VM/RESCHED"]);
if (result.size() > 0)
{
resched = atoi(result[0].c_str());
}
else
{
resched = 0;
}
this->xpath(action, "/VM/HISTORY_RECORDS/HISTORY/ACTION", -1);
xpath(action, "/VM/HISTORY_RECORDS/HISTORY/ACTION", -1);
resume = (action == History::STOP_ACTION ||
action == History::UNDEPLOY_ACTION ||