def prestagesandbox(self, jobconfig): job = self.getJobObject() mon = job.getMonitoringService() inw = job.getInputWorkspace() sandbox_files = jobconfig.getSandboxFiles() logger.info("pre-staging files for saga job with id: %s", job.id) ## Compression is ENABLED. All input sandbox files are archived ## into an uncompressed tarball which is then transfered to the ## execution host. This speeds up things a lot in many scenarios. ## if self.enable_compression: logger.info(" * adding %s user defined files to input sandbox", len(sandbox_files)) import Ganga.Core.Sandbox as Sandbox compressed_input_sandbox = job.createPackedInputSandbox( jobconfig.getSandboxFiles() + Sandbox.getGangaModulesAsSandboxFiles(Sandbox.getDefaultModules()) + Sandbox.getGangaModulesAsSandboxFiles(mon.getSandboxModules()) ) try: for f in compressed_input_sandbox: archive_url = saga.url("file://localhost/" + f) logger.info( " * copying %s -> %s ", archive_url.url, self.filesystem_url + "/" + self.workdir_uuid + "/" ) sf = saga.filesystem.file(archive_url.url) sf.copy(self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error("exception caught while transfering file: %s", e.get_all_exceptions()) job.updateStatus("failed") return False ## Compression is DISABLED. All input sandbox files are transfered ## one-by-one to the execution host. This can be very slow, especially ## if SAGA is using the Globus GridFTP adaptor. else: logger.info("prestaging %s input sandbox files", len(sandbox_files)) for f in sandbox_files: try: source = saga.url(f.name) if len(source.scheme) == 0: source.scheme = "file" if len(source.host) == 0: source.host = "localhost" if f.subdir != ".": # create subdirectory & copy target = saga.url(self.filesystem_url + "/" + self.workdir_uuid + "/" + f.subdir + "/") sd = saga.filesystem.directory(target, saga.filesystem.Create) sf = saga.filesystem.file(source) logger.info(" * copying %s -> %s ", source, target) sf.copy(target, saga.filesystem.Overwrite) # copy the file else: # copy to remote work dir logger.info( " * copying %s -> %s ", source, self.filesystem_url + "/" + self.workdir_uuid + "/" ) sf = saga.filesystem.file(source) sf.copy(self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error("exception caught while transfering file: %s", e.get_all_exceptions()) job.updateStatus("failed") return False ## ## copy the job script ## try: jobscript_path = saga.url("file://localhost/" + inw.getPath() + "/__jobscript__") if os.path.exists(jobscript_path.path): logger.info( " * copying %s -> %s ", jobscript_path.url, self.filesystem_url + "/" + self.workdir_uuid + "/" ) sf = saga.filesystem.file(jobscript_path.url) sf.copy(self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error("exception caught while transfering file: %s", e.get_all_exceptions()) job.updateStatus("failed") return False return True
def makesagajobdesc(self, job, jobconfig): ## We need a unique subdirectory per job to avoid input/output file clashes ## The easiest way to do this is with a UUID-style directory name wd_uuid = "ganga-job-" # if job.name == '': # wd_uuid += "noname-" # else: # wd_uuid += job.name + "-" import uuid wd_uuid += str(uuid.uuid4()) job.backend.workdir_uuid = wd_uuid ## Now we need to create a wrapper script on the fly. The wrapper ## script will be be transfered to the execution host and takes care ## of the archive unpacking as well as job monitoring / reporting. ws = SAGAWrapperScript() import inspect import Ganga.Core.Sandbox as Sandbox import Ganga.Utility as Utility ws.setInlineModules(inspect.getsource(Sandbox.WNSandbox)) ws.setMonitoringService(job.getMonitoringService().getWrapperScriptConstructorText()) ws.setExecutable(jobconfig.getExeString()) ws.setArguments(jobconfig.getArgStrings()) ws.setOutputPatterns(jobconfig.outputbox) ws.setInputSandbox("_input_sandbox_" + str(job.id) + ".tgz") text = ws.getScript() jd = saga.job.description() logger.debug("setting up new saga job with id: %s", job.id) # create jobscript in input sandbox from Ganga.GPIDev.Lib.File import FileBuffer jobscript = job.getInputWorkspace().writefile(FileBuffer("__jobscript__", text), executable=1) logger.debug(" * created new jobscript wrapper: %s", jobscript) # workdir if len(job.backend.workdir) != 0: jd.working_directory = job.backend.workdir logger.debug(" * backend.workdir -> saga.workdir: %s", jd.working_directory) else: # default to the remote filesystem path component jd.working_directory = saga.url(self.filesystem_url + "/" + self.workdir_uuid + "/").path logger.debug(" * saga.workdir: %s (not given - extracted from 'filesystem_url')", jd.working_directory) # executable exe = jd.working_directory + "__jobscript__" jd.executable = exe # jobconfig.getExeString() logger.debug(" * application.exe -> saga.executable: %s", jd.executable) # arguments argList = jobconfig.getArgStrings() # for arg in job.application.args: # argList.append( arg ) #"\\'%s\\'" % arg ) if len(argList) != 0: jd.arguments = argList logger.debug(" * application.args -> saga.arguments: %s", jd.arguments) # environment envList = [] for k, v in job.application.env.items(): envList.append(k + "=" + v) # "\\'%s\\'" % arg ) if len(envList) != 0: jd.environment = envList logger.debug(" * application.env -> saga.environment: %s", jd.environment) # queue if len(job.backend.queue) != 0: jd.queue = job.backend.queue logger.debug(" * backend.queue -> saga.queue: %s", jd.queue) # allocation if len(job.backend.allocation) != 0: jd.job_project = [job.backend.allocation] logger.debug(" * backend.allocation -> saga.job_project: %s", jd.job_project) # spmd_variation if len(job.backend.spmd_variation) != 0: jd.spmd_variation = job.backend.spmd_variation logger.debug(" * backend.spmd_variation -> saga.spmd_variation: %s", jd.spmd_variation) # number_of_processes if len(job.backend.number_of_processes) != 0: jd.number_of_processes = job.backend.number_of_processes logger.debug(" * backend.number_of_processes -> saga.number_of_processes: %s", jd.number_of_processes) ## We have to create special filenames for stdout/stderr redirection ## To avoid name clashes, we append a UUID to the filename. path_component = saga.url(self.filesystem_url + "/" + self.workdir_uuid + "/") try: d = saga.filesystem.directory(path_component, saga.filesystem.Create) logger.debug(" * created output/working directory on the remote system: %s", path_component) except saga.exception as e: logger.error("exception caught while creating output/working directory: %s", e.get_all_messages()) self.getJobObject().updateStatus("failed") ## STDOUT self.saga_job_out = path_component.url + "/out.log" # jd.output = saga.url(self.saga_job_out).path logger.debug(" * stdout should become available here: %s", saga.url(self.saga_job_out).url) ## STDERR self.saga_job_err = path_component.url + "/err.log" # jd.error = saga.url(self.saga_job_err).path logger.debug(" * stderr should become available here: %s", saga.url(self.saga_job_err).url) return jd
def prestagesandbox(self, jobconfig): job = self.getJobObject() mon = job.getMonitoringService() inw = job.getInputWorkspace() sandbox_files = jobconfig.getSandboxFiles() logger.info("pre-staging files for saga job with id: %s", job.id) ## Compression is ENABLED. All input sandbox files are archived ## into an uncompressed tarball which is then transfered to the ## execution host. This speeds up things a lot in many scenarios. ## if self.enable_compression: logger.info(" * adding %s user defined files to input sandbox", len(sandbox_files)) import Ganga.Core.Sandbox as Sandbox from Ganga.GPIDev.Lib.File import File from Ganga.Core.Sandbox.WNSandbox import PYTHON_DIR import inspect fileutils = File(inspect.getsourcefile(Ganga.Utility.files), subdir=PYTHON_DIR) compressed_input_sandbox = job.createPackedInputSandbox( jobconfig.getSandboxFiles() + [fileutils]) try: for f in compressed_input_sandbox: archive_url = saga.url("file://localhost/" + f) logger.info( " * copying %s -> %s ", archive_url.url, self.filesystem_url + "/" + self.workdir_uuid + "/") sf = saga.filesystem.file(archive_url.url) sf.copy( self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error('exception caught while transfering file: %s', e.get_all_exceptions()) job.updateStatus("failed") return False ## Compression is DISABLED. All input sandbox files are transfered ## one-by-one to the execution host. This can be very slow, especially ## if SAGA is using the Globus GridFTP adaptor. else: logger.info("prestaging %s input sandbox files", len(sandbox_files)) for f in sandbox_files: try: source = saga.url(f.name) if (len(source.scheme) == 0): source.scheme = "file" if (len(source.host) == 0): source.host = "localhost" if (f.subdir != '.'): # create subdirectory & copy target = saga.url(self.filesystem_url + "/" + self.workdir_uuid + "/" + f.subdir + "/") sd = saga.filesystem.directory(target, saga.filesystem.Create) sf = saga.filesystem.file(source) logger.info(" * copying %s -> %s ", source, target) sf.copy(target, saga.filesystem.Overwrite) # copy the file else: # copy to remote work dir logger.info( " * copying %s -> %s ", source, self.filesystem_url + "/" + self.workdir_uuid + "/") sf = saga.filesystem.file(source) sf.copy( self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error('exception caught while transfering file: %s', e.get_all_exceptions()) job.updateStatus("failed") return False ## ## copy the job script ## try: jobscript_path = saga.url("file://localhost/" + inw.getPath() + "/__jobscript__") if os.path.exists(jobscript_path.path): logger.info( " * copying %s -> %s ", jobscript_path.url, self.filesystem_url + "/" + self.workdir_uuid + "/") sf = saga.filesystem.file(jobscript_path.url) sf.copy(self.filesystem_url + "/" + self.workdir_uuid + "/", saga.filesystem.Overwrite) except saga.exception as e: logger.error('exception caught while transfering file: %s', e.get_all_exceptions()) job.updateStatus("failed") return False return True