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, 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 _queryTier0DataSvc (self, url)
 

Private Attributes

 _debug
 
 _proxy
 
 _retries
 
 _retryPeriod
 
 _timeOut
 
 _uri
 

Detailed Description

Definition at line 65 of file tier0.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 67 of file tier0.py.

67  def __init__( self, uri, timeOut, retries, retryPeriod, proxy, debug ):
68  """
69  Parameters:
70  uri: Tier0DataSvc URI;
71  timeOut: time out for Tier0DataSvc HTTPS calls;
72  retries: maximum retries for Tier0DataSvc HTTPS calls;
73  retryPeriod: sleep time between two Tier0DataSvc HTTPS calls;
74  proxy: HTTP proxy for accessing Tier0DataSvc HTTPS calls;
75  debug: if set to True, enables debug information.
76  """
77  self._uri = uri
78  self._timeOut = timeOut
79  self._retries = retries
80  self._retryPeriod = retryPeriod
81  self._proxy = proxy
82  self._debug = debug
83 

Member Function Documentation

◆ _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 93 of file tier0.py.

93  def _queryTier0DataSvc( self, url ):
94  """
95  Queries Tier0DataSvc.
96  url: Tier0DataSvc URL.
97  @returns: dictionary, from whence the required information must be retrieved according to the API call.
98  Raises if connection error, bad response, or timeout after retries occur.
99  """
100 
101  userAgent = "User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % ( sys.version_info[ :3 ] + ( pycurl.version_info()[ 1 ], ) )
102 
103  proxy = ""
104  if self._proxy: proxy = ' --proxy=%s ' % self._proxy
105 
106  debug = " -s -S "
107  if self._debug: debug = " -v "
108 
109  cmd = '/usr/bin/curl -k -L --user-agent "%s" %s --connect-timeout %i --retry %i %s %s ' % (userAgent, proxy, self._timeOut, self._retries, debug, url)
110 
111  # time the curl to understand if re-tries have been carried out
112  start = time.time()
113  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114  (stdoutdata, stderrdata) = process.communicate()
115  retcode = process.returncode
116  end = time.time()
117 
118  if retcode != 0 or stderrdata:
119  # if the first curl has failed, logg its stderror and prepare and independent retry
120  msg = "looks like curl returned an error: retcode=%s and took %s seconds" % (retcode,(end-start),)
121  msg += ' msg = "'+str(stderrdata)+'"'
122  logging.error(msg)
123 
124  time.sleep(10)
125  cmd = '/usr/bin/curl -k -L --user-agent "%s" %s --connect-timeout %i --retry %i %s %s ' % (userAgent, proxy, self._timeOut, self._retries, "-v", url)
126  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
127  (stdoutdata, stderrdata) = process.communicate()
128  retcode = process.returncode
129  if retcode != 0:
130  msg = "looks like curl returned an error for the second time: retcode=%s" % (retcode,)
131  msg += ' msg = "'+str(stderrdata)+'"'
132  logging.error(msg)
133  raise Tier0Error(msg)
134  else :
135  msg = "curl returned ok upon the second try"
136  logging.info(msg)
137 
138  return json.loads( ''.join(stdoutdata).replace( "'", '"').replace(' None', ' "None"') )
139 
140 

References EcalMatacqAnalyzer._debug, EcalABAnalyzer._debug, tier0.Tier0Handler._debug, EcalLaserAnalyzer2._debug, EcalLaserAnalyzer._debug, uploads.uploader._debug, tier0.Tier0Handler._proxy, tier0.Tier0Handler._retries, tier0.Tier0Handler._timeOut, 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().

◆ 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 141 of file tier0.py.

141  def getFirstSafeRun( self ):
142  """
143  Queries Tier0DataSvc to get the first condition safe run.
144  Parameters:
145  @returns: integer, the run number.
146  Raises if connection error, bad response, timeout after retries occur, or if the run number is not available.
147  """
148  firstConditionSafeRunAPI = "firstconditionsaferun"
149  safeRunDict = self._queryTier0DataSvc( os.path.join( self._uri, firstConditionSafeRunAPI ) )
150  if safeRunDict is None:
151  errStr = """First condition safe run is not available in Tier0DataSvc from URL \"%s\"""" %( os.path.join( self._uri, firstConditionSafeRunAPI ), )
152  if self._proxy:
153  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
154  raise Tier0Error( errStr )
155  return int(safeRunDict['result'][0])
156 

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

◆ 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 157 of file tier0.py.

157  def getGlobalTag( self, config ):
158  """
159  Queries Tier0DataSvc to get the most recent Global Tag for a given workflow.
160  Parameters:
161  config: Tier0DataSvc API call for the workflow to be looked for;
162  @returns: a string with the Global Tag name.
163  Raises if connection error, bad response, timeout after retries occur, or if no Global Tags are available.
164  """
165  data = self._queryTier0DataSvc( os.path.join( self._uri, config ) )
166  gtnames = sorted(unique( [ str( di[ 'global_tag' ] ) for di in data['result'] if di[ 'global_tag' ] is not None ] ))
167  try:
168  recentGT = gtnames[-1]
169  return recentGT
170  except IndexError:
171  errStr = """No Global Tags for \"%s\" are available in Tier0DataSvc from URL \"%s\"""" %( config, os.path.join( self._uri, config ) )
172  if self._proxy:
173  errStr += """ using proxy \"%s\".""" %( str( self._proxy ), )
174  raise Tier0Error( errStr )
175 
176 

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

◆ setDebug()

def tier0.Tier0Handler.setDebug (   self)

Definition at line 84 of file tier0.py.

84  def setDebug( self ):
85  self._debug = True
86 

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

◆ setProxy()

def tier0.Tier0Handler.setProxy (   self,
  proxy 
)

Definition at line 90 of file tier0.py.

90  def setProxy( self, proxy ):
91  self._proxy = proxy
92 

References tier0.Tier0Handler._proxy.

◆ unsetDebug()

def tier0.Tier0Handler.unsetDebug (   self)

Definition at line 87 of file tier0.py.

87  def unsetDebug( self ):
88  self._debug = False
89 

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

Member Data Documentation

◆ _debug

tier0.Tier0Handler._debug
private

◆ _proxy

tier0.Tier0Handler._proxy
private

◆ _retries

tier0.Tier0Handler._retries
private

◆ _retryPeriod

tier0.Tier0Handler._retryPeriod
private

Definition at line 80 of file tier0.py.

◆ _timeOut

tier0.Tier0Handler._timeOut
private

◆ _uri

tier0.Tier0Handler._uri
private
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
str
#define str(s)
Definition: TestProcessor.cc:51
createfilelist.int
int
Definition: createfilelist.py:10
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444