Insert default security group to network_groups table when do upgrade from 21x to 22x branch

This commit is contained in:
alena 2011-05-23 12:36:21 -07:00
parent 55692fd7cf
commit c0d84f3de8
1 changed files with 18 additions and 4 deletions

View File

@ -370,14 +370,28 @@ public class ConfigurationServerImpl implements ConfigurationServer {
try {
insertSql = "SELECT * FROM `cloud`.`security_group` where account_id=2 and name='default'";
String tableName = "security_group";
try {
String checkSql = "SELECT * from network_group";
PreparedStatement stmt = txn.prepareAutoCloseStatement(checkSql);
stmt.executeQuery();
tableName = "network_group";
} catch (Exception ex) {
// if network_groups table exists, create the default security group there
}
insertSql = "SELECT * FROM " + tableName + " where account_id=2 and name='default'";
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
ResultSet rs = stmt.executeQuery();
if (!rs.next()) {
//save default security group
insertSql = "INSERT INTO `cloud`.`security_group` (name, description, account_id, domain_id) " +
"VALUES ('default', 'Default Security Group', 2, 1)";
if (tableName.equals("security_group")) {
insertSql = "INSERT INTO " + tableName +" (name, description, account_id, domain_id) " +
"VALUES ('default', 'Default Security Group', 2, 1)";
} else {
insertSql = "INSERT INTO " + tableName +" (name, description, account_id, domain_id, account_name) " +
"VALUES ('default', 'Default Security Group', 2, 1, 'admin')";
}
txn = Transaction.currentTxn();
try {