async def route_req(self, table_name: str, key: K, web: Web, request: Request) -> Response: """Route request to worker having key in table. Arguments: table_name: Name of the table. key: The key that we want. web: The currently sued web driver, request: The web request currently being served. """ app = self.app try: dest_url: URL = app.router.key_store(table_name, key) except KeyError: raise ServiceUnavailable() dest_ident = (host, port) = self._urlident(dest_url) if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) async with app.http_client.get(routed_url) as response: return web.text( await response.text(), content_type=response.content_type, status=response.status, )
async def get(self, request: web.Request, name: str, key: str) -> web.Response: router = self.app.router try: dest_url = router.key_store(name, key) except KeyError: raise ServiceUnavailable() else: return self.json(str(dest_url))
async def route_req(self, table_name: str, key: K, web: Web, request: Request) -> Response: app = self.app try: dest_url: URL = app.router.key_store(table_name, key) except KeyError: raise ServiceUnavailable() dest_ident = (host, port) = self._urlident(dest_url) if dest_ident == self._urlident(app.conf.canonical_url): raise SameNode() routed_url = request.url.with_host(host).with_port(int(port)) async with app.http_client.get(routed_url) as response: return web.text(await response.text(), content_type=response.content_type)
async def route_topic_req(self, topic: TopicT, key: K, web: Web, request: Request) -> Response: """Route request to a worker that processes the partition with the given key. Arguments: topic: the topic to route request for. key: The key that we want. web: The currently sued web driver, request: The web request currently being served. """ app = self.app try: dest_url: URL = app.router.external_topic_key_store(topic, key) except KeyError: raise ServiceUnavailable() return await self._route_req(dest_url, web, request)
async def route_req(self, table_name: str, key: K, web: Web, request: Request) -> Response: """Route request to worker having key in table. Arguments: table_name: Name of the table. key: The key that we want. web: The currently sued web driver, request: The web request currently being served. """ app = self.app try: dest_url: URL = app.router.key_store(table_name, key) except KeyError: raise ServiceUnavailable() return await self._route_req(dest_url, web, request)
async def get(self, request: web.Request, name: str, key: str) -> web.Response: """Return JSON response after looking up the route of a table key. Arguments: name: Name of table. key: Key to look up node for. Raises: faust.web.exceptions.ServiceUnavailable: if broker metadata has not yet been received. """ router = self.app.router try: dest_url = router.key_store(name, key) except KeyError: raise ServiceUnavailable() else: return self.json(str(dest_url))