CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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__
 
def getFirstSafeRun
 
def getGlobalTag
 
def setDebug
 
def setProxy
 
def unsetDebug
 

Private Member Functions

def _queryTier0DataSvc
 

Private Attributes

 _debug
 
 _proxy
 
 _retries
 
 _retryPeriod
 
 _timeOut
 
 _uri
 

Detailed Description

Definition at line 65 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 67 of file tier0.py.

67 
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

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

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

93 
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 
121  # if the first curl has failed, logg its stderror and prepare and independent retry
122  msg = "looks like curl returned an error: retcode=%s and took %s seconds" % (retcode,(end-start),)
123  msg += ' msg = "'+str(stderrdata)+'"'
124  logging.error(msg)
125 
126  time.sleep(10)
127  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)
128  process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
129  (stdoutdata, stderrdata) = process.communicate()
130  retcode = process.returncode
131  if retcode != 0:
132  msg = "looks like curl returned an error for the second time: retcode=%s" % (retcode,)
133  msg += ' msg = "'+str(stderrdata)+'"'
134  logging.error(msg)
135  raise Tier0Error(msg)
136  else :
137  msg = "curl returned ok upon the second try"
138  logging.info(msg)
139  resp = json.loads( ''.join(stdoutdata.decode()).replace( "'", '"').replace(' None', ' "None"') )
140  return resp
141 
def _queryTier0DataSvc
Definition: tier0.py:93
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#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, and str.

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

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

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

Definition at line 84 of file tier0.py.

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

84 
85  def setDebug( self ):
86  self._debug = True
def tier0.Tier0Handler.setProxy (   self,
  proxy 
)

Definition at line 90 of file tier0.py.

References tier0.Tier0Handler._proxy.

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

Definition at line 87 of file tier0.py.

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

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

Member Data Documentation

tier0.Tier0Handler._debug
private

Definition at line 82 of file tier0.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0Handler._queryTier0DataSvc(), tier0.Tier0Handler._queryTier0DataSvc(), FrontierCondition_GT_autoExpress_cfi.Tier0Handler.setDebug(), tier0.Tier0Handler.setDebug(), FrontierCondition_GT_autoExpress_cfi.Tier0Handler.unsetDebug(), and tier0.Tier0Handler.unsetDebug().

tier0.Tier0Handler._proxy
private

Definition at line 81 of file tier0.py.

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

tier0.Tier0Handler._retries
private

Definition at line 79 of file tier0.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0Handler._queryTier0DataSvc(), and tier0.Tier0Handler._queryTier0DataSvc().

tier0.Tier0Handler._retryPeriod
private

Definition at line 80 of file tier0.py.

tier0.Tier0Handler._timeOut
private

Definition at line 78 of file tier0.py.

Referenced by FrontierCondition_GT_autoExpress_cfi.Tier0Handler._queryTier0DataSvc(), and tier0.Tier0Handler._queryTier0DataSvc().

tier0.Tier0Handler._uri
private

Definition at line 77 of file tier0.py.

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