use of org.apache.commons.configuration.ConfigurationException in project incubator-gobblin by apache.
the class CliOptions method parseArgs.
/**
* Parse command line arguments and return a {@link java.util.Properties} object for the gobblin job found.
* @param caller Class of the calling main method. Used for error logs.
* @param args Command line arguments.
* @return Instance of {@link Properties} for the Gobblin job to run.
* @throws IOException
*/
public static Properties parseArgs(Class<?> caller, String[] args) throws IOException {
try {
// Parse command-line options
CommandLine cmd = new DefaultParser().parse(options(), args);
if (cmd.hasOption(HELP_OPTION.getOpt())) {
printUsage(caller);
System.exit(0);
}
if (!cmd.hasOption(SYS_CONFIG_OPTION.getLongOpt()) || !cmd.hasOption(JOB_CONFIG_OPTION.getLongOpt())) {
printUsage(caller);
System.exit(1);
}
// Load system and job configuration properties
Properties sysConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(SYS_CONFIG_OPTION.getLongOpt()));
Properties jobConfig = JobConfigurationUtils.fileToProperties(cmd.getOptionValue(JOB_CONFIG_OPTION.getLongOpt()));
return JobConfigurationUtils.combineSysAndJobProperties(sysConfig, jobConfig);
} catch (ParseException | ConfigurationException e) {
throw new IOException(e);
}
}
use of org.apache.commons.configuration.ConfigurationException in project incubator-gobblin by apache.
the class PullFileLoader method loadJavaPropsWithFallback.
/**
* Load a {@link Properties} compatible path using fallback as fallback.
* @return The {@link Config} in path with fallback as fallback.
* @throws IOException
*/
private Config loadJavaPropsWithFallback(Path propertiesPath, Config fallback) throws IOException {
PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
try (InputStreamReader inputStreamReader = new InputStreamReader(this.fs.open(propertiesPath), Charsets.UTF_8)) {
propertiesConfiguration.setDelimiterParsingDisabled(ConfigUtils.getBoolean(fallback, PROPERTY_DELIMITER_PARSING_ENABLED_KEY, DEFAULT_PROPERTY_DELIMITER_PARSING_ENABLED_KEY));
propertiesConfiguration.load(inputStreamReader);
Config configFromProps = ConfigUtils.propertiesToConfig(ConfigurationConverter.getProperties(propertiesConfiguration));
return ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY, PathUtils.getPathWithoutSchemeAndAuthority(propertiesPath).toString())).withFallback(configFromProps).withFallback(fallback);
} catch (ConfigurationException ce) {
log.error("Failed to load Java properties from file at {} due to {}", propertiesPath, ce.getLocalizedMessage());
throw new IOException(ce);
}
}
use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.
the class ClusterSpec method fromConfiguration.
/**
*
* @throws ConfigurationException if the public or private key cannot be read.
*/
public static ClusterSpec fromConfiguration(Configuration config) throws ConfigurationException {
ClusterSpec spec = new ClusterSpec();
spec.setServiceName(config.getString(Property.SERVICE_NAME.getConfigName()));
spec.setInstanceTemplates(InstanceTemplate.parse(config.getStringArray(Property.INSTANCE_TEMPLATES.getConfigName())));
spec.setProvider(config.getString(Property.PROVIDER.getConfigName()));
spec.setIdentity(checkNotNull(config.getString(Property.IDENTITY.getConfigName()), Property.IDENTITY));
spec.setCredential(config.getString(Property.CREDENTIAL.getConfigName()));
spec.setClusterName(config.getString(Property.CLUSTER_NAME.getConfigName()));
try {
String privateKeyPath = config.getString(Property.PRIVATE_KEY_FILE.getConfigName());
if (privateKeyPath != null)
spec.setPrivateKey(new File(privateKeyPath));
String publicKeyPath = config.getString(Property.PUBLIC_KEY_FILE.getConfigName());
publicKeyPath = publicKeyPath == null && privateKeyPath != null ? privateKeyPath + ".pub" : publicKeyPath;
if (publicKeyPath != null)
spec.setPublicKey(new File(publicKeyPath));
} catch (IOException e) {
throw new ConfigurationException("error reading key from file", e);
}
spec.setClientCidrs(config.getList(Property.CLIENT_CIDRS.getConfigName()));
spec.config = config;
return spec;
}
use of org.apache.commons.configuration.ConfigurationException in project pinot by linkedin.
the class SegmentLocalFSDirectory method loadData.
private synchronized void loadData() throws IOException {
if (columnIndexDirectory != null) {
return;
}
String version = segmentMetadata.getVersion();
SegmentVersion segmentVersion = SegmentVersion.valueOf(version);
switch(segmentVersion) {
case v1:
case v2:
columnIndexDirectory = new FilePerIndexDirectory(segmentDirectory, segmentMetadata, readMode);
break;
case v3:
try {
columnIndexDirectory = new SingleFileIndexDirectory(segmentDirectory, segmentMetadata, readMode);
} catch (ConfigurationException e) {
LOGGER.error("Failed to create columnar index directory", e);
throw new RuntimeException(e);
}
break;
}
}
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());
}
}
}
Aggregations