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

Comparing COMP/CRAB/python/SchedulerGlite.py (file contents):
Revision 1.1.2.3.2.1 by spiga, Fri Sep 15 07:51:02 2006 UTC vs.
Revision 1.14 by spiga, Mon Jun 25 14:21:56 2007 UTC

# Line 1 | Line 1
1 < from Scheduler import Scheduler
1 > from SchedulerEdg import SchedulerEdg
2   from crab_logger import Logger
3   from crab_exceptions import *
4   from crab_util import *
5 < from EdgConfig import *
5 > from GliteConfig import *
6   import common
7  
8   import os, sys, time
9  
10 < class SchedulerGlite(Scheduler):
10 > class SchedulerGlite(SchedulerEdg):
11      def __init__(self):
12 <        Scheduler.__init__(self,"GLITE")
13 <        self.states = [ "Acl", "cancelReason", "cancelling","ce_node","children", \
14 <                      "children_hist","children_num","children_states","condorId","condor_jdl", \
15 <                      "cpuTime","destination", "done_code","exit_code","expectFrom", \
16 <                      "expectUpdate","globusId","jdl","jobId","jobtype", \
17 <                      "lastUpdateTime","localId","location", "matched_jdl","network_server", \
18 <                      "owner","parent_job", "reason","resubmitted","rsl","seed",\
19 <                      "stateEnterTime","stateEnterTimes","subjob_failed", \
20 <                      "user tags" , "status" , "status_code","hierarchy"]
21 <        return
22 <
23 <    def configure(self, cfg_params):
24 <
25 <        try:
26 <            RB = cfg_params["EDG.rb"]
27 <            edgConfig = EdgConfig(RB)
28 <            self.edg_config = edgConfig.config()
29 <            self.edg_config_vo = edgConfig.configVO()
30 <        except KeyError:
31 <            self.edg_config = ''
32 <            self.edg_config_vo = ''
33 <
34 <        try:
35 <            self.proxyServer = cfg_params["EDG.proxy_server"]
36 <        except KeyError:
37 <            self.proxyServer = 'myproxy.cern.ch'
38 <        common.logger.debug(5,'Setting myproxy server to '+self.proxyServer)
39 <
40 <        try: self.LCG_version = cfg_params["EDG.lcg_version"]
41 <        except KeyError: self.LCG_version = '2'
42 <
43 <        try: self.EDG_requirements = cfg_params['EDG.requirements']
44 <        except KeyError: self.EDG_requirements = ''
45 <
46 <        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
47 <        except KeyError: self.EDG_retry_count = ''
48 <
49 <        try:
50 <            self.EDG_ce_black_list = cfg_params['EDG.ce_black_list']
51 <        except KeyError:
52 <            self.EDG_ce_black_list  = ''
53 <
54 <        try:
55 <            self.EDG_ce_white_list = cfg_params['EDG.ce_white_list']
56 <        except KeyError: self.EDG_ce_white_list = ''
57 <
58 <        try: self.VO = cfg_params['EDG.virtual_organization']
59 <        except KeyError: self.VO = 'cms'
60 <
61 <        try: self.return_data = cfg_params['USER.return_data']
62 <        except KeyError: self.return_data = 1
63 <
64 <        try:
65 <             self.copy_input_data = common.analisys_common_info['copy_input_data']
66 <        except KeyError: self.copy_input_data = 0
67 <
68 <        try:
69 <            self.copy_data = cfg_params["USER.copy_data"]
70 <            if int(self.copy_data) == 1:
71 <                try:
72 <                    self.SE = cfg_params['USER.storage_element']
73 <                    self.SE_PATH = cfg_params['USER.storage_path']
74 <                except KeyError:
75 <                    msg = "Error. The [USER] section does not have 'storage_element'"
76 <                    msg = msg + " and/or 'storage_path' entries, necessary to copy the output"
77 <                    common.logger.message(msg)
78 <                    raise CrabException(msg)
79 <        except KeyError: self.copy_data = 0
80 <
81 <        if ( int(self.return_data) == 0 and int(self.copy_data) == 0 ):
82 <           msg = 'Warning: return_data = 0 and copy_data = 0 ==> your exe output will be lost\n'
83 <           msg = msg + 'Please modify return_data and copy_data value in your crab.cfg file\n'
84 <           raise CrabException(msg)
85 <
86 <        try:
87 <            self.lfc_host = cfg_params['EDG.lfc_host']
88 <        except KeyError:
89 <            msg = "Error. The [EDG] section does not have 'lfc_host' value"
90 <            msg = msg + " it's necessary to know the LFC host name"
91 <            common.logger.message(msg)
92 <            raise CrabException(msg)
93 <        try:
94 <            self.lcg_catalog_type = cfg_params['EDG.lcg_catalog_type']
95 <        except KeyError:
96 <            msg = "Error. The [EDG] section does not have 'lcg_catalog_type' value"
97 <            msg = msg + " it's necessary to know the catalog type"
98 <            common.logger.message(msg)
99 <            raise CrabException(msg)
100 <        try:
101 <            self.lfc_home = cfg_params['EDG.lfc_home']
102 <        except KeyError:
103 <            msg = "Error. The [EDG] section does not have 'lfc_home' value"
104 <            msg = msg + " it's necessary to know the home catalog dir"
105 <            common.logger.message(msg)
106 <            raise CrabException(msg)
107 <      
108 <        try:
109 <            self.register_data = cfg_params["USER.register_data"]
110 <            if int(self.register_data) == 1:
111 <                try:
112 <                    self.LFN = cfg_params['USER.lfn_dir']
113 <                except KeyError:
114 <                    msg = "Error. The [USER] section does not have 'lfn_dir' value"
115 <                    msg = msg + " it's necessary for LCF registration"
116 <                    common.logger.message(msg)
117 <                    raise CrabException(msg)
118 <        except KeyError: self.register_data = 0
119 <
120 <        if ( int(self.copy_data) == 0 and int(self.register_data) == 1 ):
121 <           msg = 'Warning: register_data = 1 must be used with copy_data = 1\n'
122 <           msg = msg + 'Please modify copy_data value in your crab.cfg file\n'
123 <           common.logger.message(msg)
124 <           raise CrabException(msg)
125 <
126 <        try: self.EDG_requirements = cfg_params['EDG.requirements']
127 <        except KeyError: self.EDG_requirements = ''
128 <                                                                                                                                                            
129 <        try: self.EDG_retry_count = cfg_params['EDG.retry_count']
130 <        except KeyError: self.EDG_retry_count = ''
131 <                                                                                                                                                            
132 <        try: self.EDG_clock_time = cfg_params['EDG.max_wall_clock_time']
133 <        except KeyError: self.EDG_clock_time= ''
134 <                                                                                                                                                            
135 <        try: self.EDG_cpu_time = cfg_params['EDG.max_cpu_time']
136 <        except KeyError: self.EDG_cpu_time = ''
137 <
138 <
139 <        try: self.schedulerName = cfg_params['CRAB.scheduler']
140 <        except KeyError: self.schedulerName = ''
141 <
142 <        try: self.jobtypeName = cfg_params['CRAB.jobtype']
143 <        except KeyError: self.jobtypeName = ''
144 <
145 <        # Add EDG_WL_LOCATION to the python path
146 <        try:
147 <            path = os.environ['EDG_WL_LOCATION']
148 <        except:
149 <            msg = "Error: the EDG_WL_LOCATION variable is not set."
150 <            raise CrabException(msg)
151 <
152 <        libPath=os.path.join(path, "lib")
153 <        sys.path.append(libPath)
154 <        libPath=os.path.join(path, "lib", "python")
155 <        sys.path.append(libPath)
156 <
157 <        self.proxyValid=0
158 <
159 <        try:
160 <            self._taskId = cfg_params['taskId']
161 <        except:
162 <            self._taskId = ''
163 <
164 <        try: self.jobtypeName = cfg_params['CRAB.jobtype']
165 <        except KeyError: self.jobtypeName = ''
166 <
167 <        try: self.schedulerName = cfg_params['CRAB.scheduler']
168 <        except KeyError: self.scheduler = ''
12 >        SchedulerEdg.__init__(self)
13  
14 <        return
15 <    
14 >    def rb_configure(self, RB):
15 >        self.glite_config = ''
16 >        self.rb_param_file = ''
17 >
18 >        gliteConfig = GliteConfig(RB)
19 >        self.glite_config = gliteConfig.config()
20 >
21 >        if (self.glite_config != ''):
22 >            self.rb_param_file = 'WMSconfig = '+self.glite_config+';\n'
23 >            #print "rb_param_file = ", self.rb_param_file
24 >        return self.rb_param_file
25  
26      def sched_parameter(self):
27          """
28 <        Returns file with scheduler-specific parameters
28 >        Returns file with requirements and scheduler-specific parameters
29          """
30 <        if (self.edg_config and self.edg_config_vo != ''):
31 <            self.param='sched_param.clad'
30 >        index = int(common.jobDB.nJobs()) - 1
31 >        job = common.job_list[index]
32 >        jbt = job.type()
33 >        
34 >        lastDest=''
35 >        first = []
36 >        last  = []
37 >        for n in range(common.jobDB.nJobs()):
38 >            currDest=common.jobDB.destination(n)
39 >            if (currDest!=lastDest):
40 >                lastDest = currDest
41 >                first.append(n)
42 >                if n != 0:last.append(n-1)
43 >        if len(first)>len(last) :last.append(common.jobDB.nJobs())
44 >  
45 >        req = ''
46 >        req = req + jbt.getRequirements()
47 >  
48 >  
49 >        if self.EDG_requirements:
50 >            if (not req == ' '): req = req +  ' && '
51 >            req = req + self.EDG_requirements
52 >
53 >        if self.EDG_ce_white_list:
54 >            ce_white_list = string.split(self.EDG_ce_white_list,',')
55 >            tmpCe=[]
56 >            concString = '&&'
57 >            for ce in ce_white_list:
58 >                tmpCe.append('RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId)')
59 >            if len(tmpCe): req = req + " && (" + concString.join(tmpCe) + ") "
60 >        
61 >        if self.EDG_ce_black_list:
62 >            ce_black_list = string.split(self.EDG_ce_black_list,',')
63 >            tmpCe=[]
64 >            concString = '&&'
65 >            for ce in ce_black_list:
66 >                tmpCe.append('(!RegExp("' + string.strip(ce) + '", other.GlueCEUniqueId))')
67 >            if len(tmpCe): req = req + " && (" + concString.join(tmpCe) + ") "
68 >
69 >        if self.EDG_clock_time:
70 >            if (not req == ' '): req = req + ' && '
71 >            req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
72 >
73 >        if self.EDG_cpu_time:
74 >            if (not req == ' '): req = req + ' && '
75 >            req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
76 >                
77 >        for i in range(len(first)): # Add loop DS
78 >            self.param='sched_param_'+str(i)+'.clad'
79              param_file = open(common.work_space.shareDir()+'/'+self.param, 'w')
80 <            param_file.write('RBconfig = "'+self.edg_config+'";\n')  
81 <            param_file.write('RBconfigVO = "'+self.edg_config_vo+'";')
80 >
81 >            itr4=self.findSites_(first[i])
82 >            reqSites=''
83 >            reqtmp=[]  
84 >            concString = '||'
85 >
86 >            #############
87 >            # MC Changed matching syntax to avoid gang matching
88 >            #############
89 >            for arg in itr4:
90 >                reqtmp.append(' Member("'+arg+'" , other.GlueCESEBindGroupSEUniqueID) ')
91 >
92 >            if len(reqtmp): reqSites = reqSites + " && (" + concString.join(reqtmp) + ") "
93 >
94 >            # requirement added to skip gliteCE
95 >            reqSites = reqSites + '&& (!RegExp("blah", other.GlueCEUniqueId));\n'
96 >
97 >            param_file.write('Requirements = ' + req + reqSites )
98 >  
99 >            if (self.rb_param_file != ''):
100 >                param_file.write(self.rb_param_file)  
101 >
102 >            if len(self.EDG_addJdlParam):
103 >                for p in self.EDG_addJdlParam:
104 >                    param_file.write(p)
105 >
106              param_file.close()  
183            return 1
184        else:
185            return 0
107  
108      def wsSetupEnvironment(self):
109          """
# Line 195 | Line 116 | class SchedulerGlite(Scheduler):
116          txt += 'nargs=$#\n'
117          txt += 'shift $nargs\n'
118          txt += "# job number (first parameter for job wrapper)\n"
198        #txt += "NJob=$1\n"
119          txt += "NJob=${args[0]}\n"
120  
121          txt += '# job identification to DashBoard \n'
122 <        txt += 'MonitorJobID=`echo ${NJob}_$EDG_WL_JOBID`\n'
123 <        txt += 'SyncGridJobId=`echo $EDG_WL_JOBID`\n'
122 >        txt += 'MonitorJobID=`echo ${NJob}_$GLITE_WMS_JOBID`\n'
123 >        txt += 'SyncGridJobId=`echo $GLITE_WMS_JOBID`\n'
124          txt += 'MonitorID=`echo ' + self._taskId + '`\n'
125          txt += 'echo "MonitorJobID=`echo $MonitorJobID`" | tee -a $RUNTIME_AREA/$repo \n'
126          txt += 'echo "SyncGridJobId=`echo $SyncGridJobId`" | tee -a $RUNTIME_AREA/$repo \n'
127          txt += 'echo "MonitorID=`echo $MonitorID`" | tee -a $RUNTIME_AREA/$repo\n'
128  
129          txt += 'echo "middleware discovery " \n'
130 <        txt += 'if [ $VO_CMS_SW_DIR ]; then\n'
130 >        txt += 'if [ $VO_CMS_SW_DIR ]; then \n'
131          txt += '    middleware=LCG \n'
132 <        txt += '    echo "SyncCE=`edg-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
132 >        txt += '    echo "SyncCE=`glite-brokerinfo getCE`" | tee -a $RUNTIME_AREA/$repo \n'
133          txt += '    echo "GridFlavour=`echo $middleware`" | tee -a $RUNTIME_AREA/$repo \n'
134          txt += '    echo "middleware =$middleware" \n'
135          txt += 'elif [ $GRID3_APP_DIR ]; then\n'
# Line 251 | Line 171 | class SchedulerGlite(Scheduler):
171                txt += 'echo "SE_PATH = $SE_PATH"\n'
172  
173          txt += 'export VO='+self.VO+'\n'
174 <        ### FEDE: add some line for LFC catalog setting
174 >        ### some line for LFC catalog setting
175          txt += 'if [ $middleware == LCG ]; then \n'
176          txt += '    if [[ $LCG_CATALOG_TYPE != \''+self.lcg_catalog_type+'\' ]]; then\n'
177          txt += '        export LCG_CATALOG_TYPE='+self.lcg_catalog_type+'\n'
# Line 312 | Line 232 | class SchedulerGlite(Scheduler):
232          txt += 'fi \n'
233  
234          return txt
235 <
316 <    def wsCopyInput(self):
317 <        """
318 <        Copy input data from SE to WN    
319 <        """
320 <        txt = ''
321 <        try:
322 <            self.copy_input_data = common.analisys_common_info['copy_input_data']
323 <        except KeyError: self.copy_input_data = 0
324 <        if int(self.copy_input_data) == 1:
325 <        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
326 <           txt += 'if [ $middleware == OSG ]; then\n'
327 <           txt += '   #\n'
328 <           txt += '   #   Copy Input Data from SE to this WN deactivated in OSG mode\n'
329 <           txt += '   #\n'
330 <           txt += '   echo "Copy Input Data from SE to this WN deactivated in OSG mode"\n'
331 <           txt += 'elif [ $middleware == LCG ]; then \n'
332 <           txt += '   #\n'
333 <           txt += '   #   Copy Input Data from SE to this WN\n'
334 <           txt += '   #\n'
335 <           ### changed by georgia (put a loop copying more than one input files per jobs)          
336 <           txt += '   for input_file in $cur_file_list \n'
337 <           txt += '   do \n'
338 <           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$input_lfn/$input_file file:`pwd`/$input_file 2>&1\n'
339 <           txt += '      copy_input_exit_status=$?\n'
340 <           txt += '      echo "COPY_INPUT_EXIT_STATUS = $copy_input_exit_status"\n'
341 <           txt += '      if [ $copy_input_exit_status -ne 0 ]; then \n'
342 <           txt += '         echo "Problems with copying to WN" \n'
343 <           txt += '      else \n'
344 <           txt += '         echo "input copied into WN" \n'
345 <           txt += '      fi \n'
346 <           txt += '   done \n'
347 <           ### copy a set of PU ntuples (same for each jobs -- but accessed randomly)
348 <           txt += '   for file in $cur_pu_list \n'
349 <           txt += '   do \n'
350 <           txt += '      lcg-cp --vo $VO --verbose -t 1200 lfn:$pu_lfn/$file file:`pwd`/$file 2>&1\n'
351 <           txt += '      copy_input_pu_exit_status=$?\n'
352 <           txt += '      echo "COPY_INPUT_PU_EXIT_STATUS = $copy_input_pu_exit_status"\n'
353 <           txt += '      if [ $copy_input_pu_exit_status -ne 0 ]; then \n'
354 <           txt += '         echo "Problems with copying pu to WN" \n'
355 <           txt += '      else \n'
356 <           txt += '         echo "input pu files copied into WN" \n'
357 <           txt += '      fi \n'
358 <           txt += '   done \n'
359 <           txt += '   \n'
360 <           txt += '   ### Check SCRATCH space available on WN : \n'
361 <           txt += '   df -h \n'
362 <           txt += 'fi \n'
363 <          
364 <        return txt
365 <
366 <    def wsCopyOutput(self):
367 <        """
368 <        Write a CopyResults part of a job script, e.g.
369 <        to copy produced output into a storage element.
370 <        """
371 <        txt = ''
372 <        if int(self.copy_data) == 1:
373 <           txt += '#\n'
374 <           txt += '#   Copy output to SE = $SE\n'
375 <           txt += '#\n'
376 <           txt += '    if [ $middleware == OSG ]; then\n'
377 <           txt += '        echo "X509_USER_PROXY = $X509_USER_PROXY"\n'
378 <           txt += '        echo "source $OSG_APP/glite/setup_glite_ui.sh"\n'
379 <           txt += '        source $OSG_APP/glite/setup_glite_ui.sh\n'
380 <           txt += '        export X509_CERT_DIR=$OSG_APP/glite/etc/grid-security/certificates\n'
381 <           txt += '        echo "export X509_CERT_DIR=$X509_CERT_DIR"\n'
382 <           txt += '    fi \n'
383 <           txt += '    for out_file in $file_list ; do\n'
384 <           txt += '        echo "Trying to copy output file to $SE using lcg-cp"\n'
385 <           txt += '        echo "lcg-cp --vo $VO -t 1200 --verbose file://`pwd`/$out_file gsiftp://${SE}${SE_PATH}$out_file"\n'
386 <           txt += '        exitstring=`lcg-cp --vo $VO -t 1200 --verbose file://\`pwd\`/$out_file gsiftp://${SE}${SE_PATH}$out_file 2>&1`\n'
387 <           txt += '        copy_exit_status=$?\n'
388 <           txt += '        echo "COPY_EXIT_STATUS for lcg-cp = $copy_exit_status"\n'
389 <           txt += '        echo "STAGE_OUT = $copy_exit_status"\n'
390 <           txt += '        if [ $copy_exit_status -ne 0 ]; then\n'
391 <           txt += '            echo "Problems with SE = $SE"\n'
392 <           txt += '            echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
393 <           txt += '            echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
394 <           txt += '            echo "lcg-cp failed, attempting srmcp"\n'
395 <           txt += '            echo "mkdir -p $HOME/.srmconfig"\n'
396 <           txt += '            mkdir -p $HOME/.srmconfig\n'
397 <           txt += '            if [ $middleware == LCG ]; then\n'
398 <           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
399 <           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
400 <           txt += '            elif [ $middleware == OSG ]; then\n'
401 <           txt += '               echo "srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////`pwd`/$out_file srm://${SE}:8443${SE_PATH}$out_file"\n'
402 <           txt += '               exitstring=`srmcp -retry_num 5 -retry_timeout 240000 -x509_user_trusted_certificates $OSG_APP/glite/etc/grid-security/certificates file:////\`pwd\`/$out_file srm://${SE}:8443${SE_PATH}$out_file 2>&1`\n'
403 <           txt += '            fi \n'
404 <           txt += '            copy_exit_status=$?\n'
405 <           txt += '            echo "COPY_EXIT_STATUS for srm = $copy_exit_status"\n'
406 <           txt += '            echo "STAGE_OUT = $copy_exit_status"\n'
407 <           txt += '            if [ $copy_exit_status -ne 0 ]; then\n'
408 <           txt += '               echo "Problems with SE = $SE"\n'
409 <           txt += '               echo "StageOutExitStatus = 198" | tee -a $RUNTIME_AREA/$repo\n'
410 <           txt += '               echo "StageOutExitStatusReason = $exitstring" | tee -a $RUNTIME_AREA/$repo\n'
411 <           txt += '               echo "lcg-cp and srm failed"\n'
412 <           txt += '               echo "If storage_path in your config file contains a ? you may need a \? instead."\n'
413 <           txt += '            else\n'
414 <           txt += '               echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
415 <           txt += '               echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
416 <           txt += '               echo "output copied into $SE/$SE_PATH directory"\n'
417 <           txt += '               echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
418 <           txt += '               echo "srmcp succeeded"\n'
419 <           txt += '            fi\n'
420 <           txt += '        else\n'
421 <           txt += '            echo "StageOutSE = $SE" | tee -a $RUNTIME_AREA/$repo\n'
422 <           txt += '            echo "StageOutCatalog = " | tee -a $RUNTIME_AREA/$repo\n'
423 <           txt += '            echo "output copied into $SE/$SE_PATH directory"\n'
424 <           txt += '            echo "StageOutExitStatus = 0" | tee -a $RUNTIME_AREA/$repo\n'
425 <           txt += '            echo "lcg-cp succeeded"\n'
426 <           txt += '         fi\n'
427 <           txt += '     done\n'
428 <        return txt
429 <
430 <    def wsRegisterOutput(self):
431 <        """
432 <        Returns part of a job script which does scheduler-specific work.
433 <        """
434 <
435 <        txt = ''
436 <        if int(self.register_data) == 1:
437 <        ## OLI_Daniele deactivate for OSG (wait for LCG UI installed on OSG)
438 <           txt += 'if [ $middleware == OSG ]; then\n'
439 <           txt += '   #\n'
440 <           txt += '   #   Register output to LFC deactivated in OSG mode\n'
441 <           txt += '   #\n'
442 <           txt += '   echo "Register output to LFC deactivated in OSG mode"\n'
443 <           txt += 'elif [ $middleware == LCG ]; then \n'
444 <           txt += '#\n'
445 <           txt += '#  Register output to LFC\n'
446 <           txt += '#\n'
447 <           txt += '   if [ $copy_exit_status -eq 0 ]; then\n'
448 <           txt += '      for out_file in $file_list ; do\n'
449 <           txt += '         echo "Trying to register the output file into LFC"\n'
450 <           txt += '         echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1"\n'
451 <           txt += '         lcg-rf -l $LFN/$out_file --vo $VO -t 1200 sfn://$SE$SE_PATH/$out_file 2>&1 \n'
452 <           txt += '         register_exit_status=$?\n'
453 <           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
454 <           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
455 <           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
456 <           txt += '            echo "Problems with the registration to LFC" \n'
457 <           txt += '            echo "Try with srm protocol" \n'
458 <           txt += '            echo "lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1"\n'
459 <           txt += '            lcg-rf -l $LFN/$out_file --vo $VO -t 1200 srm://$SE$SE_PATH/$out_file 2>&1 \n'
460 <           txt += '            register_exit_status=$?\n'
461 <           txt += '            echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
462 <           txt += '            echo "STAGE_OUT = $register_exit_status"\n'
463 <           txt += '            if [ $register_exit_status -ne 0 ]; then \n'
464 <           txt += '               echo "Problems with the registration into LFC" \n'
465 <           txt += '            fi \n'
466 <           txt += '         else \n'
467 <           txt += '            echo "output registered to LFC"\n'
468 <           txt += '         fi \n'
469 <           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
470 <           txt += '      done\n'
471 <           txt += '   else \n'
472 <           txt += '      echo "Trying to copy output file to CloseSE"\n'
473 <           txt += '      CLOSE_SE=`glite-brokerinfo getCloseSEs | head -1`\n'
474 <           txt += '      for out_file in $file_list ; do\n'
475 <           txt += '         echo "lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1" \n'
476 <           txt += '         lcg-cr -v -l lfn:${LFN}/$out_file -d $CLOSE_SE -P $LFN/$out_file --vo $VO file://$RUNTIME_AREA/$out_file 2>&1 \n'
477 <           txt += '         register_exit_status=$?\n'
478 <           txt += '         echo "REGISTER_EXIT_STATUS = $register_exit_status"\n'
479 <           txt += '         echo "STAGE_OUT = $register_exit_status"\n'
480 <           txt += '         if [ $register_exit_status -ne 0 ]; then \n'
481 <           txt += '            echo "Problems with CloseSE or Catalog" \n'
482 <           txt += '         else \n'
483 <           txt += '            echo "The program was successfully executed"\n'
484 <           txt += '            echo "SE = $CLOSE_SE"\n'
485 <           txt += '            echo "LFN for the file is LFN=${LFN}/$out_file"\n'
486 <           txt += '         fi \n'
487 <           txt += '         echo "StageOutExitStatus = $register_exit_status" | tee -a $RUNTIME_AREA/$repo\n'
488 <           txt += '      done\n'
489 <           txt += '   fi \n'
490 <           txt += '   exit_status=$register_exit_status\n'
491 <           txt += 'fi \n'
492 <        return txt
493 <
235 >        
236      def loggingInfo(self, id):
237          """
238          retrieve the logging info from logging and bookkeeping and return it
239          """
240          self.checkProxy()
241 <        cmd = 'glite-job-logging-info -v 2 ' + id
500 <        #cmd_out = os.popen(cmd)
241 >        cmd = 'glite-job-logging-info -v 3 ' + id
242          cmd_out = runCommand(cmd)
243          return cmd_out
244  
504
505    def getExitStatus(self, id):
506        return self.getStatusAttribute_(id, 'exit_code')
507
508    def queryStatus(self, id):
509        return self.getStatusAttribute_(id, 'status')
510
511    def queryDest(self, id):  
512        return self.getStatusAttribute_(id, 'destination')
513
514
515    def getStatusAttribute_(self, id, attr):
516        """ Query a status of the job with id """
517
518        self.checkProxy()
519        hstates = {}
520        Status = importName('edg_wl_userinterface_common_LbWrapper', 'Status')
521        # Bypass edg-job-status interfacing directly to C++ API
522        # Job attribute vector to retrieve status without edg-job-status
523        level = 0
524        # Instance of the Status class provided by LB API
525        jobStat = Status()
526        st = 0
527        jobStat.getStatus(id, level)
528        err, apiMsg = jobStat.get_error()
529        if err:
530            common.logger.debug(5,'Error caught' + apiMsg)
531            return None
532        else:
533            for i in range(len(self.states)):
534                # Fill an hash table with all information retrieved from LB API
535                hstates[ self.states[i] ] = jobStat.loadStatus(st)[i]
536            result = jobStat.loadStatus(st)[ self.states.index(attr) ]
537            return result
538
245      def queryDetailedStatus(self, id):
246          """ Query a detailed status of the job with id """
247          cmd = 'glite-job-status '+id
248          cmd_out = runCommand(cmd)
249          return cmd_out
250  
251 <    ##### FEDE ######        
252 <    def findSites_(self, n_tot_job):
253 <        itr4 = []
254 <       # print "n_tot_job = ", n_tot_job
255 <        for n in range(n_tot_job):
550 <            sites = common.jobDB.destination(n)
551 <            #job = common.job_list[n]
552 <            #jbt = job.type()
553 <           # print "common.jobDB.destination(n) = ", common.jobDB.destination(n)
554 <           # print "sites = ", sites
555 <            itr = ''
556 <            for site in sites:
557 <                #itr = itr + 'target.GlueSEUniqueID==&quot;'+site+'&quot; || '
558 <                itr = itr + 'target.GlueSEUniqueID=="'+site+'" || '
559 <                pass
560 <            # remove last ||
561 <            itr = itr[0:-4]
562 <            itr4.append( itr )
563 <        # remove last ,
564 <       # print "itr4 = ", itr4
565 <        return itr4
566 <
567 <    def createXMLSchScript(self, nj, argsList):
568 <   # def createXMLSchScript(self, nj):
569 <        """
570 <        Create a XML-file for BOSS4.
571 <        """
572 <  #      job = common.job_list[nj]
573 <        """
574 <        INDY
575 <        [begin] da rivedere:
576 <        in particolare passerei il jobType ed eliminerei le dipendenze da job
577 <        """
578 <        index = nj - 1
579 <        job = common.job_list[index]
580 <        jbt = job.type()
581 <        
582 <        inp_sandbox = jbt.inputSandbox(index)
583 <        out_sandbox = jbt.outputSandbox(index)
584 <        """
585 <        [end] da rivedere
586 <        """
587 <
588 <        
589 <        title = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
590 <        jt_string = ''
591 <        
592 <        xml_fname = str(self.jobtypeName)+'.xml'
593 <        xml = open(common.work_space.shareDir()+'/'+xml_fname, 'a')
594 <
595 <        #TaskName  
596 <        dir = string.split(common.work_space.topDir(), '/')
597 <        taskName = dir[len(dir)-2]
598 <  
599 <        to_writeReq = ''
600 <        to_write = ''
601 <
602 <        req=' '
603 <        req = req + jbt.getRequirements(nj)
604 <
605 <
606 <        #sites = common.jobDB.destination(nj)
607 <        #if len(sites)>0 and sites[0]!="Any":
608 <        #    req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
609 <        #req = req    
610 <    
611 <        if self.EDG_requirements:
612 <            if (req == ' '):
613 <                req = req + self.EDG_requirements
614 <            else:
615 <                req = req +  ' && ' + self.EDG_requirements
616 <        if self.EDG_ce_white_list:
617 <            ce_white_list = string.split(self.EDG_ce_white_list,',')
618 <            for i in range(len(ce_white_list)):
619 <                if i == 0:
620 <                    if (req == ' '):
621 <                        req = req + '((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
622 <                    else:
623 <                        req = req +  ' && ((RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
624 <                    pass
625 <                else:
626 <                    req = req +  ' || (RegExp("' + ce_white_list[i] + '", other.GlueCEUniqueId))'
627 <            req = req + ')'
628 <        
629 <        if self.EDG_ce_black_list:
630 <            ce_black_list = string.split(self.EDG_ce_black_list,',')
631 <            for ce in ce_black_list:
632 <                if (req == ' '):
633 <                    req = req + '(!RegExp("' + ce + '", other.GlueCEUniqueId))'
634 <                else:
635 <                    req = req +  ' && (!RegExp("' + ce + '", other.GlueCEUniqueId))'
636 <                pass
637 <        if self.EDG_clock_time:
638 <            if (req == ' '):
639 <                req = req + 'other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
640 <            else:
641 <                req = req + ' && other.GlueCEPolicyMaxWallClockTime>='+self.EDG_clock_time
642 <
643 <        if self.EDG_cpu_time:
644 <            if (req == ' '):
645 <                req = req + ' other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
646 <            else:
647 <                req = req + ' && other.GlueCEPolicyMaxCPUTime>='+self.EDG_cpu_time
648 <
649 <        #if (req != ' '):
650 <        #    req = req + '\n'
651 <        #    to_writeReq = req
652 <                                                                                                                                                            
653 <        if ( self.EDG_retry_count ):              
654 <            to_write = to_write + 'RetryCount = "'+self.EDG_retry_count+'"\n'
655 <            pass
656 <
657 <        to_write = to_write + 'MyProxyServer = "&quot;' + self.proxyServer + '&quot;"\n'
658 <        to_write = to_write + 'VirtualOrganisation = "&quot;' + self.VO + '&quot;"\n'
659 <
660 <
661 <        #TaskName  
662 <        dir = string.split(common.work_space.topDir(), '/')
663 <        taskName = dir[len(dir)-2]
664 <
665 <        xml.write(str(title))
666 <        xml.write('<task name="' +str(taskName)+'">\n')
667 <        xml.write(jt_string)
668 <
669 <        xml.write('<iterator>\n')
670 <
671 <        #print str(nj)
672 < #        xml.write('\t<iteratorRule name="ITR1" rule="1:'+ str(nj) + '" />\n')
673 <        #print argsList
674 < #        xml.write('\t<iteratorRule name="ITR2" rule="'+ argsList + '" />\n')
675 <        #print jobList
676 < #        xml.write('\t<iteratorRule name="ITR3" rule="1:'+ str(nj) + ':6" />\n')        #print str(nj)
677 <        xml.write('\t<iteratorRule name="ITR1">\n')
678 <        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ' </ruleElement>\n')
679 <        xml.write('\t</iteratorRule>\n')
680 <        xml.write('\t<iteratorRule name="ITR2">\n')
681 <        #print argsList
682 <        for arg in argsList:
683 <            xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
684 <            pass
685 <        xml.write('\t</iteratorRule>\n')
686 <        #print jobList
687 <        xml.write('\t<iteratorRule name="ITR3">\n')
688 <        xml.write('\t\t<ruleElement> 1:'+ str(nj) + ':1:6 </ruleElement>\n')
689 <        xml.write('\t</iteratorRule>\n')
690 <
691 <        #### FEDE #####
692 <        '''
693 <        indy: qui sotto ci sta itr4
694 <        '''
695 <        
696 <        itr4=self.findSites_(nj)
697 <        #print "--->>> itr4 = ", itr4
698 <        if (itr4 != ''):
699 <            xml.write('\t<iteratorRule name="ITR4">\n')
700 <        #print argsList
701 <            for arg in itr4:
702 <                xml.write('\t\t<ruleElement> <![CDATA[\n'+ arg + '\n\t\t]]> </ruleElement>\n')
703 <                pass
704 <            xml.write('\t</iteratorRule>\n')
705 <            req = req + ' && anyMatch(other.storage.CloseSEs, (_ITR4_))'
706 <            pass
707 <        #    print "--->>> req= ", req        
708 <        
709 <        if (to_write != ''):
710 <            xml.write('<extraTags\n')
711 <            xml.write(to_write)
712 <            xml.write('/>\n')
713 <            pass
714 <
715 <        xml.write('<chain scheduler="'+str(self.schedulerName)+'">\n')
716 <        xml.write(jt_string)
717 <
718 <        if (req != ' '):
719 <            req = req + '\n'
720 <            xml.write('<extraTags>\n')
721 <            xml.write('<Requirements>\n')
722 <            xml.write('<![CDATA[\n')
723 <            xml.write(req)
724 <            xml.write(']]>\n')
725 <            xml.write('</Requirements>\n')
726 <            xml.write('</extraTags>\n')
727 <            pass
251 >    def findSites_(self, n):
252 >        sites = common.jobDB.destination(n)
253 >        if len(sites)>0 and sites[0]=="":
254 >            return []
255 >        return sites
256  
257 <        #executable
257 >    def submitTout(self, list):
258 >        return 120
259  
731        """
732        INDY
733        script dipende dal jobType: dovrebbe essere semplice tirarlo fuori in altro modo
734        """        
735        script = job.scriptFilename()
736        xml.write('<program>\n')
737        xml.write('<exec> ' + os.path.basename(script) +' </exec>\n')
738        xml.write(jt_string)
739    
740          
741        ### only one .sh  JDL has arguments:
742        ### Fabio
743 #        xml.write('args = "' + str(nj+1)+' '+ jbt.getJobTypeArguments(nj, "EDG") +'"\n')
744        xml.write('<args> <![CDATA[\n _ITR2_ \n]]> </args>\n')
745        xml.write('<program_types> crabjob </program_types>\n')
746        inp_box = script + ','
747
748        if inp_sandbox != None:
749            for fl in inp_sandbox:
750                inp_box = inp_box + '' + fl + ','
751                pass
752            pass
753
754        # Marco (VERY TEMPORARY ML STUFF)
755        inp_box = inp_box + os.path.abspath(os.environ['CRABDIR']+'/python/'+'report.py') + ',' +\
756                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'DashboardAPI.py') + ','+\
757                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'Logger.py') + ','+\
758                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'ProcInfo.py') + ','+\
759                  os.path.abspath(os.environ['CRABDIR']+'/python/'+'apmon.py')
760        # End Marco
761
762        if (not jbt.additional_inbox_files == []):
763            inp_box = inp_box + ', '
764            for addFile in jbt.additional_inbox_files:
765                addFile = os.path.abspath(addFile)
766                inp_box = inp_box+''+addFile+','
767                pass
768
769        if inp_box[-1] == ',' : inp_box = inp_box[:-1]
770        inp_box = '<infiles> <![CDATA[\n' + inp_box + '\n]]> </infiles>\n'
771        xml.write(inp_box)
772        
773        base = jbt.name()
774        stdout = base + '__ITR3_.stdout'
775        stderr = base + '__ITR3_.stderr'
776        
777        xml.write('<stderr> ' + stderr + '</stderr>\n')
778        xml.write('<stdout> ' + stdout + '</stdout>\n')
779        
780
781        out_box = stdout + ',' + \
782                  stderr + ',.BrokerInfo,'
783
784        """
785        if int(self.return_data) == 1:
786            if out_sandbox != None:
787                for fl in out_sandbox:
788                    out_box = out_box + '' + fl + ','
789                    pass
790                pass
791            pass
792        """
793
794        """
795        INDY
796        qualcosa del genere andrebbe fatta per gli infiles
797        """        
798        if int(self.return_data) == 1:
799            for fl in jbt.output_file:
800                out_box = out_box + '' + jbt.numberFile_(fl, '_ITR1_') + ','
801                pass
802            pass
803
804        if out_box[-1] == ',' : out_box = out_box[:-1]
805        out_box = '<outfiles> <![CDATA[\n' + out_box + '\n]]></outfiles>\n'
806        xml.write(out_box)
807
808        xml.write('<BossAttr> crabjob.INTERNAL_ID=_ITR1_ </BossAttr>\n')
809
810        xml.write('</program>\n')
811        xml.write('</chain>\n')
812
813        xml.write('</iterator>\n')
814        xml.write('</task>\n')
815
816        xml.close()
817        return
818
819    def checkProxy(self):
820        """
821        Function to check the Globus proxy.
822        """
823        if (self.proxyValid): return
824        timeleft = -999
825        minTimeLeft=10*3600 # in seconds
826
827        minTimeLeftServer = 100 # in hours
828
829        mustRenew = 0
830        timeLeftLocal = runCommand('voms-proxy-info -timeleft 2>/dev/null')
831        timeLeftServer = -999
832        if not timeLeftLocal or int(timeLeftLocal) <= 0 or not isInt(timeLeftLocal):
833            mustRenew = 1
834        else:
835            timeLeftServer = runCommand('voms-proxy-info -actimeleft 2>/dev/null | head -1')
836            if not timeLeftServer or not isInt(timeLeftServer):
837                mustRenew = 1
838            elif timeLeftLocal<minTimeLeft or timeLeftServer<minTimeLeft:
839                mustRenew = 1
840            pass
841        pass
842
843        if mustRenew:
844            common.logger.message( "No valid proxy found or remaining time of validity of already existing proxy shorter than 10 hours!\n Creating a user proxy with default length of 96h\n")
845            cmd = 'voms-proxy-init -voms cms -valid 96:00'
846            try:
847                # SL as above: damn it!
848                out = os.system(cmd)
849                if (out>0): raise CrabException("Unable to create a valid proxy!\n")
850            except:
851                msg = "Unable to create a valid proxy!\n"
852                raise CrabException(msg)
853            pass
854
855        ## now I do have a voms proxy valid, and I check the myproxy server
856        renewProxy = 0
857        cmd = 'myproxy-info -d -s '+self.proxyServer
858        cmd_out = runCommand(cmd,0,20)
859        if not cmd_out:
860            common.logger.message('No credential delegated to myproxy server '+self.proxyServer+' will do now')
861            renewProxy = 1
862        else:
863            # if myproxy exist but not long enough, renew
864            reTime = re.compile( r'timeleft: (\d+)' )
865            if reTime.match( cmd_out ):
866                time = reTime.search( line ).group(1)
867                if time < minTimeLeftServer:
868                    renewProxy = 1
869                    common.logger.message('No credential delegation will expire in '+time+' hours: renew it')
870                pass
871            pass
872        
873        # if not, create one.
874        if renewProxy:
875            cmd = 'myproxy-init -d -n -s '+self.proxyServer
876            out = os.system(cmd)
877            if (out>0):
878                raise CrabException("Unable to delegate the proxy to myproxyserver "+self.proxyServer+" !\n")
879            pass
880
881        # cache proxy validity
882        self.proxyValid=1
883        return
884
885    def configOpt_(self):
886        edg_ui_cfg_opt = ' '
887        if self.edg_config:
888            edg_ui_cfg_opt = ' -c ' + self.edg_config + ' '
889        if self.edg_config_vo:
890            edg_ui_cfg_opt += ' --config-vo ' + self.edg_config_vo + ' '
891        return edg_ui_cfg_opt

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines