37
37
"""
38
38
import os
39
39
import stat
40
+ import sys
40
41
41
42
import arc # Has to work if this module is called #pylint: disable=import-error
42
- from DIRAC import S_OK , S_ERROR , gConfig
43
- from DIRAC .ConfigurationSystem .Client .Helpers .Resources import getCESiteMapping
43
+ from DIRAC import S_OK , S_ERROR
44
44
from DIRAC .Core .Utilities .Subprocess import shellCall
45
45
from DIRAC .Core .Utilities .File import makeGuid
46
46
from DIRAC .Core .Utilities .List import breakListIntoChunks
50
50
from DIRAC .WorkloadManagementSystem .Client import PilotStatus
51
51
52
52
53
- # Uncomment the following 5 lines for getting verbose ARC api output (debugging)
54
- # import sys
55
- # logstdout = arc.LogStream(sys.stdout)
56
- # logstdout.setFormat(arc.ShortFormat)
57
- # arc.Logger_getRootLogger().addDestination(logstdout)
58
- # arc.Logger_getRootLogger().setThreshold(arc.VERBOSE)
59
-
60
53
MANDATORY_PARAMETERS = ["Queue" ] # Mandatory for ARC CEs in GLUE2?
61
54
STATES_MAP = {
62
55
"Accepted" : PilotStatus .WAITING ,
77
70
78
71
class ARCComputingElement (ComputingElement ):
79
72
73
+ _arcLevels = ["DEBUG" , "VERBOSE" , "INFO" , "WARNING" , "ERROR" , "FATAL" ]
74
+
80
75
#############################################################################
81
76
def __init__ (self , ceUniqueID ):
82
77
"""Standard constructor."""
@@ -117,14 +112,14 @@ def _getARCJob(self, jobID):
117
112
j .JobStatusURL = arc .URL (str (statURL ))
118
113
j .JobStatusInterfaceName = "org.nordugrid.ldapng"
119
114
120
- mangURL = "gsiftp://%s :2811/jobs/" % ( self . ceHost )
115
+ mangURL = f "gsiftp://{ self . ceHost } :2811/jobs/"
121
116
j .JobManagementURL = arc .URL (str (mangURL ))
122
117
j .JobManagementInterfaceName = "org.nordugrid.gridftpjob"
123
118
124
119
j .ServiceInformationURL = j .JobManagementURL
125
120
j .ServiceInformationInterfaceName = "org.nordugrid.ldapng"
126
121
else :
127
- commonURL = "https://%s :8443/arex" % self . ceHost
122
+ commonURL = f "https://{ self . ceHost } :8443/arex"
128
123
j .JobStatusURL = arc .URL (str (commonURL ))
129
124
j .JobStatusInterfaceName = "org.ogf.glue.emies.activitymanagement"
130
125
@@ -195,7 +190,7 @@ def _writeXRSL(self, executableFile, inputs=None, outputs=None, executables=None
195
190
if not isinstance (outputs , list ):
196
191
outputs = [outputs ]
197
192
for outputFile in outputs :
198
- xrslOutputs += '(%s "")' % ( outputFile )
193
+ xrslOutputs += f'( { outputFile } "")'
199
194
200
195
xrsl = """
201
196
&(executable="{executable}")
@@ -244,6 +239,23 @@ def _reset(self):
244
239
self .log .warn ("Unknown ARC endpoint, change to default" , self .endpointType )
245
240
else :
246
241
self .endpointType = endpointType
242
+
243
+ # ARCLogLevel to enable/disable logs coming from the ARC client
244
+ # Because the ARC logger works independently from the standard logging library,
245
+ # it needs a specific initialization flag
246
+ # Expected values are: ["", "DEBUG", "VERBOSE", "INFO", "WARNING", "ERROR" and "FATAL"]
247
+ # Modifying the ARCLogLevel of an ARCCE instance would impact all existing instances within a same process.
248
+ logLevel = self .ceParameters .get ("ARCLogLevel" , "" )
249
+ if logLevel :
250
+ arc .Logger_getRootLogger ().removeDestinations ()
251
+ if logLevel not in self ._arcLevels :
252
+ self .log .warn ("ARCLogLevel input is not known:" , f"{ logLevel } not in { self ._arcLevels } " )
253
+ else :
254
+ logstdout = arc .LogStream (sys .stdout )
255
+ logstdout .setFormat (arc .ShortFormat )
256
+ arc .Logger_getRootLogger ().addDestination (logstdout )
257
+ arc .Logger_getRootLogger ().setThreshold (getattr (arc , logLevel ))
258
+
247
259
return S_OK ()
248
260
249
261
#############################################################################
@@ -259,7 +271,7 @@ def submitJob(self, executableFile, proxy, numberOfJobs=1, inputs=None, outputs=
259
271
return result
260
272
self .usercfg .ProxyPath (os .environ ["X509_USER_PROXY" ])
261
273
262
- self .log .verbose ("Executable file path: %s" % executableFile )
274
+ self .log .verbose (f "Executable file path: { executableFile } " )
263
275
if not os .access (executableFile , 5 ):
264
276
os .chmod (executableFile , stat .S_IRWXU | stat .S_IRGRP | stat .S_IXGRP | stat .S_IROTH + stat .S_IXOTH )
265
277
@@ -286,8 +298,8 @@ def submitJob(self, executableFile, proxy, numberOfJobs=1, inputs=None, outputs=
286
298
jobdescs = arc .JobDescriptionList ()
287
299
# Get the job into the ARC way
288
300
xrslString , diracStamp = self ._writeXRSL (executableFile , inputs , outputs , executables )
289
- self .log .debug ("XRSL string submitted : %s" % xrslString )
290
- self .log .debug ("DIRAC stamp for job : %s" % diracStamp )
301
+ self .log .debug (f "XRSL string submitted : { xrslString } " )
302
+ self .log .debug (f "DIRAC stamp for job : { diracStamp } " )
291
303
# The arc bindings don't accept unicode objects in Python 2 so xrslString must be explicitly cast
292
304
result = arc .JobDescription .Parse (str (xrslString ), jobdescs )
293
305
if not result :
0 commit comments