MIFOSX-949 cleaning up db upgrades and externalizing remaining properties

This commit is contained in:
Vishwas Babu A J
2014-03-25 17:10:17 -07:00
parent d079442e0e
commit 0ca68e98d5
6 changed files with 112 additions and 25 deletions
@@ -0,0 +1,14 @@
ALTER TABLE `tenants`
ADD COLUMN `pool_initial_size` int(5) DEFAULT 5 AFTER `auto_update`,
ADD COLUMN `pool_validation_interval` int(11) DEFAULT 30000,
ADD COLUMN `pool_remove_abandoned` tinyint(1) DEFAULT 1,
ADD COLUMN `pool_remove_abandoned_timeout` int(5) DEFAULT 60,
ADD COLUMN `pool_log_abandoned` tinyint(1) DEFAULT 1,
ADD COLUMN `pool_abandon_when_percentage_full` int(5) DEFAULT 50,
ADD COLUMN `pool_test_on_borrow` tinyint(1) DEFAULT 1,
ADD COLUMN `pool_max_active` int(5) DEFAULT 40,
ADD COLUMN `pool_min_idle` int(5) DEFAULT 20,
ADD COLUMN `pool_max_idle` int(5) DEFAULT 10,
ADD COLUMN `pool_suspect_timeout` int(5) DEFAULT 60,
ADD COLUMN `pool_time_between_eviction_runs_millis` int(11) DEFAULT 34000,
ADD COLUMN `pool_min_evictable_idle_time_millis` int(11) DEFAULT 60000;
@@ -73,13 +73,19 @@ CREATE TABLE `tenants` (
`schema_username` varchar(100) NOT NULL DEFAULT 'root',
`schema_password` varchar(100) NOT NULL DEFAULT 'mysql',
`auto_update` tinyint(1) NOT NULL DEFAULT '1',
`initial_size` int(5) DEFAULT NULL,
`validation_interval` int(60) DEFAULT NULL,
`remove_abandoned` varchar(10) DEFAULT NULL,
`remove_abandoned_timeout` int(10) DEFAULT NULL,
`log_abandoned` varchar(10) DEFAULT NULL,
`abondoned_when_percentage_full` int(10) DEFAULT NULL,
`test_on_borrow` varchar(10) DEFAULT NULL,
`pool_initial_size` int(5) DEFAULT 5,
`pool_validation_interval` int(11) DEFAULT 30000,
`pool_remove_abandoned` tinyint(1) DEFAULT 1,
`pool_remove_abandoned_timeout` int(5) DEFAULT 60,
`pool_log_abandoned` tinyint(1) DEFAULT 1,
`pool_abandon_when_percentage_full` int(5) DEFAULT 50,
`pool_test_on_borrow` tinyint(1) DEFAULT 1,
`pool_max_active` int(5) DEFAULT 40,
`pool_min_idle` int(5) DEFAULT 20,
`pool_max_idle` int(5) DEFAULT 10,
`pool_suspect_timeout` int(5) DEFAULT 60,
`pool_time_between_eviction_runs_millis` int(11) DEFAULT 34000,
`pool_min_evictable_idle_time_millis` int(11) DEFAULT 60000,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -24,11 +24,19 @@ public class MifosPlatformTenant {
private final int removeAbandonedTimeout;
private final boolean logAbandoned;
private final int abandonWhenPercentageFull;
private final int maxActive;
private final int minIdle;
private final int maxIdle;
private final int suspectTimeout;
private final int timeBetweenEvictionRunsMillis;
private final int minEvictableIdleTimeMillis;
public MifosPlatformTenant(final Long id, final String tenantIdentifier, final String name, final String schemaName,
final String schemaServer, final String schemaServerPort, final String schemaUsername, final String schemaPassword,
final String timezoneId, final boolean autoUpdateEnabled,final int initialSize,final boolean testOnBorrow,final long validationInterval,
final boolean removeAbandoned,final int removeAbandonedTimeout,final boolean logAbandoned,final int abandonWhenPercentageFull) {
final String schemaServer, final String schemaServerPort, final String schemaUsername, final String schemaPassword,
final String timezoneId, final boolean autoUpdateEnabled, final int initialSize, final boolean testOnBorrow,
final long validationInterval, final boolean removeAbandoned, final int removeAbandonedTimeout, final boolean logAbandoned,
final int abandonWhenPercentageFull, final int maxActive, final int minIdle, final int maxIdle, final int suspectTimeout,
final int timeBetweenEvictionRunsMillis, final int minEvictableIdleTimeMillis) {
this.id = id;
this.tenantIdentifier = tenantIdentifier;
this.name = name;
@@ -46,6 +54,12 @@ public class MifosPlatformTenant {
this.removeAbandonedTimeout = removeAbandonedTimeout;
this.logAbandoned = logAbandoned;
this.abandonWhenPercentageFull = abandonWhenPercentageFull;
this.maxActive = maxActive;
this.minIdle = minIdle;
this.maxIdle = maxIdle;
this.suspectTimeout = suspectTimeout;
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
}
public String databaseURL() {
@@ -54,6 +68,26 @@ public class MifosPlatformTenant {
return url;
}
public int getMaxActive() {
return this.maxActive;
}
public int getMinIdle() {
return this.minIdle;
}
public int getMaxIdle() {
return this.maxIdle;
}
public int getTimeBetweenEvictionRunsMillis() {
return this.timeBetweenEvictionRunsMillis;
}
public int getMinEvictableIdleTimeMillis() {
return this.minEvictableIdleTimeMillis;
}
public int getInitialSize() {
return initialSize;
}
@@ -114,4 +148,8 @@ public class MifosPlatformTenant {
return this.autoUpdateEnabled;
}
public int getSuspectTimeout() {
return this.suspectTimeout;
}
}
@@ -74,13 +74,6 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
poolConfiguration.setPassword(tenant.getSchemaPassword());
poolConfiguration.setInitialSize(tenant.getInitialSize());
// poolConfiguration.setMaxActive(5);
// poolConfiguration.setMinIdle(1);
// poolConfiguration.setMaxIdle(4);
// poolConfiguration.setSuspectTimeout(60);
// poolConfiguration.setTimeBetweenEvictionRunsMillis(30000);
// poolConfiguration.setMinEvictableIdleTimeMillis(60000);
poolConfiguration.setTestOnBorrow(tenant.isTestOnBorrow());
poolConfiguration.setValidationQuery("SELECT 1");
@@ -91,6 +84,18 @@ public class TomcatJdbcDataSourcePerTenantService implements RoutingDataSourceSe
poolConfiguration.setLogAbandoned(tenant.isLogAbandoned());
poolConfiguration.setAbandonWhenPercentageFull(tenant.getAbandonWhenPercentageFull());
/**
* Vishwas- Do we need to enable the below properties and add
* ResetAbandonedTimer for long running batch Jobs?
**/
//poolConfiguration.setMaxActive(tenant.getMaxActive());
//poolConfiguration.setMinIdle(tenant.getMinIdle());
//poolConfiguration.setMaxIdle(tenant.getMaxIdle());
//poolConfiguration.setSuspectTimeout(tenant.getSuspectTimeout());
//poolConfiguration.setTimeBetweenEvictionRunsMillis(tenant.getTimeBetweenEvictionRunsMillis());
//poolConfiguration.setMinEvictableIdleTimeMillis(tenant.getMinEvictableIdleTimeMillis());
poolConfiguration.setJdbcInterceptors("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;"
+ "org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport");
@@ -38,7 +38,12 @@ public class BasicAuthTenantDetailsServiceJdbc implements BasicAuthTenantDetails
private final StringBuilder sqlBuilder = new StringBuilder(
"id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")//
.append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ,initial_size as initialSize,validation_interval as validationInterval,remove_abandoned as removeAbandoned,remove_abandoned_timeout as removeAbandonedTimeout,log_abandoned as logAbandoned,abondoned_when_percentage_full as abondonedWhenPercentageFull,test_on_borrow as testOnBorrow ")//
.append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId , pool_initial_size as initialSize, ") //
.append(" pool_validation_interval as validationInterval, pool_remove_abandoned as removeAbandoned, pool_remove_abandoned_timeout as removeAbandonedTimeout, ")//
.append(" pool_log_abandoned as logAbandoned, pool_abandon_when_percentage_full as abandonedWhenPercentageFull, pool_test_on_borrow as testOnBorrow, ")//
.append(" pool_max_active as poolMaxActive, pool_min_idle as poolMinIdle, pool_max_idle as poolMaxIdle, ")//
.append(" pool_suspect_timeout as poolSuspectTimeout, pool_time_between_eviction_runs_millis as poolTimeBetweenEvictionRunsMillis, ")//
.append(" pool_min_evictable_idle_time_millis as poolMinEvictableIdleTimeMillis ")//
.append(" from tenants t");//
public String schema() {
@@ -64,11 +69,18 @@ public class BasicAuthTenantDetailsServiceJdbc implements BasicAuthTenantDetails
final boolean removeAbandoned = rs.getBoolean("removeAbandoned");
final int removeAbandonedTimeout = rs.getInt("removeAbandonedTimeout");
final boolean logAbandoned = rs.getBoolean("logAbandoned");
final int abandonWhenPercentageFull = rs.getInt("abondonedWhenPercentageFull");
final int abandonWhenPercentageFull = rs.getInt("abandonedWhenPercentageFull");
final int maxActive = rs.getInt("poolMaxActive");
final int minIdle = rs.getInt("poolMinIdle");
final int maxIdle = rs.getInt("poolMaxIdle");
final int suspectTimeout = rs.getInt("poolSuspectTimeout");
final int timeBetweenEvictionRunsMillis = rs.getInt("poolTimeBetweenEvictionRunsMillis");
final int minEvictableIdleTimeMillis = rs.getInt("poolMinEvictableIdleTimeMillis");
return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername,
schemaPassword, timezoneId, autoUpdateEnabled,initialSize,testOnBorrow,validationInterval,removeAbandoned,removeAbandonedTimeout
,logAbandoned,abandonWhenPercentageFull);
schemaPassword, timezoneId, autoUpdateEnabled, initialSize, testOnBorrow, validationInterval, removeAbandoned,
removeAbandonedTimeout, logAbandoned, abandonWhenPercentageFull, maxActive, minIdle, maxIdle, suspectTimeout,
timeBetweenEvictionRunsMillis, minEvictableIdleTimeMillis);
}
}
@@ -39,7 +39,12 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
private final StringBuilder sqlBuilder = new StringBuilder(
"id, name,identifier, schema_name as schemaName, schema_server as schemaServer, schema_server_port as schemaServerPort, auto_update as autoUpdate, ")//
.append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId ,initial_size as initialSize,validation_interval as validationInterval,remove_abandoned as removeAbandoned,remove_abandoned_timeout as removeAbandonedTimeout,log_abandoned as logAbandoned,abondoned_when_percentage_full as abondonedWhenPercentageFull,test_on_borrow as testOnBorrow ")//
.append(" schema_username as schemaUsername, schema_password as schemaPassword , timezone_id as timezoneId , pool_initial_size as initialSize, ") //
.append(" pool_validation_interval as validationInterval, pool_remove_abandoned as removeAbandoned, pool_remove_abandoned_timeout as removeAbandonedTimeout, ")//
.append(" pool_log_abandoned as logAbandoned, pool_abandon_when_percentage_full as abandonedWhenPercentageFull, pool_test_on_borrow as testOnBorrow, ")//
.append(" pool_max_active as poolMaxActive, pool_min_idle as poolMinIdle, pool_max_idle as poolMaxIdle, ")//
.append(" pool_suspect_timeout as poolSuspectTimeout, pool_time_between_eviction_runs_millis as poolTimeBetweenEvictionRunsMillis, ")//
.append(" pool_min_evictable_idle_time_millis as poolMinEvictableIdleTimeMillis ")//
.append(" from tenants t");//
public String schema() {
@@ -65,11 +70,18 @@ public class JdbcTenantDetailsService implements TenantDetailsService {
final boolean removeAbandoned = rs.getBoolean("removeAbandoned");
final int removeAbandonedTimeout = rs.getInt("removeAbandonedTimeout");
final boolean logAbandoned = rs.getBoolean("logAbandoned");
final int abandonWhenPercentageFull = rs.getInt("abondonedWhenPercentageFull");
final int abandonWhenPercentageFull = rs.getInt("abandonedWhenPercentageFull");
final int maxActive = rs.getInt("poolMaxActive");
final int minIdle = rs.getInt("poolMinIdle");
final int maxIdle = rs.getInt("poolMaxIdle");
final int suspectTimeout = rs.getInt("poolSuspectTimeout");
final int timeBetweenEvictionRunsMillis = rs.getInt("poolTimeBetweenEvictionRunsMillis");
final int minEvictableIdleTimeMillis = rs.getInt("poolMinEvictableIdleTimeMillis");
return new MifosPlatformTenant(id, tenantIdentifier, name, schemaName, schemaServer, schemaServerPort, schemaUsername,
schemaPassword, timezoneId, autoUpdateEnabled,initialSize,testOnBorrow,validationInterval,removeAbandoned,removeAbandonedTimeout
,logAbandoned,abandonWhenPercentageFull);
schemaPassword, timezoneId, autoUpdateEnabled, initialSize, testOnBorrow, validationInterval, removeAbandoned,
removeAbandonedTimeout, logAbandoned, abandonWhenPercentageFull, maxActive, minIdle, maxIdle, suspectTimeout,
timeBetweenEvictionRunsMillis, minEvictableIdleTimeMillis);
}
}