[Swift-commit] r7985 - in trunk/src/org: globus/swift/data griphyn/vdl/karajan griphyn/vdl/util
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Thu Jul 10 19:47:15 CDT 2014
Author: hategan
Date: 2014-07-10 19:47:15 -0500 (Thu, 10 Jul 2014)
New Revision: 7985
Modified:
trunk/src/org/globus/swift/data/Director.java
trunk/src/org/griphyn/vdl/karajan/Loader.java
trunk/src/org/griphyn/vdl/util/ConfigPropertyType.java
trunk/src/org/griphyn/vdl/util/ConfigTree.java
trunk/src/org/griphyn/vdl/util/SwiftConfig.java
trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java
Log:
a few fixes and updates to the config stuff
Modified: trunk/src/org/globus/swift/data/Director.java
===================================================================
--- trunk/src/org/globus/swift/data/Director.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/globus/swift/data/Director.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -114,8 +114,8 @@
static void init(SwiftConfig config) throws IOException
{
- broadcastMode = config.getStringProperty("cdm.broadcast.mode");
- logfile = config.getStringProperty("logfile");
+ broadcastMode = config.getCDMBroadcastMode();
+ logfile = config.getCDMLogFile();
if (broadcastMode.equals("file"))
broadcasted.put("LOCAL_FILE", new HashSet<String>());
Modified: trunk/src/org/griphyn/vdl/karajan/Loader.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/Loader.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/griphyn/vdl/karajan/Loader.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -99,6 +99,7 @@
static {
CMD_LINE_OPTIONS = new ArrayList<String>();
+ CMD_LINE_OPTIONS.add("sites");
CMD_LINE_OPTIONS.add("hostName");
CMD_LINE_OPTIONS.add("TCPPortRange");
CMD_LINE_OPTIONS.add("lazyErrors");
@@ -657,9 +658,15 @@
"string", ArgumentParser.OPTIONAL);
Map<String, SwiftConfigSchema.Info> desc = SwiftConfig.SCHEMA.getPropertyDescriptions();
- for (Map.Entry<String, SwiftConfigSchema.Info> e : desc.entrySet()) {
- SwiftConfigSchema.Info pi = e.getValue();
- ap.addOption(e.getKey(), pi.doc, pi.type.toString(),
+ for (String opt : CMD_LINE_OPTIONS) {
+ if (!SwiftConfig.SCHEMA.isNameValid(opt)) {
+ throw new RuntimeException("Invalid property: " + opt);
+ }
+ SwiftConfigSchema.Info pi = desc.get(opt);
+ if (pi == null) {
+ throw new RuntimeException("No info for property '" + opt + "'");
+ }
+ ap.addOption(opt, pi.doc, pi.type.toString(),
ArgumentParser.OPTIONAL);
}
return ap;
Modified: trunk/src/org/griphyn/vdl/util/ConfigPropertyType.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/ConfigPropertyType.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/griphyn/vdl/util/ConfigPropertyType.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -21,6 +21,8 @@
import org.globus.swift.catalog.types.Arch;
import org.globus.swift.catalog.types.Os;
+import com.typesafe.config.ConfigOrigin;
+
public abstract class ConfigPropertyType<T> {
public static final ConfigPropertyType<Boolean> BOOLEAN = new CPTBoolean();
public static final ConfigPropertyType<String> STRING = new CPTString();
@@ -42,11 +44,11 @@
}
@SuppressWarnings("unchecked")
- public Object check(String propName, Object value, String source) {
- return checkValue(propName, (T) value, source);
+ public Object check(String propName, Object value, ConfigOrigin loc) {
+ return checkValue(propName, (T) value, loc);
}
- public abstract Object checkValue(String propName, T value, String source);
+ public abstract Object checkValue(String propName, T value, ConfigOrigin loc);
public abstract ConfigPropertyType<?> getBaseType();
@@ -75,9 +77,9 @@
}
@Override
- public Object checkValue(String propName, String value, String source) {
+ public Object checkValue(String propName, String value, ConfigOrigin loc) {
if (!choices.contains(value)) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Valid values are: " + pp(choices));
}
return value;
@@ -108,7 +110,7 @@
private static class CPTString extends ConfigPropertyType<String> {
@Override
- public Object checkValue(String propName, String value, String source) {
+ public Object checkValue(String propName, String value, ConfigOrigin loc) {
// all values accepted
return value;
}
@@ -126,7 +128,7 @@
private static class Int extends ConfigPropertyType<Integer> {
@Override
- public Object checkValue(String propName, Integer value, String source) {
+ public Object checkValue(String propName, Integer value, ConfigOrigin loc) {
return value;
}
@@ -143,7 +145,7 @@
private static class CPTBoolean extends ConfigPropertyType<Boolean> {
@Override
- public Object checkValue(String propName, Boolean value, String source) {
+ public Object checkValue(String propName, Boolean value, ConfigOrigin loc) {
return value;
}
@@ -160,9 +162,9 @@
private static class SPInt extends ConfigPropertyType<Integer> {
@Override
- public Object checkValue(String propName, Integer value, String source) {
+ public Object checkValue(String propName, Integer value, ConfigOrigin loc) {
if (value <= 0) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
return value;
@@ -181,9 +183,9 @@
private static class PInt extends ConfigPropertyType<Integer> {
@Override
- public Object checkValue(String propName, Integer value, String source) {
+ public Object checkValue(String propName, Integer value, ConfigOrigin loc) {
if (value < 0) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
return value;
@@ -203,7 +205,7 @@
private static class Throttle extends ConfigPropertyType<Object> {
@Override
- public Object checkValue(String propName, Object value, String source) {
+ public Object checkValue(String propName, Object value, ConfigOrigin loc) {
if ("off".equals(value)) {
return Integer.MAX_VALUE;
}
@@ -213,7 +215,7 @@
return i;
}
}
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be an " + toString());
}
@@ -230,9 +232,9 @@
private static class PFloat extends ConfigPropertyType<Double> {
@Override
- public Object checkValue(String propName, Double value, String source) {
+ public Object checkValue(String propName, Double value, ConfigOrigin loc) {
if (value < 0) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
return value;
@@ -251,7 +253,7 @@
private static class CPTFloat extends ConfigPropertyType<Double> {
@Override
- public Object checkValue(String propName, Double value, String source) {
+ public Object checkValue(String propName, Double value, ConfigOrigin loc) {
return value;
}
@@ -270,9 +272,9 @@
}
@Override
- public Object checkValue(String propName, Double value, String source) {
+ public Object checkValue(String propName, Double value, ConfigOrigin loc) {
if (value < l || value > h) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
return value;
@@ -291,12 +293,12 @@
private static class CPTTime extends ConfigPropertyType<String> {
@Override
- public Object checkValue(String propName, String value, String source) {
+ public Object checkValue(String propName, String value, ConfigOrigin loc) {
try {
WallTime.timeToSeconds(value);
}
catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(source + ":\n\tInvalid time value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid time value '" + value + "' for property '" +
propName + "'. Mist be a " + toString());
}
return value;
@@ -315,7 +317,7 @@
private static class PortRange extends ConfigPropertyType<String> {
@Override
- public Object checkValue(String propName, String value, String source) {
+ public Object checkValue(String propName, String value, ConfigOrigin loc) {
String[] els = value.split(",\\s*");
if (els.length == 2) {
try {
@@ -326,7 +328,7 @@
catch (NumberFormatException e) {
}
}
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
@@ -343,10 +345,10 @@
private static class CPTFile extends ConfigPropertyType<String> {
@Override
- public Object checkValue(String propName, String value, String source) {
+ public Object checkValue(String propName, String value, ConfigOrigin loc) {
File f = new File(value);
if (!f.exists()) {
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. File does not exist.");
}
return value;
@@ -365,7 +367,7 @@
private static class CPTObject extends ConfigPropertyType<Object> {
@Override
- public Object checkValue(String propName, Object value, String source) {
+ public Object checkValue(String propName, Object value, ConfigOrigin loc) {
return value;
}
@@ -383,7 +385,7 @@
private static class StringList extends ConfigPropertyType<Object> {
@Override
- public Object checkValue(String propName, Object value, String source) {
+ public Object checkValue(String propName, Object value, ConfigOrigin loc) {
if (value instanceof List) {
List<?> l = (List<?>) value;
boolean allStrings = true;
@@ -400,7 +402,7 @@
// also allow comma separated strings in a string
return Arrays.asList(((String) value).split(",\\s*"));
}
- throw new IllegalArgumentException(source + ":\n\tInvalid value '" + value + "' for property '" +
+ throw new IllegalArgumentException(location(loc) + ":\n\tInvalid value '" + value + "' for property '" +
propName + "'. Must be a " + toString());
}
@@ -414,4 +416,8 @@
return "list of strings";
}
}
+
+ private static String location(ConfigOrigin loc) {
+ return loc.filename() + ":" + loc.lineNumber();
+ }
}
Modified: trunk/src/org/griphyn/vdl/util/ConfigTree.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/ConfigTree.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/griphyn/vdl/util/ConfigTree.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -119,9 +119,6 @@
}
public void getLeafPaths(List<String> l, String partial) {
- if (value != null) {
- l.add(partial);
- }
if (nodes != null) {
for (Map.Entry<String, Node<T>> e : nodes.entrySet()) {
if (partial == null) {
@@ -132,26 +129,19 @@
}
}
}
+ else {
+ l.add(partial);
+ }
}
public void expandWildcards(List<String> l, String k, String wildcard, String partial) {
- if (value != null) {
- if (partial == null) {
- l.add(k);
+ if (nodes == null || nodes.isEmpty()) {
+ if (k.isEmpty()) {
+ l.add(partial);
}
else {
- l.add(partial + "." + k);
+ throw new IllegalArgumentException("No such path: " + partial + "." + k);
}
- }
- if (nodes == null || nodes.isEmpty()) {
- if (rest(k).isEmpty()) {
- if (partial == null) {
- l.add(k);
- }
- else {
- l.add(partial + "." + k);
- }
- }
return;
}
String mk = first(k);
@@ -176,7 +166,7 @@
// x.* is allowed to not be there
return;
}
- if (partial == null) {
+ if (partial == null || k.equals("")) {
l.add(k);
}
else {
Modified: trunk/src/org/griphyn/vdl/util/SwiftConfig.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/SwiftConfig.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/griphyn/vdl/util/SwiftConfig.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -65,7 +65,9 @@
WRAPPER_STAGING_LOCAL_SERVER("wrapperStagingLocalServer"),
REPLICATION_MIN_QUEUE_TIME("replicationMinQueueTime"),
REPLICATION_LIMIT("replicationLimit"),
- WRAPPER_INVOCATION_MODE("wrapperInvocationMode");
+ WRAPPER_INVOCATION_MODE("wrapperInvocationMode"),
+ CDM_BROADCAST_MODE("CDMBroadcastMode"),
+ CMD_LOG_FILE("CDMLogFile");
public String propName;
private Key(String propName) {
@@ -419,6 +421,28 @@
else if (ctype.equals("app")) {
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");
+ }
+ }
else if (ctype.equals("options")) {
@SuppressWarnings("unchecked")
Map<String, Object> opt = (Map<String, Object>) getObject(c, "options");
@@ -629,4 +653,12 @@
public boolean isMappingCheckerEnabled() {
return (Boolean) get(Key.DM_CHECKER);
}
+
+ public String getCDMBroadcastMode() {
+ return (String) get(Key.CDM_BROADCAST_MODE);
+ }
+
+ public String getCDMLogFile() {
+ return (String) get(Key.CMD_LOG_FILE);
+ }
}
Modified: trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java
===================================================================
--- trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java 2014-07-11 00:46:15 UTC (rev 7984)
+++ trunk/src/org/griphyn/vdl/util/SwiftConfigSchema.java 2014-07-11 00:47:15 UTC (rev 7985)
@@ -97,7 +97,7 @@
}
private String stripDoc(String doc) {
- return doc.replaceAll("[\\t\\n]+", "");
+ return doc.replaceAll("[\\t\\n]+", " ");
}
private ConfigPropertyType<?> getTypeInstance(String type, ConfigValue value) {
@@ -192,8 +192,7 @@
if (notFound != null) {
findMissing(key, confTree, i, validated);
ConfigOrigin loc = info.get(key).loc;
- throw new SwiftConfigException(conf.origin(), "missing property '" + notFound +
- "' defined in " + loc.filename() + ":" + loc.lineNumber());
+ throw new SwiftConfigException(conf.origin(), "missing mandatory property '" + notFound + "'");
}
}
return validated;
@@ -201,6 +200,7 @@
private String findMissing(String key, ConfigTree<Boolean> confTree, Info i, ConfigTree<Object> validated) {
List<String> found = confTree.expandWildcards(key, STAR);
+
for (String f : found) {
if (!confTree.hasKey(f)) {
if (i.optional) {
@@ -208,7 +208,7 @@
validated.put(f, i.value);
}
}
- else {
+ else if (!parentsAreOptional(key, confTree)) {
return f;
}
}
@@ -216,6 +216,27 @@
return null;
}
+ private boolean parentsAreOptional(String k, ConfigTree<Boolean> confTree) {
+ while (!k.isEmpty()) {
+ k = parent(k);
+ Info i = info.get(k);
+ if (i != null && !i.optional && !confTree.hasKey(k)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private String parent(String k) {
+ int ix = k.lastIndexOf('.');
+ if (ix == -1) {
+ return "";
+ }
+ else {
+ return k.substring(0, ix);
+ }
+ }
+
private void setValue(Map<String, Object> validated, Config conf, String k) {
if (!conf.hasPath(k)) {
String defKey = k + ".\"_default\"";
@@ -235,7 +256,7 @@
if (t.getBaseType() != ConfigPropertyType.STRING && t.getBaseType() != ConfigPropertyType.OBJECT) {
throw invalidValue(value, k, v, t.getBaseType());
}
- return t.check(k, value.unwrapped(), null);
+ return t.check(k, value.unwrapped(), value.origin());
case NUMBER:
if (t.getBaseType() != ConfigPropertyType.INT && t.getBaseType() != ConfigPropertyType.FLOAT) {
throw invalidValue(value, k, v, t.getBaseType());
@@ -253,12 +274,21 @@
}
return value.unwrapped();
default:
- return t.check(k, v, null);
+ return t.check(k, v, value.origin());
}
}
private SwiftConfigException invalidValue(ConfigValue value, String k, Object v, ConfigPropertyType<?> t) {
- return new SwiftConfigException(value.origin(), "invalid value '" + v + "' for property '" + k + "'. Expected a " + t);
+ switch (t.toString().charAt(0)) {
+ case 'a':
+ case 'e':
+ case 'i':
+ case 'o':
+ case 'u':
+ return new SwiftConfigException(value.origin(), "invalid value '" + v + "' for property '" + k + "'. Expected an " + t);
+ default:
+ return new SwiftConfigException(value.origin(), "invalid value '" + v + "' for property '" + k + "'. Expected a " + t);
+ }
}
public synchronized Map<String, Info> getPropertyDescriptions() {
More information about the Swift-commit
mailing list