ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/SchedulerCondor.py
(Generate patch)

Comparing COMP/CRAB/python/SchedulerCondor.py (file contents):
Revision 1.2 by ewv, Wed May 21 19:27:30 2008 UTC vs.
Revision 1.31 by farinafa, Tue May 11 13:39:50 2010 UTC

# Line 1 | Line 1
1 + """
2 + Implements the vanilla (local) Condor scheduler
3 + """
4 +
5   __revision__ = "$Id$"
6   __version__ = "$Revision$"
7  
8 < from Scheduler import Scheduler
9 < from SchedulerLocal import SchedulerLocal
6 < from crab_exceptions import *
7 < from crab_util import *
8 < from crab_logger import Logger
9 < import common
8 > from SchedulerLocal  import SchedulerLocal
9 > from crab_exceptions import CrabException
10  
11 + import common
12   import os
13 + import socket
14  
15 < #  Naming convention:
16 < #  methods starting with 'ws' are responsible to provide
17 < #  corresponding part of the job script ('ws' stands for 'write script').
15 > # FUTURE: for python 2.4 & 2.6
16 > try:
17 >    from hashlib import sha1
18 > except:
19 >    from sha import sha as sha1
20  
21   class SchedulerCondor(SchedulerLocal) :
18
19  def __init__(self):
20    Scheduler.__init__(self,"CONDOR")
21    return
22
23  def configure(self, cfg_params):
24    SchedulerLocal.configure(self, cfg_params)
25    self.environment_unique_identifier ='${HOSTNAME}_${CONDOR_ID}_' + common._db.queryTask('name')
26    return
27
28  def sched_parameter(self,i,task):
29    """
30    Return scheduler-specific parameters
31    """
32    index = int(common._db.nJobs()) - 1
33    sched_param= ''
34
35    for i in range(index):
36      pass
37
38    return sched_param
39
40  def realSchedParams(self,cfg_params):
22      """
23 <    Return dictionary with specific parameters, to use
24 <    with real scheduler
23 >    Class to implement the vanilla (local) Condor scheduler
24 >     Naming convention:  Methods starting with 'ws' provide
25 >     the corresponding part of the job script
26 >     ('ws' stands for 'write script').
27      """
28  
29 <    tmpDir = os.path.join(common.work_space.shareDir(),'.condor_temp')
30 <    params = {'tmpDir':tmpDir}
31 <    return  params
32 <
33 <  def loggingInfo(self, id):
34 <    """ return logging info about job nj """
35 <    cmd = 'something'
36 <    #cmd_out = runCommand(cmd)
37 <    return ''
29 >    def __init__(self):
30 >        SchedulerLocal.__init__(self,"CONDOR")
31 >        self.datasetPath   = None
32 >        self.selectNoInput = None
33 >
34 >        self.environment_unique_identifier = None
35 >        return
36 >
37 >
38 >    def configure(self, cfg_params):
39 >        """
40 >        Configure the scheduler with the config settings from the user
41 >        """
42 >
43 >        SchedulerLocal.configure(self, cfg_params)
44 >
45 >        try:
46 >            tmp =  cfg_params['CMSSW.datasetpath']
47 >            if tmp.lower() == 'none':
48 >                self.datasetPath = None
49 >                self.selectNoInput = 1
50 >            else:
51 >                self.datasetPath = tmp
52 >                self.selectNoInput = 0
53 >        except KeyError:
54 >            msg = "Error: datasetpath not defined "
55 >            raise CrabException(msg)
56 >
57 >        return
58 >
59 >    def envUniqueID(self):
60 >        taskHash = sha1(common._db.queryTask('name')).hexdigest()
61 >        id = "https://" + socket.gethostname() + '/' + taskHash + "/${NJob}"
62 >        return id
63 >
64 >    def sched_parameter(self, i, task):
65 >        """
66 >        Return scheduler-specific parameters
67 >        """
68 >        req = ''
69 >        if self.EDG_addJdlParam:
70 >            if self.EDG_addJdlParam[-1] == '':
71 >                self.EDG_addJdlParam = self.EDG_addJdlParam[:-1]
72 >            for p in self.EDG_addJdlParam:
73 >                req += p.strip()+';\n'
74 >
75 >        return req
76 >
77 >
78 >    def realSchedParams(self, cfg_params):
79 >        """
80 >        Return dictionary with specific parameters, to use with real scheduler
81 >        """
82 >
83 >        tmpDir = os.path.join(common.work_space.shareDir(),'.condor_temp')
84 >        tmpDir = os.path.join(common.work_space.shareDir(),'.condor_temp')
85 >        jobDir = common.work_space.jobDir()
86 >        params = {'tmpDir':tmpDir,
87 >                  'jobDir':jobDir}
88 >        return params
89 >
90 >
91 >    def listMatch(self, seList, full):
92 >        """
93 >        Check the compatibility of available resources
94 >        """
95 >
96 >        return [True]
97 >
98 >
99 >    def decodeLogInfo(self, fileName):
100 >        """
101 >        Parse logging info file and return main info
102 >        """
103 >
104 >        import CondorGLoggingInfo
105 >        loggingInfo = CondorGLoggingInfo.CondorGLoggingInfo()
106 >        reason = loggingInfo.decodeReason(fileName)
107 >        return reason
108 >
109 >
110 >    def wsCopyOutput(self):
111 >        """
112 >        Write a CopyResults part of a job script, e.g.
113 >        to copy produced output into a storage element.
114 >        """
115 >        txt = self.wsCopyOutput_comm()
116 >        return txt
117 >
118 >
119 >    def wsExitFunc(self):
120 >        """
121 >        Returns the part of the job script which runs prior to exit
122 >        """
123 >
124 >        txt = '\n'
125 >        txt += '#\n'
126 >        txt += '# EXECUTE THIS FUNCTION BEFORE EXIT \n'
127 >        txt += '#\n\n'
128 >
129 >        txt += 'func_exit() { \n'
130 >        txt += self.wsExitFunc_common()
131 >
132 >        txt += '    tar zcvf ${out_files}.tgz  ${final_list}\n'
133 >        txt += '    cp  ${out_files}.tgz $_CONDOR_SCRATCH_DIR/\n'
134 >        txt += '    cp  crab_fjr_$NJob.xml $_CONDOR_SCRATCH_DIR/\n'
135 >
136 >        txt += '    exit $job_exit_code\n'
137 >        txt += '}\n'
138 >
139 >        return txt
140 >
141 >    def wsInitialEnvironment(self):
142 >        """
143 >        Returns part of a job script which does scheduler-specific work.
144 >        """
145 >
146 >        txt  = '\n# Written by SchedulerCondor::wsInitialEnvironment\n'
147 >        txt += 'echo "Beginning environment"\n'
148 >        txt += 'printenv | sort\n'
149 >
150 >        txt += 'middleware='+self.name()+' \n'
151 >        txt += 'if [ -e /opt/d-cache/srm/bin ]; then\n'
152 >        txt += '  export PATH=${PATH}:/opt/d-cache/srm/bin\n'
153 >        txt += 'fi\n'
154 >
155 >        txt += """
156 > if [ $_CONDOR_SCRATCH_DIR ] && [ -d $_CONDOR_SCRATCH_DIR ]; then
157 >    echo "cd to Condor scratch directory: $_CONDOR_SCRATCH_DIR"
158 >    if [ -e ../default.tgz ] ;then
159 >      echo "Found ISB in parent directory (Local Condor)"
160 >      cp ../default.tgz $_CONDOR_SCRATCH_DIR
161 >    fi
162 >    cd $_CONDOR_SCRATCH_DIR
163 > fi
164 > """
165 >
166 >        return txt
167 >
168 >
169 >    def sched_fix_parameter(self):
170 >        """
171 >        Returns string with requirements and scheduler-specific parameters
172 >        """
173 >
174 >        if self.EDG_requirements:
175 >            req = self.EDG_requirements
176 >            taskReq = {'commonRequirements':req}
177 >            common._db.updateTask_(taskReq)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines