summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Sommerseth <dazo@users.sourceforge.net>2010-08-27 20:37:09 +0200
committerDavid Sommerseth <dazo@users.sourceforge.net>2010-08-27 20:37:09 +0200
commit9c625c5a1945428f5b33202ab9179c9052cbf116 (patch)
tree9d10dc648dda2b8a3956abacee21c375fce30a06
parentf3c241d2d47e16bb9695d2dd4898c6f1da4e3fb6 (diff)
downloadrteval-9c625c5a1945428f5b33202ab9179c9052cbf116.tar.gz
rteval-9c625c5a1945428f5b33202ab9179c9052cbf116.tar.xz
rteval-9c625c5a1945428f5b33202ab9179c9052cbf116.zip
Implemented simple XML-RPC call to check the database status
This can be used to check if the XML-RPC service have access to the database Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
-rw-r--r--rteval/rtevalclient.py3
-rw-r--r--server/rtevaldb.py24
-rw-r--r--server/xmlrpc_API1.py4
3 files changed, 31 insertions, 0 deletions
diff --git a/rteval/rtevalclient.py b/rteval/rtevalclient.py
index b8bf8cd..190958b 100644
--- a/rteval/rtevalclient.py
+++ b/rteval/rtevalclient.py
@@ -46,6 +46,9 @@ class rtevalclient:
def Hello(self):
return self.srv.Hello(self.hostname)
+ def DatabaseStatus(self):
+ return self.srv.DatabaseStatus()
+
def SendReport(self, xmldoc):
if xmldoc.type != 'document_xml':
raise Exception, "Input is not XML document"
diff --git a/server/rtevaldb.py b/server/rtevaldb.py
index d8453c9..7a0ccaf 100644
--- a/server/rtevaldb.py
+++ b/server/rtevaldb.py
@@ -48,3 +48,27 @@ def register_submission(config, clientid, filename, debug=False, noaction=False)
dbc.COMMIT()
return res[0]
+def database_status(config, debug=False, noaction=False):
+ dbc = Database(host=config.db_server, port=config.db_port, database=config.database,
+ user=config.db_username, password=config.db_password,
+ debug=debug, noaction=noaction)
+ if not dbc:
+ return {"status": "No connection to pgsql://%s:%s/%s" % (config.db_server,
+ config.db_port,
+ config.database)}
+
+ res = dbc.SELECT('rtevalruns',
+ ["to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS') AS server_time",
+ "max(rterid) AS last_rterid",
+ "max(submid) AS last_submid"]
+ )
+ if len(res) != 3:
+ return {"status": "Could not query database pgsql://%s:%s/%s" % (config.db_server,
+ config.db_port,
+ config.database)}
+ return {"status": "OK",
+ "server_time": res['records'][0][0],
+ "last_rterid": res['records'][0][1],
+ "last_submid": res['records'][0][2]
+ }
+
diff --git a/server/xmlrpc_API1.py b/server/xmlrpc_API1.py
index e874b5c..71e23d6 100644
--- a/server/xmlrpc_API1.py
+++ b/server/xmlrpc_API1.py
@@ -110,3 +110,7 @@ class XMLRPC_API1():
return {"greeting": "Hello %s" % clientid,
"server": platform.node(),
"APIversion": self.apiversion}
+
+
+ def DatabaseStatus(self):
+ return rtevaldb.database_status(self.config)