public static String getPath(ConfigElement element, String... umbrellaElements) { return getPath(element, false, umbrellaElements); }
public Map<ConfigElement.PathIdentifier,Object> getAll() { Map<ConfigElement.PathIdentifier,Object> result = Maps.newHashMap(); for (String key : config.getKeys("")) { Preconditions.checkArgument(StringUtils.isNotBlank(key)); try { final ConfigElement.PathIdentifier pid = ConfigElement.parse(getRootNamespace(),key); Preconditions.checkArgument(pid.element.isOption() && !pid.lastIsUmbrella); result.put(pid, get((ConfigOption) pid.element, pid.umbrellaElements)); } catch (IllegalArgumentException e) { log.debug("Ignored configuration entry for {} since it does not map to an option",key,e); } } return result; }
protected Set<String> getContainedNamespaces(ReadConfiguration config, ConfigNamespace umbrella, String... umbrellaElements) { verifyElement(umbrella); Preconditions.checkArgument(umbrella.isUmbrella()); String prefix = ConfigElement.getPath(umbrella,umbrellaElements); Set<String> result = Sets.newHashSet(); for (String key : config.getKeys(prefix)) { Preconditions.checkArgument(key.startsWith(prefix)); String sub = key.substring(prefix.length()+1).trim(); if (!sub.isEmpty()) { String ns = ConfigElement.getComponents(sub)[0]; Preconditions.checkArgument(StringUtils.isNotBlank(ns),"Invalid sub-namespace for key: %s",key); result.add(ns); } } return result; }
void registerChild(ConfigElement element) { Preconditions.checkNotNull(element); Preconditions.checkArgument(element.getNamespace()==this,"Configuration element registered with wrong namespace"); Preconditions.checkArgument(!children.containsKey(element.getName()), "A configuration element with the same name has already been added to this namespace: %s",element.getName()); children.put(element.getName(),element); }
private static void copyInputKeys(org.apache.hadoop.conf.Configuration hadoopConf, org.apache.commons.configuration.Configuration source) { // Copy IndexUpdateJob settings into the hadoop-backed cfg Iterator<String> iterator = source.getKeys(); while (iterator.hasNext()) { String key = iterator.next(); ConfigElement.PathIdentifier pid; try { pid = ConfigElement.parse(ROOT_NS, key); } catch (RuntimeException e) { log.debug("[inputkeys] Skipping {}", key, e); continue; } if (!pid.element.isOption()) continue; String k = ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + key; String v = source.getProperty(key).toString(); hadoopConf.set(k, v); log.debug("[inputkeys] Set {}={}", k, v); } }
for (Map.Entry<ConfigElement.PathIdentifier, Object> ent : getManagedSubset(localBasicConfiguration.getAll()).entrySet()) { ConfigElement.PathIdentifier pid = ent.getKey(); assert pid.element.isOption(); ConfigOption<?> opt = (ConfigOption<?>)pid.element; Object localValue = ent.getValue(); String fullOptionName = ConfigElement.getPath(pid.element, pid.umbrellaElements); String template = "Local setting {}={} (Type: {}) is overridden by globally managed value ({}). Use the {} interface instead of the local configuration to control this setting."; Object replacements[] = new Object[] { fullOptionName, localValue, opt.getType(), storeValue, ManagementSystem.class.getSimpleName() };
public boolean isNamespace() { return !isOption(); }
@Override public TransactionBuilder customOption(String k, Object v) { if (null == writableCustomOptions) throw new IllegalStateException("This builder was not constructed with setCustomOption support"); writableCustomOptions.set((ConfigOption<Object>)ConfigElement.parse(ROOT_NS, k).element, v); return this; }
@Override public String get(String path) { ConfigElement.PathIdentifier pp = ConfigElement.parse(config.getRootNamespace(),path); if (pp.element.isNamespace()) { ConfigNamespace ns = (ConfigNamespace)pp.element; StringBuilder s = new StringBuilder();
public static String getPath(ConfigElement element, boolean includeRoot, String... umbrellaElements) { Preconditions.checkNotNull(element); if (umbrellaElements==null) umbrellaElements = new String[0]; StringBuilder path = new StringBuilder(element.getName()); int umbrellaPos = umbrellaElements.length-1; while (!element.isRoot() && !element.getNamespace().isRoot()) { ConfigNamespace parent = element.getNamespace(); if (parent.isUmbrella()) { Preconditions.checkArgument(umbrellaPos>=0,"Missing umbrella element path for element: %s",element); String umbrellaName = umbrellaElements[umbrellaPos]; Preconditions.checkArgument(!StringUtils.containsAny(umbrellaName,ILLEGAL_CHARS),"Invalid umbrella name provided: %s. Contains illegal chars",umbrellaName); path.insert(0, umbrellaName + SEPARATOR); umbrellaPos--; } path.insert(0, parent.getName() + SEPARATOR); element = parent; } if (includeRoot) { // Assumes that roots are not umbrellas // If roots could be umbrellas, we might have to change the interpretation of umbrellaElements path.insert(0, (element.isRoot() ? element.getName() : element.getNamespace().getName()) + SEPARATOR); } //Don't make this check so that we can still access more general config items Preconditions.checkArgument(umbrellaPos<0,"Found unused umbrella element: %s",umbrellaPos<0?null:umbrellaElements[umbrellaPos]); return path.toString(); }
public static String toString(ConfigElement element) { String result = element.getName(); if (element.isNamespace()) { result = "+ " + result; if (((ConfigNamespace)element).isUmbrella()) result += " [*]"; } else { result = "- " + result; ConfigOption option = (ConfigOption)element; result+= " ["; switch (option.getType()) { case FIXED: result+="f"; break; case GLOBAL_OFFLINE: result+="g!"; break; case GLOBAL: result+="g"; break; case MASKABLE: result+="m"; break; case LOCAL: result+="l"; break; } result+=","+option.getDatatype().getSimpleName(); result+=","+option.getDefaultValue(); result+="]"; } result = result + "\n"; String desc = element.getDescription(); result+="\t"+'"'+desc.substring(0, Math.min(desc.length(), 50))+'"'; return result; }
public static PathIdentifier parse(ConfigNamespace root, String path) { Preconditions.checkNotNull(root); if (StringUtils.isBlank(path)) return new PathIdentifier(root,new String[]{},false); String[] components = getComponents(path); Preconditions.checkArgument(components.length>0,"Empty path provided: %s",path); List<String> umbrellaElements = Lists.newArrayList(); ConfigNamespace parent = root; ConfigElement last = root; boolean lastIsUmbrella = false; for (int i=0;i<components.length;i++) { if (parent.isUmbrella() && !lastIsUmbrella) { umbrellaElements.add(components[i]); lastIsUmbrella = true; } else { last = parent.getChild(components[i]); Preconditions.checkArgument(last!=null,"Unknown configuration element in namespace [%s]: %s",parent.toString(),components[i]); if (i+1<components.length) { Preconditions.checkArgument(last instanceof ConfigNamespace,"Expected namespace at position [%s] of [%s] but got: %s",i,path,last); parent = (ConfigNamespace)last; } lastIsUmbrella = false; } } return new PathIdentifier(last,umbrellaElements.toArray(new String[umbrellaElements.size()]), lastIsUmbrella); }
private static void copyInputKeys(org.apache.hadoop.conf.Configuration hadoopConf, org.apache.commons.configuration.Configuration source) { // Copy IndexUpdateJob settings into the hadoop-backed cfg Iterator<String> iterator = source.getKeys(); while (iterator.hasNext()) { String key = iterator.next(); ConfigElement.PathIdentifier pid; try { pid = ConfigElement.parse(ROOT_NS, key); } catch (RuntimeException e) { log.debug("[inputkeys] Skipping {}", key, e); continue; } if (!pid.element.isOption()) continue; String k = ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + key; String v = source.getProperty(key).toString(); hadoopConf.set(k, v); log.debug("[inputkeys] Set {}={}", k, v); } }
public void setAll(Map<ConfigElement.PathIdentifier,Object> options) { for (Map.Entry<ConfigElement.PathIdentifier,Object> entry : options.entrySet()) { Preconditions.checkArgument(entry.getKey().element.isOption()); set((ConfigOption) entry.getKey().element, entry.getValue(), entry.getKey().umbrellaElements); } }
m.group(3); try { ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, cfgKey); ConfigOption<?> opt = (ConfigOption<?>) pid.element;
protected String getPath(ConfigElement option, String... umbrellaElements) { verifyElement(option); return ConfigElement.getPath(option,umbrellaElements); }
@Override public UserModifiableConfiguration set(String path, Object value) { ConfigElement.PathIdentifier pp = ConfigElement.parse(config.getRootNamespace(),path); Preconditions.checkArgument(pp.element.isOption(),"Need to provide configuration option - not namespace: %s",path); ConfigOption option = (ConfigOption)pp.element; verifier.verifyModification(option); if (option.getDatatype().isArray()) { Class arrayType = option.getDatatype().getComponentType(); Object arr; if (value.getClass().isArray()) { int size = Array.getLength(value); arr = Array.newInstance(arrayType,size); for (int i=0;i<size;i++) { Array.set(arr,i,convertBasic(Array.get(value,i),arrayType)); } } else { arr = Array.newInstance(arrayType,1); Array.set(arr,0,convertBasic(value,arrayType)); } value = arr; } else { value = convertBasic(value,option.getDatatype()); } config.set(option,value,pp.umbrellaElements); return this; }
private static Map<ConfigElement.PathIdentifier, Object> getManagedSubset(Map<ConfigElement.PathIdentifier, Object> m) { return Maps.filterEntries(m, entry -> { assert entry.getKey().element.isOption(); return ((ConfigOption)entry.getKey().element).isManaged(); }); }
Map<String, Object> jobConfMap = conf.getSubset(confRoot); for (Map.Entry<String, Object> jobConfEntry : jobConfMap.entrySet()) { hadoopJobConf.set((ConfigOption) ConfigElement.parse(confRoot, jobConfEntry.getKey()).element, jobConfEntry.getValue());
@Override public Map<String, Object> getBaseConfiguration(String graphName, Class<?> test, String testMethodName, final LoadGraphWith.GraphData loadGraphWith) { ModifiableConfiguration conf = getJanusGraphConfiguration(graphName, test, testMethodName); conf.set(GraphDatabaseConfiguration.COMPUTER_RESULT_MODE, "persist"); conf.set(GraphDatabaseConfiguration.AUTO_TYPE, "tp3"); Map<String, Object> result = new HashMap<>(); conf.getAll().forEach( (key, value) -> result.put(ConfigElement.getPath(key.element, key.umbrellaElements), value)); result.put(Graph.GRAPH, JanusGraphFactory.class.getName()); return result; }