Exemplo n.º 1
0
def GetExecutable():
    configuration = GetConfiguration()

    (machine, machineEntry, sourceBaseDir) = simlib.GetLocalEnvironment()

    configPath = simlib.BuildPath(simenv.CONFIGS_PATH, configuration)

    if not (simlib.FileExists(configPath)):
        fatal(
            "configuration '%s', which has path '%s' does not exist or is not readable"
            % (configuration, configPath))

    exe = simlib.BuildPath(simenv.CACTUS_PATH, 'exe',
                           'cactus_%s' % configuration)

    if not (simlib.FileExists(exe)):
        fatal(
            "Executable %s for configuration %s does not exist or is not readable"
            % (exe, configuration))

    submitScript = simlib.BuildPath(configPath, "SubmitScript")

    if not (simlib.FileExists(submitScript)):
        warning("empty submit script for configuration %s" % configuration)
        submitScript = None

    runScript = simlib.BuildPath(configPath, "RunScript")

    if not (simlib.FileExists(runScript)):
        fatal("Error: empty/missing run script for configuration %s" %
              configuration)

    return (exe, submitScript, runScript)
Exemplo n.º 2
0
def CreateRestartSkeleton(simulationName):

    (machine, machineEntry, sourceBaseDir) = simlib.GetLocalEnvironment()

    basedir = simlib.GetBaseDir(machineEntry)

    try:
        simlib.MakeDirs(basedir)
    except OSError, e:
        fatal(
            "could not access simulation base directory %s for reading and writing: %s"
            % (basedir, e))
Exemplo n.º 3
0
def CreateSimulationId(simulationName):
    (machine, machineEntry, sourceBaseDir) = simlib.GetLocalEnvironment()

    hostname = machineEntry.hostname

    # make sure fd is closed.
    fd = simenv.popen('whoami')
    user = fd.read().strip()
    fd.close()

    tt = time.localtime()

    timestamp = "%4d.%02d.%02d-%02d.%02d.%02d" % (
        tt.tm_year, tt.tm_mon, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec)

    pid = os.getpid()

    simulation_id = "simulation-%s-%s-%s-%s-%s-%s" % (
        simulationName, machine, hostname, user, timestamp, pid)

    return simulation_id
Exemplo n.º 4
0
def GetExecHost(restart):

    DefineDatabase = simsubs.DefineDatabase()

    (machine, machineEntry, sourceBaseDir) = simlib.GetLocalEnvironment()

    job_id = restart.GetJobId()
    job_status = 'U'

    if job_id != -1:
        job_status = GetJobStatus(job_id)

    if job_status != 'R':
        warning("Job is not running, cannot retreive exechost")
        return None

    simlib.VerifyKeys(machineEntry, ['exechost', 'exechostpattern'])

    DefineDatabase.Set('JOB_ID', job_id)
    DefineDatabase.Set('USER', machineEntry.user)
    DefineDatabase.Set('SIMULATION_NAME', restart.SimulationName)

    exechost = DefineDatabase.SubAll(machineEntry.GetKey('exechost'))
    exechostpattern = DefineDatabase.SubAll(
        machineEntry.GetKey('exechostpattern'))

    output, rc = simlib.ExecuteCommand(exechost, True)

    rx = re.compile(exechostpattern, re.MULTILINE)

    matches = rx.search(output)

    if rc or matches == None:
        warning("Unable to retrieve exechost using pattern %s" %
                exechostpattern)
        return None

    return matches.group(1)
Exemplo n.º 5
0
def GetJobStatus(job_id):
    # TODO: there needs to be documentation stating what the possible
    # return values are

    DefineDatabase = simsubs.DefineDatabase()

    (machine, machineEntry, sourceBaseDir) = simlib.GetLocalEnvironment()
    simlib.VerifyKeys(machineEntry, [
        'getstatus', 'queuedpattern', 'runningpattern', 'statuspattern', 'user'
    ])

    status_command = machineEntry.GetKey('getstatus')
    status_pattern = machineEntry.GetKey('statuspattern')
    queued_pattern = machineEntry.GetKey('queuedpattern')
    running_pattern = machineEntry.GetKey('runningpattern')

    holding_pattern = machineEntry.GetKey('holdingpattern')

    user = machineEntry.GetKey('user')

    DefineDatabase.Set('USER', user)
    DefineDatabase.Set('JOB_ID', job_id)

    status_command = DefineDatabase.SubAll(status_command)
    status_pattern = DefineDatabase.SubAll(status_pattern)
    queued_pattern = DefineDatabase.SubAll(queued_pattern)
    running_pattern = DefineDatabase.SubAll(running_pattern)
    holding_pattern = DefineDatabase.SubAll(holding_pattern)

    #capture output.
    output, ret = simlib.ExecuteCommand(status_command, output=True)

    # U == unknown?
    status = 'U'

    if ret != None:
        lines = output.split("\n")

        #first, lets see if the job is still in the queue, regardless of whether or not we can determine the job status

        # TODO: counting lines doesn't help detecting errors
        InQueue = lines.count(job_id) > 0

        matched = []

        for line in lines:
            matches = re.search(status_pattern, line)
            if matches != None:
                # queued_pattern
                if re.search(queued_pattern, line):
                    status = 'Q'
                    matched.append(queued_pattern)

                # running_pattern
                if re.search(running_pattern, line):
                    status = 'R'
                    matched.append(running_pattern)

                # holding_pattern
                if holding_pattern != None:
                    if re.search(holding_pattern, line):
                        status = 'H'
                        matched.append(holding_pattern)

        # TODO: matches is set in the last loop iteration only; this if
        # statement is bogus
        if matches > 1:
            # TODO: output a better error message; the list of patterns
            # alone is not useful because patterns are difficult to read;
            # better would be also what state the patterns are for
            fatal("multiple status patterns matched: %s" % matched)

        if InQueue and status == 'U':
            status = 'E'

    if status == 'U':
        warning("job status is U")
        dprint("queue status return code is: %d" % ret)
        dprint("queue status output is:")
        for line in lines:
            dprint("  lines=[%s]" % line)
        dprint("patterns are:")
        dprint("  status_pattern=[%s]" % status_pattern)
        dprint("  queued_pattern=[%s]" % queued_pattern)
        dprint("  running_pattern=[%s]" % running_pattern)
        dprint("  holding_pattern=[%s]" % holding_pattern)

    return status