use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.
the class JanusGraphFactory method getLocalConfiguration.
/**
* Load a properties file containing a JanusGraph graph configuration.
* <p>
* <ol>
* <li>Load the file contents into a {@link org.apache.commons.configuration2.PropertiesConfiguration}</li>
* <li>For each key that points to a configuration object that is either a directory
* or local file, check
* whether the associated value is a non-null, non-absolute path. If so,
* then prepend the absolute path of the parent directory of the provided configuration {@code file}.
* This has the effect of making non-absolute backend
* paths relative to the config file's directory rather than the JVM's
* working directory.
* <li>Return the {@link ReadConfiguration} for the prepared configuration file</li>
* </ol>
* <p>
*
* @param file A properties file to load
* @return A configuration derived from {@code file}
*/
private static ReadConfiguration getLocalConfiguration(File file) {
Preconditions.checkNotNull(file);
Preconditions.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
try {
PropertiesConfiguration configuration = ConfigurationUtil.loadPropertiesConfig(file);
final File tmpParent = file.getParentFile();
final File configParent;
if (null == tmpParent) {
/*
* null usually means we were given a JanusGraph config file path
* string like "foo.properties" that refers to the current
* working directory of the process.
*/
configParent = new File(System.getProperty("user.dir"));
} else {
configParent = tmpParent;
}
Preconditions.checkNotNull(configParent);
Preconditions.checkArgument(configParent.isDirectory());
// TODO this mangling logic is a relic from the hardcoded string days; it should be deleted and rewritten as a setting on ConfigOption
final Pattern p = Pattern.compile("(" + Pattern.quote(STORAGE_NS.getName()) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY.getName()) + "|" + Pattern.quote(STORAGE_CONF_FILE.getName()) + ")" + "|" + Pattern.quote(INDEX_NS.getName()) + "\\..*" + "(" + Pattern.quote(INDEX_DIRECTORY.getName()) + "|" + Pattern.quote(INDEX_CONF_FILE.getName()) + ")" + ")");
final List<String> keysToMangle = StreamSupport.stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(), 0), false).filter(key -> null != key && p.matcher(key).matches()).collect(Collectors.toList());
for (String k : keysToMangle) {
Preconditions.checkNotNull(k);
final String s = configuration.getString(k);
Preconditions.checkArgument(StringUtils.isNotBlank(s), "Invalid Configuration: key %s has null empty value", k);
configuration.setProperty(k, getAbsolutePath(configParent, s));
}
return new CommonsConfiguration(configuration);
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Could not load configuration at: " + file, e);
}
}
use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.
the class JanusGraphFactory method open.
/**
* Opens a {@link JanusGraph} database configured according to the provided configuration.
* This method shouldn't be called by end users; it is used by internal server processes to
* open graphs defined at server start that do not include the graphname property.
*
* @param configuration Configuration for the graph database
* @param backupName Backup name for graph
* @return JanusGraph graph database
*/
public static JanusGraph open(ReadConfiguration configuration, String backupName) {
final ModifiableConfiguration config = new ModifiableConfiguration(ROOT_NS, (WriteConfiguration) configuration, BasicConfiguration.Restriction.NONE);
final String graphName = config.has(GRAPH_NAME) ? config.get(GRAPH_NAME) : backupName;
final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
if (null != graphName) {
Preconditions.checkNotNull(jgm, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
return (JanusGraph) jgm.openGraph(graphName, gName -> new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(configuration)));
} else {
if (jgm != null) {
log.warn("You should supply \"graph.graphname\" in your .properties file configuration if you are opening " + "a graph that has not already been opened at server start, i.e. it was " + "defined in your YAML file. This will ensure the graph is tracked by the JanusGraphManager, " + "which will enable autocommit and rollback functionality upon all gremlin script executions. " + "Note that JanusGraphFactory#open(String === shortcut notation) does not support consuming the property " + "\"graph.graphname\" so these graphs should be accessed dynamically by supplying a .properties file here " + "or by using the ConfiguredGraphFactory.");
}
return new StandardJanusGraph(new GraphDatabaseConfigurationBuilder().build(configuration));
}
}
use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.
the class ReadConfigurationBuilderTest method shouldBuildReadConfiguration.
@Test
public void shouldBuildReadConfiguration() {
when(storeManager.getFeatures()).thenReturn(features);
when(keyColumnValueStoreConfiguration.asReadConfiguration()).thenReturn(readConfiguration);
ReadConfiguration result = buildConfiguration();
assertEquals(readConfiguration, result);
}
use of org.janusgraph.diskstorage.configuration.ReadConfiguration in project janusgraph by JanusGraph.
the class GraphDatabaseConfigurationBuilder method build.
public GraphDatabaseConfiguration build(ReadConfiguration localConfig) {
Preconditions.checkNotNull(localConfig);
BasicConfiguration localBasicConfiguration = new BasicConfiguration(ROOT_NS, localConfig, BasicConfiguration.Restriction.NONE);
ModifiableConfiguration overwrite = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.NONE);
final KeyColumnValueStoreManager storeManager = Backend.getStorageManager(localBasicConfiguration);
final StoreFeatures storeFeatures = storeManager.getFeatures();
final ReadConfiguration globalConfig = new ReadConfigurationBuilder().buildGlobalConfiguration(localConfig, localBasicConfiguration, overwrite, storeManager, new ModifiableConfigurationBuilder(), new KCVSConfigurationBuilder());
// Copy over local config options
ModifiableConfiguration localConfiguration = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.LOCAL);
localConfiguration.setAll(getLocalSubset(localBasicConfiguration.getAll()));
Configuration combinedConfig = new MixedConfiguration(ROOT_NS, globalConfig, localConfig);
// Compute unique instance id
String uniqueGraphId = UniqueInstanceIdRetriever.getInstance().getOrGenerateUniqueInstanceId(combinedConfig);
overwrite.set(UNIQUE_INSTANCE_ID, uniqueGraphId);
checkAndOverwriteTransactionLogConfiguration(combinedConfig, overwrite, storeFeatures);
checkAndOverwriteSystemManagementLogConfiguration(combinedConfig, overwrite);
MergedConfiguration configuration = new MergedConfiguration(overwrite, combinedConfig);
return new GraphDatabaseConfiguration(localConfig, localConfiguration, uniqueGraphId, configuration);
}
Aggregations