public static String getPath(ConfigElement element, String... umbrellaElements) { return getPath(element, false, umbrellaElements); }
protected String getPath(ConfigElement option, String... umbrellaElements) { verifyElement(option); return ConfigElement.getPath(option,umbrellaElements); }
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; }
@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; }
protected Map<String,Object> getSubset(ReadConfiguration config, ConfigNamespace umbrella, String... umbrellaElements) { verifyElement(umbrella); String prefix = umbrella.isRoot() ? "" : ConfigElement.getPath(umbrella, umbrellaElements); Map<String,Object> result = Maps.newHashMap(); for (String key : config.getKeys(prefix)) { Preconditions.checkArgument(key.startsWith(prefix)); // A zero-length prefix is a root. A positive-length prefix // is not a root and we should tack on an additional character // to consume the dot between the prefix and the rest of the key. int startIndex = umbrella.isRoot() ? prefix.length() : prefix.length() + 1; String sub = key.substring(startIndex).trim(); if (!sub.isEmpty()) { result.put(sub,config.get(key,Object.class)); } } return result; }
private <A> void setIllegalGraphOption(ConfigOption<A> opt, ConfigOption.Type requiredType, A attemptedValue) { // Sanity check: make sure the Type of the configuration option is what we expect final ConfigOption.Type type = opt.getType(); Preconditions.checkState(type.equals(requiredType)); Preconditions.checkArgument(requiredType.equals(ConfigOption.Type.LOCAL) || requiredType.equals(ConfigOption.Type.FIXED)); // Get full string path of config option final String path = ConfigElement.getPath(opt); // Try to read the option try { mgmt.get(path); } catch (Throwable t) { log.debug("Caught expected exception", t); } // Try to modify the option try { mgmt.set(path, attemptedValue); mgmt.commit(); fail("Option " + path + " with type " + type + " should not be modifiable in the persistent graph config"); } catch (Throwable t) { log.debug("Caught expected exception", t); } }
public void clopen(Object... settings) { config = getConfiguration(); if (mgmt!=null && mgmt.isOpen()) mgmt.rollback(); if (null != tx && tx.isOpen()) tx.commit(); if (settings!=null && settings.length>0) { final Map<TestConfigOption,Object> options = validateConfigOptions(settings); JanusGraphManagement janusGraphManagement = null; final ModifiableConfiguration modifiableConfiguration = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,config, BasicConfiguration.Restriction.LOCAL); for (final Map.Entry<TestConfigOption,Object> option : options.entrySet()) { if (option.getKey().option.isLocal()) { modifiableConfiguration.set(option.getKey().option,option.getValue(),option.getKey().umbrella); } else { if (janusGraphManagement==null) janusGraphManagement = graph.openManagement(); janusGraphManagement.set(ConfigElement.getPath(option.getKey().option,option.getKey().umbrella),option.getValue()); } } if (janusGraphManagement!=null) janusGraphManagement.commit(); modifiableConfiguration.close(); } if (null != graph && null != graph.tx() && graph.tx().isOpen()) graph.tx().commit(); if (null != graph && graph.isOpen()) graph.close(); Preconditions.checkNotNull(config); open(config); }
wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); try { graph = (StandardJanusGraph) JanusGraphFactory.open(wc); } catch (JanusGraphConfigurationException e) { assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME))); wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); graph = (StandardJanusGraph) JanusGraphFactory.open(wc); wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), false); graph = (StandardJanusGraph) JanusGraphFactory.open(wc); close(); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); try { graph = (StandardJanusGraph) JanusGraphFactory.open(wc); } catch (JanusGraphConfigurationException e) { assertTrue(e.getMessage().contains(ConfigElement.getPath(MAX_COMMIT_TIME))); wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); graph = (StandardJanusGraph) JanusGraphFactory.open(wc);
throw new ExpiredLockException("Expired lock on " + kc.toString() + ": lock timestamp " + tr.getTimestamp() + " " + times.getUnit() + " is older than " + ConfigElement.getPath(GraphDatabaseConfiguration.LOCK_EXPIRE) + "=" + lockExpire);
final String path = ConfigElement.getPath(opt);
/** * Ensure clearing storage actually removes underlying database. * @throws Exception */ @Test public void testClearStorage() throws Exception { tearDown(); config.set(ConfigElement.getPath(GraphDatabaseConfiguration.DROP_ON_CLEAR), true); final Backend backend = getBackend(config, false); assertTrue("graph should exist before clearing storage", backend.getStoreManager().exists()); clearGraph(config); assertFalse("graph should not exist after clearing storage", backend.getStoreManager().exists()); }
/** * Ensure clearing storage actually removes underlying graph and index databases. * @throws Exception */ @Test public void testClearStorage() throws Exception { GraphOfTheGodsFactory.load(graph); tearDown(); config.set(ConfigElement.getPath(GraphDatabaseConfiguration.DROP_ON_CLEAR), true); final Backend backend = getBackend(config, false); assertStorageExists(backend, true); clearGraph(config); try { backend.close(); } catch (final Exception e) { /* Most backends do not support closing after clearing */} try (final Backend newBackend = getBackend(config, false)) { assertStorageExists(newBackend, false); } }
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() };
private static void copyIndexJobKeys(org.apache.hadoop.conf.Configuration hadoopConf, String indexName, String relationType) { hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(IndexUpdateJob.INDEX_NAME), indexName); hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(IndexUpdateJob.INDEX_RELATION_TYPE), relationType); hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(GraphDatabaseConfiguration.JOB_START_TIME), String.valueOf(System.currentTimeMillis())); }
private static void copyIndexJobKeys(org.apache.hadoop.conf.Configuration hadoopConf, String indexName, String relationType) { hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(IndexUpdateJob.INDEX_NAME), indexName); hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(IndexUpdateJob.INDEX_RELATION_TYPE), relationType); hadoopConf.set(ConfigElement.getPath(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_KEYS, true) + "." + ConfigElement.getPath(GraphDatabaseConfiguration.JOB_START_TIME), String.valueOf(System.currentTimeMillis())); }
private void checkConfigDeprecation(org.janusgraph.diskstorage.configuration.Configuration config) { if (config.has(GraphDatabaseConfiguration.STORAGE_PORT)) { logger.warn("The configuration property {} is ignored for HBase. Set hbase.zookeeper.property.clientPort in hbase-site.xml or {}.hbase.zookeeper.property.clientPort in JanusGraph's configuration file.", ConfigElement.getPath(GraphDatabaseConfiguration.STORAGE_PORT), ConfigElement.getPath(HBASE_CONFIGURATION_NAMESPACE)); } }
private static void copyPropertiesToInputAndOutputConf(Configuration sink, Properties source) { final String prefix = ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "."; for (Map.Entry<Object, Object> e : source.entrySet()) { String k; String v = e.getValue().toString(); k = prefix + e.getKey().toString(); sink.set(k, v); log.info("Set {}={}", k, v); } } }
private static void copyPropertiesToInputAndOutputConf(Configuration sink, Properties source) { final String prefix = ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "."; for (Map.Entry<Object, Object> e : source.entrySet()) { String k; String v = e.getValue().toString(); k = prefix + e.getKey().toString(); sink.set(k, v); log.info("Set {}={}", k, v); } } }
public static ModifiableConfiguration prefixView(ConfigNamespace newRoot, ConfigNamespace prefixRoot, ModifiableHadoopConfiguration mc) { HadoopConfiguration prefixConf = new HadoopConfiguration(mc.getHadoopConfiguration(), ConfigElement.getPath(prefixRoot, true) + "."); return new ModifiableConfiguration(newRoot, prefixConf, Restriction.NONE); }
public static ModifiableConfiguration prefixView(ConfigNamespace newRoot, ConfigNamespace prefixRoot, ModifiableHadoopConfiguration mc) { HadoopConfiguration prefixConf = new HadoopConfiguration(mc.getHadoopConfiguration(), ConfigElement.getPath(prefixRoot, true) + "."); return new ModifiableConfiguration(newRoot, prefixConf, Restriction.NONE); }