示例#1
0
def parseSwitches():
    '''
    Parses the arguments passed by the user
  '''

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if args:
        subLogger.error(
            "Found the following positional args '%s', but we only accept switches"
            % args)
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    switches = dict(Script.getUnprocessedSwitches())
    switches.setdefault('statusType', None)

    for key in ('element', 'name', 'status', 'reason'):

        if not key in switches:
            subLogger.error("%s Switch missing" % key)
            subLogger.error("Please, check documentation below")
            Script.showHelp()
            DIRACExit(1)

    if not switches['element'] in ('Site', 'Resource', 'Node'):
        subLogger.error("Found %s as element switch" % switches['element'])
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    statuses = StateMachine.RSSMachine(None).getStates()

    if not switches['status'] in statuses:
        subLogger.error("Found %s as element switch" % switches['element'])
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    subLogger.debug("The switches used are:")
    map(subLogger.debug, switches.iteritems())

    return switches
示例#2
0
def parseSwitches():
    """
    Parses the arguments passed by the user
    """

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if args:
        subLogger.error(
            "Found the following positional args '%s', but we only accept switches"
            % args)
        subLogger.error("Please, check documentation below")
        Script.showHelp(exitCode=1)

    switches = dict(Script.getUnprocessedSwitches())
    switches.setdefault("statusType", None)
    switches.setdefault("VO", None)

    for key in ("element", "name", "status", "reason"):

        if key not in switches:
            subLogger.error("%s Switch missing" % key)
            subLogger.error("Please, check documentation below")
            Script.showHelp(exitCode=1)

    if not switches["element"] in ("Site", "Resource", "Node"):
        subLogger.error("Found %s as element switch" % switches["element"])
        subLogger.error("Please, check documentation below")
        Script.showHelp(exitCode=1)

    statuses = StateMachine.RSSMachine(None).getStates()

    if not switches["status"] in statuses:
        subLogger.error("Found %s as element switch" % switches["element"])
        subLogger.error("Please, check documentation below")
        Script.showHelp(exitCode=1)

    subLogger.debug("The switches used are:")
    map(subLogger.debug, switches.items())

    return switches
示例#3
0
def initSEs():
    """
    Initializes SEs statuses taking their values from the CS.
    """
    from DIRAC import gConfig
    from DIRAC.DataManagementSystem.Utilities.DMSHelpers import DMSHelpers
    from DIRAC.ResourceStatusSystem.Utilities import CSHelpers, RssConfiguration
    from DIRAC.ResourceStatusSystem.PolicySystem import StateMachine
    from DIRAC.ResourceStatusSystem.Client import ResourceStatusClient

    # WarmUp local copy
    CSHelpers.warmUp()

    subLogger.info("Initializing SEs")

    rssClient = ResourceStatusClient.ResourceStatusClient()

    statuses = StateMachine.RSSMachine(None).getStates()
    statusTypes = RssConfiguration.RssConfiguration().getConfigStatusType(
        "StorageElement")
    reason = "dirac-rss-sync"

    subLogger.debug(statuses)
    subLogger.debug(statusTypes)

    for se in DMSHelpers().getStorageElements():

        subLogger.debug(se)

        opts = gConfig.getOptionsDict("/Resources/StorageElements/%s" % se)
        if not opts["OK"]:
            subLogger.warn(opts["Message"])
            continue
        opts = opts["Value"]

        subLogger.debug(opts)

        # We copy the list into a new object to remove items INSIDE the loop !
        statusTypesList = statusTypes[:]

        for statusType, status in opts.items():

            # Sanity check...
            if statusType not in statusTypesList:
                continue

            # Transforms statuses to RSS terms
            if status in ("NotAllowed", "InActive"):
                status = "Banned"

            if status not in statuses:
                subLogger.error("%s not a valid status for %s - %s" %
                                (status, se, statusType))
                continue

            # We remove from the backtracking
            statusTypesList.remove(statusType)

            subLogger.debug([se, statusType, status, reason])
            result = rssClient.addOrModifyStatusElement(
                "Resource",
                "Status",
                name=se,
                statusType=statusType,
                status=status,
                elementType="StorageElement",
                tokenOwner="rs_svc",
                reason=reason,
            )

            if not result["OK"]:
                subLogger.error("Failed to modify")
                subLogger.error(result["Message"])
                continue

        # Backtracking: statusTypes not present on CS
        for statusType in statusTypesList:

            result = rssClient.addOrModifyStatusElement(
                "Resource",
                "Status",
                name=se,
                statusType=statusType,
                status=DEFAULT_STATUS,
                elementType="StorageElement",
                tokenOwner="rs_svc",
                reason=reason,
            )
            if not result["OK"]:
                subLogger.error("Error in backtracking for %s,%s,%s" %
                                (se, statusType, status))
                subLogger.error(result["Message"])

    return S_OK()
示例#4
0
def initSEs():
    '''
    Initializes SEs statuses taking their values from the CS.
  '''

    # WarmUp local copy
    CSHelpers.warmUp()

    subLogger.info('Initializing SEs')

    rssClient = ResourceStatusClient.ResourceStatusClient()

    statuses = StateMachine.RSSMachine(None).getStates()
    statusTypes = RssConfiguration.RssConfiguration().getConfigStatusType(
        'StorageElement')
    reason = 'dirac-rss-sync'

    subLogger.debug(statuses)
    subLogger.debug(statusTypes)

    for se in DMSHelpers().getStorageElements():

        subLogger.debug(se)

        opts = gConfig.getOptionsDict('/Resources/StorageElements/%s' % se)
        if not opts['OK']:
            subLogger.warn(opts['Message'])
            continue
        opts = opts['Value']

        subLogger.debug(opts)

        # We copy the list into a new object to remove items INSIDE the loop !
        statusTypesList = statusTypes[:]

        for statusType, status in opts.iteritems():

            # Sanity check...
            if statusType not in statusTypesList:
                continue

            # Transforms statuses to RSS terms
            if status in ('NotAllowed', 'InActive'):
                status = 'Banned'

            if status not in statuses:
                subLogger.error('%s not a valid status for %s - %s' %
                                (status, se, statusType))
                continue

            # We remove from the backtracking
            statusTypesList.remove(statusType)

            subLogger.debug([se, statusType, status, reason])
            result = rssClient.addOrModifyStatusElement(
                'Resource',
                'Status',
                name=se,
                statusType=statusType,
                status=status,
                elementType='StorageElement',
                tokenOwner='rs_svc',
                reason=reason)

            if not result['OK']:
                subLogger.error('Failed to modify')
                subLogger.error(result['Message'])
                continue

        # Backtracking: statusTypes not present on CS
        for statusType in statusTypesList:

            result = rssClient.addOrModifyStatusElement(
                'Resource',
                'Status',
                name=se,
                statusType=statusType,
                status=DEFAULT_STATUS,
                elementType='StorageElement',
                tokenOwner='rs_svc',
                reason=reason)
            if not result['OK']:
                subLogger.error('Error in backtracking for %s,%s,%s' %
                                (se, statusType, status))
                subLogger.error(result['Message'])

    return S_OK()