Ejemplo n.º 1
0
    def validate_routing_table(self, user_account=None):
        """Check that the routing table on this account is valid.

        Currently we just check account ownership of tags and conversations.

        TODO: Cycle detection, if that's even possible. Maybe other stuff.
        TODO: Determine if this is necessary and move it elsewhere if it is.
        """
        if user_account is None:
            user_account = yield self.get_user_account()
        routing_table = yield self.get_routing_table(user_account)
        # We don't care about endpoints here, only connectors.
        routing_connectors = set()
        for src_conn, _src_ep, dst_conn, _dst_ep in routing_table.entries():
            routing_connectors.add(src_conn)
            routing_connectors.add(dst_conn)

        # Checking tags is cheap and easy, so do that first.
        channels = yield self.active_channels()
        for channel in channels:
            channel_conn = channel.get_connector()
            if channel_conn in routing_connectors:
                routing_connectors.remove(channel_conn)

        # Now we run through active conversations to check those.
        convs = yield self.active_conversations()
        for conv in convs:
            conv_conn = conv.get_connector()
            if conv_conn in routing_connectors:
                routing_connectors.remove(conv_conn)

        if routing_connectors:
            raise VumiError(
                "Routing table contains illegal connector names: %s" %
                (routing_connectors, ))
Ejemplo n.º 2
0
 def get_routing_table(self, user_account=None):
     if user_account is None:
         user_account = yield self.get_user_account()
     if user_account.routing_table is None:
         raise VumiError("Routing table missing for account: %s" %
                         (user_account.key, ))
     returnValue(user_account.routing_table)
Ejemplo n.º 3
0
 def start(self):
     self.started = True
     greeting = ''
     if self.template_current.get('display'):
         greeting += self.template_current['display'].get(self.language, '')
     if self.echo:
         print "\n", greeting
     if not self.template:
         raise VumiError("template must be loaded")
     if not self.data:
         raise VumiError("data must be loaded")
     __next = self.template_current.get('next')
     t = self.template.get(__next)
     d = (self.data, __next)
     self.select(t, d)
     return greeting
Ejemplo n.º 4
0
    def get_worker_class(self):
        worker_class = self.opts.pop('worker-class')
        depr_worker_class = self.opts.pop('worker_class')

        if depr_worker_class is not None:
            warnings.warn(
                "The --worker_class option is deprecated since"
                " Vumi 0.3. Please use --worker-class instead.",
                category=DeprecationWarning)
            if worker_class is None:
                worker_class = depr_worker_class

        if worker_class is None:
            raise VumiError("please specify --worker-class")

        return worker_class
Ejemplo n.º 5
0
 def send_command(self, command):
     if self.command_publisher is None:
         raise VumiError("No command message publisher available.")
     return self.command_publisher.publish_message(command)
Ejemplo n.º 6
0
 def send_command(self, command):
     if self.amqp_client is None:
         raise VumiError("No command message publisher available.")
     if not self.amqp_client.is_connected():
         self.amqp_client.connect()
     self.amqp_client.publish_command_message(command)
Ejemplo n.º 7
0
 def get_metric_manager(self, prefix):
     if self.metric_publisher is None:
         raise VumiError("No metric publisher available.")
     return MetricManager(prefix, publisher=self.metric_publisher)
Ejemplo n.º 8
0
 def startWorker(self):
     # I hate camelCasing method but since Twisted has it as a
     # standard I voting to stick with it
     raise VumiError("You need to subclass Worker and its "
                     "startWorker method")