[rhmessaging-commits] rhmessaging commits: r4038 - in mgmt/newdata/cumin/python/cumin: grid and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Fri Jun 18 10:56:13 EDT 2010


Author: eallen
Date: 2010-06-18 10:56:12 -0400 (Fri, 18 Jun 2010)
New Revision: 4038

Modified:
   mgmt/newdata/cumin/python/cumin/grid/negotiator.py
   mgmt/newdata/cumin/python/cumin/grid/negotiator.strings
   mgmt/newdata/cumin/python/cumin/model.py
Log:
Changes for new negotiator qmf calls 

Modified: mgmt/newdata/cumin/python/cumin/grid/negotiator.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/negotiator.py	2010-06-18 14:53:41 UTC (rev 4037)
+++ mgmt/newdata/cumin/python/cumin/grid/negotiator.py	2010-06-18 14:56:12 UTC (rev 4038)
@@ -5,7 +5,7 @@
 from wooly.widgets import *
 
 from cumin.formats import *
-from cumin.model import FetchRawConfig, FetchRawConfigSet
+from cumin.model import FetchRawConfigSet
 from cumin.objectframe import *
 from cumin.objectselector import *
 from cumin.parameters import *
@@ -24,8 +24,8 @@
 
         super(NegotiatorFrame, self).__init__(app, name, cls)
 
-        self.start = DaemonStart(app, self, "NEGOTIATOR")
-        self.stop = DaemonStop(app, self, "NEGOTIATOR")
+        #self.start = DaemonStart(app, self, "NEGOTIATOR")
+        #self.stop = DaemonStop(app, self, "NEGOTIATOR")
 
         self.group_add = NegotiatorGroupAdd(app, self)
 
@@ -96,7 +96,7 @@
             href = "%s" % self.user_task.get_href \
                 (session, (self.negotiator.get(session), data[0]))
         else:
-            href = self.task.get_href(session, self.negotiator.get(session))
+            href = self.task.get_href(session)
         content = data[2][2] and str(data[1]) or "NOT SET"
         return fmt_link(href, content, "", "", self.fmt_hover(data[0]))
 
@@ -216,7 +216,7 @@
 
     class DynamicColumn(QmfGroupColumn):
         def render_data(self, session, data):
-            href = self.task.get_href(session, self.negotiator.get(session))
+            href = self.task.get_href(session)
             content = "%s%%" % str(round(float(data[1]) * 100.0, 2))
             return fmt_link(href, content, "", "", self.fmt_hover(data[0]))
 
@@ -273,15 +273,20 @@
 
         self.negotiator = negotiator
 
-        self.users = self.Users()
+        self.users = self.Users(app, "users")
+        self.add_attribute(self.users)
 
     def get_group_names(self, session):
         groups = self.groups.get(session)
         if len(groups) == 0:
             negotiator = self.negotiator.get(session)
-
-            action = NewQmfCall(self.app, {'Value': None})
-            results = action.qmf_call(negotiator, "GetRawConfig", ("GROUP_NAMES",))
+            default =  {'Value': None}
+            action = QmfCall(self.app, default=default, timeout=10)
+            results = action.execute(negotiator, "GetRawConfig", "GROUP_NAMES")
+            # TODO: remove this temp workaround
+            # XXX temp work around for qmf call
+            if results.error:
+                results.data = {'Value': 'msg, grid, mgmt, rt'}
             groups = results.data
             try:
                 groups = self.split_group_names(groups['Value'])
@@ -310,7 +315,7 @@
                 groups = self.get_group_names(session)
             negotiator = self.negotiator.get(session)
             action = FetchRawConfigSet(self.app)
-            raw_configs = action.execute(negotiator, groups, config, timeout=15)
+            raw_configs = action.execute(negotiator, groups, config)
 
             for group in sorted(raw_configs):
                 res = raw_configs[group]
@@ -349,7 +354,11 @@
                                          self.autoregroup, [""])
 
     def get_users(self, session, groups):
-        return self.users.get(session, groups)
+        try:
+            users = self.users.get_users(session, groups, self.negotiator)
+        except:
+            users = dict()
+        return users
 
     def append_unclaimed_dyn_quota(self, session, quotas, force=False):
         total = 0.0
@@ -370,16 +379,18 @@
         def get_default(self, session):
             return list()
 
-    class Users(object):
-        def get(self, session, groups):
-            # XXX rewrite this for the new data
-            return dict()
-
+    class Users(Attribute):
+        def get_users(self, session, groups, negotiator):
             #returns {group: [user, user], group: [user, user], ...}
-            users = self.items.get(session)
+            users = self.get(session)
             if not users:
-                items = self.get_items(session)
-                user_names = [x[1] for x in items]
+                neg = negotiator.get(session)
+                pool = neg.Pool
+                cls = self.app.model.com_redhat_grid.Scheduler
+                scheduler = cls.get_object(session.cursor, Pool=pool)
+                cls = self.app.model.com_redhat_grid.Submitter
+                submitters = cls.get_selection(session.cursor, _schedulerRef_id=scheduler._id)
+                user_names = [x.Name for x in submitters]
                 users = dict()
                 for group in groups:
                     for user_name in user_names:
@@ -388,7 +399,7 @@
                                 users[group] = list()
                             users[group].append(user_name)
 
-                self.items.set(session, users)
+                self.set(session, users)
             return users
 
 class GroupAddForm(ObjectTaskForm):
@@ -400,15 +411,12 @@
         self.group_helper = GroupHelper(app, "groups", self.object)
         self.add_child(self.group_helper)
 
-        self.group_name = Parameter(app, "name")
-        self.add_parameter(self.group_name)
+        self.group_name = NameField(app, "name")
+        self.add_field(self.group_name)
 
     def render_title(self, session):
         return "Add Group"
 
-    def render_group_name_path(self, session):
-        return self.group_name.path
-
     def process_submit(self, session):
         negotiator = self.object.get(session)
         group_name = self.group_name.get(session)
@@ -418,7 +426,8 @@
             original_groups.append(group_name)
             new_groups = ", ".join(original_groups)
             self.task.invoke(session, negotiator, "GROUP_NAMES", new_groups)
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
+
         self.task.exit_with_redirect(session)
 
     def is_valid(self, group):
@@ -515,7 +524,7 @@
                     self.task.invoke(session, negotiator, "GROUP_PRIO_FACTOR_"+group, new_value)
                     changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
     def is_valid_factor(self, value):
@@ -561,7 +570,7 @@
                     self.task.invoke(session, negotiator, "GROUP_PRIO_FACTOR_"+user, new_value)
                     changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
 class EditDynamicQuotaForm(GroupForm):
@@ -632,7 +641,7 @@
                                  "GROUP_QUOTA_DYNAMIC_" + group, quota)
                 changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
     def check_quota(self, quota, original):
@@ -706,7 +715,7 @@
                 self.task.invoke(session, negotiator, "GROUP_QUOTA_"+group, new_value)
                 changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
 class EditRegroupForm(GroupForm):
@@ -784,7 +793,7 @@
                     self.task.invoke(session, negotiator, "GROUP_AUTOREGROUP_"+group, regroup[group])
                 changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
 class UserRegroupForm(EditRegroupForm):
@@ -819,7 +828,7 @@
                 self.task.invoke(session, negotiator, "GROUP_AUTOREGROUP_"+user, regroup[user])
                 changed = True
         if changed:
-            self.task.invoke(session, negotiator, "Reconfig", None)
+            self.task.reconfig(negotiator)
         self.task.exit_with_redirect(session)
 
 class PriorityPieChart(StatFlashChart):
@@ -883,27 +892,27 @@
         return "Set limit"
 
     def do_invoke(self, invoc, negotiator, name, max):
-        assert isinstance(negotiator, Negotiator)
+        action = SetLimit(self.app)
+        result = action.execute(negotiator, name, max)
+        if result.error:
+            invoc.exception(invod, result.error)
+        else:
+            action = QmfCall(self.app)
+            action.execute(negotiator, "Reconfig")
 
-        negotiator.SetLimit(completion, name, max)
+        invoc.end()
 
-        # XXX 
-        def completion():
-            pass
-
-        negotiator.Reconfig(completion)
-
 class NegotiatorGroupTask(ObjectTask):
     def do_exit(self, session):
         self.app.main_page.main.grid.pool.negotiator.view.show(session)
 
-    def do_invoke(self, completion, session, negotiator, group, value):
-        assert isinstance(negotiator, Negotiator)
+    def do_invoke(self, invoc, negotiator, group, value):
+        self.qmf_call(invoc, negotiator, "SetRawConfig", group, value)
 
-        if group == "Reconfig":
-            negotiator.Reconfig(completion)
-        else:
-            negotiator.SetRawConfig(completion, group, value)
+    def reconfig(self, negotiator):
+        action = QmfCall(self.app)
+        #TODO: put this back when setrawconfig is fixed
+        #action.execute(negotiator, "Reconfig")
 
 class NegotiatorGroupAdd(NegotiatorGroupTask):
     def __init__(self, app, frame):

Modified: mgmt/newdata/cumin/python/cumin/grid/negotiator.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/negotiator.strings	2010-06-18 14:53:41 UTC (rev 4037)
+++ mgmt/newdata/cumin/python/cumin/grid/negotiator.strings	2010-06-18 14:56:12 UTC (rev 4038)
@@ -8,10 +8,6 @@
 
 [NegotiatorOverview.html]
 <div id="{id}" class="CuminTable GroupTable">
-  <div class="sactions">
-    <h2>Actions:</h2>
-    {buttons}
-  </div>
   <table {class}>
     <thead><tr>{headers}</tr></thead>
     <tbody>{items}</tbody>

Modified: mgmt/newdata/cumin/python/cumin/model.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/model.py	2010-06-18 14:53:41 UTC (rev 4037)
+++ mgmt/newdata/cumin/python/cumin/model.py	2010-06-18 14:56:12 UTC (rev 4038)
@@ -1585,12 +1585,22 @@
 
         return "%s%s" % (conf, rect)
 
+class QmfException(Exception):
+    def __init__(self, value):
+        super(QmfException, self).__init__(value)
+        self.value = value
+
+    def __str__(self):
+        return repr(self.value)
+
 class QmfCall(object):
-    def __init__(self, app, default=None):
+    def __init__(self, app, default=None, timeout=5):
+        self.app = app
         self.data = default
         self.got_data = False
         self.error = False
         self.status = None
+        self.timeout = timeout
 
     def get_completion(self):
         def completion(status, data):
@@ -1599,58 +1609,41 @@
                 self.data = data
                 self.got_data = True
             else:
-                self.error = True
-
+                self.error = QmfException(status)
         return completion
 
-    def do_wait(self, timeout=5):
-        wait(self.done, timeout=timeout)
+    def do_wait(self):
+        wait(self.done, timeout=self.timeout)
         return self
 
     def done(self):
         return self.got_data or self.error
 
-class NewQmfCall(object):
-    def __init__(self, app, default=None):
-        self.app = app
-        self.data = default
-        self.got_data = False
-        self.error = False
-        self.status = None
-        self.timeout = 5
-
-    def qmf_call(self, obj, meth, *args):
-        def completion(status_code, output_args):
-            self.status = status_code
-            if (status == 0) or (status == "OK"):
-                self.data = output_args
-                self.got_data = True
-            else:
-                self.data = self.default
-                self.error = True
-
+    def execute(self, negotiator, method_name, *args):
         session = self.app.session
-        session.call_method(completion, obj, meth, *args)
-        return self.do_wait(self.timeout)
+        try:
+            session.call_method(self.get_completion(), negotiator, method_name, args)
+        except Exception, e:
+            self.error = e
 
-    def do_wait(self, timeout=5):
-        wait(self.done, timeout=timeout)
-        return self
+        results = self.do_wait()
+        if not results.got_data and not results.error:
+            results.error = QmfException("Request timed out")
 
-    def done(self):
-        return self.got_data or self.error
+        return results
 
 class QmfCallSet(object):
     def __init__(self, app):
         self.app = app
         self.calls = dict()
+        self.timeout = 5
 
     def add_call(self, key, default=None):
         call = QmfCall(self.app, default)
         self.calls[key] = call
         return call
 
-    def do_wait(self, timeout=5):
+    def do_wait(self):
         def predicate(calls):
             done = 0
             for call in calls:
@@ -1658,44 +1651,40 @@
                     done += 1
             return done == len(calls)
 
-        wait(predicate, timeout=timeout, args=self.calls)
+        wait(predicate, timeout=self.timeout, args=self.calls)
         return self.calls
 
-class FetchRawConfig(QmfCall):
-    def __init_(self, app):
-        super(FetchRawConfig, self).__init__(app)
-        self.data = {'Value': None}
-
-    def execute(self, negotiator, config_name, timeout=5):
-        negotiator.GetRawConfig(self.get_completion(), config_name, None)
-        return self.do_wait(timeout)
-
 class FetchRawConfigSet(QmfCallSet):
-    def execute(self, negotiator, groups, prepend="", timeout=5):
+    def execute(self, negotiator, groups, prepend=""):
         default = {'Value': 0}
+        session = self.app.session
         for group in groups:
             call = self.add_call(group, default)
-            negotiator.GetRawConfig(call.get_completion(), prepend+group, None)
 
-        return self.do_wait(timeout)
+            try:
+                session.call_method(call.get_completion(), negotiator, "GetRawConfig", (prepend+group,))
+            except Exception, e:
+                call.error = e
 
+        return self.do_wait()
+
 class FetchJobAd(QmfCall):
     def __init__(self, app):
         super(FetchJobAd, self).__init__(app)
         self.data = {'JobAd': {"":{"VALUE":"", "TYPE":0}}}
 
-    def execute(self, scheduler, jobId, timeout=10):
-        scheduler.GetAd(self.get_completion(), jobId, None)
-        return self.do_wait(timeout)
-
 class FetchJobOutput(QmfCall):
     def __init__(self, app):
         super(FetchJobOutput, self).__init__(app)
         self.data = {'Data': ""}
 
-    def execute(self, scheduler, jobId, file, start, end, timeout=10):
-        scheduler.Fetch(self.get_completion(), jobId, file, start, end, None)
-        return self.do_wait(timeout)
+    def execute(self, job_server, jobId, file, start, end):
+        session = self.app.session
+        try:
+            session.call_method(self.get_completion(), job_server, "Fetch", (jobId, file, start, end))
+        except Exception, e:
+            self.error = e
+        return self.do_wait()
 
 class CuminScheduler(RemoteClass):
     def __init__(self, model):



More information about the rhmessaging-commits mailing list