[Swift-commit] r7988 - trunk/src/org/griphyn/vdl/util

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Fri Jul 11 22:48:39 CDT 2014


Author: hategan
Date: 2014-07-11 22:48:39 -0500 (Fri, 11 Jul 2014)
New Revision: 7988

Modified:
   trunk/src/org/griphyn/vdl/util/ConfigTree.java
   trunk/src/org/griphyn/vdl/util/ConvertConfig.java
   trunk/src/org/griphyn/vdl/util/SwiftConfig.java
   trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java
Log:
config updates

Modified: trunk/src/org/griphyn/vdl/util/ConfigTree.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/ConfigTree.java	2014-07-12 03:47:24 UTC (rev 7987)
+++ trunk/src/org/griphyn/vdl/util/ConfigTree.java	2014-07-12 03:48:39 UTC (rev 7988)
@@ -203,10 +203,10 @@
         }
         
         private void toString(StringBuilder sb, int level, String k) {
-            for (int i = 0; i < level; i++) {
-                sb.append('\t');
-            }
             if (nodes == null || nodes.isEmpty()) {
+                for (int i = 0; i < level; i++) {
+                    sb.append('\t');
+                }
                 if (value != null) {
                     sb.append(k);
                     sb.append(": ");
@@ -224,13 +224,16 @@
             else if (nodes.size() == 1) {
                 String key = nodes.keySet().iterator().next();
                 if (k == null) {
-                    nodes.values().iterator().next().toString(sb, 0, key);
+                    nodes.values().iterator().next().toString(sb, level, key);
                 }
                 else {
-                    nodes.values().iterator().next().toString(sb, 0, k + "." + key);
+                    nodes.values().iterator().next().toString(sb, level, k + "." + key);
                 }
             }
             else {
+                for (int i = 0; i < level; i++) {
+                    sb.append('\t');
+                }
                 if (k != null) {
                     sb.append(k);
                     sb.append(' ');
@@ -245,6 +248,18 @@
                 sb.append("}\n");
             }
         }
+
+        public List<String> getLeafPaths() {
+            List<String> l = new ArrayList<String>();
+            getLeafPaths(l, null);
+            return l;
+        }
+        
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            toString(sb, 0, null);
+            return sb.toString();
+        }
     }
     
     private Node<T> root;
@@ -274,9 +289,7 @@
     }
 
     public List<String> getLeafPaths() {
-        List<String> l = new ArrayList<String>();
-        root.getLeafPaths(l, null);
-        return l;
+        return root.getLeafPaths();
     }
 
     /**

Modified: trunk/src/org/griphyn/vdl/util/ConvertConfig.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/ConvertConfig.java	2014-07-12 03:47:24 UTC (rev 7987)
+++ trunk/src/org/griphyn/vdl/util/ConvertConfig.java	2014-07-12 03:48:39 UTC (rev 7988)
@@ -153,55 +153,101 @@
                     }
                     if (e.getKey().type == Service.EXECUTION) {
                         ExecutionService es = (ExecutionService) e.getValue();
-                        ps.println("\texecution {");
-                        ps.println("\t\ttype: \"" + provider + "\"");
+                        beginObject(1, "site.*.execution", ps);
+                        writeValue(2, "site.*.execution.type", provider, ps);
                         if (es.getServiceContact() != null) {
-                            ps.println("\t\tURL: \"" + es.getServiceContact().getContact() + "\"");
+                            writeValue(2, "site.*.execution.URL", es.getServiceContact().getContact(), ps);
                         }
                         if (es.getJobManager() != null) {
-                            ps.println("\t\tjobManager: \"" + es.getJobManager() + "\"");
+                            writeValue(2, "site.*.execution.jobManager", es.getJobManager(), ps);
                         }
                         if (provider.equals("coaster")) {
                             hasCoasterService = true;
                             generateCoasterServiceAttributes(bc, ps);
                         }
-                        ps.println("\t}");
+                        endObject(1, ps);
                         if (!provider.equals("coaster")) {
                             generateServiceAttributes(es, ps);
                         }
                     }
                     else if (e.getKey().type == Service.FILE_OPERATION) {
                         hasFileService = true;
-                        ps.println("\tfilesystem {");
-                        ps.println("\t\ttype: \"" + provider + "\"");
+                        beginObject(1, "site.*.filesystem", ps);
+                        writeValue(2, "site.*.filesystem.type", provider, ps);
                         if (e.getValue().getServiceContact() != null) {
-                            ps.println("\t\tURL: \"" + e.getValue().getServiceContact().getContact() + "\"");
+                            writeValue(2, "site.*.filesystem.URL", e.getValue().getServiceContact().getContact(), ps);
                         }
-                        ps.println("\t}");
+                        endObject(1, ps);
                     }
                 }
                 if (!hasFileService) {
-                    ps.println("\tstaging: \"provider\"");
+                    writeValue(1, "site.*.staging", "proxy", ps);
                 }
                 if (bc.hasProperty("workdir")) {
-                    ps.println("\tworkDirectory: \"" + bc.getProperty("workdir") + "\"");
+                    writeValue(1, "site.*.workDirectory", bc.getProperty("workdir"), ps);
                 }
                 if (bc.hasProperty("scratch")) {
-                    ps.println("\tscratch: \"" + bc.getProperty("scratch") + "\"");
+                    writeValue(1, "site.*.scratch", bc.getProperty("scratch"), ps);
                 }
                 generateSiteAttributes(bc.getProperties(), ps);
                 if (tc != null) {
-                    generateAppInfo(bc.getName(), tc, hasCoasterService, 1, ps);
+                    generateAppInfo("site.*.", bc.getName(), tc, hasCoasterService, 1, ps);
                 }
+                else {
+                    if (bc.hasProperty("globus:maxwalltime")) {
+                        ps.println("\tapp.ALL {");
+                        writeValue(2, "site.*.app.*.maxWallTime", bc.getProperty("globus:maxwalltime"), ps);
+                        ps.println("\t}");
+                    }
+                }
                 ps.println("}\n");
             }
         }
         if (tc != null) {
-            generateAppInfo("*", tc, false, 0, ps);
+            generateAppInfo("", "*", tc, false, 0, ps);
         }
     }
     
-    private void generateAppInfo(String host, TransformationCatalog tc, boolean hasCoasterService, int level, PrintStream ps) {
+    private void writeValue(int level, String key, Object value, PrintStream ps) {
+        if (!SwiftConfig.SCHEMA.isNameValid(key)) {
+            throw new IllegalArgumentException("Invalid property: " + key);
+        }
+        SwiftConfigSchema.Info i = SwiftConfig.SCHEMA.getInfo(key);
+        if (i == null) {
+            SwiftConfig.SCHEMA.getInfo(key);
+            throw new IllegalArgumentException("No type information found for: " + key);
+        }
+        i.type.check(key, value, i.loc);
+        tabs(level, ps);
+        ps.print(last(key));
+        ps.print(": ");
+        if (value instanceof String) {
+            ps.println("\"" + value + "\"");
+        }
+        else {
+            ps.println(value);
+        }
+    }
+
+    private void endObject(int level, PrintStream ps) {
+        tabs(level, ps);
+        ps.println("}");
+    }
+
+    private void beginObject(int level, String key, PrintStream ps) {
+        if (!SwiftConfig.SCHEMA.isNameValid(key)) {
+            throw new IllegalArgumentException("Invalid property: " + key);
+        }
+        tabs(level, ps);
+        ps.print(last(key));
+        ps.println(" {");
+    }
+
+    private String last(String key) {
+        return key.substring(key.lastIndexOf('.') + 1);
+    }
+
+    private void generateAppInfo(String prefix, String host, TransformationCatalog tc, boolean hasCoasterService, int level, PrintStream ps) {
         try {
             for (TCEntry e : tc.getTC()) {
                 if (e.getResourceId().equals(host)) {
@@ -213,10 +259,10 @@
                         tabs(level, ps);
                         ps.println("app." + e.getLogicalName() + " {");
                     }
-                    tabs(level + 1, ps);
-                    ps.println("executable: " + e.getPhysicalTransformation());
+                    
+                    writeValue(level + 1, prefix + "app.*.executable", e.getPhysicalTransformation(), ps);
                     if (e.getProfiles() != null) {
-                        generateAppProfiles(e, hasCoasterService, level, ps);
+                        generateAppProfiles(prefix + "app.*.", e, hasCoasterService, level, ps);
                     }
                     tabs(level, ps);
                     ps.println("}\n");
@@ -228,27 +274,25 @@
         }
     }
 
-    private void generateAppProfiles(TCEntry e, boolean hasCoasterService, int level, PrintStream ps) {
+    private void generateAppProfiles(String prefix, TCEntry e, boolean hasCoasterService, int level, PrintStream ps) {
         StringBuilder options = new StringBuilder();
         for (Profile p : e.getProfiles()) {
             if (p.getProfileKey().startsWith("env.")) {
                 tabs(level, ps);
                 ps.println(p.getProfileKey() + ": \"" + p.getProfileValue() + "\"");
             }
-            else if (p.getProfileKey().equals("maxwalltime")) {
-                tabs(level, ps);
-                ps.println("maxWallTime: \"" + p.getProfileValue() + "\"");
+            else if (p.getProfileKey().equalsIgnoreCase("maxwalltime")) {
+                writeValue(level, prefix + "maxWallTime", p.getProfileValue(), ps);
             }
-            else if (p.getProfileKey().equals("queue")) {
+            else if (p.getProfileKey().equalsIgnoreCase("queue")) {
                 if (!hasCoasterService) {
-                    tabs(level, ps);
-                    ps.println("jobQueue: \"" + p.getProfileValue() + "\"");
+                    writeValue(level, prefix + "jobQueue", p.getProfileValue(), ps);
                 }
             }
-            else if (p.getProfileKey().equals("project")) {
+            else if (p.getProfileKey().equalsIgnoreCase("project")) {
                 if (!hasCoasterService) {
                     tabs(level, ps);
-                    ps.println("jobProject: \"" + p.getProfileValue() + "\"");
+                    writeValue(level, prefix + "jobProject", p.getProfileValue(), ps);
                 }
             }
             else {
@@ -277,22 +321,22 @@
 
     private void generateSiteAttributes(Map<String, Object> properties, PrintStream ps) {
         if (properties.containsKey("sysinfo")) {
-            ps.println("\tOS: \"" + properties.get("sysinfo") + "\"");
+            writeValue(1, "site.*.OS", properties.get("sysinfo"), ps);
         }
-        if (properties.containsKey("delayBase")) {
-            ps.println("\tdelayBase: " + properties.get("delayBase"));
+        if (properties.containsKey("delaybase")) {
+            writeValue(1, "site.*.delayBase", properties.get("delaybase"), ps);
         }
-        if (properties.containsKey("initialScore")) {
+        if (properties.containsKey("initialscore")) {
             double jobThrottle = 2;
-            if (properties.containsKey("jobThrottle")) {
-                jobThrottle = TypeUtil.toDouble(properties.get("jobThrottle"));
+            if (properties.containsKey("jobthrottle")) {
+                jobThrottle = TypeUtil.toDouble(properties.get("jobthrottle"));
             }
-            double initialScore = TypeUtil.toDouble(properties.get("initialScore"));
-            ps.println("\tmaxParallelTasks: " + (int) (jobThrottle * WeightedHost.T + 1));
-            ps.println("\tinitialParallelTasks: " + (int) (jobThrottle * WeightedHost.computeTScore(initialScore) + 1));
+            double initialScore = TypeUtil.toDouble(properties.get("initialscore"));
+            writeValue(1, "site.*.maxParallelTasks", (int) (jobThrottle * WeightedHost.T + 1), ps);
+            writeValue(1, "site.*.initialParallelTasks", (int) (jobThrottle * WeightedHost.computeTScore(initialScore) + 1), ps);
         }
-        if (properties.containsKey("maxSubmitRate")) {
-            ps.println("\tmaxSubmitRate: " + properties.get("maxSubmitRate"));
+        if (properties.containsKey("maxsubmitrate")) {
+            writeValue(1, "site.*.maxSubmitRate", properties.get("maxubmitrate"), ps);
         }
     }
 
@@ -348,11 +392,11 @@
         attr(coasterAttrs, "workerManager", AttrType.STRING);
         attr(coasterAttrs, "softImage", AttrType.STRING);
         attr(coasterAttrs, "jobsPerNode", "tasksPerNode", AttrType.INT);
+        attr(coasterAttrs, "ppn", "jobOptions.ppn", AttrType.INT);
         
         serviceAttrs = new HashMap<String, Attr>();
         attr(serviceAttrs, "queue", "jobQueue", AttrType.STRING);
         attr(serviceAttrs, "project", "jobProject", AttrType.STRING);
-        attr(serviceAttrs, "maxtime", "jobMaxTime", AttrType.STRING);
         attr(serviceAttrs, "jobType", "jobType", AttrType.STRING);
                 
         props = new HashMap<String, Attr>();
@@ -414,20 +458,47 @@
     }
 
     private void generateCoasterServiceAttributes(BoundContact bc, PrintStream ps) {
+        ps.println("\t\toptions {");
         for (String attr : bc.getProperties().keySet()) {
             Attr a = coasterAttrs.get(attr.toLowerCase());
             if (a != null) {
-                ps.print("\t\t" + a.name + ": ");
+                ps.print("\t\t\t" + a.name + ": ");
                 printValue(a.type, bc.getProperty(attr), ps);
             }
+            else if (attr.equalsIgnoreCase("globus:providerAttributes")) {
+                providerAttributes((String) bc.getProperty(attr), ps);
+            }
+            else if (attr.equalsIgnoreCase("globus:maxWallTime")) {
+                // handled somewhere else
+            }
             else {
-                if (attr.startsWith("globus.")) {
-                    throw new RuntimeException("Unrecognize profile: '" + attr + "'");
+                if (attr.startsWith("globus:")) {
+                    ps.println("\t\t\t# Option ignored: " + attr + " = " + bc.getProperty(attr));
                 }
             }
         }
+        ps.println("\t\t}");
     }
     
+    private void providerAttributes(String val, PrintStream ps) {
+        ps.println("\t\t\tjobOptions {");
+        String[] tokens = val.split("[;\n]");
+        for (String token : tokens) {
+            token = token.trim();
+            if (token.length() > 0) {
+                String[] t2 = token.split("=", 2);
+                if (t2.length == 1) {
+                    ps.println("\t\t\t\t" + t2[0] + ": true");
+                }
+                else {
+                    ps.println("\t\t\t\t" + t2[0] + ": \"" + t2[1] + "\"");
+                }
+            }
+        }
+        
+        ps.println("\t\t\t}");
+    }
+
     private void printValue(AttrType type, Object value, PrintStream ps) {
         switch (type) {
             case INT:
@@ -672,10 +743,10 @@
             throw new IllegalArgumentException("No value for profile " + ns + ":" + key);
         }
         if (ns.equals("karajan")) {
-            bc.setProperty(key, value);
+            bc.setProperty(key.toLowerCase(), value);
         }
         else {
-            bc.setProperty(ns + ":" + key, value);
+            bc.setProperty(ns + ":" + key.toLowerCase(), value);
         }
     }
 

Modified: trunk/src/org/griphyn/vdl/util/SwiftConfig.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/SwiftConfig.java	2014-07-12 03:47:24 UTC (rev 7987)
+++ trunk/src/org/griphyn/vdl/util/SwiftConfig.java	2014-07-12 03:48:39 UTC (rev 7988)
@@ -49,6 +49,8 @@
     public static final Logger logger = Logger.getLogger(SwiftConfig.class);
     
     public static final boolean CHECK_DYNAMIC_NAMES = true;
+    public static final boolean BUILD_CHECK = true;
+    
     public static final List<String> DEFAULT_LOCATIONS;
     
     public enum Key {
@@ -85,9 +87,9 @@
         }
         String swiftHome = System.getProperty("swift.home");
         if (swiftHome == null) {
-            swiftHome = System.getenv("SWIFT_HOME");
+            swiftHome = System.getProperty("swift.home");
             if (swiftHome == null) {
-                throw new IllegalStateException("SWIFT_HOME is not set");
+                throw new IllegalStateException("swift.home is not set");
             }
         }
         
@@ -248,6 +250,9 @@
     private void build(ConfigTree<Object> tree) {
         this.tree = tree;
         List<String> sites = null;
+        if (BUILD_CHECK) {
+            checkKey("sites");
+        }
         for (Map.Entry<String, ConfigTree.Node<Object>> e : tree.entrySet()) {
             if (e.getKey().equals("site")) {
                 for (Map.Entry<String, ConfigTree.Node<Object>> f : e.getValue().entrySet()) {
@@ -278,6 +283,17 @@
         }
     }
 
+    /**
+     * Checks if a key is present in the schema. This is used when building
+     * a config from a file to prevent looking for keys that are not allowed
+     * by the schema.
+     */
+    private void checkKey(String key) {
+        if (!SCHEMA.isNameValid(key)) {
+            throw new IllegalArgumentException("No such property in schema: " + key);
+        }
+    }
+
     private void apps(SwiftContact sc, ConfigTree.Node<Object> n) {
         /*
          * app."*" {
@@ -350,6 +366,13 @@
         Application app = new Application();
         app.setName(name);
         
+        if (BUILD_CHECK) {
+            checkKey("app.*.executable");
+            checkKey("app.*.options");
+            checkKey("app.*.env");
+            checkKey("app.*.options.jobProject");
+            checkKey("app.*.options.jobQueue");
+        }
         for (Map.Entry<String, ConfigTree.Node<Object>> e : n.entrySet()) {
             String k = e.getKey();
             ConfigTree.Node<Object> c = e.getValue();
@@ -358,18 +381,19 @@
                 app.setExecutable(getString(c));
             }
             else if (k.equals("options")) {
-                @SuppressWarnings("unchecked")
-                Map<String, Object> opt = (Map<String, Object>) getObject(c, "options");
-                for (Map.Entry<String, Object> f : opt.entrySet()) {
-                    app.addProperty(f.getKey(), f.getValue());
+                
+                for (String key : c.getLeafPaths()) {
+                    if (key.equals("jobProject")) {
+                        app.addProperty("project", c.get(key));
+                    }
+                    else if (key.equals("jobQueue")) {
+                        app.addProperty("queue", c.get(key));
+                    }
+                    else {
+                        app.addProperty(key, c.get(key));
+                    }
                 }
             }
-            else if (k.equals("jobQueue")) {
-                app.addProperty("queue", getString(c));
-            }
-            else if (k.equals("jobProject")) {
-                app.addProperty("project", getString(c));
-            }
             else if (k.equals("env")) {
                 List<KVPair> envs = envs(c);
                 for (KVPair env : envs) {
@@ -397,10 +421,19 @@
         try {
             SwiftContact sc = new SwiftContact(name);
     
+            if (BUILD_CHECK) {
+                checkKey("site.*.OS");
+                checkKey("site.*.execution");
+                checkKey("site.*.filesystem");
+                checkKey("site.*.workDirectory");
+                checkKey("site.*.scratch");
+                checkKey("site.*.app");
+                checkKey("site.*.staging");
+            }
+            
             if (n.hasKey("OS")) {
                 sc.setProperty("sysinfo", getString(n, "OS"));
-            }
-                    
+            }        
             
             for (Map.Entry<String, ConfigTree.Node<Object>> e : n.entrySet()) {
                 String ctype = e.getKey();
@@ -422,34 +455,8 @@
                     apps(sc, c);
                 }
                 else if (ctype.equals("staging")) {
-                    String staging = getString(c);
-                    if (staging.equals("swift") || staging.equals("wrapper")) {
-                        sc.setProperty("staging", staging);
-                    }
-                    else if (staging.equals("local")) {
-                        sc.setProperty("staging", "provider");
-                        sc.setProperty("stagingMethod", "file");
-                    }
-                    else if (staging.equals("service-local")) {
-                        sc.setProperty("staging", "provider");
-                        sc.setProperty("stagingMethod", "file");
-                    }
-                    else if (staging.equals("proxy")) {
-                        sc.setProperty("staging", "provider");
-                        sc.setProperty("stagingMethod", "proxy");
-                    }
-                    else if (staging.equals("shared-fs")) {
-                        sc.setProperty("staging", "provider");
-                        sc.setProperty("stagingMethod", "sfs");
-                    }
+                    staging(sc, c);
                 }
-                else if (ctype.equals("options")) {
-                    @SuppressWarnings("unchecked")
-                    Map<String, Object> opt = (Map<String, Object>) getObject(c, "options");
-                    for (Map.Entry<String, Object> f : opt.entrySet()) {
-                        sc.setProperty(f.getKey(), f.getValue());
-                    }
-                }
                 else {
                     sc.setProperty(ctype, getObject(c));
                 }
@@ -461,22 +468,99 @@
         }
     }
     
+    private void staging(SwiftContact sc, Node<Object> n) {
+        String staging = getString(n);
+        if (BUILD_CHECK) {
+            checkValue("site.*.staging", 
+                "swift", "wrapper", "local", "service-local", "proxy", "shared-fs");
+        }
+        if (staging.equals("swift") || staging.equals("wrapper")) {
+            sc.setProperty("staging", staging);
+        }
+        else if (staging.equals("local")) {
+            sc.setProperty("staging", "provider");
+            sc.setProperty("stagingMethod", "file");
+        }
+        else if (staging.equals("service-local")) {
+            sc.setProperty("staging", "provider");
+            sc.setProperty("stagingMethod", "file");
+        }
+        else if (staging.equals("proxy")) {
+            sc.setProperty("staging", "provider");
+            sc.setProperty("stagingMethod", "proxy");
+        }
+        else if (staging.equals("shared-fs")) {
+            sc.setProperty("staging", "provider");
+            sc.setProperty("stagingMethod", "sfs");
+        }
+    }
+
+    private void checkValue(String key, String... values) {
+        SwiftConfigSchema.Info i = SCHEMA.getInfo(key);
+        if (i == null) {
+            throw new IllegalArgumentException("No type information found for: " + key);
+        }
+        for (String v : values) {
+            i.type.check(key, v, i.loc);
+        }
+    }
+
     private Service filesystem(Node<Object> c) throws InvalidProviderException, ProviderMethodException {        
         Service s = new ServiceImpl();
         s.setType(Service.FILE_OPERATION);
-        service(c, s);
+        fileService(c, s);
         return s;
     }
+    
+    private void fileService(Node<Object> n, Service s) throws InvalidProviderException, ProviderMethodException {
+        String provider = null;
+        String url = null;
+        if (BUILD_CHECK) {
+            checkKey("site.*.filesystem.type");
+            checkKey("site.*.filesystem.URL");
+            checkKey("site.*.filesystem.options");
+        }
+        for (Map.Entry<String, ConfigTree.Node<Object>> e : n.entrySet()) {
+            String k = e.getKey();
+            ConfigTree.Node<Object> c = e.getValue();
+            
+            if (k.equals("type")) {
+                provider = getString(c);
+            }
+            else if (k.equals("URL")) {
+                url = getString(c);
+            }
+            else if (k.equals("options")) {
+                for (Map.Entry<String, ConfigTree.Node<Object>> f : e.getValue().entrySet()) {
+                    s.setAttribute(f.getKey(), getObject(f.getValue()));
+                }
+            }
+        }
+        
+        s.setProvider(provider);
+        if (url != null) {
+            ServiceContact contact = new ServiceContactImpl(url);
+            s.setServiceContact(contact);
+            s.setSecurityContext(AbstractionFactory.newSecurityContext(provider, contact));
+        }
+    }
 
+
     private Service execution(ConfigTree.Node<Object> n) throws InvalidProviderException, ProviderMethodException {
         ExecutionService s = new ExecutionServiceImpl();
-        service(n, s);                        
+        execService(n, s);
         return s;
     }
 
-    private void service(Node<Object> n, Service s) throws InvalidProviderException, ProviderMethodException {
+    private void execService(Node<Object> n, Service s) throws InvalidProviderException, ProviderMethodException {
         String provider = null;
         String url = null;
+        if (BUILD_CHECK) {
+            checkKey("site.*.execution.type");
+            checkKey("site.*.execution.URL");
+            checkKey("site.*.execution.jobManager");
+            checkKey("site.*.execution.options");
+        }
         for (Map.Entry<String, ConfigTree.Node<Object>> e : n.entrySet()) {
             String k = e.getKey();
             ConfigTree.Node<Object> c = e.getValue();
@@ -490,7 +574,36 @@
             else if (k.equals("jobManager")) {
                 ((ExecutionService) s).setJobManager(getString(c));
             }
-            else if (k.equals("jobProject")) {
+            else if (k.equals("options")) {
+                execOptions((ExecutionService) s, c);
+            }
+            
+        }
+        
+        s.setProvider(provider);
+        if (url != null) {
+            ServiceContact contact = new ServiceContactImpl(url);
+            s.setServiceContact(contact);
+            s.setSecurityContext(AbstractionFactory.newSecurityContext(provider, contact));
+        }
+    }
+
+    private void execOptions(ExecutionService s, Node<Object> n) {
+        if (BUILD_CHECK) {
+            checkKey("site.*.execution.options.jobProject");
+            checkKey("site.*.execution.options.maxJobs");
+            checkKey("site.*.execution.options.maxJobTime");
+            checkKey("site.*.execution.options.maxNodesPerJob");
+            checkKey("site.*.execution.options.jobQueue");
+            checkKey("site.*.execution.options.jobOptions");
+        }
+        
+        for (Map.Entry<String, ConfigTree.Node<Object>> e : n.entrySet()) {
+            String k = e.getKey();
+            ConfigTree.Node<Object> c = e.getValue();
+            
+            
+            if (k.equals("jobProject")) {
                 s.setAttribute("project", getObject(c));
             }
             else if (k.equals("maxJobs")) {
@@ -505,17 +618,18 @@
             else if (k.equals("jobQueue")) {
                 s.setAttribute("queue", getObject(c));
             }
+            else if (k.equals("tasksPerNode")) {
+                s.setAttribute("jobsPerNode", getObject(c));
+            }
+            else if (k.equals("jobOptions")) {
+                for (String key : c.getLeafPaths()) {
+                    s.setAttribute(key, c.get(key));
+                }
+            }
             else {
                 s.setAttribute(k, getObject(c));
             }
         }
-        
-        s.setProvider(provider);
-        if (url != null) {
-            ServiceContact contact = new ServiceContactImpl(url);
-            s.setServiceContact(contact);
-            s.setSecurityContext(AbstractionFactory.newSecurityContext(provider, contact));
-        }
     }
 
     private String getString(Node<Object> c) {

Modified: trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java	2014-07-12 03:47:24 UTC (rev 7987)
+++ trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java	2014-07-12 03:48:39 UTC (rev 7988)
@@ -22,7 +22,7 @@
 import com.typesafe.config.ConfigValue;
 
 public class SwiftConfigSchema {
-    private static final String STAR = "\"*\"";
+    private static final String STAR = "*";
     
     public static class Info {
         public ConfigPropertyType<?> type;
@@ -30,6 +30,10 @@
         public boolean optional;
         public String doc;
         public ConfigOrigin loc;
+        
+        public String toString() {
+            return String.valueOf(type);
+        }
     }
     
     private Config schema;
@@ -47,13 +51,14 @@
         info = new ConfigTree<Info>();
         for (Map.Entry<String, ConfigValue> e : schema.entrySet()) {
             String k = e.getKey();
+            String nk = k.replace("\"*\"", "*");
             String type = null;
             Object defaultValue = null;
             String doc = null;
             ConfigOrigin loc = null;
             if (k.endsWith(".\"_type\"")) {
                 type = schema.getString(k);
-                k = k.substring(0, k.lastIndexOf('.'));
+                nk = nk.substring(0, nk.lastIndexOf('.'));
                 loc = e.getValue().origin();
             }
             else if (k.indexOf(".\"_") == -1){
@@ -62,20 +67,20 @@
             }
             else if (k.endsWith(".\"_default\"")){
                 defaultValue = e.getValue().unwrapped();
-                k = k.substring(0, k.lastIndexOf('.'));
+                nk = nk.substring(0, nk.lastIndexOf('.'));
             }
             else if (k.endsWith(".\"_doc\"")){
                 doc = stripDoc((String) e.getValue().unwrapped());
-                k = k.substring(0, k.lastIndexOf('.'));
+                nk = nk.substring(0, nk.lastIndexOf('.'));
             }
             else if (k.indexOf(".\"_") != -1) {
                 continue;
             }
-            Info i = info.get(k);
+            Info i = info.get(nk);
             if (i == null) {
                 i = new Info();
-                info.put(k, i);
-                validNames.add(k);
+                info.put(nk, i);
+                setValid(nk);
             }
             if (type != null) {
                 if (type.startsWith("?")) {
@@ -96,6 +101,13 @@
         }
     }
 
+    private void setValid(String k) {
+        validNames.add(k);
+        if (!k.isEmpty()) {
+            setValid(parent(k));
+        }
+    }
+
     private String stripDoc(String doc) {
         return doc.replaceAll("[\\t\\n]+", " ");
     }
@@ -315,4 +327,8 @@
     public Collection<String> listProperties() {
         return validNames;
     }
+
+    public Info getInfo(String key) {
+        return info.get(key);
+    }
 }




More information about the Swift-commit mailing list