had not seen directly but there was still somewhere in scheduler &
satellitelink were pyro version was tested against..

I guess it's even better with this generated patchs (that includes previous)
that defines a getProxy method in pyro_wrapper and makes use of it.

(master)g...@greg-laptop:~/Documents/Projets/shinken$ git format-patch
c715cf0c2fe87d20745b6f821877fa7ea7f102a4
0001-pyro-make-the-test-for-pyro-version-only-1-time-inst.patch
0002-use-getProxy-in-pyro_wrapper-instead-of-testing.patch
0003-pyro_wrapper-was-misused-also-in-satellitelink.patch
(master)g...@greg-laptop:~/Documents/Projets/shinken$

stat diff:

(master)g...@greg-laptop:~/Documents/Projets/shinken$ git diff --stat
 c715cf0c2fe87d20745b6f821877fa7ea7f102a4
 shinken/pyro_wrapper.py  |  109
++++++++++++++++++++--------------------------
 shinken/satellitelink.py |   29 +++---------
 shinken/scheduler.py     |   12 +----
 3 files changed, 57 insertions(+), 93 deletions(-)
(master)g...@greg-laptop:~/Documents/Projets/shinken$


regards,

greg.



Le 26 décembre 2010 15:23, Grégory Starck <g.sta...@gmail.com> a écrit :

> Hi devel guys,
>
> after long time without having an eye in the code, I just see pyro_wrapper
> define methods that for every call are testing for the pyro version and are
> acting correspondingly.
>
> Here attached a small patch against latest commit I got by pull
> (c715cf0c2fe87d20745b6f821877fa7ea7f102a4).
>
> The patch makes now the different methods be defined in the try: Except
> part ; and no more multiple "if pyro_version==3: else:  "
>
> What do you think ?
>
> regards,
>
> Greg.
>
>
From 4ce5e41be028215b137c4e4e75f8b5d17eca28b6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Starck?= <g.sta...@gmail.com>
Date: Sun, 26 Dec 2010 15:38:50 +0100
Subject: [PATCH 2/2] use getProxy in pyro_wrapper instead of testing

---
 shinken/pyro_wrapper.py |    7 +++++++
 shinken/scheduler.py    |   12 ++----------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/shinken/pyro_wrapper.py b/shinken/pyro_wrapper.py
index c866df0..7b9c034 100644
--- a/shinken/pyro_wrapper.py
+++ b/shinken/pyro_wrapper.py
@@ -65,6 +65,9 @@ try:
     def set_timeout(con, timeout):
         con._setTimeout(timeout)
 
+    def getProxy(uri):
+        return Pyro.core.getProxyForURI(self.uri)
+
 
 except AttributeError:
     print "Using Pyro", Pyro.constants.VERSION
@@ -111,3 +114,7 @@ except AttributeError:
     def set_timeout(con, timeout):
         con._pyroTimeout = timeout
 
+    def getProxy(uri):
+        return Pyro.core.Proxy(self.uri)
+
+
diff --git a/shinken/scheduler.py b/shinken/scheduler.py
index b123849..50ca0d4 100644
--- a/shinken/scheduler.py
+++ b/shinken/scheduler.py
@@ -815,11 +815,7 @@ class Scheduler:
         self.t_each_loop = time.time() #use to track system time change
 
         while self.must_run :
-            #Ok, still a difference between 3 and 4 ...
-            if shinken.pyro_wrapper.pyro_version == 3:
-                socks = self.daemon.getServerSockets()
-            else:
-                socks = self.daemon.sockets()
+            socks = shinken.pyro_wrapper.get_sockets(self.daemon)
             t_begin = time.time()
             #socks.append(self.fifo)
             # 'foreign' event loop
@@ -827,11 +823,7 @@ class Scheduler:
             if ins != []:
                 for s in socks:
                     if s in ins:
-                        #Yes, even here there is a difference :)
-                        if shinken.pyro_wrapper.pyro_version == 3:
-                            self.daemon.handleRequests()
-                        else:
-                            self.daemon.handleRequests([s])
+                        shinken.pyro_wrapper.handleRequests(self.daemon, s)
                         t_after = time.time()
                         diff = t_after-t_begin
                         timeout = timeout - diff
-- 
1.7.1

From c3cf7204a782e46d90d6109affeb619eeea9dfa6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Starck?= <g.sta...@gmail.com>
Date: Sun, 26 Dec 2010 15:51:35 +0100
Subject: [PATCH 3/3] pyro_wrapper: was misused also in satellitelink

---
 shinken/satellitelink.py |   29 +++++++----------------------
 1 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/shinken/satellitelink.py b/shinken/satellitelink.py
index 9ea3403..44da0d4 100644
--- a/shinken/satellitelink.py
+++ b/shinken/satellitelink.py
@@ -68,16 +68,9 @@ class SatelliteLink(Item):
 
 
     def create_connexion(self):
-        #URI are differents between 3 and 4
-        if shinken.pyro_wrapper.pyro_version == 3:
-            self.uri = 'PYROLOC://'+self.address+":"+str(self.port)+"/ForArbiter"
-            self.con = Pyro.core.getProxyForURI(self.uri)
-            #Ok, set timeout to 3 sec (ping timeout)
-            self.con._setTimeout(self.timeout)
-        else:
-            self.uri = 'PYRO:ForArbiter@'+self.address+":"+str(self.port)
-            self.con = Pyro.core.Proxy(self.uri)
-            self.con._pyroTimeout = self.timeout
+        self.uri = shinken.pyro_wrapper.create_uri(self.address, self.port, "/ForArbiter")
+        self.con = shinken.pyro_wrapper.getProxy(self.uri)
+        shinken.pyro_wrapper.set_timeout(self.con, 5)
 
 
     def put_conf(self, conf):
@@ -86,18 +79,10 @@ class SatelliteLink(Item):
         #print "Connexion is OK, now we put conf", conf
         #print "Try to put conf:", conf
         try:
-            #Still fun with pyro 3 and 4...
-            if shinken.pyro_wrapper.pyro_version == 3:
-                #Data timeout is far longer than timeout (ping one)
-                self.con._setTimeout(self.data_timeout)
-                self.con.put_conf(conf)
-                self.con._setTimeout(self.timeout)
-                return True
-            else:
-                self.con._pyroTimeout = self.data_timeout
-                self.con.put_conf(conf)
-                self.con._pyroTimeout = self.timeout
-                return True
+            shinken.pyro_wrapper.set_timeout(self.con, 120)
+            self.con.put_conf(conf)
+            shinken.pyro_wrapper.set_timeout(self.con, 5)
+            return True
         except Pyro.errors.URIError , exp:
             self.con = None
             return False
-- 
1.7.1

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Shinken-devel mailing list
Shinken-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/shinken-devel

Reply via email to