当前位置: 首页>>代码示例>>Python>>正文


Python ResourceManagementClient.addOrModifyGGUSTicketsCache方法代码示例

本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient.addOrModifyGGUSTicketsCache方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceManagementClient.addOrModifyGGUSTicketsCache方法的具体用法?Python ResourceManagementClient.addOrModifyGGUSTicketsCache怎么用?Python ResourceManagementClient.addOrModifyGGUSTicketsCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient的用法示例。


在下文中一共展示了ResourceManagementClient.addOrModifyGGUSTicketsCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GGUSTicketsCommand

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import addOrModifyGGUSTicketsCache [as 别名]
class GGUSTicketsCommand(Command):
    """
    GGUSTickets "master" Command
  """

    def __init__(self, args=None, clients=None):

        super(GGUSTicketsCommand, self).__init__(args, clients)

        if "GGUSTicketsClient" in self.apis:
            self.gClient = self.apis["GGUSTicketsClient"]
        else:
            self.gClient = GGUSTicketsClient()

        if "ResourceManagementClient" in self.apis:
            self.rmClient = self.apis["ResourceManagementClient"]
        else:
            self.rmClient = ResourceManagementClient()

    def _storeCommand(self, result):
        """
      Stores the results of doNew method on the database.
    """

        for ggus in result:
            resQuery = self.rmClient.addOrModifyGGUSTicketsCache(
                ggus["GocSite"], ggus["Link"], ggus["OpenTickets"], ggus["Tickets"]
            )
            if not resQuery["OK"]:
                return resQuery
        return S_OK()

    def _prepareCommand(self):
        """
      GGUSTicketsCommand requires one arguments:
      - elementName : <str>
      
      GGUSTickets are associated with gocDB names, so we have to transform the
      diracSiteName into a gocSiteName.
    """

        if not "name" in self.args:
            return S_ERROR('"name" not found in self.args')
        name = self.args["name"]

        return getGOCSiteName(name)

    def doNew(self, masterParams=None):
        """
      Gets the parameters to run, either from the master method or from its
      own arguments.
      
      For every elementName ( cannot process bulk queries.. ) contacts the 
      ggus client. The server is not very stable, so we protect against crashes.
      
      If there are ggus tickets, are recorded and then returned.    
    """

        if masterParams is not None:
            gocName = masterParams
            gocNames = [gocName]

        else:
            gocName = self._prepareCommand()
            if not gocName["OK"]:
                return gocName
            gocName = gocName["Value"]
            gocNames = [gocName]

        try:
            results = self.gClient.getTicketsList(gocName)
        except urllib2.URLError, e:
            return S_ERROR("%s %s" % (gocName, e))

        if not results["OK"]:
            return results
        results = results["Value"]

        uniformResult = []

        for gocSite, ggusResult in results.items():

            if not gocSite in gocNames:
                continue

            ggusDict = {}
            ggusDict["GocSite"] = gocSite
            ggusDict["Link"] = ggusResult["URL"]

            del ggusResult["URL"]

            openTickets = 0
            for priorityDict in ggusResult.values():
                openTickets += len(priorityDict)

            ggusDict["Tickets"] = ggusResult
            ggusDict["OpenTickets"] = openTickets

            uniformResult.append(ggusDict)

#.........这里部分代码省略.........
开发者ID:graciani,项目名称:DIRAC,代码行数:103,代码来源:GGUSTicketsCommand.py

示例2: GGUSTicketsCommand

# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import addOrModifyGGUSTicketsCache [as 别名]
class GGUSTicketsCommand(Command):
  '''
    GGUSTickets "master" Command
  '''

  def __init__(self, args=None, clients=None):

    super(GGUSTicketsCommand, self).__init__(args, clients)

    if 'GGUSTicketsClient' in self.apis:
      self.gClient = self.apis['GGUSTicketsClient']
    else:
      self.gClient = GGUSTicketsClient()

    if 'ResourceManagementClient' in self.apis:
      self.rmClient = self.apis['ResourceManagementClient']
    else:
      self.rmClient = ResourceManagementClient()

  def _storeCommand(self, result):
    '''
      Stores the results of doNew method on the database.
    '''

    for ggus in result:
      resQuery = self.rmClient.addOrModifyGGUSTicketsCache(ggus['GocSite'],
                                                           ggus['Link'],
                                                           ggus['OpenTickets'],
                                                           ggus['Tickets'])
      if not resQuery['OK']:
        return resQuery
    return S_OK()

  def _prepareCommand(self):
    '''
      GGUSTicketsCommand requires one arguments:
      - elementName : <str>

      GGUSTickets are associated with gocDB names, so we have to transform the
      diracSiteName into a gocSiteName.
    '''

    if 'name' not in self.args:
      return S_ERROR('"name" not found in self.args')
    name = self.args['name']

    return getGOCSiteName(name)

  def doNew(self, masterParams=None):
    '''
      Gets the parameters to run, either from the master method or from its
      own arguments.

      For every elementName ( cannot process bulk queries.. ) contacts the
      ggus client. The server is not very stable, so we protect against crashes.

      If there are ggus tickets, are recorded and then returned.
    '''

    if masterParams is not None:
      gocName = masterParams
      gocNames = [gocName]

    else:
      gocName = self._prepareCommand()
      if not gocName['OK']:
        return gocName
      gocName = gocName['Value']
      gocNames = [gocName]

    try:
      results = self.gClient.getTicketsList(gocName)
    except urllib2.URLError as e:
      return S_ERROR('%s %s' % (gocName, e))

    if not results['OK']:
      return results
    results = results['Value']

    uniformResult = []

    for gocSite, ggusResult in results.items():

      if gocSite not in gocNames:
        continue

      ggusDict = {}
      ggusDict['GocSite'] = gocSite
      ggusDict['Link'] = ggusResult['URL']

      del ggusResult['URL']

      openTickets = 0
      for priorityDict in ggusResult.values():
        openTickets += len(priorityDict)

      ggusDict['Tickets'] = ggusResult
      ggusDict['OpenTickets'] = openTickets

      uniformResult.append(ggusDict)
#.........这里部分代码省略.........
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:103,代码来源:GGUSTicketsCommand.py


注:本文中的DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient.addOrModifyGGUSTicketsCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。