Skip to content

Commit 402b45c

Browse files
author
Daniel Abercrombie
authored
Merge pull request #117 from dabercro/oracle
Major updates
2 parents e34d3dd + a437b25 commit 402b45c

26 files changed

Lines changed: 1930 additions & 726 deletions

bin/workflowtool

Lines changed: 5 additions & 678 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
'cherrypy<18.0.0',
2323
'mako',
2424
'numpy>=1.6.1',
25-
'scipy>=0.19.1',
25+
'scipy==1.1.0',
2626
'sklearn',
2727
'passlib>=1.6',
2828
'bcrypt',
2929
'pyOpenSSL',
3030
'pyyaml',
3131
'validators',
3232
'tabulate',
33-
'pymongo<3.5.0'
33+
'pymongo<3.5.0',
34+
'cx_Oracle'
3435
]
3536
)

workflowwebtools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
:author: Daniel Abercrombie <dabercro@mit.edu>
55
"""
66

7-
__version__ = '0.5.0'
7+
__version__ = '0.8.2'
88

99
__all__ = []

workflowwebtools/clusterworkflows.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def get_workflow_vectors(workflows, session=None, allmap=None):
7979
settings = serverconfig.config_dict()['cluster'][column]
8080
column_output[column] = [numpy.zeros(len(allmap[column])) for _ in workflows]
8181

82+
cherrypy.log('Getting db_lock: 3')
8283
curs.db_lock.acquire()
8384
curs.curs.execute("SELECT SUM(numbererrors), {0}, stepname "
8485
"FROM workflows "
@@ -96,6 +97,7 @@ def get_workflow_vectors(workflows, session=None, allmap=None):
9697
if stepname:
9798
wfname = stepname.split('/')[1]
9899

100+
cherrypy.log('releasing db_lock: 3')
99101
curs.db_lock.release()
100102

101103
# Preprocessing here

workflowwebtools/default/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ cluster:
8181
cache_refresh:
8282
errors: 345600
8383
workspace: '.'
84+
refresh_period: 15

workflowwebtools/errorinfo.py

Whitespace-only changes.

workflowwebtools/errorutils.py

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,33 @@
1414

1515
import validators
1616
import cherrypy
17+
import cx_Oracle
1718

1819
from cmstoolbox import sitereadiness
1920
from cmstoolbox.webtools import get_json
2021

2122
from . import workflowinfo
2223
from . import serverconfig
2324

25+
def errors_from_list(workflows):
26+
"""
27+
:param list workflows: A list of workflows that are in assistance-manual
28+
:returns: The errors for the workflows
29+
:rtype: dict
30+
"""
31+
indict = {}
32+
33+
for workflow in workflows:
34+
base = workflowinfo.WorkflowInfo(workflow)
35+
prep_id = base.get_prep_id()
36+
for wkf in set(workflowinfo.PrepIDInfo(prep_id).get_workflows()):
37+
indict.update(
38+
workflowinfo.WorkflowInfo(wkf).get_errors(get_unreported=True)
39+
)
40+
41+
return indict
42+
43+
2444
def open_location(data_location):
2545
"""
2646
This function assumes that the contents of the location is in JSON format.
@@ -30,8 +50,19 @@ def open_location(data_location):
3050
:returns: information in the JSON file
3151
:rtype: dict
3252
"""
53+
config_dict = serverconfig.config_dict()
54+
55+
if 'oracle' in config_dict:
56+
oracle_db_conn = cx_Oracle.connect(*config_dict['oracle']) # pylint:disable=c-extension-no-member
57+
oracle_cursor = oracle_db_conn.cursor()
58+
oracle_cursor.execute(
59+
"SELECT NAME FROM CMS_UNIFIED_ADMIN.workflow WHERE lower(STATUS) LIKE '%manual%'")
60+
wkfs = [row for row, in oracle_cursor]
61+
oracle_db_conn.close()
62+
cherrypy.log('Number of workflows from database: %i' % len(wkfs))
63+
return errors_from_list(wkfs)
64+
3365
raw = None
34-
indict = {}
3566

3667
if os.path.isfile(data_location):
3768
with open(data_location, 'r') as input_file:
@@ -41,7 +72,7 @@ def open_location(data_location):
4172
components = urlparse.urlparse(data_location)
4273

4374
# Anything we need for the Shibboleth cookie could be in the config file
44-
cookie_stuff = serverconfig.config_dict()['data']
75+
cookie_stuff = config_dict['data']
4576

4677
raw = get_json(components.netloc, components.path,
4778
use_https=True,
@@ -56,16 +87,10 @@ def open_location(data_location):
5687
if not (keys and isinstance(raw[keys[0]], list)):
5788
return raw
5889

59-
for workflow, statuses in raw.iteritems():
60-
if True in ['manual' in status for status in statuses]:
61-
base = workflowinfo.WorkflowInfo(workflow)
62-
prep_id = base.get_prep_id()
63-
for wkf in set(workflowinfo.PrepIDInfo(prep_id).get_workflows()):
64-
indict.update(
65-
workflowinfo.WorkflowInfo(wkf).get_errors(get_unreported=True)
66-
)
67-
68-
return indict
90+
return errors_from_list([
91+
workflow for workflow, statuses in raw.iteritems()
92+
if True in ['manual' in status for status in statuses]
93+
])
6994

7095

7196
def get_list_info(status_list):

workflowwebtools/globalerrors.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ def execute(self, query, params=None):
6868
:rtype: list
6969
"""
7070

71+
output = []
72+
7173
self.db_lock.acquire()
72-
if params:
73-
self.curs.execute(query, params)
74-
else:
75-
self.curs.execute(query)
74+
curs = self.conn.cursor()
75+
try:
76+
if params:
77+
curs.execute(query, params)
78+
else:
79+
curs.execute(query)
7680

77-
output = list(self.curs.fetchall())
78-
self.db_lock.release()
81+
output = list(curs.fetchall())
82+
finally:
83+
self.db_lock.release()
7984

8085
return output
8186

@@ -258,11 +263,13 @@ def get_step_list(self, workflow):
258263

259264
if self._step_list is None:
260265
self._step_list = defaultdict(list)
266+
cherrypy.log('Getting db_lock: 2')
261267
self.db_lock.acquire()
262268
self.curs.execute('SELECT DISTINCT(stepname) FROM workflows ORDER BY stepname')
263269
for tup in self.curs.fetchall():
264270
stepname = tup[0]
265271
self._step_list[stepname.split('/')[1]].append(stepname)
272+
cherrypy.log('Releasing db_lock: 2')
266273
self.db_lock.release()
267274

268275
return self._step_list[workflow]
@@ -324,32 +331,39 @@ def check_session(session, can_refresh=False):
324331
"""
325332

326333
if session:
334+
cherrypy.log('Getting global lock: 1')
327335
GLOBAL_LOCK.acquire()
328336
if session.get('lock') is None:
329337
session['lock'] = threading.Lock()
338+
cherrypy.log('Releasing global lock: 1')
330339
GLOBAL_LOCK.release()
331340

341+
cherrypy.log('Getting session lock')
332342
session['lock'].acquire()
333343

334344
if session.get('info') is None:
335345
session['info'] = ErrorInfo()
336346
theinfo = session.get('info')
337347

338348
else:
349+
cherrypy.log('Getting global lock: 2')
339350
GLOBAL_LOCK.acquire()
340351
global GLOBAL_INFO
341352
if GLOBAL_INFO is None:
342353
GLOBAL_INFO = ErrorInfo()
343354

344355
theinfo = GLOBAL_INFO
356+
cherrypy.log('Releasing global lock: 2')
345357
GLOBAL_LOCK.release()
346358

347359
# If session ErrorInfo is old, set up another connection
348-
if can_refresh and theinfo.timestamp < time.time() - 60*30:
360+
if can_refresh and theinfo.timestamp < time.time() - \
361+
60*serverconfig.config_dict()['refresh_period']:
349362
theinfo.teardown()
350363
theinfo.setup()
351364

352365
if session:
366+
cherrypy.log('Releasing session lock')
353367
session['lock'].release()
354368

355369
return theinfo

workflowwebtools/manageactions.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ def submitaction(user, workflows, action, session=None, **kwargs):
180180
return workflows, reasons, params
181181

182182

183+
def submit2(documents): # pylint: disable=missing-docstring
184+
coll = get_actions_collection()
185+
186+
for document in documents:
187+
workflow = document['workflow']
188+
params = document['parameters']
189+
190+
cherrypy.log('About to insert workflow: %s action: %s' % (workflow, params))
191+
192+
coll.update_one({'workflow': workflow},
193+
{'$set':
194+
{'timestamp': int(time.time()),
195+
'parameters': params,
196+
'acted': 0}},
197+
upsert=True)
198+
199+
183200
def get_actions(num_days=None, num_hours=24, acted=0):
184201
"""Get the recent actions to be acted on in dictionary form
185202

workflowwebtools/predict/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)