[Ovirt-devel] [PATCH matahari] Moves the CPU properties into the Host API space.

Darryl L. Pierce dpierce at redhat.com
Mon May 24 12:33:14 UTC 2010


There was no valid reason to keep this set of APIs in their own agent
and class, so those have been eliminated.

A new HostListener method, HostListener::updated(), was added. It is via
this method that the Host will notify all transports that the load
average statistic is updated on the host.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 src/Makefile.am             |   11 +------
 src/host.cpp                |   33 +++++++++++++++++-----
 src/host.h                  |   10 ++++---
 src/hostlistener.h          |    1 +
 src/linux_platform.cpp      |   10 +++---
 src/linux_platform.h        |    2 +-
 src/main.cpp                |    3 --
 src/platform.h              |   18 +++++-------
 src/processors.cpp          |   63 -------------------------------------------
 src/processors.h            |   46 -------------------------------
 src/processorslistener.h    |   29 -------------------
 src/qmf/hostagent.cpp       |    9 ++++++
 src/qmf/hostagent.h         |    1 +
 src/qmf/processorsagent.cpp |   49 ---------------------------------
 src/qmf/processorsagent.h   |   50 ----------------------------------
 src/schema.xml              |   16 +++++------
 16 files changed, 64 insertions(+), 287 deletions(-)
 delete mode 100644 src/processors.cpp
 delete mode 100644 src/processors.h
 delete mode 100644 src/processorslistener.h
 delete mode 100644 src/qmf/processorsagent.cpp
 delete mode 100644 src/qmf/processorsagent.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 498ee72..7daea07 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,9 +9,7 @@ generated_file_list = \
 	qmf/com/redhat/matahari/NetworkDevice.cpp \
 	qmf/com/redhat/matahari/NetworkDevice.h \
 	qmf/com/redhat/matahari/Package.cpp \
-	qmf/com/redhat/matahari/Package.h \
-	qmf/com/redhat/matahari/Processors.cpp \
-	qmf/com/redhat/matahari/Processors.h
+	qmf/com/redhat/matahari/Package.h
 
 nodist_matahari_SOURCES = $(generated_file_list) $(first)
 
@@ -26,13 +24,8 @@ matahari_SOURCES = \
 	networkdevice.h \
 	platform.cpp \
 	platform.h \
-	processors.cpp \
-	processors.h \
-	processorslistener.h \
 	qmf/hostagent.cpp \
-	qmf/hostagent.h \
-	qmf/processorsagent.cpp \
-	qmf/processorsagent.h
+	qmf/hostagent.h
 
 $(generated_file_list): $(generated_file_list)
 
diff --git a/src/host.cpp b/src/host.cpp
index 29b84ec..6d9a1fe 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -99,14 +99,19 @@ Host::setup(ManagementAgent* agent, HostAgent* hostAgent)
 void
 Host::update()
 {
-  _processors.update();
-
   for(vector<NetworkDeviceAgent>::iterator iter = _networkdevices.begin();
       iter != _networkdevices.end();
       iter++)
     {
       iter->update();
     }
+
+  for(set<HostListener*>::iterator iter = _listeners.begin();
+      iter != _listeners.end();
+      iter++)
+    {
+      (*iter)->updated();
+    }
 }
 
 void
@@ -121,12 +126,6 @@ Host::removeHostListener(HostListener* listener)
   _listeners.erase(listener);
 }
 
-Processors&
-Host::getProcessors()
-{
-  return _processors;
-}
-
 string
 Host:: getUUID() const
 {
@@ -163,6 +162,24 @@ Host::isBeeping() const
   return _beeping;
 }
 
+string
+Host::getCPUModel() const
+{
+  return Platform::instance()->getCPUModel();
+}
+
+unsigned int
+Host::getNumberOfCPUCores() const
+{
+  return Platform::instance()->getNumberOfCPUCores();
+}
+
+double
+Host::getLoadAverage() const
+{
+  return Platform::instance()->getLoadAverage();
+}
+
 void
 Host::identify(const int iterations)
 {
diff --git a/src/host.h b/src/host.h
index bcb8c12..f21c86c 100644
--- a/src/host.h
+++ b/src/host.h
@@ -24,7 +24,6 @@
 #include <set>
 
 #include "hostlistener.h"
-#include "processors.h"
 #include "networkdevice.h"
 
 using namespace std;
@@ -42,7 +41,6 @@ class Host
   unsigned int    _memory;
   bool            _beeping;
 
-  Processors                 _processors;
   vector<NetworkDeviceAgent> _networkdevices;
   set<HostListener*>         _listeners;
 
@@ -55,14 +53,18 @@ class Host
   void addHostListener(HostListener*);
   void removeHostListener(HostListener*);
 
-  Processors& getProcessors();
-
+  // general host properties
   string getUUID() const;
   string getHostname() const;
   string getHypervisor() const;
   string getArchitecture() const;
   unsigned int getMemory() const;
 
+  // CPU properties
+  string       getCPUModel() const;
+  unsigned int getNumberOfCPUCores() const;
+  double       getLoadAverage() const;
+
   bool isBeeping() const;
   void identify(const int iterations);
   void shutdown();
diff --git a/src/hostlistener.h b/src/hostlistener.h
index 298e51d..0d09594 100644
--- a/src/hostlistener.h
+++ b/src/hostlistener.h
@@ -27,6 +27,7 @@
 class HostListener
 {
  public:
+  virtual void updated() = 0;
   virtual void heartbeat(unsigned long timestamp) = 0;
 };
 
diff --git a/src/linux_platform.cpp b/src/linux_platform.cpp
index fbcfdb9..b05a327 100644
--- a/src/linux_platform.cpp
+++ b/src/linux_platform.cpp
@@ -36,7 +36,7 @@ extern "C" {
 
 LinuxPlatform::LinuxPlatform()
 {
-  int core_count = 0;
+  int cpu_count = 0;
   string model = "unknown";
 
   struct udev* udev = udev_new();
@@ -50,9 +50,9 @@ LinuxPlatform::LinuxPlatform()
 
       udev_list_entry_foreach(entry, entries)
         {
-          core_count++;
+          cpu_count++;
         }
-      set_number_of_cores(core_count);
+      setNumberOfCPUCores(cpu_count);
     }
 
   udev_enumerate_unref(enumerator);
@@ -100,7 +100,7 @@ LinuxPlatform::LinuxPlatform()
                 }
               else
                 {
-                  if(name == "model name") set_processor_model(value);
+                  if(name == "model name") setCPUModel(value);
                 }
             }
         }
@@ -109,7 +109,7 @@ LinuxPlatform::LinuxPlatform()
 }
 
 double
-LinuxPlatform::get_load_average() const
+LinuxPlatform::getLoadAverage() const
 {
   double load_average;
   ifstream input;
diff --git a/src/linux_platform.h b/src/linux_platform.h
index 095bc08..a66cbe4 100644
--- a/src/linux_platform.h
+++ b/src/linux_platform.h
@@ -32,7 +32,7 @@ class LinuxPlatform : public Platform
   LinuxPlatform();
   virtual ~LinuxPlatform() {}
 
-  virtual double get_load_average() const;
+  virtual double getLoadAverage() const;
   virtual vector<NetworkDeviceAgent> get_network_devices() const;
 };
 
diff --git a/src/main.cpp b/src/main.cpp
index f45353a..3ab4147 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,7 +34,6 @@
 #include "host.h"
 
 #include "qmf/hostagent.h"
-#include "qmf/processorsagent.h"
 
 #include "qmf/com/redhat/matahari/Package.h"
 
@@ -82,7 +81,6 @@ main(int argc, char **argv)
     ManagementAgent *agent;
     Host host;
     HostAgent hostAgent(host);
-    ProcessorsAgent processorsAgent(host.getProcessors());;
 
     struct option opt[] = {
         {"help", no_argument, NULL, 'h'},
@@ -185,7 +183,6 @@ main(int argc, char **argv)
 
     // Get the info and post it to the broker
     hostAgent.setup(agent);
-    processorsAgent.setup(agent, &hostAgent);
 
     while(1)
       {
diff --git a/src/platform.h b/src/platform.h
index 54fbe37..ba70378 100644
--- a/src/platform.h
+++ b/src/platform.h
@@ -37,28 +37,24 @@ class Platform
  private:
   static Platform* _instance;
 
-  string processor_model;
-  unsigned int number_of_cores;
+  string       _cpu_model;
+  unsigned int _cpu_cores;
 
  protected:
   Platform() {}
   virtual~ Platform() {}
 
-  void set_processor_model(const string model) { processor_model = model; }
-  void set_number_of_cores(const int number) { number_of_cores = number; }
+  void setCPUModel(const string model)      { _cpu_model = model; }
+  void setNumberOfCPUCores(const int cores) { _cpu_cores = cores; }
 
  public:
   // the singleton instance
   static Platform* instance();
 
-  // returns text describing the processor model.
-  string get_processor_model() const { return processor_model; }
+  string       getCPUModel() const         { return _cpu_model; }
+  unsigned int getNumberOfCPUCores() const { return _cpu_cores; }
 
-  // returns the number of cores in the processor.
-  int get_number_of_cores() const { return number_of_cores; }
-
-  // returns the load average for the platform
-  virtual double get_load_average() const = 0;
+  virtual double getLoadAverage() const = 0;
 
   // returns the list of network devices for this platform
   virtual vector<NetworkDeviceAgent> get_network_devices() const = 0;
diff --git a/src/processors.cpp b/src/processors.cpp
deleted file mode 100644
index 1850aba..0000000
--- a/src/processors.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/* processor.cpp - 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 "processors.h"
-#include "platform.h"
-
-void
-Processors::addProcessorsListener(ProcessorsListener* listener)
-{
-  _listeners.insert(listener);
-}
-
-void
-Processors::removeProcessorsListener(ProcessorsListener* listener)
-{
-  _listeners.erase(listener);
-}
-
-void
-Processors::update()
-{
-  for(set<ProcessorsListener*>::iterator iter = _listeners.begin();
-      iter != _listeners.end();
-      iter++)
-    {
-      (*iter)->updated();
-    }
-}
-
-string
-Processors::getModel() const
-{
-  return Platform::instance()->get_processor_model();
-}
-
-
-unsigned int
-Processors::getNumberOfCores() const
-{
-  return Platform::instance()->get_number_of_cores();
-}
-
-float
-Processors::getLoadAverage() const
-{
-  return Platform::instance()->get_load_average();
-}
diff --git a/src/processors.h b/src/processors.h
deleted file mode 100644
index e69a6ee..0000000
--- a/src/processors.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef __PROCESSORS_H
-#define __PROCESSORS_H
-
-/* processor.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 <set>
-#include <string>
-
-#include "processorslistener.h"
-
-using namespace std;
-
-class Processors
-{
- private:
-  set<ProcessorsListener*> _listeners;
-
- public:
-  void addProcessorsListener(ProcessorsListener* listener);
-  void removeProcessorsListener(ProcessorsListener* listener);
-
-  void update();
-
-  string getModel() const;
-  unsigned int getNumberOfCores() const;
-  float getLoadAverage() const;
-};
-
-#endif
diff --git a/src/processorslistener.h b/src/processorslistener.h
deleted file mode 100644
index d6818c8..0000000
--- a/src/processorslistener.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#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
index 9807f65..1baac73 100644
--- a/src/qmf/hostagent.cpp
+++ b/src/qmf/hostagent.cpp
@@ -44,6 +44,9 @@ HostAgent::setup(ManagementAgent* agent)
   _management_object->set_arch(_host.getArchitecture());
   _management_object->set_memory(_host.getMemory());
   _management_object->set_beeping(_host.isBeeping());
+
+  _management_object->set_cpu_model(_host.getCPUModel());
+  _management_object->set_cpu_cores(_host.getNumberOfCPUCores());
 }
 
 Manageable::status_t
@@ -63,6 +66,12 @@ HostAgent::ManagementMethod(uint32_t method, Args& arguments, string& text)
 }
 
 void
+HostAgent::updated()
+{
+  _management_object->set_load_average(_host.getLoadAverage());
+}
+
+void
 HostAgent::heartbeat(unsigned long timestamp)
 {
 }
diff --git a/src/qmf/hostagent.h b/src/qmf/hostagent.h
index 6d2f2a0..9d01f2c 100644
--- a/src/qmf/hostagent.h
+++ b/src/qmf/hostagent.h
@@ -45,6 +45,7 @@ class HostAgent : public Manageable, public HostListener
   ManagementObject* GetManagementObject() const { return _management_object; }
   status_t ManagementMethod(uint32_t method, Args& arguments, string& text);
 
+  virtual void updated();
   virtual void heartbeat(unsigned long timestamp);
 };
 
diff --git a/src/qmf/processorsagent.cpp b/src/qmf/processorsagent.cpp
deleted file mode 100644
index c1703de..0000000
--- a/src/qmf/processorsagent.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/* 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
deleted file mode 100644
index 1d814d4..0000000
--- a/src/qmf/processorsagent.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#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
diff --git a/src/schema.xml b/src/schema.xml
index 206e39b..fd83ac1 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -2,6 +2,7 @@
 
   <class name="Host">
 
+    <!-- general properties -->
     <property name="uuid"       type="sstr"  access="RO" desc="Host UUID" index="y"/>
     <property name="hostname"   type="sstr"  access="RO" desc="Hostname"/>
     <property name="memory"     type="int64" access="RO" desc="Amount of primary memory for host (kb)" unit="kb"/>
@@ -9,20 +10,17 @@
     <property name="arch"       type="sstr"  access="RO" desc="Architecture of host"/>
     <property name="beeping"    type="bool"  access="RW" desc="speaker beep loop active? (used to identify host)"/>
 
+    <!-- CPU properties -->
+    <property  name="cpu_model"    type="lstr"   access="RO" desc="The process model description." />
+    <property  name="cpu_cores"    type="uint8"  access="RO" desc="The number of processor cores." />
+    <statistic name="load_average" type="double"             desc="The current processing load average." />
+
+    <!-- APIs -->
     <method name="shutdown" desc="Shutdown node" />
     <method name="reboot" desc="Reboot node" />
 
   </class>
 
-  <!-- The processor for the node. -->
-  <class name="Processors">
-    <property name="host"   type="objId" access="RC" desc="The host machine." index="y" references="Host" parentRef="y" />
-    <property name="model"  type="lstr"  access="RO" desc="The processor label." />
-    <property name="cores"  type="int8"  access="RO" desc="The number of cores." />
-
-    <statistic name="load_average" type="float" desc="The processing load average." />
-  </class>
-
   <!-- represents a physical network device -->
   <class name="NetworkDevice">
     <property name="host"        type="objId" access="RC" desc="The host machine." index="y" references="Host" parentRef="y" />
-- 
1.6.6.1




More information about the ovirt-devel mailing list