mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-241: Moved regions upgrade changes to Upgrade40to41.jav from schema file. Sets the right regins_id from db.properties instead of using default 1.
Conflicts: setup/db/db/schema-40to410.sql
This commit is contained in:
parent
6a46656c72
commit
1d31c3ecaf
@ -130,7 +130,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
|
||||
@Inject private ResourceCountDao _resourceCountDao;
|
||||
@Inject private NetworkOfferingServiceMapDao _ntwkOfferingServiceMapDao;
|
||||
@Inject private IdentityDao _identityDao;
|
||||
@Inject private RegionDao _regionDao;
|
||||
|
||||
public ConfigurationServerImpl() {
|
||||
setRunLevel(ComponentLifecycle.RUN_LEVEL_FRAMEWORK_BOOTSTRAP);
|
||||
@ -234,8 +233,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
|
||||
// Create default networks
|
||||
createDefaultNetworks();
|
||||
|
||||
createDefaultRegion();
|
||||
|
||||
// Create userIpAddress ranges
|
||||
|
||||
// Update existing vlans with networkId
|
||||
@ -338,21 +335,23 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
|
||||
|
||||
@DB
|
||||
protected void saveUser() {
|
||||
//ToDo: Add regionId to default users and accounts
|
||||
int region_id = _configDao.getRegionId();
|
||||
// insert system account
|
||||
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (1, UUID(), 'system', '1', '1', '1')";
|
||||
String insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (1, UUID(), 'system', '1', '1', ?)";
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
stmt.setInt(1, region_id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
// insert system user
|
||||
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, region_id)" +
|
||||
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), '1')";
|
||||
" VALUES (1, UUID(), 'system', RAND(), 1, 'system', 'cloud', now(), ?)";
|
||||
txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
stmt.setInt(1, region_id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
@ -365,21 +364,23 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
|
||||
String lastname = "cloud";
|
||||
|
||||
// create an account for the admin user first
|
||||
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', '1')";
|
||||
insertSql = "INSERT INTO `cloud`.`account` (id, uuid, account_name, type, domain_id, region_id) VALUES (" + id + ", UUID(), '" + username + "', '1', '1', ?)";
|
||||
txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
stmt.setInt(1, region_id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
|
||||
// now insert the user
|
||||
insertSql = "INSERT INTO `cloud`.`user` (id, uuid, username, password, account_id, firstname, lastname, created, state, region_id) " +
|
||||
"VALUES (" + id + ", UUID(), '" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', '1')";
|
||||
"VALUES (" + id + ", UUID(), '" + username + "', RAND(), 2, '" + firstname + "','" + lastname + "',now(), 'disabled', ?)";
|
||||
|
||||
txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||
stmt.setInt(1, region_id);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
}
|
||||
@ -1272,9 +1273,4 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
|
||||
return svcProviders;
|
||||
}
|
||||
|
||||
private void createDefaultRegion(){
|
||||
//Get Region name and URL from db.properties
|
||||
_regionDao.persist(new RegionVO(_regionDao.getRegionId(), "Local", "http://localhost:8080/client/api", "", ""));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
package com.cloud.upgrade.dao;
|
||||
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
@ -33,48 +34,95 @@ import java.util.UUID;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class Upgrade40to41 implements DbUpgrade {
|
||||
final static Logger s_logger = Logger.getLogger(Upgrade40to41.class);
|
||||
final static Logger s_logger = Logger.getLogger(Upgrade40to41.class);
|
||||
|
||||
@Override
|
||||
public String[] getUpgradableVersionRange() {
|
||||
return new String[] { "4.0.0", "4.1.0" };
|
||||
}
|
||||
@Override
|
||||
public String[] getUpgradableVersionRange() {
|
||||
return new String[] { "4.0.0", "4.1.0" };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUpgradedVersion() {
|
||||
return "4.1.0";
|
||||
}
|
||||
@Override
|
||||
public String getUpgradedVersion() {
|
||||
return "4.1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsRollingUpgrade() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean supportsRollingUpgrade() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getPrepareScripts() {
|
||||
String script = Script.findScript("", "db/schema-40to410.sql");
|
||||
@Override
|
||||
public File[] getPrepareScripts() {
|
||||
String script = Script.findScript("", "db/schema-40to410.sql");
|
||||
if (script == null) {
|
||||
throw new CloudRuntimeException("Unable to find db/schema-40to410.sql");
|
||||
}
|
||||
|
||||
return new File[] { new File(script) };
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
@Override
|
||||
public void performDataMigration(Connection conn) {
|
||||
updateRegionEntries(conn);
|
||||
upgradeEIPNetworkOfferings(conn);
|
||||
upgradeEgressFirewallRules(conn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getCleanupScripts() {
|
||||
@Override
|
||||
public File[] getCleanupScripts() {
|
||||
String script = Script.findScript("", "db/schema-40to410-cleanup.sql");
|
||||
if (script == null) {
|
||||
throw new CloudRuntimeException("Unable to find db/schema-40to410-cleanup.sql");
|
||||
}
|
||||
|
||||
return new File[] { new File(script) };
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRegionEntries(Connection conn) {
|
||||
int region_id = Transaction.s_region_id;
|
||||
PreparedStatement pstmt = null;
|
||||
try {
|
||||
//Update regionId in region table
|
||||
s_logger.debug("Updating region table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`region` set id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in account table
|
||||
s_logger.debug("Updating account table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`account` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in user table
|
||||
s_logger.debug("Updating user table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`user` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in domain table
|
||||
s_logger.debug("Updating domain table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud`.`domain` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
|
||||
//Update regionId in cloud_usage account table
|
||||
s_logger.debug("Updating cloud_usage account table with Id: "+region_id);
|
||||
pstmt = conn.prepareStatement("update `cloud_usage`.`account` set region_id = ?");
|
||||
pstmt.setInt(1, region_id);
|
||||
pstmt.executeUpdate();
|
||||
s_logger.debug("Successfully updated region entries with regionId: "+region_id);
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Error while updating region entries", e);
|
||||
} finally {
|
||||
try {
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void upgradeEIPNetworkOfferings(Connection conn) {
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
@ -260,7 +260,8 @@ CREATE TABLE `cloud`.`region` (
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
-- INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','','');
|
||||
INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','','');
|
||||
|
||||
ALTER TABLE `cloud`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
ALTER TABLE `cloud`.`user` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
ALTER TABLE `cloud`.`domain` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user