use of org.apache.commons.configuration.ConfigurationException in project distributedlog by twitter.
the class ConfigurationSubscription method initConfig.
private boolean initConfig() {
if (fileConfigs.isEmpty()) {
try {
for (FileConfigurationBuilder fileConfigBuilder : fileConfigBuilders) {
FileConfiguration fileConfig = fileConfigBuilder.getConfiguration();
FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();
reloadingStrategy.setRefreshDelay(0);
fileConfig.setReloadingStrategy(reloadingStrategy);
fileConfigs.add(fileConfig);
}
} catch (ConfigurationException ex) {
if (!fileNotFound(ex)) {
LOG.error("Config init failed {}", ex);
}
}
}
return !fileConfigs.isEmpty();
}
use of org.apache.commons.configuration.ConfigurationException in project distributedlog by twitter.
the class DynamicConfigurationFactory method getDynamicConfiguration.
public synchronized Optional<DynamicDistributedLogConfiguration> getDynamicConfiguration(String configPath, ConcurrentBaseConfiguration defaultConf) throws ConfigurationException {
Preconditions.checkNotNull(configPath);
try {
if (!dynamicConfigs.containsKey(configPath)) {
File configFile = new File(configPath);
FileConfigurationBuilder properties = new PropertiesConfigurationBuilder(configFile.toURI().toURL());
DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(defaultConf);
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(properties);
ConfigurationSubscription subscription = new ConfigurationSubscription(dynConf, fileConfigBuilders, executorService, reloadPeriod, reloadUnit);
subscriptions.add(subscription);
dynamicConfigs.put(configPath, dynConf);
LOG.info("Loaded dynamic configuration at {}", configPath);
}
return Optional.of(dynamicConfigs.get(configPath));
} catch (MalformedURLException ex) {
throw new ConfigurationException(ex);
}
}
use of org.apache.commons.configuration.ConfigurationException in project KeyBox by skavanagh.
the class DBInitServlet method init.
/**
* task init method that created DB and generated public/private keys
*
* @param config task config
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
Connection connection = null;
Statement statement = null;
// check if reset ssh application key is set
boolean resetSSHKey = "true".equals(AppConfig.getProperty("resetApplicationSSHKey"));
try {
// if DB password is empty generate a random
if (StringUtils.isEmpty(AppConfig.getProperty("dbPassword"))) {
String dbPassword = null;
String dbPasswordConfirm = null;
if (!"true".equals(System.getProperty("GEN_DB_PASS"))) {
// prompt for password and confirmation
while (dbPassword == null || !dbPassword.equals(dbPasswordConfirm)) {
if (System.console() == null) {
Scanner in = new Scanner(System.in);
System.out.println("Please enter database password: ");
dbPassword = in.nextLine();
System.out.println("Please confirm database password: ");
dbPasswordConfirm = in.nextLine();
} else {
dbPassword = new String(System.console().readPassword("Please enter database password: "));
dbPasswordConfirm = new String(System.console().readPassword("Please confirm database password: "));
}
if (!dbPassword.equals(dbPasswordConfirm)) {
System.out.println("Passwords do not match");
}
}
}
// set password
if (StringUtils.isNotEmpty(dbPassword)) {
AppConfig.encryptProperty("dbPassword", dbPassword);
// if password not set generate a random
} else {
System.out.println("Generating random database password");
AppConfig.encryptProperty("dbPassword", RandomStringUtils.random(32, true, true));
}
// else encrypt password if plain-text
} else if (!AppConfig.isPropertyEncrypted("dbPassword")) {
AppConfig.encryptProperty("dbPassword", AppConfig.getProperty("dbPassword"));
}
connection = DBUtils.getConn();
statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from information_schema.tables where upper(table_name) = 'USERS' and table_schema='PUBLIC'");
if (!rs.next()) {
resetSSHKey = true;
// create DB objects
statement.executeUpdate("create table if not exists users (id INTEGER PRIMARY KEY AUTO_INCREMENT, first_nm varchar, last_nm varchar, email varchar, username varchar not null unique, password varchar, auth_token varchar, auth_type varchar not null default '" + Auth.AUTH_BASIC + "', user_type varchar not null default '" + Auth.ADMINISTRATOR + "', salt varchar, otp_secret varchar, last_login_tm timestamp, expiration_tm timestamp)");
statement.executeUpdate("create table if not exists user_theme (user_id INTEGER PRIMARY KEY, bg varchar(7), fg varchar(7), d1 varchar(7), d2 varchar(7), d3 varchar(7), d4 varchar(7), d5 varchar(7), d6 varchar(7), d7 varchar(7), d8 varchar(7), b1 varchar(7), b2 varchar(7), b3 varchar(7), b4 varchar(7), b5 varchar(7), b6 varchar(7), b7 varchar(7), b8 varchar(7), foreign key (user_id) references users(id) on delete cascade) ");
statement.executeUpdate("create table if not exists system (id INTEGER PRIMARY KEY AUTO_INCREMENT, display_nm varchar not null, username varchar not null, host varchar not null, port INTEGER not null, authorized_keys varchar not null, status_cd varchar not null default 'INITIAL')");
statement.executeUpdate("create table if not exists profiles (id INTEGER PRIMARY KEY AUTO_INCREMENT, nm varchar not null, desc varchar not null)");
statement.executeUpdate("create table if not exists system_map (profile_id INTEGER, system_id INTEGER, foreign key (profile_id) references profiles(id) on delete cascade , foreign key (system_id) references system(id) on delete cascade, primary key (profile_id, system_id))");
statement.executeUpdate("create table if not exists user_map (user_id INTEGER, profile_id INTEGER, foreign key (user_id) references users(id) on delete cascade, foreign key (profile_id) references profiles(id) on delete cascade, primary key (user_id, profile_id))");
statement.executeUpdate("create table if not exists application_key (id INTEGER PRIMARY KEY AUTO_INCREMENT, public_key varchar not null, private_key varchar not null, passphrase varchar)");
statement.executeUpdate("create table if not exists status (id INTEGER, user_id INTEGER, status_cd varchar not null default 'INITIAL', foreign key (id) references system(id) on delete cascade, foreign key (user_id) references users(id) on delete cascade, primary key(id, user_id))");
statement.executeUpdate("create table if not exists scripts (id INTEGER PRIMARY KEY AUTO_INCREMENT, user_id INTEGER, display_nm varchar not null, script varchar not null, foreign key (user_id) references users(id) on delete cascade)");
statement.executeUpdate("create table if not exists public_keys (id INTEGER PRIMARY KEY AUTO_INCREMENT, key_nm varchar not null, type varchar, fingerprint varchar, public_key varchar, enabled boolean not null default true, create_dt timestamp not null default CURRENT_TIMESTAMP(), user_id INTEGER, profile_id INTEGER, foreign key (profile_id) references profiles(id) on delete cascade, foreign key (user_id) references users(id) on delete cascade)");
statement.executeUpdate("create table if not exists session_log (id BIGINT PRIMARY KEY AUTO_INCREMENT, session_tm timestamp default CURRENT_TIMESTAMP, first_nm varchar, last_nm varchar, username varchar not null, ip_address varchar)");
statement.executeUpdate("create table if not exists terminal_log (session_id BIGINT, instance_id INTEGER, output varchar not null, log_tm timestamp default CURRENT_TIMESTAMP, display_nm varchar not null, username varchar not null, host varchar not null, port INTEGER not null, foreign key (session_id) references session_log(id) on delete cascade)");
// if exists readfile to set default password
String salt = EncryptionUtil.generateSalt();
String defaultPassword = EncryptionUtil.hash("changeme" + salt);
// set password if running in EC2
File file = new File("/opt/bastillion/instance_id");
if (file.exists()) {
String str = FileUtils.readFileToString(file, "UTF-8");
if (StringUtils.isNotEmpty(str)) {
defaultPassword = EncryptionUtil.hash(str.trim() + salt);
}
}
// insert default admin user
PreparedStatement pStmt = connection.prepareStatement("insert into users (username, password, user_type, salt) values(?,?,?,?)");
pStmt.setString(1, "admin");
pStmt.setString(2, defaultPassword);
pStmt.setString(3, Auth.MANAGER);
pStmt.setString(4, salt);
pStmt.execute();
DBUtils.closeStmt(pStmt);
}
DBUtils.closeRs(rs);
// if reset ssh application key then generate new key
if (resetSSHKey) {
// delete old key entry
PreparedStatement pStmt = connection.prepareStatement("delete from application_key");
pStmt.execute();
DBUtils.closeStmt(pStmt);
// generate new key and insert passphrase
System.out.println("Setting Bastillion SSH public/private key pair");
// generate application pub/pvt key and get values
String passphrase = SSHUtil.keyGen();
String publicKey = SSHUtil.getPublicKey();
String privateKey = SSHUtil.getPrivateKey();
// insert new keys
pStmt = connection.prepareStatement("insert into application_key (public_key, private_key, passphrase) values(?,?,?)");
pStmt.setString(1, publicKey);
pStmt.setString(2, EncryptionUtil.encrypt(privateKey));
pStmt.setString(3, EncryptionUtil.encrypt(passphrase));
pStmt.execute();
DBUtils.closeStmt(pStmt);
System.out.println("Bastillion Generated Global Public Key:");
System.out.println(publicKey);
// set config to default
AppConfig.updateProperty("publicKey", "");
AppConfig.updateProperty("privateKey", "");
AppConfig.updateProperty("defaultSSHPassphrase", "${randomPassphrase}");
// set to false
AppConfig.updateProperty("resetApplicationSSHKey", "false");
}
// delete ssh keys
SSHUtil.deletePvtGenSSHKey();
DBUtils.closeStmt(statement);
DBUtils.closeConn(connection);
} catch (SQLException | ConfigurationException | IOException | GeneralSecurityException | JSchException ex) {
log.error(ex.toString(), ex);
throw new ServletException(ex.toString(), ex);
}
RefreshAuthKeyUtil.startRefreshAllSystemsTimerTask();
}
use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.
the class HadoopClusterActionHandler method createHadoopConfigFiles.
private void createHadoopConfigFiles(ClusterActionEvent event, ClusterSpec clusterSpec, Cluster cluster) throws IOException {
Map<String, String> deviceMappings = getDeviceMappings(event);
// Velocity is assuming flat classloaders or TCCL to load templates.
// This doesn't work in OSGi unless we set the TCCL to the bundle classloader before invocation
ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
event.getStatementBuilder().addStatements(buildCommon("/tmp/core-site.xml", clusterSpec, cluster), buildHdfs("/tmp/hdfs-site.xml", clusterSpec, cluster, deviceMappings.keySet()), buildMapReduce("/tmp/mapred-site.xml", clusterSpec, cluster, deviceMappings.keySet()), buildHadoopEnv("/tmp/hadoop-env.sh", clusterSpec, cluster), TemplateUtils.createFileFromTemplate("/tmp/hadoop-metrics.properties", event.getTemplateEngine(), getMetricsTemplate(event, clusterSpec, cluster), clusterSpec, cluster));
} catch (ConfigurationException e) {
throw new IOException(e);
} finally {
Thread.currentThread().setContextClassLoader(oldTccl);
}
String devMappings = VolumeManager.asString(deviceMappings);
addStatement(event, call("prepare_all_disks", "'" + devMappings + "'"));
}
use of org.apache.commons.configuration.ConfigurationException in project whirr by apache.
the class ElasticSearchConfigurationBuilder method buildConfig.
/**
* Build a configuration by adding the expected defaults
*/
public static Configuration buildConfig(ClusterSpec spec, Cluster cluster) {
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(spec.getConfiguration());
try {
config.addConfiguration(new PropertiesConfiguration(ElasticSearchConfigurationBuilder.class.getResource("/whirr-elasticsearch-default.properties")));
} catch (ConfigurationException e) {
// this should never happen
LOG.error("Configuration error", e);
}
if ("aws-ec2".equals(spec.getProvider()) || "ec2".equals(spec.getProvider())) {
addDefaultsForEC2(spec, config);
} else {
addDefaultsForUnicast(cluster, config);
}
if (!config.containsKey("es.cluster.name")) {
config.addProperty("es.cluster.name", spec.getClusterName());
}
return config;
}
Aggregations