mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-4095 : Remove region_id from Transaction. Read from db.properties whenever required
Conflicts: framework/db/src/com/cloud/utils/db/GenericDaoBase.java
This commit is contained in:
parent
df3b099449
commit
81f1a0b831
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -23,5 +23,5 @@ import com.cloud.utils.db.GenericDao;
|
||||
public interface RegionDao extends GenericDao<RegionVO, Integer> {
|
||||
|
||||
RegionVO findByName(String name);
|
||||
|
||||
int getRegionId();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,8 +265,6 @@ public interface GenericDao<T, ID extends Serializable> {
|
||||
*/
|
||||
Class<T> getEntityBeanType();
|
||||
|
||||
public int getRegionId();
|
||||
|
||||
/**
|
||||
* @param sc
|
||||
* @param filter
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user