use of org.apache.commons.configuration.ConfigurationException in project pinot by linkedin.
the class SingleFileIndexDirectory method loadMap.
private void loadMap() throws ConfigurationException {
File mapFile = new File(segmentDirectory, INDEX_MAP_FILE);
PropertiesConfiguration mapConfig = new PropertiesConfiguration(mapFile);
Iterator keys = mapConfig.getKeys();
while (keys.hasNext()) {
String key = (String) keys.next();
// column names can have '.' in it hence scan from backwards
// parsing names like "column.name.dictionary.startOffset"
// or, "column.name.dictionary.endOffset" where column.name is the key
int lastSeparatorPos = key.lastIndexOf(MAP_KEY_SEPARATOR);
Preconditions.checkState(lastSeparatorPos != -1, "Key separator not found: " + key + ", segment: " + segmentDirectory);
String propertyName = key.substring(lastSeparatorPos + 1);
int indexSeparatorPos = key.lastIndexOf(MAP_KEY_SEPARATOR, lastSeparatorPos - 1);
Preconditions.checkState(indexSeparatorPos != -1, "Index separator not found: " + key + " , segment: " + segmentDirectory);
String indexName = key.substring(indexSeparatorPos + 1, lastSeparatorPos);
String columnName = key.substring(0, indexSeparatorPos);
IndexKey indexKey = new IndexKey(columnName, ColumnIndexType.getValue(indexName));
IndexEntry entry = columnEntries.get(indexKey);
if (entry == null) {
entry = new IndexEntry(indexKey);
columnEntries.put(indexKey, entry);
}
if (propertyName.equals(MAP_KEY_NAME_START_OFFSET)) {
entry.startOffset = mapConfig.getLong(key);
} else if (propertyName.equals(MAP_KEY_NAME_SIZE)) {
entry.size = mapConfig.getLong(key);
} else {
throw new ConfigurationException("Invalid map file key: " + key + ", segmentDirectory: " + segmentDirectory.toString());
}
}
// validation
for (Map.Entry<IndexKey, IndexEntry> colIndexEntry : columnEntries.entrySet()) {
IndexEntry entry = colIndexEntry.getValue();
if (entry.size < 0 || entry.startOffset < 0) {
throw new ConfigurationException("Invalid map entry for key: " + colIndexEntry.getKey().toString() + ", segment: " + segmentDirectory.toString());
}
}
}
use of org.apache.commons.configuration.ConfigurationException in project es6draft by anba.
the class Resources method loadConfiguration.
/**
* Loads the configuration file.
*/
public static Configuration loadConfiguration(Class<?> clazz) {
TestConfiguration config = clazz.getAnnotation(TestConfiguration.class);
String file = config.file();
String name = config.name();
try {
PropertiesConfiguration properties = new PropertiesConfiguration();
// entries are mandatory unless an explicit default value was given
properties.setThrowExceptionOnMissing(true);
properties.getInterpolator().setParentInterpolator(MISSING_VAR);
properties.load(resource(file), "UTF-8");
Configuration configuration = new CompositeConfiguration(Arrays.asList(new SystemConfiguration(), properties));
return configuration.subset(name);
} catch (ConfigurationException | IOException e) {
throw new RuntimeException(e);
} catch (NoSuchElementException e) {
throw e;
}
}
use of org.apache.commons.configuration.ConfigurationException in project ninja by ninjaframework.
the class SwissKnife method loadConfigurationInUtf8.
/**
* This is important: We load stuff as UTF-8.
*
* We are using in the default Apache Commons loading mechanism.
*
* With two little tweaks: 1. We don't accept any delimimter by default 2.
* We are reading in UTF-8
*
* More about that:
* http://commons.apache.org/configuration/userguide/howto_filebased
* .html#Loading
*
* From the docs: - If the combination from base path and file name is a
* full URL that points to an existing file, this URL will be used to load
* the file. - If the combination from base path and file name is an
* absolute file name and this file exists, it will be loaded. - If the
* combination from base path and file name is a relative file path that
* points to an existing file, this file will be loaded. - If a file with
* the specified name exists in the user's home directory, this file will be
* loaded. - Otherwise the file name is interpreted as a resource name, and
* it is checked whether the data file can be loaded from the classpath.
*
* @param fileOrUrlOrClasspathUrl Location of the file. Can be on file
* system, or on the classpath. Will both work.
* @return A PropertiesConfiguration or null if there were problems getting
* it.
*/
public static PropertiesConfiguration loadConfigurationInUtf8(String fileOrUrlOrClasspathUrl) {
PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
propertiesConfiguration.setEncoding(NinjaConstant.UTF_8);
propertiesConfiguration.setDelimiterParsingDisabled(true);
propertiesConfiguration.setFileName(fileOrUrlOrClasspathUrl);
propertiesConfiguration.getLayout().setSingleLine(NinjaConstant.applicationSecret, true);
try {
propertiesConfiguration.load(fileOrUrlOrClasspathUrl);
} catch (ConfigurationException e) {
logger.info("Could not load file " + fileOrUrlOrClasspathUrl + " (not a bad thing necessarily, but I am returing null)");
return null;
}
return propertiesConfiguration;
}
use of org.apache.commons.configuration.ConfigurationException in project titan by thinkaurelius.
the class TitanFactory method getLocalConfiguration.
/**
* Load a properties file containing a Titan graph configuration.
* <p/>
* <ol>
* <li>Load the file contents into a {@link org.apache.commons.configuration.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}
*/
@SuppressWarnings("unchecked")
private static ReadConfiguration getLocalConfiguration(File file) {
Preconditions.checkArgument(file != null && file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
try {
PropertiesConfiguration configuration = new PropertiesConfiguration(file);
final File tmpParent = file.getParentFile();
final File configParent;
if (null == tmpParent) {
/*
* null usually means we were given a Titan 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 Iterator<String> keysToMangle = Iterators.filter(configuration.getKeys(), new Predicate<String>() {
@Override
public boolean apply(String key) {
if (null == key)
return false;
return p.matcher(key).matches();
}
});
while (keysToMangle.hasNext()) {
String k = keysToMangle.next();
Preconditions.checkNotNull(k);
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.apache.commons.configuration.ConfigurationException in project distributedlog by twitter.
the class MonitorService method runServer.
public void runServer() throws IllegalArgumentException, IOException {
Preconditions.checkArgument(uriArg.isPresent(), "No distributedlog uri provided.");
Preconditions.checkArgument(serverSetArg.isPresent(), "No proxy server set provided.");
if (intervalArg.isPresent()) {
interval = intervalArg.get();
}
if (regionIdArg.isPresent()) {
regionId = regionIdArg.get();
}
if (streamRegexArg.isPresent()) {
streamRegex = streamRegexArg.get();
}
if (instanceIdArg.isPresent()) {
instanceId = instanceIdArg.get();
}
if (totalInstancesArg.isPresent()) {
totalInstances = totalInstancesArg.get();
}
if (heartbeatEveryChecksArg.isPresent()) {
heartbeatEveryChecks = heartbeatEveryChecksArg.get();
}
if (instanceId < 0 || totalInstances <= 0 || instanceId >= totalInstances) {
throw new IllegalArgumentException("Invalid instance id or total instances number.");
}
handshakeWithClientInfo = handshakeWithClientInfoArg.isPresent();
watchNamespaceChanges = watchNamespaceChangesArg.isPresent();
URI uri = URI.create(uriArg.get());
DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
if (confFileArg.isPresent()) {
String configFile = confFileArg.get();
try {
dlConf.loadConf(new File(configFile).toURI().toURL());
} catch (ConfigurationException e) {
throw new IOException("Failed to load distributedlog configuration from " + configFile + ".");
} catch (MalformedURLException e) {
throw new IOException("Failed to load distributedlog configuration from malformed " + configFile + ".");
}
}
logger.info("Starting stats provider : {}.", statsProvider.getClass());
statsProvider.start(dlConf);
String[] serverSetPaths = StringUtils.split(serverSetArg.get(), ",");
if (serverSetPaths.length == 0) {
throw new IllegalArgumentException("Invalid serverset paths provided : " + serverSetArg.get());
}
ServerSet[] serverSets = createServerSets(serverSetPaths);
ServerSet local = serverSets[0];
ServerSet[] remotes = new ServerSet[serverSets.length - 1];
System.arraycopy(serverSets, 1, remotes, 0, remotes.length);
dlClient = DistributedLogClientBuilder.newBuilder().name("monitor").clientId(ClientId$.MODULE$.apply("monitor")).redirectBackoffMaxMs(50).redirectBackoffStartMs(100).requestTimeoutMs(2000).maxRedirects(2).serverSets(local, remotes).streamNameRegex(streamRegex).handshakeWithClientInfo(handshakeWithClientInfo).clientBuilder(ClientBuilder.get().connectTimeout(Duration.fromSeconds(1)).tcpConnectTimeout(Duration.fromSeconds(1)).requestTimeout(Duration.fromSeconds(2)).hostConnectionLimit(2).hostConnectionCoresize(2).keepAlive(true).failFast(false)).statsReceiver(monitorReceiver.scope("client")).buildMonitorClient();
runMonitor(dlConf, uri);
}
Aggregations