예제 #1
0
 def handle_request(self, request):
     exceptions = []
     userobject = request.user_object()
     if not userobject:
         username = request.get_cookie("NBMUSER", None)
         if not username:
             raise Unauthorized("User unknown")
         address = request.get_address()
         if not self._cloud_manager.is_host_in_formation(address):
             raise Unauthorized("Address unrecognized: " + address)
         message = "Getting user because address/usrename: %r, %r"
         msglog.debug(message % (address, username))
         userobject = self.user_manager.get_user(username)
     request_data = request.get_post_data_as_dictionary()
     request_data.update(request.get_query_string_as_dictionary())
     if request_data.has_key('command') and request_data.has_key('guid'):
         exceptions = []
         path = request.get_path()
         username = userobject.name()
         method = request.get_command()
         protocol = request.get_protocol()
         command = request_data['command'][0]
         user = self.user_service.user_from_object(userobject)
         origins = {}
         for guid in request_data['guid']:
             try:
                 event = AlarmEvent.get_event(guid)
             except KeyError:
                 msglog.warn("Attempt to get event %r failed." % guid)
             else:
                 origins.setdefault(event.origin, []).append(event)
         for origin, events in origins.items():
             if origin == AlarmEvent.LOCALORIGIN:
                 for event in events:
                     message = "User '%s'" % username
                     if self.secured:
                         event = query_multi_adapter((event, user), ISecure)
                     try:
                         event.notify(command, self, time.time(), message)
                     except Exception, error:
                         msg = "Notify %r of %r failed." % (event, command)
                         msglog.log("broadway", msglog.types.WARN, msg)
                         msglog.exception(prefix="handled")
                         # CSCte94039 - form the proper error msg
                         exceptions.append((command, str(error)))
             else:
                 headers = {"Cookie": "NBMUSER=%s" % userobject.name()}
                 guids = [event.GUID for event in events]
                 parameters = [("command", command)]
                 parameters.extend([("guid", guid) for guid in guids])
                 data = urllib.urlencode(parameters)
                 url = '%s://%s%s' % (protocol, origin, path)
                 if method == "GET":
                     url = "?".join([url, data])
                     data = None
                 redirect = urllib2.Request(url, data, headers)
                 try:
                     urllib2.urlopen(redirect).read()
                 except Exception, error:
                     message = "'%s' remote events on '%s' failed."
                     msglog.warn(message % (command, origin))
                     msglog.exception(prefix="handled")
                     exceptions.append((origin, command, error))
예제 #2
0
        print "%s (%s):\n\t%s" % (self.name, id(subscription), event)


callbacks = {}
for i in range(0, 10):
    callbacks[i] = Callback("callback%s" % i)

sub1 = a1.register(callbacks[1], AlarmEvent)
sub2 = a2.register(callbacks[2], AlarmEvent)
sub3 = a3.register(callbacks[3], AlarmEvent)
sub4 = a4.register(callbacks[4], AlarmEvent)
sub5 = a5.register(callbacks[5], AlarmEvent)


a1.trigger(trigger1, time.time(), "1-1")
assert AlarmEvent.get_event(callbacks[1].event.id) is callbacks[1].event, "ID lookup failed"
a1.trigger(trigger1, time.time(), "1-2")
a1.trigger(trigger1, time.time(), "1-3")
a1.trigger(trigger1, time.time(), "1-4")
a1.trigger(trigger1, time.time(), "1-5")
a1.clear(trigger1, time.time(), {"a1": "fine"})

a1.trigger(trigger1, time.time(), "1-1")
a1.trigger(trigger1, time.time(), "1-2")
a1.trigger(trigger1, time.time(), "1-3")
a1.trigger(trigger1, time.time(), "1-4")
a1.trigger(trigger1, time.time(), "1-5")

ef = a1.event_factory
inactive = ef.get_by_state(["inactive"])
raised = ef.get_by_state(["raised"])
예제 #3
0
        self.args = args
        print '%s (%s):\n\t%s' % (self.name, id(subscription), event)

callbacks = {}
for i in range(0,10):
    callbacks[i] = Callback('callback%s' % i)

sub1 = a1.register(callbacks[1], AlarmEvent)
sub2 = a2.register(callbacks[2], AlarmEvent)
sub3 = a3.register(callbacks[3], AlarmEvent)
sub4 = a4.register(callbacks[4], AlarmEvent)
sub5 = a5.register(callbacks[5], AlarmEvent)


a1.trigger(trigger1,time.time(),'1-1')
assert AlarmEvent.get_event(callbacks[1].event.id) is callbacks[1].event, (
    'ID lookup failed')
a1.trigger(trigger1,time.time(),'1-2')
a1.trigger(trigger1,time.time(),'1-3')
a1.trigger(trigger1,time.time(),'1-4')
a1.trigger(trigger1,time.time(),'1-5')
a1.clear(trigger1,time.time(),{'a1':'fine'})

a1.trigger(trigger1,time.time(),'1-1')
a1.trigger(trigger1,time.time(),'1-2')
a1.trigger(trigger1,time.time(),'1-3')
a1.trigger(trigger1,time.time(),'1-4')
a1.trigger(trigger1,time.time(),'1-5')

ef = a1.event_factory
inactive = ef.get_by_state(['inactive'])
예제 #4
0
 def handle_request(self, request):
     exceptions = []
     userobject = request.user_object()
     if not userobject:
         username = request.get_cookie("NBMUSER", None)
         if not username:
             raise Unauthorized("User unknown")
         address = request.get_address()
         if not self._cloud_manager.is_host_in_formation(address):
             raise Unauthorized("Address unrecognized: " + address)
         message = "Getting user because address/usrename: %r, %r"
         msglog.debug(message % (address, username))
         userobject = self.user_manager.get_user(username)
     request_data = request.get_post_data_as_dictionary()
     request_data.update(request.get_query_string_as_dictionary())
     if request_data.has_key("command") and request_data.has_key("guid"):
         exceptions = []
         path = request.get_path()
         username = userobject.name()
         method = request.get_command()
         protocol = request.get_protocol()
         command = request_data["command"][0]
         user = self.user_service.user_from_object(userobject)
         origins = {}
         for guid in request_data["guid"]:
             try:
                 event = AlarmEvent.get_event(guid)
             except KeyError:
                 msglog.warn("Attempt to get event %r failed." % guid)
             else:
                 origins.setdefault(event.origin, []).append(event)
         for origin, events in origins.items():
             if origin == AlarmEvent.LOCALORIGIN:
                 for event in events:
                     message = "User '%s'" % username
                     if self.secured:
                         event = query_multi_adapter((event, user), ISecure)
                     try:
                         event.notify(command, self, time.time(), message)
                     except Exception, error:
                         msg = "Notify %r of %r failed." % (event, command)
                         msglog.log("broadway", msglog.types.WARN, msg)
                         msglog.exception(prefix="handled")
                         # CSCte94039 - form the proper error msg
                         exceptions.append((command, str(error)))
             else:
                 headers = {"Cookie": "NBMUSER=%s" % userobject.name()}
                 guids = [event.GUID for event in events]
                 parameters = [("command", command)]
                 parameters.extend([("guid", guid) for guid in guids])
                 data = urllib.urlencode(parameters)
                 url = "%s://%s%s" % (protocol, origin, path)
                 if method == "GET":
                     url = "?".join([url, data])
                     data = None
                 redirect = urllib2.Request(url, data, headers)
                 try:
                     urllib2.urlopen(redirect).read()
                 except Exception, error:
                     message = "'%s' remote events on '%s' failed."
                     msglog.warn(message % (command, origin))
                     msglog.exception(prefix="handled")
                     exceptions.append((origin, command, error))