def getCE(self, ceType='', ceName='', ceParametersDict={}):
    """This method returns the CE instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
    self.log.verbose('Creating CE of %s type with the name %s' % (ceType,ceName) )
    ceTypeLocal = ceType
    if not ceTypeLocal:
      ceTypeLocal = self.ceType
    ceNameLocal = ceName
    if not ceNameLocal:
      ceNameLocal = self.ceType 
    ceConfigDict = getCEConfigDict( ceNameLocal )
    self.log.verbose('CEConfigDict',ceConfigDict)
    if 'CEType' in ceConfigDict:
      ceTypeLocal = ceConfigDict['CEType']
    if not ceTypeLocal:
      error = 'Can not determine CE Type'
      self.log.error( error )
      return S_ERROR( error )
    subClassName = "%sComputingElement" % (ceTypeLocal)

    try:
      ceSubClass = __import__('DIRAC.Resources.Computing.%s' % subClassName,globals(),locals(),[subClassName])
    except Exception, x:
      msg = 'ComputingElementFactory could not import DIRAC.Resources.Computing.%s' % ( subClassName )
      self.log.exception()
      self.log.warn( msg )
      return S_ERROR( msg )
    def getCE(self, ceType='', ceName='', ceParametersDict={}):
        """This method returns the CE instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
        ceTypeLocal = ceType
        if not ceTypeLocal:
            ceTypeLocal = self.ceType
        ceNameLocal = ceName
        if not ceNameLocal:
            ceNameLocal = self.ceType
        ceConfigDict = getCEConfigDict(ceNameLocal)
        self.log.info('CEConfigDict', ceConfigDict)
        if 'CEType' in ceConfigDict:
            ceTypeLocal = ceConfigDict['CEType']
        if not ceTypeLocal:
            error = 'Can not determine CE Type'
            self.log.error(error)
            return S_ERROR(error)
        subClassName = "%sComputingElement" % (ceTypeLocal)

        try:
            ceSubClass = __import__(
                'DIRAC.Resources.Computing.%s' % subClassName, globals(),
                locals(), [subClassName])
        except Exception, x:
            msg = 'ComputingElementFactory could not import DIRAC.Resources.Computing.%s' % (
                subClassName)
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)
    def getCE(self, ceType='', ceName='', ceParametersDict={}):
        """This method returns the CE instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
        self.log.verbose('Creating CE of %s type with the name %s' %
                         (ceType, ceName))
        ceTypeLocal = ceType
        if not ceTypeLocal:
            ceTypeLocal = self.ceType
        ceNameLocal = ceName
        if not ceNameLocal:
            ceNameLocal = self.ceType
        ceConfigDict = getCEConfigDict(ceNameLocal)
        self.log.verbose('CEConfigDict', ceConfigDict)
        if 'CEType' in ceConfigDict:
            ceTypeLocal = ceConfigDict['CEType']
        if not ceTypeLocal:
            error = 'Can not determine CE Type'
            self.log.error(error)
            return S_ERROR(error)
        subClassName = "%sComputingElement" % (ceTypeLocal)

        # FIXME: what about extensions?
        # Should use the objectLoader I guess...?
        # In practice, as coded, this is just a redundant check
        try:
            ceSubClass = __import__(
                'DIRAC.Resources.Computing.%s' % subClassName, globals(),
                locals(), [subClassName])
        except Exception, x:
            msg = 'ComputingElementFactory could not import DIRAC.Resources.Computing.%s' % (
                subClassName)
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)
    def getCE(self, ceType='', ceName='', ceParametersDict={}):
        """This method returns the CE instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
        self.log = gLogger.getSubLogger(ceType)
        self.log.verbose('Creating CE of %s type with the name %s' %
                         (ceType, ceName))
        ceTypeLocal = ceType
        if not ceTypeLocal:
            ceTypeLocal = self.ceType
        ceNameLocal = ceName
        if not ceNameLocal:
            ceNameLocal = self.ceType
        ceConfigDict = getCEConfigDict(ceNameLocal)
        self.log.verbose('CEConfigDict', ceConfigDict)
        if 'CEType' in ceConfigDict:
            ceTypeLocal = ceConfigDict['CEType']
        if not ceTypeLocal:
            error = 'Can not determine CE Type'
            self.log.error(error)
            return S_ERROR(error)
        subClassName = "%sComputingElement" % (ceTypeLocal)

        objectLoader = ObjectLoader.ObjectLoader()
        result = objectLoader.loadObject(
            'Resources.Computing.%s' % subClassName, subClassName)
        if not result['OK']:
            gLogger.error('Failed to load object',
                          '%s: %s' % (subClassName, result['Message']))
            return result

        ceClass = result['Value']
        try:
            computingElement = ceClass(ceNameLocal)
            # Always set the CEType parameter according to instantiated class
            ceDict = {'CEType': ceTypeLocal}
            if ceParametersDict:
                ceDict.update(ceParametersDict)
            computingElement.setParameters(ceDict)
        except BaseException as x:
            msg = 'ComputingElementFactory could not instantiate %s object: %s' % (
                subClassName, str(x))
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)

        return S_OK(computingElement)
Beispiel #5
0
    def getCE(self, ceType="", ceName="", ceParametersDict={}):
        """This method returns the CE instance corresponding to the supplied
        CEUniqueID.  If no corresponding CE is available, this is indicated.
        """
        if ceType:
            self.log.verbose("Creating CE of type %s" % ceType)
        if ceName:
            self.log.verbose("Creating CE for name %s" % ceName)
        ceTypeLocal = ceType if ceType else self.ceType
        ceNameLocal = ceName if ceName else ceType
        ceConfigDict = getCEConfigDict(ceNameLocal)
        self.log.verbose("CEConfigDict", ceConfigDict)
        if "CEType" in ceConfigDict:
            ceTypeLocal = ceConfigDict["CEType"]
        if not ceTypeLocal:
            error = "Can not determine CE Type"
            self.log.error(error)
            return S_ERROR(error)
        subClassName = "%sComputingElement" % (ceTypeLocal)

        result = ObjectLoader().loadObject("Resources.Computing.%s" %
                                           subClassName)
        if not result["OK"]:
            self.log.error("Failed to load object",
                           "%s: %s" % (subClassName, result["Message"]))
            return result

        ceClass = result["Value"]
        try:
            computingElement = ceClass(ceNameLocal)
            # Always set the CEType parameter according to instantiated class
            ceDict = {"CEType": ceTypeLocal}
            if ceParametersDict:
                ceDict.update(ceParametersDict)
            result = computingElement.setParameters(ceDict)
            if not result["OK"]:
                return result

        except Exception as x:
            msg = "ComputingElementFactory could not instantiate %s object" % subClassName
            self.log.exception()
            self.log.warn(msg, repr(x))
            return S_ERROR(repr(x))

        return S_OK(computingElement)
  def getCE(self, ceType='', ceName='', ceParametersDict={}):
    """This method returns the CE instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
    self.log = gLogger.getSubLogger(ceType)
    self.log.verbose('Creating CE of %s type with the name %s' % (ceType, ceName))
    ceTypeLocal = ceType
    if not ceTypeLocal:
      ceTypeLocal = self.ceType
    ceNameLocal = ceName
    if not ceNameLocal:
      ceNameLocal = self.ceType
    ceConfigDict = getCEConfigDict(ceNameLocal)
    self.log.verbose('CEConfigDict', ceConfigDict)
    if 'CEType' in ceConfigDict:
      ceTypeLocal = ceConfigDict['CEType']
    if not ceTypeLocal:
      error = 'Can not determine CE Type'
      self.log.error(error)
      return S_ERROR(error)
    subClassName = "%sComputingElement" % (ceTypeLocal)

    objectLoader = ObjectLoader.ObjectLoader()
    result = objectLoader.loadObject('Resources.Computing.%s' % subClassName, subClassName)
    if not result['OK']:
      gLogger.error('Failed to load object', '%s: %s' % (subClassName, result['Message']))
      return result

    ceClass = result['Value']
    try:
      computingElement = ceClass(ceNameLocal)
      # Always set the CEType parameter according to instantiated class
      ceDict = {'CEType': ceTypeLocal}
      if ceParametersDict:
        ceDict.update(ceParametersDict)
      computingElement.setParameters(ceDict)
    except BaseException as x:
      msg = 'ComputingElementFactory could not instantiate %s object: %s' % (subClassName, str(x))
      self.log.exception()
      self.log.warn(msg)
      return S_ERROR(msg)

    return S_OK(computingElement)