mirror of https://github.com/apache/cloudstack.git
fix simulator compilation
This commit is contained in:
parent
b060bb054e
commit
e903f83872
|
|
@ -80,6 +80,7 @@ public class Transaction {
|
|||
public static final short CLOUD_DB = 0;
|
||||
public static final short USAGE_DB = 1;
|
||||
public static final short AWSAPI_DB = 2;
|
||||
public static final short SIMULATOR_DB = 3;
|
||||
public static final short CONNECTED_DB = -1;
|
||||
|
||||
private static AtomicLong s_id = new AtomicLong();
|
||||
|
|
@ -224,6 +225,7 @@ public class Transaction {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getStandaloneAwsapiConnection() {
|
||||
try {
|
||||
Connection conn = s_awsapiDS.getConnection();
|
||||
|
|
@ -235,7 +237,21 @@ public class Transaction {
|
|||
s_logger.warn("Unexpected exception: ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getStandaloneSimulatorConnection() {
|
||||
try {
|
||||
Connection conn = s_simulatorDS.getConnection();
|
||||
if (s_connLogger.isTraceEnabled()) {
|
||||
s_connLogger.trace("Retrieving a standalone connection for simulator: dbconn" + System.identityHashCode(conn));
|
||||
}
|
||||
return conn;
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn("Unexpected exception: ", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void attach(TransactionAttachment value) {
|
||||
_stack.push(new StackElement(ATTACHMENT, value));
|
||||
}
|
||||
|
|
@ -546,6 +562,14 @@ public class Transaction {
|
|||
}
|
||||
break;
|
||||
|
||||
case SIMULATOR_DB:
|
||||
if(s_simulatorDS != null) {
|
||||
_conn = s_simulatorDS.getConnection();
|
||||
} else {
|
||||
s_logger.warn("A static-initialized variable becomes null, process is dying?");
|
||||
throw new CloudRuntimeException("Database is not initialized, process is dying?");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
throw new CloudRuntimeException("No database selected for the transaction");
|
||||
|
|
@ -976,6 +1000,7 @@ public class Transaction {
|
|||
private static DataSource s_ds;
|
||||
private static DataSource s_usageDS;
|
||||
private static DataSource s_awsapiDS;
|
||||
private static DataSource s_simulatorDS;
|
||||
static {
|
||||
try {
|
||||
final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
|
||||
|
|
@ -1069,6 +1094,27 @@ public class Transaction {
|
|||
new StackKeyedObjectPoolFactory(), null, false, false);
|
||||
s_awsapiDS = new PoolingDataSource(awsapiPoolableConnectionFactory.getPool());
|
||||
|
||||
try{
|
||||
// configure the simulator db
|
||||
final int simulatorMaxActive = Integer.parseInt(dbProps.getProperty("db.simulator.maxActive"));
|
||||
final int simulatorMaxIdle = Integer.parseInt(dbProps.getProperty("db.simulator.maxIdle"));
|
||||
final long simulatorMaxWait = Long.parseLong(dbProps.getProperty("db.simulator.maxWait"));
|
||||
final String simulatorUsername = dbProps.getProperty("db.simulator.username");
|
||||
final String simulatorPassword = dbProps.getProperty("db.simulator.password");
|
||||
final String simulatorHost = dbProps.getProperty("db.simulator.host");
|
||||
final int simulatorPort = Integer.parseInt(dbProps.getProperty("db.simulator.port"));
|
||||
final String simulatorDbName = dbProps.getProperty("db.simulator.name");
|
||||
final boolean simulatorAutoReconnect = Boolean.parseBoolean(dbProps.getProperty("db.simulator.autoReconnect"));
|
||||
final GenericObjectPool simulatorConnectionPool = new GenericObjectPool(null, simulatorMaxActive, GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
|
||||
simulatorMaxWait, simulatorMaxIdle);
|
||||
final ConnectionFactory simulatorConnectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://"+simulatorHost + ":" + simulatorPort + "/" + simulatorDbName +
|
||||
"?autoReconnect="+simulatorAutoReconnect, simulatorUsername, simulatorPassword);
|
||||
final PoolableConnectionFactory simulatorPoolableConnectionFactory = new PoolableConnectionFactory(simulatorConnectionFactory, simulatorConnectionPool,
|
||||
new StackKeyedObjectPoolFactory(), null, false, false);
|
||||
s_simulatorDS = new PoolingDataSource(simulatorPoolableConnectionFactory.getPool());
|
||||
} catch (Exception e){
|
||||
s_logger.debug("Simulator DB properties are not available. Not initializing simulator DS");
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
|
||||
final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud", "cloud", "cloud");
|
||||
|
|
@ -1079,6 +1125,11 @@ public class Transaction {
|
|||
final ConnectionFactory connectionFactoryUsage = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud_usage", "cloud", "cloud");
|
||||
final PoolableConnectionFactory poolableConnectionFactoryUsage = new PoolableConnectionFactory(connectionFactoryUsage, connectionPoolUsage, null, null, false, true);
|
||||
s_usageDS = new PoolingDataSource(poolableConnectionFactoryUsage.getPool());
|
||||
|
||||
final GenericObjectPool connectionPoolsimulator = new GenericObjectPool(null, 5);
|
||||
final ConnectionFactory connectionFactorysimulator = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/cloud_simulator", "cloud", "cloud");
|
||||
final PoolableConnectionFactory poolableConnectionFactorysimulator = new PoolableConnectionFactory(connectionFactorysimulator, connectionPoolsimulator, null, null, false, true);
|
||||
s_simulatorDS = new PoolingDataSource(poolableConnectionFactorysimulator.getPool());
|
||||
s_logger.warn("Unable to load db configuration, using defaults with 5 connections. Please check your configuration", e);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue