Ejemplo n.º 1
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["LFN:      Logical File Name or file containing LFNs"])
    Script.parseCommandLine(ignoreErrors=True)
    lfns = Script.getPositionalArgs()

    if len(lfns) < 1:
        Script.showHelp()

    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac()
    exitCode = 0

    if len(lfns) == 1:
        try:
            with open(lfns[0], "r") as f:
                lfns = f.read().splitlines()
        except Exception:
            pass

    result = dirac.getFile(lfns, printOutput=True)
    if not result["OK"]:
        print("ERROR %s" % (result["Message"]))
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 2
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC ID of the Job"])
    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    for job in args:

        try:
            job = int(job)
        except Exception as x:
            errorList.append((job, "Expected integer for jobID"))
            exitCode = 2
            continue

        result = diracAdmin.getJobPilots(job)
        if not result["OK"]:
            errorList.append((job, result["Message"]))
            exitCode = 2

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Ejemplo n.º 3
0
def main():
    Script.registerSwitch(
        "v:",
        "vo=",
        "Location of pilot version in CS /Operations/<vo>/Pilot/Version"
        " (default value specified in CS under /DIRAC/DefaultSetup)",
    )
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("version: pilot version you want to update to")
    Script.parseCommandLine(ignoreErrors=False)

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    version = Script.getPositionalArgs(group=True)

    vo = None
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "v" or switch[0] == "vo":
            vo = switch[1]

    from DIRAC import S_OK, S_ERROR
    from DIRAC import gConfig, gLogger
    from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI

    def updatePilot(version, vo):
        """
        Update in the CS the pilot version used,
        If only one version present in CS it's overwritten.
        If two versions present, the new one is added and the last removed

        :param version: version vArBpC of pilot you want to use
        :param vo: Location of pilot version in CS /Operations/<vo>/Pilot/Version
        """
        setup = vo
        if not vo:
            setup = gConfig.getValue("/DIRAC/DefaultSetup")
        if not setup:
            return S_ERROR("No value set for /DIRAC/DefaultSetup in CS")

        pilotVersion = gConfig.getValue("Operations/%s/Pilot/Version" % setup, [])
        if not pilotVersion:
            return S_ERROR("No pilot version set under Operations/%s/Pilot/Version in CS" % setup)

        pilotVersion.pop()
        pilotVersion.insert(0, version)
        api = CSAPI()
        api.setOption("Operations/%s/Pilot/Version" % setup, ", ".join(pilotVersion))
        result = api.commit()
        if not result["OK"]:
            gLogger.fatal("Could not commit new version of pilot!")
            return result

        newVersion = gConfig.getValue("Operations/%s/Pilot/Version" % setup)
        return S_OK("New version of pilot set to %s" % newVersion)

    result = updatePilot(version, vo)
    if not result["OK"]:
        gLogger.fatal(result["Message"])
        DIRAC.exit(1)
    gLogger.notice(result["Value"])
    DIRAC.exit(0)
Ejemplo n.º 4
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "PFN:      Physical File Name or file containing PFNs")
    Script.registerArgument("SE:       Valid DIRAC SE")
    _, args = Script.parseCommandLine(ignoreErrors=True)

    if len(args) > 2:
        print("Only one PFN SE pair will be considered")

    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac()
    exitCode = 0

    pfn = args[0]
    seName = args[1]
    try:
        with open(pfn, "r") as f:
            pfns = f.read().splitlines()
    except Exception:
        pfns = [pfn]

    for pfn in pfns:
        result = dirac.getPhysicalFileAccessURL(pfn, seName, printOutput=True)
        if not result["OK"]:
            print("ERROR: ", result["Message"])
            exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 5
0
def main():
    Script.registerSwitch("D:", "Dir=", "Store the output in this directory")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0
    errorList = []

    outputDir = ""
    for sw, v in sws:
        if sw in ("D", "Dir"):
            outputDir = v

    for job in parseArguments(args):

        result = dirac.getJobOutputData(job, destinationDir=outputDir)
        if result["OK"]:
            print("Job %s output data retrieved" % (job))
        else:
            errorList.append((job, result["Message"]))
            exitCode = 2

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
Ejemplo n.º 6
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["User: list of SEs or comma-separated SEs"], mandatory=False)

    _, users = Script.parseCommandLine()

    from DIRAC import gLogger, gConfig

    if not users:
        res = gConfig.getSections("/Registry/Users")
        if not res["OK"]:
            gLogger.error("Failed to retrieve user list from CS", res["Message"])
            DIRAC.exit(2)
        users = res["Value"]

    gLogger.notice("-" * 30)
    gLogger.notice("%s|%s" % ("Username".ljust(15), "Quota (GB)".rjust(15)))
    gLogger.notice("-" * 30)
    for user in sorted(users):
        quota = gConfig.getValue("/Registry/Users/%s/Quota" % user, 0)
        if not quota:
            quota = gConfig.getValue("/Registry/DefaultStorageQuota")
        gLogger.notice("%s|%s" % (user.ljust(15), str(quota).rjust(15)))
    gLogger.notice("-" * 30)
    DIRAC.exit(0)
Ejemplo n.º 7
0
def main():
    original = False
    Script.registerSwitch("O", "Original", "Gets the original JDL")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    for switch in sws:
        if switch[0] == "Original" or switch[0] == "O":
            original = True

    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0
    errorList = []

    for job in parseArguments(args):

        result = dirac.getJobJDL(job, original=original, printOutput=True)
        if not result["OK"]:
            errorList.append((job, result["Message"]))
            exitCode = 2

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
Ejemplo n.º 8
0
def main():
    Script.registerArgument(["Agent: specify which agent to run"])
    positionalArgs = Script.getPositionalArgs(group=True)
    localCfg = Script.localCfg

    agentName = positionalArgs[0]
    localCfg.setConfigurationForAgent(agentName)
    localCfg.addMandatoryEntry("/DIRAC/Setup")
    localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "yes")
    localCfg.addDefaultEntry("LogLevel", "INFO")
    localCfg.addDefaultEntry("LogColor", True)
    resultDict = localCfg.loadUserData()
    if not resultDict["OK"]:
        gLogger.error("There were errors when loading configuration",
                      resultDict["Message"])
        sys.exit(1)

    includeExtensionErrors()

    agentReactor = AgentReactor(positionalArgs[0])
    result = agentReactor.loadAgentModules(positionalArgs)
    if result["OK"]:
        agentReactor.go()
        # dirac_agent might interact with ARC library which cannot be closed using a simple sys.exit(0)
        # See https://bugzilla.nordugrid.org/show_bug.cgi?id=4022 for further details
        os._exit(0)
    else:
        gLogger.error("Error while loading agent module", result["Message"])
        sys.exit(2)
Ejemplo n.º 9
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job IDs"])
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    for job in args:

        try:
            job = int(job)
        except Exception as x:
            errorList.append(("Expected integer for jobID", job))
            exitCode = 2
            continue

        result = diracAdmin.resetJob(job)
        if result["OK"]:
            print("Reset Job %s" % (job))
        else:
            errorList.append((job, result["Message"]))
            exitCode = 2

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["PilotID:  Grid ID of the pilot"])
    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    for gridID in args:

        result = diracAdmin.getPilotLoggingInfo(gridID)
        if not result["OK"]:
            errorList.append((gridID, result["Message"]))
            exitCode = 2
        else:
            print("Pilot Reference: %s", gridID)
            print(result["Value"])
            print()

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Ejemplo n.º 11
0
def main():
    Script.registerSwitch("a", "All", "  Also show inactive replicas")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        ["LFN:      Logical File Name or file containing LFNs"])
    switches, lfns = Script.parseCommandLine(ignoreErrors=True)

    active = True
    for switch in switches:
        opt = switch[0].lower()
        if opt in ("a", "all"):
            active = False

    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac()
    exitCode = 0

    if len(lfns) == 1:
        try:
            with open(lfns[0], "r") as f:
                lfns = f.read().splitlines()
        except Exception:
            pass

    result = dirac.getReplicas(lfns, active=active, printOutput=True)
    if not result["OK"]:
        print("ERROR: ", result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
def main():
    Script.registerSwitch(
        "", "Site=", "Site for which protocols are to be set (mandatory)")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["Protocol: SE access protocol"], mandatory=False)
    switches, args = Script.parseCommandLine(ignoreErrors=True)

    site = None
    for switch in switches:
        if switch[0].lower() == "site":
            site = switch[1]

    if not site or not args:
        Script.showHelp(exitCode=1)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    result = diracAdmin.setSiteProtocols(site, args, printOutput=True)
    if not result["OK"]:
        print("ERROR: %s" % result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 13
0
def main():
    global groupName
    global groupProperties
    global userNames
    Script.registerSwitch("G:", "GroupName:", "Name of the Group (Mandatory)", setGroupName)
    Script.registerSwitch(
        "U:", "UserName:"******"Short Name of user to be added to the Group (Allow Multiple instances or None)", addUserName
    )
    Script.registerSwitch(
        "P:", "Property:", "Property to be added to the Group (Allow Multiple instances or None)", addProperty
    )
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        ["Property=<Value>: Other properties to be added to the Group like (VOMSRole=XXXX)"], mandatory=False
    )

    _, args = Script.parseCommandLine(ignoreErrors=True)

    if groupName is None:
        Script.showHelp(exitCode=1)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    groupProps = {}
    if userNames:
        groupProps["Users"] = ", ".join(userNames)
    if groupProperties:
        groupProps["Properties"] = ", ".join(groupProperties)

    for prop in args:
        pl = prop.split("=")
        if len(pl) < 2:
            errorList.append(("in arguments", "Property %s has to include a '=' to separate name from value" % prop))
            exitCode = 255
        else:
            pName = pl[0]
            pValue = "=".join(pl[1:])
            gLogger.info("Setting property %s to %s" % (pName, pValue))
            groupProps[pName] = pValue

    if not diracAdmin.csModifyGroup(groupName, groupProps, createIfNonExistant=True)["OK"]:
        errorList.append(("add group", "Cannot register group %s" % groupName))
        exitCode = 255
    else:
        result = diracAdmin.csCommitChanges()
        if not result["OK"]:
            errorList.append(("commit", result["Message"]))
            exitCode = 255

    for error in errorList:
        gLogger.error("%s: %s" % error)

    DIRAC.exit(exitCode)
Ejemplo n.º 14
0
def main():
    unit = "GB"
    Script.registerSwitch("u:", "Unit=",
                          "   Unit to use [default %s] (MB,GB,TB,PB)" % unit)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs",
                             "LFN:       Logical File Name"))
    Script.registerArgument(["LFN:       Logical File Name"], mandatory=False)
    unprSwitches, args = Script.parseCommandLine(ignoreErrors=False)

    for switch in unprSwitches:
        if switch[0].lower() == "u" or switch[0].lower() == "unit":
            unit = switch[1]
    scaleDict = {
        "MB": 1000 * 1000.0,
        "GB": 1000 * 1000 * 1000.0,
        "TB": 1000 * 1000 * 1000 * 1000.0,
        "PB": 1000 * 1000 * 1000 * 1000 * 1000.0,
    }
    if unit not in scaleDict.keys():
        gLogger.error("Unit must be one of MB,GB,TB,PB")
        DIRAC.exit(2)
    scaleFactor = scaleDict[unit]

    lfns = []
    for inputFileName in args:
        if os.path.exists(inputFileName):
            inputFile = open(inputFileName, "r")
            string = inputFile.read()
            inputFile.close()
            lfns.extend([lfn.strip() for lfn in string.splitlines()])
        else:
            lfns.append(inputFileName)

    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    res = FileCatalog().getFileSize(lfns)
    if not res["OK"]:
        gLogger.error("Failed to get size of data", res["Message"])
        DIRAC.exit(-2)
    for lfn, reason in res["Value"]["Failed"].items():
        gLogger.error("Failed to get size for %s" % lfn, reason)
    totalSize = 0
    totalFiles = 0
    for lfn, size in res["Value"]["Successful"].items():
        totalFiles += 1
        totalSize += size
    gLogger.notice("-" * 30)
    gLogger.notice("%s|%s" % ("Files".ljust(15),
                              ("Size (%s)" % unit).rjust(15)))
    gLogger.notice("-" * 30)
    gLogger.notice(
        "%s|%s" %
        (str(totalFiles).ljust(15), str("%.1f" %
                                        (totalSize / scaleFactor)).rjust(15)))
    gLogger.notice("-" * 30)
    DIRAC.exit(0)
Ejemplo n.º 15
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "Request:  ID of the Stage request in the StorageManager")
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()

    if not len(args) == 1:
        Script.showHelp()

    from DIRAC import exit as DIRACExit, gLogger

    try:
        taskID = int(args[0])
    except Exception:
        gLogger.fatal("Stage requestID must be an integer")
        DIRACExit(2)

    from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient

    client = StorageManagerClient()

    res = client.getTaskSummary(taskID)
    if not res["OK"]:
        gLogger.error(res["Message"])
        DIRACExit(2)
    taskInfo = res["Value"]["TaskInfo"]
    replicaInfo = res["Value"]["ReplicaInfo"]
    outStr = "%s: %s" % ("TaskID".ljust(20), taskID)
    outStr += "\n%s: %s" % ("Status".ljust(20), taskInfo[taskID]["Status"])
    outStr += "\n%s: %s" % ("Source".ljust(20), taskInfo[taskID]["Source"])
    outStr += "\n%s: %s" % ("SourceTaskID".ljust(20),
                            taskInfo[taskID]["SourceTaskID"])
    outStr += "\n%s: %s" % ("CallBackMethod".ljust(20),
                            taskInfo[taskID]["CallBackMethod"])
    outStr += "\n%s: %s" % ("SubmitTime".ljust(20),
                            taskInfo[taskID]["SubmitTime"])
    outStr += "\n%s: %s" % ("CompleteTime".ljust(20),
                            taskInfo[taskID]["CompleteTime"])
    for lfn, metadata in replicaInfo.items():
        outStr += "\n"
        outStr += "\n\t%s: %s" % ("LFN".ljust(8), lfn.ljust(100))
        outStr += "\n\t%s: %s" % ("SE".ljust(8),
                                  metadata["StorageElement"].ljust(100))
        outStr += "\n\t%s: %s" % ("PFN".ljust(8), str(
            metadata["PFN"]).ljust(100))
        outStr += "\n\t%s: %s" % ("Size".ljust(8), str(
            metadata["FileSize"]).ljust(100))
        outStr += "\n\t%s: %s" % ("Status".ljust(8),
                                  metadata["Status"].ljust(100))
        outStr += "\n\t%s: %s" % ("Reason".ljust(8), str(
            metadata["Reason"]).ljust(100))
    gLogger.notice(outStr)
Ejemplo n.º 16
0
def main():
    Script.registerSwitch("f:", "File=", "Writes job ids to file <value>")
    Script.registerSwitch("r:", "UseJobRepo=", "Use the job repository")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JDL:    Path to JDL file"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.Dirac import Dirac

    unprocessed_switches = sws
    use_repo = False
    repo_name = ""
    for sw, value in unprocessed_switches:
        if sw.lower() in ["r", "usejobrepo"]:
            use_repo = True
            repo_name = value
            repo_name = repo_name.replace(".cfg", ".repo")
    dirac = Dirac(use_repo, repo_name)
    exitCode = 0
    errorList = []

    jFile = None
    for sw, value in unprocessed_switches:
        if sw.lower() in ("f", "file"):
            if os.path.isfile(value):
                print("Appending job ids to existing logfile: %s" % value)
                if not os.access(value, os.W_OK):
                    print("Existing logfile %s must be writable by user." %
                          value)
            jFile = open(value, "a")

    for jdl in args:

        result = dirac.submitJob(jdl)
        if result["OK"]:
            print("JobID = %s" % (result["Value"]))
            if jFile is not None:
                # parametric jobs
                if isinstance(result["Value"], list):
                    jFile.write("\n".join(str(p) for p in result["Value"]))
                    jFile.write("\n")
                else:
                    jFile.write(str(result["Value"]) + "\n")
        else:
            errorList.append((jdl, result["Message"]))
            exitCode = 2

    if jFile is not None:
        jFile.close()

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
Ejemplo n.º 17
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs",
                             "LFN:       Logical File Names"))
    Script.parseCommandLine()

    from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations

    allowUsers = Operations().getValue(
        "DataManagement/AllowUserReplicaManagement", False)

    from DIRAC.Core.Security.ProxyInfo import getProxyInfo

    res = getProxyInfo()
    if not res["OK"]:
        gLogger.fatal("Can't get proxy info", res["Message"])
        dexit(1)
    properties = res["Value"].get("groupProperties", [])

    if not allowUsers:
        if "FileCatalogManagement" not in properties:
            gLogger.error(
                "You need to use a proxy from a group with FileCatalogManagement"
            )
            dexit(5)

    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    fc = FileCatalog()
    import os

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    args = Script.getPositionalArgs()

    inputFileName = args[0]

    if os.path.exists(inputFileName):
        inputFile = open(inputFileName, "r")
        string = inputFile.read()
        lfns = [lfn.strip() for lfn in string.splitlines()]
        inputFile.close()
    else:
        lfns = [inputFileName]

    res = fc.removeFile(lfns)
    if not res["OK"]:
        print("Error:", res["Message"])
        dexit(1)
    for lfn in sorted(res["Value"]["Failed"].keys()):
        message = res["Value"]["Failed"][lfn]
        print("Error: failed to remove %s: %s" % (lfn, message))
    print("Successfully removed %d catalog files." %
          (len(res["Value"]["Successful"])))
Ejemplo n.º 18
0
def main():
    Script.registerSwitch("e", "extended", "Show extended info")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["Group:    Only users from this group (default: all)"], default=["all"], mandatory=False)
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs(group=True)

    import DIRAC
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []
    extendedInfo = False

    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("e", "extended"):
            extendedInfo = True

    def printUsersInGroup(group=False):
        result = diracAdmin.csListUsers(group)
        if result["OK"]:
            if group:
                print("Users in group %s:" % group)
            else:
                print("All users registered:")
            for username in result["Value"]:
                print(" %s" % username)

    def describeUsersInGroup(group=False):
        result = diracAdmin.csListUsers(group)
        if result["OK"]:
            if group:
                print("Users in group %s:" % group)
            else:
                print("All users registered:")
            result = diracAdmin.csDescribeUsers(result["Value"])
            print(diracAdmin.pPrint.pformat(result["Value"]))

    for group in args:
        if "all" in args:
            group = False
        if not extendedInfo:
            printUsersInGroup(group)
        else:
            describeUsersInGroup(group)

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRAC.exit(exitCode)
Ejemplo n.º 19
0
def main():
    Script.registerSwitch("f:", "File=",
                          "Get output for jobs with IDs from the file")
    Script.registerSwitch("g:", "JobGroup=",
                          "Get output for jobs in the given group")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"], mandatory=False)
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    import DIRAC
    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments
    from DIRAC.Core.Utilities.Time import toString, date, day

    dirac = Dirac()

    jobs = []
    for sw, value in sws:
        if sw.lower() in ("f", "file"):
            if os.path.exists(value):
                jFile = open(value)
                jobs += jFile.read().split()
                jFile.close()
        elif sw.lower() in ("g", "jobgroup"):
            group = value
            jobDate = toString(date() - 30 * day)
            result = dirac.selectJobs(jobGroup=value, date=jobDate)
            if not result["OK"]:
                if "No jobs selected" not in result["Message"]:
                    print("Error:", result["Message"])
                    DIRAC.exit(-1)
            else:
                jobs += result["Value"]

    for arg in parseArguments(args):
        jobs.append(arg)

    if not jobs:
        print("Warning: no jobs selected")
        Script.showHelp()
        DIRAC.exit(0)

    result = dirac.deleteJob(jobs)
    if result["OK"]:
        print("Deleted jobs %s" % ",".join([str(j) for j in result["Value"]]))
        exitCode = 0
    else:
        print(result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 20
0
def main():
    Script.registerSwitch("f:", "File=",
                          "Get status for jobs with IDs from the file")
    Script.registerSwitch("g:", "JobGroup=",
                          "Get status for jobs in the given group")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"], mandatory=False)
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Core.Utilities.Time import toString, date, day
    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0

    jobs = []
    for key, value in sws:
        if key.lower() in ("f", "file"):
            if os.path.exists(value):
                jFile = open(value)
                jobs += jFile.read().split()
                jFile.close()
        elif key.lower() in ("g", "jobgroup"):
            jobDate = toString(date() - 30 * day)
            # Choose jobs no more than 30 days old
            result = dirac.selectJobs(jobGroup=value, date=jobDate)
            if not result["OK"]:
                print("Error:", result["Message"])
                DIRACExit(-1)
            jobs += result["Value"]

    if len(args) < 1 and not jobs:
        Script.showHelp(exitCode=1)

    if len(args) > 0:
        jobs += parseArguments(args)

    result = dirac.getJobStatus(jobs)
    if result["OK"]:
        for job in result["Value"]:
            print("JobID=" + str(job), end=" ")
            for status in result["Value"][job].items():
                print("%s=%s;" % status, end=" ")
            print()
    else:
        exitCode = 2
        print("ERROR: %s" % result["Message"])

    DIRACExit(exitCode)
Ejemplo n.º 21
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    result = Dirac().killJob(parseArguments(args))
    if result["OK"]:
        print("Killed jobs %s" % ",".join([str(j) for j in result["Value"]]))
        exitCode = 0
    else:
        print("ERROR", result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 22
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument((
        "URL:            URL of the service to ping (instead of System and Service)",
        "System/Service: Full component name (ie: WorkloadManagement/Matcher)",
        "System:         Name of the DIRAC system (ie: WorkloadManagement)",
    ))
    Script.registerArgument(
        " Service:        Name of the DIRAC service (ie: Matcher)",
        mandatory=False)
    _, args = Script.parseCommandLine(ignoreErrors=True)
    system = None
    service = None
    url = None
    if len(args) == 1:
        # it is a URL
        if args[0].startswith("dips://"):
            url = args[0]
        # It is System/Service
        else:
            sys_serv = args[0].split("/")
            if len(sys_serv) != 2:
                Script.showHelp(exitCode=1)
            else:
                system, service = sys_serv

    elif len(args) == 2:
        system, service = args[0], args[1]
    else:
        Script.showHelp(exitCode=1)

    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac()
    exitCode = 0

    result = dirac.pingService(system, service, printOutput=True, url=url)

    if not result:
        print("ERROR: Null result from ping()")
        exitCode = 2
    elif not result["OK"]:
        print("ERROR: ", result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 23
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("prodID: Production ID")
    _, args = Script.parseCommandLine()

    from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient

    # get arguments
    prodID = args[0]

    res = ProductionClient().setProductionStatus(prodID, "Cleaned")
    if not res["OK"]:
        DIRAC.gLogger.error(res["Message"])
        DIRAC.exit(1)

    DIRAC.gLogger.notice("Production %s successully cleaned" % prodID)
    DIRAC.exit(0)
Ejemplo n.º 24
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("Setup:    Name of the setup",
                            default="",
                            mandatory=False)
    Script.parseCommandLine(ignoreErrors=True)
    setup = Script.getPositionalArgs(group=True)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    result = diracAdmin.getServicePorts(setup, printOutput=True)
    if result["OK"]:
        DIRAC.exit(0)
    else:
        print(result["Message"])
        DIRAC.exit(2)
Ejemplo n.º 25
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs", "LFN:       Logical File Names"))
    Script.registerArgument(["Catalog:   file catalog plug-ins"], mandatory=False)
    Script.parseCommandLine()

    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    import os

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    inputFileName, catalogs = Script.getPositionalArgs(group=True)

    if os.path.exists(inputFileName):
        inputFile = open(inputFileName, "r")
        string = inputFile.read()
        lfns = string.splitlines()
        inputFile.close()
    else:
        lfns = [inputFileName]

    res = FileCatalog(catalogs=catalogs).getFileMetadata(lfns)
    if not res["OK"]:
        print("ERROR:", res["Message"])
        DIRACExit(-1)

    print("FileName".ljust(100), "Size".ljust(10), "GUID".ljust(40), "Status".ljust(8), "Checksum".ljust(10))
    for lfn in sorted(res["Value"]["Successful"].keys()):
        metadata = res["Value"]["Successful"][lfn]
        checksum = ""
        if "Checksum" in metadata:
            checksum = str(metadata["Checksum"])
        size = ""
        if "Size" in metadata:
            size = str(metadata["Size"])
        guid = ""
        if "GUID" in metadata:
            guid = str(metadata["GUID"])
        status = ""
        if "Status" in metadata:
            status = str(metadata["Status"])
        print("%s %s %s %s %s" % (lfn.ljust(100), size.ljust(10), guid.ljust(40), status.ljust(8), checksum.ljust(10)))

    for lfn in sorted(res["Value"]["Failed"].keys()):
        message = res["Value"]["Failed"][lfn]
        print(lfn, message)
Ejemplo n.º 26
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("RepoDir:  Location of Job Repository")
    _, args = Script.parseCommandLine(ignoreErrors=False)

    repoLocation = args[0]
    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac(withRepo=True, repoLocation=repoLocation)

    exitCode = 0
    result = dirac.monitorRepository(printOutput=True)
    if not result["OK"]:
        print("ERROR: ", result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 27
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs",
                             "LFN:       Logical File Names"))
    Script.registerArgument(["LFN:       Logical File Names"], mandatory=False)
    Script.parseCommandLine()

    import os
    import DIRAC
    from DIRAC import gLogger

    first, lfns = Script.getPositionalArgs(group=True)
    if os.path.exists(first):
        with open(first, "r") as inputFile:
            string = inputFile.read()
        lfns.extend([lfn.strip() for lfn in string.splitlines()])
    else:
        lfns.insert(0, first)

    from DIRAC.Core.Utilities.List import breakListIntoChunks
    from DIRAC.DataManagementSystem.Client.DataManager import DataManager

    dm = DataManager()

    errorReasons = {}
    successfullyRemoved = 0
    for lfnList in breakListIntoChunks(lfns, 100):
        res = dm.removeFile(lfnList)
        if not res["OK"]:
            gLogger.error("Failed to remove data", res["Message"])
            DIRAC.exit(-2)
        for lfn, r in res["Value"]["Failed"].items():
            reason = str(r)
            if reason not in errorReasons:
                errorReasons[reason] = []
            errorReasons[reason].append(lfn)
        successfullyRemoved += len(res["Value"]["Successful"])

    for reason, lfns in errorReasons.items():
        gLogger.notice("Failed to remove %d files with error: %s" %
                       (len(lfns), reason))
    if successfullyRemoved > 0:
        gLogger.notice("Successfully removed %d files" % successfullyRemoved)
    DIRAC.exit(0)
Ejemplo n.º 28
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["File:     File Name"])
    _, files = Script.parseCommandLine(ignoreErrors=False)

    exitCode = 0

    import DIRAC
    from DIRAC.Core.Utilities.Adler import fileAdler

    for fa in files:
        adler = fileAdler(fa)
        if adler:
            print(fa.rjust(100), adler.ljust(10))  # pylint: disable=no-member
        else:
            print("ERROR %s: Failed to get adler" % fa)
            exitCode = 2

    DIRAC.exit(exitCode)
Ejemplo n.º 29
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("PilotRef: pilot reference")
    _, args = Script.parseCommandLine(ignoreErrors=True)

    pilotRef = args[0]

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0

    result = diracAdmin.killPilot(pilotRef)
    if not result["OK"]:
        DIRAC.gLogger.error("Failed to kill pilot", pilotRef)
        DIRAC.gLogger.error(result["Message"])
        exitCode = 1

    DIRAC.exit(exitCode)
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("transID: transformation ID")
    _, args = Script.parseCommandLine()

    from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient

    if len(args) != 1:
        Script.showHelp(exitCode=1)

    tc = TransformationClient()
    res = tc.getTransformationFiles({"TransformationID": args[0]})

    if not res["OK"]:
        DIRAC.gLogger.error(res["Message"])
        DIRAC.exit(2)

    for transfile in res["Value"]:
        DIRAC.gLogger.notice(transfile["LFN"])