cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From weiz...@apache.org
Subject git commit: updated refs/heads/4.2 to 7dc0dca
Date Fri, 04 Oct 2013 09:25:42 GMT
Updated Branches:
  refs/heads/4.2 54d92f6fd -> 7dc0dca9e


add upgrade path from 4.2.0 to 4.2.1


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

Branch: refs/heads/4.2
Commit: 7dc0dca9e6d41a7a2d1cb3fd86effa5fa0a95cb0
Parents: 54d92f6
Author: Wei Zhou <w.zhou@leaseweb.com>
Authored: Fri Oct 4 11:23:25 2013 +0200
Committer: Wei Zhou <w.zhou@leaseweb.com>
Committed: Fri Oct 4 11:23:25 2013 +0200

----------------------------------------------------------------------
 .../cloud/upgrade/DatabaseUpgradeChecker.java   |  65 +++---
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 149 -------------
 .../com/cloud/upgrade/dao/Upgrade420to421.java  | 211 +++++++++++++++++++
 3 files changed, 244 insertions(+), 181 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7dc0dca9/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
index c64be67..a9e50a0 100755
--- a/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
+++ b/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
@@ -62,6 +62,7 @@ import com.cloud.upgrade.dao.Upgrade307to410;
 import com.cloud.upgrade.dao.Upgrade30to301;
 import com.cloud.upgrade.dao.Upgrade40to41;
 import com.cloud.upgrade.dao.Upgrade410to420;
+import com.cloud.upgrade.dao.Upgrade420to421;
 import com.cloud.upgrade.dao.UpgradeSnapshot217to224;
 import com.cloud.upgrade.dao.UpgradeSnapshot223to224;
 import com.cloud.upgrade.dao.VersionDao;
@@ -88,110 +89,110 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker
{
                 new UpgradeSnapshot217to224(), new Upgrade222to224(), new Upgrade224to225(),
new Upgrade225to226(),
                 new Upgrade227to228(), new Upgrade228to229(), new Upgrade229to2210(), new
Upgrade2210to2211(),
                 new Upgrade2211to2212(), new Upgrade2212to2213(), new Upgrade2213to2214(),
new Upgrade2214to30(),
-                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420() });
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.1.8", new DbUpgrade[] { new Upgrade218to22(), new Upgrade221to222(),
new UpgradeSnapshot217to224(),
                 new Upgrade222to224(), new Upgrade218to224DomainVlans(), new Upgrade224to225(),
new Upgrade225to226(),
                 new Upgrade227to228(), new Upgrade228to229(), new Upgrade229to2210(), new
Upgrade2210to2211(),
                 new Upgrade2211to2212(), new Upgrade2212to2213(), new Upgrade2213to2214(),
-                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.1.9", new DbUpgrade[] { new Upgrade218to22(), new Upgrade221to222(),
new UpgradeSnapshot217to224(),
                 new Upgrade222to224(), new Upgrade218to224DomainVlans(), new Upgrade224to225(),
new Upgrade225to226(),
                 new Upgrade227to228(), new Upgrade228to229(), new Upgrade229to2210(), new
Upgrade2210to2211(),
                 new Upgrade2211to2212(), new Upgrade2212to2213(), new Upgrade2213to2214(),
new Upgrade2214to30(),
-                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420() });
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.1", new DbUpgrade[] { new Upgrade221to222(), new UpgradeSnapshot223to224(),
new Upgrade222to224(),
                 new Upgrade224to225(), new Upgrade225to226(), new Upgrade227to228(), new
Upgrade228to229(),
                 new Upgrade229to2210(), new Upgrade2210to2211(), new Upgrade2211to2212(),
new Upgrade2212to2213(),
-                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421()
});
 
         _upgradeMap.put("2.2.2", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224(),
new Upgrade224to225(),
                 new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229(), new
Upgrade229to2210(),
                 new Upgrade2210to2211(), new Upgrade2211to2212(), new Upgrade2212to2213(),
new Upgrade2213to2214(),
-                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.3", new DbUpgrade[] { new Upgrade222to224(), new UpgradeSnapshot223to224(),
new Upgrade224to225(),
                 new Upgrade225to226(), new Upgrade227to228(), new Upgrade228to229(), new
Upgrade229to2210(),
                 new Upgrade2210to2211(), new Upgrade2211to2212(), new Upgrade2212to2213(),
new Upgrade2213to2214(),
-                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.4", new DbUpgrade[] { new Upgrade224to225(), new Upgrade225to226(),
new Upgrade227to228(),
                 new Upgrade228to229(), new Upgrade229to2210(), new Upgrade2210to2211(), new
Upgrade2211to2212(),
                 new Upgrade2212to2213(), new Upgrade2213to2214(), new Upgrade2214to30(),
new Upgrade30to301(),
-                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420()
});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
         _upgradeMap.put("2.2.5", new DbUpgrade[] { new Upgrade225to226(), new Upgrade227to228(),
new Upgrade228to229(),
                 new Upgrade229to2210(), new Upgrade2210to2211(), new Upgrade2211to2212(),
new Upgrade2212to2213(),
                 new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(),
-                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421()
});
 
         _upgradeMap.put("2.2.6", new DbUpgrade[] { new Upgrade227to228(), new Upgrade228to229(),
new Upgrade229to2210(),
                 new Upgrade2210to2211(), new Upgrade2211to2212(), new Upgrade2212to2213(),
new Upgrade2213to2214(),
-                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.7", new DbUpgrade[] { new Upgrade227to228(), new Upgrade228to229(),
new Upgrade229to2210(),
                 new Upgrade2210to2211(), new Upgrade2211to2212(), new Upgrade2212to2213(),
-                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421()
});
 
         _upgradeMap.put("2.2.8", new DbUpgrade[] { new Upgrade228to229(), new Upgrade229to2210(),
new Upgrade2210to2211(),
                 new Upgrade2211to2212(), new Upgrade2212to2213(), new Upgrade2213to2214(),
new Upgrade2214to30()
-        , new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420() });
+        , new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.9", new DbUpgrade[] { new Upgrade229to2210(), new Upgrade2210to2211(),
new Upgrade2211to2212(),
                 new Upgrade2212to2213(), new Upgrade2213to2214(), new Upgrade2214to30(),
new Upgrade30to301(),
-                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420()
});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
         _upgradeMap.put("2.2.10", new DbUpgrade[] { new Upgrade2210to2211(), new Upgrade2211to2212(),
new Upgrade2212to2213(),
-                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(), new
Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421()
});
 
         _upgradeMap.put("2.2.11", new DbUpgrade[] { new Upgrade2211to2212(), new Upgrade2212to2213(),
new Upgrade2213to2214(),
-                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.12", new DbUpgrade[] { new Upgrade2212to2213(), new Upgrade2213to2214(),
new Upgrade2214to30(),
-                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420() });
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420(), new Upgrade420to421() });
 
         _upgradeMap.put("2.2.13", new DbUpgrade[] { new Upgrade2213to2214(), new Upgrade2214to30(),
new Upgrade30to301(),
-                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420()
});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
         _upgradeMap.put("2.2.14", new DbUpgrade[] { new Upgrade2214to30(), new Upgrade30to301(),
new Upgrade301to302(),
-                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421()
});
         
         
 
-        _upgradeMap.put("3.0.0", new DbUpgrade[] { new Upgrade30to301(), new Upgrade301to302(),
new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420() });
+        _upgradeMap.put("3.0.0", new DbUpgrade[] { new Upgrade30to301(), new Upgrade301to302(),
new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
-        _upgradeMap.put("3.0.1", new DbUpgrade[] { new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420() });
+        _upgradeMap.put("3.0.1", new DbUpgrade[] { new Upgrade301to302(), new Upgrade302to40(),
new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421() });
 
-        _upgradeMap.put("3.0.2", new DbUpgrade[] { new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420() });
+        _upgradeMap.put("3.0.2", new DbUpgrade[] { new Upgrade302to40(), new Upgrade40to41(),
new Upgrade410to420(), new Upgrade420to421() });
 
-        _upgradeMap.put("4.0.0", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420()
});
+        _upgradeMap.put("4.0.0", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
-        _upgradeMap.put("4.0.1", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420()
});
+        _upgradeMap.put("4.0.1", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
-        _upgradeMap.put("4.0.2", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420()
});
+        _upgradeMap.put("4.0.2", new DbUpgrade[] { new Upgrade40to41(), new Upgrade410to420(),
new Upgrade420to421() });
 
-        _upgradeMap.put("4.1.0", new DbUpgrade[] { new Upgrade410to420() });
+        _upgradeMap.put("4.1.0", new DbUpgrade[] { new Upgrade410to420(), new Upgrade420to421()
});
 
-        _upgradeMap.put("4.1.1", new DbUpgrade[] { new Upgrade410to420() });
+        _upgradeMap.put("4.1.1", new DbUpgrade[] { new Upgrade410to420(), new Upgrade420to421()
});
         
         //CP Upgrades
-        _upgradeMap.put("3.0.3", new DbUpgrade[] { new Upgrade303to304(), new Upgrade304to305(),
new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420()
});
+        _upgradeMap.put("3.0.3", new DbUpgrade[] { new Upgrade303to304(), new Upgrade304to305(),
new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(),
new Upgrade420to421() });
         
-        _upgradeMap.put("3.0.4", new DbUpgrade[] { new Upgrade304to305(), new Upgrade305to306(),
new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420() });
+        _upgradeMap.put("3.0.4", new DbUpgrade[] { new Upgrade304to305(), new Upgrade305to306(),
new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to421()
});
         
-        _upgradeMap.put("3.0.5", new DbUpgrade[] { new Upgrade305to306(), new Upgrade306to307(),
new Upgrade307to410(), new Upgrade410to420() });
+        _upgradeMap.put("3.0.5", new DbUpgrade[] { new Upgrade305to306(), new Upgrade306to307(),
new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to421() });
         
-        _upgradeMap.put("3.0.6", new DbUpgrade[] { new Upgrade306to307(), new Upgrade307to410(),
new Upgrade410to420() });
+        _upgradeMap.put("3.0.6", new DbUpgrade[] { new Upgrade306to307(), new Upgrade307to410(),
new Upgrade410to420(), new Upgrade420to421() });
         
-        _upgradeMap.put("3.0.7", new DbUpgrade[] { new Upgrade307to410(), new Upgrade410to420()
});
+        _upgradeMap.put("3.0.7", new DbUpgrade[] { new Upgrade307to410(), new Upgrade410to420(),
new Upgrade420to421() });
         
         _upgradeMap.put("2.2.15", new DbUpgrade[] { new Upgrade2214to30(), new Upgrade30to301(),
new Upgrade301to302(),
-                new Upgrade302to303(), new Upgrade303to304(), new Upgrade304to305(), new
Upgrade305to306(),  new Upgrade306to307(),new Upgrade307to410(), new Upgrade410to420()});
+                new Upgrade302to303(), new Upgrade303to304(), new Upgrade304to305(), new
Upgrade305to306(),  new Upgrade306to307(),new Upgrade307to410(), new Upgrade410to420(), new
Upgrade420to421()});
         
         _upgradeMap.put("2.2.16", new DbUpgrade[] { new Upgrade2214to30(), new Upgrade30to301(),
new Upgrade301to302(),
-                new Upgrade302to303(), new Upgrade303to304(), new Upgrade304to305(), new
Upgrade305to306(),  new Upgrade306to307(),new Upgrade307to410(), new Upgrade410to420()});
+                new Upgrade302to303(), new Upgrade303to304(), new Upgrade304to305(), new
Upgrade305to306(),  new Upgrade306to307(),new Upgrade307to410(), new Upgrade410to420(), new
Upgrade420to421()});
     }
 
     protected void runScript(Connection conn, File file) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7dc0dca9/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
index cd4a959..646b406 100755
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java
@@ -115,7 +115,6 @@ public class Upgrade410to420 implements DbUpgrade {
         migrateVolumeOnSecondaryStorage(conn);
         createFullCloneFlag(conn);
         upgradeVpcServiceMap(conn);
-        upgradeResourceCount(conn);
     }
 
     private void createFullCloneFlag(Connection conn) {
@@ -3013,152 +3012,4 @@ public class Upgrade410to420 implements DbUpgrade {
             }
         }
     }
-
-    private void upgradeResourceCount(Connection conn) {
-        s_logger.debug("upgradeResourceCount start");
-        PreparedStatement pstmt1 = null;
-        PreparedStatement pstmt2 = null;
-        PreparedStatement pstmt3 = null;
-        PreparedStatement pstmt4 = null;
-        PreparedStatement pstmt5 = null;
-        ResultSet rs = null;
-        ResultSet rsAccount = null;
-        ResultSet rsCount = null;
-        try {
-            pstmt1 = conn.prepareStatement("select id, domain_id FROM `cloud`.`account` where
removed is NULL ");
-            rsAccount = pstmt1.executeQuery();
-            while (rsAccount.next()) {
-                long account_id = rsAccount.getLong(1);
-                long domain_id = rsAccount.getLong(2);
-                // 1. update cpu,memory for all accounts
-                pstmt2 = conn.prepareStatement( "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)"
+
-                            " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" +
-                            " WHERE vm_instance.service_offering_id = service_offering.id
AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" +
-                            " AND vm_instance.vm_type='User' AND state not in ('Destroyed',
'Error', 'Expunging')");
-                pstmt2.setLong(1, account_id);
-                rsCount = pstmt2.executeQuery();
-                if (rsCount.next()) {
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", rsCount.getLong(1));
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "memory",
rsCount.getLong(2));
-                } else {
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", 0L);
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "memory",
0L);
-                }
-                // 2. update primary_storage for all accounts
-                pstmt3 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE
account_id= ?" +
-                        " AND (path is not NULL OR state in ('Allocated')) AND removed is
NULL" +
-                        " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE
vm_type='User')");
-                pstmt3.setLong(1, account_id);
-                rsCount = pstmt3.executeQuery();
-                if (rsCount.next()) {
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage",
rsCount.getLong(1));
-                } else {
-                    upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage",
0L);
-                }
-                // 3. update secondary_storage for all accounts
-                long totalVolumesSize = 0;
-                long totalSnapshotsSize = 0;
-                long totalTemplatesSize = 0;
-                pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE
account_id= ?" +
-                        " AND path is NULL AND state not in ('Allocated') AND removed is
NULL");
-                pstmt4.setLong(1, account_id);
-                rsCount = pstmt4.executeQuery();
-                if (rsCount.next()) {
-                    totalVolumesSize = rsCount.getLong(1);
-                }
-                pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`snapshots`
WHERE account_id= ? AND removed is NULL");
-                pstmt4.setLong(1, account_id);
-                rsCount = pstmt4.executeQuery();
-                if (rsCount.next()) {
-                    totalSnapshotsSize = rsCount.getLong(1);
-                }
-                pstmt4 = conn.prepareStatement("SELECT sum(template_store_ref.size) FROM
`cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" +
-                		" AND template_store_ref.template_id = vm_template.id AND download_state
= 'DOWNLOADED' AND destroyed = false AND removed is NULL");
-                pstmt4.setLong(1, account_id);
-                rsCount = pstmt4.executeQuery();
-                if (rsCount.next()) {
-                    totalTemplatesSize = rsCount.getLong(1);
-                }
-                upgradeResourceCountforAccount(conn, account_id, domain_id, "secondary_storage",
totalVolumesSize + totalSnapshotsSize + totalTemplatesSize);
-            }
-            // 4. upgrade cpu,memory,primary_storage,secondary_storage for domains
-            String resource_types[] = {"cpu","memory", "primary_storage", "secondary_storage"};
-            pstmt5 = conn.prepareStatement("select id FROM `cloud`.`domain`");
-            rsAccount = pstmt5.executeQuery();
-            while (rsAccount.next()) {
-                long domain_id = rsAccount.getLong(1);
-                for(int count=0; count < resource_types.length; count++) {
-                    String resource_type = resource_types[count];
-                    upgradeResourceCountforDomain(conn, domain_id, resource_type, 0L); //
reset value to 0 before statistics
-                }
-            }
-            for(int count= 0; count < resource_types.length; count++) {
-                String resource_type = resource_types[count];
-                pstmt5 = conn.prepareStatement("select account.domain_id,sum(resource_count.count)
from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id
" +
-                        "where resource_count.type=? group by account.domain_id;");
-                pstmt5.setString(1, resource_type);
-                rsCount = pstmt5.executeQuery();
-                while (rsCount.next()) {
-                    long domain_id = rsCount.getLong(1);
-                    long resource_count = rsCount.getLong(2);
-                    upgradeResourceCountforDomain(conn, domain_id, resource_type, resource_count);
-                }
-            }
-            s_logger.debug("upgradeResourceCount finish");
-        } catch (SQLException e) {
-            throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage)
", e);
-        } finally {
-            try {
-                if (rs != null) {
-                    rs.close();
-                }
-                if (rsAccount != null) {
-                    rsAccount.close();
-                }
-                if (rsCount != null) {
-                    rsCount.close();
-                }
-                if (pstmt1 != null) {
-                    pstmt1.close();
-                }
-                if (pstmt2 != null) {
-                    pstmt2.close();
-                }
-                if (pstmt3 != null) {
-                    pstmt3.close();
-                }
-                if (pstmt4 != null) {
-                    pstmt4.close();
-                }
-                if (pstmt5 != null) {
-                    pstmt5.close();
-                }
-            } catch (SQLException e) {
-            }
-        }
-    }
-
-    private static void upgradeResourceCountforAccount(Connection conn, Long account_id,
Long domain_id, String type, Long resource_count) throws SQLException {
-        //update or insert into resource_count table.
-        PreparedStatement pstmt = null;
-        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (account_id,
type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?");
-        pstmt.setLong(1, account_id);
-        pstmt.setString(2, type);
-        pstmt.setLong(3, resource_count);
-        pstmt.setLong(4, resource_count);
-        pstmt.executeUpdate();
-        pstmt.close();
-    }
-    
-    private static void upgradeResourceCountforDomain(Connection conn, Long domain_id, String
type, Long resource_count) throws SQLException {
-        //update or insert into resource_count table.
-        PreparedStatement pstmt = null;
-        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (domain_id, type,
count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?");
-        pstmt.setLong(1, domain_id);
-        pstmt.setString(2, type);
-        pstmt.setLong(3, resource_count);
-        pstmt.setLong(4, resource_count);
-        pstmt.executeUpdate();
-        pstmt.close();
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7dc0dca9/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
new file mode 100755
index 0000000..6707eb9
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
@@ -0,0 +1,211 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.upgrade.dao;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class Upgrade420to421 implements DbUpgrade {
+    final static Logger s_logger = Logger.getLogger(Upgrade420to421.class);
+
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[] { "4.2.0" };
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "4.2.1";
+    }
+
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+
+    @Override
+    public File[] getPrepareScripts() {
+        return null;
+    }
+
+    @Override
+    public File[] getCleanupScripts() {
+        return null;
+    }
+
+    @Override
+    public void performDataMigration(Connection conn) {
+        upgradeResourceCount(conn);
+    }
+
+    private void upgradeResourceCount(Connection conn) {
+        s_logger.debug("upgradeResourceCount start");
+        PreparedStatement pstmt1 = null;
+        PreparedStatement pstmt2 = null;
+        PreparedStatement pstmt3 = null;
+        PreparedStatement pstmt4 = null;
+        PreparedStatement pstmt5 = null;
+        ResultSet rs = null;
+        ResultSet rsAccount = null;
+        ResultSet rsCount = null;
+        try {
+            pstmt1 = conn.prepareStatement("select id, domain_id FROM `cloud`.`account` where
removed is NULL ");
+            rsAccount = pstmt1.executeQuery();
+            while (rsAccount.next()) {
+                long account_id = rsAccount.getLong(1);
+                long domain_id = rsAccount.getLong(2);
+                // 1. update cpu,memory for all accounts
+                pstmt2 = conn.prepareStatement( "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)"
+
+                            " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" +
+                            " WHERE vm_instance.service_offering_id = service_offering.id
AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" +
+                            " AND vm_instance.vm_type='User' AND state not in ('Destroyed',
'Error', 'Expunging')");
+                pstmt2.setLong(1, account_id);
+                rsCount = pstmt2.executeQuery();
+                if (rsCount.next()) {
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", rsCount.getLong(1));
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "memory",
rsCount.getLong(2));
+                } else {
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "cpu", 0L);
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "memory",
0L);
+                }
+                // 2. update primary_storage for all accounts
+                pstmt3 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE
account_id= ?" +
+                        " AND (path is not NULL OR state in ('Allocated')) AND removed is
NULL" +
+                        " AND instance_id IN (SELECT id FROM `cloud`.`vm_instance` WHERE
vm_type='User')");
+                pstmt3.setLong(1, account_id);
+                rsCount = pstmt3.executeQuery();
+                if (rsCount.next()) {
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage",
rsCount.getLong(1));
+                } else {
+                    upgradeResourceCountforAccount(conn, account_id, domain_id, "primary_storage",
0L);
+                }
+                // 3. update secondary_storage for all accounts
+                long totalVolumesSize = 0;
+                long totalSnapshotsSize = 0;
+                long totalTemplatesSize = 0;
+                pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`volumes` WHERE
account_id= ?" +
+                        " AND path is NULL AND state not in ('Allocated') AND removed is
NULL");
+                pstmt4.setLong(1, account_id);
+                rsCount = pstmt4.executeQuery();
+                if (rsCount.next()) {
+                    totalVolumesSize = rsCount.getLong(1);
+                }
+                pstmt4 = conn.prepareStatement("SELECT sum(size) FROM `cloud`.`snapshots`
WHERE account_id= ? AND removed is NULL");
+                pstmt4.setLong(1, account_id);
+                rsCount = pstmt4.executeQuery();
+                if (rsCount.next()) {
+                    totalSnapshotsSize = rsCount.getLong(1);
+                }
+                pstmt4 = conn.prepareStatement("SELECT sum(template_store_ref.size) FROM
`cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" +
+                		" AND template_store_ref.template_id = vm_template.id AND download_state
= 'DOWNLOADED' AND destroyed = false AND removed is NULL");
+                pstmt4.setLong(1, account_id);
+                rsCount = pstmt4.executeQuery();
+                if (rsCount.next()) {
+                    totalTemplatesSize = rsCount.getLong(1);
+                }
+                upgradeResourceCountforAccount(conn, account_id, domain_id, "secondary_storage",
totalVolumesSize + totalSnapshotsSize + totalTemplatesSize);
+            }
+            // 4. upgrade cpu,memory,primary_storage,secondary_storage for domains
+            String resource_types[] = {"cpu","memory", "primary_storage", "secondary_storage"};
+            pstmt5 = conn.prepareStatement("select id FROM `cloud`.`domain`");
+            rsAccount = pstmt5.executeQuery();
+            while (rsAccount.next()) {
+                long domain_id = rsAccount.getLong(1);
+                for(int count=0; count < resource_types.length; count++) {
+                    String resource_type = resource_types[count];
+                    upgradeResourceCountforDomain(conn, domain_id, resource_type, 0L); //
reset value to 0 before statistics
+                }
+            }
+            for(int count= 0; count < resource_types.length; count++) {
+                String resource_type = resource_types[count];
+                pstmt5 = conn.prepareStatement("select account.domain_id,sum(resource_count.count)
from `cloud`.`account` left join `cloud`.`resource_count` on account.id=resource_count.account_id
" +
+                        "where resource_count.type=? group by account.domain_id;");
+                pstmt5.setString(1, resource_type);
+                rsCount = pstmt5.executeQuery();
+                while (rsCount.next()) {
+                    long domain_id = rsCount.getLong(1);
+                    long resource_count = rsCount.getLong(2);
+                    upgradeResourceCountforDomain(conn, domain_id, resource_type, resource_count);
+                }
+            }
+            s_logger.debug("upgradeResourceCount finish");
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("Unable to upgrade resource count (cpu,memory,primary_storage,secondary_storage)
", e);
+        } finally {
+            try {
+                if (rs != null) {
+                    rs.close();
+                }
+                if (rsAccount != null) {
+                    rsAccount.close();
+                }
+                if (rsCount != null) {
+                    rsCount.close();
+                }
+                if (pstmt1 != null) {
+                    pstmt1.close();
+                }
+                if (pstmt2 != null) {
+                    pstmt2.close();
+                }
+                if (pstmt3 != null) {
+                    pstmt3.close();
+                }
+                if (pstmt4 != null) {
+                    pstmt4.close();
+                }
+                if (pstmt5 != null) {
+                    pstmt5.close();
+                }
+            } catch (SQLException e) {
+            }
+        }
+    }
+
+    private static void upgradeResourceCountforAccount(Connection conn, Long account_id,
Long domain_id, String type, Long resource_count) throws SQLException {
+        //update or insert into resource_count table.
+        PreparedStatement pstmt = null;
+        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (account_id,
type, count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?");
+        pstmt.setLong(1, account_id);
+        pstmt.setString(2, type);
+        pstmt.setLong(3, resource_count);
+        pstmt.setLong(4, resource_count);
+        pstmt.executeUpdate();
+        pstmt.close();
+    }
+    
+    private static void upgradeResourceCountforDomain(Connection conn, Long domain_id, String
type, Long resource_count) throws SQLException {
+        //update or insert into resource_count table.
+        PreparedStatement pstmt = null;
+        pstmt = conn.prepareStatement("INSERT INTO `cloud`.`resource_count` (domain_id, type,
count) VALUES (?,?,?) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), count=?");
+        pstmt.setLong(1, domain_id);
+        pstmt.setString(2, type);
+        pstmt.setLong(3, resource_count);
+        pstmt.setLong(4, resource_count);
+        pstmt.executeUpdate();
+        pstmt.close();
+    }
+}


Mime
View raw message