[Swift-commit] r3147 - trunk/src/org/griphyn/vdl/karajan/lib

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sun Oct 11 14:30:13 CDT 2009


Author: hategan
Date: 2009-10-11 14:30:13 -0500 (Sun, 11 Oct 2009)
New Revision: 3147

Added:
   trunk/src/org/griphyn/vdl/karajan/lib/SiteProfile.java
Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java
Log:
Separated site from tc profile

Added: trunk/src/org/griphyn/vdl/karajan/lib/SiteProfile.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/SiteProfile.java	                        (rev 0)
+++ trunk/src/org/griphyn/vdl/karajan/lib/SiteProfile.java	2009-10-11 19:30:13 UTC (rev 3147)
@@ -0,0 +1,136 @@
+/*
+ * Created on Dec 26, 2006
+ */
+package org.griphyn.vdl.karajan.lib;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+import org.globus.cog.abstraction.impl.common.execution.WallTime;
+import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.arguments.ArgUtil;
+import org.globus.cog.karajan.arguments.NamedArguments;
+import org.globus.cog.karajan.stack.VariableStack;
+import org.globus.cog.karajan.util.BoundContact;
+import org.globus.cog.karajan.util.TypeUtil;
+import org.globus.cog.karajan.workflow.ExecutionException;
+import org.globus.cog.karajan.workflow.nodes.grid.GridExec;
+import org.globus.swift.catalog.TransformationCatalogEntry;
+import org.globus.swift.catalog.types.Os;
+import org.globus.swift.catalog.util.Profile;
+import org.griphyn.vdl.karajan.TCCache;
+import org.griphyn.vdl.util.FQN;
+
+public class SiteProfile extends VDLFunction {
+    public static final Logger logger = Logger.getLogger(SiteProfile.class);
+    
+	public static final Arg PA_HOST = new Arg.Positional("host");
+	public static final Arg PA_FQN = new Arg.Positional("fqn");
+
+	static {
+		setArguments(SiteProfile.class, new Arg[] { PA_HOST, PA_FQN });
+	}
+
+	public Object function(VariableStack stack) throws ExecutionException {
+		BoundContact bc = (BoundContact) PA_HOST.getValue(stack);
+		return getSingle(bc, new FQN(TypeUtil.toString(PA_FQN.getValue(stack))));
+	}
+	
+	public static final FQN SWIFT_WRAPPER_INTERPRETER = new FQN("swift:wrapperInterpreter");
+	public static final FQN SWIFT_WRAPPER_INTERPRETER_OPTIONS = new FQN("swift:wrapperInterpreterOptions");
+	public static final FQN SWIFT_WRAPPER_SCRIPT = new FQN("swift:wrapperScript");
+	public static final FQN SWIFT_CLEANUP_COMMAND = new FQN("swift:cleanupCommand");
+	public static final FQN SWIFT_CLEANUP_COMMAND_OPTIONS = new FQN("swift:cleanupCommandOptions");
+	public static final FQN SYSINFO_OS = new FQN("SYSINFO:OS");
+	
+	private static final Map DEFAULTS;
+	
+	private static void addDefault(Os os, FQN fqn, Object value) {
+		Map osm = (Map) DEFAULTS.get(os);
+		if (osm == null) {
+			osm = new HashMap();
+			DEFAULTS.put(os, osm);
+		}
+		osm.put(fqn, value);
+	}
+	
+	private static boolean hasDefault(Os os, FQN fqn) {
+		Map osm = (Map) DEFAULTS.get(os);
+		if (osm == null) {
+			return false;
+		}
+		else {
+			return osm.containsKey(fqn);
+		}
+	}
+	
+	private static Object getDefault(Os os, FQN fqn) {
+		Map osm = (Map) DEFAULTS.get(os);
+		if (osm == null) {
+			osm = (Map) DEFAULTS.get(null);
+		}
+		return osm.get(fqn);
+	}
+	
+	static {
+		DEFAULTS = new HashMap();
+		addDefault(Os.WINDOWS, SWIFT_WRAPPER_INTERPRETER, "cscript.exe");
+		addDefault(Os.WINDOWS, SWIFT_WRAPPER_SCRIPT, "_swiftwrap.vbs");
+		addDefault(Os.WINDOWS, SWIFT_WRAPPER_INTERPRETER_OPTIONS, new String[] {"//Nologo"});
+		addDefault(Os.WINDOWS, SWIFT_CLEANUP_COMMAND, "cmd.exe");
+		addDefault(Os.WINDOWS, SWIFT_CLEANUP_COMMAND_OPTIONS, new String[] {"/C", "del", "/Q"});
+		addDefault(null, SWIFT_WRAPPER_INTERPRETER, "/bin/bash");
+		addDefault(null, SWIFT_WRAPPER_SCRIPT, "_swiftwrap");
+		addDefault(null, SWIFT_WRAPPER_INTERPRETER_OPTIONS, null);
+		addDefault(null, SWIFT_CLEANUP_COMMAND, "/bin/rm");
+		addDefault(null, SWIFT_CLEANUP_COMMAND_OPTIONS, new String[] {"-rf"});
+	}
+	
+	private Object getSingle(BoundContact bc, FQN fqn) {
+            String value = getProfile(bc, fqn);
+            if (value == null) {
+            	Os os = getOS(bc);
+            	if ("swift".equals(fqn.getNamespace())) {
+            		return getDefault(os, fqn);
+            	}
+                else if (SYSINFO_OS.equals(fqn)) {
+                	return os;
+                }
+                else {
+                	return null;
+                }
+            }
+            else {
+            	return value;
+            }
+	}
+
+    private String getProfile(BoundContact bc, FQN fqn) {
+        Object o = bc.getProperty(fqn.toString());
+        if (o == null) {
+            return null;
+        }
+        else {
+            return o.toString();
+        }
+    }
+    
+    private Os getOS(BoundContact bc) {
+    	Object o = bc.getProperty("sysinfo");
+    	if (o == null) {
+    		return Os.LINUX;
+    	}
+    	else {
+    		String[] p = o.toString().split("::");
+    		if (p.length < 2) {
+    			throw new IllegalArgumentException("Invalid sysinfo for " + bc + ": " + o);
+    		}
+    		return Os.fromString(p[1]);
+    	}
+    }
+}

Modified: trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java	2009-10-11 19:29:02 UTC (rev 3146)
+++ trunk/src/org/griphyn/vdl/karajan/lib/TCProfile.java	2009-10-11 19:30:13 UTC (rev 3147)
@@ -20,9 +20,9 @@
 import org.globus.cog.karajan.util.TypeUtil;
 import org.globus.cog.karajan.workflow.ExecutionException;
 import org.globus.cog.karajan.workflow.nodes.grid.GridExec;
-import org.griphyn.cPlanner.classes.Profile;
-import org.griphyn.common.catalog.TransformationCatalogEntry;
-import org.griphyn.common.classes.Os;
+import org.globus.swift.catalog.TransformationCatalogEntry;
+import org.globus.swift.catalog.types.Os;
+import org.globus.swift.catalog.util.Profile;
 import org.griphyn.vdl.karajan.TCCache;
 import org.griphyn.vdl.util.FQN;
 
@@ -31,10 +31,9 @@
     
 	public static final Arg PA_TR = new Arg.Positional("tr");
 	public static final Arg PA_HOST = new Arg.Positional("host");
-	public static final Arg OA_FQN = new Arg.Optional("fqn");
-
+	
 	static {
-		setArguments(TCProfile.class, new Arg[] { PA_TR, PA_HOST, OA_FQN });
+		setArguments(TCProfile.class, new Arg[] { PA_TR, PA_HOST });
 	}
 
 	private static Map PROFILE_T;
@@ -56,9 +55,6 @@
 		TCCache tc = getTC(stack);
 		String tr = TypeUtil.toString(PA_TR.getValue(stack));
 		BoundContact bc = (BoundContact) PA_HOST.getValue(stack);
-		if (OA_FQN.isPresent(stack)) {
-		    return getSingle(tc, tr, bc, new FQN(TypeUtil.toString(OA_FQN.getValue(stack))));
-		}
 		
 		NamedArguments named = ArgUtil.getNamedReturn(stack);
 		Map attrs = null;
@@ -82,89 +78,6 @@
 		return null;
 	}
 	
-	public static final FQN SWIFT_WRAPPER_INTERPRETER = new FQN("swift:wrapperInterpreter");
-	public static final FQN SWIFT_WRAPPER_INTERPRETER_OPTIONS = new FQN("swift:wrapperInterpreterOptions");
-	public static final FQN SWIFT_WRAPPER_SCRIPT = new FQN("swift:wrapperScript");
-	public static final FQN INTERNAL_OS = new FQN("INTERNAL:OS");
-	
-	private Object getSingle(TCCache tc, String tr, BoundContact bc, FQN fqn) {
-            TransformationCatalogEntry tce = getTCE(tc, new FQN(tr), bc);
-            String value = getProfile(tce, fqn);
-            if (value == null) {
-                value = getProfile(bc, fqn);
-            }
-            if (value == null) {
-                if (SWIFT_WRAPPER_INTERPRETER.equals(fqn)) {
-                    if (tce.getSysInfo().getOs().equals(Os.WINDOWS)) {
-                        return "cscript.exe";
-                    }
-                    else {
-                        return "/bin/bash";
-                    }
-                }
-                else if (SWIFT_WRAPPER_SCRIPT.equals(fqn)) {
-                    if (tce.getSysInfo().getOs().equals(Os.WINDOWS)) {
-                        return "_swiftwrap.vbs";
-                    }
-                    else {
-                        return "_swiftwrap";
-                    }
-                }
-                else if (SWIFT_WRAPPER_INTERPRETER_OPTIONS.equals(fqn)) {
-                	if (tce.getSysInfo().getOs().equals(Os.WINDOWS)) {
-                		return new String[] {"//Nologo"};
-                	}
-                	else {
-                		return null;
-                	}
-                }
-                else if (INTERNAL_OS.equals(fqn)) {
-                	Os os = tce.getSysInfo().getOs();
-                	if (os == null) {
-                		return Os.LINUX;
-                	}
-                	else {
-                		return os;
-                	}
-                }
-            }
-            return value;
-	}
-
-    private String getProfile(BoundContact bc, FQN fqn) {
-        Object o = bc.getProperty(fqn.toString());
-        if (o == null) {
-            return null;
-        }
-        else {
-            return o.toString();
-        }
-    }
-
-    private String getProfile(TransformationCatalogEntry tce, FQN fqn) {
-        List profiles = tce.getProfiles();
-        if (profiles == null) {
-        	return null;
-        }
-        Iterator i = profiles.iterator();
-        while (i.hasNext()) {
-            Profile p = (Profile) i.next();
-            if (eq(p.getProfileNamespace(), fqn.getNamespace()) && eq(p.getProfileKey(), fqn.getName())) {
-                return p.getProfileValue();
-            }
-        }
-        return null;
-    }
-	
-	private boolean eq(Object o1, Object o2) {
-	    if (o1 == null) {
-	        return o2 == null;
-	    }
-	    else {
-	        return o1.equals(o2);
-	    }
-	}
-
     private void checkWalltime(String tr, NamedArguments attrs) {
 	    Object walltime = null;
 	    if (attrs != null) {




More information about the Swift-commit mailing list