예제 #1
0
    def getIdProvider(self, name, **kwargs):
        """This method returns a IdProvider instance corresponding to the supplied
        name.

        :param str name: the name of the Identity Provider client

        :return: S_OK(IdProvider)/S_ERROR()
        """
        if not name:
            return S_ERROR("Identity Provider client name must be not None.")
        # Get Authorization Server metadata
        try:
            asMetaDict = collectMetadata(kwargs.get("issuer"),
                                         ignoreErrors=True)
        except Exception as e:
            return S_ERROR(str(e))
        self.log.debug("Search configuration for", name)
        clients = getDIRACClients()
        if name in clients:
            # If it is a DIRAC default pre-registred client
            pDict = asMetaDict
            pDict.update(clients[name])
        else:
            # if it is external identity provider client
            result = getProviderInfo(name)
            if not result["OK"]:
                self.log.error("Failed to read configuration",
                               "%s: %s" % (name, result["Message"]))
                return result
            pDict = result["Value"]
            # Set default redirect_uri
            pDict["redirect_uri"] = pDict.get("redirect_uri",
                                              asMetaDict["redirect_uri"])

        pDict.update(kwargs)
        pDict["ProviderName"] = name

        self.log.verbose("Creating IdProvider of %s type with the name %s" %
                         (pDict["ProviderType"], name))
        subClassName = "%sIdProvider" % pDict["ProviderType"]

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

        pClass = result["Value"]
        try:
            provider = pClass(**pDict)
        except Exception as x:
            msg = "IdProviderFactory could not instantiate %s object: %s" % (
                subClassName, str(x))
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)

        return S_OK(provider)
예제 #2
0
    def getCEObject(self, parameters=None):
        """This method returns the CloudEndpoint instance corresponding to the supplied
        CEUniqueID.  If no corresponding CE is available, this is indicated.
        """
        if not parameters:
            parameters = {}
        ceType = parameters.get("CEType", "Cloud")
        self.log.verbose("Creating Endpoint of %s type" % ceType)
        subClassName = "%sEndpoint" % (ceType)

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

        ceClass = result["Value"]
        try:
            endpoint = ceClass(parameters)
        except Exception as x:
            msg = "EndpointFactory could not instantiate %s object: %s" % (
                subClassName, str(x))
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)

        return S_OK(endpoint)
예제 #3
0
  def getIdProvider(self, idProvider):
    """ This method returns a IdProvider instance corresponding to the supplied name.

        :param str idProvider: the name of the Identity Provider

        :return: S_OK(IdProvider)/S_ERROR()
    """
    result = getInfoAboutProviders(of='Id', providerName=idProvider, option="all", section="all")
    if not result['OK']:
      return result
    pDict = result['Value']
    pDict['ProviderName'] = idProvider
    pType = pDict['ProviderType']

    self.log.verbose('Creating IdProvider', 'of %s type with the name %s' % (pType, idProvider))
    subClassName = "%sIdProvider" % (pType)

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

    pClass = result['Value']
    try:
      provider = pClass()
      provider.setParameters(pDict)
    except Exception as x:
      msg = 'IdProviderFactory could not instantiate %s object: %s' % (subClassName, str(x))
      self.log.exception()
      self.log.error(msg)
      return S_ERROR(msg)

    return S_OK(provider)
예제 #4
0
    def getCEObject(self, parameters={}):
        """This method returns the CloudEndpoint instance corresponding to the supplied
       CEUniqueID.  If no corresponding CE is available, this is indicated.
    """
        ceType = parameters.get('CEType', 'Cloud')
        self.log.verbose('Creating Endpoint of %s type' % ceType)
        subClassName = "%sEndpoint" % (ceType)

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

        ceClass = result['Value']
        try:
            endpoint = ceClass(parameters)
        except Exception as x:
            msg = 'EndpointFactory could not instantiate %s object: %s' % (
                subClassName, str(x))
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)

        return S_OK(endpoint)
예제 #5
0
  def __getCatalogClass(self, catalogType):

    objectLoader = ObjectLoader.ObjectLoader()
    result = objectLoader.loadObject('Resources.Catalog.%sClient' % catalogType, catalogType + 'Client')
    if not result['OK']:
      gLogger.error('Failed to load catalog object', '%s' % result['Message'])

    return result
예제 #6
0
 def __init__(self, opsHelper):
     if not opsHelper:
         opsHelper = Operations()
     self.__opsHelper = opsHelper
     self.__log = gLogger.getSubLogger("SharesCorrector")
     self.__shareCorrectors = {}
     self.__correctorsOrder = []
     self.__baseCS = "JobScheduling/ShareCorrections"
     self.__objLoader = ObjectLoader.ObjectLoader()
예제 #7
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.
    """
        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)
예제 #8
0
def getMQConnectorClass(mqType):
    """ Function loads the specialized MQConnector class based on mqType.
      It is assumed that MQConnector has a name in the format mqTypeMQConnector
      e.g. if StompMQConnector.
  Args:
    mqType(str): prefix of specialized class name e.g. Stomp.
  Returns:
    S_OK/S_ERROR: with loaded specialized class of MQConnector.
  """
    subClassName = mqType + 'MQConnector'
    objectLoader = ObjectLoader.ObjectLoader()
    result = objectLoader.loadObject(
        'Resources.MessageQueue.%s' % subClassName, subClassName)
    if not result['OK']:
        gLogger.error('Failed to load object',
                      '%s: %s' % (subClassName, result['Message']))
    return result
예제 #9
0
    def getProxyProvider(self, proxyProvider):
        """ This method returns a ProxyProvider instance corresponding to the supplied
        name.

        :param str proxyProvider: the name of the Proxy Provider

        :return: S_OK(ProxyProvider)/S_ERROR()
    """
        if not proxyProvider:
            return S_ERROR('Provider name not set.')
        result = getInfoAboutProviders(of='Proxy',
                                       providerName=proxyProvider,
                                       option='all',
                                       section='all')
        if not result['OK']:
            return result
        ppDict = result['Value']
        ppDict['ProviderName'] = proxyProvider
        ppType = ppDict.get('ProviderType')
        if not ppType:
            return S_ERROR('Cannot find information for ProxyProvider %s' %
                           proxyProvider)
        self.log.verbose('Creating ProxyProvider of %s type with the name %s' %
                         (ppType, proxyProvider))
        subClassName = "%sProxyProvider" % (ppType)

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

        ppClass = result['Value']
        try:
            pProvider = ppClass()
            pProvider.setParameters(ppDict)
        except BaseException as x:
            msg = 'ProxyProviderFactory could not instantiate %s object: %s' % (
                subClassName, str(x))
            self.log.exception()
            self.log.warn(msg)
            return S_ERROR(msg)

        return S_OK(pProvider)
예제 #10
0
    def createCatalog(self, catalogName, useProxy=False):
        """ Create a file catalog object from its name and CS description
    """
        if useProxy:
            catalog = FileCatalogProxyClient(catalogName)
            return S_OK(catalog)

        # get the CS description first
        catalogPath = getCatalogPath(catalogName)
        catalogType = gConfig.getValue(catalogPath + '/CatalogType',
                                       catalogName)
        catalogURL = gConfig.getValue(catalogPath + '/CatalogURL',
                                      "DataManagement/" + catalogType)

        self.log.debug('Creating %s client' % catalogName)

        objectLoader = ObjectLoader.ObjectLoader()
        result = objectLoader.loadObject(
            'Resources.Catalog.%sClient' % catalogType, catalogType + 'Client')
        if not result['OK']:
            gLogger.error('Failed to load catalog object: %s' %
                          result['Message'])
            return result

        catalogClass = result['Value']

        try:
            # FIXME: is it really needed? This is the factory, can't this be moved out?
            if catalogType in ['LcgFileCatalogCombined', 'LcgFileCatalog']:
                # The LFC special case
                infoSys = gConfig.getValue(catalogPath + '/LcgGfalInfosys', '')
                host = gConfig.getValue(catalogPath + '/MasterHost', '')
                catalog = catalogClass(infoSys, host)
            else:
                if catalogURL:
                    catalog = catalogClass(url=catalogURL)
                else:
                    catalog = catalogClass()
            self.log.debug('Loaded module %sClient' % catalogType)
            return S_OK(catalog)
        except Exception, x:
            errStr = "Failed to instantiate %s()" % (catalogType)
            gLogger.exception(errStr, lException=x)
            return S_ERROR(errStr)