示例#1
0
 def test_get_tickets(self):
     response = self.fetch("/tickets")
     eq_(response.code, 200)
     result = json.loads(response.body)
     ok_("tickets" in result)
     eq_(len(result["tickets"]), 3)
     for ticket in result["tickets"]:
         source = Node.get_by(uuid=ticket["source"])
         destination = Node.get_by(uuid=ticket["destination"])
         ok_(Ticket.get_by(stream=Stream.get_by(slug=ticket["stream"]), source=source, destination=destination))
示例#2
0
    def _load_ticket(self, stream_slug, destination_uuid):
        stream = Stream.get_by(slug=stream_slug)
        if not destination_uuid:
            return Ticket.get_by(stream=stream, destination=Node.me())

        node = Node.get_by(uuid=destination_uuid)
        return Ticket.query.filter_by(stream=stream, destination=node).first()
示例#3
0
文件: ticket.py 项目: peplin/astral
    def _load_ticket(self, stream_slug, destination_uuid):
        stream = Stream.get_by(slug=stream_slug)
        if not destination_uuid:
            return Ticket.get_by(stream=stream, destination=Node.me())

        node = Node.get_by(uuid=destination_uuid)
        return Ticket.query.filter_by(stream=stream, destination=node).first()
示例#4
0
 def test_delete_node(self):
     node = NodeFactory()
     self.http_client.fetch(HTTPRequest(
         self.get_url(node.absolute_url()), 'DELETE'), self.stop)
     response = self.wait()
     eq_(response.code, 200)
     eq_(Node.get_by(uuid=node.uuid), None)
示例#5
0
 def test_delete_node(self):
     node = NodeFactory()
     self.http_client.fetch(
         HTTPRequest(self.get_url(node.absolute_url()), 'DELETE'),
         self.stop)
     response = self.wait()
     eq_(response.code, 200)
     eq_(Node.get_by(uuid=node.uuid), None)
示例#6
0
文件: stream.py 项目: peplin/astral
 def from_dict(cls, data):
     stream = Stream.get_by(name=data['name'])
     if not stream:
         source = Node.get_by(uuid=data.get('source') or
                 data.get('source_uuid'))
         if not source:
             log.debug("%s had a source not in our database -- not creating " 
                     "Stream", data)
             return
         else:
             stream = cls(source=source, name=data['name'],
                     description=data.get('description', ''))
             session.commit()
     return stream
示例#7
0
文件: nodes.py 项目: truonglvx/astral
 def post(self):
     """Add the node specified in POSTed JSON to the list of known nodes."""
     uuid = self.get_json_argument('uuid')
     if (Node.me().supernode and self.get_json_argument(
                 'primary_supernode_uuid', '') == Node.me().uuid):
         children_count = Node.query.filter_by(primary_supernode=Node.me()
                 ).count()
         if children_count > settings.SUPERNODE_MAX_CHILDREN:
             raise HTTPError(503)
     if not Node.get_by(uuid=uuid):
         # TODO what if supernode changes? need to update
         self.request.arguments.setdefault('ip_address',
                 self.request.remote_ip)
         Node.from_dict(self.request.arguments)
         session.commit()
示例#8
0
 def from_dict(cls, data):
     stream = Stream.get_by(name=data['name'])
     if not stream:
         source = Node.get_by(
             uuid=data.get('source') or data.get('source_uuid'))
         if not source:
             log.debug(
                 "%s had a source not in our database -- not creating "
                 "Stream", data)
             return
         else:
             stream = cls(source=source,
                          name=data['name'],
                          description=data.get('description', ''))
             session.commit()
     return stream
示例#9
0
                stream.tickets_url(), destination_uuid=destination.uuid)
        except RequestError, e:
            log.info(
                "Couldn't connect to %s to ask for %s -- deleting "
                "the node from the database", node, stream)
            log.debug("Node returned: %s", e)
            node.delete()
        except RequestFailed, e:
            if e.response.status_int == 412:
                log.debug("%s didn't have room to forward %s to us", node,
                          stream)
        else:
            if existing_ticket:
                return existing_ticket
            if ticket_data:
                source = Node.get_by(uuid=ticket_data['source'])
                if not source:
                    source_node_data = NodesAPI(node.uri()).get(
                        Node.absolute_url(source))
                    source = Node.from_dict(source_node_data)
                return Ticket(stream=stream,
                              source=source,
                              source_port=ticket_data['source_port'],
                              destination=destination,
                              hops=ticket_data['hops'] + 1)

    @classmethod
    def _request_stream_from_watchers(cls,
                                      stream,
                                      destination,
                                      unconfirmed_tickets=None):
示例#10
0
文件: tickets.py 项目: peplin/astral
            ticket_data = TicketsAPI(node.uri()).create(stream.tickets_url(),
                    destination_uuid=destination.uuid)
        except RequestError, e:
            log.info("Couldn't connect to %s to ask for %s -- deleting "
                    "the node from the database", node, stream)
            log.debug("Node returned: %s", e)
            node.delete()
        except RequestFailed, e:
            if e.response.status_int == 412:
                log.debug("%s didn't have room to forward %s to us",
                        node, stream)
        else:
            if existing_ticket:
                return existing_ticket
            if ticket_data:
                source = Node.get_by(uuid=ticket_data['source'])
                if not source:
                    source_node_data = NodesAPI(node.uri()).get(
                            Node.absolute_url(source))
                    source = Node.from_dict(source_node_data)
                return Ticket(stream=stream, source=source,
                        source_port=ticket_data['source_port'],
                        destination=destination,
                        hops=ticket_data['hops'] + 1)

    @classmethod
    def _request_stream_from_watchers(cls, stream, destination,
            unconfirmed_tickets=None):
        tickets = []
        for ticket in Ticket.query.filter_by(stream=stream):
            if cls._already_seeding(ticket):
示例#11
0
文件: base.py 项目: peplin/astral
 def node(self):
     return Node.get_by(uuid=self.uuid) or Node.me(uuid_override=self.uuid)
示例#12
0
文件: base.py 项目: truonglvx/astral
 def node(self):
     return Node.get_by(uuid=self.uuid) or Node.me(uuid_override=self.uuid)