Example #1
0
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.__event_updated_values = {}
     self.new_node_tree()
     root = as_internal_node("/")
     self._cov_counter = 0
     GetException().configure({"name": "exception", "parent": "/services"})
     SUBSCRIPTION_MANAGER.configure(
         {
             "debug": 0,
             "_normal_pool_size": 2,
             "_slow_pool_size": 2,
             "_prime_pool_size": 2,
             "_minimum_poll_interval": 0.001,
             "_slow_poll_threshold": 0.500,
         }
     )
     for i in range(0, 10):
         f = FastNode()
         f.configure({"parent": root, "name": "FastNode-%03d" % i})
         s = SlowNode()
         s.configure({"parent": root, "name": "SlowNode-%03d" % i})
         e = ErrorNode()
         e.configure({"parent": root, "name": "ErrorNode-%03d" % i})
         b = BatchNode(i & 1)
         b.configure({"parent": root, "name": "BatchNode-%03d" % i})
     root.start()
     return
 def test_timeout(self):
     sids = []
     for i in range(2):
         if not i:
             timeout = 1.0
         else:
             timeout = None
         # ID3 is /services/time/UTC/milliseconds which should
         # change "really fast."
         sid = SUBSCRIPTION_MANAGER.create_polled({self.ID3: self.ID3},
                                                  timeout)
         # Make sure it comes up.
         t1 = time.time()
         self.__values_changing(sid)
         sids.append(sid)
     # Double check the values are changing and that the subscriptions
     # stay valid while we poll for values.
     t1 = time.time()
     while (time.time() - t1) < 2.0:
         for sid in sids:
             self.__values_changing(sid)
         time.sleep(0.1)
     # Now ensure that sid[0] times out...
     sid = sids.pop(0)
     t1 = time.time()
     while sid in SUBSCRIPTION_MANAGER.diag_get_sids():
         if (time.time() - t1) > 2.0:
             raise "%r did not timeout." % sid
         time.sleep(0.1)
     # Finally, make sure that the other subscription is valid.
     sid = sids.pop(0)
     self.__values_changing(sid)
     return
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.__event_updated_values = {}
     self.new_node_tree()
     root = as_internal_node('/')
     self._cov_counter = 0
     GetException().configure({'name': 'exception', 'parent': '/services'})
     SUBSCRIPTION_MANAGER.configure({
         'debug': 0,
         '_normal_pool_size': 2,
         '_slow_pool_size': 2,
         '_prime_pool_size': 2,
         '_minimum_poll_interval': 0.001,
         '_slow_poll_threshold': 0.500,
     })
     for i in range(0, 10):
         f = FastNode()
         f.configure({'parent': root, 'name': "FastNode-%03d" % i})
         s = SlowNode()
         s.configure({'parent': root, 'name': "SlowNode-%03d" % i})
         e = ErrorNode()
         e.configure({'parent': root, 'name': "ErrorNode-%03d" % i})
         b = BatchNode(i & 1)
         b.configure({'parent': root, 'name': "BatchNode-%03d" % i})
     root.start()
     return
Example #4
0
    def test_polled_event_handling(self):
        event_maker = EventProducerTestClass()
        event_maker.configure({"name": "EventProducerTester", "parent": "/"})
        event_maker.start()
        sid = SUBSCRIPTION_MANAGER.create_polled({1: event_maker})

        # Wait for polling to start and verify value made it without any events
        t1 = time.time()
        all_values = {1: None}
        while all_values[1] is None:
            if (time.time() - t1) > 1.0:
                raise "Got tired of waiting..."
            all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
            time.sleep(0.1)
        # Check that subscription value is the initial value of 100
        if all_values[1]["value"] != 100:
            raise ("polled_event_handling did not return inital value: " + str(all_values[1]["value"]))
        # make a rapid series of changes to the node value
        for i in range(10):
            event_maker._cov_check(i)
            time.sleep(0.1)
        # check change count, should be approx 10
        all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
        change_count = all_values[1]["changes"]
        if change_count < 8 or change_count > 12:
            raise ("polled_event_handling change count wrong." "  Should be approx 10, not %d" % (change_count,))
        # Check that the last value is corrent.
        final_value = all_values[1]["value"]
        if final_value != 9:
            raise ("polled_event_handling final value incorrect." "  Should be 9, not %d" % (final_value,))
        return
 def setUp(self):
     DefaultTestFixture.setUp(self)
     self.__event_updated_values = {}
     self.new_node_tree()
     root = as_internal_node('/')
     self._cov_counter = 0
     GetException().configure({'name':'exception', 'parent':'/services'})
     SUBSCRIPTION_MANAGER.configure({'debug':0,
                                     '_normal_pool_size':2,
                                     '_slow_pool_size':2,
                                     '_prime_pool_size':2,
                                     '_minimum_poll_interval':0.001,
                                     '_slow_poll_threshold':0.500,
                                     }
                                    )
     for i in range(0,10):
         f = FastNode()
         f.configure({'parent':root, 'name':"FastNode-%03d"%i})
         s = SlowNode()
         s.configure({'parent':root, 'name':"SlowNode-%03d"%i})
         e = ErrorNode()
         e.configure({'parent':root, 'name':"ErrorNode-%03d"%i})
         b = BatchNode(i & 1)
         b.configure({'parent':root, 'name':"BatchNode-%03d"%i})
     root.start()
     return
 def test_timeout(self):
     sids = []
     for i in range(2):
         if not i:
             timeout = 1.0
         else:
             timeout = None
         # ID3 is /services/time/UTC/milliseconds which should
         # change "really fast."
         sid = SUBSCRIPTION_MANAGER.create_polled({self.ID3:self.ID3},
                                                  timeout)
         # Make sure it comes up.
         t1 = time.time()
         self.__values_changing(sid)
         sids.append(sid)
     # Double check the values are changing and that the subscriptions
     # stay valid while we poll for values.
     t1 = time.time()
     while (time.time() - t1) < 2.0:
         for sid in sids:
             self.__values_changing(sid)
         time.sleep(0.1)
     # Now ensure that sid[0] times out...
     sid = sids.pop(0)
     t1 = time.time()
     while sid in SUBSCRIPTION_MANAGER.diag_get_sids():
         if (time.time()-t1) > 2.0:
             raise "%r did not timeout." % sid
         time.sleep(0.1)
     # Finally, make sure that the other subscription is valid.
     sid = sids.pop(0)
     self.__values_changing(sid)
     return
    def test_polled_event_handling(self):
        event_maker = EventProducerTestClass()
        event_maker.configure({'name': 'EventProducerTester', 'parent': '/'})
        event_maker.start()
        sid = SUBSCRIPTION_MANAGER.create_polled({1: event_maker})

        # Wait for polling to start and verify value made it without any events
        t1 = time.time()
        all_values = {1: None}
        while all_values[1] is None:
            if (time.time() - t1) > 1.0:
                raise "Got tired of waiting..."
            all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
            time.sleep(0.1)
        # Check that subscription value is the initial value of 100
        if all_values[1]['value'] != 100:
            raise ("polled_event_handling did not return inital value: " +
                   str(all_values[1]['value']))
        # make a rapid series of changes to the node value
        for i in range(10):
            event_maker._cov_check(i)
            time.sleep(0.1)
        # check change count, should be approx 10
        all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
        change_count = all_values[1]['changes']
        if change_count < 8 or change_count > 12:
            raise ("polled_event_handling change count wrong."
                   "  Should be approx 10, not %d" % (change_count, ))
        # Check that the last value is corrent.
        final_value = all_values[1]['value']
        if final_value != 9:
            raise ("polled_event_handling final value incorrect."
                   "  Should be 9, not %d" % (final_value, ))
        return
 def test_poll_all(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise ("poll_all(self.nrt1to4) did not return all values."
                    " (%d out of %d)" %
                    (len(all_values), len(self.nrt1to4)))
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise ("Never got changes for all four result dictionaries, %d." %
                len(all_values))
     return
 def test_poll_all(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0,10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values),len(self.nrt1to4))
                 )
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise (
             "Never got changes for all four result dictionaries, %d." %
             len(all_values)
             )
     return
    def test_targeted_event_handling(self):
        event_maker = EventProducerTestClass()
        event_maker.configure({'name':'EventProducerTester','parent':'/'})
        event_maker.start()
        nr = {1:event_maker}
        sid = SUBSCRIPTION_MANAGER.create_delivered(self, nr)

        # Wait for polling to start and verify value made it without any events
        t1 = time.time()
        while (time.time() - t1) < 1.0:
            all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
            time.sleep(0.1)
        # Check that subscription value is the initial value of 100
        if all_values[1]['value'] != 100:
            raise ("polled_event_handling did not return inital value: " +
                   str(all_values[1]['value']))
        # make a rapid series of changes to the node value
        for i in range(10):
            event_maker._cov_check(i)
            time.sleep(0.1)
        # check change count, should be approx 10
        value_updates = self.__event_updated_values[1]['changes']
        cov_counts = self._cov_counter
        if value_updates < cov_counts:
            raise (
                "Targeted event handling event count did not match %d vs %d"
                % (value_updates, cov_counts)
                )
    def test_targeted_event_handling(self):
        event_maker = EventProducerTestClass()
        event_maker.configure({'name': 'EventProducerTester', 'parent': '/'})
        event_maker.start()
        nr = {1: event_maker}
        sid = SUBSCRIPTION_MANAGER.create_delivered(self, nr)

        # Wait for polling to start and verify value made it without any events
        t1 = time.time()
        while (time.time() - t1) < 1.0:
            all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
            time.sleep(0.1)
        # Check that subscription value is the initial value of 100
        if all_values[1]['value'] != 100:
            raise ("polled_event_handling did not return inital value: " +
                   str(all_values[1]['value']))
        # make a rapid series of changes to the node value
        for i in range(10):
            event_maker._cov_check(i)
            time.sleep(0.1)
        # check change count, should be approx 10
        value_updates = self.__event_updated_values[1]['changes']
        cov_counts = self._cov_counter
        if value_updates < cov_counts:
            raise (
                "Targeted event handling event count did not match %d vs %d" %
                (value_updates, cov_counts))
Example #12
0
 def test_timeout_batch(self):
     # nrtB10 changes "really fast."
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrtB10, 1.0)
     # Make sure it comes up.
     t1 = time.time()
     self.__values_changing(sid)
     # Double check the values are changing and that the subscriptions
     # stay valid while we poll for values.
     t1 = time.time()
     while (time.time() - t1) < 2.0:
         self.__values_changing(sid)
         time.sleep(0.1)
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 10:
         raise ("Bogus test, there should be 10 mnr at this point, not %r."
                % len(SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 1:
         raise ("Bogus test, there should be 1 mnb at this point, not %r." %
                len(SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     t1 = time.time()
     while sid in SUBSCRIPTION_MANAGER.diag_get_sids():
         if (time.time() - t1) > 2.0:
             raise "%r did not timeout." % sid
         time.sleep(0.1)
     # Make sure that the mnr is removed when the last snr is deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 0:
         raise ("There should not be any mnrs at this point,"
                " but there are %r." % len(
                    SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     # Finally, make sure that the mnb is removed when the last mnr is
     # deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 0:
         raise ("There should not be any mnbs at this point,"
                " but there are %r." % len(
                    SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     return
Example #13
0
 def __init__(self):
     ServiceNode.__init__(self)
     # Instantiate implicit children.
     from mpx.service.interactive import InteractiveService
     InteractiveService().configure({
         'name': 'Interactive Service',
         'parent': self,
         'debug': 0,
         'port': 9666,
         'interface': 'localhost'
     })
     from mpx.service.time import Time
     Time().configure({'name': 'time', 'parent': self})
     from mpx.service.session import SessionManager
     SessionManager().configure({'name': 'session_manager', 'parent': self})
     from mpx.service.user_manager import UserManager
     UserManager().configure({'name': 'User Manager', 'parent': self})
     from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER
     SUBSCRIPTION_MANAGER.configure({
         'name': 'Subscription Manager',
         'parent': self
     })
     # Guarantee that /services/garbage_collector will exist, whether or not
     # there is an entry in the XML file.
     from mpx.service.garbage_collector import GARBAGE_COLLECTOR
     # @todo Make ReloadableSingleton!
     GARBAGE_COLLECTOR.configure({
         'name': 'garbage_collector',
         'parent': self
     })
 def test_empty(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.empty(sid)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != {}:
         raise "Node reference table not empty."
     return
 def test_replace(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.replace(sid, self.nrt3to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt3to4:
         raise "Replaced node reference table mismatch."
     return
 def test_replace(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.replace(sid, self.nrt3to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt3to4:
         raise "Replaced node reference table mismatch."
     return
 def test_empty(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.empty(sid)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != {}:
         raise "Node reference table not empty."
     return
 def __values_changing(self, sid):
     r1 = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while 1:
         changed_values = SUBSCRIPTION_MANAGER.poll_changed(sid)
         if len(changed_values):
             return
         if (time.time() - t1) > 1.0:
             raise "Never got changes for any of the values."
         time.sleep(0.1)
     assert 1, "Can't reach here."
 def __values_changing(self, sid):
     r1 = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while 1:
         changed_values = SUBSCRIPTION_MANAGER.poll_changed(sid)
         if len(changed_values):
             return
         if (time.time() - t1) > 1.0:
             raise "Never got changes for any of the values."
         time.sleep(0.1)
     assert 1, "Can't reach here."
Example #20
0
 def cancel_batch_async(self, sessionID):
   if self._subscriptions.has_key(sessionID):
       try:
         subscription = self._subscriptions[sessionID]
         del self._subscriptions[sessionID]
         del self._qualified_method_list[sessionID]
         del self._services[sessionID]
         del self._methods[sessionID]
         SUBSCRIPTION_MANAGER.destroy(subscription)
       except:
         msglog.log('RNA_XMLRPC_Handler',msglog.types.WARN,
                    "Error destroying subscription %r." % (subscription,))
         msglog.exception()
   return
Example #21
0
 def test_fast_minimum_poll_interval(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({"minimum_poll_interval": 0.0})
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values), len(self.nrt1to4))
             )
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise (
             ("Never got changes for all four result dictionaries, %d.\n" "Values: %r")
             % (len(all_values), all_values)
         )
     # ID3 is /services/time/UTC/milliseconds which should
     # change "really fast."
     c1 = all_values[self.ID3]["changes"]
     time.sleep(1.0)
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     c2 = all_values[self.ID3]["changes"]
     if (c2 - c1) < 25:  # It's usually 500 on fearfactory...
         raise "%r only changed %d times in one second." % (self.ID3, (c2 - c1))
     return
Example #22
0
 def cancel_batch_async(self, sessionID):
     if self._subscriptions.has_key(sessionID):
         try:
             subscription = self._subscriptions[sessionID]
             del self._subscriptions[sessionID]
             del self._qualified_method_list[sessionID]
             del self._services[sessionID]
             del self._methods[sessionID]
             SUBSCRIPTION_MANAGER.destroy(subscription)
         except:
             msglog.log(
                 'RNA_XMLRPC_Handler', msglog.types.WARN,
                 "Error destroying subscription %r." % (subscription, ))
             msglog.exception()
     return
 def _print_mnbs(self):
     print ""
     print "*" * 60
     for s in SUBSCRIPTION_MANAGER.diag_get_mnbs():
         print s
     print "*" * 60
     return
Example #24
0
 def scan_nodes_for_changes(self):
     sub_dict = SM.poll_all(self.sid)
     self.node_values=sub_dict
     print 'scan_nodes_for_changes sm:', sub_dict
     if sub_dict: #if there have been any changes
         #look at the value in the sheet and send it if there is a difference
         for row_index in sub_dict.keys():
             try:
                 url, mode, value = self.sheet[row_index]
                 new_value = sub_dict[row_index]['value']
                 if mode < 3: #not write only
                     update = 0
                     print "compare: ", str(new_value), value
                     if str(new_value) != value:
                         update = 1
                         try:
                             if new_value == eval(value): #check numeric comparison
                                 update = 0
                         except:
                             pass #text words won't eval
                     if update:
                         print 'scan_nodes_for_changes set_cell:', row_index
                         self.set_cell(row_index, 3, new_value) 
             except:
                 msglog.exception()
 def _print_subscriptions(self):
     print ""
     print "*" * 60
     for s in SUBSCRIPTION_MANAGER.diag_get_subscriptions():
         print s
     print "*" * 60
     return
 def test_add_and_get(self):
     st_time = time.time()
     rdict = SUBSCRIPTION_MANAGER.create_polled_and_get(self.nrt1to2)
     # Ensure we got back values for everything
     assert rdict['sid'] != None, "sid is not set in results dictionary."
     for x in rdict['values'].values():
         assert x != None, "Got None in values: %s." % str(rdict['values'])
 def test_add_and_get(self):
     st_time = time.time()
     rdict = SUBSCRIPTION_MANAGER.create_polled_and_get(self.nrt1to2)
     # Ensure we got back values for everything
     assert rdict['sid'] != None, "sid is not set in results dictionary."
     for x in rdict['values'].values():
         assert x != None, "Got None in values: %s." % str(rdict['values'])
 def _print_mnbs(self):
     print ""
     print "*"*60
     for s in SUBSCRIPTION_MANAGER.diag_get_mnbs():
         print s
     print "*"*60
     return
 def _print_subscriptions(self):
     print ""
     print "*"*60
     for s in SUBSCRIPTION_MANAGER.diag_get_subscriptions():
         print s
     print "*"*60
     return
 def test_poll_changed(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     all_values = {}
     time.sleep(0.1)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         time.sleep(0.1)
         changed_values = SUBSCRIPTION_MANAGER.poll_changed(sid)
         all_values.update(changed_values)
         if len(all_values) == 4:
             # We got all 4 values!
             return
     raise "Never got changes for all four values, %d." % len(all_values)
     return
 def test_poll_changed(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     all_values = {}
     time.sleep(0.1)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         time.sleep(0.1)
         changed_values = SUBSCRIPTION_MANAGER.poll_changed(sid)
         all_values.update(changed_values)
         if len(all_values) == 4:
             # We got all 4 values!
             return
     raise "Never got changes for all four values, %d." % len(all_values)
     return
Example #32
0
 def test_adjusted_minimum_poll_interval(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({"minimum_poll_interval": 0.2})
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values), len(self.nrt1to4))
             )
     # Check that (eventually) all the values are result dictionaries.
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if None not in all_values.values():
             # ID3 is /services/time/UTC/milliseconds which should
             # change "really fast."
             c1 = all_values[self.ID3]["changes"]
             time.sleep(1.0)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             c2 = all_values[self.ID3]["changes"]
             if (c2 - c1) > 6:  # 0.2 == Max 5/second.
                 raise ("1/5th second throttle failed," " %r changed %d times in one second.") % (
                     self.ID3,
                     (c2 - c1),
                 )
             return
         time.sleep(0.1)
     raise ("Never got changes for all four result dictionaries, %d." % len(all_values))
     return
 def test_poll_all_plus_exceptions(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({
         'minimum_poll_interval':0.0,
         })
     nrt1to4bad5to6 = {}
     nrt1to4bad5to6.update(self.nrt1to4)
     nrt1to4bad5to6['/services/time/is/an/illusion'] = (
         '/services/time/is/an/illusion'
         )
     nrt1to4bad5to6['/services/exception'] = '/services/exception'
     sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != nrt1to4bad5to6:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0,10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(nrt1to4bad5to6):
             # We did not get all 4 values!
             raise (
                 "poll_all(self.nrt1to4) did not return all values."
                 " (%d out of %d)" % (len(all_values),len(nrt1to4bad5to6))
                 )
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             self.__all_plus_exceptions_check(all_values)
             # Finally, test that a new subscription gets the correct
             # results.
             time.sleep(0.1)
             sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)                
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)                
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise ("Never got values for all nodes: %r." % all_values)
     return
Example #34
0
 def subscription_create_polled(self,
                                sessionID,
                                node_reference_table=None,
                                timeout=60.0):
     # Raise exception if this is not a valid session
     if not self.manager().validate(sessionID, touch=1):
         raise EInvalidSession('Invalid session')
     return SUBSCRIPTION_MANAGER.create_polled(node_reference_table,
                                               timeout)
 def test_poll_all_plus_exceptions(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({
         'minimum_poll_interval':
         0.0,
     })
     nrt1to4bad5to6 = {}
     nrt1to4bad5to6.update(self.nrt1to4)
     nrt1to4bad5to6['/services/time/is/an/illusion'] = (
         '/services/time/is/an/illusion')
     nrt1to4bad5to6['/services/exception'] = '/services/exception'
     sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != nrt1to4bad5to6:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(nrt1to4bad5to6):
             # We did not get all 4 values!
             raise ("poll_all(self.nrt1to4) did not return all values."
                    " (%d out of %d)" %
                    (len(all_values), len(nrt1to4bad5to6)))
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         if None not in all_values.values():
             self.__all_plus_exceptions_check(all_values)
             # Finally, test that a new subscription gets the correct
             # results.
             time.sleep(0.1)
             sid = SUBSCRIPTION_MANAGER.create_polled(nrt1to4bad5to6)
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)
             time.sleep(0.1)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             self.__all_plus_exceptions_check(all_values)
             return
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise ("Never got values for all nodes: %r." % all_values)
     return
Example #36
0
 def nodebrowser_handler(self, nb, path, node, node_url):
     # the purpose of this special handler is to get all the points in
     # one subscription instead of individually.  This greatly speeds up
     # the rz net peer driver
     sid = None
     html = ''
     if len(self.children_names()):
         node_table = {}
         for c in self.children_nodes():  #pre AML
             if isinstance(c, PointNode):
                 node_table[id(c)] = c
         if len(node_table):
             sid = SM.create_polled(node_table)
     try:
         html = nb.get_default_view(node, node_url)
     finally:
         if sid:
             SM.destroy(sid)
     return html
Example #37
0
 def nodebrowser_handler(self, nb, path, node, node_url):
     # the purpose of this special handler is to get all the points in 
     # one subscription instead of individually.  This greatly speeds up
     # the rz net peer driver
     sid = None
     html = ''
     if len(self.children_names()):
         node_table = {}
         for c in self.children_nodes(): #pre AML
             if isinstance(c, PointNode):
                 node_table[id(c)]=c
         if len(node_table):
             sid = SM.create_polled(node_table)
     try:
         html = nb.get_default_view(node, node_url)
     finally:
         if sid:
             SM.destroy(sid)
     return html
 def test_create_delivered(self):
     sid = SUBSCRIPTION_MANAGER.create_delivered(self, self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     time.sleep(0.1)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         self.__event_lock.acquire()
         try:
             if len(self.__event_updated_values) == 4:
                 # We got all 4 values!
                 return
         finally:
             self.__event_lock.release()
         time.sleep(0.1)
     if len(self.__event_updated_values) != 4:
         raise (("Never got changes for all four values, only %d.\n"
                 "Values: %r") % (len(self.__event_updated_values),
                                  self.__event_updated_values))
 def test_create_delivered(self):
     sid = SUBSCRIPTION_MANAGER.create_delivered(self, self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     time.sleep(0.1)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         self.__event_lock.acquire()
         try:
             if len(self.__event_updated_values) == 4:
                 # We got all 4 values!
                 return
         finally:
             self.__event_lock.release()
         time.sleep(0.1)
     if len(self.__event_updated_values) != 4:
         raise (("Never got changes for all four values, only %d.\n"
                 "Values: %r") % (len(self.__event_updated_values),
                                  self.__event_updated_values))
Example #40
0
 def get(self, skipcache=0):
     if self.link:
         if not self._smid:
             try:
                 value = self.as_node(self.link).get() #get it once to force autodiscovery
                 if hasattr(value, 'as_magnitude'):
                     value = value.as_magnitude()
                 self._last_value = value
                 self._smid = SM.create_delivered(self, {1:self.link}) #ID of subscription used for all descendent mpx_get templates
             except:
                 msglog.exception()
     return self._last_value
Example #41
0
 def __init__(self):
     ServiceNode.__init__(self)
     # Instantiate implicit children.
     from mpx.service.interactive import InteractiveService
     InteractiveService().configure({'name':'Interactive Service',
                                     'parent':self,'debug':0,
                                     'port':9666,'interface':'localhost'})
     from mpx.service.time import Time
     Time().configure({'name':'time','parent':self})
     from mpx.service.session import SessionManager
     SessionManager().configure({'name':'session_manager', 'parent':self})
     from mpx.service.user_manager import UserManager
     UserManager().configure({'name':'User Manager', 'parent':self})
     from mpx.service.subscription_manager import SUBSCRIPTION_MANAGER
     SUBSCRIPTION_MANAGER.configure({'name':'Subscription Manager',
                                     'parent':self})
     # Guarantee that /services/garbage_collector will exist, whether or not
     # there is an entry in the XML file.
     from mpx.service.garbage_collector import GARBAGE_COLLECTOR
     # @todo Make ReloadableSingleton!
     GARBAGE_COLLECTOR.configure({'name':'garbage_collector',
                                  'parent':self})
Example #42
0
 def resync(self):
     try:
         print 'resync'
         new_sheet = self.get_sheet()
         #subscribe to nodes that need to be read
         sub_dict = {} #dictionary to create subscriptions
         for row_index in new_sheet.keys():
             url, mode, value = new_sheet[row_index]
             if mode < 3: #need to subscribe to non-write-only
                 sub_dict[row_index] = url
             #for nodes that need to be set from values in the spreadsheet
             if mode == 2 or mode == 3: #need to set
                 try:
                     as_node(url).set(value) #value is a string or None
                 except:
                     msglog.exception()
         self.sheet = new_sheet
         if sub_dict: #create a new subscription then delete the old one
             sid = SM.create_polled(sub_dict)
             if self.sid:
                 SM.destroy(self.sid)
             self.sid = sid
             sub_dict = SM.poll_all(sid)
             self.node_values = sub_dict
             #update the spread sheet
             for row_index in sub_dict.keys():
                 url, mode, value = new_sheet[row_index]
                 if mode == 0 or mode == 1: #need to write
                     try:
                         self.set_cell(row_index, 3, sub_dict[row_index]['value']) 
                     except:
                         msglog.exception()
         #the spreadsheet and mediator should now be in sync
         self.scan()
     except:
         msglog.exception()
 def test_timeout_batch(self):
     # nrtB10 changes "really fast."
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrtB10, 1.0)
     # Make sure it comes up.
     t1 = time.time()
     self.__values_changing(sid)
     # Double check the values are changing and that the subscriptions
     # stay valid while we poll for values.
     t1 = time.time()
     while (time.time() - t1) < 2.0:
         self.__values_changing(sid)
         time.sleep(0.1)
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 10:
         raise (
             "Bogus test, there should be 10 mnr at this point, not %r." %
             len(SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 1:
         raise ("Bogus test, there should be 1 mnb at this point, not %r." %
                len(SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     t1 = time.time()
     while sid in SUBSCRIPTION_MANAGER.diag_get_sids():
         if (time.time() - t1) > 2.0:
             raise "%r did not timeout." % sid
         time.sleep(0.1)
     # Make sure that the mnr is removed when the last snr is deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 0:
         raise ("There should not be any mnrs at this point,"
                " but there are %r." %
                len(SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     # Finally, make sure that the mnb is removed when the last mnr is
     # deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 0:
         raise ("There should not be any mnbs at this point,"
                " but there are %r." %
                len(SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     return
Example #44
0
 def get(self, skipcache=0):
     if self.link:
         if not self._smid:
             try:
                 value = self.as_node(
                     self.link).get()  #get it once to force autodiscovery
                 if hasattr(value, 'as_magnitude'):
                     value = value.as_magnitude()
                 self._last_value = value
                 self._smid = SM.create_delivered(
                     self, {1: self.link}
                 )  #ID of subscription used for all descendent mpx_get templates
             except:
                 msglog.exception()
     return self._last_value
 def test_modify(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.modify(sid, self.ID2, self.ID3)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt == self.nrt1to2:
         raise "Modified node reference table not modified."
     if nrt != {self.ID1: self.ID1, self.ID2: self.ID3}:
         raise "Modified node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.modify(sid, self.ID3, self.ID2)
     except ENoSuchNodeID:
         pass
     else:
         raise "No such NodeID not detected."
     return
 def test_modify(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.modify(sid, self.ID2, self.ID3)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt == self.nrt1to2:
         raise "Modified node reference table not modified."
     if nrt != {self.ID1:self.ID1,self.ID2:self.ID3}:
         raise "Modified node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.modify(sid, self.ID3, self.ID2)
     except ENoSuchNodeID:
         pass
     else:
         raise "No such NodeID not detected."
     return
 def test_add(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.add(sid, self.ID5, self.ID5)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     nrt125 = {}
     nrt125.update(self.nrt1to2)
     nrt125[self.ID5] = self.ID5
     if nrt != nrt125:
         raise "Node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.add(sid, self.ID5, self.ID5)
     except ENodeIDExists:
         pass
     else:
         raise "Node ID in use not detected."
     return
 def test_remove(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.remove(sid, self.ID2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     nrt134 = {}
     nrt134.update(self.nrt1to4)
     del nrt134[self.ID2]
     if nrt != nrt134:
         raise "Node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.remove(sid, self.ID2)
     except ENoSuchNodeID:
         pass
     else:
         raise "No such NodeID not detected."
     return
 def test_fast_minimum_poll_interval(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({
         'minimum_poll_interval':
         0.0,
     })
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise ("poll_all(self.nrt1to4) did not return all values."
                    " (%d out of %d)" %
                    (len(all_values), len(self.nrt1to4)))
     # Check that (eventually) all the values are result dictionaries.
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         time.sleep(0.1)
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     if None in all_values.values():
         raise (("Never got changes for all four result dictionaries, %d.\n"
                 "Values: %r") % (len(all_values), all_values))
     # ID3 is /services/time/UTC/milliseconds which should
     # change "really fast."
     c1 = all_values[self.ID3]['changes']
     time.sleep(1.0)
     all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
     c2 = all_values[self.ID3]['changes']
     if (c2 - c1) < 25:  # It's usually 500 on fearfactory...
         raise "%r only changed %d times in one second." % (
             self.ID3,
             (c2 - c1),
         )
     return
 def test_add(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.add(sid, self.ID5, self.ID5)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     nrt125 = {}
     nrt125.update(self.nrt1to2)
     nrt125[self.ID5] = self.ID5
     if nrt != nrt125:
         raise "Node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.add(sid, self.ID5, self.ID5)
     except ENodeIDExists:
         pass
     else:
         raise "Node ID in use not detected."
     return
 def test_remove(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     SUBSCRIPTION_MANAGER.remove(sid, self.ID2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     nrt134 = {}
     nrt134.update(self.nrt1to4)
     del nrt134[self.ID2]
     if nrt != nrt134:
         raise "Node reference table mismatch."
     try:
         SUBSCRIPTION_MANAGER.remove(sid, self.ID2)
     except ENoSuchNodeID:
         pass
     else:
         raise "No such NodeID not detected."
     return
 def test_adjusted_minimum_poll_interval(self):
     SUBSCRIPTION_MANAGER._set_tunable_parameters({
         'minimum_poll_interval':
         0.2,
     })
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to4)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to4:
         raise "Initial node reference table mismatch."
     # Check that each invokation gets all values.
     for i in range(0, 10):
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if len(all_values) != len(self.nrt1to4):
             # We did not get all 4 values!
             raise ("poll_all(self.nrt1to4) did not return all values."
                    " (%d out of %d)" %
                    (len(all_values), len(self.nrt1to4)))
     # Check that (eventually) all the values are result dictionaries.
     t1 = time.time()
     while (time.time() - t1) < 1.0:
         all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
         if None not in all_values.values():
             # ID3 is /services/time/UTC/milliseconds which should
             # change "really fast."
             c1 = all_values[self.ID3]['changes']
             time.sleep(1.0)
             all_values = SUBSCRIPTION_MANAGER.poll_all(sid)
             c2 = all_values[self.ID3]['changes']
             if (c2 - c1) > 6:  # 0.2 == Max 5/second.
                 raise ("1/5th second throttle failed,"
                        " %r changed %d times in one second.") % (
                            self.ID3,
                            (c2 - c1),
                        )
             return
         time.sleep(0.1)
     raise ("Never got changes for all four result dictionaries, %d." %
            len(all_values))
     return
 def test_node_reference_table(self):
     sid = SUBSCRIPTION_MANAGER.create_polled(self.nrt1to2)
     nrt = SUBSCRIPTION_MANAGER.node_reference_table(sid)
     if nrt != self.nrt1to2:
         raise "Node reference table mismatch."
     return
Example #54
0
 def stop(self):
     CompositeNode.stop(self)
     if self._smid:
         SM.destroy(self._smid)
         self._smid = None
 def test_destroy_batch(self):
     sids = []
     for i in range(2):
         # BatchNodes change "really fast."
         sid = SUBSCRIPTION_MANAGER.create_polled(self.nrtB10)
         # Make sure it comes up.
         t1 = time.time()
         self.__values_changing(sid)
         sids.append(sid)
     # Double check the values are changing.
     for sid in sids:
         self.__values_changing(sid)
     # Now nuke one of the suscriptions and see that the other stays valid.
     sid = sids.pop(0)
     SUBSCRIPTION_MANAGER.destroy(sid)
     try:
         SUBSCRIPTION_MANAGER.destroy(sid)
     except ENoSuchSubscription:
         pass
     else:
         raise "No such subscription not detected."
     # Make sure that the other subscription is valid.
     sid = sids.pop(0)
     self.__values_changing(sid)
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 10:
         raise (
             "Bogus test, there should be 10 mnr at this point, not %r." %
             len(SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 1:
         raise (
             "Bogus test, there should be 1 mnb at this point, not %r." %
             len(SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     SUBSCRIPTION_MANAGER.destroy(sid)
     # Make sure that the mnr is removed when the last snr is deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnrs()) != 0:
         raise (
             "There should not be any mnrs at this point,"
             " but there are %r." %
             len(SUBSCRIPTION_MANAGER.diag_get_mnrs()))
     # Finally, make sure that the mnb is removed when the last mnr is
     # deleted.
     if len(SUBSCRIPTION_MANAGER.diag_get_mnbs()) != 0:
         raise (
             "There should not be any mnbs at this point,"
             " but there are %r." %
             len(SUBSCRIPTION_MANAGER.diag_get_mnbs()))
     return
Example #56
0
    def invoke_batch_async(self, sessionID, *qualified_method_list):
        subscription = None
        if not self.manager().validate(sessionID, touch=1):
            if self._subscriptions.has_key(sessionID):
                try:
                    subscription = self._subscriptions[sessionID]
                    del self._subscriptions[sessionID]
                    del self._qualified_method_list[sessionID]
                    del self._services[sessionID]
                    del self._methods[sessionID]
                    SUBSCRIPTION_MANAGER.destroy(subscription)
                except:
                    msglog.log(
                        'RNA_XMLRPC_Handler', msglog.types.WARN,
                        "Error destroying subscription %r on stale session %r."
                        % (subscription, sessionID))
                    msglog.exception()
            raise EInvalidSession('Invalid session')

        if self._subscriptions.has_key(sessionID):
            subscription = self._subscriptions[sessionID]
            if (self._qualified_method_list[sessionID] !=
                    qualified_method_list):
                # New batch, destroy the out of date subscription.
                try:
                    del self._subscriptions[sessionID]
                    del self._qualified_method_list[sessionID]
                    del self._services[sessionID]
                    del self._methods[sessionID]
                    SUBSCRIPTION_MANAGER.destroy(subscription)
                except:
                    msglog.log(
                        'RNA_XMLRPC_Handler', msglog.types.WARN,
                        "Error destroying previous subscription %r." %
                        (subscription, ))
                    msglog.exception()
                subscription = None

        if subscription is None:
            #
            # No subscription matching the batch, create one!
            # Build a node_reference_table:
            subscription_map = {}
            services = []
            methods = []
            for i in range(0, len(qualified_method_list)):
                rna = qualified_method_list[i]
                i_method = rna.rfind(':')
                if i_method == -1 or (i_method == 3 and rna[:3] == "mpx"):
                    # There is no method specified.
                    rna_node = rna
                    rna_method = ''
                else:
                    rna_node = rna[:i_method]
                    rna_method = rna[i_method + 1:]
                services.append(rna_node)
                methods.append(rna_method)
                if methods[i] == 'get':
                    subscription_map[services[i]] = services[i]
            # Create the subscription using the genereated node_reference_table:
            subscription = SUBSCRIPTION_MANAGER.create_polled(
                subscription_map, 5 * 60.0)
            self._subscriptions[sessionID] = subscription
            self._qualified_method_list[sessionID] = qualified_method_list
            self._services[sessionID] = services
            self._methods[sessionID] = methods
            #
            # Now that we've added our node's, validate the other sessions.
            #
            validate_list = []
            validate_list.extend(self._subscriptions.keys())
            for test_session in validate_list:
                if not self.manager().validate(test_session, touch=0):
                    expired = None
                    try:
                        expired = self._subscriptions[test_session]
                        del self._subscriptions[test_session]
                        del self._qualified_method_list[test_session]
                        del self._services[test_session]
                        del self._methods[test_session]
                        SUBSCRIPTION_MANAGER.destroy(expired)
                    except:
                        msglog.log(
                            'RNA_XMLRPC_Handler', msglog.types.WARN,
                            "Error destroying subscription %r on stale session %r."
                            % (expired, test_session))
                        msglog.exception()
        # Get all 'ready' values.
        services = self._services[sessionID]
        methods = self._methods[sessionID]
        polled_values = SUBSCRIPTION_MANAGER.poll_all(subscription)
        results = []
        for i in range(0, len(services)):
            service = services[i]
            try:
                if methods[i] == 'get':
                    result = polled_values[service]
                    if result is None:
                        result = 'error: Waiting for update...'
                    else:
                        result = result['value']
                    if isinstance(result, Exception):
                        result = self._exception_string(result)
                else:
                    result = 'error: %r method not supported, only get().' % (
                        methods[i])
                results.append(result)
            except Exception, e:
                results.append(self._exception_string(e))
Example #57
0
 def subscription_poll_all(self, sessionID, sid):
     # Raise exception if this is not a valid session
     if not self.manager().validate(sessionID, touch=1):
         raise EInvalidSession('Invalid session')
     return SUBSCRIPTION_MANAGER.poll_all(sid)
Example #58
0
 def subscription_modify(self, sessionID, sid, nid, node_reference):
     # Raise exception if this is not a valid session
     if not self.manager().validate(sessionID, touch=1):
         raise EInvalidSession('Invalid session')
     return SUBSCRIPTION_MANAGER.modify(sid, nid, node_reference)