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

feature #575: Add error messages to VM templates (VMM part)

This commit is contained in:
Ruben S. Montero 2011-04-15 00:34:22 +02:00
parent bea18b1100
commit cd163f2a54
3 changed files with 107 additions and 66 deletions

View File

@ -541,6 +541,13 @@ public:
*/
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
// ------------------------------------------------------------------------
@ -823,6 +830,10 @@ private:
// -------------------------------------------------------------------------
// Attribute Parser
// -------------------------------------------------------------------------
/**
* Name for the error messages attribute
*/
static const char * error_attribute_name;
/**
* Mutex to perform just one attribute parse at a time

View File

@ -102,6 +102,8 @@ const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS "
"vm_pool (oid INTEGER PRIMARY KEY, name TEXT, body TEXT, uid INTEGER, "
"last_poll INTEGER, state INTEGER, lcm_state INTEGER)";
const char * VirtualMachine::error_attribute_name = "ERROR_MESSAGE";
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -1012,6 +1014,33 @@ error_common:
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

@ -227,17 +227,68 @@ void VirtualMachineManagerDriver::poll (
/* MAD Interface */
/* ************************************************************************** */
/* -------------------------------------------------------------------------- */
/* Helpers for the protocol function */
/* -------------------------------------------------------------------------- */
static void log_error(VirtualMachine* vm,
ostringstream& os,
istringstream& is,
const char * msg)
{
string info;
getline(is,info);
os.str("");
os << msg;
if (info[0] != '-')
{
os << ": " << info;
vm->set_error_message(os.str());
}
vm->log("VMM",Log::ERROR,os);
}
static Log::MessageType log_type(const char r)
{
Log::MessageType lt;
switch (r)
{
case 'E':
lt = Log::ERROR;
break;
case 'I':
lt = Log::INFO;
break;
case 'D':
lt = Log::DEBUG;
break;
default:
lt = Log::INFO;
}
return lt;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::protocol(
string& message)
{
istringstream is(message);
ostringstream os;
istringstream is(message);
ostringstream os;
string action;
string result;
string action;
string result;
int id;
VirtualMachine * vm;
int id;
VirtualMachine * vm;
os << "Message received: " << message;
NebulaLog::log("VMM", Log::DEBUG, os);
@ -265,7 +316,7 @@ void VirtualMachineManagerDriver::protocol(
is.clear();
getline(is,info);
NebulaLog::log("VMM",Log::INFO, info.c_str());
NebulaLog::log("VMM", log_type(result[0]), info.c_str());
}
return;
@ -316,17 +367,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error deploying virtual machine";
if (info[0] != '-')
os << ": " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error deploying virtual machine");
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -342,14 +383,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error shuting down VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error shuting down VM");
lcm->trigger(LifeCycleManager::SHUTDOWN_FAILURE, id);
}
@ -365,14 +399,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error canceling VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error canceling VM");
lcm->trigger(LifeCycleManager::CANCEL_FAILURE, id);
}
@ -388,14 +415,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error saving VM state, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error saving VM state");
lcm->trigger(LifeCycleManager::SAVE_FAILURE, id);
}
@ -411,14 +431,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error restoring VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error restoring VM");
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -434,14 +447,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error live-migrating VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error live migrating VM");
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -507,7 +513,7 @@ void VirtualMachineManagerDriver::protocol(
{
tiss >> state;
}
else
else if (!var.empty())
{
string val;
@ -580,12 +586,7 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error monitoring VM, " << info;
log_error(vm,os,is,"Error monitoring VM");
vm->log("VMM",Log::ERROR,os);
}
@ -595,7 +596,7 @@ void VirtualMachineManagerDriver::protocol(
string info;
getline(is,info);
vm->log("VMM",Log::INFO,info.c_str());
vm->log("VMM",log_type(result[0]),info.c_str());
}
vm->unlock();