annotate commons/core/launcher/JobScriptTemplate.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 #!/usr/bin/env python
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import os
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import sys
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 import time
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 import shutil
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 from commons.core.checker.RepetException import RepetException
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 from commons.core.sql.TableJobAdaptator import TableJobAdaptator
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 from commons.core.sql.DbFactory import DbFactory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 from commons.core.sql.Job import Job
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 try:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 newDir = None
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 print os.uname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 beginTime = time.time()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 print 'beginTime=%f' % beginTime
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 print "work in dir '@@tmpDir@@'"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 if not os.path.exists( "@@tmpDir@@" ):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 raise IOError("ERROR: temporary directory '@@tmpDir@@' doesn't exist")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 minFreeGigaInTmpDir = 1
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 freeSpace = os.statvfs("@@tmpDir@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 if ((freeSpace.f_bavail * freeSpace.f_frsize) / 1073741824.0 < minFreeGigaInTmpDir):
18
94ab73e8a190 Uploaded
m-zytnicki
parents: 6
diff changeset
25 raise RepetException("ERROR: less than %iG of free space in '@@tmpDir@@'" % minFreeGigaInTmpDir)
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 os.chdir("@@tmpDir@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 newDir = "@@groupId@@_@@jobName@@_@@time@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 if os.path.exists(newDir):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 shutil.rmtree(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 os.mkdir(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 os.chdir(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 iTJA.changeJobStatus(iJob, "running")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 @@cmdStart@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 if log != 0:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 raise RepetException("ERROR: job returned %i" % log)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 else:
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 print "job finished successfully"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 @@cmdFinish@@
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 os.chdir("..")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 shutil.rmtree(newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 iTJA.changeJobStatus(iJob, "finished")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 endTime = time.time()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 print 'endTime=%f' % endTime
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 print 'executionTime=%f' % (endTime - beginTime)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 print os.uname()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 except IOError, e :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 print e
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 iTJA.changeJobStatus(iJob, "error")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 sys.exit(1)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 except Exception, e :
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 print "tmpDir is : @@tmpDir@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 print "cDir is : @@cDir@@"
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 print e
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 if newDir != None and os.path.exists("../%s" % newDir) and not os.path.exists("@@cDir@@/%s" % newDir):
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 os.chdir("..")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 shutil.move(newDir, "@@cDir@@/%s" % newDir)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87 iJob = Job(jobname = "@@jobName@@", groupid = "@@groupId@@", launcherFile = "@@launcher@@", node = os.getenv("HOSTNAME"))
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 iDb = DbFactory.createInstance()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 iTJA = TableJobAdaptator(iDb, "@@jobTableName@@")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 print "current status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 iTJA.changeJobStatus(iJob, "error")
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 print "updated status: %s" % iTJA.getJobStatus(iJob)
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93 sys.stdout.flush()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 iDb.close()
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 sys.exit(1)