Search in sources :

Example 86 with ConfigurationException

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);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ParseException(org.apache.commons.cli.ParseException) IOException(java.io.IOException) Properties(java.util.Properties) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 87 with ConfigurationException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ConfigurationException(org.apache.commons.configuration.ConfigurationException) Config(com.typesafe.config.Config) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 88 with ConfigurationException

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;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 89 with ConfigurationException

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;
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) SegmentVersion(com.linkedin.pinot.core.indexsegment.generator.SegmentVersion)

Example 90 with ConfigurationException

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());
        }
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) Iterator(java.util.Iterator) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)168 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)64 IOException (java.io.IOException)53 File (java.io.File)40 URL (java.net.URL)17 Configuration (org.apache.commons.configuration.Configuration)14 MalformedURLException (java.net.MalformedURLException)13 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)13 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 ActionEvent (java.awt.event.ActionEvent)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 ActionListener (java.awt.event.ActionListener)7 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 Iterator (java.util.Iterator)4 JCommander (com.beust.jcommander.JCommander)3