1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

feature #575: Improved log messages for drivers. Error string also propagated to images

This commit is contained in:
Ruben S. Montero 2011-04-15 01:51:38 +02:00
parent aebb1cd6a7
commit db8aa7f5bf
10 changed files with 82 additions and 66 deletions

View File

@ -217,6 +217,13 @@ public:
return obj_template->erase(name); return obj_template->erase(name);
} }
/**
* Sets an error message for the VM in the template
* @param message
* @return 0 on success
*/
void set_template_error_message(const string& message);
protected: protected:
/** /**
@ -318,6 +325,11 @@ private:
* Pointer to the SQL table for the PoolObjectSQL * Pointer to the SQL table for the PoolObjectSQL
*/ */
const char * table; const char * table;
/**
* Name for the error messages attribute
*/
static const char * error_attribute_name;
}; };
#endif /*POOL_OBJECT_SQL_H_*/ #endif /*POOL_OBJECT_SQL_H_*/

View File

@ -541,17 +541,9 @@ public:
*/ */
int parse_template_attribute(const string& attribute, string& parsed); int parse_template_attribute(const string& attribute, string& parsed);
/**
* Sets an error message for the VM in the template
* @param message
* @return 0 on success
*/
void set_error_message(const string& message);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// States // States
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** /**
* Returns the VM state (Dispatch Manager) * Returns the VM state (Dispatch Manager)
* @return the VM state * @return the VM state
@ -826,14 +818,9 @@ private:
return -1; return -1;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Attribute Parser // Attribute Parser
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/**
* Name for the error messages attribute
*/
static const char * error_attribute_name;
/** /**
* Mutex to perform just one attribute parse at a time * Mutex to perform just one attribute parse at a time

View File

@ -91,7 +91,7 @@ void AuthManagerDriver::protocol(
{ {
is.clear(); is.clear();
getline(is,info); getline(is,info);
NebulaLog::log("AuM",Log::INFO, info.c_str()); NebulaLog::log("AuM", log_type(result[0]), info.c_str());
} }
return; return;

View File

@ -125,7 +125,7 @@ void HookManagerDriver::protocol(
is.clear(); is.clear();
getline(is,info); getline(is,info);
NebulaLog::log("HKM",Log::INFO, info.c_str()); NebulaLog::log("HKM", log_type(result[0]), info.c_str());
} }
return; return;
@ -169,6 +169,13 @@ void HookManagerDriver::protocol(
else else
{ {
oss << "Error executing Hook: " << hook_name << ". " << info; oss << "Error executing Hook: " << hook_name << ". " << info;
if ( info[0] != '-' )
{
vm->set_template_error_message(os.str());
vmpool->update(vm);
}
vm->log("HKM",Log::ERROR,oss); vm->log("HKM",Log::ERROR,oss);
} }
} }
@ -177,7 +184,7 @@ void HookManagerDriver::protocol(
string info; string info;
getline(is,info); getline(is,info);
vm->log("HKM",Log::INFO,info.c_str()); vm->log("HKM",log_type(result[0]),info.c_str());
} }
vm->unlock(); vm->unlock();

View File

@ -110,7 +110,7 @@ void InformationManagerDriver::protocol(
hinfo += "\n"; hinfo += "\n";
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo; oss << "Host " << id << " successfully monitored.";
NebulaLog::log("InM",Log::DEBUG,oss); NebulaLog::log("InM",Log::DEBUG,oss);
rc = host->update_info(hinfo); rc = host->update_info(hinfo);
@ -136,7 +136,7 @@ void InformationManagerDriver::protocol(
string info; string info;
getline(is,info); getline(is,info);
NebulaLog::log("InM",Log::INFO,info.c_str()); NebulaLog::log("InM",log_type(result[0]),info.c_str());
} }
return; return;

View File

@ -93,6 +93,7 @@ void ImageManagerDriver::protocol(
int id; int id;
Image * image; Image * image;
string source;
string info; string info;
@ -123,7 +124,7 @@ void ImageManagerDriver::protocol(
is.clear(); is.clear();
getline(is,info); getline(is,info);
NebulaLog::log("ImG",Log::INFO, info.c_str()); NebulaLog::log("ImG",log_type(result[0]), info.c_str());
} }
return; return;
@ -148,8 +149,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY); image->set_state(Image::READY);
ipool->update(image); ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image copied and ready to use."); NebulaLog::log("ImM", Log::INFO, "Image copied and ready to use.");
} }
else else
@ -164,8 +163,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY); image->set_state(Image::READY);
ipool->update(image); ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image saved and ready to use."); NebulaLog::log("ImM", Log::INFO, "Image saved and ready to use.");
} }
else else
@ -180,8 +177,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY); image->set_state(Image::READY);
ipool->update(image); ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image created and ready to use"); NebulaLog::log("ImM", Log::INFO, "Image created and ready to use");
} }
else else
@ -192,14 +187,11 @@ void ImageManagerDriver::protocol(
else if ( action == "RM" ) else if ( action == "RM" )
{ {
int rc; int rc;
string source;
source = image->get_source(); source = image->get_source();
rc = ipool->drop(image); rc = ipool->drop(image);
image->unlock();
if ( rc < 0 ) if ( rc < 0 )
{ {
NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB"); NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB");
@ -211,20 +203,17 @@ void ImageManagerDriver::protocol(
} }
else else
{ {
ostringstream oss; goto error_rm;
oss <<"Error removing image from repository. Remove file " << source
<<" to completely delete image.";
NebulaLog::log("ImM",Log::ERROR,oss);
} }
} }
else if (action == "LOG") else if (action == "LOG")
{ {
getline(is,info); getline(is,info);
NebulaLog::log("ImM", Log::INFO, info.c_str()); NebulaLog::log("ImM", log_type(result[0]), info.c_str());
} }
image->unlock();
return; return;
error_cp: error_cp:
@ -240,6 +229,12 @@ error_mv:
error_mkfs: error_mkfs:
os.str(""); os.str("");
os << "Error creating datablock"; os << "Error creating datablock";
goto error_common;
error_rm:
os.str("");
os << "Error removing image from repository. Remove file " << source
<< " to completely delete image.";
error_common: error_common:
getline(is,info); getline(is,info);
@ -247,6 +242,7 @@ error_common:
if (!info.empty() && (info[0] != '-')) if (!info.empty() && (info[0] != '-'))
{ {
os << ": " << info; os << ": " << info;
image->set_template_error_message(os.str());
} }
NebulaLog::log("ImM", Log::ERROR, os); NebulaLog::log("ImM", Log::ERROR, os);

View File

@ -108,3 +108,37 @@ int PoolObjectSQL::drop(SqlDB *db)
return rc; return rc;
} }
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * PoolObjectSQL::error_attribute_name = "ERROR_MESSAGE";
void PoolObjectSQL::set_template_error_message(const string& message)
{
SingleAttribute * attr;
ostringstream error;
char str[26];
time_t the_time;
the_time = time(NULL);
#ifdef SOLARIS
ctime_r(&(the_time),str,sizeof(char)*26);
#else
ctime_r(&(the_time),str);
#endif
// Get rid of final enter character
str[24] = '\0';
error << str << ": " << message;
attr = new SingleAttribute(error_attribute_name,error.str());
obj_template->set(attr);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -147,7 +147,9 @@ void TransferManagerDriver::protocol(
if (info[0] != '-') if (info[0] != '-')
{ {
os << ": " << info; os << ": " << info;
vm->set_error_message(os.str());
vm->set_template_error_message(os.str());
vmpool->update(vm);
} }
vm->log("TM",Log::ERROR,os); vm->log("TM",Log::ERROR,os);

View File

@ -102,8 +102,6 @@ const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"vm_pool (oid INTEGER PRIMARY KEY, name TEXT, body TEXT, uid INTEGER, " "vm_pool (oid INTEGER PRIMARY KEY, name TEXT, body TEXT, uid INTEGER, "
"last_poll INTEGER, state INTEGER, lcm_state INTEGER)"; "last_poll INTEGER, state INTEGER, lcm_state INTEGER)";
const char * VirtualMachine::error_attribute_name = "ERROR_MESSAGE";
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -1014,33 +1012,6 @@ error_common:
return -1; return -1;
} }
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::set_error_message(const string& message)
{
SingleAttribute * attr;
ostringstream error;
char str[26];
time_t the_time;
the_time = time(NULL);
#ifdef SOLARIS
ctime_r(&(the_time),str,sizeof(char)*26);
#else
ctime_r(&(the_time),str);
#endif
// Get rid of final enter character
str[24] = '\0';
error << str << ": " << message;
attr = new SingleAttribute(error_attribute_name,error.str());
obj_template->set(attr);
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */

View File

@ -246,7 +246,7 @@ static void log_error(VirtualMachine* vm,
if (info[0] != '-') if (info[0] != '-')
{ {
os << ": " << info; os << ": " << info;
vm->set_error_message(os.str()); vm->set_template_error_message(os.str());
} }
vm->log("VMM",Log::ERROR,os); vm->log("VMM",Log::ERROR,os);
@ -346,6 +346,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error deploying virtual machine"); log_error(vm,os,is,"Error deploying virtual machine");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id); lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
} }
@ -362,6 +363,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error shuting down VM"); log_error(vm,os,is,"Error shuting down VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::SHUTDOWN_FAILURE, id); lcm->trigger(LifeCycleManager::SHUTDOWN_FAILURE, id);
} }
@ -378,6 +380,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error canceling VM"); log_error(vm,os,is,"Error canceling VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::CANCEL_FAILURE, id); lcm->trigger(LifeCycleManager::CANCEL_FAILURE, id);
} }
@ -394,6 +397,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error saving VM state"); log_error(vm,os,is,"Error saving VM state");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::SAVE_FAILURE, id); lcm->trigger(LifeCycleManager::SAVE_FAILURE, id);
} }
@ -410,6 +414,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error restoring VM"); log_error(vm,os,is,"Error restoring VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id); lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
} }
@ -426,6 +431,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error live migrating VM"); log_error(vm,os,is,"Error live migrating VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id); lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
} }
@ -565,6 +571,7 @@ void VirtualMachineManagerDriver::protocol(
else else
{ {
log_error(vm,os,is,"Error monitoring VM"); log_error(vm,os,is,"Error monitoring VM");
vmpool->update(vm);
vm->log("VMM",Log::ERROR,os); vm->log("VMM",Log::ERROR,os);
} }