/** * Load the properties from the specified file into a {@link Properties} object. * * @param fileName the name of the file to load properties from * @param conf configuration object to determine the file system to be used * @return a new {@link Properties} instance */ public static Properties fileToProperties(String fileName, Configuration conf) throws IOException, ConfigurationException { PropertiesConfiguration propsConfig = new PropertiesConfiguration(); Path filePath = new Path(fileName); URI fileURI = filePath.toUri(); if (fileURI.getScheme() == null && fileURI.getAuthority() == null) { propsConfig.load(FileSystem.getLocal(conf).open(filePath)); } else { propsConfig.load(filePath.getFileSystem(conf).open(filePath)); } return ConfigurationConverter.getProperties(propsConfig); }
/** * 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) { throw new IOException(ce); } }
propertiesConfiguration.load(fileOrUrlOrClasspathUrl);
public static void main(String[] args) throws Exception { //Process Command Line to get config and port CommandLineParser cliParser = new GnuParser(); Options cliOptions = buildCommandLineOptions(); CommandLine cmd = cliParser.parse(cliOptions, args, true); if ((!cmd.hasOption(BROKER_CONFIG_OPT_NAME)) || (!cmd.hasOption(REQUEST_SIZE_OPT_NAME)) || (!cmd .hasOption(TABLE_NAME_OPT_NAME)) || (!cmd.hasOption(TABLE_NAME_OPT_NAME))) { System.err.println("Missing required arguments !!"); System.err.println(cliOptions); throw new RuntimeException("Missing required arguments !!"); } String brokerConfigPath = cmd.getOptionValue(BROKER_CONFIG_OPT_NAME); int requestSize = Integer.parseInt(cmd.getOptionValue(REQUEST_SIZE_OPT_NAME)); int numRequests = Integer.parseInt(cmd.getOptionValue(NUM_REQUESTS_OPT_NAME)); String resourceName = cmd.getOptionValue(TABLE_NAME_OPT_NAME); // build brokerConf PropertiesConfiguration brokerConf = new PropertiesConfiguration(); brokerConf.setDelimiterParsingDisabled(false); brokerConf.load(brokerConfigPath); RoutingTableConfig config = new RoutingTableConfig(); config.init(brokerConf.subset(ROUTING_CFG_PREFIX)); ScatterGatherPerfClient client = new ScatterGatherPerfClient(config, requestSize, resourceName, false, numRequests, 1, 1); client.run(); System.out.println("Shutting down !!"); client.shutdown(); System.out.println("Shut down complete !!"); }
PropertiesConfiguration queryExecutorConfig = new PropertiesConfiguration(); queryExecutorConfig.setDelimiterParsingDisabled(false); queryExecutorConfig.load(new File(resourceUrl.getFile())); _queryExecutor = new ServerQueryExecutorV1Impl(); _queryExecutor.init(queryExecutorConfig, instanceDataManager, _serverMetrics);
public static ClientConfiguration deserialize(String serializedConfig) { PropertiesConfiguration propConfig = new PropertiesConfiguration(); propConfig.setListDelimiter('\0'); try { propConfig.load(new StringReader(serializedConfig)); } catch (ConfigurationException e) { throw new IllegalArgumentException( "Error deserializing client configuration: " + serializedConfig, e); } return new ClientConfiguration(Collections.singletonList(propConfig)); }
/** * Initializes a configuration object from the contents of a configuration file. Currently * supports Java "properties" files. The returned object can be further configured with subsequent * calls to other methods on this class. * * @param file * the path to the configuration file * @since 1.9.0 */ public static ClientConfiguration fromFile(File file) { PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiter('\0'); try { props.load(file); return new ClientConfiguration(Collections.singletonList(props)); } catch (ConfigurationException e) { throw new IllegalArgumentException("Bad configuration file: " + file, e); } }
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "process runs in same security context as user who provided path") private static ClientConfiguration loadFromSearchPath(List<String> paths) { List<Configuration> configs = new LinkedList<>(); for (String path : paths) { File conf = new File(path); if (conf.isFile() && conf.canRead()) { PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiter('\0'); try { props.load(conf); log.info("Loaded client configuration file {}", conf); } catch (ConfigurationException e) { throw new IllegalStateException("Error loading client configuration file " + conf, e); } configs.add(props); } } // We couldn't find the client configuration anywhere if (configs.isEmpty()) { log.debug( "Found no client.conf in default paths. Using default client configuration values."); } return new ClientConfiguration(configs); }
void reloadKylinConfig(InputStream is) { PropertiesConfiguration config = new PropertiesConfiguration(); config.setListDelimiter((char)0); // disable list delimiter, Kylin will parse and split try { config.load(is); } catch (ConfigurationException e) { throw new RuntimeException("Cannot load kylin config.", e); } finally { try { is.close(); } catch (IOException e) { logger.error("Failed to close inputstream.", e); } } this.kylinConfig = config; this.metadataUrl = getOptional(KYLIN_METADATA_URL); this.storageUrl = getOptional(KYLIN_STORAGE_URL); }
/** * Returns value of property in accumulo.properties file, otherwise default value * * @param propertyName * Name of the property to pull * @param defaultValue * Value to default to if not found. * @return value of property or default */ public static String getAccumuloProperty(String propertyName, String defaultValue) { if (accumuloConfigUrl == null) { log.warn( "Using default value '{}' for '{}' as there is no Accumulo configuration on classpath", defaultValue, propertyName); return defaultValue; } try { PropertiesConfiguration config = new PropertiesConfiguration(); config.setDelimiterParsingDisabled(true); config.setThrowExceptionOnMissing(false); config.load(accumuloConfigUrl); String value = config.getString(propertyName); if (value != null) return value; return defaultValue; } catch (Exception e) { throw new IllegalStateException( "Failed to look up property " + propertyName + " in " + accumuloConfigUrl.getFile(), e); } }
public static void registerBackends() { String confFile = "/backend.properties"; InputStream input = RegisterUtil.class.getClass() .getResourceAsStream(confFile); E.checkState(input != null, "Can't read file '%s' as stream", confFile); PropertiesConfiguration props = new PropertiesConfiguration(); props.setDelimiterParsingDisabled(true); try { props.load(input); } catch (ConfigurationException e) { throw new HugeException("Can't load config file: %s", e, confFile); } HugeConfig config = new HugeConfig(props); List<String> backends = config.get(DistOptions.BACKENDS); for (String backend : backends) { registerBackend(backend); } }
if (accumuloPropsLocation != null) { try { propsConfig.load(accumuloPropsLocation.openStream()); } catch (IOException | ConfigurationException e) { throw new IllegalArgumentException(e);
private static PropertiesConfiguration newPropsFile(String file) throws ConfigurationException { PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiter('\0'); props.load(file); return props; }
private static PropertiesConfiguration newPropsFile(File file) throws ConfigurationException { PropertiesConfiguration props = new PropertiesConfiguration(); props.setListDelimiter('\0'); props.load(file); return props; }
public PropertyFileConfiguration(String configurationPath) throws ConfigurationException { Validation.isNullOrEmptyParameter("configurationPath", configurationPath); this.configurationPath = configurationPath; InputStream in = getClass().getResourceAsStream(configurationPath); propertiesConfiguration = new PropertiesConfiguration(); try { propertiesConfiguration.load(in); } catch (Exception e) { System.err.println("unable to load file: " + configurationPath); e.printStackTrace(); } }
protected void load(String filename) { PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); try { propertiesConfiguration.load(filename); config.addConfiguration(propertiesConfiguration); } catch (ConfigurationException e) { throw new ExceptionInInitializerError(e); } logger.info("Loaded {}", filename); }
public static ClientConfiguration deserialize(String serializedConfig) { PropertiesConfiguration propConfig = new PropertiesConfiguration(); propConfig.setListDelimiter('\0'); try { propConfig.load(new StringReader(serializedConfig)); } catch (ConfigurationException e) { throw new IllegalArgumentException( "Error deserializing client configuration: " + serializedConfig, e); } return new ClientConfiguration(propConfig); }
public FluoConfiguration(File propertiesFile) { this(); try { PropertiesConfiguration config = new PropertiesConfiguration(); // disabled to prevent accumulo classpath value from being shortened config.setDelimiterParsingDisabled(true); config.load(propertiesFile); addConfiguration(config); } catch (ConfigurationException e) { throw new IllegalArgumentException(e); } }
@Test public void tikaShouldBeDisabledByDefault() throws Exception { PropertiesConfiguration configuration = new PropertiesConfiguration(); configuration.load(new StringReader("")); assertThat(TikaConfigurationReader.readTikaConfiguration(configuration)) .isEqualTo( TikaConfiguration.builder() .disabled() .build()); }