Author: justi9
Date: 2010-05-19 17:31:07 -0400 (Wed, 19 May 2010)
New Revision: 3978
Added:
mgmt/newdata/cumin/bin/cumin-smoke-test
Modified:
mgmt/newdata/cumin/python/cumin/model.py
mgmt/newdata/cumin/python/cumin/session.py
Log:
Add a call_method to CuminSession; add a test program
Added: mgmt/newdata/cumin/bin/cumin-smoke-test
===================================================================
--- mgmt/newdata/cumin/bin/cumin-smoke-test (rev 0)
+++ mgmt/newdata/cumin/bin/cumin-smoke-test 2010-05-19 21:31:07 UTC (rev 3978)
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+import os
+import sys
+
+home = os.environ.get("CUMIN_HOME",
os.path.normpath("/usr/share/cumin"))
+sys.path.append(os.path.join(home, "python"))
+
+from cumin import *
+from cumin.config import *
+from cumin.util import *
+
+def main():
+ config = CuminConfig()
+ values = config.parse()
+
+ parser = CuminOptionParser(values.web)
+
+ parser.add_option("--host", default=values.web.host)
+ parser.add_option("--port", default=values.web.port)
+
+ opts, args = parser.parse_args()
+
+ setup_logging(opts)
+
+ cumin = Cumin(config.home, opts.broker, opts.database,
+ opts.host, opts.port)
+
+ cumin.user = values.web.user
+
+ cumin.check()
+ cumin.init()
+
+ if opts.init_only:
+ return
+
+ cumin.start()
+
+ sleep(5)
+
+ conn = cumin.database.get_connection()
+ cursor = conn.cursor()
+
+ cls = cumin.model.org_apache_qpid_broker.Broker
+ broker = cls.get_object(cursor)
+
+ def completion(x, y):
+ print "XXX", x, y
+
+ cumin.session.call_method(completion, broker, "echo", (1,
"yeah"))
+
+ try:
+ while True:
+ # print_threads()
+
+ sleep(5)
+ finally:
+ cumin.stop()
+
+if __name__ == "__main__":
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass
Property changes on: mgmt/newdata/cumin/bin/cumin-smoke-test
___________________________________________________________________
Name: svn:executable
+ *
Modified: mgmt/newdata/cumin/python/cumin/model.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/model.py 2010-05-19 18:35:46 UTC (rev 3977)
+++ mgmt/newdata/cumin/python/cumin/model.py 2010-05-19 21:31:07 UTC (rev 3978)
@@ -25,11 +25,6 @@
self.app = app
self.model_dir = model_dir
- self.lock = Lock()
-
- # int seq => callable
- self.outstanding_method_calls = dict()
-
self.tasks = list()
self.task_invocations = list()
Modified: mgmt/newdata/cumin/python/cumin/session.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/session.py 2010-05-19 18:35:46 UTC (rev 3977)
+++ mgmt/newdata/cumin/python/cumin/session.py 2010-05-19 21:31:07 UTC (rev 3978)
@@ -1,7 +1,7 @@
from model import *
from util import *
-from qmf.console import Console, Session
+from qmf.console import Console, Session, ClassKey, ObjectId
log = logging.getLogger("cumin.session")
@@ -13,6 +13,11 @@
self.qmf_session = None
self.qmf_brokers = list()
+ # int seq => callable
+ self.outstanding_method_calls = dict()
+
+ self.lock = Lock()
+
def add_broker(self, uri):
log.info("Adding QMF broker at %s", uri)
@@ -36,7 +41,7 @@
assert self.qmf_session is None
- self.qmf_session = Session(CuminConsole(self.app.model),
+ self.qmf_session = Session(CuminConsole(self),
manageConnections=True,
rcvObjects=False)
@@ -48,12 +53,34 @@
for qmf_broker in self.qmf_brokers:
self.qmf_session.delBroker(qmf_broker)
+ def call_method(self, callback, obj, name, args):
+ assert isinstance(obj, RosemaryObject)
+
+ oid_args = {"_agent_name": obj._qmf_agent_id,
+ "_object_name": obj._qmf_object_id}
+
+ broker = self.qmf_brokers[0]
+ ck = ClassKey(obj._qmf_class_key)
+ oid = ObjectId(oid_args)
+
+ self.lock.acquire()
+ try:
+ seq = self.qmf_session._sendMethodRequest \
+ (broker, ck, oid, name, args)
+
+ if seq is not None:
+ self.outstanding_method_calls[seq] = callback
+
+ return seq
+ finally:
+ self.lock.release()
+
def __repr__(self):
return "%s(%s)" % (self.__class__.__name__, self.broker_uri)
class CuminConsole(Console):
- def __init__(self, model):
- self.model = model
+ def __init__(self, session):
+ self.session = session
def newAgent(self, qmf_agent):
log.info("New agent %s", qmf_agent)
@@ -66,9 +93,9 @@
seq, broker)
log.debug("Response: %s", response)
- self.model.lock.acquire()
+ self.session.lock.acquire()
try:
- callback = self.model.outstanding_method_calls.pop(seq)
+ callback = self.session.outstanding_method_calls.pop(seq)
callback(response.text, response.outArgs)
finally:
- self.model.lock.release()
+ self.session.lock.release()