[Swift-commit] r5207 - in trunk: libexec resources src/org/griphyn/vdl/engine src/org/griphyn/vdl/karajan/lib

wozniak at ci.uchicago.edu wozniak at ci.uchicago.edu
Thu Oct 6 16:19:33 CDT 2011


Author: wozniak
Date: 2011-10-06 16:19:33 -0500 (Thu, 06 Oct 2011)
New Revision: 5207

Modified:
   trunk/libexec/execute-default.k
   trunk/libexec/vdl-int.k
   trunk/libexec/vdl.k
   trunk/resources/Karajan.stg
   trunk/resources/swiftscript.g
   trunk/resources/swiftscript.stg
   trunk/resources/swiftscript.xsd
   trunk/src/org/griphyn/vdl/engine/Karajan.java
   trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java
Log:
Allow dynamic profiles in SwiftScript


Modified: trunk/libexec/execute-default.k
===================================================================
--- trunk/libexec/execute-default.k	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/libexec/execute-default.k	2011-10-06 21:19:33 UTC (rev 5207)
@@ -1,4 +1,4 @@
-element([tr, optional(arguments, stdin, stdout, stderr, deperror, mdeperror), channel(stagein), channel(stageout), channel(restartout)]
+element([tr, optional(arguments, stdin, stdout, stderr, attributes, deperror, mdeperror), channel(stagein), channel(stageout), channel(restartout)]
 
 	vdl:initprogressstate()
 
@@ -20,8 +20,9 @@
 							parallelFor(i, replicationChannel
 								ignoreErrors(match = "^Abort$"
 									execute2(
-										tr, maybe(arguments=unwrapClosedList(arguments)), 
-										maybe(stdin=stdin), maybe(stdout=stdout), maybe(stderr=stderr), 
+										tr, maybe(arguments=unwrapClosedList(arguments)),
+										maybe(stdin=stdin), maybe(stdout=stdout), maybe(stderr=stderr),
+                    maybe(attributes=attributes),
 										stagein, stageout, restartout, replicationGroup, replicationChannel
 									)
 								)
@@ -33,6 +34,7 @@
 					)
 					catch(".*"
 						log(LOG:INFO, "END_FAILURE thread={#thread} tr={tr}")
+						log(LOG:WARN, "EXCEPTION {exception}")
 						vdl:setprogress("Failed")
 						if(
 							vdl:configProperty("lazy.errors") == "false" then(
@@ -56,7 +58,7 @@
 		else (
 			if(
 				merr == true then(
-					exception := exception(concat("VDL2: Application ", str:quote(tr), 
+					exception := exception(concat("VDL2: Application ", str:quote(tr),
 						" not executed due to errors in mapping dependencies"))
 					to(errors, exception)
 					log(LOG:INFO, exception)

Modified: trunk/libexec/vdl-int.k
===================================================================
--- trunk/libexec/vdl-int.k	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/libexec/vdl-int.k	2011-10-06 21:19:33 UTC (rev 5207)
@@ -31,7 +31,6 @@
 			dir:make(dc, host=host)
 		)
 
-
 		element(checkJobStatus, [rhost, wfdir, jobid, tr, jobdir]
 			log(LOG:DEBUG, "START jobid={jobid}")
 			try(
@@ -192,7 +191,6 @@
 			)
 		)
 
-
 		element(stageWrapperParams, [jobid, jobdir, wrapfile, dir, host]
 			log(LOG:INFO, "START jobid={jobid} - staging in wrapper params")
 			provider := provider(wrapfile)
@@ -207,7 +205,6 @@
 
 			task:transfer(srcprovider=provider, srchost=srchost, srcfile=filename, srcdir=srcdir, desthost=host, destdir=destdir)
 			log(LOG:INFO, "END jobid={jobid}")
-
 		)
 
 		element(doStagein, [jobid, files, dir, host]
@@ -401,7 +398,7 @@
 			recfile
 		)
 
-		element(execute2, [tr, optional(arguments, stdin, stdout, stderr), stagein, stageout,  restartout,
+		element(execute2, [tr, optional(arguments, stdin, stdout, stderr, attributes), stagein, stageout,  restartout,
 			replicationGroup, replicationChannel]
 			stagein := list(unique(each(stagein)))
 			stageout := list(unique(each(stageout)))
@@ -480,7 +477,7 @@
 								directory=wfdir
 								redirect=false
 								host=rhost
-								vdl:tcprofile(rhost, tr=tr) //this gets various app params from the tc, such as environment, walltime, etc
+								vdl:tcprofile(rhost, maybe(attributes=attributes), tr=tr) //this gets various app params from the tc, such as environment, walltime, etc
 								replicationGroup=replicationGroup
 								replicationChannel=replicationChannel
 								jobid=jobid
@@ -510,7 +507,7 @@
 							directory=wfdir
 							redirect=false
 							host=rhost
-							vdl:tcprofile(rhost, tr=tr) //this gets various app params from the tc, such as environment, walltime, etc
+							vdl:tcprofile(rhost, maybe(attributes=attributes), tr=tr)
 							replicationGroup=replicationGroup
 							replicationChannel=replicationChannel
 							jobid=jobid

Modified: trunk/libexec/vdl.k
===================================================================
--- trunk/libexec/vdl.k	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/libexec/vdl.k	2011-10-06 21:19:33 UTC (rev 5207)
@@ -9,7 +9,7 @@
 
 	import("vdl-sc.k", export = true)
 	import("vdl-lib.xml", export = true)
-	
+
 	pstaging := configProperty("use.provider.staging")
 	int := if (pstaging == "true", "vdl-int-staging.k", "vdl-int.k")
 
@@ -23,18 +23,18 @@
 		log("info","RUNID id=run:{VDL:RUNID}")
 		echo("RunID: {VDL:RUNID}")
 	)
-	
+
 	export("stagein", elementDef(classname="org.griphyn.vdl.karajan.lib.Stagein"))
 	export("stageout", elementDef(classname="org.griphyn.vdl.karajan.lib.Stageout"))
 
 	export(
-	
-		element(parameterlog, [direction, variable, id, thread], 
-			if( 
-				vdl:configProperty("provenance.log") == "true" 
-				log("info","PARAM thread={thread} direction={direction} variable={variable} provenanceid={id}") 
-			) 
-		) 
+
+		element(parameterlog, [direction, variable, id, thread],
+			if(
+				vdl:configProperty("provenance.log") == "true"
+				log("info","PARAM thread={thread} direction={direction} variable={variable} provenanceid={id}")
+			)
+		)
 		element(split, [var], each(str:split(vdl:getFieldValue(var), " ")))
 
 		element(quote, [var, optional(path)],
@@ -59,7 +59,7 @@
 				)
 			)
 		)
-		
+
 		element(mapping, [descriptor, ...]
 			mapping=map(map:entry("descriptor", descriptor), each(...))
 		)
@@ -84,6 +84,10 @@
 			tr = name
 		)
 
+    element(attributes, [attrs]
+      attributes = attrs
+    )
+
 		element(mains, [channel(cleanup), channel(errors), channel(warnings)]
 			anyerrors := vdl:processBulkErrors("The following errors have occurred:", errors)
 
@@ -110,7 +114,7 @@
 		parallelElement(mainp, [channel(graph), channel(cleanup)]
 			parallel(
 				if(
-					vdl:configProperty("pgraph") != "false" 
+					vdl:configProperty("pgraph") != "false"
 						generateProvenanceGraph(graph)
 				)
 				to(cleanup, unique(for(c, cleanup, c)))

Modified: trunk/resources/Karajan.stg
===================================================================
--- trunk/resources/Karajan.stg	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/resources/Karajan.stg	2011-10-06 21:19:33 UTC (rev 5207)
@@ -12,8 +12,8 @@
   $if(types)$
   <types>
      <xs:schema targetNamespace="http://ci.uchicago.edu/swift/2009/02/swiftscript" xmlns="http://ci.uchicago.edu/swift/2009/02/swiftscript" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">
-     $types;separator="\n"$  
-     </xs:schema>	 
+     $types;separator="\n"$
+     </xs:schema>
   </types>
   $endif$
   $constants;separator="\n"$
@@ -37,7 +37,7 @@
 
 typeDef(name,type,members,sourcelocation) ::= <<
  $if(type)$
-   	 <xs:element name="$name$" type="$type$"/>      
+   	 <xs:element name="$name$" type="$type$"/>
  $else$
    $if(!members)$
  	   <xs:simpleType name="$name$">
@@ -52,7 +52,7 @@
    $endif$
  $endif$
 >>
- 	
+
 memberdefinition(type,name,sourcelocation) ::= <<
    <xs:element name="$name$" type="$type$"/>
 >>
@@ -98,13 +98,14 @@
 $endif$
 >>
 
-vdl_execute(outputs,inputs,application,name,line) ::= <<
+vdl_execute(outputs,inputs,attributes,application,name,line) ::= <<
 <log level="debug" message="PROCEDURE line=$line$ thread={#thread} name=$name$"/>
 <vdl:execute>
+  $attributes$
   <vdl:tr>$application.exec$</vdl:tr>
   $inputs:vdl_stagein();separator="\n"$
   $outputs:vdl_stageout();separator="\n"$
-  $vdl_arguments(arguments=application.arguments, stdin=application.stdin,stdout=application.stdout,stderr=application.stderr)$
+  $vdl_arguments(attributes=application.attributes,arguments=application.arguments, stdin=application.stdin,stdout=application.stdout,stderr=application.stderr)$
 </vdl:execute>
 $outputs:vdl_closedataset();separator="\n"$
 <log level="debug" message="PROCEDURE_END line=$line$"/>
@@ -144,7 +145,8 @@
 <vdl:cleandataset var="{$it$}"/>
 >>
 
-vdl_arguments(arguments,stdin,stdout,stderr) ::= <<
+vdl_arguments(attributes,arguments,stdin,stdout,stderr) ::= <<
+  $attributes$
 <vdl:arguments>
   $arguments;separator="\n"$
 </vdl:arguments>
@@ -165,6 +167,26 @@
 $endif$
 >>
 
+vdl_attributes(entries) ::= <<
+<vdl:attributes>
+   <map>
+    $entries;separator="\n"$
+  </map>
+</vdl:attributes>
+
+>>
+
+map_entry(key,value) ::= <<
+      <entry>
+        <vdl:getfieldvalue>
+          $key$
+        </vdl:getfieldvalue>
+        <vdl:getfieldvalue>
+          $value$
+        </vdl:getfieldvalue>
+      </entry>
+>>
+
 parallel(statements) ::= <<
 $if(rest(statements))$
 <parallel>
@@ -194,7 +216,7 @@
     <vdl:getfieldvalue>$cond$</vdl:getfieldvalue>
     <sys:break/>
   </sys:if>
-  
+
 </vdl:infinitecountingwhile>
 >>
 
@@ -222,7 +244,7 @@
 >>
 
 // need to log inputs and outputs at the calling stage here because
-// they are not 
+// they are not
 // $outputs:vdl_log_output();separator="\n"$
 
 callInternal(func, outputs, inputs) ::= <<
@@ -547,7 +569,7 @@
 
 slicearray(parent, memberchild, datatype) ::= <<
 <sequential>
- <set name="swift#array">$parent$</set> 
+ <set name="swift#array">$parent$</set>
  <set name="swift#slice">
   <vdl:slicearray>
     <argument name="var"><variable>swift#array</variable></argument>

Modified: trunk/resources/swiftscript.g
===================================================================
--- trunk/resources/swiftscript.g	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/resources/swiftscript.g	2011-10-06 21:19:33 UTC (rev 5207)
@@ -118,7 +118,7 @@
       thisTypeTemplate=template("type");
       thisTypeTemplate.setAttribute("name", thisType);
       e.setAttribute("type", thisTypeTemplate);
-      code.setAttribute("members", e); 
+      code.setAttribute("members", e);
     }
     (
         COMMA
@@ -134,7 +134,7 @@
            thisTypeTemplate=template("type");
            thisTypeTemplate.setAttribute("name", thisType);
            e1.setAttribute("type", thisTypeTemplate);
-           code.setAttribute("members", e1); 
+           code.setAttribute("members", e1);
          }
     )*
     SEMI
@@ -167,7 +167,7 @@
        }
 
 // these are non-declaration append-associative array statements
- 
+
 	|   (predictAppendStat) => d=appendStat
 		{
 		 code.setAttribute("statements",d);
@@ -218,7 +218,7 @@
     :
      n=declarator
 	(LBRACK
-	(sTemp=type {sType = (String) sTemp.getAttribute("name") ;} )? 
+	(sTemp=type {sType = (String) sTemp.getAttribute("name") ;} )?
 	RBRACK {thisType = thisType + "[" + sType + "]" ; sType = ""; } )*
      {
         thisTypeTemplate=template("type");
@@ -434,6 +434,7 @@
         )?
         RPAREN
         LCURLY
+        ( appProfile[app] )*
         exec=declarator
         {app.setAttribute("exec",exec);}
         ( appArg[app] )* SEMI
@@ -445,6 +446,18 @@
         }
     ;
 
+appProfile [StringTemplate code]
+{   StringTemplate p=null;
+    StringTemplate k=null;
+    StringTemplate v=null;}
+    : "profile" k=expression ASSIGN v=expression SEMI
+        {
+            p=template("app_profile");
+            p.setAttribute("key", k);
+            p.setAttribute("value", v);
+            code.setAttribute("profiles", p);
+        }
+    ;
 
 // TODO in here, why do we have an | between LBRACKBRACK and ASSIGN?
 // does this mean that we don't have array initialisation in formal
@@ -475,7 +488,7 @@
         }
     ;
 
-type returns [ StringTemplate code = null ] 
+type returns [ StringTemplate code = null ]
 	{ StringBuilder buf = new StringBuilder(); }
 :
 	id:ID {
@@ -486,7 +499,7 @@
 		code.setAttribute("name", buf.toString());
 	}
 ;
-    
+
 typeSubscript[StringBuilder buf] :
 	LBRACK { buf.append('['); }
 	(id:ID { buf.append(id.getText()); })?
@@ -570,7 +583,7 @@
         code.setAttribute("var", id.getText());
         code.setAttribute("in", ds);
         if (indexId != null) {
-           code.setAttribute("index", indexId.getText());           
+           code.setAttribute("index", indexId.getText());
         }
     }
     compoundStat[body] {code.setAttribute("body", body);}
@@ -636,7 +649,7 @@
 
 predictAppendStat
 {StringTemplate x=null;}
-    : x=identifier APPEND ;    
+    : x=identifier APPEND ;
 
 assignStat returns [StringTemplate code=null]
 {StringTemplate id=null;}
@@ -661,7 +674,7 @@
 	{ StringTemplate id=null; }
 :
     id=identifier
-    APPEND 
+    APPEND
     (
     	(predictProcedurecallAssign) => code=procedurecallCode {
     		StringTemplate o = template("returnParam");
@@ -669,12 +682,12 @@
 			code.setAttribute("outputs",o);
         }
     	|
-      	code=arrayAppend { 
-			code.setAttribute("array", id);          
+      	code=arrayAppend {
+			code.setAttribute("array", id);
 		}
     )
 ;
-    
+
 arrayAppend returns [ StringTemplate code = null ]
 	{ StringTemplate a = null, e = null, id = null; }
 :
@@ -744,7 +757,7 @@
         )?
         RPAREN
     ;
-    
+
 procedureCallExpr returns [StringTemplate code=template("call")]
 {StringTemplate f=null;}
     :
@@ -846,6 +859,7 @@
     {code.setAttribute("config",app);}
     ;
 
+/* This is the deprecated format for app { } blocks */
 appSpec returns [StringTemplate code=template("app")]
 {StringTemplate exec=null;}
     :  "app" LCURLY
@@ -1060,7 +1074,7 @@
 
 primExpr returns [StringTemplate code=null]
 {StringTemplate id=null, exp=null;}
-    : (predictProcedureCallExpr) => code=procedureCallExpr                     
+    : (predictProcedureCallExpr) => code=procedureCallExpr
     | code=identifier
     | LPAREN exp=orExpr RPAREN { code=template("paren");
         code.setAttribute("exp", exp);}
@@ -1078,7 +1092,7 @@
 // other IDs
 
 identifier returns [StringTemplate code=null]
-{ 
+{
   StringTemplate c=null;
   code=template("variableReference");
 }

Modified: trunk/resources/swiftscript.stg
===================================================================
--- trunk/resources/swiftscript.stg	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/resources/swiftscript.stg	2011-10-06 21:19:33 UTC (rev 5207)
@@ -12,10 +12,10 @@
     $imports;separator="\n"$
   </imports>
   $endif$
-  $if(types)$  
+  $if(types)$
   <types>
-     $types;separator="\n"$   
-  </types>  
+     $types;separator="\n"$
+  </types>
   $endif$
   $functions;separator="\n"$
   $statements;separator="\n"$
@@ -42,7 +42,7 @@
 		<typename>$name$</typename>
 		<typealias>$type$</typealias>
 		<typestructure></typestructure>
-	</type>   
+	</type>
 $else$
 $if(!members)$
 	<type>
@@ -140,14 +140,14 @@
 parameter(type,name,outlink,defaultv,sourcelocation) ::= <<
 
 $if(outlink)$
-  <output 
+  <output
 $else$
-  <input 
+  <input
 $endif$
 
 name="$name$" type="$type$"
 
-$if(defaultv)$> 
+$if(defaultv)$>
 $defaultv$
 
 $if(outlink)$
@@ -161,10 +161,13 @@
 $endif$
 >>
 
-app(exec,arguments,stdin,stdout,stderr,sourcelocation) ::= <<
+app(exec,profiles,arguments,stdin,stdout,stderr,sourcelocation) ::= <<
 <binding>
   <application src="$sourcelocation$">
     <executable>$exec$</executable>
+$if(profiles)$
+    $profiles$
+$endif$
 $if(stdin)$
     $stdin$
 $endif$
@@ -181,6 +184,14 @@
 </binding>
 >>
 
+app_profile(key, value, sourcelocation) ::= <<
+  <profile>
+    $key$
+    $value$
+  </profile>
+
+>>
+
 functionInvocation(name,args,sourcelocation) ::= <<
 <function name="$name$">
 $if(args)$

Modified: trunk/resources/swiftscript.xsd
===================================================================
--- trunk/resources/swiftscript.xsd	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/resources/swiftscript.xsd	2011-10-06 21:19:33 UTC (rev 5207)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
            version="1.0"
-           targetNamespace="http://ci.uchicago.edu/swift/2009/02/swiftscript" 
+           targetNamespace="http://ci.uchicago.edu/swift/2009/02/swiftscript"
            xmlns="http://ci.uchicago.edu/swift/2009/02/swiftscript"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
@@ -49,11 +49,11 @@
          <xs:complexType>
           <xs:sequence>
 	        <xs:element name="typename" type="xs:string" />
-			<xs:element name="typealias" type="xs:string" />			
+			<xs:element name="typealias" type="xs:string" />
 	        <xs:element name="typestructure" type="TypeStructure" />
 	      </xs:sequence>
          </xs:complexType>
-        </xs:element>        
+        </xs:element>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
@@ -65,7 +65,7 @@
       </xs:sequence>
     </xs:complexType>
   </xs:element>
-  
+
   <xs:complexType name="Procedure">
     <xs:annotation>
       <xs:documentation>a procedure defines the logical interface of a
@@ -121,7 +121,7 @@
         <xs:documentation>the name of the procedure</xs:documentation>
       </xs:annotation>
     </xs:attribute>
-    
+
     <xs:attribute name="src" type="xs:string" />
   </xs:complexType>
 
@@ -168,6 +168,10 @@
         </xs:annotation>
       </xs:element>
 
+      <xs:element name="profile" type="Profile"
+                  minOccurs="0" maxOccurs="unbounded">
+      </xs:element>
+
       <xs:sequence>
 
         <xs:element minOccurs="0" name="stdin" type="UnlabelledUnaryOperator">
@@ -202,6 +206,13 @@
 
   </xs:complexType>
 
+  <xs:complexType name="Profile">
+    <xs:sequence>
+      <xs:element ref="abstractExpression" />
+      <xs:element ref="abstractExpression" />
+    </xs:sequence>
+  </xs:complexType>
+
   <xs:group name="ArgumentGroup">
     <xs:sequence>
       <xs:element minOccurs="0" name="function" type="Function"/>
@@ -225,6 +236,10 @@
     </xs:attribute>
   </xs:complexType>
 
+  <!--
+      This is an older idea about how to put profile settings in XML
+      It should not be accessible from SwiftScript any more. -Justin
+
   <xs:complexType mixed="true" name="Profile">
     <xs:annotation>
       <xs:documentation>profile specifies configuration information pertaining
@@ -245,6 +260,7 @@
 
     <xs:attribute name="key" type="xs:NMTOKEN" use="required"/>
   </xs:complexType>
+  -->
 
   <xs:complexType name="Array">
     <xs:annotation>
@@ -342,7 +358,7 @@
     <xs:attribute name="src" type="xs:string" />
 
   </xs:complexType>
-  
+
   <xs:complexType name="Append">
     <xs:annotation>
       <xs:documentation>appends a value to an array
@@ -404,7 +420,7 @@
       </xs:element>
 
       <xs:element name="assign" type="Assign"/>
-      
+
       <xs:element name="append" type="Append"/>
 
       <xs:element name="call" type="Call"/>
@@ -615,7 +631,7 @@
 		             type="TypeRow" name="member" />
 	</xs:sequence>
   </xs:complexType>
-	
+
   <xs:complexType name="TypeRow">
 	<xs:sequence>
 		<xs:element name="membername" type="xs:string"/>

Modified: trunk/src/org/griphyn/vdl/engine/Karajan.java
===================================================================
--- trunk/src/org/griphyn/vdl/engine/Karajan.java	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/src/org/griphyn/vdl/engine/Karajan.java	2011-10-06 21:19:33 UTC (rev 5207)
@@ -86,7 +86,7 @@
 	}
 
 	public static void compile(String in, PrintStream out, boolean provenanceEnabled) throws CompilationException {
-		Karajan me = new Karajan();
+		Karajan karajan = new Karajan();
 		StringTemplateGroup templates;
 		try {
 		    StringTemplateGroup main = new StringTemplateGroup(new InputStreamReader(
@@ -112,8 +112,8 @@
 		}
 
 		Program prog = programDoc.getProgram();
-		me.setTemplateGroup(templates);
-		StringTemplate code = me.program(prog);
+		karajan.setTemplateGroup(templates);
+		StringTemplate code = karajan.program(prog);
 		out.println(code.toString());
 	}
 
@@ -370,7 +370,7 @@
 			checkIsTypeDefined(type);
 			outerScope.addVariable(param.getName(), type);
 		}
-
+		
 		Binding bind;
 		if ((bind = proc.getBinding()) != null) {
 			binding(bind, procST, innerScope);
@@ -1022,12 +1022,34 @@
 				appST.setAttribute("stdout", expressionToKarajan(app.getStdout().getAbstractExpression(), scope));
 			if(app.getStderr()!=null)
 				appST.setAttribute("stderr", expressionToKarajan(app.getStderr().getAbstractExpression(), scope));
+			addProfiles(app, scope, appST);
 			return appST;
 		} catch(CompilationException e) {
 			throw new CompilationException(e.getMessage()+" in application "+app.getExecutable()+" at "+app.getSrc(),e);
 		}
 	}
 
+	private void addProfiles(ApplicationBinding app, 
+	                         VariableScope scope,
+	                         StringTemplate appST) 
+	throws CompilationException {
+		Profile[] profiles = app.getProfileArray();
+		if (profiles.length == 0) 
+			return;
+		StringTemplate attributes = template("vdl_attributes");
+		for (Profile profile : profiles) { 
+			XmlObject xmlKey   = profile.getAbstractExpressionArray(0);
+			XmlObject xmlValue = profile.getAbstractExpressionArray(1);
+			StringTemplate key   = expressionToKarajan(xmlKey, scope);
+			StringTemplate value = expressionToKarajan(xmlValue, scope);
+			StringTemplate entry = template("map_entry");
+			entry.setAttribute("key", key);
+			entry.setAttribute("value", value);
+			attributes.setAttribute("entries", entry);
+		}
+		appST.setAttribute("attributes", attributes);
+	}
+
 	/** Produces a Karajan function invocation from a SwiftScript invocation.
 	  * The Karajan invocation will have the same name as the SwiftScript
 	  * function, in the 'vdl' Karajan namespace. Parameters to the

Modified: trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java	2011-10-06 21:00:21 UTC (rev 5206)
+++ trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java	2011-10-06 21:19:33 UTC (rev 5207)
@@ -27,11 +27,19 @@
 public class TCProfile extends VDLFunction {
     public static final Logger logger = Logger.getLogger(TCProfile.class);
     
-	public static final Arg OA_TR = new Arg.Optional("tr");
-	public static final Arg PA_HOST = new Arg.Positional("host");
+	public static final Arg OA_TR    = new Arg.Optional("tr");
 	
+	/**
+	   Allows for dynamic attributes from the SwiftScript 
+	   profile statements. 
+	   These override any other attributes. 
+	 */
+	public static final Arg OA_ATTRS = new Arg.Positional("attributes");
+	
+	public static final Arg PA_HOST  = new Arg.Positional("host");
+	
 	static {
-		setArguments(TCProfile.class, new Arg[] { PA_HOST, OA_TR });
+		setArguments(TCProfile.class, new Arg[] { PA_HOST, OA_ATTRS, OA_TR });
 	}
 
 	private static Map<String, Arg> PROFILE_T;
@@ -52,14 +60,17 @@
 	public Object function(VariableStack stack) throws ExecutionException {
 		TCCache tc = getTC(stack);
 		String tr = null;
+		
+		Map<String,Object> dynamicAttributes = 
+			readDynamicAttributes(stack);
+		
 		if (OA_TR.isPresent(stack)) {
 		    tr = TypeUtil.toString(OA_TR.getValue(stack));
 		}
 		BoundContact bc = (BoundContact) PA_HOST.getValue(stack);
 		
 		NamedArguments named = ArgUtil.getNamedReturn(stack);
-		Map<String,Object> attrs = null;
-		
+		Map<String,Object> attrs = null;	
 		attrs = attributesFromHost(bc, attrs, named);
 
 		TCEntry tce = null;
@@ -75,11 +86,46 @@
 		}
 		named.add(GridExec.A_ENVIRONMENT, env);
 		checkWalltime(tr, named);
+		attrs = addDynamicAttributes(attrs, dynamicAttributes);
 		addAttributes(named, attrs);
 		return null;
 	}
+
+	/**
+	   Bring in the dynamic attributes from the Karajan stack 
+	   @return Map, may be null
+	 */
+	@SuppressWarnings("unchecked")
+	private Map<String, Object> 
+	readDynamicAttributes(VariableStack stack) 
+	throws ExecutionException {
+		Map<String, Object> result = null;
+		if (OA_ATTRS.isPresent(stack)) 
+			result = (Map<String,Object>) OA_ATTRS.getValue(stack);
+		return result;
+	}
 	
-    private void checkWalltime(String tr, NamedArguments attrs) {
+	/**
+       Store dynamic attributes into returned attributes, 
+       overwriting if necessary
+       @param result Attributes so far known, may be null
+       @param dynamicAttributes Attributes to insert, may be null
+       @result Combination, may be null
+	 */
+	private Map<String, Object>
+	addDynamicAttributes(Map<String, Object> result,
+	                     Map<String, Object> dynamicAttributes) {
+		if (result == null && dynamicAttributes == null)
+			return null;
+		if (result == null)
+			return dynamicAttributes;
+		if (dynamicAttributes == null)
+			return result;
+		result.putAll(dynamicAttributes);
+		return result;
+	}
+	
+	private void checkWalltime(String tr, NamedArguments attrs) {
 	    Object walltime = null;
 	    if (attrs != null) {
 	        if (attrs.hasArgument("maxwalltime")) {




More information about the Swift-commit mailing list