Commit 2a613153 authored by payno's avatar payno

[refactoring] Rename JobDefinition by JobFactory

parent 0d50fcc7
......@@ -10,7 +10,7 @@ Hello world (minimal):
from oarpy import oarjob
jobdef = oarjob.JobDefinition(command='echo "Hello word"')
jobdef = oarjob.JobFactory(command='echo "Hello word"')
job = jobdef.submit()
job.wait()
......@@ -30,7 +30,7 @@ Hello world (specify resources and postpone execution):
from oarpy.oarresource import Resource
resource = Resource(core=2,walltime={'hours':2},gpu=True)
jobdef = oarjob.JobDefinition(name='helloworld',project='oarpy',
jobdef = oarjob.JobFactory(name='helloworld',project='oarpy',
command='echo "Hello word"',resource=resource)
job = jobdef.submit(hold=True)
......
......@@ -8,8 +8,8 @@
"------------------------------------------------\n",
"Three classes are used\n",
"* oarpy.oarjob.Job: manage existing jobs (status, stop, suspend, resume)\n",
"* oarpy.oarjob.JobDefinition: define and launch jobs (creates oarpy.oarjob.Job)\n",
"* oarpy.oarresource.Resource: optional OAR resources for JobDefinition (nodes, cores, gpu)"
"* oarpy.oarjob.JobFactory: define and launch jobs (creates oarpy.oarjob.Job)\n",
"* oarpy.oarresource.Resource: optional OAR resources for JobFactory (nodes, cores, gpu)"
]
},
{
......@@ -152,7 +152,7 @@
}
],
"source": [
"jobdef = oarjob.JobDefinition(command=\"ls\")\n",
"jobdef = oarjob.JobFactory(command=\"ls\")\n",
"print(jobdef)"
]
},
......@@ -177,7 +177,7 @@
}
],
"source": [
"jobdef = oarjob.JobDefinition(name='test',project='oarpy',command='ls')\n",
"jobdef = oarjob.JobFactory(name='test',project='oarpy',command='ls')\n",
"print(jobdef)"
]
},
......@@ -202,8 +202,8 @@
}
],
"source": [
"jobdef = oarjob.JobDefinition(name='test',project='oarpy',command='ls',\n",
" working_directory='/tmp/oarpy',log_directory='/tmp/oarpy/log')\n",
"jobdef = oarjob.JobFactory(name='test',project='oarpy',command='ls',\n",
" working_directory='/tmp/oarpy',log_directory='/tmp/oarpy/log')\n",
"print(jobdef)"
]
},
......@@ -239,8 +239,8 @@
],
"source": [
"resource = Resource(nodes=1,core=8,walltime={'minutes':1})\n",
"jobdef = oarjob.JobDefinition(name='test',project='oarpy',\n",
" command='ls',resource=resource)\n",
"jobdef = oarjob.JobFactory(name='test',project='oarpy',\n",
" command='ls',resource=resource)\n",
"print(jobdef)"
]
},
......@@ -262,8 +262,8 @@
"def definition(seconds):\n",
" command = 'python -c \"from time import sleep\\nfor i in range({}):\\n print(i)\\n sleep(1)\"'\n",
" resource = Resource(core=1,walltime={'seconds':seconds*3})\n",
" return oarjob.JobDefinition(name='test{}'.format(seconds),project='oarpy',\n",
" resource=resource,command=command.format(seconds))"
" return oarjob.JobFactory(name='test{}'.format(seconds),project='oarpy',\n",
" resource=resource,command=command.format(seconds))"
]
},
{
......
......@@ -25,7 +25,7 @@
"source": [
"from oarpy import oarjob\n",
"\n",
"jobdef = oarjob.JobDefinition(command='echo \"Hello word\"')\n",
"jobdef = oarjob.JobFactory(command='echo \"Hello word\"')\n",
"job = jobdef.submit()\n",
"job.wait()\n",
"\n",
......@@ -66,7 +66,7 @@
"from oarpy.oarresource import Resource\n",
"\n",
"resource = Resource(core=1,walltime={'hours':1},gpu=False)\n",
"jobdef = oarjob.JobDefinition(name='helloworld',project='oarpy',\n",
"jobdef = oarjob.JobFactory(name='helloworld',project='oarpy',\n",
" command='echo \"Hello word\"',resource=resource)\n",
"\n",
"job = jobdef.submit(hold=True)\n",
......
......@@ -333,7 +333,7 @@ class Job(object):
kwargs['log_directory'] = self.log_directory
kwargs['log_base'] = self.log_base
kwargs['resource'] = self.resource
return JobDefinition(**kwargs)
return JobFactory(**kwargs)
def _parse_stats(self, stats):
# Dates are in local timezone
......@@ -386,7 +386,7 @@ class Job(object):
return self.jobid >= other.jobid
class JobDefinition(object):
class JobFactory(object):
"""Define and submit new jobs
"""
......
......@@ -56,22 +56,22 @@ class test_oarjob(unittest.TestCase):
self.assertFalse(job.needsresume)
self.assertEqual(job['state'],job.status)
def test_jobdefinition(self):
def test_jobfactory(self):
self.skipoar()
self.assertTrue(oarjob.JobDefinition())
self.assertTrue(oarjob.JobDefinition(command='ls -all'))
self.assertTrue(oarjob.JobFactory())
self.assertTrue(oarjob.JobFactory(command='ls -all'))
res = Resource(nodes=1,cpu=2,core=2,gpu=True,mem_core_mb=8000)
info = oarjob.JobDefinition(resource=res,command='ls -all',log_base='test')
info = oarjob.JobFactory(resource=res, command='ls -all', log_base='test')
cli = "-O test.stdout -E test.stderr -l nodes=1/cpu=2/core=2 -p \"gpu='YES' and mem_core_mb>=8000\" \"ls -all\""
self.assertEqual(cli,info.cli_string)
def definition(self,seconds,name):
command = 'python -c "from time import sleep\nfor i in range({}):\n print(i)\n sleep(1)"'
resource = Resource(core=1,walltime={'seconds':seconds*3})
jobdef = oarjob.JobDefinition(name=name,project='oarpy',
resource=resource,command=command.format(seconds),
working_directory=self.working_directory)
jobdef = oarjob.JobFactory(name=name, project='oarpy',
resource=resource, command=command.format(seconds),
working_directory=self.working_directory)
output = list(range(seconds))
return jobdef,output
......@@ -124,7 +124,7 @@ def test_suite():
"""Test suite including all test suites"""
testSuite = unittest.TestSuite()
testSuite.addTest(test_oarjob("test_status"))
testSuite.addTest(test_oarjob("test_jobdefinition"))
testSuite.addTest(test_oarjob("test_jobfactory"))
testSuite.addTest(test_oarjob("test_immediate"))
testSuite.addTest(test_oarjob("test_notimmediate"))
testSuite.addTest(test_oarjob("test_interrupt"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment