Search in sources :

Example 1 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project whirr by apache.

the class ClusterSpecCommand method getClusterSpec.

protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationException {
    Configuration optionsConfig = new PropertiesConfiguration();
    for (Map.Entry<Property, OptionSpec> entry : optionSpecs.entrySet()) {
        Property property = entry.getKey();
        OptionSpec option = entry.getValue();
        if (property.hasMultipleArguments()) {
            optionsConfig.setProperty(property.getConfigName(), optionSet.valuesOf(option));
        } else {
            optionsConfig.setProperty(property.getConfigName(), optionSet.valueOf(option));
        }
    }
    CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(optionsConfig);
    if (optionSet.has(configOption)) {
        Configuration defaults = new PropertiesConfiguration(optionSet.valueOf(configOption));
        config.addConfiguration(defaults);
    }
    for (Property required : EnumSet.of(SERVICE_NAME, CLUSTER_NAME, IDENTITY)) {
        if (config.getString(required.getConfigName()) == null) {
            throw new IllegalArgumentException(String.format("Option '%s' not set.", required.getSimpleName()));
        }
    }
    return ClusterSpec.fromConfiguration(config);
}
Also used : OptionSpec(joptsimple.OptionSpec) ArgumentAcceptingOptionSpec(joptsimple.ArgumentAcceptingOptionSpec) Configuration(org.apache.commons.configuration.Configuration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Map(java.util.Map) Property(org.apache.whirr.service.ClusterSpec.Property)

Example 2 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project archaius by Netflix.

the class OverridingPropertiesConfiguration method getConfigFromPropertiesFile.

public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException {
    if (loaded.contains(startingUrl.toExternalForm())) {
        logger.warn(startingUrl + " is already loaded");
        return null;
    }
    PropertiesConfiguration propConfig = null;
    try {
        propConfig = new OverridingPropertiesConfiguration(startingUrl);
        logger.info("Loaded properties file " + startingUrl);
    } catch (ConfigurationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FileNotFoundException) {
            throw (FileNotFoundException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }
    if (nextLoadKeys == null) {
        return propConfig;
    }
    String urlString = startingUrl.toExternalForm();
    String base = urlString.substring(0, urlString.lastIndexOf("/"));
    loaded.add(startingUrl.toString());
    loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
    return propConfig;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 3 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project OpenAttestation by OpenAttestation.

the class TAConfig method gatherConfiguration.

private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
    CompositeConfiguration composite = new CompositeConfiguration();
    // first priority are properties defined on the current JVM (-D switch or through web container)
    SystemConfiguration system = new SystemConfiguration();
    dumpConfiguration(system, "system");
    composite.addConfiguration(system);
    // second priority are properties defined on the classpath (like user's home directory)        
    try {
        // user's home directory (assuming it's on the classpath!)
        readPropertiesFile("/" + propertiesFilename, composite);
    } catch (IOException ex) {
        log.info("Did not find " + propertiesFilename + " on classpath", ex);
    }
    // third priority are properties defined in standard install location
    System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
    ArrayList<File> files = new ArrayList<File>();
    // windows-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
        System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
        files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
        files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
    }
    // linux-specific location
    if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
        files.add(new File("./config/" + propertiesFilename));
        files.add(new File("/etc/oat-client/" + propertiesFilename));
    }
    // this line specific to TA for backwards compatibility, not needed in AS/AH
    files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
    // add all the files we found
    for (File f : files) {
        try {
            if (f.exists() && f.canRead()) {
                PropertiesConfiguration standard = new PropertiesConfiguration(f);
                dumpConfiguration(standard, "file:" + f.getAbsolutePath());
                composite.addConfiguration(standard);
            }
        } catch (ConfigurationException ex) {
            log.error(null, ex);
        }
    }
    // last priority are the defaults that were passed in, we use them if no better source was found
    if (defaults != null) {
        MapConfiguration defaultconfig = new MapConfiguration(defaults);
        dumpConfiguration(defaultconfig, "default");
        composite.addConfiguration(defaultconfig);
    }
    dumpConfiguration(composite, "composite");
    return composite;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) MapConfiguration(org.apache.commons.configuration.MapConfiguration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SystemConfiguration(org.apache.commons.configuration.SystemConfiguration) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 4 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project pinot by linkedin.

the class ResourceTestHelper method setup.

/**
   * Sets up Pinot server instance, index directory for creation of segments, creates a default segment
   * and starts pinot admin api service
   * This should be called only once in the  @BeforeClass method of a unit test.
   * Caller must ensure teardown() is called when the test completes (in @AfterClass)
   */
public void setup() throws Exception {
    INDEX_DIR = Files.createTempDirectory(TableSizeResourceTest.class.getName() + "_segmentDir").toFile();
    File confFile = new File(TestUtils.getFileFromResourceUrl(InstanceServerStarter.class.getClassLoader().getResource("conf/pinot.properties")));
    config = new PropertiesConfiguration();
    config.setDelimiterParsingDisabled(false);
    config.load(confFile);
    serverConf = new ServerConf(config);
    LOGGER.info("Trying to create a new ServerInstance!");
    serverInstance = new ServerInstance();
    LOGGER.info("Trying to initial ServerInstance!");
    serverInstance.init(serverConf, new MetricsRegistry());
    LOGGER.info("Trying to start ServerInstance!");
    serverInstance.start();
    apiApplication = new AdminApiApplication(serverInstance);
    apiApplication.start(Integer.parseInt(CommonConstants.Server.DEFAULT_ADMIN_API_PORT));
    client = ClientBuilder.newClient();
    target = client.target(apiApplication.getBaseUri().toString());
    setupSegment();
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) ServerConf(com.linkedin.pinot.server.conf.ServerConf) InstanceServerStarter(com.linkedin.pinot.server.integration.InstanceServerStarter) ServerInstance(com.linkedin.pinot.server.starter.ServerInstance) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) AdminApiApplication(com.linkedin.pinot.server.starter.helix.AdminApiApplication)

Example 5 with PropertiesConfiguration

use of org.apache.commons.configuration.PropertiesConfiguration in project pinot by linkedin.

the class SingleNodeServerStarter method buildServerConfig.

/**
   * Construct from config file path
   * @param configFilePath Path to the config file
   * @throws Exception
   */
public static void buildServerConfig(File configFilePath) throws Exception {
    if (!configFilePath.exists()) {
        LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
        throw new ConfigurationException("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
    }
    // build _serverConf
    final PropertiesConfiguration serverConf = new PropertiesConfiguration();
    serverConf.setDelimiterParsingDisabled(false);
    serverConf.load(configFilePath);
    _serverConf = new ServerConf(serverConf);
}
Also used : ServerConf(com.linkedin.pinot.server.conf.ServerConf) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)102 File (java.io.File)37 Configuration (org.apache.commons.configuration.Configuration)29 ConfigurationException (org.apache.commons.configuration.ConfigurationException)26 IOException (java.io.IOException)12 Test (org.testng.annotations.Test)11 BeforeClass (org.testng.annotations.BeforeClass)10 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)9 IndexLoadingConfigMetadata (com.linkedin.pinot.common.metadata.segment.IndexLoadingConfigMetadata)8 FileBasedInstanceDataManager (com.linkedin.pinot.core.data.manager.offline.FileBasedInstanceDataManager)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)7 FileInputStream (java.io.FileInputStream)6 URL (java.net.URL)6 ServerQueryExecutorV1Impl (com.linkedin.pinot.core.query.executor.ServerQueryExecutorV1Impl)5 ServerConf (com.linkedin.pinot.server.conf.ServerConf)5 FileNotFoundException (java.io.FileNotFoundException)5 Properties (java.util.Properties)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ServerMetrics (com.linkedin.pinot.common.metrics.ServerMetrics)4 FileBasedInstanceDataManagerConfig (com.linkedin.pinot.core.data.manager.config.FileBasedInstanceDataManagerConfig)4