incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kis...@apache.org
Subject [1/3] git commit: refs/heads/4.1 - CLOUDSTACK-241: Moved regions upgrade chnages to Upgrade40to41.jav from schema file. Sets the right regins_id from db.properties instead of using default 1.
Date Thu, 28 Feb 2013 06:10:04 GMT
CLOUDSTACK-241: Moved regions upgrade chnages to Upgrade40to41.jav from schema file. Sets the
right regins_id from db.properties instead of using default 1.


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

Branch: refs/heads/4.1
Commit: 79995bf6296f4c9a440a1fd11fa2b0162b7d8074
Parents: 1a2173f
Author: Kishan Kavala <kishan@cloud.com>
Authored: Thu Feb 28 11:20:35 2013 +0530
Committer: Kishan Kavala <kishan@cloud.com>
Committed: Thu Feb 28 11:21:02 2013 +0530

----------------------------------------------------------------------
 .../com/cloud/server/ConfigurationServerImpl.java  |   22 ++--
 .../src/com/cloud/upgrade/dao/Upgrade40to41.java   |  102 +++++++++++----
 setup/db/db/schema-40to410.sql                     |    2 +-
 3 files changed, 85 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/79995bf6/server/src/com/cloud/server/ConfigurationServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java
index 294bd6a..c5ae1e2 100755
--- a/server/src/com/cloud/server/ConfigurationServerImpl.java
+++ b/server/src/com/cloud/server/ConfigurationServerImpl.java
@@ -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);
@@ -236,8 +235,6 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
             // Create default networks
             createDefaultNetworks();
 
-            createDefaultRegion();
-
             // Create userIpAddress ranges
 
             // Update existing vlans with networkId
@@ -340,21 +337,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) {
         }
@@ -367,21 +366,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) {
         }
@@ -1292,9 +1293,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",
"", ""));
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/79995bf6/server/src/com/cloud/upgrade/dao/Upgrade40to41.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/upgrade/dao/Upgrade40to41.java b/server/src/com/cloud/upgrade/dao/Upgrade40to41.java
index e7fea23..9268764 100644
--- a/server/src/com/cloud/upgrade/dao/Upgrade40to41.java
+++ b/server/src/com/cloud/upgrade/dao/Upgrade40to41.java
@@ -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);
-
-	@Override
-	public String[] getUpgradableVersionRange() {
-		return new String[] { "4.0.0", "4.1.0" };
-	}
-
-	@Override
-	public String getUpgradedVersion() {
-		return "4.1.0";
-	}
-
-	@Override
-	public boolean supportsRollingUpgrade() {
-		return false;
-	}
-
-	@Override
-	public File[] getPrepareScripts() {
-		String script = Script.findScript("", "db/schema-40to410.sql");
+    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 getUpgradedVersion() {
+        return "4.1.0";
+    }
+
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+
+    @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;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/79995bf6/setup/db/db/schema-40to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql
index a2f5699..2c0b981 100644
--- a/setup/db/db/schema-40to410.sql
+++ b/setup/db/db/schema-40to410.sql
@@ -260,7 +260,7 @@ CREATE TABLE  `cloud`.`region` (
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
-
+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';


Mime
View raw message