List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:gobblin.scheduler.SchedulerDaemon.java
public static void main(String[] args) throws Exception { if (args.length < 1 || args.length > 2) { System.err.println(//from w ww . jav a2 s .co m "Usage: SchedulerDaemon <default configuration properties file> [custom configuration properties file]"); System.exit(1); } // Load default framework configuration properties Properties defaultProperties = ConfigurationConverter.getProperties(new PropertiesConfiguration(args[0])); // Load custom framework configuration properties (if any) Properties customProperties = new Properties(); if (args.length == 2) { customProperties.putAll(ConfigurationConverter.getProperties(new PropertiesConfiguration(args[1]))); } log.debug("Scheduler Daemon::main starting with defaultProperties: {}, customProperties: {}", defaultProperties, customProperties); // Start the scheduler daemon new SchedulerDaemon(defaultProperties, customProperties).start(); }
From source file:com.feedzai.fos.server.Runner.java
/** * Launches the server.//from ww w . j av a2 s . c o m * See @{link StartupConfiguration} for command line switches. * <p/> Will start an embedded RMI registry if "-s" was specified. * * @param args the command line switches * @throws ConfigurationException */ public static void main(String... args) throws ConfigurationException { long time = System.currentTimeMillis(); StartupConfiguration parameters = new StartupConfiguration(); JCommander jCommander = new JCommander(parameters); FosServer fosServer; try { jCommander.parse(args); logger.info("Starting fos server using configuration from {}", parameters.getConfiguration()); FosConfig serverConfig = new FosConfig(new PropertiesConfiguration(parameters.getConfiguration())); if (serverConfig.isEmbeddedRegistry()) { LocateRegistry.createRegistry(serverConfig.getRegistryPort()); logger.debug("RMI registry started in port {}", serverConfig.getRegistryPort()); } fosServer = new FosServer(serverConfig); fosServer.bind(); logger.info("FOS Server started in {}ms", (System.currentTimeMillis() - time)); } catch (ParameterException e) { jCommander.usage(); } catch (Exception e) { logger.error("Could not launch RMI service", e); } }
From source file:gobblin.compaction.CompactionRunner.java
public static void main(String[] args) throws ConfigurationException, IOException, SQLException { if (args.length != 1) { LOG.info("Proper usage: java -jar compaction.jar <global-config-file>\n" + "or\n" + "hadoop jar compaction.jar <global-config-file>\n" + "or\n" + "yarn jar compaction.jar <global-config-file>\n"); System.exit(1);// w ww . ja v a 2 s . c o m } Configuration globalConfig = new PropertiesConfiguration(args[0]); properties = ConfigurationConverter.getProperties(globalConfig); File compactionConfigDir = new File(properties.getProperty(COMPACTION_CONFIG_DIR)); File[] listOfFiles = compactionConfigDir.listFiles(); if (listOfFiles == null || listOfFiles.length == 0) { System.err.println("No compaction configuration files found under " + compactionConfigDir); System.exit(1); } int numOfJobs = 0; for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { numOfJobs++; } } LOG.info("Found " + numOfJobs + " compaction tasks."); PrintWriter pw = new PrintWriter(new OutputStreamWriter( new FileOutputStream(properties.getProperty(TIMING_FILE, TIMING_FILE_DEFAULT)), Charset.forName("UTF-8"))); for (File file : listOfFiles) { if (file.isFile() && !file.getName().startsWith(".")) { Configuration jobConfig = new PropertiesConfiguration(file.getAbsolutePath()); jobProperties = ConfigurationConverter.getProperties(jobConfig); long startTime = System.nanoTime(); compact(); long endTime = System.nanoTime(); long elapsedTime = endTime - startTime; double seconds = TimeUnit.NANOSECONDS.toSeconds(elapsedTime); pw.printf("%s: %f%n", file.getAbsolutePath(), seconds); } } pw.close(); }
From source file:edu.usc.goffish.gopher.impl.Main.java
public static void main(String[] args) { Properties properties = new Properties(); try {/*from ww w. jav a 2 s.c om*/ properties.load(new FileInputStream(CONFIG_FILE)); } catch (IOException e) { String message = "Error while loading Container Configuration from " + CONFIG_FILE + " Cause -" + e.getCause(); log.warning(message); } if (args.length == 4) { PropertiesConfiguration propertiesConfiguration; String url = null; URI uri = URI.create(args[3]); String dataDir = uri.getPath(); String currentHost = uri.getHost(); try { propertiesConfiguration = new PropertiesConfiguration(dataDir + "/gofs.config"); propertiesConfiguration.load(); url = (String) propertiesConfiguration.getString(DataNode.DATANODE_NAMENODE_LOCATION_KEY); } catch (ConfigurationException e) { String message = " Error while reading gofs-config cause -" + e.getCause(); handleException(message); } URI nameNodeUri = URI.create(url); INameNode nameNode = new RemoteNameNode(nameNodeUri); int partition = -1; try { for (URI u : nameNode.getDataNodes()) { if (URIHelper.isLocalURI(u)) { IDataNode dataNode = DataNode.create(u); IntCollection partitions = dataNode.getLocalPartitions(args[2]); partition = partitions.iterator().nextInt(); break; } } if (partition == -1) { String message = "Partition not loaded from uri : " + nameNodeUri; handleException(message); } properties.setProperty(GopherInfraHandler.PARTITION, String.valueOf(partition)); } catch (Exception e) { String message = "Error while loading Partitions from " + nameNodeUri + " Cause -" + e.getMessage(); e.printStackTrace(); handleException(message); } properties.setProperty(Constants.STATIC_PELLET_COUNT, String.valueOf(1)); FloeRuntimeEnvironment environment = FloeRuntimeEnvironment.getEnvironment(); environment.setSystemConfig(properties); properties.setProperty(Constants.CURRET_HOST, currentHost); String managerHost = args[0]; int managerPort = Integer.parseInt(args[1]); Container container = environment.getContainer(); container.setManager(managerHost, managerPort); DefaultClientConfig config = new DefaultClientConfig(); config.getProperties().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); config.getFeatures().put(ClientConfig.FEATURE_DISABLE_XML_SECURITY, true); Client c = Client.create(config); if (managerHost == null || managerPort == 0) { handleException("Manager Host / Port have to be configured in " + args[0]); } WebResource r = c.resource("http://" + managerHost + ":" + managerPort + "/Manager/addContainerInfo/Container=" + container.getContainerInfo().getContainerId() + "/Host=" + container.getContainerInfo().getContainerHost()); c.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); r.post(); log.log(Level.INFO, "Container started "); } else { String message = "Invalid arguments , arg[0]=Manager host, " + "arg[1] = mamanger port,arg[2]=graph id,arg[3]=partition uri"; message += "\n Current Arguments...." + args.length + "\n"; for (int i = 0; i < args.length; i++) { message += "arg " + i + " : " + args[i] + "\n"; } handleException(message); } }
From source file:gobblin.metastore.util.DatabaseJobHistoryStoreSchemaManager.java
public static void main(String[] args) throws IOException { if (args.length < 1 || args.length > 2) { printUsage();/*w w w . j a va2s. c om*/ } Closer closer = Closer.create(); try { CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); if (args.length == 2) { config.addConfiguration(new PropertiesConfiguration(args[1])); } Properties properties = getProperties(config); DatabaseJobHistoryStoreSchemaManager schemaManager = closer .register(DatabaseJobHistoryStoreSchemaManager.builder(properties).build()); if (String.CASE_INSENSITIVE_ORDER.compare("migrate", args[0]) == 0) { schemaManager.migrate(); } else if (String.CASE_INSENSITIVE_ORDER.compare("info", args[0]) == 0) { schemaManager.info(); } else { printUsage(); } } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } }
From source file:it.polimi.tower4clouds.rdf_history_db.Main.java
public static void main(String[] args) { // args = "-fakemessages 10 -waitfakemessages 1000".split(" "); PropertiesConfiguration releaseProperties = null; try {//from w ww. ja va 2s .c o m releaseProperties = new PropertiesConfiguration("release.properties"); } catch (ConfigurationException e) { logger.error("Internal error", e); System.exit(1); } APP_NAME = releaseProperties.getString("application.name"); APP_FILE_NAME = releaseProperties.getString("dist.file.name"); APP_VERSION = releaseProperties.getString("release.version"); Main m = new Main(); JCommander jc = new JCommander(m, args); if (m.help) { jc.setProgramName(APP_FILE_NAME); jc.usage(); System.exit(0); } logger.info("{} {}", APP_NAME, APP_VERSION); HashMap<String, String> paramsMap = new HashMap<String, String>(); for (ParameterDescription param : jc.getParameters()) if (param.isAssigned()) { String name = param.getLongestName().replaceAll("-", ""); String value = null; try { value = Main.class.getField(name).get(m).toString(); } catch (Exception e) { } paramsMap.put(name, value); } perform(paramsMap); }
From source file:eu.mrbussy.pdfsplitter.Application.java
/** * Start the main program.//ww w . j a va 2 s. c o m * * @param args * - Arguments passed on to the program */ public static void main(String[] args) { // Read configurations try { String configDirname = FilenameUtils.concat(System.getProperty("user.home"), String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR)); String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE); // Check to see if the directory exists and the file can be created/opened File configDir = new File(configDirname); if (!configDir.exists()) configDir.mkdir(); // Check to see if the file exists. If not create it File file = new File(filename); if (!file.exists()) { file.createNewFile(); } Configuration = new PropertiesConfiguration(file); // Automatically store the settings that change Configuration.setAutoSave(true); } catch (ConfigurationException | IOException ex) { // Unable to read the file. Probably because it does not exist --> create it. ex.printStackTrace(); } // Set locale to a configured language Locale.setDefault( new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL"))); // Start by parsing the command line ParseCommandline(args); // Display the help if required and leave the app if (arguments.hasOption("h")) { showHelp(); } // Display the app version and leave the app. if (arguments.hasOption("v")) { showVersion(); } // Not command line so start the app GUI if (!arguments.hasOption("c")) { try { // Change the look and feel UIManager.setLookAndFeel( Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel")); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { (new MainWindow()).setVisible(true); } }); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // Something terrible happened so show the help showHelp(); } } }
From source file:joshelser.as2015.ingester.CategoryUpdater.java
public static void main(String[] args) throws Exception { JCommander commander = new JCommander(); final Opts options = new Opts(); commander.addObject(options);/*from w ww . ja v a 2s .c om*/ commander.setProgramName("Query"); try { commander.parse(args); } catch (ParameterException ex) { commander.usage(); System.err.println(ex.getMessage()); System.exit(1); } ClientConfiguration conf = ClientConfiguration.loadDefault(); if (null != options.clientConfFile) { conf = new ClientConfiguration(new PropertiesConfiguration(options.clientConfFile)); } conf.withInstance(options.instanceName).withZkHosts(options.zookeepers); ZooKeeperInstance inst = new ZooKeeperInstance(conf); Connector conn = inst.getConnector(options.user, new PasswordToken(options.password)); BatchScanner bs = conn.createBatchScanner(options.table, Authorizations.EMPTY, 16); BatchWriter bw = conn.createBatchWriter(options.table, new BatchWriterConfig()); try { bs.setRanges(Collections.singleton(new Range())); final Text categoryText = new Text("category"); bs.fetchColumnFamily(categoryText); final Text categoryName = new Text("name"); final Text row = new Text(); for (Entry<Key, Value> entry : bs) { entry.getKey().getRow(row); Mutation m = new Mutation(row); m.put(categoryText, categoryName, entry.getValue()); bw.addMutation(m); } } finally { bs.close(); bw.close(); } }
From source file:EVT.java
/** * @param args/*from ww w . j a v a2 s.co m*/ */ public static void main(final String[] args) throws MalformedURLException { try { URL url = new EVT().getClass().getClassLoader().getResource("general.properties"); config = new PropertiesConfiguration(url); } catch (ConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); System.exit(1); } final Map parameters = parseParameters(args); if (parameters.containsKey("-v")) verboseMode = 1; if (parameters.containsKey("-V") || parameters.containsKey("-vv")) verboseMode = 2; //the from version and the to version must be put in property file String supportedVersions = PropertiesUtil.concatenatePropsValues(config, ALFRESCO_VERSION, ","); List<String> supportedVersionsList = Arrays.asList(supportedVersions.split(",")); String alfrescoVersion = (String) parameters.get(ALFRESCO_VERSION); boolean supportedVersion = (alfrescoVersion != null) && supportedVersionsList.contains(alfrescoVersion); System.out.println( "\nAlfresco Environment Validation Tool (for Alfresco Enterprise " + supportedVersions + ")"); System.out.println("------------------------------------------------------------------"); if (parameters.isEmpty() || parameters.containsKey("-?") || parameters.containsKey("--help") || parameters.containsKey("/?") || !parameters.containsKey(DBValidator.PARAMETER_DATABASE_TYPE) || !parameters.containsKey(DBValidator.PARAMETER_DATABASE_HOSTNAME) || !parameters.containsKey(DBValidator.PARAMETER_DATABASE_LOGIN) || !parameters.containsKey(ALFRESCO_VERSION) || !parameters.containsKey(IndexDiskSpeedValidator.PARAMETER_DISK_LOCATION)) { System.out.println(""); System.out.println("usage: evt[.sh|.cmd] [-?|--help] [-v] [-V|-vv]"); System.out.println(" -a alfrescoversion -t databaseType -h databaseHost [-r databasePort]"); System.out.println( " [-d databaseName] -l databaseLogin [-p databasePassword] -i indexlocation"); System.out.println(""); System.out.println("where: -?|--help - display this help"); System.out.println(" -v - produce verbose output"); System.out.println(" -V|-vv - produce super-verbose output (stack traces)"); System.out.println( " alfrescoversion - Version for which the verification is made . May be one of:"); System.out.println( " 4.0.0,4.0.1,4.0.2,4.1.1,4.1.2,4.1.3,4.1.4,4.1.5,4.1.6,4.2"); System.out.println(" databaseType - the type of database. May be one of:"); System.out.println(" mysql, postgresql, oracle, mssqlserver, db2"); System.out.println(" databaseHost - the hostname of the database server"); System.out.println(" databasePort - the port the database is listening on (optional -"); System.out.println(" defaults to default for the database type)"); System.out.println(" databaseName - the name of the Alfresco database (optional -"); System.out.println(" defaults to 'alfresco')"); System.out.println(" databaseLogin - the login Alfresco will use to connect to the"); System.out.println(" database"); System.out.println(" databasePassword - the password for that user (optional)"); System.out.println( " indexlocation - a path to a folder that will contain Alfresco indexes"); System.out.println(""); System.out.println("The tool must be run as the OS user that Alfreso will run as. In particular"); System.out.println("it will report erroneous results if run as \"root\" (or equivalent on other"); System.out.println("OSes) if Alfresco is not intended to be run as that user."); System.out.println(""); } else if (!supportedVersion) { System.out.println(""); System.out.println("Version " + alfrescoVersion + " is not in the list of the Alfresco versions supported by this tool."); System.out.println("Please specify one of the following versions: " + supportedVersions); } else { final StdoutValidatorCallback callback = new StdoutValidatorCallback(); (new AllValidators()).validate(parameters, callback); System.out.println("\n\n **** FINAL GRADE: " + TestResult.typeToString(callback.worstResult) + " ****\n"); } }
From source file:joshelser.as2015.ingester.Ingester.java
public static void main(String[] args) throws Exception { JCommander commander = new JCommander(); final Opts options = new Opts(); commander.addObject(options);/*from w ww . j a va2 s . com*/ commander.setProgramName("Amazon Review Parser"); try { commander.parse(args); } catch (ParameterException ex) { commander.usage(); System.err.println(ex.getMessage()); System.exit(1); } Registry registry = new RegistryImpl(); registry.add(new ReviewMapping()); ClientConfiguration conf = ClientConfiguration.loadDefault(); if (null != options.clientConfFile) { conf = new ClientConfiguration(new PropertiesConfiguration(options.clientConfFile)); } conf.withInstance(options.instanceName).withZkHosts(options.zookeepers); ZooKeeperInstance inst = new ZooKeeperInstance(conf); Connector conn = inst.getConnector(options.user, new PasswordToken(options.password)); if (!conn.tableOperations().exists(options.table)) { conn.tableOperations().create(options.table); } log.info("Writing data from {}", options.file); long count = 0; try (BufferedReader reader = new BufferedReader(new FileReader(options.file)); Store store = new StoreImpl(registry, conn, options.table)) { List<String> schema = parseArray(readLine(reader)); String[] record; while ((record = readLine(reader)) != null) { try { List<String> values = parseArray(record); CsvReview review = new CsvReview(schema, values); store.write(Collections.singleton(review)); count++; } catch (Exception e) { log.error("Failed to parse '" + Arrays.toString(record) + "'", e); } } } log.info("Wrote {} records for {}", count, options.file); }