mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
feature #1678: Moved update info of datastore, and minor work on monitor callback function
This commit is contained in:
parent
36ef1f0177
commit
2660b2ff5b
@ -170,17 +170,6 @@ public:
|
||||
used_mb = used;
|
||||
}
|
||||
|
||||
void process_poll(Template &monitor_data)
|
||||
{
|
||||
string err;
|
||||
|
||||
obj_template->merge(&monitor_data, err);
|
||||
|
||||
erase_template_attribute("TOTAL_MB", total_mb);
|
||||
erase_template_attribute("FREE_MB", free_mb);
|
||||
erase_template_attribute("USED_MB", used_mb);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the available capacity in the datastore.
|
||||
* @params avail the total available size in the datastore (MB)
|
||||
|
@ -165,22 +165,23 @@ public:
|
||||
* @param found VMs running in the host (as expected) and info.
|
||||
* @return 0 on success
|
||||
**/
|
||||
int update_info(string &parse_str,
|
||||
int update_info(Template &tmpl,
|
||||
bool &with_vm_info,
|
||||
set<int> &lost,
|
||||
map<int,string> &found,
|
||||
const set<int> &non_shared_ds);
|
||||
|
||||
/**
|
||||
* Extracts the DS attributes from the given template
|
||||
* @param parse_str string with values to be parsed
|
||||
* @param ds map of DS monitoring information
|
||||
* @param template object parsed from parse_str
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int extract_ds_info(
|
||||
int extract_ds_info(
|
||||
string &parse_str,
|
||||
map<int,string> &ds);
|
||||
Template &tmpl,
|
||||
map<int, const VectorAttribute*> &ds);
|
||||
|
||||
/**
|
||||
* Update host after a failed monitor. It state
|
||||
|
@ -61,22 +61,6 @@ public:
|
||||
*/
|
||||
void recover();
|
||||
|
||||
/**
|
||||
* Updates the DS with the information gathered by the drivers
|
||||
*
|
||||
* @param id DS id
|
||||
* @param monitor_str String returned by the poll driver call
|
||||
*/
|
||||
static void process_poll(int id, const string &monitor_str);
|
||||
|
||||
/**
|
||||
* Updates the DS with the information gathered by the drivers
|
||||
*
|
||||
* @param ds DS to update, must be locked
|
||||
* @param monitor_str String returned by the poll driver call
|
||||
*/
|
||||
static void process_poll(Datastore* ds, const string &monitor_str);
|
||||
|
||||
private:
|
||||
friend class ImageManager;
|
||||
|
||||
|
@ -409,16 +409,17 @@ public:
|
||||
* Gets a TM configuration attribute
|
||||
*/
|
||||
int get_tm_conf_attribute(
|
||||
const string& tm_name,
|
||||
VectorAttribute* &value) const
|
||||
const string& tm_name,
|
||||
const VectorAttribute* &value) const
|
||||
{
|
||||
vector<Attribute*>::iterator it;
|
||||
vector<Attribute*> values;
|
||||
vector<const Attribute*>::const_iterator it;
|
||||
vector<const Attribute*> values;
|
||||
|
||||
nebula_configuration->Template::get("TM_MAD_CONF", values);
|
||||
|
||||
for (it = values.begin(); it != values.end(); it ++)
|
||||
{
|
||||
value = dynamic_cast<VectorAttribute*>(*it);
|
||||
value = dynamic_cast<const VectorAttribute*>(*it);
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include "NebulaLog.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper)
|
||||
|
||||
const char * Datastore::table = "datastore_pool";
|
||||
|
||||
const char * Datastore::db_names =
|
||||
@ -80,9 +78,9 @@ int Datastore::disk_attribute(VectorAttribute * disk)
|
||||
|
||||
oss << oid;
|
||||
|
||||
disk->replace("DATASTORE", get_name());
|
||||
disk->replace("DATASTORE_ID", oss.str());
|
||||
disk->replace("TM_MAD", get_tm_mad());
|
||||
disk->replace("DATASTORE", get_name());
|
||||
disk->replace("DATASTORE_ID", oss.str());
|
||||
disk->replace("TM_MAD", get_tm_mad());
|
||||
|
||||
if ( get_cluster_id() != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
@ -106,8 +104,6 @@ int Datastore::disk_attribute(VectorAttribute * disk)
|
||||
disk->replace("LN_TARGET", st);
|
||||
}
|
||||
|
||||
// TODO: if _TARGET is empty, set defaults?
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -124,7 +120,7 @@ Datastore::DatastoreType Datastore::str_to_type(string& str_type)
|
||||
return dst;
|
||||
}
|
||||
|
||||
TO_UPPER(str_type);
|
||||
one_util::toupper(str_type);
|
||||
|
||||
if ( str_type == "IMAGE_DS" )
|
||||
{
|
||||
@ -147,8 +143,9 @@ Datastore::DatastoreType Datastore::str_to_type(string& str_type)
|
||||
|
||||
int Datastore::set_tm_mad(string &tm_mad, string &error_str)
|
||||
{
|
||||
VectorAttribute* vatt;
|
||||
int rc;
|
||||
const VectorAttribute* vatt;
|
||||
|
||||
int rc;
|
||||
string st;
|
||||
|
||||
rc = Nebula::instance().get_tm_conf_attribute(tm_mad, vatt);
|
||||
@ -156,24 +153,55 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str)
|
||||
if (rc != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "TM_MAD named \"" << tm_mad << "\" is not defined in oned.conf";
|
||||
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: detect missing tm_mad conf? if (st.empty()){}
|
||||
if (type == SYSTEM_DS)
|
||||
{
|
||||
st = vatt->vector_value("SHARED");
|
||||
|
||||
if (st.empty())
|
||||
{
|
||||
st = "YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
one_util::toupper(st);
|
||||
}
|
||||
|
||||
replace_template_attribute("SHARED", st);
|
||||
}
|
||||
else
|
||||
{
|
||||
st = vatt->vector_value("LN_TARGET");
|
||||
|
||||
if (st.empty())
|
||||
{
|
||||
st = "NONE";
|
||||
}
|
||||
else
|
||||
{
|
||||
one_util::toupper(st);
|
||||
}
|
||||
|
||||
replace_template_attribute("LN_TARGET", st);
|
||||
|
||||
st = vatt->vector_value("CLONE_TARGET");
|
||||
|
||||
if (st.empty())
|
||||
{
|
||||
st = "SYSTEM";
|
||||
}
|
||||
else
|
||||
{
|
||||
one_util::toupper(st);
|
||||
}
|
||||
|
||||
replace_template_attribute("CLONE_TARGET", st);
|
||||
}
|
||||
|
||||
|
167
src/host/Host.cc
167
src/host/Host.cc
@ -179,84 +179,20 @@ error_common:
|
||||
|
||||
int Host::extract_ds_info(
|
||||
string &parse_str,
|
||||
map<int,string> &ds)
|
||||
Template &tmpl,
|
||||
map<int, const VectorAttribute*> &ds)
|
||||
{
|
||||
char * error_msg;
|
||||
Template tmpl;
|
||||
int rc;
|
||||
|
||||
VectorAttribute* vatt;
|
||||
vector<Attribute*> ds_att;
|
||||
vector<Attribute*>::iterator it;
|
||||
const VectorAttribute * vatt;
|
||||
vector<const Attribute*> ds_att;
|
||||
|
||||
rc = tmpl.parse(parse_str, &error_msg);
|
||||
vector<const Attribute*>::const_iterator it;
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
// TODO
|
||||
free(error_msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmpl.get("DS", ds_att);
|
||||
|
||||
for (it = ds_att.begin(); it != ds_att.end(); it++)
|
||||
{
|
||||
int dsid;
|
||||
|
||||
vatt = dynamic_cast<VectorAttribute*>(*it);
|
||||
|
||||
if (vatt == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("ID", dsid);
|
||||
|
||||
if (rc == 0 && dsid != -1)
|
||||
{
|
||||
string* s = vatt->to_xml();
|
||||
string poll = *s;
|
||||
delete s;
|
||||
|
||||
ds.insert(make_pair(dsid, poll));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::update_info(string &parse_str,
|
||||
bool &with_vm_info,
|
||||
set<int> &lost,
|
||||
map<int,string> &found,
|
||||
const set<int> &non_shared_ds)
|
||||
{
|
||||
char * error_msg;
|
||||
Template tmpl;
|
||||
|
||||
VectorAttribute* vatt;
|
||||
vector<Attribute*>::iterator it;
|
||||
vector<Attribute*> vm_att;
|
||||
vector<Attribute*> ds_att;
|
||||
vector<Attribute*> local_ds_att;
|
||||
|
||||
int rc;
|
||||
int vmid;
|
||||
long long val;
|
||||
|
||||
ostringstream zombie;
|
||||
ostringstream wild;
|
||||
|
||||
int num_zombies = 0;
|
||||
int num_wilds = 0;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Parse Template //
|
||||
// ---------------------------------------------------------------------- //
|
||||
// -------------------------------------------------------------------------
|
||||
// Parse Template
|
||||
// -------------------------------------------------------------------------
|
||||
rc = tmpl.parse(parse_str, &error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
@ -278,9 +214,63 @@ int Host::update_info(string &parse_str,
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Remove expired information from current template //
|
||||
// ---------------------------------------------------------------------- //
|
||||
// -------------------------------------------------------------------------
|
||||
// Get DS information
|
||||
// -------------------------------------------------------------------------
|
||||
tmpl.get("DS", ds_att);
|
||||
|
||||
for (it = ds_att.begin(); it != ds_att.end(); it++)
|
||||
{
|
||||
int dsid;
|
||||
|
||||
vatt = dynamic_cast<const VectorAttribute*>(*it);
|
||||
|
||||
if (vatt == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("ID", dsid);
|
||||
|
||||
if (rc == 0 && dsid != -1)
|
||||
{
|
||||
ds.insert(make_pair(dsid, vatt));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Host::update_info(Template &tmpl,
|
||||
bool &with_vm_info,
|
||||
set<int> &lost,
|
||||
map<int,string> &found,
|
||||
const set<int> &non_shared_ds)
|
||||
{
|
||||
VectorAttribute* vatt;
|
||||
vector<Attribute*>::iterator it;
|
||||
vector<Attribute*> vm_att;
|
||||
vector<Attribute*> ds_att;
|
||||
vector<Attribute*> local_ds_att;
|
||||
|
||||
int rc;
|
||||
int vmid;
|
||||
long long val;
|
||||
|
||||
string error_st;
|
||||
|
||||
ostringstream zombie;
|
||||
ostringstream wild;
|
||||
|
||||
int num_zombies = 0;
|
||||
int num_wilds = 0;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Remove expired information from current template
|
||||
// -------------------------------------------------------------------------
|
||||
clear_template_error_message();
|
||||
|
||||
remove_template_attribute("ZOMBIES");
|
||||
@ -294,21 +284,14 @@ int Host::update_info(string &parse_str,
|
||||
|
||||
remove_template_attribute("DS");
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Copy new values //
|
||||
// ---------------------------------------------------------------------- //
|
||||
// -------------------------------------------------------------------------
|
||||
// Copy monitor, extract share info & update last_monitored and state
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
string error_st;
|
||||
obj_template->merge(&tmpl, error_st);
|
||||
|
||||
// Touch the host to update its last_monitored timestamp and state
|
||||
|
||||
touch(true);
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Extract share information //
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
||||
if (isEnabled())
|
||||
{
|
||||
erase_template_attribute("TOTALCPU", val);
|
||||
@ -333,9 +316,9 @@ int Host::update_info(string &parse_str,
|
||||
host_share.used_disk = val;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Correlate VM information with the list of running VMs //
|
||||
// ---------------------------------------------------------------------- //
|
||||
// -------------------------------------------------------------------------
|
||||
// Correlate VM information with the list of running VMs
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
erase_template_attribute("VM_POLL", with_vm_info);
|
||||
|
||||
@ -396,9 +379,9 @@ int Host::update_info(string &parse_str,
|
||||
add_template_attribute("ZOMBIES", zombie.str());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Copy local system datastore monitorization //
|
||||
// ---------------------------------------------------------------------- //
|
||||
// -------------------------------------------------------------------------
|
||||
// Copy system datastore monitorization (non_shared) to host share
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
obj_template->remove("DS", ds_att);
|
||||
|
||||
@ -542,7 +525,7 @@ bool Host::isHybrid() const
|
||||
one_util::toupper(hypervisor);
|
||||
|
||||
for(int i=0; i < NUM_HYBRID_HYPERVISORS; i++)
|
||||
{
|
||||
{
|
||||
if(hypervisor==HYBRID_HYPERVISORS[i])
|
||||
{
|
||||
is_hybrid = true;
|
||||
|
@ -112,14 +112,22 @@ void InformationManagerDriver::protocol(const string& message) const
|
||||
|
||||
set<int> lost;
|
||||
map<int,string> found;
|
||||
map<int,string> datastores;
|
||||
set<int> non_shared_ds;
|
||||
|
||||
Datastore * ds;
|
||||
map<int,const VectorAttribute*> datastores;
|
||||
|
||||
map<int,string>::iterator itm;
|
||||
Template tmpl;
|
||||
|
||||
Datastore * ds;
|
||||
|
||||
map<int, const VectorAttribute*>::iterator itm;
|
||||
|
||||
int rc;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Get information from driver and decode from base64
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
getline (is, hinfo64);
|
||||
|
||||
if (hinfo64.empty())
|
||||
@ -127,20 +135,22 @@ void InformationManagerDriver::protocol(const string& message) const
|
||||
return;
|
||||
}
|
||||
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host;
|
||||
}
|
||||
|
||||
hinfo = one_util::base64_decode(hinfo64);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Monitoring Error
|
||||
// ---------------------------------------------------------------------
|
||||
if (result != "SUCCESS")
|
||||
{
|
||||
set<int> vm_ids;
|
||||
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
delete hinfo;
|
||||
goto error_host;
|
||||
}
|
||||
|
||||
host->error_info(*hinfo, vm_ids);
|
||||
|
||||
Nebula &ne = Nebula::instance();
|
||||
@ -154,45 +164,67 @@ void InformationManagerDriver::protocol(const string& message) const
|
||||
delete hinfo;
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
rc = Host::extract_ds_info(*hinfo, datastores);
|
||||
// ---------------------------------------------------------------------
|
||||
// Get DS Information from Moniroting Information
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
rc = host->extract_ds_info(*hinfo, tmpl, datastores);
|
||||
|
||||
delete hinfo;
|
||||
|
||||
host->unlock();
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
// TODO
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> non_shared_ds;
|
||||
|
||||
if (rc == 0)
|
||||
for (itm = datastores.begin(); itm != datastores.end(); itm++)
|
||||
{
|
||||
for (itm = datastores.begin(); itm != datastores.end(); itm++)
|
||||
ds = dspool->get(itm->first, true);
|
||||
|
||||
if (ds == 0)
|
||||
{
|
||||
ds = dspool->get(itm->first, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ds != 0)
|
||||
if (ds->get_type() == Datastore::SYSTEM_DS)
|
||||
{
|
||||
if (ds->is_shared())
|
||||
{
|
||||
if (ds->get_type() == Datastore::SYSTEM_DS)
|
||||
{
|
||||
if (ds->is_shared())
|
||||
{
|
||||
ImageManagerDriver::process_poll(ds, itm->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
non_shared_ds.insert(itm->first);
|
||||
}
|
||||
}
|
||||
float total = 0, free = 0, used = 0;
|
||||
ostringstream oss;
|
||||
|
||||
ds->unlock();
|
||||
(itm->second)->vector_value("TOTAL_MB", total);
|
||||
(itm->second)->vector_value("FREE_MB", free);
|
||||
(itm->second)->vector_value("USED_MB", used);
|
||||
|
||||
ds->update_monitor(total, free, used);
|
||||
|
||||
oss << "Datastore " << ds->get_name() <<
|
||||
" (" << ds->get_oid() << ") successfully monitored.";
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, oss);
|
||||
}
|
||||
else
|
||||
{
|
||||
non_shared_ds.insert(itm->first);
|
||||
}
|
||||
}
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Parse Host information
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
host = hpool->get(id,true);
|
||||
|
||||
if ( host == 0 )
|
||||
@ -201,9 +233,7 @@ void InformationManagerDriver::protocol(const string& message) const
|
||||
goto error_host;
|
||||
}
|
||||
|
||||
rc = host->update_info(*hinfo, vm_poll, lost, found, non_shared_ds);
|
||||
|
||||
delete hinfo;
|
||||
rc = host->update_info(tmpl, vm_poll, lost, found, non_shared_ds);
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
|
@ -195,8 +195,7 @@ static int cp_action(istringstream& is,
|
||||
|
||||
image->unlock();
|
||||
|
||||
oss << "Image " << id << " copied and ready to use.";
|
||||
NebulaLog::log("ImM", Log::INFO, oss);
|
||||
NebulaLog::log("ImM", Log::INFO, "Image copied and ready to use.");
|
||||
|
||||
return ds_id;
|
||||
|
||||
@ -618,59 +617,53 @@ static void monitor_action(istringstream& is,
|
||||
return;
|
||||
}
|
||||
|
||||
ImageManagerDriver::process_poll(id, *dsinfo);
|
||||
|
||||
delete dsinfo;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void ImageManagerDriver::process_poll(int id, const string &monitor_str)
|
||||
{
|
||||
Datastore* ds = Nebula::instance().get_dspool()->get(id,true);
|
||||
|
||||
if ( ds == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
process_poll(ds, monitor_str);
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::process_poll(Datastore* ds, const string &monitor_str)
|
||||
{
|
||||
Template monitor_data;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
string error_msg;
|
||||
int rc = monitor_data.parse_str_or_xml(monitor_str, error_msg);
|
||||
|
||||
DatastorePool* dspool = Nebula::instance().get_dspool();
|
||||
char* error_msg;
|
||||
int rc = monitor_data.parse(*dsinfo, &error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
oss << "Error parsing datastore information: " << error_msg
|
||||
<< ". Monitoring information: " << endl << monitor_str;
|
||||
<< ". Monitoring information: " << endl << *dsinfo;
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss);
|
||||
|
||||
delete dsinfo;
|
||||
free(error_msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ds->process_poll(monitor_data);
|
||||
delete dsinfo;
|
||||
|
||||
float total, free, used;
|
||||
string ds_name;
|
||||
|
||||
monitor_data.get("TOTAL_MB", total);
|
||||
monitor_data.get("FREE_MB", free);
|
||||
monitor_data.get("USED_MB", used);
|
||||
|
||||
Datastore * ds = dspool->get(id, true);
|
||||
|
||||
if (ds == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds_name = ds->get_name();
|
||||
|
||||
ds->update_monitor(total, free, used);
|
||||
|
||||
dspool->update(ds);
|
||||
|
||||
oss << "Datastore " << ds->get_name()
|
||||
<< " (" << ds->get_oid() << ") successfully monitored.";
|
||||
ds->unlock();
|
||||
|
||||
oss << "Datastore " << ds_name << " (" << id << ") successfully monitored.";
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, oss);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user