Changeset View
Changeset View
Standalone View
Standalone View
swh/graph/server/app.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
<p>See its | <p>See its | ||||
<a href="https://docs.softwareheritage.org/devel/swh-graph/api.html">API | <a href="https://docs.softwareheritage.org/devel/swh-graph/api.html">API | ||||
documentation</a> for more information.</p> | documentation</a> for more information.</p> | ||||
</body> | </body> | ||||
</html>""", | </html>""", | ||||
) | ) | ||||
async def argsMissing(request): | |||||
return aiohttp.web.HTTPBadRequest(text="argument(s) missing") | |||||
class GraphView(aiohttp.web.View): | class GraphView(aiohttp.web.View): | ||||
"""Base class for views working on the graph, with utility functions""" | """Base class for views working on the graph, with utility functions""" | ||||
def __init__(self, *args, **kwargs): | def __init__(self, *args, **kwargs): | ||||
super().__init__(*args, **kwargs) | super().__init__(*args, **kwargs) | ||||
self.backend = self.request.app["backend"] | self.backend = self.request.app["backend"] | ||||
def node_of_swhid(self, swhid): | def node_of_swhid(self, swhid): | ||||
▲ Show 20 Lines • Show All 234 Lines • ▼ Show 20 Lines | |||||
def make_app(backend, **kwargs): | def make_app(backend, **kwargs): | ||||
app = RPCServerApp(**kwargs) | app = RPCServerApp(**kwargs) | ||||
app.add_routes( | app.add_routes( | ||||
[ | [ | ||||
aiohttp.web.get("/", index), | aiohttp.web.get("/", index), | ||||
aiohttp.web.get("/graph", index), | aiohttp.web.get("/graph", index), | ||||
aiohttp.web.view("/graph/stats", StatsView), | aiohttp.web.view("/graph/stats", StatsView), | ||||
aiohttp.web.view("/graph/leaves", argsMissing), | |||||
aiohttp.web.view("/graph/leaves/{src}", LeavesView), | aiohttp.web.view("/graph/leaves/{src}", LeavesView), | ||||
aiohttp.web.view("/graph/neighbors", argsMissing), | |||||
aiohttp.web.view("/graph/neighbors/{src}", NeighborsView), | aiohttp.web.view("/graph/neighbors/{src}", NeighborsView), | ||||
aiohttp.web.view("/graph/visit/nodes", argsMissing), | |||||
aiohttp.web.view("/graph/visit/nodes/{src}", VisitNodesView), | aiohttp.web.view("/graph/visit/nodes/{src}", VisitNodesView), | ||||
aiohttp.web.view("/graph/visit/edges", argsMissing), | |||||
aiohttp.web.view("/graph/visit/edges/{src}", VisitEdgesView), | aiohttp.web.view("/graph/visit/edges/{src}", VisitEdgesView), | ||||
aiohttp.web.view("/graph/visit/paths", argsMissing), | |||||
aiohttp.web.view("/graph/visit/paths/{src}", VisitPathsView), | aiohttp.web.view("/graph/visit/paths/{src}", VisitPathsView), | ||||
# temporarily disabled in wait of a proper fix for T1969 | # temporarily disabled in wait of a proper fix for T1969 | ||||
# aiohttp.web.view("/graph/walk/{src}/{dst}", WalkView) | # aiohttp.web.view("/graph/walk/{src}/{dst}", WalkView) | ||||
aiohttp.web.view("/graph/randomwalk", argsMissing), | |||||
aiohttp.web.view("/graph/randomwalk/{src}", argsMissing), | |||||
aiohttp.web.view("/graph/randomwalk/{src}/{dst}", RandomWalkView), | aiohttp.web.view("/graph/randomwalk/{src}/{dst}", RandomWalkView), | ||||
aiohttp.web.view("/graph/neighbors/count", argsMissing), | |||||
aiohttp.web.view("/graph/neighbors/count/{src}", CountNeighborsView), | aiohttp.web.view("/graph/neighbors/count/{src}", CountNeighborsView), | ||||
aiohttp.web.view("/graph/leaves/count", argsMissing), | |||||
aiohttp.web.view("/graph/leaves/count/{src}", CountLeavesView), | aiohttp.web.view("/graph/leaves/count/{src}", CountLeavesView), | ||||
aiohttp.web.view("/graph/visit/nodes/count", argsMissing), | |||||
aiohttp.web.view("/graph/visit/nodes/count/{src}", CountVisitNodesView), | aiohttp.web.view("/graph/visit/nodes/count/{src}", CountVisitNodesView), | ||||
] | ] | ||||
) | ) | ||||
app["backend"] = backend | app["backend"] = backend | ||||
return app | return app |