incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [2/51] [abbrv] git commit: fix simulator compilation
Date Fri, 14 Sep 2012 21:16:45 GMT
fix simulator compilation


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/e903f838
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/e903f838
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/e903f838

Branch: refs/heads/4.0
Commit: e903f838720d1378062d2c625b56090bd054edcc
Parents: b060bb0
Author: Edison Su <sudison@gmail.com>
Authored: Fri Sep 14 13:37:27 2012 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Fri Sep 14 13:38:08 2012 -0700

----------------------------------------------------------------------
 utils/src/com/cloud/utils/db/Transaction.java |   53 +++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e903f838/utils/src/com/cloud/utils/db/Transaction.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/Transaction.java b/utils/src/com/cloud/utils/db/Transaction.java
index 755de8b..bcf7ae1 100755
--- a/utils/src/com/cloud/utils/db/Transaction.java
+++ b/utils/src/com/cloud/utils/db/Transaction.java
@@ -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);
         }
     }


Mime
View raw message