Skip to content

Commit 4df640d

Browse files
authored
Merge pull request #4 from XENONnT/rundb_surgery
Rundb surgery
2 parents 2aa6cea + 6a0dabf commit 4df640d

File tree

8 files changed

+44
-227
lines changed

8 files changed

+44
-227
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.pydevproject
33
__pycache__
44
*.dbtoken
5+
outsource.egg-info
56

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# outsource
22
Job submission code for XENONnT
33

4+
## Installation
5+
TODO
6+
7+
Outsource requires modules from [utilix](https://github.com/XENONnT/utilix)
8+
49
## Configuration file
510

6-
This tool expects a configuration file named `$HOME/.xenonnt.conf`. Note that
7-
environment variables can be used in the form `$HOME`. Example:
11+
Just like utilix, this tool expects a configuration file named `$HOME/.xenonnt.conf`. Particularly it uses information in the field of the config with header 'Outsource', see below:
812

9-
[Common]
13+
[RunDB]
1014

1115
rundb_api_url = [ask Evan]
1216
rundb_api_user = [ask Evan]

outsource/Config.py

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
1-
import re
2-
import os
3-
import time
4-
import configparser
5-
6-
dir_raw = '/xenon/xenon1t/raw'
7-
8-
9-
class EnvInterpolation(configparser.BasicInterpolation):
10-
'''Interpolation which expands environment variables in values.'''
111

12-
def before_get(self, parser, section, option, value, defaults):
13-
return os.path.expandvars(value)
14-
15-
16-
class Config():
17-
18-
# singleton
19-
instance = None
20-
21-
def __init__(self):
22-
if not Config.instance:
23-
Config.instance = Config.__Config()
24-
2+
import os
3+
from utilix.config import Config
254

26-
def __getattr__(self, name):
27-
return getattr(self.instance, name)
28-
29-
30-
class __Config(configparser.ConfigParser):
31-
32-
def __init__(self):
33-
34-
config_file_path = os.path.join(os.environ['HOME'], '.xenonnt.conf')
35-
print('Loading configuration from %s' %(config_file_path))
36-
37-
configparser.ConfigParser.__init__(self, interpolation=EnvInterpolation())
38-
try:
39-
self.readfp(open(config_file_path), 'r')
40-
except FileNotFoundError as e:
41-
raise RuntimeError('Unable to open %s. Please see the README for an example configuration' %(config_file_path)) from e
5+
config = Config()
426

43-
def base_dir(self):
44-
return os.path.dirname(__file__)
45-
46-
def work_dir(self):
47-
return self.get('Outsource', 'work_dir')
48-
49-
def runs_dir(self):
50-
return os.path.join(self.work_dir(), 'runs')
7+
dir_raw = '/xenon/xenon1t/raw'
518

52-
def pegasus_path(self):
53-
return self.get('Outsource', 'pegasus_path')
9+
base_dir = os.path.dirname(__file__)
10+
work_dir = config.get('Outsource', 'work_dir')
11+
runs_dir = os.path.join(work_dir, 'runs')
12+
pegasus_path = config.get('Outsource', 'pegasus_path')

outsource/Outsource.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
import sys
1010

1111
from outsource.Shell import Shell
12-
from outsource.Config import Config
12+
from outsource.Config import config, pegasus_path, base_dir, work_dir, runs_dir
1313

14-
config = Config()
1514
logger = logging.getLogger("outsource")
1615

1716
# Pegasus environment
18-
sys.path.insert(0, os.path.join(config.pegasus_path(), 'lib64/python2.6/site-packages'))
19-
os.environ['PATH'] = os.path.join(config.pegasus_path(), 'bin') + ':' + os.environ['PATH']
17+
sys.path.insert(0, os.path.join(pegasus_path, 'lib64/python2.6/site-packages'))
18+
os.environ['PATH'] = os.path.join(pegasus_path, 'bin') + ':' + os.environ['PATH']
2019
from Pegasus.DAX3 import *
2120

2221

@@ -88,7 +87,7 @@ def submit_workflow(self):
8887
except OSError:
8988
pass
9089
try:
91-
os.makedirs(config.runs_dir(), 0o755)
90+
os.makedirs(runs_dir, 0o755)
9291
except OSError:
9392
pass
9493

@@ -109,31 +108,31 @@ def _generate_dax(self):
109108
dax = ADAG('xenonnt')
110109

111110
# event callouts
112-
dax.invoke('start', config.base_dir() + '/workflow/events/wf-start')
113-
dax.invoke('at_end', config.base_dir() + '/workflow/events/wf-end')
111+
dax.invoke('start', base_dir + '/workflow/events/wf-start')
112+
dax.invoke('at_end', base_dir + '/workflow/events/wf-end')
114113

115114
# Add executables to the DAX-level replica catalog
116115
wrapper = Executable(name='run-pax.sh', arch='x86_64', installed=False)
117-
wrapper.addPFN(PFN('file://' + config.base_dir() + '/workflow/run-pax.sh', 'local'))
116+
wrapper.addPFN(PFN('file://' + base_dir + '/workflow/run-pax.sh', 'local'))
118117
wrapper.addProfile(Profile(Namespace.PEGASUS, 'clusters.size', 2))
119118
dax.addExecutable(wrapper)
120119

121120
merge = Executable(name='merge.sh', arch='x86_64', installed=False)
122-
merge.addPFN(PFN('file://' + config.base_dir() + '/workflow/merge.sh', 'local'))
121+
merge.addPFN(PFN('file://' + base_dir + '/workflow/merge.sh', 'local'))
123122
dax.addExecutable(merge)
124123

125124
upload = Executable(name='upload.sh', arch='x86_64', installed=False)
126-
upload.addPFN(PFN('file://' + config.base_dir() + '/workflow/upload.sh', 'local'))
125+
upload.addPFN(PFN('file://' + base_dir + '/workflow/upload.sh', 'local'))
127126
dax.addExecutable(upload)
128127

129128
# determine_rse - a helper for the job to determine where to pull data from
130129
determine_rse = File('determine_rse.py')
131-
determine_rse.addPFN(PFN('file://' + os.path.join(config.base_dir(), 'workflow/determine_rse.py'), 'local'))
130+
determine_rse.addPFN(PFN('file://' + os.path.join(base_dir, 'workflow/determine_rse.py'), 'local'))
132131
dax.addFile(determine_rse)
133132

134133
# paxify is what processes the data. Gets called by the executable run-pax.sh
135134
paxify = File('paxify.py')
136-
paxify.addPFN(PFN('file://' + os.path.join(config.base_dir(), 'workflow/paxify.py'), 'local'))
135+
paxify.addPFN(PFN('file://' + os.path.join(base_dir, 'workflow/paxify.py'), 'local'))
137136
dax.addFile(paxify)
138137

139138
for dbcfg in self._dbcfgs:
@@ -225,9 +224,9 @@ def _generate_dax(self):
225224
upload_job = Job("upload.sh")
226225
upload_job.addProfile(Profile(Namespace.HINTS, 'execution.site', 'local'))
227226
upload_job.uses(merged_root, link=Link.INPUT)
228-
upload_job.addArguments(dbcfg.name,
227+
upload_job.addArguments(dbcfg.name,
229228
merged_root,
230-
config.base_dir())
229+
base_dir)
231230
dax.addJob(upload_job)
232231
dax.depends(parent=merge_job, child=upload_job)
233232

@@ -242,23 +241,23 @@ def _plan_and_submit(self):
242241
Call out to plan-env-helper.sh to start the workflow
243242
'''
244243

245-
cmd = ' '.join([os.path.join(config.base_dir(), 'workflow/plan-env-helper.sh'),
246-
config.pegasus_path(),
247-
config.base_dir(),
248-
config.work_dir(),
244+
cmd = ' '.join([os.path.join(base_dir, 'workflow/plan-env-helper.sh'),
245+
pegasus_path,
246+
base_dir,
247+
work_dir,
249248
self._generated_dir(),
250-
config.runs_dir(),
249+
runs_dir,
251250
self._wf_id])
252251
shell = Shell(cmd, log_cmd = False, log_outerr = True)
253252
shell.run()
254253

255254

256255
def _generated_dir(self):
257-
return os.path.join(config.work_dir(), 'generated', self._wf_id)
256+
return os.path.join(work_dir, 'generated', self._wf_id)
258257

259258

260259
def _workflow_dir(self):
261-
return os.path.join(config.runs_dir(), self._wf_id)
260+
return os.path.join(runs_dir, self._wf_id)
262261

263262

264263
def _validate_x509_proxy(self):

outsource/RunConfig.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import os
22
import re
33
import time
4-
from outsource.Config import Config
5-
from outsource import db
4+
from .Config import config, base_dir, work_dir
5+
from utilix import db
66

7-
config = Config()
87

98

109
class RunConfigBase:
@@ -13,8 +12,8 @@ class RunConfigBase:
1312
_update_run_db = False
1413
_force_rerun = False
1514
_x509_proxy = os.path.join(os.environ['HOME'], 'user_cert')
16-
_executable = os.path.join(config.base_dir(), 'workflow', 'run-pax.sh')
17-
_workdir = config.get('Outsource', 'work_dir')
15+
_executable = os.path.join(base_dir, 'workflow', 'run-pax.sh')
16+
_workdir = work_dir
1817
_workflow_id = re.sub('\..*', '', str(time.time()))
1918
_pax_version = config.get('Outsource', 'pax_version')
2019

outsource/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
from outsource.rundb import DB
2-
3-
# initialize instance of DB here since we just need one instance for all modules to use
4-
db = DB()

outsource/rundb.py

Lines changed: 0 additions & 141 deletions
This file was deleted.

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
def readme():
5-
with open('README.rst') as f:
5+
with open('README.md') as f:
66
return f.read()
77

88

@@ -12,8 +12,8 @@ def readme():
1212
long_description=readme(),
1313
url='https://github.com/XENONnT/outsource',
1414
packages=['outsource'],
15-
install_requires=[
16-
'markdown',
17-
],
15+
install_requires=['markdown',
16+
'utilix'
17+
],
1818
include_package_data=True,
1919
zip_safe=False)

0 commit comments

Comments
 (0)