List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:io.amient.yarn1.YarnClient.java
/** * This method should be called by the implementing application static main * method. It does all the work around creating a yarn application and * submitting the request to the yarn resource manager. The class given in * the appClass argument will be run inside the yarn-allocated master * container./*from w w w. j a v a 2s .c o m*/ */ public static void submitApplicationMaster(Properties appConfig, Class<? extends YarnMaster> masterClass, String[] args, Boolean awaitCompletion) throws Exception { log.info("Yarn1 App Configuration:"); for (Object param : appConfig.keySet()) { log.info(param.toString() + " = " + appConfig.get(param).toString()); } String yarnConfigPath = appConfig.getProperty("yarn1.site", "/etc/hadoop"); String masterClassName = masterClass.getName(); appConfig.setProperty("yarn1.master.class", masterClassName); String applicationName = appConfig.getProperty("yarn1.application.name", masterClassName); log.info("--------------------------------------------------------------"); if (Boolean.valueOf(appConfig.getProperty("yarn1.local.mode", "false"))) { YarnMaster.run(appConfig, args); return; } int masterPriority = Integer.valueOf( appConfig.getProperty("yarn1.master.priority", String.valueOf(YarnMaster.DEFAULT_MASTER_PRIORITY))); int masterMemoryMb = Integer.valueOf(appConfig.getProperty("yarn1.master.memory.mb", String.valueOf(YarnMaster.DEFAULT_MASTER_MEMORY_MB))); int masterNumCores = Integer.valueOf( appConfig.getProperty("yarn1.master.num.cores", String.valueOf(YarnMaster.DEFAULT_MASTER_CORES))); String queue = appConfig.getProperty("yarn1.queue"); Configuration yarnConfig = new YarnConfiguration(); yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/core-site.xml")); yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/hdfs-site.xml")); yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/yarn-site.xml")); for (Map.Entry<Object, Object> entry : appConfig.entrySet()) { yarnConfig.set(entry.getKey().toString(), entry.getValue().toString()); } final org.apache.hadoop.yarn.client.api.YarnClient yarnClient = org.apache.hadoop.yarn.client.api.YarnClient .createYarnClient(); yarnClient.init(yarnConfig); yarnClient.start(); for (NodeReport report : yarnClient.getNodeReports(NodeState.RUNNING)) { log.debug("Node report:" + report.getNodeId() + " @ " + report.getHttpAddress() + " | " + report.getCapability()); } log.info("Submitting application master class " + masterClassName); YarnClientApplication app = yarnClient.createApplication(); GetNewApplicationResponse appResponse = app.getNewApplicationResponse(); final ApplicationId appId = appResponse.getApplicationId(); if (appId == null) { System.exit(111); } else { appConfig.setProperty("am.timestamp", String.valueOf(appId.getClusterTimestamp())); appConfig.setProperty("am.id", String.valueOf(appId.getId())); } YarnClient.distributeResources(yarnConfig, appConfig, applicationName); String masterJvmArgs = appConfig.getProperty("yarn1.master.jvm.args", ""); YarnContainerContext masterContainer = new YarnContainerContext(yarnConfig, appConfig, masterJvmArgs, masterPriority, masterMemoryMb, masterNumCores, applicationName, YarnMaster.class, args); ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext(); appContext.setApplicationName(masterClassName); appContext.setResource(masterContainer.capability); appContext.setPriority(masterContainer.priority); appContext.setQueue(queue); appContext.setApplicationType(appConfig.getProperty("yarn1.application.type", "YARN")); appContext.setAMContainerSpec(masterContainer.createContainerLaunchContext()); log.info("Master container spec: " + masterContainer.capability); yarnClient.submitApplication(appContext); ApplicationReport report = yarnClient.getApplicationReport(appId); log.info("Tracking URL: " + report.getTrackingUrl()); if (awaitCompletion) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (!yarnClient.isInState(Service.STATE.STOPPED)) { log.info("Killing yarn application in shutdown hook"); try { yarnClient.killApplication(appId); } catch (Throwable e) { log.error("Failed to kill yarn application - please check YARN Resource Manager", e); } } } }); float lastProgress = -0.0f; while (true) { try { Thread.sleep(10000); report = yarnClient.getApplicationReport(appId); if (lastProgress != report.getProgress()) { lastProgress = report.getProgress(); log.info(report.getApplicationId() + " " + (report.getProgress() * 100.00) + "% " + (System.currentTimeMillis() - report.getStartTime()) + "(ms) " + report.getDiagnostics()); } if (!report.getFinalApplicationStatus().equals(FinalApplicationStatus.UNDEFINED)) { log.info(report.getApplicationId() + " " + report.getFinalApplicationStatus()); log.info("Tracking url: " + report.getTrackingUrl()); log.info("Finish time: " + ((System.currentTimeMillis() - report.getStartTime()) / 1000) + "(s)"); break; } } catch (Throwable e) { log.error("Master Heart Beat Error - terminating", e); yarnClient.killApplication(appId); Thread.sleep(2000); } } yarnClient.stop(); if (!report.getFinalApplicationStatus().equals(FinalApplicationStatus.SUCCEEDED)) { System.exit(112); } } yarnClient.stop(); }
From source file:de.rub.syssec.saaf.Main.java
/** * Load or update log4j properties from 'conf/log4j.properties' file. If * useColor is set, the Appender Layout is overwritten with the * ANSIColorLayout.// w w w .ja v a 2 s.c o m * * @author Hanno Lemoine <hanno.lemoine@gdata.de> * @param useColor * Boolean to activate ANSIColorLayout. * @param inverseColor * set if you have a white background */ private static void updateLog4jConfiguration(Boolean useColor, Boolean inverseColor) { Properties log4j_props = new Properties(); try { log4j_props.load(new FileInputStream("conf/log4j.properties")); } catch (IOException e) { System.err.println("Error: Cannot laod log4j configuration file. Exiting."); exit(); } if (useColor) { log4j_props.setProperty("log4j.appender.A1.layout", "de.rub.syssec.saaf.misc.log4j.ANSIColorLayout"); } if (useColor && inverseColor) { // final String cWhite = "\u001B[1;37m"; final String cBlack = "\u001B[0;30m"; final String cGray = "\u001B[1;30m"; final String cRed = "\u001B[0;31m"; final String cYel = "\u001B[1;33m"; final String cCya = "\u001B[0;36m"; log4j_props.setProperty("log4j.appender.A1.layout.all", cBlack); log4j_props.setProperty("log4j.appender.A1.layout.fatal", cRed); log4j_props.setProperty("log4j.appender.A1.layout.error", cRed); log4j_props.setProperty("log4j.appender.A1.layout.warn", cYel); log4j_props.setProperty("log4j.appender.A1.layout.info", cGray); log4j_props.setProperty("log4j.appender.A1.layout.debug", cCya); log4j_props.setProperty("log4j.appender.A1.layout.stacktrace", cRed); log4j_props.setProperty("log4j.appender.A1.layout.defaultcolor", cBlack); } LogManager.resetConfiguration(); PropertyConfigurator.configure(log4j_props); }
From source file:com.tesora.dve.common.PEFileUtils.java
private static Properties encrypt(Properties props) throws PEException { // we are going to iterate over all properties looking for any that // contain the string "password" for (String key : props.stringPropertyNames()) { if (StringUtils.containsIgnoreCase(key, "password")) { String value = props.getProperty(key); if (!StringUtils.isBlank(value)) { props.setProperty(key, PECryptoUtils.encrypt(value)); }// w w w. j a v a 2 s .c o m } } return props; }
From source file:com.tesora.dve.common.PEFileUtils.java
private static Properties decrypt(Properties props) throws PEException { // we are going to iterate over all properties looking for any that // contain the string "password" for (String key : props.stringPropertyNames()) { if (StringUtils.containsIgnoreCase(key, "password")) { String value = props.getProperty(key); if (!StringUtils.isBlank(value)) { props.setProperty(key, PECryptoUtils.decrypt(value)); }//from w w w. j a v a 2s. c om } } return props; }
From source file:emperior.Main.java
public static void updateResumeTask(String task) { if (!adminmode) { Properties properties = new Properties(); try {//from w w w. j a v a 2 s.co m BufferedInputStream stream = new BufferedInputStream(new FileInputStream("Emperior.properties")); properties.load(stream); properties.setProperty("resumetask", task); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("Emperior.properties")); properties.store(out, ""); out.close(); stream.close(); } catch (Exception e) { } } }
From source file:emperior.Main.java
public static void updateStartedWithTask(String task) { if (!adminmode) { Properties properties = new Properties(); try {/*from ww w . j a v a 2 s . com*/ BufferedInputStream stream = new BufferedInputStream(new FileInputStream("Emperior.properties")); properties.load(stream); properties.setProperty("startedwith", task); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("Emperior.properties")); properties.store(out, ""); out.close(); stream.close(); } catch (Exception e) { } } }
From source file:gobblin.util.ConfigUtils.java
/** * Convert a given {@link Config} instance to a {@link Properties} instance. * * @param config the given {@link Config} instance * @param prefix an optional prefix; if present, only properties whose name starts with the prefix * will be returned.// w w w . j ava 2 s. co m * @return a {@link Properties} instance */ public static Properties configToProperties(Config config, Optional<String> prefix) { Properties properties = new Properties(); if (config != null) { Config resolvedConfig = config.resolve(); for (Map.Entry<String, ConfigValue> entry : resolvedConfig.entrySet()) { if (!prefix.isPresent() || entry.getKey().startsWith(prefix.get())) { String propKey = desanitizeKey(entry.getKey()); properties.setProperty(propKey, resolvedConfig.getString(entry.getKey())); } } } return properties; }
From source file:Main.java
public static boolean setProperty(String filePath, String fileName, String propertyName, Map<String, String> propertyValueMap) { try {// www. j ava2s.co m Properties p = loadPropertyInstance(filePath, fileName); StringBuilder propertyValue = new StringBuilder(); if (propertyValueMap != null && propertyValueMap.size() > 0) { for (String key : propertyValueMap.keySet()) { propertyValue.append(key.replaceAll("\\\\", "\\\\\\\\").replaceAll("(\\\\)+$", "") .replaceAll("\\,", "\\\\,").replaceAll(";", "\\\\;") + "," + propertyValueMap.get(key).replaceAll("(\\\\)+$", "").replaceAll("\\\\", "\\\\\\\\") .replaceAll("\\,", "\\\\,").replaceAll(";", "\\\\;") + ";"); } } p.setProperty(propertyName, propertyValue.toString()); String comment = "Update '" + propertyName + "' value"; return storePropertyInstance(filePath, fileName, p, comment); } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:com.wdt.java.OptionControlClass.java
public static void processArgsLogic(CommandLine line, Options options) { Properties dbSettings = new Properties(); ParsParams pp = new ParsParams(); Properties mainProperties = new Properties(); String propFile = new String(); String tableName = new String(); String tableOwner = new String(); DataBaseIO dbIO = new DataBaseIO(); if (line.hasOption("?")) { usage(options);//from w w w. j a va2s . c o m return; } //check if direction defined if (!line.hasOption("conffile")) { if (!line.hasOption("url") || !line.hasOption("passwd") || !line.hasOption("user")) { error(options, "Please define either \"conffile\" or connection properties (url, passwd, user)!"); return; } else { dbSettings.setProperty("ORACLE_DB_URL", line.getOptionValue("url")); dbSettings.setProperty("ORACLE_DB_USERNAME", line.getOptionValue("user")); dbSettings.setProperty("ORACLE_DB_PASSWORD", line.getOptionValue("passwd")); } } else { dbSettings = dbIO.getDBproperties(line.getOptionValue("conffile")); } DataSource ods = dbIO.getDS(dbSettings); dbIO.setDs(ods); if ((!line.hasOption("propTableName")) || (!line.hasOption("propTableOwner")) || (!line.hasOption("propertieFile"))) { error(options, "propertieFile, propTableName, propTableOwner are mandatory to define."); return; } else { tableName = line.getOptionValue("propTableName"); tableOwner = line.getOptionValue("propTableOwner"); propFile = line.getOptionValue("propertieFile"); } if (line.hasOption("db2file")) { mainProperties = dbIO.readPropertiesFromDB(tableOwner, tableName); pp.writePropertiesToFile(propFile, mainProperties); } else if (line.hasOption("file2db")) { mainProperties = pp.getPropertiesFromFile(propFile); dbIO.deletePropertiesFromDB(tableOwner, tableName); dbIO.insertPropertiesInDB(mainProperties, tableOwner, tableName); } else { error(options, "You should define db2file or file2db"); } }
From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java
private static Properties generateInternalNames(String datasetName) { // String ds = datasetName; if (datasetName.length() > TBLNAMELEN) datasetName = datasetName.substring(0, TBLNAMELEN); // not fool proof... but Properties tableNames = new Properties(); tableNames.setProperty(Constants.NAME_TABLE_DIRECT_PRIMARY_HASH, datasetName + "_DPH"); tableNames.setProperty(Constants.NAME_TABLE_DIRECT_SECONDARY_HASH, datasetName + "_DS"); tableNames.setProperty(Constants.NAME_TABLE_REVERSE_PRIMARY_HASH, datasetName + "_RPH"); tableNames.setProperty(Constants.NAME_TABLE_REVERSE_SECONDARY_HASH, datasetName + "_RS"); tableNames.setProperty(Constants.NAME_TABLE_LONG_STRINGS, datasetName + "_LSTR"); tableNames.setProperty(Constants.NAME_TABLE_BASIC_STATS, datasetName + "_BASESTATS"); tableNames.setProperty(Constants.NAME_TABLE_TOPK_STATS, datasetName + "_TOPKSTATS"); tableNames.setProperty(Constants.NAME_TABLE_DATATYPE, datasetName + "_DT"); return tableNames; }