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))
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()
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()
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)
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)
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
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()
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
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):
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):
def node(self): return Node.get_by(uuid=self.uuid) or Node.me(uuid_override=self.uuid)
def node(self): return Node.get_by(uuid=self.uuid) or Node.me(uuid_override=self.uuid)