Esempio n. 1
0
  def __init__(
          self,
          requestJSON,
          handlersDict,
          csPath,
          agentName,
          standalone=False,
          requestClient=None):
    """c'tor

    :param self: self reference
    :param str requestJSON: request serialized to JSON
    :param dict opHandlers: operation handlers
    """
    self.request = Request(requestJSON)
    # # csPath
    self.csPath = csPath
    # # agent name
    self.agentName = agentName
    # # standalone flag
    self.standalone = standalone
    # # handlers dict
    self.handlersDict = handlersDict
    # # handlers class def
    self.handlers = {}
    # # own sublogger
    self.log = gLogger.getSubLogger("pid_%s/%s" % (os.getpid(), self.request.RequestName))
    # # get shifters info
    self.__managersDict = {}
    shifterProxies = self.__setupManagerProxies()
    if not shifterProxies["OK"]:
      self.log.error(shifterProxies["Message"])

    # # initialize gMonitor
    gMonitor.setComponentType(gMonitor.COMPONENT_AGENT)
    gMonitor.setComponentName(self.agentName)
    gMonitor.initialize()

    # # own gMonitor activities
    gMonitor.registerActivity("RequestAtt", "Requests processed",
                              "RequestExecutingAgent", "Requests/min", gMonitor.OP_SUM)
    gMonitor.registerActivity("RequestFail", "Requests failed",
                              "RequestExecutingAgent", "Requests/min", gMonitor.OP_SUM)
    gMonitor.registerActivity("RequestOK", "Requests done",
                              "RequestExecutingAgent", "Requests/min", gMonitor.OP_SUM)

    if requestClient is None:
      self.requestClient = ReqClient()
    else:
      self.requestClient = requestClient
Esempio n. 2
0
def initialize(script=False, ignoreErrors=False, initializeMonitor=False, enableCommandLine=False):
  global scriptName, gIsAlreadyInitialized

  # Please do not call initialize in every file
  if gIsAlreadyInitialized:
    return False
  gIsAlreadyInitialized = True

  userDisabled = not localCfg.isCSEnabled()
  if not userDisabled:
    localCfg.disableCS()

  if not enableCommandLine:
    localCfg.disableParsingCommandLine()

  if script:
    scriptName = script
  localCfg.setConfigurationForScript(scriptName)

  if not ignoreErrors:
    localCfg.addMandatoryEntry("/DIRAC/Setup")
  resultDict = localCfg.loadUserData()
  if not ignoreErrors and not resultDict['OK']:
    gLogger.error("There were errors when loading configuration", resultDict['Message'])
    sys.exit(1)

  if not userDisabled:
    localCfg.enableCS()

  if initializeMonitor:
    gMonitor.setComponentType(gMonitor.COMPONENT_SCRIPT)
    gMonitor.setComponentName(scriptName)
    gMonitor.setComponentLocation("script")
    gMonitor.initialize()
  else:
    gMonitor.disable()
  includeExtensionErrors()

  return True