diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2023-11-03 08:26:19 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-11-09 17:33:02 +0000 |
commit | 8f8501ed403dec27acbe780b936bc087fc5006d0 (patch) | |
tree | 60e6415075c7c71eacec23ca7dda53e4a324b12e /bitbake/lib/prserv | |
parent | f97b686884166dd77d1818e70615027c6ba8c348 (diff) | |
download | poky-8f8501ed403dec27acbe780b936bc087fc5006d0.tar.gz |
bitbake: asyncrpc: Abstract sockets
Rewrites the asyncrpc client and server code to make it possible to have
other transport backends that are not stream based (e.g. websockets
which are message based). The connection handling classes are now shared
between both the client and server to make it easier to implement new
transport mechanisms
(Bitbake rev: 2aaeae53696e4c2f13a169830c3b7089cbad6eca)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/prserv')
-rw-r--r-- | bitbake/lib/prserv/client.py | 8 | ||||
-rw-r--r-- | bitbake/lib/prserv/serv.py | 31 |
2 files changed, 20 insertions, 19 deletions
diff --git a/bitbake/lib/prserv/client.py b/bitbake/lib/prserv/client.py index 69ab7a4ac9..6b81356fac 100644 --- a/bitbake/lib/prserv/client.py +++ b/bitbake/lib/prserv/client.py | |||
@@ -14,28 +14,28 @@ class PRAsyncClient(bb.asyncrpc.AsyncClient): | |||
14 | super().__init__('PRSERVICE', '1.0', logger) | 14 | super().__init__('PRSERVICE', '1.0', logger) |
15 | 15 | ||
16 | async def getPR(self, version, pkgarch, checksum): | 16 | async def getPR(self, version, pkgarch, checksum): |
17 | response = await self.send_message( | 17 | response = await self.invoke( |
18 | {'get-pr': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum}} | 18 | {'get-pr': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum}} |
19 | ) | 19 | ) |
20 | if response: | 20 | if response: |
21 | return response['value'] | 21 | return response['value'] |
22 | 22 | ||
23 | async def importone(self, version, pkgarch, checksum, value): | 23 | async def importone(self, version, pkgarch, checksum, value): |
24 | response = await self.send_message( | 24 | response = await self.invoke( |
25 | {'import-one': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'value': value}} | 25 | {'import-one': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'value': value}} |
26 | ) | 26 | ) |
27 | if response: | 27 | if response: |
28 | return response['value'] | 28 | return response['value'] |
29 | 29 | ||
30 | async def export(self, version, pkgarch, checksum, colinfo): | 30 | async def export(self, version, pkgarch, checksum, colinfo): |
31 | response = await self.send_message( | 31 | response = await self.invoke( |
32 | {'export': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'colinfo': colinfo}} | 32 | {'export': {'version': version, 'pkgarch': pkgarch, 'checksum': checksum, 'colinfo': colinfo}} |
33 | ) | 33 | ) |
34 | if response: | 34 | if response: |
35 | return (response['metainfo'], response['datainfo']) | 35 | return (response['metainfo'], response['datainfo']) |
36 | 36 | ||
37 | async def is_readonly(self): | 37 | async def is_readonly(self): |
38 | response = await self.send_message( | 38 | response = await self.invoke( |
39 | {'is-readonly': {}} | 39 | {'is-readonly': {}} |
40 | ) | 40 | ) |
41 | if response: | 41 | if response: |
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py index c686b2065c..ea7933164b 100644 --- a/bitbake/lib/prserv/serv.py +++ b/bitbake/lib/prserv/serv.py | |||
@@ -20,8 +20,8 @@ PIDPREFIX = "/tmp/PRServer_%s_%s.pid" | |||
20 | singleton = None | 20 | singleton = None |
21 | 21 | ||
22 | class PRServerClient(bb.asyncrpc.AsyncServerConnection): | 22 | class PRServerClient(bb.asyncrpc.AsyncServerConnection): |
23 | def __init__(self, reader, writer, table, read_only): | 23 | def __init__(self, socket, table, read_only): |
24 | super().__init__(reader, writer, 'PRSERVICE', logger) | 24 | super().__init__(socket, 'PRSERVICE', logger) |
25 | self.handlers.update({ | 25 | self.handlers.update({ |
26 | 'get-pr': self.handle_get_pr, | 26 | 'get-pr': self.handle_get_pr, |
27 | 'import-one': self.handle_import_one, | 27 | 'import-one': self.handle_import_one, |
@@ -36,12 +36,12 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
36 | 36 | ||
37 | async def dispatch_message(self, msg): | 37 | async def dispatch_message(self, msg): |
38 | try: | 38 | try: |
39 | await super().dispatch_message(msg) | 39 | return await super().dispatch_message(msg) |
40 | except: | 40 | except: |
41 | self.table.sync() | 41 | self.table.sync() |
42 | raise | 42 | raise |
43 | 43 | else: | |
44 | self.table.sync_if_dirty() | 44 | self.table.sync_if_dirty() |
45 | 45 | ||
46 | async def handle_get_pr(self, request): | 46 | async def handle_get_pr(self, request): |
47 | version = request['version'] | 47 | version = request['version'] |
@@ -57,7 +57,7 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
57 | except sqlite3.Error as exc: | 57 | except sqlite3.Error as exc: |
58 | logger.error(str(exc)) | 58 | logger.error(str(exc)) |
59 | 59 | ||
60 | self.write_message(response) | 60 | return response |
61 | 61 | ||
62 | async def handle_import_one(self, request): | 62 | async def handle_import_one(self, request): |
63 | response = None | 63 | response = None |
@@ -71,7 +71,7 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
71 | if value is not None: | 71 | if value is not None: |
72 | response = {'value': value} | 72 | response = {'value': value} |
73 | 73 | ||
74 | self.write_message(response) | 74 | return response |
75 | 75 | ||
76 | async def handle_export(self, request): | 76 | async def handle_export(self, request): |
77 | version = request['version'] | 77 | version = request['version'] |
@@ -85,12 +85,10 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
85 | logger.error(str(exc)) | 85 | logger.error(str(exc)) |
86 | metainfo = datainfo = None | 86 | metainfo = datainfo = None |
87 | 87 | ||
88 | response = {'metainfo': metainfo, 'datainfo': datainfo} | 88 | return {'metainfo': metainfo, 'datainfo': datainfo} |
89 | self.write_message(response) | ||
90 | 89 | ||
91 | async def handle_is_readonly(self, request): | 90 | async def handle_is_readonly(self, request): |
92 | response = {'readonly': self.read_only} | 91 | return {'readonly': self.read_only} |
93 | self.write_message(response) | ||
94 | 92 | ||
95 | class PRServer(bb.asyncrpc.AsyncServer): | 93 | class PRServer(bb.asyncrpc.AsyncServer): |
96 | def __init__(self, dbfile, read_only=False): | 94 | def __init__(self, dbfile, read_only=False): |
@@ -99,20 +97,23 @@ class PRServer(bb.asyncrpc.AsyncServer): | |||
99 | self.table = None | 97 | self.table = None |
100 | self.read_only = read_only | 98 | self.read_only = read_only |
101 | 99 | ||
102 | def accept_client(self, reader, writer): | 100 | def accept_client(self, socket): |
103 | return PRServerClient(reader, writer, self.table, self.read_only) | 101 | return PRServerClient(socket, self.table, self.read_only) |
104 | 102 | ||
105 | def _serve_forever(self): | 103 | def start(self): |
104 | tasks = super().start() | ||
106 | self.db = prserv.db.PRData(self.dbfile, read_only=self.read_only) | 105 | self.db = prserv.db.PRData(self.dbfile, read_only=self.read_only) |
107 | self.table = self.db["PRMAIN"] | 106 | self.table = self.db["PRMAIN"] |
108 | 107 | ||
109 | logger.info("Started PRServer with DBfile: %s, Address: %s, PID: %s" % | 108 | logger.info("Started PRServer with DBfile: %s, Address: %s, PID: %s" % |
110 | (self.dbfile, self.address, str(os.getpid()))) | 109 | (self.dbfile, self.address, str(os.getpid()))) |
111 | 110 | ||
112 | super()._serve_forever() | 111 | return tasks |
113 | 112 | ||
113 | async def stop(self): | ||
114 | self.table.sync_if_dirty() | 114 | self.table.sync_if_dirty() |
115 | self.db.disconnect() | 115 | self.db.disconnect() |
116 | await super().stop() | ||
116 | 117 | ||
117 | def signal_handler(self): | 118 | def signal_handler(self): |
118 | super().signal_handler() | 119 | super().signal_handler() |