Ejemplo n.º 1
0
 def add_rule(self, topic_name, subscription_name, rule_name, rule_value):
     bus_service = self._get_bus_service()
     rule = Rule()
     rule.filter_type = 'SqlFilter'
     rule.filter_expression = rule_value
     ret = bus_service.create_rule(topic_name, subscription_name, rule_name, rule)
     print(ret)
Ejemplo n.º 2
0
 def __init__(self, table_cred = None):
     rule = Rule()
     rule.filter_type = 'SqlFilter'
     rule.filter_expression = "event = '%s' AND isSpeeding = TRUE" % (SpeedCamera.EVENT_VEHICLE)
     # Call super class constructor
     PersistentSubscriber.__init__(self, self.TABLE,
                                   SpeedCamera.TOPIC, "PoliceMonitor",
                                   "PoliceMonitorRule", rule)
Ejemplo n.º 3
0
 def __init__(self, table_cred = None):
     rule = Rule()
     rule.filter_type = 'SqlFilter'
     rule.filter_expression = "event = '%s' OR event = '%s'" % (SpeedCamera.EVENT_ACTIVATION, SpeedCamera.EVENT_DEACTIVATION)
     # Call super class constructor
     PersistentSubscriber.__init__(self, self.TABLE,
                                   SpeedCamera.TOPIC, "CameraRegister",
                                   "CameraRegisterRule", rule)
    def test_create_rule_with_options_sql_rule_action(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')

        # Act
        rule1 = Rule()
        rule1.action_type = 'SqlRuleAction'
        rule1.action_expression = "SET foo = 5"
        created = self.sbs.create_rule(self.topic_name, 'MySubscription', 'MyRule1', rule1)

        # Assert
        self.assertTrue(created)
    def test_create_rule_with_options_correlation_filter(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')

        # Act
        rule1 = Rule()
        rule1.filter_type = 'CorrelationFilter'
        rule1.filter_expression = 'myid'
        created = self.sbs.create_rule(self.topic_name, 'MySubscription', 'MyRule1', rule1)

        # Assert
        self.assertTrue(created)
Ejemplo n.º 6
0
    def test_create_rule_with_options_sql_rule_action(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')

        # Act
        rule1 = Rule()
        rule1.action_type = 'SqlRuleAction'
        rule1.action_expression = "SET foo = 5"
        created = self.sbs.create_rule(self.topic_name, 'MySubscription',
                                       'MyRule1', rule1)

        # Assert
        self.assertTrue(created)
Ejemplo n.º 7
0
    def test_create_rule_with_options_correlation_filter(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')

        # Act
        rule1 = Rule()
        rule1.filter_type = 'CorrelationFilter'
        rule1.filter_expression = 'myid'
        created = self.sbs.create_rule(self.topic_name, 'MySubscription',
                                       'MyRule1', rule1)

        # Assert
        self.assertTrue(created)
    def test_get_rule_with_existing_rule_with_options(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')
        sent_rule = Rule()
        sent_rule.filter_type = 'SqlFilter'
        sent_rule.filter_expression = 'foo > 40'
        sent_rule.action_type = 'SqlRuleAction'
        sent_rule.action_expression = 'SET foo = 5'
        self.sbs.create_rule(self.topic_name, 'MySubscription', 'MyRule1', sent_rule)

        # Act
        received_rule = self.sbs.get_rule(self.topic_name, 'MySubscription', 'MyRule1')

        # Assert
        self.assertIsNotNone(received_rule)
        self.assertEquals(received_rule.name, 'MyRule1')
        self.assertEquals(received_rule.filter_type, sent_rule.filter_type)
        self.assertEquals(received_rule.filter_expression, sent_rule.filter_expression)
        self.assertEquals(received_rule.action_type, sent_rule.action_type)
        self.assertEquals(received_rule.action_expression, sent_rule.action_expression)
Ejemplo n.º 9
0
    def test_get_rule_with_existing_rule_with_options(self):
        # Arrange
        self._create_topic_and_subscription(self.topic_name, 'MySubscription')
        sent_rule = Rule()
        sent_rule.filter_type = 'SqlFilter'
        sent_rule.filter_expression = 'foo > 40'
        sent_rule.action_type = 'SqlRuleAction'
        sent_rule.action_expression = 'SET foo = 5'
        self.sbs.create_rule(self.topic_name, 'MySubscription', 'MyRule1',
                             sent_rule)

        # Act
        received_rule = self.sbs.get_rule(self.topic_name, 'MySubscription',
                                          'MyRule1')

        # Assert
        self.assertIsNotNone(received_rule)
        self.assertEquals(received_rule.name, 'MyRule1')
        self.assertEquals(received_rule.filter_type, sent_rule.filter_type)
        self.assertEquals(received_rule.filter_expression,
                          sent_rule.filter_expression)
        self.assertEquals(received_rule.action_type, sent_rule.action_type)
        self.assertEquals(received_rule.action_expression,
                          sent_rule.action_expression)
Ejemplo n.º 10
0
 def _add_event_subscription(self, event_id):
     rule = Rule()
     rule.filter_type = 'SqlFilter'
     rule.filter_expression = f"EventId='{event_id}'"
     self.bus_service.create_rule('sensordata', 'test', event_id, rule)
                                shared_access_key_name=svcbus_keyname,
                                shared_access_key_value=svcbus_keyvalue)

# Create a Topic

bus_service.create_topic('cameratopic')

# Create Subscriptions

# NoSQL Consumer application retrieves all registration and sighting messages

bus_service.create_subscription('cameratopic', 'AllMessages')

# Police Monitor application retrieves sighting messages where speed>speedlimit

bus_service.create_subscription('cameratopic', 'Speeding')

rule = Rule()
rule.filter_type = 'SqlFilter'
rule.filter_expression = 'speeding = True'

bus_service.create_rule('cameratopic', 'Speeding', 'SpeedingFilter', rule)
bus_service.delete_rule('cameratopic', 'Speeding', DEFAULT_RULE_NAME)

# Vehicle check application retrieves all sighting messages

bus_service.create_subscription('cameratopic', 'VehCheck')

bus_service.create_rule('cameratopic', 'VehCheck', 'SpeedingFilter', rule)
bus_service.delete_rule('cameratopic', 'VehCheck', DEFAULT_RULE_NAME)