Last active
December 20, 2015 02:09
-
-
Save melrom/6054487 to your computer and use it in GitHub Desktop.
saga remote staging example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import saga | |
import getpass | |
REMOTE_HOST = "login1.stampede.tacc.utexas.edu" | |
USERNAME = os.environ.get('USER') | |
WORKING_DIRECTORY = "/home1/02554/sagatut/XSEDETutorial/%s/SAGA" % USERNAME | |
def main(): | |
try: | |
# Your ssh identity on the remote machine | |
ctx = saga.Context("ssh") | |
ctx.user_id = "sagatut" | |
session = saga.Session() | |
session.add_context(ctx) | |
# Create a job service object that represent the local machine. | |
# The keyword 'fork://' in the url scheme triggers the 'shell' adaptor | |
# which can execute jobs on the local machine as well as on a remote | |
# machine via "ssh://hostname". | |
js = saga.job.Service("slurm+ssh://%s" % REMOTE_HOST, session=session) | |
# describe our job | |
jd = saga.job.Description() | |
# Next, we describe the job we want to run. A complete set of job | |
# description attributes can be found in the API documentation. | |
jd.environment = {'MYOUTPUT':'"Hello from SAGA"'} | |
jd.executable = '/bin/echo' | |
jd.arguments = ['$MYOUTPUT'] | |
jd.queue = "normal" | |
jd.wall_time_limit = 1 # minutes | |
jd.working_directory = WORKING_DIRECTORY | |
jd.output = "examplejob.out" | |
jd.error = "examplejob.err" | |
# Create a new job from the job description. The initial state of | |
# the job is 'New'. | |
myjob = js.create_job(jd) | |
# Check our job's id and state | |
print "Job ID : %s" % (myjob.id) | |
print "Job State : %s" % (myjob.state) | |
print "\n...starting job...\n" | |
# Now we can start our job. | |
myjob.run() | |
print "Job ID : %s" % (myjob.id) | |
print "Job State : %s" % (myjob.state) | |
print "\n...waiting for job...\n" | |
# wait for the job to either finish or fail | |
myjob.wait() | |
print "Job State : %s" % (myjob.state) | |
print "Exitcode : %s" % (myjob.exit_code) | |
outfilesource = 'sftp://%s/%s/examplejob.out' % (REMOTE_HOST, WORKING_DIRECTORY) | |
outfiletarget = "file:////%s/" % os.getcwd() | |
out = saga.filesystem.File(outfilesource, session=session) | |
out.copy(outfiletarget) | |
print "Staged out %s to %s (size: %s bytes)" % (outfilesource, outfiletarget, out.get_size()) | |
return 0 | |
except saga.SagaException, ex: | |
# Catch all saga exceptions | |
print "An exception occured: (%s) %s " % (ex.type, (str(ex))) | |
# Trace back the exception. That can be helpful for debugging. | |
print " \n*** Backtrace:\n %s" % ex.traceback | |
return -1 | |
if __name__ == "__main__": | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment