oc-cdtapi 3.13.15__py3-none-any.whl → 3.14.0__py3-none-any.whl
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.
- oc_cdtapi/PgQAPI.py +172 -0
- {oc_cdtapi-3.13.15.dist-info → oc_cdtapi-3.14.0.dist-info}/METADATA +4 -1
- {oc_cdtapi-3.13.15.dist-info → oc_cdtapi-3.14.0.dist-info}/RECORD +7 -6
- {oc_cdtapi-3.13.15.dist-info → oc_cdtapi-3.14.0.dist-info}/WHEEL +1 -1
- {oc_cdtapi-3.13.15.data → oc_cdtapi-3.14.0.data}/scripts/nexus.py +0 -0
- {oc_cdtapi-3.13.15.dist-info → oc_cdtapi-3.14.0.dist-info}/LICENSE +0 -0
- {oc_cdtapi-3.13.15.dist-info → oc_cdtapi-3.14.0.dist-info}/top_level.txt +0 -0
oc_cdtapi/PgQAPI.py
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# created 2025-02 https://github.com/ivansa-ru
|
2
|
+
|
3
|
+
import json
|
4
|
+
import logging
|
5
|
+
import os
|
6
|
+
import psycopg2
|
7
|
+
from urllib.parse import urlparse
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
class PgQAPI (object):
|
12
|
+
"""
|
13
|
+
message statuses are:
|
14
|
+
N = new
|
15
|
+
A = active, being processed
|
16
|
+
F = failed
|
17
|
+
P = processed
|
18
|
+
message priority 1-100 the higher value the lower priority (to be implemented)
|
19
|
+
"""
|
20
|
+
|
21
|
+
def __init__(self, pg_connection=None, url=None, username=None, password=None):
|
22
|
+
logging.debug('Initializing PgQAPI')
|
23
|
+
if pg_connection:
|
24
|
+
logging.debug('Using provided connection')
|
25
|
+
self.conn = pg_connection
|
26
|
+
else:
|
27
|
+
logging.debug('No connection provided, creating')
|
28
|
+
self.conn = self.pg_connect(url, username, password)
|
29
|
+
self.message_types = ['dlartifacts', 'dlbuild', 'dlcontents', 'dlupload', 'ns']
|
30
|
+
|
31
|
+
def create_queue(self, queue_code, queue_name):
|
32
|
+
logging.debug('reached create_queue')
|
33
|
+
logging.debug('checking existence of queue with code [%s]' % queue_code)
|
34
|
+
q_id = self.get_queue_id(queue_code)
|
35
|
+
if q_id:
|
36
|
+
logging.error('queue with code [%s] already exists' % queue_code)
|
37
|
+
return None
|
38
|
+
else:
|
39
|
+
csr = self.conn.cursor()
|
40
|
+
q = 'insert into queue_type (code, name, status) values (%s, %s, %s)'
|
41
|
+
csr.execute(q, (queue_code, queue_name, 'A') )
|
42
|
+
self.conn.commit()
|
43
|
+
q_id = self.get_queue_id(queue_code)
|
44
|
+
if q_id:
|
45
|
+
return q_id
|
46
|
+
else:
|
47
|
+
logging.error('failed to create queue')
|
48
|
+
|
49
|
+
def compose_message(self, message_type, parms):
|
50
|
+
logging.debug('reached compose_message')
|
51
|
+
logging.debug('trying to compose message of type [%s]' % message_type)
|
52
|
+
if message_type not in self.message_types:
|
53
|
+
logging.error('unknown message type [%s]' % message_type)
|
54
|
+
return None
|
55
|
+
method_name = f'compose_{message_type}'
|
56
|
+
method = getattr(self, method_name, None)
|
57
|
+
return method(parms)
|
58
|
+
|
59
|
+
def compose_dlbuild(self, parms):
|
60
|
+
logging.debug('reached compose_dlbuild')
|
61
|
+
logging.debug('received parms: [%s]' % parms)
|
62
|
+
tag = parms.get('tag')
|
63
|
+
if not tag:
|
64
|
+
logging.error('no tag specified')
|
65
|
+
return None
|
66
|
+
logging.debug('composing message for tag [%s]' % tag)
|
67
|
+
message = ["build_delivery", [tag], {}]
|
68
|
+
logging.debug('composed message')
|
69
|
+
logging.debug(message)
|
70
|
+
return message
|
71
|
+
|
72
|
+
def enqueue_message(self, queue_code=None, msg_text=None, priority=50, pg_connection=None):
|
73
|
+
logging.debug('reached enqueue_message')
|
74
|
+
if pg_connection:
|
75
|
+
logging.debug('using provided connection')
|
76
|
+
conn = pg_connection
|
77
|
+
else:
|
78
|
+
conn = self.conn
|
79
|
+
logging.debug('will try to create message [%s] in queue [%s]' % (msg_text, queue_code) )
|
80
|
+
q_id = self.get_queue_id(queue_code)
|
81
|
+
csr = conn.cursor()
|
82
|
+
q = 'insert into queue_message (queue_type__oid, status, payload, priority) values (%s, %s, %s, %s)'
|
83
|
+
csr.execute(q, (q_id, 'N', json.dumps(msg_text), priority) )
|
84
|
+
conn.commit()
|
85
|
+
|
86
|
+
def exec_select(self, q, parms=None):
|
87
|
+
logging.debug('reached exec_select')
|
88
|
+
logging.debug('will try to execute [%s] with [%s]' % (q, parms) )
|
89
|
+
csr = self.conn.cursor()
|
90
|
+
csr.execute(q, parms)
|
91
|
+
ds = csr.fetchall()
|
92
|
+
return ds
|
93
|
+
|
94
|
+
def exec_update(self, q, parms=None, commit=True):
|
95
|
+
logging.debug('reached exec_update')
|
96
|
+
logging.debug('will try to execute [%s] with [%s]' % (q, parms) )
|
97
|
+
csr = self.conn.cursor()
|
98
|
+
csr.execute(q, parms)
|
99
|
+
if commit:
|
100
|
+
self.conn.commit()
|
101
|
+
|
102
|
+
def get_msg(self, message_id):
|
103
|
+
logging.debug('reached get_msg')
|
104
|
+
logging.debug('getting status of message [%s]' % message_id)
|
105
|
+
ds = self.exec_select('select status, payload from queue_message where id = %s', (str(message_id) ) )
|
106
|
+
if ds:
|
107
|
+
logging.debug('message found, returning [%s]', ds[0])
|
108
|
+
return ds[0]
|
109
|
+
else:
|
110
|
+
return None
|
111
|
+
|
112
|
+
def get_queue_id(self, queue_code):
|
113
|
+
logging.debug('reached get_queue_id')
|
114
|
+
logging.debug('searching for queue with code [%s]' % queue_code)
|
115
|
+
ds = self.exec_select('select id from queue_type where code = %s', (queue_code, ) )
|
116
|
+
if ds:
|
117
|
+
logging.debug('queue found, returning its id [%s]' % ds[0][0])
|
118
|
+
return ds[0][0]
|
119
|
+
else:
|
120
|
+
logging.error('queue does not exist, returning None')
|
121
|
+
# TODO raise an exception here
|
122
|
+
return None
|
123
|
+
|
124
|
+
def pg_connect(self, url=None, username=None, password=None):
|
125
|
+
logging.debug('reached pg_connect')
|
126
|
+
if (url is None):
|
127
|
+
logging.debug('constructing dsn from env variables')
|
128
|
+
url = os.environ.get('PSQL_MQ_URL')
|
129
|
+
username = os.environ.get('PSQL_MQ_USER')
|
130
|
+
password = os.environ.get('PSQL_MQ_PASSWORD')
|
131
|
+
else:
|
132
|
+
logging.debug('constructing dsn from parameters')
|
133
|
+
dsn = f"postgresql://{username}:{password}@{url}"
|
134
|
+
logging.debug('attempting to connect to [%s]' % url)
|
135
|
+
conn = psycopg2.connect(dsn)
|
136
|
+
if conn:
|
137
|
+
logging.debug('connected. [%s]' % conn)
|
138
|
+
return conn
|
139
|
+
logging.error('failed to connect')
|
140
|
+
return None
|
141
|
+
|
142
|
+
def msg_proc_start(self, message_id):
|
143
|
+
logging.debug('reached msg_proc_start')
|
144
|
+
logging.debug('starting processing of message [%s]' % message_id)
|
145
|
+
ds = self.get_msg(message_id)
|
146
|
+
if not ds:
|
147
|
+
logging.error('message [%s] does not exist' % message_id)
|
148
|
+
return None
|
149
|
+
(msg_status, payload) = ds
|
150
|
+
if msg_status != 'N':
|
151
|
+
logging.error('message [%s] is in bad status [%s]' % (str(message_id), msg_status) )
|
152
|
+
return False
|
153
|
+
self.exec_update('update queue_message set proc_start=now(), status=%s where id = %s', ('A', message_id) )
|
154
|
+
return payload
|
155
|
+
|
156
|
+
def new_msg_from_queue(self, queue_code):
|
157
|
+
logging.debug('reached new_msg_from_queue')
|
158
|
+
logging.debug('checking queue [%s]' % queue_code)
|
159
|
+
queue_id = self.get_queue_id(queue_code)
|
160
|
+
if not queue_id:
|
161
|
+
logging.error('queue [%s] does not exist' % queue_code)
|
162
|
+
return None
|
163
|
+
ds = self.exec_select('select min(id), count(id) from queue_message where queue_type__oid = %s and status = %s', (queue_id, 'N') )
|
164
|
+
if ds[0][1] == 0:
|
165
|
+
logging.debug('currently no new messages in queue [%s]' % queue_code)
|
166
|
+
return None
|
167
|
+
msg_id = ds[0][0]
|
168
|
+
logging.debug('found new message id [%s], [%s] new messages in queue' % (msg_id, ds[0][1]) )
|
169
|
+
logging.debug('setting status of message to A')
|
170
|
+
payload = self.msg_proc_start(msg_id)
|
171
|
+
return payload
|
172
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.2
|
2
2
|
Name: oc-cdtapi
|
3
|
-
Version: 3.
|
3
|
+
Version: 3.14.0
|
4
4
|
Summary: Custom Development python API libraries
|
5
5
|
License: Apache2.0
|
6
6
|
Requires-Python: >=3.6
|
@@ -8,8 +8,11 @@ Description-Content-Type: text/plain
|
|
8
8
|
License-File: LICENSE
|
9
9
|
Requires-Dist: requests
|
10
10
|
Requires-Dist: packaging
|
11
|
+
Dynamic: description
|
11
12
|
Dynamic: description-content-type
|
12
13
|
Dynamic: license
|
13
14
|
Dynamic: requires-dist
|
14
15
|
Dynamic: requires-python
|
15
16
|
Dynamic: summary
|
17
|
+
|
18
|
+
Custom Development python API libraries
|
@@ -6,12 +6,13 @@ oc_cdtapi/DmsGetverAPI.py,sha256=ZPU4HlF59fngKu5mSFhtss3rlBuduffDOSm_y3XWrxk,155
|
|
6
6
|
oc_cdtapi/ForemanAPI.py,sha256=0rMK_C1xSp-S8UcFuz2nE7U0HEVmZKJefCW9T_9ksnU,43106
|
7
7
|
oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
|
8
8
|
oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
|
9
|
+
oc_cdtapi/PgQAPI.py,sha256=bAgwo4YVuD60uAEv7hrjTQmmAfcMP86IBlSNhlXJzWc,6882
|
9
10
|
oc_cdtapi/RundeckAPI.py,sha256=O3LmcFaHSz8UqeUyIHTTEMJncDD191Utd-iZaeJay2s,24243
|
10
11
|
oc_cdtapi/TestServer.py,sha256=HV97UWg2IK4gOYAp9yaMdwFUWsw9v66MxyZdI3qQctA,2715
|
11
12
|
oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
oc_cdtapi-3.
|
13
|
-
oc_cdtapi-3.
|
14
|
-
oc_cdtapi-3.
|
15
|
-
oc_cdtapi-3.
|
16
|
-
oc_cdtapi-3.
|
17
|
-
oc_cdtapi-3.
|
13
|
+
oc_cdtapi-3.14.0.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
|
14
|
+
oc_cdtapi-3.14.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
15
|
+
oc_cdtapi-3.14.0.dist-info/METADATA,sha256=N-EEwBO-9DoGh2Crqvk3x4UZadvKv4W4LPgQMZFRfPA,431
|
16
|
+
oc_cdtapi-3.14.0.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
17
|
+
oc_cdtapi-3.14.0.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
|
18
|
+
oc_cdtapi-3.14.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|