[Swift-commit] r3126 - trunk/libexec

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sat Oct 10 20:39:23 CDT 2009


Author: hategan
Date: 2009-10-10 20:39:23 -0500 (Sat, 10 Oct 2009)
New Revision: 3126

Added:
   trunk/libexec/_swiftwrap.vbs
Modified:
   trunk/libexec/vdl-int.k
Log:
added windows wrapper; allow flexible wrappers

Added: trunk/libexec/_swiftwrap.vbs
===================================================================
--- trunk/libexec/_swiftwrap.vbs	                        (rev 0)
+++ trunk/libexec/_swiftwrap.vbs	2009-10-11 01:39:23 UTC (rev 3126)
@@ -0,0 +1,370 @@
+ai = 0
+Set args = WScript.Arguments
+Dim info, fs
+Set fs = WScript.CreateObject("Scripting.FileSystemObject")
+Set shell = WScript.CreateObject("WScript.Shell")
+MandatoryArg = True
+OptionalArg = False
+
+'WScript.Echo("-ab-:" + prepareOne("ab"))
+'WScript.Echo("-a b-:" + prepareOne("a b"))
+'WScript.Echo("-a\b-:" + prepareOne("a\b"))
+'WScript.Echo("-a""b-:" + prepareOne("a""b"))
+'WScript.Echo("-a\""b-:" + prepareOne("a\""b"))
+'WScript.Echo("-a\\b-:" + prepareOne("a\\b"))
+'WScript.Echo("-a\\""b-:" + prepareOne("a\\""b"))
+
+Sub fail(message, code)
+	log message
+	If STATUSMODE = "files" Then
+		errf = WFDIR + "\status\" + JOBDIR + "\" + ID + "-error"
+		log "Error file: " + errf
+		Set sf = fs.OpenTextFile(errf, 2, True)
+		sf.WriteLine(message)
+		sf.Close
+		WScript.Quit(0)
+	Else
+		WScript.Echo(message)
+		WScript.Quit(code)
+	End If
+End Sub
+
+Sub openinfo(name) 
+	Set info = fs.OpenTextFile(name, 8, True)
+End Sub
+
+Sub closeinfo
+	info.close()
+End Sub
+
+Function getArgVal(cls, name)
+	arr = getArgVals(cls, name)
+	If UBound(arr) = 0 Then
+		getArgVal = Empty
+	Else
+		getArgVal = RTrim(Join(arr))
+	End If
+End Function
+
+Function getArgVals(cls, name)
+	Dim val(255)
+	sz = 0
+	again = True
+	Do While again
+		done = (ai >= args.count)
+		If Not(done) Then
+			If Left(args(ai), 1) = "-" Then
+				done = True
+			End If
+		End If
+		If done Then
+			If UBound(val) = 0 and cls = MandatoryArg Then
+				fail "Expected " + name, 253
+			End If
+			again = False
+		Else
+			val(sz) = args(ai)
+			ai = ai + 1
+			sz = sz + 1
+		End If
+	Loop
+	getArgVals = val
+End Function
+
+Function getOptArg() 
+	getOptArg = getArgVal(OptionalArg, "")
+End Function
+
+Function expectArg(name)
+	nope = (ai >= args.count)
+	If Not(nope) Then
+		If args(ai) <> "-" + name Then
+			nope = True
+		End If
+	End If
+	If nope Then
+		fail "Expected argument " + name, 252
+	Else
+		ai = ai + 1
+	End If
+End Function
+
+Sub logstate(args)
+	'todo: timestamp and whatever else the "standard" format
+	info.WriteLine("Progress " + args)
+End Sub	
+
+Sub log(args)
+	'todo: timestamp and whatever else the "standard" format
+	info.WriteLine(args)
+End Sub
+
+
+Function deleteIfExists(name)
+	If fs.FileExists(name) Then
+		fs.DeleteFile(name)
+	End If
+End Function
+
+Sub mkdir(f)
+	If f = "" Then
+		fail "mkdir called with empty argument", 249
+	End If
+	If Not fs.FolderExists(f) Then
+		mkdir fs.GetParentFolderName(f)
+		fs.CreateFolder(f)
+	End If
+End Sub
+
+Function prepareOne(v) 
+	'Arguments with spaces must be quoted with a double quote
+	'Literal double quotes must be escaped with a backslash
+	'Literal backslashes must be escaped (with a backslash) if they appear before a double quote
+	start = 1
+	Do While start < Len(v) and Not start = 0
+		start = InStr(start, v, "\")
+		If start <> 0 Then
+			v = Left(v, start) + "\" + Right(v, Len(v) - start)
+			start = start + 2
+		End If
+	Loop
+	start = 1
+	Do While start < Len(v) and Not start = 0
+		start = InStr(start, v, """")
+		If start <> 0 Then
+			v = Left(v, start - 1) + "\" + Right(v, Len(v) - start + 1)
+			start = start + 2
+		End If
+	Loop
+	If Not InStr(v, " ") = 0 Then
+		v = """" + v + """"
+	End If
+	prepareOne = v
+End Function
+
+Function prepareArgs(args)
+	For i = 0 To UBound(args)
+		args(i) = prepareOne(args(i))
+	Next
+	prepareArgs = join(args)
+End Function
+
+
+WFDIR = fs.GetAbsolutePathName(".")
+
+openinfo("wrapper.log")
+
+ID = getArgVal(MandatoryArg, "job id")
+expectArg("jobdir")
+JOBDIR = getArgVal(MandatoryArg, "job dir")
+
+mkdir WFDIR + "\info\" + JOBDIR
+
+closeinfo
+deleteIfExists(WFDIR + "\info\" + JOBDIR + "\" + ID + "-info")
+openinfo(WFDIR + "\info\" + JOBDIR + "\" + ID + "-info")
+
+logstate "LOG_START"
+
+expectArg("e")
+EXEC = getArgVal(MandatoryArg, "executable")
+
+expectArg("out")
+STDOUT=getArgVal(MandatoryArg, "stdout")
+
+expectArg("err")
+STDERR=getArgVal(MandatoryArg, "stderr")
+
+expectArg("i")
+STDIN=getOptArg()
+
+expectArg("d")
+DIRS=getOptArg()
+
+expectArg("if")
+INF=getOptArg()
+
+expectArg("of")
+OUTF=getOptArg()
+
+expectArg("k")
+KICKSTART=getOptArg()
+
+expectArg("status")
+STATUSMODE=getArgVal(MandatoryArg, "status")
+
+expectArg("a")
+Dim ARGS
+ARGS=getArgVals(OptionalArg, "args")
+
+If STATUSMODE = "files" Then
+	mkdir WFDIR + "\status\" + JOBDIR
+End If
+
+'No linking on Windows
+COPYNOTLINK=True	
+DIR=WFDIR + "\jobs\" + JOBDIR + "\" + ID
+
+Set env = shell.Environment("PROCESS")
+If Not env("PATHPREFIX") = "" Then
+	env("PATH") = env("PATHPREFIX") + ";" + env("PATH")
+End If
+
+If Not env("SWIFT_EXTRA_INFO") = "" Then
+	log "EXTRAINFO=" + env("SWIFT_EXTRA_INFO")
+End If
+
+
+log "DIR=" + DIR
+log "EXEC=" + EXEC
+log "STDIN=" + STDIN
+log "STDOUT=" + STDOUT
+log "STDERR=" + STDERR
+log "DIRS=" + DIRS
+log "INF=" + INF
+log "OUTF=" + OUTF
+log "STATUSMODE=" + STATUSMODE
+log "KICKSTART=" + KICKSTART
+log "ARGS=" + Join(ARGS)
+
+logstate "CREATE_JOBDIR"
+log "Jobdir: " + DIR
+mkdir DIR
+log "Created job directory: " + DIR
+
+logstate "CREATE_INPUTDIR"
+
+For Each D in Split(DIRS, "|")
+	mkdir DIR + "\" + D
+	log "Created output directory: " + DIR + "\" + D
+Next
+
+logstate "LINK_INPUTS"
+For Each L in Split(INF, "|")
+	fs.CopyFile WFDIR + "\shared\" + L, DIR + "\" + L
+	log "Copied input: " + WFDIR + "\shared\" + L + " to " + DIR + "\" + L
+Next
+
+logstate "EXECUTE"
+shell.CurrentDirectory = DIR
+
+If LCase(fs.GetAbsolutePathName(EXEC)) <> LCase(EXEC) Then
+	'relative name
+	If Not fs.FileExists(EXEC) Then
+		found = False
+		'search in path
+		dirs = split(env("PATH"), ";")
+		For Each d in dirs
+			If fs.FileExists(d + "\" + EXEC) Then
+				found = True
+				Exit For
+			End If
+		Next
+		If Not Found Then
+			fail "The executable (" + EXEC + ") was not found in the current directory or search path", 252
+		End If
+	End If
+Else
+	If Not fs.FileExists(EXEC) Then
+		fail "Executable (" + EXEC + ") does not exist", 251
+	End If
+End If
+
+If KICKSTART = "" Then
+	Set min = Nothing
+	Set mout = Nothing
+	Set merr = Nothing
+	If STDIN <> "" Then
+		Set min = fs.OpenTextFile(STDIN, 1, False)
+	End If
+	If STDOUT <> "" Then
+		Set mout = fs.OpenTextFile(STDOUT, 2, True)
+	End If
+	If STDERR <> "" Then
+		Set merr = fs.OpenTextFile(STDERR, 2, True)
+	End If
+	qargs = prepareArgs(ARGS)
+	log "Cmd: " + prepareOne(EXEC) + " " + qargs
+	Set p = shell.exec(prepareOne(EXEC) + " " + qargs)
+	log "Executable started"
+
+	Do While Not p.StdOut.AtEndOfStream and Not p.StdErr.AtEndOfStream and p.Status = 0
+		some = False
+		If Not min Is Nothing Then
+			l = min.ReadLine
+			p.StdIn.WriteLine(l)
+			some = True
+		End If
+		If Not p.StdOut.AtEndOfStream Then
+			l = p.StdOut.ReadLine
+			If Not mout Is Nothing Then
+				mout.WriteLine(l)
+			End If
+			some = True
+		End If
+		If Not p.StdErr.AtEndOfStream Then
+			l = p.StdErr.ReadLine
+			If Not merr Is Nothing Then
+				merr.WriteLine(l)
+			End If
+			some = True
+		End If
+		WScript.Sleep(100)
+	Loop
+	If Not min Is Nothing Then
+		min.close()
+	End If
+	If Not mout Is Nothing Then
+		mout.close()
+	End If
+	If Not merr Is Nothing Then
+		merr.close()
+	End If
+	If p.ExitCode <> 0 Then
+		fail "Exit code " + p.ExitCode, p.ExitCode
+	End If
+Else
+	fail "Kickstart is not supported on Windows", 250
+End If
+	
+shell.CurrentDirectory = WFDIR
+
+log "Moving back to workflow directory " + WFDIR
+logstate "EXECUTE_DONE"
+log "Job ran successfully"
+
+MISSING = ""
+For Each O in Split(OUTF, "|")
+	If Not fs.FileExists(DIR + "\" + O) Then
+		If MISSING = "" Then
+			MISSING = O
+		Else
+			MISSING = MISSING + ", " + O
+		End If
+	End If
+Next
+If Not MISSING = "" Then
+	fail "The following output files were not created by the application: " + MISSING, 254
+End If
+
+logstate "MOVING_OUTPUTS"
+For Each O in split(OUTF, "|")
+	fs.MoveFile DIR + "\" + O,  "shared\" + O
+Next
+
+logstate "RM_JOBDIR"
+fs.DeleteFolder DIR, True
+
+If STATUSMODE = "files" Then
+	logstate "TOUCH_SUCCESS"
+	Set sf = fs.OpenTextFile("status\" + JOBDIR + "\" + ID + "-success", 2, True)
+	sf.Close
+End If
+
+logstate "END"
+
+closeinfo
+
+'ensure we exit with a 0 after a successful exection
+WScript.Quit(0)
+

Modified: trunk/libexec/vdl-int.k
===================================================================
--- trunk/libexec/vdl-int.k	2009-10-11 01:30:18 UTC (rev 3125)
+++ trunk/libexec/vdl-int.k	2009-10-11 01:39:23 UTC (rev 3126)
@@ -70,7 +70,7 @@
 					 * the presence of the success file and remove it, all
 					 * in one operation. It relies on file:remove() throwing 
 					 * an exception if the file is not there. 
-					 */
+					 */ 
 					file:remove("{wfdir}/status/{jobdir}/{jobid}-success", host=rhost)
 					log(LOG:INFO, "SUCCESS jobid={jobid} - Success file found")
 				)
@@ -104,8 +104,9 @@
 				wfdir := "{VDL:SCRIPTNAME}-{VDL:RUNID}"
 				sharedDir := dircat(wfdir, "shared")
 				dir:make(sharedDir, host=rhost)
-				transfer(srcdir="{vds.home}/libexec/", srcfile="_swiftwrap", destdir=sharedDir, desthost=rhost)
-				transfer(srcdir="{vds.home}/libexec/", srcfile="_swiftseq", destdir=sharedDir, desthost=rhost)
+				transfer(srcdir="{swift.home}/libexec/", srcfile="_swiftwrap", destdir=sharedDir, desthost=rhost)
+				transfer(srcdir="{swift.home}/libexec/", srcfile="_swiftwrap.vbs", destdir=sharedDir, desthost=rhost)
+				transfer(srcdir="{swift.home}/libexec/", srcfile="_swiftseq", destdir=sharedDir, desthost=rhost)
 				dir:make(dircat(wfdir, "kickstart"), host=rhost)
 
 				statusMode := configProperty("status.mode",host=rhost)
@@ -416,6 +417,7 @@
 				stderr := try(stderr, "stderr.txt")
 				kickstart := vdl:kickstart(rhost)
 				fileDirs := fileDirs(stagein, stageout)
+				os := vdl:tcprofile(tr, rhost, fqn="INTERNAL:OS") 
 
 				if(wrapperMode == "files"
 					sequential(
@@ -455,20 +457,29 @@
 						vdl:setprogress("Submitting")
 
 						if(wrapperMode == "files"
-							vdl:execute("/bin/bash",
-								list("shared/_swiftwrap", jobid, "-p", jobdir)
-							directory=wfdir
-							redirect=false
-							host=rhost
-							vdl:tcprofile(tr, rhost) //this gets various app params from the tc, such as environment, walltime, etc
-							replicationGroup=replicationGroup
-							replicationChannel=replicationChannel
-							jobid=jobid
+							vdl:execute(
+								vdl:tcprofile(tr, rhost, fqn="swift:wrapperInterpreter"),
+								list(
+									vdl:tcprofile(tr, rhost, fqn="swift:wrapperInterpreterOptions"),
+									dircat("shared", vdl:tcprofile(tr, rhost, fqn="swift:wrapperScript"), os=os), 
+									jobid, "-p", jobdir
+								)
+								directory=wfdir
+								redirect=false
+								host=rhost
+								vdl:tcprofile(tr, rhost) //this gets various app params from the tc, such as environment, walltime, etc
+								replicationGroup=replicationGroup
+								replicationChannel=replicationChannel
+								jobid=jobid
 							)
 						)
 						if(wrapperMode == "args"
-							vdl:execute("/bin/bash",
-								list("shared/_swiftwrap", jobid,
+							vdl:execute(
+								vdl:tcprofile(tr, rhost, fqn="swift:wrapperInterpreter"),
+								list(
+								vdl:tcprofile(tr, rhost, fqn="swift:wrapperInterpreterOptions"),
+								dircat("shared", vdl:tcprofile(tr, rhost, fqn="swift:wrapperScript"), os=os),
+								jobid,
 								"-jobdir", jobdir,
 								"-e", vdl:executable(tr, rhost), 
 								"-out", stdout, 
@@ -538,7 +549,7 @@
 						outs := transferStandardFiles(rhost, tmpdir, jobid, stdout, stderr)
 						
 						discard(maybe(transferWrapperLog(rhost, wfdir, jobid, jobdir)))
-							
+
 						kickstartRec := if(
 							kickstart == "" ""
 							else(




More information about the Swift-commit mailing list