def sendEvent(self, runid, brokerName, topic):
        trans = events.EventTransmitter(brokerName, topic)

        root = PropertySet()
        root.set(events.Event.TOPIC, topic)
        root.set("myname","myname")
        root.set(events.Event.STATUS, "my special status")

        locationID = events.LocationId()

        event = events.StatusEvent(runid, locationID, root)
        # ok...now publish it
        trans.publishEvent(event)
Beispiel #2
0
    def sendEvent(self, brokerName, topic):
        """Send an Event."""
        trans = events.EventTransmitter(brokerName, topic)

        root = PropertySet()
        root.set(events.Event.TOPIC, topic)
        root.set("myname", "myname")
        root.set(events.StatusEvent.STATUS, "my special status")
        root.set(events.StatusEvent.RUNID, "srptestrun")
        root.set("bazinga", "sheldon")

        originatorId = events.LocationId()
        event = events.StatusEvent("srptestrun", originatorId, root)

        # ok...now publish it
        trans.publishEvent(event)
Beispiel #3
0
    def testLocationId(self):
        testEnv = EventsEnvironment()
        broker = testEnv.getBroker()
        thisHost = platform.node()

        locationID = events.LocationId()

        # check to see if localID is 0
        localId = locationID.getLocalID()
        self.assertEqual(localId, 0)

        # check host name
        hostname = locationID.getHostName()
        self.assertEqual(hostname, socket.gethostname())

        # check process id
        processId = locationID.getProcessID()
        self.assertEqual(processId, os.getpid())

        locationID2 = events.LocationId()

        # check to see if localID is 1
        localId = locationID2.getLocalID()
        self.assertEqual(localId, 1)

        self.assertEqual(locationID.getLocalID(), 0)

        # check host name
        hostname = locationID.getHostName()
        self.assertEqual(hostname, socket.gethostname())

        # check process id
        processId = locationID2.getProcessID()
        self.assertEqual(processId, os.getpid())

        root = PropertySet()
        root.set("myname", "myname")
        status = "my special status"
        root.set(events.Event.STATUS, status)

        statusEvent = events.StatusEvent("my runid", locationID, root)
        statusEvent2 = events.StatusEvent("my runid", locationID2, root)

        topic = "mytopic_%s_%d" % (thisHost, os.getpid())
        transmitter = events.EventTransmitter(broker, topic)

        hostname = locationID2.getHostName()

        # create a receiver selector with the hostname, process id and local id
        sel = "%s = '%s' and %s = %d and %s = %d" % (
            events.StatusEvent.ORIG_HOSTNAME, hostname,
            events.StatusEvent.ORIG_PROCESSID, os.getpid(),
            events.StatusEvent.ORIG_LOCALID, 1)

        receiver = events.EventReceiver(broker, topic, sel)

        # transmit the events
        transmitter.publishEvent(statusEvent)
        transmitter.publishEvent(statusEvent2)

        # should receive event with with the process id
        returnedEvent = receiver.receiveEvent()
        ps = returnedEvent.getPropertySet()
        self.assertEqual(ps.get('ORIG_HOSTNAME'), hostname)
        self.assertEqual(ps.get('ORIG_PROCESSID'), os.getpid())
        self.assertEqual(ps.get('ORIG_LOCALID'), 1)

        # should NOT receive another event, because it was filtered out by
        # the broker
        returnedEvent2 = receiver.receiveEvent(1)
        self.assertIsNone(returnedEvent2)
Beispiel #4
0
 def setUp(self):
     locationId = events.LocationId()
     locationId.reset()
Beispiel #5
0
    def testCommandEvent(self):
        testEnv = EventsEnvironment()
        broker = testEnv.getBroker()
        thisHost = platform.node()

        topic = "test_events_command_%s_%d" % (thisHost, os.getpid())

        # send a command event
        receiver = events.EventReceiver(broker, topic)
        trans = events.EventTransmitter(broker, topic)

        originatorId = events.LocationId()
        root = PropertySet()
        root.set(events.StatusEvent.TOPIC, topic)
        root.set("myname", "myname")
        root.set(events.StatusEvent.STATUS, "my special status")
        event = events.StatusEvent("srptestrun", originatorId, root)

        statusOriginatorId = event.getOriginator()
        destinationID = events.LocationId(statusOriginatorId)

        commandOriginatorID = events.LocationId()
        root2 = PropertySet()
        root2.set(events.CommandEvent.TOPIC, topic)
        root2.set("myname", "myname2")
        root2.set(events.CommandEvent.STATUS, "my special status2")
        event2 = events.CommandEvent("srptestrun", commandOriginatorID,
                                     destinationID, root2)

        trans.publishEvent(event2)
        val = receiver.receiveCommandEvent()

        # be sure we received an event
        self.assertIsNotNone(val)
        # these are the filterable names we expect to see
        names = [
            events.CommandEvent.DEST_HOSTNAME,
            events.CommandEvent.DEST_LOCALID,
            events.CommandEvent.DEST_PROCESSID, events.CommandEvent.EVENTTIME,
            events.CommandEvent.ORIG_HOSTNAME,
            events.CommandEvent.ORIG_LOCALID,
            events.CommandEvent.ORIG_PROCESSID, events.CommandEvent.PUBTIME,
            events.CommandEvent.RUNID, events.CommandEvent.STATUS,
            events.CommandEvent.TOPIC, events.CommandEvent.TYPE
        ]
        self.assertValid(val, names, commandOriginatorID.getLocalID(),
                         destinationID.getLocalID())

        # send a command event with additional filterable properties
        receiver = events.EventReceiver(broker, topic)

        trans = events.EventTransmitter(broker, topic)

        originatorId = events.LocationId()
        event = events.StatusEvent("srptestrun", originatorId, root)

        statusOriginatorId = event.getOriginator()
        destinationID = events.LocationId(statusOriginatorId)

        commandOriginatorID = events.LocationId()

        filterable = PropertySet()
        filterable.set("FOO", 12.3)
        filterable.set("BAR", .45)

        event2 = events.CommandEvent("srptestrun", commandOriginatorID,
                                     destinationID, root2, filterable)

        trans.publishEvent(event2)

        val = receiver.receiveCommandEvent()

        # be sure we received an event
        self.assertIsNotNone(val)

        # these are the filterable names we expect to see
        names = [
            events.CommandEvent.DEST_HOSTNAME,
            events.CommandEvent.DEST_LOCALID,
            events.CommandEvent.DEST_PROCESSID, events.CommandEvent.EVENTTIME,
            events.CommandEvent.ORIG_HOSTNAME,
            events.CommandEvent.ORIG_LOCALID,
            events.CommandEvent.ORIG_PROCESSID, events.CommandEvent.PUBTIME,
            events.CommandEvent.RUNID, events.CommandEvent.STATUS,
            events.CommandEvent.TOPIC, events.CommandEvent.TYPE, 'FOO', 'BAR'
        ]
        self.assertValid(val, names, commandOriginatorID.getLocalID(),
                         destinationID.getLocalID())

        self.assertTrue(event.getType(), events.EventTypes.COMMAND)