CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
tier0.Tier0Handler Class Reference
Inheritance diagram for tier0.Tier0Handler:

Public Member Functions

def __init__ (self, uri, timeOut, maxTime, retries, retryPeriod, proxy, debug)
 
def getFirstSafeRun (self)
 
def getGlobalTag (self, config)
 
def setDebug (self)
 
def setProxy (self, proxy)
 
def unsetDebug (self)
 

Private Member Functions

def _curlQueryTier0
 
def _getCerts (self)
 
def _queryTier0DataSvc (self, url)
 

Private Attributes

 _debug
 
 _maxTime
 
 _proxy
 
 _retries
 
 _retryPeriod
 
 _timeOut
 
 _uri
 

Detailed Description

Definition at line 71 of file tier0.py.

Constructor & Destructor Documentation

◆ __init__()

def tier0.Tier0Handler.__init__ (   self,
  uri,
  timeOut,
  maxTime,
  retries,
  retryPeriod,
  proxy,
  debug 
)
Parameters:
uri: Tier0DataSvc URI;
timeOut: time out for connection of Tier0DataSvc HTTPS calls [seconds];
maxTime: maximum time for Tier0DataSvc HTTPS calls (including data transfer) [seconds];
retries: maximum retries for Tier0DataSvc HTTPS calls;
retryPeriod: sleep time between two Tier0DataSvc HTTPS calls [seconds];
proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls;
debug: if set to True, enables debug information.

Definition at line 73 of file tier0.py.

73  def __init__( self, uri, timeOut, maxTime, retries, retryPeriod, proxy, debug ):
74  """
75  Parameters:
76  uri: Tier0DataSvc URI;
77  timeOut: time out for connection of Tier0DataSvc HTTPS calls [seconds];
78  maxTime: maximum time for Tier0DataSvc HTTPS calls (including data transfer) [seconds];
79  retries: maximum retries for Tier0DataSvc HTTPS calls;
80  retryPeriod: sleep time between two Tier0DataSvc HTTPS calls [seconds];
81  proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls;
82  debug: if set to True, enables debug information.
83  """
84  self._uri = uri
85  self._timeOut = timeOut
86  self._maxTime = maxTime
87  self._retries = retries
88  self._retryPeriod = retryPeriod
89  self._proxy = proxy
90  self._debug = debug
91 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ _curlQueryTier0()

def tier0.Tier0Handler._curlQueryTier0 (   self,
  url 
)
private

Definition at line 116 of file tier0.py.

References EcalMatacqAnalyzer._debug, EcalABAnalyzer._debug, tier0.Tier0Handler._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, EcalLaserAnalyzer._debug, tier0.Tier0Handler._getCerts(), and tier0.Tier0Handler._proxy.

Referenced by tier0.Tier0Handler._queryTier0DataSvc().

116  def _curlQueryTier0( self, url:str, force_debug:bool = False, force_cert:bool = False):
117  userAgent = "User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" \
118  % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
119  debug = "-v" if self._debug or force_debug else "-s -S"
120 
121  proxy = f"--proxy {self._proxy}" if self._proxy else ""
122  certs = self._getCerts() if not self._proxy or force_cert else ""
123 
124  cmd = f'/usr/bin/curl -k -L --user-agent "{userAgent}" {proxy}'\
125  f' --connect-timeout {self._timeOut} --max-time {self._maxTime} --retry {self._retries}'\
126  f' {debug} {url} {certs}'
127 
128  # time the curl to understand if re-tries have been carried out
129  start = time.time()
130  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
131  (stdoutdata, stderrdata) = process.communicate()
132  end = time.time()
133  return process.returncode, stdoutdata, stderrdata, end-start
134 

◆ _getCerts()

def tier0.Tier0Handler._getCerts (   self,
  str 
)
private

Definition at line 101 of file tier0.py.

Referenced by tier0.Tier0Handler._curlQueryTier0().

101  def _getCerts( self ) -> str:
102  cert_path = os.getenv('X509_USER_CERT', '')
103  key_path = os.getenv('X509_USER_KEY', '')
104 
105  certs = ""
106  if cert_path:
107  certs += f' --cert {cert_path}'
108  else:
109  logging.warning("No certificate provided for Tier0 access, use X509_USER_CERT and"
110  " optionally X509_USER_KEY env variables to specify the path to the cert"
111  " (and the key unless included in the cert file)")
112  if key_path:
113  certs += f' --key {key_path}'
114  return certs
115 

◆ _queryTier0DataSvc()

def tier0.Tier0Handler._queryTier0DataSvc (   self,
  url 
)
private
Queries Tier0DataSvc.
url: Tier0DataSvc URL.
@returns: dictionary, from whence the required information must be retrieved according to the API call.
Raises if connection error, bad response, or timeout after retries occur.

Definition at line 135 of file tier0.py.

References tier0.Tier0Handler._curlQueryTier0(), tier0.Tier0Handler._proxy, tier0.Tier0Handler._retryPeriod, join(), python.rootplot.root2matplotlib.replace(), and str.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0Handler.getFirstSafeRun(), tier0.Tier0Handler.getFirstSafeRun(), FrontierCondition_GT_autoExpress_cfi.Tier0Handler.getGlobalTag(), and tier0.Tier0Handler.getGlobalTag().

135  def _queryTier0DataSvc( self, url ):
136  """
137  Queries Tier0DataSvc.
138  url: Tier0DataSvc URL.
139  @returns: dictionary, from whence the required information must be retrieved according to the API call.
140  Raises if connection error, bad response, or timeout after retries occur.
141  """
142 
143  retcode, stdoutdata, stderrdata, query_time = self._curlQueryTier0(url)
144 
145  if retcode != 0 or stderrdata:
146 
147  # if the first curl has failed, logg its stderror and prepare and independent retry
148  msg = "looks like curl returned an error: retcode=%s and took %s seconds" % (retcode, query_time,)
149  msg += ' msg = "'+str(stderrdata)+'"'
150  logging.error(msg)
151  if self._proxy:
152  logging.info("before assumed proxy provides authentication, now trying with both proxy and certificate")
153 
154  time.sleep(self._retryPeriod)
155  retcode, stdoutdata, stderrdata, query_time = self._curlQueryTier0(url, force_debug=True, force_cert=True)
156  if retcode != 0:
157  msg = "looks like curl returned an error for the second time: retcode=%s" % (retcode,)
158  msg += ' msg = "'+str(stderrdata)+'"'
159  logging.error(msg)
160  raise Tier0Error(msg)
161  else:
162  msg = "curl returned ok upon the second try"
163  logging.info(msg)
164  resp = json.loads( ''.join(stdoutdata.decode()).replace( "'", '"').replace(' None', ' "None"') )
165  return resp
166 
167 
def replace(string, replacements)
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define str(s)

◆ getFirstSafeRun()

def tier0.Tier0Handler.getFirstSafeRun (   self)
Queries Tier0DataSvc to get the first condition safe run.
Parameters:
@returns: integer, the run number.
Raises if connection error, bad response, timeout after retries occur, or if the run number is not available.

Definition at line 168 of file tier0.py.

References tier0.Tier0Handler._proxy, tier0.Tier0Handler._queryTier0DataSvc(), tier0.Tier0Handler._uri, createfilelist.int, and str.

168  def getFirstSafeRun( self ):
169  """
170  Queries Tier0DataSvc to get the first condition safe run.
171  Parameters:
172  @returns: integer, the run number.
173  Raises if connection error, bad response, timeout after retries occur, or if the run number is not available.
174  """
175  firstConditionSafeRunAPI = "firstconditionsaferun"
176  safeRunDict = self._queryTier0DataSvc( os.path.join( self._uri, firstConditionSafeRunAPI ) )
177  if safeRunDict is None:
178  errStr = """First condition safe run is not available in Tier0DataSvc from URL \"%s\"""" \
179  %( os.path.join( self._uri, firstConditionSafeRunAPI ), )
180  if self._proxy:
181  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
182  raise Tier0Error( errStr )
183  return int(safeRunDict['result'][0])
184 
#define str(s)

◆ getGlobalTag()

def tier0.Tier0Handler.getGlobalTag (   self,
  config 
)
Queries Tier0DataSvc to get the most recent Global Tag for a given workflow.
Parameters:
config: Tier0DataSvc API call for the workflow to be looked for;
@returns: a string with the Global Tag name.
Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available.

Definition at line 185 of file tier0.py.

References tier0.Tier0Handler._proxy, tier0.Tier0Handler._queryTier0DataSvc(), tier0.Tier0Handler._uri, str, and tier0.unique().

185  def getGlobalTag( self, config ):
186  """
187  Queries Tier0DataSvc to get the most recent Global Tag for a given workflow.
188  Parameters:
189  config: Tier0DataSvc API call for the workflow to be looked for;
190  @returns: a string with the Global Tag name.
191  Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available.
192  """
193  data = self._queryTier0DataSvc( os.path.join( self._uri, config ) )
194  gtnames = sorted(unique( [ str( di['global_tag'] ) for di in data['result'] if di['global_tag'] is not None ] ))
195  try:
196  recentGT = gtnames[-1]
197  return recentGT
198  except IndexError:
199  errStr = """No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\"""" \
200  %( config, os.path.join( self._uri, config ) )
201  if self._proxy:
202  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
203  raise Tier0Error( errStr )
204 
205 
def unique(seq, keepstr=True)
Definition: tier0.py:24
#define str(s)

◆ setDebug()

def tier0.Tier0Handler.setDebug (   self)

Definition at line 92 of file tier0.py.

References EcalMatacqAnalyzer._debug, EcalABAnalyzer._debug, tier0.Tier0Handler._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, and EcalLaserAnalyzer._debug.

92  def setDebug( self ):
93  self._debug = True
94 

◆ setProxy()

def tier0.Tier0Handler.setProxy (   self,
  proxy 
)

Definition at line 98 of file tier0.py.

References tier0.Tier0Handler._proxy.

98  def setProxy( self, proxy ):
99  self._proxy = proxy
100 

◆ unsetDebug()

def tier0.Tier0Handler.unsetDebug (   self)

Definition at line 95 of file tier0.py.

References EcalMatacqAnalyzer._debug, EcalABAnalyzer._debug, tier0.Tier0Handler._debug, uploads.uploader._debug, EcalLaserAnalyzer2._debug, and EcalLaserAnalyzer._debug.

95  def unsetDebug( self ):
96  self._debug = False
97 

Member Data Documentation

◆ _debug

tier0.Tier0Handler._debug
private

◆ _maxTime

tier0.Tier0Handler._maxTime
private

Definition at line 86 of file tier0.py.

◆ _proxy

tier0.Tier0Handler._proxy
private

◆ _retries

tier0.Tier0Handler._retries
private

◆ _retryPeriod

tier0.Tier0Handler._retryPeriod
private

Definition at line 88 of file tier0.py.

Referenced by tier0.Tier0Handler._queryTier0DataSvc().

◆ _timeOut

tier0.Tier0Handler._timeOut
private

◆ _uri

tier0.Tier0Handler._uri
private