cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [6/8] git commit: updated refs/heads/ui-restyle to 116e06e
Date Wed, 16 Oct 2013 21:45:33 GMT
CLOUDSTACK-4095 : Remove region_id from Transaction. Read from db.properties whenever required

Conflicts:
	framework/db/src/com/cloud/utils/db/GenericDaoBase.java


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

Branch: refs/heads/ui-restyle
Commit: 81f1a0b831f40564ef2ceee225ccd86e7447e030
Parents: df3b099
Author: Kishan Kavala <kishan@cloud.com>
Authored: Wed Oct 16 19:22:33 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Wed Oct 16 19:28:42 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/upgrade/dao/Upgrade307to410.java  | 30 ++++++++++++++++++-
 .../com/cloud/upgrade/dao/Upgrade40to41.java    | 30 ++++++++++++++++++-
 .../apache/cloudstack/region/dao/RegionDao.java |  2 +-
 .../cloudstack/region/dao/RegionDaoImpl.java    |  5 ++++
 .../db/src/com/cloud/utils/db/GenericDao.java   |  2 --
 .../src/com/cloud/utils/db/GenericDaoBase.java  |  5 ----
 .../db/src/com/cloud/utils/db/Transaction.java  |  7 -----
 .../cloudstack/region/RegionManagerImpl.java    | 31 +++++++++++++++++++-
 8 files changed, 94 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java
index 5c7717f..6631050 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade307to410.java
@@ -18,15 +18,22 @@
 package com.cloud.upgrade.dao;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
+import java.util.Properties;
 
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
 import org.apache.log4j.Logger;
 
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.properties.EncryptableProperties;
 
 public class Upgrade307to410 implements DbUpgrade {
     final static Logger s_logger = Logger.getLogger(Upgrade307to410.class);
@@ -62,7 +69,28 @@ public class Upgrade307to410 implements DbUpgrade {
     }
     
     private void updateRegionEntries(Connection conn) {
-        int region_id = Transaction.s_region_id;
+        File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
+        final Properties dbProps;
+        if (EncryptionSecretKeyChecker.useEncryption()) {
+            StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
+            dbProps = new EncryptableProperties(encryptor);
+        } else {
+            dbProps = new Properties();
+        }
+        try {
+            dbProps.load(new FileInputStream(dbPropsFile));
+        } catch (IOException e) {
+            s_logger.fatal("Unable to load db properties file, pl. check the classpath and
file path configuration", e);
+            return;
+        } catch (NullPointerException e) {
+            s_logger.fatal("Unable to locate db properties file within classpath or absolute
path: db.properties");
+            return;
+        }
+        int region_id = 1;
+        String regionId = dbProps.getProperty("region.id");
+        if(regionId != null){
+            region_id = Integer.parseInt(regionId);
+        }
         PreparedStatement pstmt = null;
         try {
             //Update regionId in region table

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
index 9e386b9..79ca5e1 100644
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade40to41.java
@@ -17,16 +17,23 @@
 
 package com.cloud.upgrade.dao;
 
+import com.cloud.utils.PropertiesUtil;
+import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import org.apache.log4j.Logger;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.properties.EncryptableProperties;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Properties;
 import java.util.UUID;
 
 public class Upgrade40to41 implements DbUpgrade {
@@ -74,7 +81,28 @@ public class Upgrade40to41 implements DbUpgrade {
     }
 
     private void updateRegionEntries(Connection conn) {
-        int region_id = Transaction.s_region_id;
+        File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
+        final Properties dbProps;
+        if (EncryptionSecretKeyChecker.useEncryption()) {
+            StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
+            dbProps = new EncryptableProperties(encryptor);
+        } else {
+            dbProps = new Properties();
+        }
+        try {
+            dbProps.load(new FileInputStream(dbPropsFile));
+        } catch (IOException e) {
+            s_logger.fatal("Unable to load db properties file, pl. check the classpath and
file path configuration", e);
+            return;
+        } catch (NullPointerException e) {
+            s_logger.fatal("Unable to locate db properties file within classpath or absolute
path: db.properties");
+            return;
+        }
+        int region_id = 1;
+        String regionId = dbProps.getProperty("region.id");
+        if(regionId != null){
+            region_id = Integer.parseInt(regionId);
+        }
         PreparedStatement pstmt = null;
         try {
             //Update regionId in region table

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java
index 91b51d3..c20735e 100644
--- a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java
+++ b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDao.java
@@ -23,5 +23,5 @@ import com.cloud.utils.db.GenericDao;
 public interface RegionDao extends GenericDao<RegionVO, Integer> {
 
 	RegionVO findByName(String name);
-
+    int getRegionId();
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
index 8f50f93..4a636a6 100644
--- a/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
+++ b/engine/schema/src/org/apache/cloudstack/region/dao/RegionDaoImpl.java
@@ -45,4 +45,9 @@ public class RegionDaoImpl extends GenericDaoBase<RegionVO, Integer>
implements
         sc.setParameters("name", name);
         return findOneBy(sc);
 	}
+
+    @Override
+    public int getRegionId(){
+        return 1;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/framework/db/src/com/cloud/utils/db/GenericDao.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/GenericDao.java b/framework/db/src/com/cloud/utils/db/GenericDao.java
index 6c7e928..ef25d7f 100755
--- a/framework/db/src/com/cloud/utils/db/GenericDao.java
+++ b/framework/db/src/com/cloud/utils/db/GenericDao.java
@@ -265,8 +265,6 @@ public interface GenericDao<T, ID extends Serializable> {
      */
     Class<T> getEntityBeanType();
     
-    public int getRegionId();
-
     /**
      * @param sc
      * @param filter

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/framework/db/src/com/cloud/utils/db/GenericDaoBase.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/GenericDaoBase.java b/framework/db/src/com/cloud/utils/db/GenericDaoBase.java
index b4c02cf..574974e 100755
--- a/framework/db/src/com/cloud/utils/db/GenericDaoBase.java
+++ b/framework/db/src/com/cloud/utils/db/GenericDaoBase.java
@@ -1796,11 +1796,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable>
extends Compone
         return builder.create();
     }
 
-    @Override
-    public int getRegionId(){
-    	return Transaction.s_region_id;
-    }
-
     public Integer getCount(SearchCriteria<T> sc) {
         String clause = sc != null ? sc.getWhereClause() : null;
         if (clause != null && clause.length() == 0) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/framework/db/src/com/cloud/utils/db/Transaction.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/Transaction.java b/framework/db/src/com/cloud/utils/db/Transaction.java
index a5da4b3..8c2f199 100755
--- a/framework/db/src/com/cloud/utils/db/Transaction.java
+++ b/framework/db/src/com/cloud/utils/db/Transaction.java
@@ -83,7 +83,6 @@ public class Transaction {
     public static final short AWSAPI_DB = 2;
     public static final short SIMULATOR_DB = 3;
     public static final short CONNECTED_DB = -1;
-    public static int s_region_id;
 
     private static AtomicLong s_id = new AtomicLong();
     private static final TransactionMBeanImpl s_mbean = new TransactionMBeanImpl();
@@ -1079,12 +1078,6 @@ public class Transaction {
                 System.setProperty("javax.net.ssl.trustStorePassword", dbProps.getProperty("db.cloud.trustStorePassword"));
             }
 
-            String regionId = dbProps.getProperty("region.id");
-            if(regionId == null){
-            	s_region_id = 1;
-            } else {
-            	s_region_id = Integer.parseInt(regionId);
-            }
             final GenericObjectPool cloudConnectionPool = new GenericObjectPool(null, cloudMaxActive,
GenericObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION,
                     cloudMaxWait, cloudMaxIdle, cloudTestOnBorrow, false, cloudTimeBtwEvictionRunsMillis,
1, cloudMinEvcitableIdleTimeMillis, cloudTestWhileIdle);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81f1a0b8/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
index 9bcf4be..046779f 100755
--- a/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
+++ b/server/src/org/apache/cloudstack/region/RegionManagerImpl.java
@@ -26,22 +26,30 @@ import com.cloud.user.DomainManager;
 import com.cloud.user.UserAccount;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserAccountDao;
+import com.cloud.utils.PropertiesUtil;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
+import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
 import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
 import org.apache.cloudstack.api.command.admin.domain.UpdateDomainCmd;
 import org.apache.cloudstack.api.command.admin.user.DeleteUserCmd;
 import org.apache.cloudstack.api.command.admin.user.UpdateUserCmd;
 import org.apache.cloudstack.region.dao.RegionDao;
 import org.apache.log4j.Logger;
+import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
+import org.jasypt.properties.EncryptableProperties;
 import org.springframework.stereotype.Component;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 @Component
 @Local(value = { RegionManager.class })
@@ -63,7 +71,28 @@ public class RegionManagerImpl extends ManagerBase implements RegionManager,
Man
     @Override
     public boolean configure(final String name, final Map<String, Object> params) throws
ConfigurationException {
         _name = name;
-        _id = _regionDao.getRegionId();
+        File dbPropsFile = PropertiesUtil.findConfigFile("db.properties");
+        final Properties dbProps;
+        if (EncryptionSecretKeyChecker.useEncryption()) {
+            StandardPBEStringEncryptor encryptor = EncryptionSecretKeyChecker.getEncryptor();
+            dbProps = new EncryptableProperties(encryptor);
+        } else {
+            dbProps = new Properties();
+        }
+        try {
+            dbProps.load(new FileInputStream(dbPropsFile));
+        } catch (IOException e) {
+            s_logger.fatal("Unable to load db properties file, pl. check the classpath and
file path configuration", e);
+            return false;
+        } catch (NullPointerException e) {
+            s_logger.fatal("Unable to locate db properties file within classpath or absolute
path: db.properties");
+            return false;
+        }
+        String regionId = dbProps.getProperty("region.id");
+        _id = 1;
+        if(regionId != null){
+            _id = Integer.parseInt(regionId);
+        }
         return true;
     }
 


Mime
View raw message