streamflow-postgresql 0.0.3__tar.gz → 0.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/PKG-INFO +2 -2
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/README.md +1 -1
- streamflow-postgresql-0.0.5/lint-requirements.txt +4 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/pyproject.toml +4 -5
- streamflow-postgresql-0.0.5/requirements.txt +2 -0
- streamflow-postgresql-0.0.5/streamflow_postgresql/database.py +539 -0
- {streamflow-postgresql-0.0.3/postgresql → streamflow-postgresql-0.0.5/streamflow_postgresql}/plugin.py +1 -1
- {streamflow-postgresql-0.0.3/postgresql → streamflow-postgresql-0.0.5/streamflow_postgresql}/schemas/postgresql.json +2 -2
- streamflow-postgresql-0.0.5/streamflow_postgresql/version.py +1 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/streamflow_postgresql.egg-info/PKG-INFO +2 -2
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/streamflow_postgresql.egg-info/SOURCES.txt +6 -6
- streamflow-postgresql-0.0.5/streamflow_postgresql.egg-info/entry_points.txt +2 -0
- streamflow-postgresql-0.0.5/streamflow_postgresql.egg-info/requires.txt +17 -0
- streamflow-postgresql-0.0.5/streamflow_postgresql.egg-info/top_level.txt +1 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/test-requirements.txt +1 -1
- streamflow-postgresql-0.0.3/lint-requirements.txt +0 -4
- streamflow-postgresql-0.0.3/postgresql/database.py +0 -582
- streamflow-postgresql-0.0.3/postgresql/version.py +0 -1
- streamflow-postgresql-0.0.3/requirements.txt +0 -3
- streamflow-postgresql-0.0.3/streamflow_postgresql.egg-info/entry_points.txt +0 -2
- streamflow-postgresql-0.0.3/streamflow_postgresql.egg-info/requires.txt +0 -18
- streamflow-postgresql-0.0.3/streamflow_postgresql.egg-info/top_level.txt +0 -1
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/LICENSE +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/MANIFEST.in +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/bandit-requirements.txt +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/setup.cfg +0 -0
- {streamflow-postgresql-0.0.3/postgresql → streamflow-postgresql-0.0.5/streamflow_postgresql}/__init__.py +0 -0
- {streamflow-postgresql-0.0.3/postgresql → streamflow-postgresql-0.0.5/streamflow_postgresql}/schemas/postgresql.sql +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/streamflow_postgresql.egg-info/dependency_links.txt +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/streamflow_postgresql.egg-info/zip-safe +0 -0
- {streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/tests/test_persistence.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: streamflow-postgresql
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: StreamFlow PostgreSQL plugin
|
|
5
5
|
Author-email: Iacopo Colonnelli <iacopo.colonnelli@unito.it>
|
|
6
6
|
License: LGPL-3.0-or-later
|
|
@@ -40,7 +40,7 @@ pip install streamflow-postgresql
|
|
|
40
40
|
If everything worked correctly, whenever a workflow execution start the following message should be printed in the log:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
Successfully registered plugin
|
|
43
|
+
Successfully registered plugin streamflow_postgresql.plugin.PostgreSQLStreamFlowPlugin
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
## Usage
|
|
@@ -11,7 +11,7 @@ pip install streamflow-postgresql
|
|
|
11
11
|
If everything worked correctly, whenever a workflow execution start the following message should be printed in the log:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
Successfully registered plugin
|
|
14
|
+
Successfully registered plugin streamflow_postgresql.plugin.PostgreSQLStreamFlowPlugin
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -34,21 +34,20 @@ Package = "https://pypi.org/project/streamflow-postgresql"
|
|
|
34
34
|
Repository = "https://github.com/alpha-unito/streamflow-postgresql"
|
|
35
35
|
|
|
36
36
|
[project.entry-points]
|
|
37
|
-
"unito.streamflow.plugin" = {"unito.postgresql" = "
|
|
38
|
-
|
|
37
|
+
"unito.streamflow.plugin" = {"unito.postgresql" = "streamflow_postgresql.plugin:PostgreSQLStreamFlowPlugin"}
|
|
39
38
|
|
|
40
39
|
[tool.setuptools]
|
|
41
40
|
packages = [
|
|
42
|
-
"
|
|
41
|
+
"streamflow_postgresql"
|
|
43
42
|
]
|
|
44
43
|
zip-safe = true
|
|
45
44
|
|
|
46
45
|
[tool.setuptools.package-data]
|
|
47
|
-
"
|
|
46
|
+
"streamflow_postgresql" = ["schemas/*.json", "schemas/*.sql"]
|
|
48
47
|
|
|
49
48
|
[tool.setuptools.dynamic]
|
|
50
49
|
dependencies = {file = "requirements.txt"}
|
|
51
|
-
version = {attr = "
|
|
50
|
+
version = {attr = "streamflow_postgresql.version.VERSION"}
|
|
52
51
|
|
|
53
52
|
[tool.setuptools.dynamic.optional-dependencies]
|
|
54
53
|
bandit = {file = "bandit-requirements.txt"}
|
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any, MutableMapping, MutableSequence
|
|
6
|
+
|
|
7
|
+
import asyncpg
|
|
8
|
+
import pkg_resources
|
|
9
|
+
from streamflow.core import utils
|
|
10
|
+
from streamflow.core.context import StreamFlowContext
|
|
11
|
+
from streamflow.core.deployment import Target
|
|
12
|
+
from streamflow.core.persistence import DependencyType
|
|
13
|
+
from streamflow.core.utils import get_date_from_ns
|
|
14
|
+
from streamflow.core.workflow import Port, Status, Step, Token
|
|
15
|
+
from streamflow.persistence.base import CachedDatabase
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class PostgreSQLConnectionPool:
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
dbname: str,
|
|
22
|
+
hostname: str,
|
|
23
|
+
username: str,
|
|
24
|
+
password: str,
|
|
25
|
+
timeout: int,
|
|
26
|
+
maxsize: int = 10,
|
|
27
|
+
):
|
|
28
|
+
self.dbname: str = dbname
|
|
29
|
+
self.hostname: str = hostname
|
|
30
|
+
self.username: str = username
|
|
31
|
+
self.password: str = password
|
|
32
|
+
self.timeout: int = timeout
|
|
33
|
+
self.maxsize: int = maxsize
|
|
34
|
+
self._pool: asyncpg.Pool | None = None
|
|
35
|
+
|
|
36
|
+
async def __aenter__(self):
|
|
37
|
+
if not self._pool:
|
|
38
|
+
self._pool = await asyncpg.create_pool(
|
|
39
|
+
database=self.dbname,
|
|
40
|
+
user=self.username,
|
|
41
|
+
password=self.password,
|
|
42
|
+
host=self.hostname,
|
|
43
|
+
timeout=self.timeout,
|
|
44
|
+
max_size=self.maxsize,
|
|
45
|
+
)
|
|
46
|
+
schema_path = pkg_resources.resource_filename(
|
|
47
|
+
__name__, os.path.join("schemas", "postgresql.sql")
|
|
48
|
+
)
|
|
49
|
+
with open(schema_path) as f:
|
|
50
|
+
async with self._pool.acquire() as conn:
|
|
51
|
+
async with conn.transaction():
|
|
52
|
+
await conn.execute(f.read())
|
|
53
|
+
return self._pool
|
|
54
|
+
|
|
55
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
async def close(self):
|
|
59
|
+
if self._pool:
|
|
60
|
+
await self._pool.close()
|
|
61
|
+
self._pool = None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class PostgreSQLDatabase(CachedDatabase):
|
|
65
|
+
def __init__(
|
|
66
|
+
self,
|
|
67
|
+
context: StreamFlowContext,
|
|
68
|
+
dbname: str,
|
|
69
|
+
hostname: str,
|
|
70
|
+
username: str,
|
|
71
|
+
password: str,
|
|
72
|
+
timeout: int = 20,
|
|
73
|
+
maxConnections: int = 10,
|
|
74
|
+
):
|
|
75
|
+
super().__init__(context)
|
|
76
|
+
self.pool: PostgreSQLConnectionPool = PostgreSQLConnectionPool(
|
|
77
|
+
dbname=dbname,
|
|
78
|
+
hostname=hostname,
|
|
79
|
+
username=username,
|
|
80
|
+
password=password,
|
|
81
|
+
timeout=timeout,
|
|
82
|
+
maxsize=maxConnections,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
async def close(self):
|
|
86
|
+
await self.pool.close()
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def get_schema(cls) -> str:
|
|
90
|
+
return pkg_resources.resource_filename(
|
|
91
|
+
__name__, os.path.join("schemas", "postgresql.json")
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
async def add_command(self, step_id: int, tag: str, cmd: str) -> int:
|
|
95
|
+
async with self.pool as pool:
|
|
96
|
+
async with pool.acquire() as conn:
|
|
97
|
+
async with conn.transaction():
|
|
98
|
+
return await conn.fetchval(
|
|
99
|
+
"INSERT INTO command(step, tag, cmd) "
|
|
100
|
+
"VALUES($1, $2, $3) "
|
|
101
|
+
"RETURNING id",
|
|
102
|
+
step_id,
|
|
103
|
+
tag,
|
|
104
|
+
cmd.encode("utf-8"),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
async def add_dependency(
|
|
108
|
+
self, step: int, port: int, type: DependencyType, name: str
|
|
109
|
+
) -> None:
|
|
110
|
+
async with self.pool as pool:
|
|
111
|
+
async with pool.acquire() as conn:
|
|
112
|
+
async with conn.transaction():
|
|
113
|
+
await conn.execute(
|
|
114
|
+
"INSERT INTO dependency(step, port, type, name) "
|
|
115
|
+
"VALUES($1, $2, $3, $4) "
|
|
116
|
+
"ON CONFLICT DO NOTHING",
|
|
117
|
+
step,
|
|
118
|
+
port,
|
|
119
|
+
type.value,
|
|
120
|
+
name,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
async def add_deployment(
|
|
124
|
+
self,
|
|
125
|
+
name: str,
|
|
126
|
+
type: str,
|
|
127
|
+
config: str,
|
|
128
|
+
external: bool,
|
|
129
|
+
lazy: bool,
|
|
130
|
+
workdir: str | None,
|
|
131
|
+
) -> int:
|
|
132
|
+
async with self.pool as pool:
|
|
133
|
+
async with pool.acquire() as conn:
|
|
134
|
+
async with conn.transaction():
|
|
135
|
+
return await conn.fetchval(
|
|
136
|
+
"INSERT INTO deployment(name, type, config, external, lazy, workdir) "
|
|
137
|
+
"VALUES ($1, $2, $3, $4, $5, $6) "
|
|
138
|
+
"RETURNING id",
|
|
139
|
+
name,
|
|
140
|
+
type,
|
|
141
|
+
config,
|
|
142
|
+
external,
|
|
143
|
+
lazy,
|
|
144
|
+
workdir,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
async def add_port(
|
|
148
|
+
self, name: str, workflow_id: int, type: type[Port], params: str
|
|
149
|
+
) -> int:
|
|
150
|
+
async with self.pool as pool:
|
|
151
|
+
async with pool.acquire() as conn:
|
|
152
|
+
async with conn.transaction():
|
|
153
|
+
return await conn.fetchval(
|
|
154
|
+
"INSERT INTO port(name, workflow, type, params) "
|
|
155
|
+
"VALUES($1, $2, $3, $4) "
|
|
156
|
+
"RETURNING id",
|
|
157
|
+
name,
|
|
158
|
+
workflow_id,
|
|
159
|
+
utils.get_class_fullname(type),
|
|
160
|
+
json.dumps(params),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
async def add_provenance(self, inputs: MutableSequence[int], token: int):
|
|
164
|
+
async with self.pool as pool:
|
|
165
|
+
async with pool.acquire() as conn:
|
|
166
|
+
async with conn.transaction():
|
|
167
|
+
await conn.executemany(
|
|
168
|
+
"INSERT INTO provenance(dependee, depender) "
|
|
169
|
+
"VALUES($1, $2) "
|
|
170
|
+
"ON CONFLICT DO NOTHING",
|
|
171
|
+
[(i, token) for i in inputs],
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
async def add_step(
|
|
175
|
+
self, name: str, workflow_id: int, status: int, type: type[Step], params: str
|
|
176
|
+
) -> int:
|
|
177
|
+
async with self.pool as pool:
|
|
178
|
+
async with pool.acquire() as conn:
|
|
179
|
+
async with conn.transaction():
|
|
180
|
+
return await conn.fetchval(
|
|
181
|
+
"INSERT INTO step(name, workflow, status, type, params) "
|
|
182
|
+
"VALUES($1, $2, $3, $4, $5) "
|
|
183
|
+
"RETURNING id",
|
|
184
|
+
name,
|
|
185
|
+
workflow_id,
|
|
186
|
+
status,
|
|
187
|
+
utils.get_class_fullname(type),
|
|
188
|
+
json.dumps(params),
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
async def add_target(
|
|
192
|
+
self,
|
|
193
|
+
deployment: int,
|
|
194
|
+
type: type[Target],
|
|
195
|
+
params: str,
|
|
196
|
+
locations: int = 1,
|
|
197
|
+
service: str | None = None,
|
|
198
|
+
workdir: str | None = None,
|
|
199
|
+
) -> int:
|
|
200
|
+
async with self.pool as pool:
|
|
201
|
+
async with pool.acquire() as conn:
|
|
202
|
+
async with conn.transaction():
|
|
203
|
+
return await conn.fetchval(
|
|
204
|
+
"INSERT INTO target(params, type, deployment, locations, service, workdir) "
|
|
205
|
+
"VALUES ($1, $2, $3, $4, $5, $6) "
|
|
206
|
+
"RETURNING id",
|
|
207
|
+
json.dumps(params),
|
|
208
|
+
utils.get_class_fullname(type),
|
|
209
|
+
deployment,
|
|
210
|
+
locations,
|
|
211
|
+
service,
|
|
212
|
+
workdir,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
async def add_token(
|
|
216
|
+
self, tag: str, type: type[Token], value: Any, port: int | None = None
|
|
217
|
+
) -> int:
|
|
218
|
+
async with self.pool as pool:
|
|
219
|
+
async with pool.acquire() as conn:
|
|
220
|
+
async with conn.transaction():
|
|
221
|
+
return await conn.fetchval(
|
|
222
|
+
"INSERT INTO token(port, type, tag, value) "
|
|
223
|
+
"VALUES($1, $2, $3, $4) "
|
|
224
|
+
"RETURNING id",
|
|
225
|
+
port,
|
|
226
|
+
utils.get_class_fullname(type),
|
|
227
|
+
tag,
|
|
228
|
+
bytearray(value, "utf-8"),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
async def add_workflow(self, name: str, params: str, status: int, type: str) -> int:
|
|
232
|
+
async with self.pool as pool:
|
|
233
|
+
async with pool.acquire() as conn:
|
|
234
|
+
async with conn.transaction():
|
|
235
|
+
return await conn.fetchval(
|
|
236
|
+
"INSERT INTO workflow(name, params, status, type) "
|
|
237
|
+
"VALUES($1, $2, $3, $4) "
|
|
238
|
+
"RETURNING id",
|
|
239
|
+
name,
|
|
240
|
+
json.dumps(params),
|
|
241
|
+
status,
|
|
242
|
+
type,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
async def get_command(self, command_id: int) -> MutableMapping[str, Any]:
|
|
246
|
+
async with self.pool as pool:
|
|
247
|
+
async with pool.acquire() as conn:
|
|
248
|
+
row = await conn.fetchrow(
|
|
249
|
+
"SELECT * FROM command WHERE id = $1", command_id
|
|
250
|
+
)
|
|
251
|
+
return {
|
|
252
|
+
k: bytearray(v) if isinstance(v, memoryview) else v
|
|
253
|
+
for k, v in row.items()
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async def get_commands_by_step(
|
|
257
|
+
self, step_id: int
|
|
258
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
259
|
+
async with self.pool as pool:
|
|
260
|
+
async with pool.acquire() as conn:
|
|
261
|
+
rows = await conn.fetch(
|
|
262
|
+
"SELECT * FROM command WHERE step = $1", step_id
|
|
263
|
+
)
|
|
264
|
+
return [
|
|
265
|
+
{
|
|
266
|
+
k: bytearray(v) if isinstance(v, memoryview) else v
|
|
267
|
+
for k, v in row.items()
|
|
268
|
+
}
|
|
269
|
+
for row in rows
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
async def get_dependees(
|
|
273
|
+
self, token_id: int
|
|
274
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
275
|
+
async with self.pool as pool:
|
|
276
|
+
async with pool.acquire() as conn:
|
|
277
|
+
return await conn.fetch(
|
|
278
|
+
"SELECT * FROM provenance WHERE depender = $1",
|
|
279
|
+
token_id,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
async def get_dependers(
|
|
283
|
+
self, token_id: int
|
|
284
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
285
|
+
async with self.pool as pool:
|
|
286
|
+
async with pool.acquire() as conn:
|
|
287
|
+
return await conn.fetch(
|
|
288
|
+
"SELECT * FROM provenance WHERE dependee = $1",
|
|
289
|
+
token_id,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
async def get_deployment(self, deplyoment_id: int) -> MutableMapping[str, Any]:
|
|
293
|
+
async with self.pool as pool:
|
|
294
|
+
async with pool.acquire() as conn:
|
|
295
|
+
return await conn.fetchrow(
|
|
296
|
+
"SELECT * FROM deployment WHERE id = $1",
|
|
297
|
+
deplyoment_id,
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
async def get_input_ports(
|
|
301
|
+
self, step_id: int
|
|
302
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
303
|
+
async with self.pool as pool:
|
|
304
|
+
async with pool.acquire() as conn:
|
|
305
|
+
return await conn.fetch(
|
|
306
|
+
"SELECT * FROM dependency WHERE step = $1 AND type = $2",
|
|
307
|
+
step_id,
|
|
308
|
+
DependencyType.INPUT.value,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
async def get_output_ports(
|
|
312
|
+
self, step_id: int
|
|
313
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
314
|
+
async with self.pool as pool:
|
|
315
|
+
async with pool.acquire() as conn:
|
|
316
|
+
return await conn.fetch(
|
|
317
|
+
"SELECT * FROM dependency WHERE step = $1 AND type = $2",
|
|
318
|
+
step_id,
|
|
319
|
+
DependencyType.OUTPUT.value,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
async def get_port(self, port_id: int) -> MutableMapping[str, Any]:
|
|
323
|
+
async with self.pool as pool:
|
|
324
|
+
async with pool.acquire() as conn:
|
|
325
|
+
return await conn.fetchrow("SELECT * FROM port WHERE id = $1", port_id)
|
|
326
|
+
|
|
327
|
+
async def get_port_tokens(self, port_id: int) -> MutableSequence[int]:
|
|
328
|
+
async with self.pool as pool:
|
|
329
|
+
async with pool.acquire() as conn:
|
|
330
|
+
rows = await conn.fetch("SELECT * FROM port WHERE id = $1", port_id)
|
|
331
|
+
return [row["id"] for row in rows]
|
|
332
|
+
|
|
333
|
+
async def get_reports(
|
|
334
|
+
self, workflow: str, last_only: bool = False
|
|
335
|
+
) -> MutableSequence[MutableSequence[MutableMapping[str, Any]]]:
|
|
336
|
+
async with self.pool as pool:
|
|
337
|
+
async with pool.acquire() as conn:
|
|
338
|
+
if last_only:
|
|
339
|
+
rows = await conn.fetch(
|
|
340
|
+
"SELECT c.id, s.name, c.start_time, c.end_time "
|
|
341
|
+
"FROM step AS s, command AS c "
|
|
342
|
+
"WHERE s.id = c.step "
|
|
343
|
+
"AND s.workflow = ("
|
|
344
|
+
"SELECT id FROM workflow "
|
|
345
|
+
"WHERE name = $1 "
|
|
346
|
+
"ORDER BY id DESC LIMIT 1)",
|
|
347
|
+
workflow,
|
|
348
|
+
)
|
|
349
|
+
return [[dict(r) for r in rows]]
|
|
350
|
+
else:
|
|
351
|
+
async with conn.transaction():
|
|
352
|
+
cursor = conn.cursor(
|
|
353
|
+
"SELECT s.workflow, c.id, s.name, c.start_time, c.end_time "
|
|
354
|
+
"FROM step AS s, command AS c "
|
|
355
|
+
"WHERE s.id = c.step "
|
|
356
|
+
"AND s.workflow IN (SELECT id FROM workflow WHERE name = $1) "
|
|
357
|
+
"ORDER BY s.workflow DESC",
|
|
358
|
+
workflow,
|
|
359
|
+
)
|
|
360
|
+
result = {}
|
|
361
|
+
async for row in cursor:
|
|
362
|
+
result.setdefault(row["workflow"], []).append(
|
|
363
|
+
{k: row[k] for k in row.keys() if k != "workflow"}
|
|
364
|
+
)
|
|
365
|
+
return list(result.values())
|
|
366
|
+
|
|
367
|
+
async def get_step(self, step_id: int) -> MutableMapping[str, Any]:
|
|
368
|
+
async with self.pool as pool:
|
|
369
|
+
async with pool.acquire() as conn:
|
|
370
|
+
return await conn.fetchrow("SELECT * FROM step WHERE id = $1", step_id)
|
|
371
|
+
|
|
372
|
+
async def get_target(self, target_id: int) -> MutableMapping[str, Any]:
|
|
373
|
+
async with self.pool as pool:
|
|
374
|
+
async with pool.acquire() as conn:
|
|
375
|
+
return await conn.fetchrow(
|
|
376
|
+
"SELECT * FROM target WHERE id = $1", target_id
|
|
377
|
+
)
|
|
378
|
+
|
|
379
|
+
async def get_token(self, token_id: int) -> MutableMapping[str, Any]:
|
|
380
|
+
async with self.pool as pool:
|
|
381
|
+
async with pool.acquire() as conn:
|
|
382
|
+
row = await conn.fetchrow("SELECT * FROM token WHERE id = $1", token_id)
|
|
383
|
+
return {
|
|
384
|
+
k: bytearray(v) if isinstance(v, memoryview) else v
|
|
385
|
+
for k, v in row.items()
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async def get_workflow(self, workflow_id: int) -> MutableMapping[str, Any]:
|
|
389
|
+
async with self.pool as pool:
|
|
390
|
+
async with pool.acquire() as conn:
|
|
391
|
+
return await conn.fetchrow(
|
|
392
|
+
"SELECT * FROM workflow WHERE id = $1", workflow_id
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
async def get_workflow_ports(
|
|
396
|
+
self, workflow_id: int
|
|
397
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
398
|
+
async with self.pool as pool:
|
|
399
|
+
async with pool.acquire() as conn:
|
|
400
|
+
return await conn.fetch(
|
|
401
|
+
"SELECT * FROM port WHERE workflow = $1",
|
|
402
|
+
workflow_id,
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
async def get_workflow_steps(
|
|
406
|
+
self, workflow_id: int
|
|
407
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
408
|
+
async with self.pool as pool:
|
|
409
|
+
async with pool.acquire() as conn:
|
|
410
|
+
return await conn.fetch(
|
|
411
|
+
"SELECT * FROM step WHERE workflow = $1",
|
|
412
|
+
workflow_id,
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
async def get_workflows_by_name(
|
|
416
|
+
self, workflow_name: str, last_only: bool = False
|
|
417
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
418
|
+
async with self.pool as pool:
|
|
419
|
+
async with pool.acquire() as conn:
|
|
420
|
+
query = "SELECT * FROM workflow WHERE name = $1 ORDER BY id desc"
|
|
421
|
+
return (
|
|
422
|
+
[conn.fetchrow(query, workflow_name)]
|
|
423
|
+
if last_only
|
|
424
|
+
else conn.fetch(query, workflow_name)
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
async def get_workflows_list(
|
|
428
|
+
self, name: str | None
|
|
429
|
+
) -> MutableSequence[MutableMapping[str, Any]]:
|
|
430
|
+
if name is not None:
|
|
431
|
+
return [
|
|
432
|
+
{
|
|
433
|
+
"end_time": get_date_from_ns(row["end_time"]),
|
|
434
|
+
"start_time": get_date_from_ns(row["start_time"]),
|
|
435
|
+
"status": Status(row["status"]).name,
|
|
436
|
+
"type": row["type"],
|
|
437
|
+
}
|
|
438
|
+
for row in await self.get_workflows_by_name(name, last_only=False)
|
|
439
|
+
]
|
|
440
|
+
else:
|
|
441
|
+
async with self.pool as pool:
|
|
442
|
+
async with pool.acquire() as conn:
|
|
443
|
+
return await conn.fetch(
|
|
444
|
+
"SELECT name, type, COUNT(*) AS num "
|
|
445
|
+
"FROM workflow GROUP BY name, type "
|
|
446
|
+
"ORDER BY name DESC"
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
async def update_command(
|
|
450
|
+
self, command_id: int, updates: MutableMapping[str, Any]
|
|
451
|
+
) -> int:
|
|
452
|
+
async with self.pool as pool:
|
|
453
|
+
async with pool.acquire() as conn:
|
|
454
|
+
async with conn.transaction():
|
|
455
|
+
await conn.execute(
|
|
456
|
+
"UPDATE command SET {} WHERE id = $1".format( # nosec
|
|
457
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
458
|
+
),
|
|
459
|
+
command_id,
|
|
460
|
+
*updates.values(),
|
|
461
|
+
)
|
|
462
|
+
self.port_cache.pop(command_id, None)
|
|
463
|
+
return command_id
|
|
464
|
+
|
|
465
|
+
async def update_deployment(
|
|
466
|
+
self, deployment_id: int, updates: MutableMapping[str, Any]
|
|
467
|
+
) -> int:
|
|
468
|
+
async with self.pool as pool:
|
|
469
|
+
async with pool.acquire() as conn:
|
|
470
|
+
async with conn.transaction():
|
|
471
|
+
await conn.execute(
|
|
472
|
+
"UPDATE deployment SET {} WHERE id = $1".format( # nosec
|
|
473
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
474
|
+
),
|
|
475
|
+
deployment_id,
|
|
476
|
+
*updates.values(),
|
|
477
|
+
)
|
|
478
|
+
self.port_cache.pop(deployment_id, None)
|
|
479
|
+
return deployment_id
|
|
480
|
+
|
|
481
|
+
async def update_port(self, port_id: int, updates: MutableMapping[str, Any]) -> int:
|
|
482
|
+
async with self.pool as pool:
|
|
483
|
+
async with pool.acquire() as conn:
|
|
484
|
+
async with conn.transaction():
|
|
485
|
+
await conn.execute(
|
|
486
|
+
"UPDATE port SET {} WHERE id = $1".format( # nosec
|
|
487
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
488
|
+
),
|
|
489
|
+
port_id,
|
|
490
|
+
*updates.values(),
|
|
491
|
+
)
|
|
492
|
+
self.port_cache.pop(port_id, None)
|
|
493
|
+
return port_id
|
|
494
|
+
|
|
495
|
+
async def update_step(self, step_id: int, updates: MutableMapping[str, Any]) -> int:
|
|
496
|
+
async with self.pool as pool:
|
|
497
|
+
async with pool.acquire() as conn:
|
|
498
|
+
async with conn.transaction():
|
|
499
|
+
await conn.execute(
|
|
500
|
+
"UPDATE step SET {} WHERE id = $1".format( # nosec
|
|
501
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
502
|
+
),
|
|
503
|
+
step_id,
|
|
504
|
+
*updates.values(),
|
|
505
|
+
)
|
|
506
|
+
self.step_cache.pop(step_id, None)
|
|
507
|
+
return step_id
|
|
508
|
+
|
|
509
|
+
async def update_target(
|
|
510
|
+
self, target_id: int, updates: MutableMapping[str, Any]
|
|
511
|
+
) -> int:
|
|
512
|
+
async with self.pool as pool:
|
|
513
|
+
async with pool.acquire() as conn:
|
|
514
|
+
async with conn.transaction():
|
|
515
|
+
await conn.execute(
|
|
516
|
+
"UPDATE target SET {} WHERE id = $1".format( # nosec
|
|
517
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
518
|
+
),
|
|
519
|
+
target_id,
|
|
520
|
+
*updates.values(),
|
|
521
|
+
)
|
|
522
|
+
self.target_cache.pop(target_id, None)
|
|
523
|
+
return target_id
|
|
524
|
+
|
|
525
|
+
async def update_workflow(
|
|
526
|
+
self, workflow_id: int, updates: MutableMapping[str, Any]
|
|
527
|
+
) -> int:
|
|
528
|
+
async with self.pool as pool:
|
|
529
|
+
async with pool.acquire() as conn:
|
|
530
|
+
async with conn.transaction():
|
|
531
|
+
await conn.execute(
|
|
532
|
+
"UPDATE workflow SET {} WHERE id = $1".format( # nosec
|
|
533
|
+
", ".join([f"{k} = ${i+2}" for i, k in enumerate(updates)])
|
|
534
|
+
),
|
|
535
|
+
workflow_id,
|
|
536
|
+
*updates.values(),
|
|
537
|
+
)
|
|
538
|
+
self.workflow_cache.pop(workflow_id, None)
|
|
539
|
+
return workflow_id
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
3
|
-
"$id": "postgresql.json",
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
3
|
+
"$id": "https://streamflow.di.unito.it/schemas/plugins/postgresql/postgresql.json",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
6
|
"dbname": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VERSION = "0.0.5"
|
{streamflow-postgresql-0.0.3 → streamflow-postgresql-0.0.5}/streamflow_postgresql.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: streamflow-postgresql
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: StreamFlow PostgreSQL plugin
|
|
5
5
|
Author-email: Iacopo Colonnelli <iacopo.colonnelli@unito.it>
|
|
6
6
|
License: LGPL-3.0-or-later
|
|
@@ -40,7 +40,7 @@ pip install streamflow-postgresql
|
|
|
40
40
|
If everything worked correctly, whenever a workflow execution start the following message should be printed in the log:
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
|
-
Successfully registered plugin
|
|
43
|
+
Successfully registered plugin streamflow_postgresql.plugin.PostgreSQLStreamFlowPlugin
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
## Usage
|
|
@@ -6,12 +6,10 @@ lint-requirements.txt
|
|
|
6
6
|
pyproject.toml
|
|
7
7
|
requirements.txt
|
|
8
8
|
test-requirements.txt
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
postgresql/schemas/postgresql.json
|
|
14
|
-
postgresql/schemas/postgresql.sql
|
|
9
|
+
streamflow_postgresql/__init__.py
|
|
10
|
+
streamflow_postgresql/database.py
|
|
11
|
+
streamflow_postgresql/plugin.py
|
|
12
|
+
streamflow_postgresql/version.py
|
|
15
13
|
streamflow_postgresql.egg-info/PKG-INFO
|
|
16
14
|
streamflow_postgresql.egg-info/SOURCES.txt
|
|
17
15
|
streamflow_postgresql.egg-info/dependency_links.txt
|
|
@@ -19,4 +17,6 @@ streamflow_postgresql.egg-info/entry_points.txt
|
|
|
19
17
|
streamflow_postgresql.egg-info/requires.txt
|
|
20
18
|
streamflow_postgresql.egg-info/top_level.txt
|
|
21
19
|
streamflow_postgresql.egg-info/zip-safe
|
|
20
|
+
streamflow_postgresql/schemas/postgresql.json
|
|
21
|
+
streamflow_postgresql/schemas/postgresql.sql
|
|
22
22
|
tests/test_persistence.py
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
asyncpg==0.28.0
|
|
2
|
+
streamflow==0.2.0.dev8
|
|
3
|
+
|
|
4
|
+
[bandit]
|
|
5
|
+
bandit==1.7.5
|
|
6
|
+
|
|
7
|
+
[lint]
|
|
8
|
+
black==23.7.0
|
|
9
|
+
codespell==2.2.5
|
|
10
|
+
flake8-bugbear==23.7.10
|
|
11
|
+
pyupgrade==3.10.1
|
|
12
|
+
|
|
13
|
+
[test]
|
|
14
|
+
pytest==7.4.0
|
|
15
|
+
pytest-asyncio==0.21.1
|
|
16
|
+
pytest-cov==4.1.0
|
|
17
|
+
pytest-xdist==3.3.1
|