1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-28 14:50:08 +03:00

feature #2009: Fix constness of Mad protocol interface

(cherry picked from commit b44788399f369fd46e0cbfa21eaf758994424606)
This commit is contained in:
Ruben S. Montero 2013-05-16 21:54:56 +02:00
parent 305747d4ed
commit 67b88ece7d
13 changed files with 62 additions and 73 deletions

View File

@ -50,8 +50,7 @@ public:
* Implements the VM Manager driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(const string& message) const;
/**
* Re-starts the driver

View File

@ -29,7 +29,7 @@ using namespace std;
/**
* HookManagerDriver provides a base class to implement Hook (Execution)
* Drivers. This class implements the protocol and recover functions
* from the Mad interface. This class may be used to further specialize
* from the Mad interface. This class may be used to further specialize
* the Execution driver.
*/
class HookManagerDriver : public Mad
@ -49,14 +49,13 @@ public:
* Implements the Hook driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(const string& message) const;
/**
* TODO: What do we need here? just poll the Hosts to recover..
*/
void recover();
/**<id> <hook_name> <LOCAL|host> <script> <args|->
* Sends an execution request to the MAD: "EXECUTE id name local cmd args"
* @param oid the virtual machine id.
@ -88,7 +87,7 @@ public:
private:
friend class HookManager;
VirtualMachinePool * vmpool;
};

View File

@ -30,16 +30,16 @@ class ImagePool;
class ImageManager;
/**
* ImageManagerDriver represents the basic abstraction for Image Repository
* drivers. It implements the protocol and recover functions from the Mad
* ImageManagerDriver represents the basic abstraction for Image Repository
* drivers. It implements the protocol and recover functions from the Mad
* interface.
*/
class ImageManagerDriver : public Mad
{
public:
ImageManagerDriver(int userid,
const map<string,string>& attrs,
ImageManagerDriver(int userid,
const map<string,string>& attrs,
bool sudo,
ImagePool* _ipool):
Mad(userid,attrs,sudo),ipool(_ipool){};
@ -50,7 +50,7 @@ public:
* Implements the Image Manager driver protocol.
* @param message the string read from the driver
*/
void protocol(string& message);
void protocol(const string& message) const;
/**
* TODO: What do we need here? Check on-going xfr?

View File

@ -50,7 +50,7 @@ public:
* Implements the IM driver protocol.
* @param message the string read from the driver
*/
void protocol(string& message);
void protocol(const string& message) const;
/**
* TODO: What do we need here? just poll the Hosts to recover..

View File

@ -32,17 +32,17 @@ using namespace std;
/**
* Base class to build specific middleware access drivers (MAD).
* This class provides generic MAD functionality.
* This class provides generic MAD functionality.
*/
class Mad
{
protected:
/**
* The constructor initialize the class members but DOES NOT start the
* The constructor initialize the class members but DOES NOT start the
* driver. A subsequent call to the start() method is needed.
* @param userid user running this MAD
* @param attrs configuration attributes for the driver
* @param sudo the driver is started through sudo if true
* @param sudo the driver is started through sudo if true
*/
Mad(
int userid,
@ -53,13 +53,13 @@ protected:
sudo_execution(sudo),
pid(-1)
{};
/**
* The destructor of the class finalizes the driver process, and all its
* associated resources (i.e. pipes)
*/
virtual ~Mad();
/**
* Send a command to the driver
* @param os an output string stream with the message, it must be
@ -70,7 +70,7 @@ protected:
{
string str;
const char * cstr;
str = os.str();
cstr = str.c_str();
@ -95,7 +95,7 @@ protected:
* @param first character of the type string
* @return the message type
*/
Log::MessageType log_type(const char r)
Log::MessageType log_type(const char r) const
{
Log::MessageType lt;
@ -121,17 +121,17 @@ private:
friend class MadManager;
/**
* Communication pipe file descriptor. Represents the MAD to nebula
* Communication pipe file descriptor. Represents the MAD to nebula
* communication stream (nebula<-mad)
*/
int mad_nebula_pipe;
/**
* Communication pipe file descriptor. Represents the nebula to MAD
* Communication pipe file descriptor. Represents the nebula to MAD
* communication stream (nebula->mad)
*/
int nebula_mad_pipe;
/**
* User running this MAD as defined in the upool DB
*/
@ -144,7 +144,7 @@ private:
map<string,string> attributes;
/**
* True if the mad is to be executed through sudo, with the identity of the
* True if the mad is to be executed through sudo, with the identity of the
* Mad owner (uid).
*/
bool sudo_execution;
@ -153,16 +153,16 @@ private:
* Process ID of the running MAD.
*/
pid_t pid;
/**
* Starts the MAD. This function creates a new process, sets up the
* Starts the MAD. This function creates a new process, sets up the
* communication pipes and sends the initialization command to the driver.
* @return 0 on success
*/
int start();
/**
* Reloads the driver: sends the finalize command, "waits" for the
* Reloads the driver: sends the finalize command, "waits" for the
* driver process and closes the communication pipes. Then the driver is
* started again by calling the start() function
* @return 0 on success
@ -174,14 +174,13 @@ private:
* actions on the associated manager.
* @param message the string read from the driver
*/
virtual void protocol(
string& message) = 0;
virtual void protocol(const string& message) const = 0;
/**
* This function is called whenever the driver crashes. This function
* should perform the actions needed to recover the VMs.
*/
virtual void recover() = 0;
virtual void recover() = 0;
};
#endif /*MAD_H_*/

View File

@ -48,8 +48,7 @@ public:
* Implements the VM Manager driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(const string& message) const;
/**
* TODO: What do we need here? Check on-going xfr?

View File

@ -49,8 +49,7 @@ public:
* Implements the VM Manager driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(const string& message) const;
/**
* TODO: What do we need here? just poll the active VMs to recover

View File

@ -25,9 +25,9 @@
/* Driver ASCII Protocol Implementation */
/* ************************************************************************** */
void AuthManagerDriver::authorize(int oid,
int uid,
const string& reqs,
void AuthManagerDriver::authorize(int oid,
int uid,
const string& reqs,
bool acl) const
{
ostringstream os;
@ -60,8 +60,7 @@ void AuthManagerDriver::authenticate(int oid,
/* MAD Interface */
/* ************************************************************************** */
void AuthManagerDriver::protocol(
string& message)
void AuthManagerDriver::protocol(const string& message) const
{
istringstream is(message);
ostringstream os;

View File

@ -29,9 +29,9 @@ void HookManagerDriver::execute(
const string& arguments ) const
{
ostringstream oss;
oss << "EXECUTE " << oid << " " << hook_name << " LOCAL " << command << " ";
if ( arguments.empty() )
{
oss << "-" << endl;
@ -55,10 +55,10 @@ void HookManagerDriver::execute(
const string& arguments ) const
{
ostringstream oss;
oss << "EXECUTE " << oid << " " << hook_name << " " << host_name << " "
oss << "EXECUTE " << oid << " " << hook_name << " " << host_name << " "
<< command << " ";
if ( arguments.empty() )
{
oss << "-" << endl;
@ -74,10 +74,9 @@ void HookManagerDriver::execute(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void HookManagerDriver::protocol(
string& message)
{
istringstream is(message);
void HookManagerDriver::protocol(const string& message) const
{
istringstream is(message);
//stores the action name
string action;
//stores the action result
@ -88,7 +87,7 @@ void HookManagerDriver::protocol(
ostringstream os;
string hinfo;
VirtualMachine * vm;
// Parse the driver message
os << "Message received: " << message;
@ -109,7 +108,7 @@ void HookManagerDriver::protocol(
is >> result >> ws;
}
else
{
{
return;
}
@ -135,49 +134,49 @@ void HookManagerDriver::protocol(
{
return;
}
vm = vmpool->get(id,true);
if ( vm == 0 )
{
return;
}
// -------------------------------------------------------------------------
// Protocol implementation
// -------------------------------------------------------------------------
if ( action == "EXECUTE" )
{
ostringstream oss;
string hook_name;
string info;
if ( is.good() )
{
getline(is,hook_name);
}
getline (is,info);
if (result == "SUCCESS")
{
{
oss << "Success executing Hook: " << hook_name << ". " << info;
vm->log("HKM",Log::INFO,oss);
}
else
{
oss << "Error executing Hook: " << hook_name << ". " << info;
if ( !info.empty() && info[0] != '-' )
{
{
vm->set_template_error_message(oss.str());
vmpool->update(vm);
}
vm->log("HKM",Log::ERROR,oss);
}
}
}
else if (action == "LOG")
{
@ -186,9 +185,9 @@ void HookManagerDriver::protocol(
getline(is,info);
vm->log("HKM",log_type(result[0]),info.c_str());
}
vm->unlock();
return;
}
@ -198,5 +197,5 @@ void HookManagerDriver::protocol(
void HookManagerDriver::recover()
{
NebulaLog::log("HKM", Log::ERROR, "Hook driver crashed, recovering...");
}

View File

@ -40,8 +40,7 @@ void InformationManagerDriver::monitor(int oid,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void InformationManagerDriver::protocol(
string& message)
void InformationManagerDriver::protocol(const string& message) const
{
istringstream is(message);
//stores the action name

View File

@ -555,8 +555,7 @@ error:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ImageManagerDriver::protocol(
string& message)
void ImageManagerDriver::protocol(const string& message) const
{
istringstream is(message);
ostringstream oss;

View File

@ -41,8 +41,7 @@ void TransferManagerDriver::transfer (
/* MAD Interface */
/* ************************************************************************** */
void TransferManagerDriver::protocol(
string& message)
void TransferManagerDriver::protocol(const string& message) const
{
istringstream is(message);
ostringstream os;

View File

@ -179,8 +179,7 @@ static void log_monitor_error(VirtualMachine* vm,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::protocol(
string& message)
void VirtualMachineManagerDriver::protocol(const string& message) const
{
istringstream is(message);
ostringstream os;