public static boolean isHostSecured() { final File confFile = PropertiesUtil.findConfigFile("agent.properties"); return confFile != null && confFile.exists() && new File(confFile.getParent() + "/" + CERT_FILENAME).exists(); } }
public static void initDataSource(String propsFileName) throws IOException { Properties dbProps = new Properties(); File dbPropsFile = PropertiesUtil.findConfigFile(propsFileName); if (dbPropsFile != null && dbPropsFile.exists()) { PropertiesUtil.loadFromFile(dbProps, dbPropsFile); initDataSource(dbProps); } }
private void checkAndEnableDynamicRoles(final Connection conn) { final Map<String, String> apiMap = PropertiesUtil.processConfigFile(new String[] { "commands.properties" }); if (apiMap == null || apiMap.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug("No commands.properties file was found, enabling dynamic roles by setting dynamic.apichecker.enabled to true if not already enabled."); } try (final PreparedStatement updateStatement = conn.prepareStatement("INSERT INTO cloud.configuration (category, instance, name, default_value, value) VALUES ('Advanced', 'DEFAULT', 'dynamic.apichecker.enabled', 'false', 'true') ON DUPLICATE KEY UPDATE value='true'")) { updateStatement.executeUpdate(); } catch (SQLException e) { LOG.error("Failed to set dynamic.apichecker.enabled to true, please run migrate-dynamicroles.py script to manually migrate to dynamic roles.", e); } } else { LOG.warn("Old commands.properties static checker is deprecated, please use migrate-dynamicroles.py to migrate to dynamic roles. Refer http://docs.cloudstack.apache.org/projects/cloudstack-administration/en/latest/accounts.html#using-dynamic-roles"); } }
public static Map<String, String> processConfigFile(String[] configFiles) { Map<String, String> configMap = new HashMap<String, String>(); Properties preProcessedCommands = new Properties(); for (String configFile : configFiles) { File commandsFile = findConfigFile(configFile); if (commandsFile != null) { try { loadFromFile(preProcessedCommands, commandsFile); } catch (IOException ioe) { s_logger.error("IO Exception loading properties file", ioe); } } else { // in case of a file within a jar in classpath, try to open stream using url try { loadFromJar(preProcessedCommands, configFile); } catch (IOException e) { s_logger.error("IO Exception loading properties file from jar", e); } } } for (Object key : preProcessedCommands.keySet()) { String preProcessedCommand = preProcessedCommands.getProperty((String)key); int splitIndex = preProcessedCommand.lastIndexOf(";"); String value = preProcessedCommand.substring(splitIndex + 1); configMap.put((String)key, value); } return configMap; }
private Map<String, Object> getDeveloperProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("developer.properties"); if (file == null) { throw new ConfigurationException("Unable to find developer.properties."); } s_logger.info("developer.properties found at " + file.getAbsolutePath()); try { final Properties properties = PropertiesUtil.loadFromFile(file); final String startMac = (String)properties.get("private.macaddr.start"); if (startMac == null) { throw new ConfigurationException("Developers must specify start mac for private ip range"); } final String startIp = (String)properties.get("private.ipaddr.start"); if (startIp == null) { throw new ConfigurationException("Developers must specify start ip for private ip range"); } final Map<String, Object> params = PropertiesUtil.toMap(properties); String endIp = (String)properties.get("private.ipaddr.end"); if (endIp == null) { endIp = getEndIpFromStartIp(startIp, 16); params.put("private.ipaddr.end", endIp); } return params; } 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); } }
/** * Load the file and return the contents as a Properties object. * @param file the file to load * @return A Properties object populated * @throws IOException */ public static Properties loadFromFile(final File file) throws IOException { final Properties properties = new Properties(); loadFromFile(properties, file); return properties; }
InputStream is = null; try { File props = PropertiesUtil.findConfigFile("db.properties"); if (props != null && props.exists()) { is = new FileInputStream(props); is = PropertiesUtil.openStreamFromURL("db.properties");
public Agent(final IAgentShell shell, final int localAgentId, final ServerResource resource) throws ConfigurationException { _shell = shell; _resource = resource; _link = null; resource.setAgentControl(this); final String value = _shell.getPersistentProperty(getResourceName(), "id"); _id = value != null ? Long.parseLong(value) : null; s_logger.info("id is " + (_id != null ? _id : "")); final Map<String, Object> params = PropertiesUtil.toMap(_shell.getProperties()); // merge with properties from command line to let resource access command line parameters for (final Map.Entry<String, Object> cmdLineProp : _shell.getCmdLineProperties().entrySet()) { params.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } if (!_resource.configure(getResourceName(), params)) { throw new ConfigurationException("Unable to configure " + _resource.getName()); } final String host = _shell.getNextHost(); _connection = new NioClient("Agent", host, _shell.getPort(), _shell.getWorkers(), this); // ((NioClient)_connection).setBindAddress(_shell.getPrivateIp()); s_logger.debug("Adding shutdown hook"); Runtime.getRuntime().addShutdownHook(_shutdownThread); _ugentTaskPool = new ThreadPoolExecutor(shell.getPingRetries(), 2 * shell.getPingRetries(), 10, TimeUnit.MINUTES, new SynchronousQueue<Runnable>(), new NamedThreadFactory( "UgentTask")); _executor = new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory( "agentRequest-Handler")); s_logger.info("Agent [id = " + (_id != null ? _id : "new") + " : type = " + getResourceName() + " : zone = " + _shell.getZone() + " : pod = " + _shell.getPod() + " : workers = " + _shell.getWorkers() + " : host = " + host + " : port = " + _shell.getPort()); }
public static Map<String, String> processConfigFile(final String[] configFiles) { final Map<String, String> configMap = new HashMap<>(); final Properties preProcessedCommands = new Properties(); for (final String configFile : configFiles) { final File commandsFile = findConfigFile(configFile); if (commandsFile != null) { try { loadFromFile(preProcessedCommands, commandsFile); } catch (final IOException ioe) { s_logger.error("IO Exception loading properties file", ioe); } } else { // in case of a file within a jar in classpath, try to open stream using url try { loadFromJar(preProcessedCommands, configFile); } catch (final IOException e) { s_logger.error("IO Exception loading properties file from jar", e); } } } for (final Object key : preProcessedCommands.keySet()) { final String preProcessedCommand = preProcessedCommands.getProperty((String) key); final int splitIndex = preProcessedCommand.lastIndexOf(";"); final String value = preProcessedCommand.substring(splitIndex + 1); configMap.put((String) key, value); } return configMap; }
private synchronized boolean loadFromFile(final File file) { try { PropertiesUtil.loadFromFile(_properties, file); _file = file; } catch (FileNotFoundException e) { s_logger.error("How did we get here? ", e); return false; } catch (IOException e) { s_logger.error("IOException: ", e); return false; } return true; }
InputStream is = null; try { final File props = PropertiesUtil.findConfigFile("db.properties"); if (props != null && props.exists()) { is = new FileInputStream(props); is = PropertiesUtil.openStreamFromURL("db.properties");
public final void setUp() throws ConfigurationException { final Map<String, Object> params = PropertiesUtil.toMap(loadProperties());
private String getEnvironmentProperty(String name) { try { final File propsFile = PropertiesUtil.findConfigFile("environment.properties"); if (propsFile == null) { return null; } else { final Properties props = new Properties(); try(final FileInputStream finputstream = new FileInputStream(propsFile);) { props.load(finputstream); }catch (IOException e) { s_logger.error("getEnvironmentProperty:Exception:" + e.getMessage()); } return props.getProperty("mount.parent"); } } catch (Exception e) { return null; } }
void loadProperties() throws ConfigurationException { final File file = PropertiesUtil.findConfigFile("agent.properties"); if (null == file) { throw new ConfigurationException("Unable to find agent.properties."); } s_logger.info("agent.properties found at " + file.getAbsolutePath()); try { PropertiesUtil.loadFromFile(_properties, file); } 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); } }
@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")); }
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { super.configure(name, params); for (String commandPropertyFile : commandPropertyFiles) { processMapping(PropertiesUtil.processConfigFile(new String[] { commandPropertyFile })); } return true; }
public boolean isHostSecured() { // Test for host certificates final File confFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE); if (confFile == null || !confFile.exists() || !Paths.get(confFile.getParent(), KeyStoreUtils.CERT_FILENAME).toFile().exists()) { return false; } // Test for libvirt TLS configuration try { new Connect(String.format("qemu+tls://%s/system", _privateIp)); } catch (final LibvirtException ignored) { return false; } return true; } }
public static SSLContext initClientSSLContext() throws GeneralSecurityException, IOException { char[] passphrase = KeyStoreUtils.DEFAULT_KS_PASSPHRASE; File confFile = PropertiesUtil.findConfigFile("agent.properties"); if (confFile != null) { s_logger.info("Conf file found: " + confFile.getAbsolutePath()); final String pass = PropertiesUtil.loadFromFile(confFile).getProperty(KeyStoreUtils.KS_PASSPHRASE_PROPERTY); if (pass != null) { passphrase = pass.toCharArray();
@Test public void loadPropertiesFromFile() throws IOException { File file = File.createTempFile("test", ".properties"); FileUtils.writeStringToFile(file, "a=b\nc=d\n"); Properties properties = PropertiesUtil.loadFromFile(file); Assert.assertEquals("b", properties.get("a")); }
@Test public void processConfigFile() throws IOException { File tempFile = File.createTempFile("temp", ".properties"); FileUtils.writeStringToFile(tempFile, "a=b\nc=d\n"); Map<String, String> config = PropertiesUtil.processConfigFile(new String[] {tempFile.getAbsolutePath()}); Assert.assertEquals("b", config.get("a")); Assert.assertEquals("d", config.get("c")); tempFile.delete(); } }