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

Constructor & Destructor Documentation

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

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

Member Function Documentation

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

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

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

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

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

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

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

Definition at line 91 of file tier0.py.

References tier0.Tier0Handler._proxy.

91  def setProxy( self, proxy ):
92  self._proxy = proxy
93 
def setProxy(self, proxy)
Definition: tier0.py:91
def tier0.Tier0Handler.unsetDebug (   self)

Member Data Documentation

tier0.Tier0Handler._debug
private
tier0.Tier0Handler._proxy
private
tier0.Tier0Handler._retries
private
tier0.Tier0Handler._retryPeriod
private

Definition at line 81 of file tier0.py.

tier0.Tier0Handler._timeOut
private
tier0.Tier0Handler._uri
private