List of usage examples for org.apache.commons.configuration PropertiesConfiguration load
public synchronized void load(Reader in) throws ConfigurationException
From source file:edu.usc.goffish.gofs.tools.GoFSFormat.java
public static void main(String[] args) throws IOException { if (args.length < REQUIRED_ARGS) { PrintUsageAndQuit(null);//from w w w .j a v a2s . com } if (args.length == 1 && args[0].equals("-help")) { PrintUsageAndQuit(null); } Path executableDirectory; try { executableDirectory = Paths .get(GoFSFormat.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getParent(); } catch (URISyntaxException e) { throw new RuntimeException("Unexpected error retrieving executable location", e); } Path configPath = executableDirectory.resolve(DEFAULT_CONFIG).normalize(); boolean copyBinaries = false; // parse optional arguments int i = 0; OptArgLoop: for (i = 0; i < args.length - REQUIRED_ARGS; i++) { switch (args[i]) { case "-config": i++; try { configPath = Paths.get(args[i]); } catch (InvalidPathException e) { PrintUsageAndQuit("Config file - " + e.getMessage()); } break; case "-copyBinaries": copyBinaries = true; break; default: break OptArgLoop; } } if (args.length - i < REQUIRED_ARGS) { PrintUsageAndQuit(null); } // finished parsing args if (i < args.length) { PrintUsageAndQuit("Unrecognized argument \"" + args[i] + "\""); } // parse config System.out.println("Parsing config..."); PropertiesConfiguration config = new PropertiesConfiguration(); config.setDelimiterParsingDisabled(true); try { config.load(Files.newInputStream(configPath)); } catch (ConfigurationException e) { throw new IOException(e); } // retrieve data nodes ArrayList<URI> dataNodes; { String[] dataNodesArray = config.getStringArray(GOFS_DATANODES_KEY); if (dataNodesArray.length == 0) { throw new ConversionException("Config must contain key " + GOFS_DATANODES_KEY); } dataNodes = new ArrayList<>(dataNodesArray.length); if (dataNodesArray.length == 0) { throw new ConversionException("Config key " + GOFS_DATANODES_KEY + " has invalid format - must define at least one data node"); } try { for (String node : dataNodesArray) { URI dataNodeURI = new URI(node); if (!"file".equalsIgnoreCase(dataNodeURI.getScheme())) { throw new ConversionException("config key " + GOFS_DATANODES_KEY + " value \"" + dataNodeURI + "\" has invalid format - data node urls must have 'file' scheme"); } else if (dataNodeURI.getPath() == null || dataNodeURI.getPath().isEmpty()) { throw new ConversionException("config key " + GOFS_DATANODES_KEY + " value \"" + dataNodeURI + "\" has invalid format - data node urls must have an absolute path specified"); } // ensure uri ends with a slash, so we know it is a directory if (!dataNodeURI.getPath().endsWith("/")) { dataNodeURI = dataNodeURI.resolve(dataNodeURI.getPath() + "/"); } dataNodes.add(dataNodeURI); } } catch (URISyntaxException e) { throw new ConversionException( "Config key " + GOFS_DATANODES_KEY + " has invalid format - " + e.getMessage()); } } // validate serializer type Class<? extends ISliceSerializer> serializerType; { String serializerTypeName = config.getString(GOFS_SERIALIZER_KEY); if (serializerTypeName == null) { throw new ConversionException("Config must contain key " + GOFS_SERIALIZER_KEY); } try { serializerType = SliceSerializerProvider.loadSliceSerializerType(serializerTypeName); } catch (ReflectiveOperationException e) { throw new ConversionException( "Config key " + GOFS_SERIALIZER_KEY + " has invalid format - " + e.getMessage()); } } // retrieve name node IInternalNameNode nameNode; try { nameNode = NameNodeProvider.loadNameNodeFromConfig(config, GOFS_NAMENODE_TYPE_KEY, GOFS_NAMENODE_LOCATION_KEY); } catch (ReflectiveOperationException e) { throw new RuntimeException("Unable to load name node", e); } System.out.println("Contacting name node..."); // validate name node if (!nameNode.isAvailable()) { throw new IOException("Name node at " + nameNode.getURI() + " is not available"); } System.out.println("Contacting data nodes..."); // validate data nodes for (URI dataNode : dataNodes) { // only attempt ssh if host exists if (dataNode.getHost() != null) { try { SSHHelper.SSH(dataNode, "true"); } catch (IOException e) { throw new IOException("Data node at " + dataNode + " is not available", e); } } } // create temporary directory Path workingDir = Files.createTempDirectory("gofs_format"); try { // create deploy directory Path deployDirectory = Files.createDirectory(workingDir.resolve(DATANODE_DIR_NAME)); // create empty slice directory Files.createDirectory(deployDirectory.resolve(DataNode.DATANODE_SLICE_DIR)); // copy binaries if (copyBinaries) { System.out.println("Copying binaries..."); FileUtils.copyDirectory(executableDirectory.toFile(), deployDirectory.resolve(executableDirectory.getFileName()).toFile()); } // write config file Path dataNodeConfigFile = deployDirectory.resolve(DataNode.DATANODE_CONFIG); try { // create config for every data node and scp deploy folder into place for (URI dataNodeParent : dataNodes) { URI dataNode = dataNodeParent.resolve(DATANODE_DIR_NAME); PropertiesConfiguration datanode_config = new PropertiesConfiguration(); datanode_config.setDelimiterParsingDisabled(true); datanode_config.setProperty(DataNode.DATANODE_INSTALLED_KEY, true); datanode_config.setProperty(DataNode.DATANODE_NAMENODE_TYPE_KEY, config.getString(GOFS_NAMENODE_TYPE_KEY)); datanode_config.setProperty(DataNode.DATANODE_NAMENODE_LOCATION_KEY, config.getString(GOFS_NAMENODE_LOCATION_KEY)); datanode_config.setProperty(DataNode.DATANODE_LOCALHOSTURI_KEY, dataNode.toString()); try { datanode_config.save(Files.newOutputStream(dataNodeConfigFile)); } catch (ConfigurationException e) { throw new IOException(e); } System.out.println("Formatting data node " + dataNode.toString() + "..."); // scp everything into place on the data node SCPHelper.SCP(deployDirectory, dataNodeParent); // update name node nameNode.addDataNode(dataNode); } // update name node nameNode.setSerializer(serializerType); } catch (Exception e) { System.out.println( "ERROR: data node formatting interrupted - name node and data nodes are in an inconsistent state and require clean up"); throw e; } System.out.println("GoFS format complete"); } finally { FileUtils.deleteQuietly(workingDir.toFile()); } }
From source file:com.linkedin.pinot.transport.perf.ScatterGatherPerfClient.java
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 !!"); }//from w w w. ja v a 2s . c o m 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 !!"); }
From source file:br.com.ceosites.cachedproperties.cache.test.util.TestUtils.java
public static PropertiesConfiguration createFileConfiguration() { PropertiesConfiguration configuration = new PropertiesConfiguration(); try {/* w ww . ja v a 2 s . c om*/ configuration.load("src/main/resources/cached.properties"); } catch (ConfigurationException ex) { Logger.getLogger(TestUtils.class.getName()).log(Level.SEVERE, null, ex); } return configuration; }
From source file:com.jf.commons.datamodels.hrm.classifiers.District.java
public static void generateData(Dao<District, Long> dao, Dao<City, Long> cdao) throws Exception { // create table if not exists TableUtils.createTableIfNotExists(dao.getConnectionSource(), District.class); // insert predefine data PropertiesConfiguration cfg = new PropertiesConfiguration(); cfg.load(new InputStreamReader(City.class.getResourceAsStream("districts.properties"), "UTF-8")); for (String d : cfg.getStringArray("districts")) { String[] district = d.split(":"); District m = new District(); m.setNew(true);/*from w ww . j a v a 2 s . c om*/ m.setName(district[0].trim()); m.setCity(cdao.queryForEq(City.FIELD_NAME, new SelectArg(district[1].trim())).get(0)); m.setCreator("admin"); dao.create(m); } }
From source file:com.uber.hoodie.utilities.UtilHelpers.java
/** * * TODO: Support hierarchical config files (see CONFIGURATION-609 for sample) * * @param fs/*from w ww . jav a2 s. c o m*/ * @param cfgPath * @return */ public static PropertiesConfiguration readConfig(FileSystem fs, Path cfgPath) { try { FSDataInputStream in = fs.open(cfgPath); PropertiesConfiguration config = new PropertiesConfiguration(); config.load(in); in.close(); return config; } catch (IOException e) { throw new HoodieIOException("Unable to read config file at :" + cfgPath, e); } catch (ConfigurationException e) { throw new HoodieDeltaStreamerException("Invalid configs found in config file at :" + cfgPath, e); } }
From source file:com.jf.commons.datamodels.hrm.classifiers.Ward.java
public static void generateData(Dao<Ward, Long> dao, Dao<City, Long> cdao, Dao<District, Long> ddao) throws Exception { // create table if not exists TableUtils.createTableIfNotExists(dao.getConnectionSource(), Ward.class); // insert wards PropertiesConfiguration cfg = new PropertiesConfiguration(); cfg.load(new InputStreamReader(City.class.getResourceAsStream("wards.properties"), "UTF-8")); for (String w : cfg.getStringArray("wards")) { String[] parts = w.split(":"); Ward m = new Ward(); m.setNew(true);//from w w w . j a va2 s . c o m m.setName(parts[0].trim()); m.setDistrict(ddao.queryForEq(District.FIELD_NAME, new SelectArg(parts[1].trim())).get(0)); m.setCity(cdao.queryForEq(City.FIELD_NAME, new SelectArg(parts[2].trim())).get(0)); m.setCreator("admin"); dao.create(m); } }
From source file:com.jf.commons.datamodels.hrm.classifiers.City.java
/** * Create table and insert predefine data * /*from www .java 2 s . c o m*/ * @param dao * @throws Exception */ public static void generateData(Dao<City, Long> dao) throws Exception { // create table if not exists TableUtils.createTableIfNotExists(dao.getConnectionSource(), City.class); // insert predefine data PropertiesConfiguration cfg = new PropertiesConfiguration(); cfg.load(new InputStreamReader(City.class.getResourceAsStream("cities.properties"), "UTF-8")); for (String c : cfg.getStringArray("cities")) { String[] city = c.split(":"); City m = new City(); m.setNew(true); m.setName(city[0].trim()); m.setNamePrefix(city[1].trim()); m.setCreator("admin"); dao.create(m); } }
From source file:com.linkedin.pinot.server.starter.SingleNodeServerStarter.java
/** * Construct from config file path// w w w . jav a 2 s . c om * @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); }
From source file:com.vmware.qe.framework.datadriven.config.DDConfig.java
/** * Gets the configuration based on the specified property file.<br> * //from www .ja v a2 s. c o m * @param filePath file containing configuration information. * @return configuration Configuration if found else returns null. */ private static Configuration getConfigFileData(String filePath) { PropertiesConfiguration flatConfig = new PropertiesConfiguration(); try { flatConfig.load(filePath); return ConfigurationUtils.convertToHierarchical(flatConfig); } catch (ConfigurationException e) { log.warn("Failed to load configuration from File {}", filePath, e); return null; } }
From source file:WBSTest.java
private static void initTorque() { try {//from w w w . j a va 2 s .c o m PropertiesConfiguration tcfg = new PropertiesConfiguration(); System.out.println(WBSTest.class.getResource("/Torque.properties")); URL torqueURL = WBSTest.class.getResource("/Torque.properties"); InputStream in = torqueURL.openStream(); tcfg.load(in); in.close(); Torque.init(tcfg); // Now really do it: initialize Torque } catch (Exception e) { e.printStackTrace(); } }