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


Python GOCDBClient.getStatus方法代码示例

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


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

示例1: DTEveryResources_Command

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]
class DTEveryResources_Command( Command ):

  def doCommand( self, resources = None ):
    """ 
    Returns downtimes information for all the resources in input.
        
    :params:
      :attr:`sites`: list of resource names (when not given, take every resource)
    
    :returns:
      {'ResourceName': {'SEVERITY': 'OUTAGE'|'AT_RISK', 
                    'StartDate': 'aDate', ...} ... }
    """

    if self.client is None:
      from DIRAC.Core.LCG.GOCDBClient import GOCDBClient
      self.client = GOCDBClient()

    if resources is None:
#      from DIRAC.Core.DISET.RPCClient import RPCClient
      RPC = RPCClient( "ResourceStatus/ResourceStatus" )
      resources = RPC.getResourcesList()
      if not resources['OK']:
        raise RSSException, where( self, self.doCommand ) + " " + resources['Message']
      else:
        resources = resources['Value']

    try:
      res = self.client.getStatus( 'Resource', resources, None, 120 )
    except:
      gLogger.exception( "Exception when calling GOCDBClient." )
      return {}

    if not res['OK']:
      raise RSSException, where( self, self.doCommand ) + " " + res['Message']
    else:
      res = res['Value']

    if res == None:
      return {}

    resToReturn = {}

    for dt_ID in res:
      dt = {}
      dt['ID'] = dt_ID
      dt['StartDate'] = res[dt_ID]['FORMATED_START_DATE']
      dt['EndDate'] = res[dt_ID]['FORMATED_END_DATE']
      dt['Severity'] = res[dt_ID]['SEVERITY']
      dt['Description'] = res[dt_ID]['DESCRIPTION'].replace( '\'', '' )
      dt['Link'] = res[dt_ID]['GOCDB_PORTAL_URL']
      resToReturn[dt_ID] = dt

    return resToReturn

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
开发者ID:caitriana,项目名称:DIRAC,代码行数:58,代码来源:ClientsCache_Command.py

示例2: DowntimeCommand

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]

#.........这里部分代码省略.........
      if not seHost:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = seHost

    return S_OK( ( element, elementName, hours, gocdbServiceType ) )

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

      For every elementName, unless it is given a list, in which case it contacts
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.

      If there are downtimes, are recorded and then returned.
    '''

    if masterParams is not None:
      element, elementNames = masterParams
      hours = None
      elementName = None
      gocdbServiceType = None
    else:
      params = self._prepareCommand()
      if not params[ 'OK' ]:
        return params
      element, elementName, hours, gocdbServiceType = params[ 'Value' ]
      elementNames = [ elementName ]

    startDate = datetime.utcnow() - timedelta( days = 14 )

    try:
      results = self.gClient.getStatus( element, elementName, startDate, 120 )
    except urllib2.URLError:
      try:
        #Let's give it a second chance..
        results = self.gClient.getStatus( element, elementName, startDate, 120 )
      except urllib2.URLError, e:
        return S_ERROR( e )

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

    if results is None:
      return S_OK( None )

    uniformResult = []

    # Humanize the results into a dictionary, not the most optimal, but readable
    for downtime, downDic in results.items():

      dt = {}
      if gocdbServiceType and downDic[ 'SERVICE_TYPE' ]:
        if  gocdbServiceType.lower() != downDic[ 'SERVICE_TYPE' ].lower():
          continue
      if element == 'Resource':
        dt[ 'Name' ] = downDic[ 'HOSTNAME' ]
      else:
        dt[ 'Name' ] = downDic[ 'SITENAME' ]

      if not dt[ 'Name' ] in elementNames:
        continue

      dt[ 'DowntimeID' ] = downtime
开发者ID:corionma,项目名称:DIRAC,代码行数:70,代码来源:DowntimeCommand.py

示例3: DowntimeCommand

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]

#.........这里部分代码省略.........
    # Transform DIRAC site names into GOCDB topics
    if element == 'Site':

      gocSite = getGOCSiteName( elementName )
      if not gocSite[ 'OK' ]:
        return gocSite
      elementName = gocSite[ 'Value' ]
          
    # The DIRAC se names mean nothing on the grid, but their hosts do mean.
    elif elementType == 'StorageElement':
      
      seHost = CSHelpers.getSEHost( elementName )
      if not seHost:
        return S_ERROR( 'No seHost for %s' % elementName )
      elementName = seHost
             
    return S_OK( ( element, elementName, hours ) )

  def doNew( self, masterParams = None ):
    '''
      Gets the parameters to run, either from the master method or from its
      own arguments.
      
      For every elementName, unless it is given a list, in which case it contacts 
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.
      
      If there are downtimes, are recorded and then returned.
    '''
    
    if masterParams is not None:
      element, elementNames = masterParams
      hours       = None
      elementName = None
    else:
      params = self._prepareCommand()
      if not params[ 'OK' ]:
        return params
      element, elementName, hours = params[ 'Value' ]  
      elementNames = [ elementName ]     

    startDate = datetime.utcnow() - timedelta( days = 2 )
          
    try:
      results = self.gClient.getStatus( element, elementName, startDate, 120 )
    except urllib2.URLError:
      try:
        #Let's give it a second chance..
        results = self.gClient.getStatus( element, elementName, startDate, 120 )
      except urllib2.URLError, e:
        return S_ERROR( e )
                  
    if not results[ 'OK' ]:
      return results
    results = results[ 'Value' ]

    if results is None:
      return S_OK( None )

    uniformResult = []
      
    # Humanize the results into a dictionary, not the most optimal, but readable
    for downtime, downDic in results.items():

      dt                  = {}
      if element == 'Resource':
        dt[ 'Name' ]        = downDic[ 'HOSTNAME' ]
      else:
        dt[ 'Name' ] = downDic[ 'SITENAME' ]
      
      if not dt[ 'Name' ] in elementNames:
        continue
      
      dt[ 'DowntimeID' ]  = downtime
      dt[ 'Element' ]     = element
      dt[ 'StartDate' ]   = downDic[ 'FORMATED_START_DATE' ]
      dt[ 'EndDate' ]     = downDic[ 'FORMATED_END_DATE' ]
      dt[ 'Severity' ]    = downDic[ 'SEVERITY' ]
      dt[ 'Description' ] = downDic[ 'DESCRIPTION' ].replace( '\'', '' )
      dt[ 'Link' ]        = downDic[ 'GOCDB_PORTAL_URL' ]
     
      uniformResult.append( dt )  
      
    storeRes = self._storeCommand( uniformResult )
    if not storeRes[ 'OK' ]:
      return storeRes
    
    # We return only one downtime, if its ongoind at dtDate
    dtDate = datetime.now()     
    if hours:
      dtDate = dtDate + timedelta( hours = hours )

    result = None           
    for dt in uniformResult:
      
      if ( dt[ 'StartDate' ] < str( dtDate ) ) and ( dt[ 'EndDate' ] > str( dtDate ) ):
        result = dt
        break        
           
    return S_OK( result )            
开发者ID:cgrefe,项目名称:DIRAC,代码行数:104,代码来源:DowntimeCommand.py

示例4: DowntimeCommand

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]

#.........这里部分代码省略.........

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

      For every elementName, unless it is given a list, in which case it contacts
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.

      If there are downtimes, are recorded and then returned.
    '''

    if masterParams is not None:
      element, elementNames = masterParams
      #translate DIRAC CS elementNames into GOCDB elementNames
      translatedElementNames = []
      for e in elementNames:
        translatedElementNames.append(CSHelpers.getSEHost( e ))
      elementNames = translatedElementNames
      hours = None
      elementName = None
      gocdbServiceType = None

    else:
      params = self._prepareCommand()
      if not params[ 'OK' ]:
        return params
      element, elementName, hours, gocdbServiceType = params[ 'Value' ]
      elementNames = [ elementName ]

    #WARNING: checking all the DT that are ongoing or starting in given <hours> from now
    startDate = None 
    if hours is not None:
      startDate = datetime.utcnow() + timedelta( hours = hours )

    try:
      results = self.gClient.getStatus( element, elementNames, startDate )
    except urllib2.URLError:
      try:
        #Let's give it a second chance..
        results = self.gClient.getStatus( element, elementNames, startDate )
      except urllib2.URLError, e:
        return S_ERROR( e )

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

    if results is None:
      return S_OK( None )
    
    
    #cleaning the Cache
    cleanRes = self._cleanCommand(element, elementNames)
    if not cleanRes[ 'OK' ]:
      return cleanRes
    

    uniformResult = []

    # Humanize the results into a dictionary, not the most optimal, but readable
    for downtime, downDic in results.items():

      dt = {}
      
      if 'HOSTNAME' in downDic.keys():
        dt[ 'Name' ] = downDic[ 'HOSTNAME' ]
      elif 'SITENAME' in downDic.keys():
        dt[ 'Name' ] = downDic[ 'SITENAME' ]
      else:
        return S_ERROR( "SITENAME or HOSTNAME are missing" )
         
      
      if 'SERVICE_TYPE' in downDic.keys():
        dt[ 'GOCDBServiceType' ] = downDic[ 'SERVICE_TYPE' ]
        if gocdbServiceType:
          gocdbST = gocdbServiceType.lower()
          csST = downDic[ 'SERVICE_TYPE' ].lower()
          if gocdbST != csST:
            return S_ERROR( "SERVICE_TYPE mismatch between GOCDB (%s) and CS (%s) for %s" % (gocdbST, csST, dt[ 'Name' ]) )          
      else:
        #WARNING: do we want None as default value?
        dt[ 'GOCDBServiceType' ] = None

      dt[ 'DowntimeID' ] = downtime
      dt[ 'Element' ] = element
      dt[ 'StartDate' ] = downDic[ 'FORMATED_START_DATE' ]
      dt[ 'EndDate' ] = downDic[ 'FORMATED_END_DATE' ]
      dt[ 'Severity' ] = downDic[ 'SEVERITY' ]
      dt[ 'Description' ] = downDic[ 'DESCRIPTION' ].replace( '\'', '' )
      dt[ 'Link' ] = downDic[ 'GOCDB_PORTAL_URL' ]

      uniformResult.append( dt )

    storeRes = self._storeCommand( uniformResult )
    if not storeRes[ 'OK' ]:
      return storeRes

    return S_OK()
开发者ID:Kiyoshi-Hayasaka,项目名称:DIRAC,代码行数:104,代码来源:DowntimeCommand.py

示例5: DowntimeCommand

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]

#.........这里部分代码省略.........
        self.log.warn("%s not in Resources/FTSEndpoints/FTS3 ?" % elementName)
      else:
        elementName = gocSite['Value']

    return S_OK((element, elementName, hours, gOCDBServiceType))

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

      For every elementName, unless it is given a list, in which case it contacts
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.

      If there are downtimes, are recorded and then returned.
    '''

    if masterParams is not None:
      element, elementNames = masterParams
      hours = 120
      elementName = None
      gOCDBServiceType = None

    else:
      params = self._prepareCommand()
      if not params['OK']:
        return params
      element, elementName, hours, gOCDBServiceType = params['Value']
      elementNames = [elementName]

    # WARNING: checking all the DT that are ongoing or starting in given <hours> from now
    try:
      results = self.gClient.getStatus(element, name=elementNames, startingInHours=hours)
    except urllib2.URLError:
      try:
        # Let's give it a second chance..
        results = self.gClient.getStatus(element, name=elementNames, startingInHours=hours)
      except urllib2.URLError as e:
        return S_ERROR(e)

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

    if results is None:  # no downtimes found
      return S_OK(None)

    # cleaning the Cache
    cleanRes = self._cleanCommand(element, elementNames)
    if not cleanRes['OK']:
      return cleanRes

    uniformResult = []

    # Humanize the results into a dictionary, not the most optimal, but readable
    for downtime, downDic in results.iteritems():

      dt = {}

      dt['Name'] = downDic.get('HOSTNAME', downDic.get('SITENAME'))
      if not dt['Name']:
        return S_ERROR("SITENAME and HOSTNAME are missing from downtime dictionary")

      dt['gOCDBServiceType'] = downDic.get('SERVICE_TYPE')
开发者ID:marianne013,项目名称:DIRAC,代码行数:69,代码来源:DowntimeCommand.py

示例6: DowntimeCommand

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]

#.........这里部分代码省略.........

        elif elementType in ["FTS", "FTS3"]:
            gocdbServiceType = "FTS"
            try:
                # WARNING: this method presupposes that the server is an FTS3 type
                elementName = getGOCFTSName(elementName)
            except:
                return S_ERROR("No FTS3 server specified in dirac.cfg (see Resources/FTSEndpoints)")

        return S_OK((element, elementName, hours, gocdbServiceType))

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

      For every elementName, unless it is given a list, in which case it contacts
      the gocdb client. The server is not very stable, so in case of failure tries
      a second time.

      If there are downtimes, are recorded and then returned.
    """

        if masterParams is not None:
            element, elementNames = masterParams
            hours = 120
            elementName = None
            gocdbServiceType = None

        else:
            params = self._prepareCommand()
            if not params["OK"]:
                return params
            element, elementName, hours, gocdbServiceType = params["Value"]
            elementNames = [elementName]

        # WARNING: checking all the DT that are ongoing or starting in given <hours> from now
        try:
            results = self.gClient.getStatus(element, name=elementNames, startingInHours=hours)
        except urllib2.URLError:
            try:
                # Let's give it a second chance..
                results = self.gClient.getStatus(element, name=elementNames, startingInHours=hours)
            except urllib2.URLError, e:
                return S_ERROR(e)

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

        if results is None:
            return S_OK(None)

        # cleaning the Cache
        cleanRes = self._cleanCommand(element, elementNames)
        if not cleanRes["OK"]:
            return cleanRes

        uniformResult = []

        # Humanize the results into a dictionary, not the most optimal, but readable
        for downtime, downDic in results.items():

            dt = {}

            if "HOSTNAME" in downDic.keys():
                dt["Name"] = downDic["HOSTNAME"]
            elif "SITENAME" in downDic.keys():
                dt["Name"] = downDic["SITENAME"]
            else:
                return S_ERROR("SITENAME or HOSTNAME are missing")

            if "SERVICE_TYPE" in downDic.keys():
                dt["GOCDBServiceType"] = downDic["SERVICE_TYPE"]
                if gocdbServiceType:
                    gocdbST = gocdbServiceType.lower()
                    csST = downDic["SERVICE_TYPE"].lower()
                    if gocdbST != csST:
                        return S_ERROR(
                            "SERVICE_TYPE mismatch between GOCDB (%s) and CS (%s) for %s" % (gocdbST, csST, dt["Name"])
                        )
            else:
                # WARNING: do we want None as default value?
                dt["GOCDBServiceType"] = None

            dt["DowntimeID"] = downtime
            dt["Element"] = element
            dt["StartDate"] = downDic["FORMATED_START_DATE"]
            dt["EndDate"] = downDic["FORMATED_END_DATE"]
            dt["Severity"] = downDic["SEVERITY"]
            dt["Description"] = downDic["DESCRIPTION"].replace("'", "")
            dt["Link"] = downDic["GOCDB_PORTAL_URL"]

            uniformResult.append(dt)

        storeRes = self._storeCommand(uniformResult)
        if not storeRes["OK"]:
            return storeRes

        return S_OK()
开发者ID:DIRACGrid,项目名称:DIRAC,代码行数:104,代码来源:DowntimeCommand.py

示例7: DTEverySites_Command

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]
class DTEverySites_Command(Command):
    def doCommand(self, sites=None):
        """ 
    Returns downtimes information for all the sites in input.
        
    :params:
      :attr:`sites`: list of site names (when not given, take every site)
    
    :returns:
      {'SiteName': {'SEVERITY': 'OUTAGE'|'AT_RISK', 
                    'StartDate': 'aDate', ...} ... }
    """

        if self.client is None:
            from DIRAC.Core.LCG.GOCDBClient import GOCDBClient

            self.client = GOCDBClient()

        if sites is None:
            #      from DIRAC.Core.DISET.RPCClient import RPCClient
            RPC = RPCClient("ResourceStatus/ResourceStatus")
            GOC_sites = RPC.getGridSitesList()
            if not GOC_sites["OK"]:
                raise RSSException, where(self, self.doCommand) + " " + sites["Message"]
            else:
                GOC_sites = GOC_sites["Value"]
        else:
            GOC_sites = [getGOCSiteName(x)["Value"] for x in sites]

        try:
            res = self.client.getStatus("Site", GOC_sites, None, 120)
        except:
            gLogger.exception("Exception when calling GOCDBClient.")
            return {}

        if not res["OK"]:
            raise RSSException, where(self, self.doCommand) + " " + res["Message"]
        else:
            res = res["Value"]

        if res == None:
            return {}

        resToReturn = {}

        for dt_ID in res:
            try:
                dt = {}
                dt["ID"] = dt_ID
                dt["StartDate"] = res[dt_ID]["FORMATED_START_DATE"]
                dt["EndDate"] = res[dt_ID]["FORMATED_END_DATE"]
                dt["Severity"] = res[dt_ID]["SEVERITY"]
                dt["Description"] = res[dt_ID]["DESCRIPTION"].replace("'", "")
                dt["Link"] = res[dt_ID]["GOCDB_PORTAL_URL"]
                DIRACnames = getDIRACSiteName(res[dt_ID]["SITENAME"])
                if not DIRACnames["OK"]:
                    raise RSSException, DIRACnames["Message"]
                DIRACnames = DIRACnames["Value"]
                for DIRACname in DIRACnames:
                    resToReturn[dt_ID.split()[0] + " " + DIRACname] = dt
            except KeyError:
                continue

        return resToReturn

    doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
开发者ID:roiser,项目名称:DIRAC,代码行数:68,代码来源:ClientsCache_Command.py

示例8: GOCDBStatus_Command

# 需要导入模块: from DIRAC.Core.LCG.GOCDBClient import GOCDBClient [as 别名]
# 或者: from DIRAC.Core.LCG.GOCDBClient.GOCDBClient import getStatus [as 别名]
class GOCDBStatus_Command(Command):
  
  def doCommand(self):
    """ 
    Return getStatus from GOC DB Client
    
    :attr:`args`: 
     - args[0]: string: should be a ValidRes

     - args[1]: string: should be the name of the ValidRes

     - args[2]: string: optional, number of hours in which 
     the down time is starting
    """
    super(GOCDBStatus_Command, self).doCommand()

    if self.client is None:
      # use standard GOC DB Client
      from DIRAC.Core.LCG.GOCDBClient import GOCDBClient   
      self.client = GOCDBClient()
    
    granularity = self.args[0]
    name = self.args[1]  
    try:  
      hours = self.args[2]
    except IndexError:
      hours = None

    if granularity in ('Site', 'Sites'):
      name = getGOCSiteName(name)
      if not name['OK']:
        raise RSSException, name['Message']
      name = name['Value']

    try:
      res = self.client.getStatus(granularity, name, None, hours, self.timeout)
      if not res['OK']:
        return {'Result':'Unknown'}
      res = res['Value']
      if res is None or res == {}:
        return {'Result':{'DT':None}}
      
      DT_dict_result = {}
      
      now = datetime.datetime.utcnow().replace(microsecond = 0, second = 0)
      
      if len(res) > 1:
        #there's more than one DT
        for dt_ID in res:
          #looking for an ongoing one
          startSTR = res[dt_ID]['FORMATED_START_DATE']
          start_datetime = datetime.datetime( *time.strptime(startSTR, "%Y-%m-%d %H:%M")[0:5] )
          if start_datetime < now:
            resDT = res[dt_ID]
            break
        try:
          resDT
        except:
          #if I'm here, there's no OnGoing DT
          resDT = res[res.keys()[0]]
        res = resDT
      else:
        res = res[res.keys()[0]]

      DT_dict_result['DT'] = res['SEVERITY']
      DT_dict_result['EndDate'] = res['FORMATED_END_DATE']
      startSTR = res['FORMATED_START_DATE']
      start_datetime = datetime.datetime( *time.strptime(startSTR, "%Y-%m-%d %H:%M")[0:5] )
      if start_datetime > now:
        diff = convertTime(start_datetime - now, 'hours')
        DT_dict_result['DT'] = DT_dict_result['DT'] + " in " + str(diff) + ' hours'
          
      return {'Result':DT_dict_result}
        
    except urllib2.URLError:
      gLogger.error("GOCDB timed out for " + granularity + " " + name )
      return  {'Result':'Unknown'}      
    except:
      gLogger.exception("Exception when calling GOCDBClient for " + granularity + " " + name )
      return {'Result':'Unknown'}

  doCommand.__doc__ = Command.doCommand.__doc__ + doCommand.__doc__
开发者ID:caitriana,项目名称:DIRAC,代码行数:84,代码来源:GOCDBStatus_Command.py


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