@Before public void setup() throws IOException { final Properties properties = new Properties(); PropertiesUtil.loadFromFile(properties, PropertiesUtil.findConfigFile("config.properties")); api = new NiciraNvpApi(); api.setControllerAddress(properties.getProperty("nvp.host")); api.setAdminCredentials( properties.getProperty("nvp.admin.user"), properties.getProperty("nvp.admin.pwd")); }
private static void initialize() { final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); final Properties dbProps; if (EncryptionSecretKeyChecker.useEncryption()) { StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor(); dbProps = new EncryptableProperties(encryptor); try { dbProps.load(new FileInputStream(dbPropsFile)); } catch (FileNotFoundException e) { throw new CloudRuntimeException( "db.properties file not found while reading DB secret key", e); } catch (IOException e) { throw new CloudRuntimeException("Erroe while reading DB secret key from db.properties", e); } String dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret"); if (dbSecretKey == null || dbSecretKey.isEmpty()) { throw new CloudRuntimeException("Empty DB secret key in db.properties"); } s_encryptor = new StandardPBEStringEncryptor(); s_encryptor.setAlgorithm("PBEWithMD5AndDES"); s_encryptor.setPassword(dbSecretKey); } else { throw new CloudRuntimeException("Trying to encrypt db values when encrytion is not enabled"); } }
@Test public void loadFromFile() throws IOException { File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); Properties properties = new Properties(); PropertiesUtil.loadFromFile(properties, file); Assert.assertEquals("b", properties.get("a")); }
static { File file = PropertiesUtil.findConfigFile("environment.properties"); if (file == null) { s_logger.debug("Unable to find environment.properties"); } else { FileInputStream finputstream; try { finputstream = new FileInputStream(file); final Properties props = new Properties(); props.load(finputstream); finputstream.close(); String search = props.getProperty("manage.xenserver.pool.master"); if (search != null) { s_managePool = Boolean.parseBoolean(search); } search = props.getProperty("sleep.interval.on.error"); if (search != null) { s_sleepOnError = NumbersUtil.parseInterval(search, 10) * 1000; } s_logger.info( "XenServer Connection Pool Configs: manage.xenserver.pool.master=" + s_managePool + "; sleep.interval.on.error=" + s_sleepOnError); } catch (FileNotFoundException e) { s_logger.debug("File is not found", e); } catch (IOException e) { s_logger.debug("IO Exception while reading file", e); } } try { javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; javax.net.ssl.TrustManager tm = new TrustAllManager(); trustAllCerts[0] = tm; javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, null); javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HostnameVerifier hv = new HostnameVerifier() { @Override public boolean verify(String hostName, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(hv); } catch (Exception e) { } }
public void init(String[] args) throws ConfigurationException { // PropertiesUtil is used both in management server and agent packages, // it searches path under class path and common J2EE containers // For KVM agent, do it specially here File file = new File("/etc/cloudstack/agent/log4j-cloud.xml"); if (!file.exists()) { file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); } DOMConfigurator.configureAndWatch(file.getAbsolutePath()); s_logger.info("Agent started"); final Class<?> c = this.getClass(); _version = c.getPackage().getImplementationVersion(); if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); } s_logger.info("Implementation Version is " + _version); loadProperties(); parseCommand(args); if (s_logger.isDebugEnabled()) { List<String> properties = Collections.list((Enumeration<String>) _properties.propertyNames()); for (String property : properties) { s_logger.debug("Found property: " + property); } } s_logger.info("Defaulting to using properties file for storage"); _storage = new PropertiesStorage(); _storage.configure("Storage", new HashMap<String, Object>()); // merge with properties from command line to let resource access // command line parameters for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties().entrySet()) { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } s_logger.info("Defaulting to the constant time backoff algorithm"); _backoff = new ConstantTimeBackoff(); _backoff.configure("ConstantTimeBackoff", new HashMap<String, Object>()); }
void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (file == null) { throw new ConfigurationException("Unable to find agent.properties."); } s_logger.info("agent.properties found at " + file.getAbsolutePath()); InputStream propertiesStream = null; try { propertiesStream = new FileInputStream(file); _properties.load(propertiesStream); } catch (final FileNotFoundException ex) { throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex); } catch (final IOException ex) { throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex); } finally { IOUtils.closeQuietly(propertiesStream); } }
@Test public void findConfigFile() { File configFile = PropertiesUtil.findConfigFile("notexistingresource"); Assert.assertNull(configFile); }