Refactoring the previous patch ended up creating two deltas. This patch pushes them both together into a single commit.
Darryl L. Pierce
2010-May-19 12:18 UTC
[Ovirt-devel] [PATCH matahari] Moving QMF functionality into a transport layer.
This is the first step towards separating the APIs from the means by which they are carried between the remote and local system. A new type, HostListener, defines a type that receives notifications when the Host fires off an event. A new type, ProcessorsListener, defines a type that receives notifications when Processors updates itself. Signed-off-by: Darryl L. Pierce <dpierce at redhat.com> --- .gitignore | 2 +- src/Makefile.am | 8 ++- src/host.cpp | 156 +++++++++++++++++++++++++++++------------- src/host.h | 56 ++++++++++------ src/hostlistener.h | 33 +++++++++ src/main.cpp | 11 +++- src/processors.cpp | 44 ++++++++---- src/processors.h | 31 +++------ src/processorslistener.h | 29 ++++++++ src/qmf/hostagent.cpp | 68 +++++++++++++++++++ src/qmf/hostagent.h | 51 ++++++++++++++ src/qmf/processorsagent.cpp | 49 ++++++++++++++ src/qmf/processorsagent.h | 50 ++++++++++++++ 13 files changed, 480 insertions(+), 108 deletions(-) create mode 100644 src/hostlistener.h create mode 100644 src/processorslistener.h create mode 100644 src/qmf/hostagent.cpp create mode 100644 src/qmf/hostagent.h create mode 100644 src/qmf/processorsagent.cpp create mode 100644 src/qmf/processorsagent.h diff --git a/.gitignore b/.gitignore index ad6d70b..8e12062 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ stamp-h1 *~ src/matahari -src/qmf +src/qmf/com diff --git a/src/Makefile.am b/src/Makefile.am index aed9e19..498ee72 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ nodist_matahari_SOURCES = $(generated_file_list) $(first) matahari_SOURCES = \ host.cpp \ host.h \ + hostlistener.h \ linux_platform.cpp \ linux_platform.h \ main.cpp \ @@ -26,7 +27,12 @@ matahari_SOURCES = \ platform.cpp \ platform.h \ processors.cpp \ - processors.h + processors.h \ + processorslistener.h \ + qmf/hostagent.cpp \ + qmf/hostagent.h \ + qmf/processorsagent.cpp \ + qmf/processorsagent.h $(generated_file_list): $(generated_file_list) diff --git a/src/host.cpp b/src/host.cpp index 34d4550..29b84ec 100644 --- a/src/host.cpp +++ b/src/host.cpp @@ -17,60 +17,43 @@ * also available at http://www.gnu.org/copyleft/gpl.html. */ -#include <fstream> +#include "host.h" +#include "platform.h" +#include <fstream> #include <libvirt/libvirt.h> -#include <qpid/management/Manageable.h> +#include <stdexcept> +#include <string> #include <sys/sysinfo.h> #include <sys/utsname.h> -#include "host.h" -#include "platform.h" -#include "qmf/com/redhat/matahari/Host.h" - -using namespace qpid::management; using namespace std; -using qpid::management::Manageable; -namespace _qmf = qmf::com::redhat::matahari; - -void -HostAgent::setup(ManagementAgent* agent) +Host::Host() { - management_object = new _qmf::Host(agent, this); - agent->addObject(management_object); - - // discover the aspects of the host - processors.setup(agent, this); - networkdevices = Platform::instance()->get_network_devices(); - - for(vector<NetworkDeviceAgent>::iterator iter = networkdevices.begin(); - iter != networkdevices.end(); - iter++) - { - iter->setup(agent, this); - } - struct utsname details; - string uuid = "Unknown"; - string hostname = "Unknown"; - string hypervisor = "Unknown"; - string architecture = "None"; - unsigned long memory = 0; - bool beeping = false; + this->_uuid = string("Unknown"); + this->_hostname = string("Unknown"); + this->_hypervisor = string("Unknown"); + this->_architecture = string("None"); + this->_memory = 0; + this->_beeping = false; - ifstream input("/var/lib/dbus/machine-id"); + std::ifstream input("/var/lib/dbus/machine-id"); if(input.is_open()) { + string uuid; + getline(input, uuid); input.close(); + this->_uuid = uuid; } if(!uname(&details)) { - hostname = string(details.nodename); - architecture = string(details.machine); + this->_hostname = string(details.nodename); + this->_architecture = string(details.machine); } else { @@ -81,39 +64,116 @@ HostAgent::setup(ManagementAgent* agent) if(lvconn) { - hypervisor = string(virConnectGetType(lvconn)); + this->_hypervisor = string(virConnectGetType(lvconn)); virConnectClose(lvconn); } struct sysinfo sysinf; if(!sysinfo(&sysinf)) { - memory = sysinf.totalram / 1024L; + this->_memory = sysinf.totalram / 1024L; } else { throw runtime_error("Unable to retrieve system memory details."); } +} - cout << "memory: " << memory << endl; +/* +void +Host::setup(ManagementAgent* agent, HostAgent* hostAgent) +{ + // discover the aspects of the host + _processors.setup(agent, hostAgent); + _networkdevices = Platform::instance()->get_network_devices(); - management_object->set_uuid(uuid); - management_object->set_hostname(hostname); - management_object->set_hypervisor(hypervisor); - management_object->set_arch(architecture); - management_object->set_memory(memory); - management_object->set_beeping(beeping); + for(vector<NetworkDeviceAgent>::iterator iter = _networkdevices.begin(); + iter != _networkdevices.end(); + iter++) + { + iter->setup(agent, hostAgent); + } } +*/ void -HostAgent::update(void) +Host::update() { - processors.update(); + _processors.update(); - for(vector<NetworkDeviceAgent>::iterator iter = networkdevices.begin(); - iter != networkdevices.end(); + for(vector<NetworkDeviceAgent>::iterator iter = _networkdevices.begin(); + iter != _networkdevices.end(); iter++) { iter->update(); } } + +void +Host::addHostListener(HostListener* listener) +{ + _listeners.insert(listener); +} + +void +Host::removeHostListener(HostListener* listener) +{ + _listeners.erase(listener); +} + +Processors& +Host::getProcessors() +{ + return _processors; +} + +string +Host:: getUUID() const +{ + return _uuid; +} + +string +Host::getHostname() const +{ + return _hostname; +} + +string +Host::getHypervisor() const +{ + return _hypervisor; +} + +string +Host::getArchitecture() const +{ + return _architecture; +} + +unsigned int +Host::getMemory() const +{ + return _memory; +} + +bool +Host::isBeeping() const +{ + return _beeping; +} + +void +Host::identify(const int iterations) +{ +} + +void +Host::shutdown() +{ +} + +void +Host::reboot() +{ +} diff --git a/src/host.h b/src/host.h index d2da776..bcb8c12 100644 --- a/src/host.h +++ b/src/host.h @@ -20,39 +20,53 @@ * also available at http://www.gnu.org/copyleft/gpl.html. */ -#include <qpid/management/Manageable.h> -#include <qpid/management/ManagementObject.h> -#include <qpid/agent/ManagementAgent.h> +#include <string> +#include <set> -#include "qmf/com/redhat/matahari/Host.h" - -#include "networkdevice.h" +#include "hostlistener.h" #include "processors.h" +#include "networkdevice.h" -using namespace qpid::management; using namespace std; -using qpid::management::Manageable; - -class HostAgent : public Manageable +/* + Host represents the public contract for the set of host APIs. + */ +class Host { private: - qmf::com::redhat::matahari::Host* management_object; - ProcessorsAgent processors; - vector<NetworkDeviceAgent> networkdevices; + string _uuid; + string _hostname; + string _hypervisor; + string _architecture; + unsigned int _memory; + bool _beeping; + + Processors _processors; + vector<NetworkDeviceAgent> _networkdevices; + set<HostListener*> _listeners; public: - HostAgent() {} - virtual ~HostAgent() {} + Host(); + virtual ~Host() {} + + void update(); + + void addHostListener(HostListener*); + void removeHostListener(HostListener*); - ManagementObject* GetManagementObject(void) const { return management_object; } + Processors& getProcessors(); - void setup(ManagementAgent* agent); - void update(void); + string getUUID() const; + string getHostname() const; + string getHypervisor() const; + string getArchitecture() const; + unsigned int getMemory() const; - // agent methods - void shutdown(void); - void reboot(void); + bool isBeeping() const; + void identify(const int iterations); + void shutdown(); + void reboot(); }; #endif // __HOST_H diff --git a/src/hostlistener.h b/src/hostlistener.h new file mode 100644 index 0000000..298e51d --- /dev/null +++ b/src/hostlistener.h @@ -0,0 +1,33 @@ +#ifndef __HOSTLISTENER_H +#define __HOSTLISTENER_H + +/* hostlistener.h - Copyright (C) 2009 Red Hat, Inc. + * Written by Darryl Pierce <dpierce at redhat.com>. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +/* + HostListener defines a type which receives notification + whenever a Host event occurs. + */ +class HostListener +{ + public: + virtual void heartbeat(unsigned long timestamp) = 0; +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index 5ab3ac2..f45353a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,10 @@ #include <getopt.h> #include "host.h" + +#include "qmf/hostagent.h" +#include "qmf/processorsagent.h" + #include "qmf/com/redhat/matahari/Package.h" using namespace qpid::management; @@ -76,7 +80,9 @@ main(int argc, char **argv) ConnectionSettings settings; ManagementAgent *agent; - HostAgent host; + Host host; + HostAgent hostAgent(host); + ProcessorsAgent processorsAgent(host.getProcessors());; struct option opt[] = { {"help", no_argument, NULL, 'h'}, @@ -178,7 +184,8 @@ main(int argc, char **argv) agent->init(settings, 5, false, ".magentdata"); // Get the info and post it to the broker - host.setup(agent); + hostAgent.setup(agent); + processorsAgent.setup(agent, &hostAgent); while(1) { diff --git a/src/processors.cpp b/src/processors.cpp index 13c492d..1850aba 100644 --- a/src/processors.cpp +++ b/src/processors.cpp @@ -20,30 +20,44 @@ #include "processors.h" #include "platform.h" -using namespace std; -namespace _qmf = qmf::com::redhat::matahari; +void +Processors::addProcessorsListener(ProcessorsListener* listener) +{ + _listeners.insert(listener); +} void -ProcessorsAgent::setup(ManagementAgent* agent, Manageable* parent) +Processors::removeProcessorsListener(ProcessorsListener* listener) { - // setup the management object - management_object = new _qmf::Processors(agent, this, parent); - agent->addObject(management_object); + _listeners.erase(listener); +} - Platform* platform = Platform::instance(); +void +Processors::update() +{ + for(set<ProcessorsListener*>::iterator iter = _listeners.begin(); + iter != _listeners.end(); + iter++) + { + (*iter)->updated(); + } +} - management_object->set_model(platform->get_processor_model()); - management_object->set_cores(platform->get_number_of_cores()); +string +Processors::getModel() const +{ + return Platform::instance()->get_processor_model(); } -void -ProcessorsAgent::update(void) const + +unsigned int +Processors::getNumberOfCores() const { - update_load_averages(); + return Platform::instance()->get_number_of_cores(); } -void -ProcessorsAgent::update_load_averages(void) const +float +Processors::getLoadAverage() const { - management_object->set_load_average(Platform::instance()->get_load_average()); + return Platform::instance()->get_load_average(); } diff --git a/src/processors.h b/src/processors.h index e681453..e69a6ee 100644 --- a/src/processors.h +++ b/src/processors.h @@ -20,36 +20,27 @@ * also available at http://www.gnu.org/copyleft/gpl.html. */ -#include <qpid/agent/ManagementAgent.h> -#include <qpid/management/Manageable.h> -#include <qpid/management/ManagementObject.h> -#include <qpid/agent/ManagementAgent.h> +#include <set> +#include <string> -#include "qmf/com/redhat/matahari/Processors.h" +#include "processorslistener.h" -using namespace qpid::management; using namespace std; -using qpid::management::Manageable; - -class ProcessorsAgent : public Manageable +class Processors { private: - qmf::com::redhat::matahari::Processors* management_object; + set<ProcessorsListener*> _listeners; public: - ProcessorsAgent() {} - virtual ~ProcessorsAgent() {} - - ManagementObject* GetManagementObject(void) const { return management_object; } + void addProcessorsListener(ProcessorsListener* listener); + void removeProcessorsListener(ProcessorsListener* listener); - void setup(ManagementAgent* agent, Manageable* parent); + void update(); - void update(void) const; - - private: - // agent methods - void update_load_averages(void) const; + string getModel() const; + unsigned int getNumberOfCores() const; + float getLoadAverage() const; }; #endif diff --git a/src/processorslistener.h b/src/processorslistener.h new file mode 100644 index 0000000..d6818c8 --- /dev/null +++ b/src/processorslistener.h @@ -0,0 +1,29 @@ +#ifndef __PROCESSORSLISTENER_H +#define __PROCESSORSLISTENER_H + +/* processorslistener.h - Copyright (C) 2009 Red Hat, Inc. + * Written by Darryl Pierce <dpierce at redhat.com>. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +class ProcessorsListener +{ + public: + virtual void updated() = 0; +}; + +#endif diff --git a/src/qmf/hostagent.cpp b/src/qmf/hostagent.cpp new file mode 100644 index 0000000..9807f65 --- /dev/null +++ b/src/qmf/hostagent.cpp @@ -0,0 +1,68 @@ +/* hostagent.cpp - Copyright (C) 2009 Red Hat, Inc. + * Written by Arjun Roy <arroy at redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +#include "hostagent.h" +#include <qpid/agent/ManagementAgent.h> + +namespace _qmf = qmf::com::redhat::matahari; + +HostAgent::HostAgent(Host& host) + :_host(host) +{ + this->_host.addHostListener(this); +} + +HostAgent::~HostAgent() +{ +} + +void +HostAgent::setup(ManagementAgent* agent) +{ + _management_object = new _qmf::Host(agent, this); + agent->addObject(_management_object); + + _management_object->set_uuid(_host.getUUID()); + _management_object->set_hostname(_host.getHostname()); + _management_object->set_hypervisor(_host.getHypervisor()); + _management_object->set_arch(_host.getArchitecture()); + _management_object->set_memory(_host.getMemory()); + _management_object->set_beeping(_host.isBeeping()); +} + +Manageable::status_t +HostAgent::ManagementMethod(uint32_t method, Args& arguments, string& text) +{ + switch(method) + { + case _qmf::Host::METHOD_SHUTDOWN: + _host.shutdown(); + return Manageable::STATUS_OK; + case _qmf::Host::METHOD_REBOOT: + _host.reboot(); + return Manageable::STATUS_OK; + } + + return Manageable::STATUS_NOT_IMPLEMENTED; +} + +void +HostAgent::heartbeat(unsigned long timestamp) +{ +} diff --git a/src/qmf/hostagent.h b/src/qmf/hostagent.h new file mode 100644 index 0000000..6d2f2a0 --- /dev/null +++ b/src/qmf/hostagent.h @@ -0,0 +1,51 @@ +#ifndef __HOSTAGENT_H +#define __HOSTAGENT_H + +/* hostagent.h - Copyright (C) 2009 Red Hat, Inc. + * Written by Arjun Roy <arroy at redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +#include <qpid/management/Manageable.h> +#include <string> + +#include "host.h" +#include "hostlistener.h" + +#include "qmf/com/redhat/matahari/Host.h" + +using namespace qpid::management; +using namespace std; + +class HostAgent : public Manageable, public HostListener +{ + private: + qmf::com::redhat::matahari::Host* _management_object; + Host& _host; + + public: + HostAgent(Host& host); + virtual ~HostAgent(); + + void setup(ManagementAgent* agent); + ManagementObject* GetManagementObject() const { return _management_object; } + status_t ManagementMethod(uint32_t method, Args& arguments, string& text); + + virtual void heartbeat(unsigned long timestamp); +}; + +#endif diff --git a/src/qmf/processorsagent.cpp b/src/qmf/processorsagent.cpp new file mode 100644 index 0000000..c1703de --- /dev/null +++ b/src/qmf/processorsagent.cpp @@ -0,0 +1,49 @@ +/* processorsagent.cpp - Copyright (C) 2009 Red Hat, Inc. + * Written by Arjun Roy <arroy at redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +#include "processorsagent.h" +#include <qpid/agent/ManagementAgent.h> + +namespace _qmf = qmf::com::redhat::matahari; + +ProcessorsAgent::ProcessorsAgent(Processors& processors) + :_processors(processors) +{ + processors.addProcessorsListener(this); +} + +ProcessorsAgent::~ProcessorsAgent() +{ +} + +void +ProcessorsAgent::setup(ManagementAgent* agent, HostAgent* parent) +{ + _management_object = new _qmf::Processors(agent, this, parent); + agent->addObject(_management_object); + + _management_object->set_model(this->_processors.getModel()); + _management_object->set_cores(this->_processors.getNumberOfCores()); +} + +void +ProcessorsAgent::updated() +{ + _management_object->set_load_average(this->_processors.getLoadAverage()); +} diff --git a/src/qmf/processorsagent.h b/src/qmf/processorsagent.h new file mode 100644 index 0000000..1d814d4 --- /dev/null +++ b/src/qmf/processorsagent.h @@ -0,0 +1,50 @@ +#ifndef __PROCESSORSAGENT_H +#define __PROCESSORSAGENT_H + +/* processoragent.h - Copyright (C) 2010 Red Hat, Inc. + * Written by Darryl L. Pierce <dpierce at redhat.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. A copy of the GNU General Public License is + * also available at http://www.gnu.org/copyleft/gpl.html. + */ + +#include <qpid/management/Manageable.h> +#include <qpid/management/ManagementObject.h> + +#include "processors.h" +#include "processorslistener.h" +#include "qmf/com/redhat/matahari/Processors.h" +#include "qmf/hostagent.h" + +using namespace qpid::management; + +class ProcessorsAgent : public Manageable, public ProcessorsListener +{ + private: + qmf::com::redhat::matahari::Processors* _management_object; + + Processors& _processors; + + public: + ProcessorsAgent(Processors& processors); + virtual ~ProcessorsAgent(); + + void setup(ManagementAgent* agent, HostAgent* parent); + ManagementObject* GetManagementObject(void) const { return _management_object; } + + virtual void updated(); +}; + +#endif -- 1.6.6.1
Darryl L. Pierce
2010-May-21 18:24 UTC
[Ovirt-devel] [Matahari] [PATCH matahari] Moving QMF functionality into a transport layer.
On Fri, May 21, 2010 at 07:56:15PM +0200, Andrew Beekhof wrote:> ACK. > Further modifications might become themselves when we try to merge the > virtio version, but this is a good start and I don't see any reason to > delay merging it.Thank you. This is now pushed into the repo. -- Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc. Delivering value year after year. Red Hat ranks #1 in value among software vendors. http://www.redhat.com/promo/vendor/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: not available URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20100521/39a0e0a7/attachment.sig>