You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/10/15 22:20:10 UTC

[15/25] git commit: updated refs/heads/ui-restyle to 3fdb61f

Add upgrade path from 4.2.1 to 4.3.0.


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

Branch: refs/heads/ui-restyle
Commit: ac02987db259dabd8685981e35d87a664a40fa4e
Parents: 7d89cec
Author: Min Chen <mi...@citrix.com>
Authored: Mon Oct 14 21:56:16 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Mon Oct 14 21:56:34 2013 -0700

----------------------------------------------------------------------
 .../cloud/upgrade/DatabaseUpgradeChecker.java   |  78 ++--
 .../com/cloud/upgrade/dao/Upgrade420to421.java  | 217 +++++++++
 .../com/cloud/upgrade/dao/Upgrade420to430.java  |  70 ---
 .../com/cloud/upgrade/dao/Upgrade421to430.java  |  70 +++
 setup/db/db/schema-420to421.sql                 |  24 +
 setup/db/db/schema-420to430-cleanup.sql         |  22 -
 setup/db/db/schema-420to430.sql                 | 448 -------------------
 setup/db/db/schema-421to430-cleanup.sql         |  22 +
 setup/db/db/schema-421to430.sql                 | 446 ++++++++++++++++++
 9 files changed, 823 insertions(+), 574 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/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 c107fa0..85e36a5 100755
--- a/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
+++ b/engine/schema/src/com/cloud/upgrade/DatabaseUpgradeChecker.java
@@ -62,7 +62,8 @@ 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.Upgrade420to430;
+import com.cloud.upgrade.dao.Upgrade420to421;
+import com.cloud.upgrade.dao.Upgrade421to430;
 import com.cloud.upgrade.dao.UpgradeSnapshot217to224;
 import com.cloud.upgrade.dao.UpgradeSnapshot223to224;
 import com.cloud.upgrade.dao.VersionDao;
@@ -89,118 +90,127 @@ 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 Upgrade420to430()});
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                , new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
         _upgradeMap.put("2.2.12", new DbUpgrade[] {new Upgrade2212to2213(), new Upgrade2213to2214(), new Upgrade2214to30(),
-                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+                new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _upgradeMap.put("2.2.13", new DbUpgrade[] {new Upgrade2213to2214(), new Upgrade2214to30(), new Upgrade30to301(),
-                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+                new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _upgradeMap.put("2.2.14", new DbUpgrade[] {new Upgrade2214to30(), new Upgrade30to301(), new Upgrade301to302(),
-                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+                new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _upgradeMap.put("3.0.0", new DbUpgrade[] {new Upgrade30to301(), new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(),
-                new Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("3.0.1", new DbUpgrade[] {new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("3.0.1", new DbUpgrade[] {new Upgrade301to302(), new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
-        _upgradeMap.put("3.0.2", new DbUpgrade[] {new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("3.0.2", new DbUpgrade[] {new Upgrade302to40(), new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.0.0", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("4.0.0", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.0.1", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("4.0.1", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.0.2", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("4.0.2", new DbUpgrade[] {new Upgrade40to41(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.1.0", new DbUpgrade[] {new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("4.1.0", new DbUpgrade[] {new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.1.1", new DbUpgrade[] {new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("4.1.1", new DbUpgrade[] {new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("4.2.0", new DbUpgrade[] {new Upgrade420to430()});
+        _upgradeMap.put("4.2.0", new DbUpgrade[] {new Upgrade420to421(), new Upgrade421to430()});
+
+        _upgradeMap.put("4.2.1", new DbUpgrade[] {new Upgrade421to430()});
 
         //CP Upgrades
         _upgradeMap.put("3.0.3", new DbUpgrade[] {new Upgrade303to304(), new Upgrade304to305(), new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(),
-                new Upgrade410to420(), new Upgrade420to430()});
+                new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _upgradeMap.put("3.0.4", new DbUpgrade[] {new Upgrade304to305(), new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(),
-                new Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("3.0.5", new DbUpgrade[] {new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("3.0.5", new DbUpgrade[] {new Upgrade305to306(), new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to421(),
+                new Upgrade421to430()});
 
-        _upgradeMap.put("3.0.6", new DbUpgrade[] {new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("3.0.6", new DbUpgrade[] {new Upgrade306to307(), new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
-        _upgradeMap.put("3.0.7", new DbUpgrade[] {new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to430()});
+        _upgradeMap.put("3.0.7", new DbUpgrade[] {new Upgrade307to410(), new Upgrade410to420(), new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
 
         _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 Upgrade420to430()});
+                new Upgrade420to421(), new Upgrade421to430()});
     }
 
     protected void runScript(Connection conn, File file) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/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 100644
index 0000000..27704e8
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java
@@ -0,0 +1,217 @@
+// 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;
+import com.cloud.utils.script.Script;
+
+public class Upgrade420to421 implements DbUpgrade {
+    final static Logger s_logger = Logger.getLogger(Upgrade420to421.class);
+
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[] { "4.2.0", "4.2.1" };
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "4.2.1";
+    }
+
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+
+    @Override
+    public File[] getPrepareScripts() {
+        String script = Script.findScript("", "db/schema-420to421.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-420to421.sql");
+        }
+
+        return new File[] { new File(script) };
+    }
+
+    @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();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
deleted file mode 100644
index ab82cc9..0000000
--- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to430.java
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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 org.apache.log4j.Logger;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
-
-public class Upgrade420to430 implements DbUpgrade {
-    final static Logger s_logger = Logger.getLogger(Upgrade420to430.class);
-
-    @Override
-    public String[] getUpgradableVersionRange() {
-        return new String[] { "4.2.0", "4.3.0" };
-    }
-
-    @Override
-    public String getUpgradedVersion() {
-        return "4.3.0";
-    }
-
-    @Override
-    public boolean supportsRollingUpgrade() {
-        return false;
-    }
-
-    @Override
-    public File[] getPrepareScripts() {
-        String script = Script.findScript("", "db/schema-420to430.sql");
-        if (script == null) {
-            throw new CloudRuntimeException("Unable to find db/schema-420to430.sql");
-        }
-
-        return new File[] { new File(script) };
-    }
-
-    @Override
-    public void performDataMigration(Connection conn) {
-    }
-
-    @Override
-    public File[] getCleanupScripts() {
-        String script = Script.findScript("", "db/schema-420to430-cleanup.sql");
-        if (script == null) {
-            throw new CloudRuntimeException("Unable to find db/schema-420to430-cleanup.sql");
-        }
-
-        return new File[] { new File(script) };
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
new file mode 100644
index 0000000..5647289
--- /dev/null
+++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade421to430.java
@@ -0,0 +1,70 @@
+// 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 org.apache.log4j.Logger;
+
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.script.Script;
+
+public class Upgrade421to430 implements DbUpgrade {
+    final static Logger s_logger = Logger.getLogger(Upgrade421to430.class);
+
+    @Override
+    public String[] getUpgradableVersionRange() {
+        return new String[] {"4.2.1", "4.3.0"};
+    }
+
+    @Override
+    public String getUpgradedVersion() {
+        return "4.3.0";
+    }
+
+    @Override
+    public boolean supportsRollingUpgrade() {
+        return false;
+    }
+
+    @Override
+    public File[] getPrepareScripts() {
+        String script = Script.findScript("", "db/schema-421to430.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-421to430.sql");
+        }
+
+        return new File[] { new File(script) };
+    }
+
+    @Override
+    public void performDataMigration(Connection conn) {
+    }
+
+    @Override
+    public File[] getCleanupScripts() {
+        String script = Script.findScript("", "db/schema-421to430-cleanup.sql");
+        if (script == null) {
+            throw new CloudRuntimeException("Unable to find db/schema-421to430-cleanup.sql");
+        }
+
+        return new File[] { new File(script) };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/setup/db/db/schema-420to421.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-420to421.sql b/setup/db/db/schema-420to421.sql
new file mode 100644
index 0000000..1e6341e
--- /dev/null
+++ b/setup/db/db/schema-420to421.sql
@@ -0,0 +1,24 @@
+-- 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.
+
+--;
+-- Schema upgrade from 4.2.0 to 4.2.1;
+--;
+
+
+INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.multipart.enabled', 'true', 'enable s3 multipart upload');
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/setup/db/db/schema-420to430-cleanup.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-420to430-cleanup.sql b/setup/db/db/schema-420to430-cleanup.sql
deleted file mode 100644
index ce5a220..0000000
--- a/setup/db/db/schema-420to430-cleanup.sql
+++ /dev/null
@@ -1,22 +0,0 @@
--- 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.
-
---;
--- Schema cleanup from 4.2.0 to 4.3.0;
---;
-
-

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/setup/db/db/schema-420to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-420to430.sql b/setup/db/db/schema-420to430.sql
deleted file mode 100644
index a765189..0000000
--- a/setup/db/db/schema-420to430.sql
+++ /dev/null
@@ -1,448 +0,0 @@
--- 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.
-
---;
--- Schema upgrade from 4.2.0 to 4.3.0;
---;
-
--- Disable foreign key checking
-SET foreign_key_checks = 0;
-
-ALTER TABLE `cloud`.`async_job` ADD COLUMN `related` CHAR(40) NOT NULL;
-ALTER TABLE `cloud`.`async_job` DROP COLUMN `session_key`;
-ALTER TABLE `cloud`.`async_job` DROP COLUMN `job_cmd_originator`;
-ALTER TABLE `cloud`.`async_job` DROP COLUMN `callback_type`;
-ALTER TABLE `cloud`.`async_job` DROP COLUMN `callback_address`;
-
-ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_type` VARCHAR(32);
-ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_dispatcher` VARCHAR(64);
-ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_executing_msid` bigint;
-ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_pending_signals` int(10) NOT NULL DEFAULT 0;
-
-ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state` VARCHAR(74) DEFAULT 'PowerUnknown';
-ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME;
-ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_count` INT DEFAULT 0;
-ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_host` bigint unsigned;
-ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__power_host` FOREIGN KEY (`power_host`) REFERENCES `cloud`.`host`(`id`);
-
-CREATE TABLE `cloud`.`vm_work_job` (
-  `id` bigint unsigned UNIQUE NOT NULL,
-  `step` char(32) NOT NULL COMMENT 'state',
-  `vm_type` char(32) NOT NULL COMMENT 'type of vm',
-  `vm_instance_id` bigint unsigned NOT NULL COMMENT 'vm instance',
-  PRIMARY KEY (`id`),
-  CONSTRAINT `fk_vm_work_job__instance_id` FOREIGN KEY (`vm_instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE,
-  INDEX `i_vm_work_job__vm`(`vm_type`, `vm_instance_id`),
-  INDEX `i_vm_work_job__step`(`step`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`async_job_journal` (
-  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
-  `job_id` bigint unsigned NOT NULL,
-  `journal_type` varchar(32),
-  `journal_text` varchar(1024) COMMENT 'journal descriptive informaton',
-  `journal_obj` varchar(1024) COMMENT 'journal strutural information, JSON encoded object',
-  `created` datetime NOT NULL COMMENT 'date created',
-  PRIMARY KEY (`id`),
-  CONSTRAINT `fk_async_job_journal__job_id` FOREIGN KEY (`job_id`) REFERENCES `async_job`(`id`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE `cloud`.`async_job_join_map` (
-  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
-  `job_id` bigint unsigned NOT NULL,
-  `join_job_id` bigint unsigned NOT NULL,
-  `join_status` int NOT NULL,
-  `join_result` varchar(1024),
-  `join_msid` bigint,
-  `complete_msid` bigint,
-  `sync_source_id` bigint COMMENT 'upper-level job sync source info before join',
-  `wakeup_handler` varchar(64),
-  `wakeup_dispatcher` varchar(64),
-  `wakeup_interval` bigint NOT NULL DEFAULT 3000 COMMENT 'wakeup interval in seconds',
-  `created` datetime NOT NULL,
-  `last_updated` datetime,
-  `next_wakeup` datetime,
-  `expiration` datetime,
-  PRIMARY KEY (`id`),
-  CONSTRAINT `fk_async_job_join_map__job_id` FOREIGN KEY (`job_id`) REFERENCES `async_job`(`id`) ON DELETE CASCADE,
-  CONSTRAINT `fk_async_job_join_map__join_job_id` FOREIGN KEY (`join_job_id`) REFERENCES `async_job`(`id`),
-  CONSTRAINT `fk_async_job_join_map__join` UNIQUE (`job_id`, `join_job_id`),
-  INDEX `i_async_job_join_map__join_job_id`(`join_job_id`),
-  INDEX `i_async_job_join_map__created`(`created`),
-  INDEX `i_async_job_join_map__last_updated`(`last_updated`),
-  INDEX `i_async_job_join_map__next_wakeup`(`next_wakeup`),
-  INDEX `i_async_job_join_map__expiration`(`expiration`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE `cloud`.`configuration` ADD COLUMN `default_value` VARCHAR(4095) COMMENT 'Default value for a configuration parameter';
-ALTER TABLE `cloud`.`configuration` ADD COLUMN `updated` datetime COMMENT 'Time this was updated by the server. null means this row is obsolete.';
-ALTER TABLE `cloud`.`configuration` ADD COLUMN `scope` VARCHAR(255) DEFAULT NULL COMMENT 'Can this parameter be scoped';
-ALTER TABLE `cloud`.`configuration` ADD COLUMN `is_dynamic` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Can the parameter be change dynamically without restarting the server';
-
-UPDATE `cloud`.`configuration` SET `default_value` = `value`;
-
-#Upgrade the offerings and template table to have actual remove and states
-ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `state` CHAR(40) NOT NULL DEFAULT 'Active' COMMENT 'state for disk offering';
-
-UPDATE `cloud`.`disk_offering` SET `state`='Inactive' WHERE `removed` IS NOT NULL;
-UPDATE `cloud`.`disk_offering` SET `removed`=NULL;
-
-UPDATE `cloud`.`vm_template` SET `state`='Inactive' WHERE `removed` IS NOT NULL;
-UPDATE `cloud`.`vm_template` SET `state`='Active' WHERE `removed` IS NULL;
-UPDATE `cloud`.`vm_template` SET `removed`=NULL;
-
-DROP VIEW IF EXISTS `cloud`.`disk_offering_view`;
-CREATE VIEW `cloud`.`disk_offering_view` AS
-    select
-        disk_offering.id,
-        disk_offering.uuid,
-        disk_offering.name,
-        disk_offering.display_text,
-        disk_offering.disk_size,
-        disk_offering.min_iops,
-        disk_offering.max_iops,
-        disk_offering.created,
-        disk_offering.tags,
-        disk_offering.customized,
-        disk_offering.customized_iops,
-        disk_offering.removed,
-        disk_offering.use_local_storage,
-        disk_offering.system_use,
-        disk_offering.bytes_read_rate,
-        disk_offering.bytes_write_rate,
-        disk_offering.iops_read_rate,
-        disk_offering.iops_write_rate,
-        disk_offering.sort_key,
-        disk_offering.type,
-		disk_offering.display_offering,
-        domain.id domain_id,
-        domain.uuid domain_uuid,
-        domain.name domain_name,
-        domain.path domain_path
-    from
-        `cloud`.`disk_offering`
-            left join
-        `cloud`.`domain` ON disk_offering.domain_id = domain.id
-	where
-		disk_offering.state='ACTIVE';
-
-DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
-CREATE VIEW `cloud`.`service_offering_view` AS
-    select 
-        service_offering.id,
-        disk_offering.uuid,
-        disk_offering.name,
-        disk_offering.display_text,
-        disk_offering.created,
-        disk_offering.tags,
-        disk_offering.removed,
-        disk_offering.use_local_storage,
-        disk_offering.system_use,
-        disk_offering.bytes_read_rate,
-        disk_offering.bytes_write_rate,
-        disk_offering.iops_read_rate,
-        disk_offering.iops_write_rate,
-        service_offering.cpu,
-        service_offering.speed,
-        service_offering.ram_size,
-        service_offering.nw_rate,
-        service_offering.mc_rate,
-        service_offering.ha_enabled,
-        service_offering.limit_cpu_use,
-        service_offering.host_tag,
-        service_offering.default_use,
-        service_offering.vm_type,
-        service_offering.sort_key,
-        service_offering.is_volatile,
-        service_offering.deployment_planner,
-        domain.id domain_id,
-        domain.uuid domain_uuid,
-        domain.name domain_name,
-        domain.path domain_path
-    from
-        `cloud`.`service_offering`
-            inner join
-        `cloud`.`disk_offering` ON service_offering.id = disk_offering.id
-            left join
-        `cloud`.`domain` ON disk_offering.domain_id = domain.id
-	where
-		disk_offering.state='Active';
-		
-DROP VIEW IF EXISTS `cloud`.`template_view`;
-CREATE VIEW `cloud`.`template_view` AS
-    select 
-        vm_template.id,
-        vm_template.uuid,
-        vm_template.unique_name,
-        vm_template.name,
-        vm_template.public,
-        vm_template.featured,
-        vm_template.type,
-        vm_template.hvm,
-        vm_template.bits,
-        vm_template.url,
-        vm_template.format,
-        vm_template.created,
-        vm_template.checksum,
-        vm_template.display_text,
-        vm_template.enable_password,
-        vm_template.dynamically_scalable,
-        vm_template.guest_os_id,
-        guest_os.uuid guest_os_uuid,
-        guest_os.display_name guest_os_name,
-        vm_template.bootable,
-        vm_template.prepopulate,
-        vm_template.cross_zones,
-        vm_template.hypervisor_type,
-        vm_template.extractable,
-        vm_template.template_tag,
-        vm_template.sort_key,
-        vm_template.removed,
-        vm_template.enable_sshkey,
-        source_template.id source_template_id,
-        source_template.uuid source_template_uuid,
-        account.id account_id,
-        account.uuid account_uuid,
-        account.account_name account_name,
-        account.type account_type,
-        domain.id domain_id,
-        domain.uuid domain_uuid,
-        domain.name domain_name,
-        domain.path domain_path,
-        projects.id project_id,
-        projects.uuid project_uuid,
-        projects.name project_name,        
-        data_center.id data_center_id,
-        data_center.uuid data_center_uuid,
-        data_center.name data_center_name,
-        launch_permission.account_id lp_account_id,
-        template_store_ref.store_id,
-		image_store.scope as store_scope,
-        template_store_ref.state,
-        template_store_ref.download_state,
-        template_store_ref.download_pct,
-        template_store_ref.error_str,
-        template_store_ref.size,
-        template_store_ref.destroyed,
-        template_store_ref.created created_on_store,
-        vm_template_details.name detail_name,
-        vm_template_details.value detail_value,
-        resource_tags.id tag_id,
-        resource_tags.uuid tag_uuid,
-        resource_tags.key tag_key,
-        resource_tags.value tag_value,
-        resource_tags.domain_id tag_domain_id,
-        resource_tags.account_id tag_account_id,
-        resource_tags.resource_id tag_resource_id,
-        resource_tags.resource_uuid tag_resource_uuid,
-        resource_tags.resource_type tag_resource_type,
-        resource_tags.customer tag_customer,
-		CONCAT(vm_template.id, '_', IFNULL(data_center.id, 0)) as temp_zone_pair
-    from
-        `cloud`.`vm_template`
-            inner join
-        `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id        
-            inner join
-        `cloud`.`account` ON account.id = vm_template.account_id
-            inner join
-        `cloud`.`domain` ON domain.id = account.domain_id
-            left join
-        `cloud`.`projects` ON projects.project_account_id = account.id    
-            left join
-        `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id         
-            left join
-        `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id    
-            left join
-        `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and template_store_ref.store_role = 'Image'
-            left join
-        `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id 
-        	left join
-        `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null    
-            left join
-        `cloud`.`data_center` ON (image_store.data_center_id = data_center.id OR template_zone_ref.zone_id = data_center.id)
-            left join
-        `cloud`.`launch_permission` ON launch_permission.template_id = vm_template.id
-            left join
-        `cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id
-            and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO')
-    where
-        vm_template.state='Active';
-
-DROP VIEW IF EXISTS `cloud`.`volume_view`;
-CREATE VIEW `cloud`.`volume_view` AS
-    select
-        volumes.id,
-        volumes.uuid,
-        volumes.name,
-        volumes.device_id,
-        volumes.volume_type,
-        volumes.size,
-        volumes.min_iops,
-        volumes.max_iops,
-        volumes.created,
-        volumes.state,
-        volumes.attached,
-        volumes.removed,
-        volumes.pod_id,
-	volumes.display_volume,
-        volumes.format,
-	volumes.path,
-        account.id account_id,
-        account.uuid account_uuid,
-        account.account_name account_name,
-        account.type account_type,
-        domain.id domain_id,
-        domain.uuid domain_uuid,
-        domain.name domain_name,
-        domain.path domain_path,
-        projects.id project_id,
-        projects.uuid project_uuid,
-        projects.name project_name,
-        data_center.id data_center_id,
-        data_center.uuid data_center_uuid,
-        data_center.name data_center_name,
-	data_center.networktype data_center_type,
-        vm_instance.id vm_id,
-        vm_instance.uuid vm_uuid,
-        vm_instance.name vm_name,
-        vm_instance.state vm_state,
-        vm_instance.vm_type,
-        user_vm.display_name vm_display_name,
-        volume_store_ref.size volume_store_size,
-        volume_store_ref.download_pct,
-        volume_store_ref.download_state,
-        volume_store_ref.error_str,
-        volume_store_ref.created created_on_store,
-        disk_offering.id disk_offering_id,
-        disk_offering.uuid disk_offering_uuid,
-        disk_offering.name disk_offering_name,
-        disk_offering.display_text disk_offering_display_text,
-        disk_offering.use_local_storage,
-        disk_offering.system_use,
-        disk_offering.bytes_read_rate,
-        disk_offering.bytes_write_rate,
-        disk_offering.iops_read_rate,
-        disk_offering.iops_write_rate,
-        storage_pool.id pool_id,
-        storage_pool.uuid pool_uuid,
-        storage_pool.name pool_name,
-        cluster.hypervisor_type,
-        vm_template.id template_id,
-        vm_template.uuid template_uuid,
-        vm_template.extractable,
-        vm_template.type template_type,
-        resource_tags.id tag_id,
-        resource_tags.uuid tag_uuid,
-        resource_tags.key tag_key,
-        resource_tags.value tag_value,
-        resource_tags.domain_id tag_domain_id,
-        resource_tags.account_id tag_account_id,
-        resource_tags.resource_id tag_resource_id,
-        resource_tags.resource_uuid tag_resource_uuid,
-        resource_tags.resource_type tag_resource_type,
-        resource_tags.customer tag_customer,
-        async_job.id job_id,
-        async_job.uuid job_uuid,
-        async_job.job_status job_status,
-        async_job.account_id job_account_id
-    from
-        `cloud`.`volumes`
-            inner join
-        `cloud`.`account` ON volumes.account_id = account.id
-            inner join
-        `cloud`.`domain` ON volumes.domain_id = domain.id
-            left join
-        `cloud`.`projects` ON projects.project_account_id = account.id
-            left join
-        `cloud`.`data_center` ON volumes.data_center_id = data_center.id
-            left join
-        `cloud`.`vm_instance` ON volumes.instance_id = vm_instance.id
-            left join
-        `cloud`.`user_vm` ON user_vm.id = vm_instance.id
-            left join
-        `cloud`.`volume_store_ref` ON volumes.id = volume_store_ref.volume_id
-            left join
-        `cloud`.`disk_offering` ON volumes.disk_offering_id = disk_offering.id
-            left join
-        `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id
-            left join
-        `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id
-            left join
-        `cloud`.`vm_template` ON volumes.template_id = vm_template.id OR volumes.iso_id = vm_template.id
-            left join
-        `cloud`.`resource_tags` ON resource_tags.resource_id = volumes.id
-            and resource_tags.resource_type = 'Volume'
-            left join
-        `cloud`.`async_job` ON async_job.instance_id = volumes.id
-            and async_job.instance_type = 'Volume'
-            and async_job.job_status = 0;
-            
-INSERT IGNORE INTO `cloud`.`configuration`(category, instance, component, name, value, description, default_value) VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.multipart.enabled', 'true', 'enable s3 multipart upload', 'true');            
-
-DROP VIEW IF EXISTS `cloud`.`storage_pool_view`;
-CREATE VIEW `cloud`.`storage_pool_view` AS
-    select
-        storage_pool.id,
-        storage_pool.uuid,
-        storage_pool.name,
-        storage_pool.status,
-        storage_pool.path,
-        storage_pool.pool_type,
-        storage_pool.host_address,
-        storage_pool.created,
-        storage_pool.removed,
-        storage_pool.capacity_bytes,
-        storage_pool.capacity_iops,
-        storage_pool.scope,
-        storage_pool.hypervisor,
-        storage_pool.storage_provider_name,
-        cluster.id cluster_id,
-        cluster.uuid cluster_uuid,
-        cluster.name cluster_name,
-        cluster.cluster_type,
-        data_center.id data_center_id,
-        data_center.uuid data_center_uuid,
-        data_center.name data_center_name,
-        data_center.networktype data_center_type,
-        host_pod_ref.id pod_id,
-        host_pod_ref.uuid pod_uuid,
-        host_pod_ref.name pod_name,
-        storage_pool_details.name tag,
-        op_host_capacity.used_capacity disk_used_capacity,
-        op_host_capacity.reserved_capacity disk_reserved_capacity,
-        async_job.id job_id,
-        async_job.uuid job_uuid,
-        async_job.job_status job_status,
-        async_job.account_id job_account_id
-    from
-        `cloud`.`storage_pool`
-            left join
-        `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id
-            left join
-        `cloud`.`data_center` ON storage_pool.data_center_id = data_center.id
-            left join
-        `cloud`.`host_pod_ref` ON storage_pool.pod_id = host_pod_ref.id
-            left join
-        `cloud`.`storage_pool_details` ON storage_pool_details.pool_id = storage_pool.id
-            and storage_pool_details.value = 'true'
-            left join
-        `cloud`.`op_host_capacity` ON storage_pool.id = op_host_capacity.host_id
-            and op_host_capacity.capacity_type = 3
-            left join
-        `cloud`.`async_job` ON async_job.instance_id = storage_pool.id
-            and async_job.instance_type = 'StoragePool'
-            and async_job.job_status = 0;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/setup/db/db/schema-421to430-cleanup.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-421to430-cleanup.sql b/setup/db/db/schema-421to430-cleanup.sql
new file mode 100644
index 0000000..ce5a220
--- /dev/null
+++ b/setup/db/db/schema-421to430-cleanup.sql
@@ -0,0 +1,22 @@
+-- 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.
+
+--;
+-- Schema cleanup from 4.2.0 to 4.3.0;
+--;
+
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac02987d/setup/db/db/schema-421to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-421to430.sql b/setup/db/db/schema-421to430.sql
new file mode 100644
index 0000000..8e4aa93
--- /dev/null
+++ b/setup/db/db/schema-421to430.sql
@@ -0,0 +1,446 @@
+-- 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.
+
+--;
+-- Schema upgrade from 4.2.0 to 4.3.0;
+--;
+
+-- Disable foreign key checking
+SET foreign_key_checks = 0;
+
+ALTER TABLE `cloud`.`async_job` ADD COLUMN `related` CHAR(40) NOT NULL;
+ALTER TABLE `cloud`.`async_job` DROP COLUMN `session_key`;
+ALTER TABLE `cloud`.`async_job` DROP COLUMN `job_cmd_originator`;
+ALTER TABLE `cloud`.`async_job` DROP COLUMN `callback_type`;
+ALTER TABLE `cloud`.`async_job` DROP COLUMN `callback_address`;
+
+ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_type` VARCHAR(32);
+ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_dispatcher` VARCHAR(64);
+ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_executing_msid` bigint;
+ALTER TABLE `cloud`.`async_job` ADD COLUMN `job_pending_signals` int(10) NOT NULL DEFAULT 0;
+
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state` VARCHAR(74) DEFAULT 'PowerUnknown';
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_time` DATETIME;
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_state_update_count` INT DEFAULT 0;
+ALTER TABLE `cloud`.`vm_instance` ADD COLUMN `power_host` bigint unsigned;
+ALTER TABLE `cloud`.`vm_instance` ADD CONSTRAINT `fk_vm_instance__power_host` FOREIGN KEY (`power_host`) REFERENCES `cloud`.`host`(`id`);
+
+CREATE TABLE `cloud`.`vm_work_job` (
+  `id` bigint unsigned UNIQUE NOT NULL,
+  `step` char(32) NOT NULL COMMENT 'state',
+  `vm_type` char(32) NOT NULL COMMENT 'type of vm',
+  `vm_instance_id` bigint unsigned NOT NULL COMMENT 'vm instance',
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_vm_work_job__instance_id` FOREIGN KEY (`vm_instance_id`) REFERENCES `vm_instance`(`id`) ON DELETE CASCADE,
+  INDEX `i_vm_work_job__vm`(`vm_type`, `vm_instance_id`),
+  INDEX `i_vm_work_job__step`(`step`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `cloud`.`async_job_journal` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
+  `job_id` bigint unsigned NOT NULL,
+  `journal_type` varchar(32),
+  `journal_text` varchar(1024) COMMENT 'journal descriptive informaton',
+  `journal_obj` varchar(1024) COMMENT 'journal strutural information, JSON encoded object',
+  `created` datetime NOT NULL COMMENT 'date created',
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_async_job_journal__job_id` FOREIGN KEY (`job_id`) REFERENCES `async_job`(`id`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE `cloud`.`async_job_join_map` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
+  `job_id` bigint unsigned NOT NULL,
+  `join_job_id` bigint unsigned NOT NULL,
+  `join_status` int NOT NULL,
+  `join_result` varchar(1024),
+  `join_msid` bigint,
+  `complete_msid` bigint,
+  `sync_source_id` bigint COMMENT 'upper-level job sync source info before join',
+  `wakeup_handler` varchar(64),
+  `wakeup_dispatcher` varchar(64),
+  `wakeup_interval` bigint NOT NULL DEFAULT 3000 COMMENT 'wakeup interval in seconds',
+  `created` datetime NOT NULL,
+  `last_updated` datetime,
+  `next_wakeup` datetime,
+  `expiration` datetime,
+  PRIMARY KEY (`id`),
+  CONSTRAINT `fk_async_job_join_map__job_id` FOREIGN KEY (`job_id`) REFERENCES `async_job`(`id`) ON DELETE CASCADE,
+  CONSTRAINT `fk_async_job_join_map__join_job_id` FOREIGN KEY (`join_job_id`) REFERENCES `async_job`(`id`),
+  CONSTRAINT `fk_async_job_join_map__join` UNIQUE (`job_id`, `join_job_id`),
+  INDEX `i_async_job_join_map__join_job_id`(`join_job_id`),
+  INDEX `i_async_job_join_map__created`(`created`),
+  INDEX `i_async_job_join_map__last_updated`(`last_updated`),
+  INDEX `i_async_job_join_map__next_wakeup`(`next_wakeup`),
+  INDEX `i_async_job_join_map__expiration`(`expiration`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+ALTER TABLE `cloud`.`configuration` ADD COLUMN `default_value` VARCHAR(4095) COMMENT 'Default value for a configuration parameter';
+ALTER TABLE `cloud`.`configuration` ADD COLUMN `updated` datetime COMMENT 'Time this was updated by the server. null means this row is obsolete.';
+ALTER TABLE `cloud`.`configuration` ADD COLUMN `scope` VARCHAR(255) DEFAULT NULL COMMENT 'Can this parameter be scoped';
+ALTER TABLE `cloud`.`configuration` ADD COLUMN `is_dynamic` TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Can the parameter be change dynamically without restarting the server';
+
+UPDATE `cloud`.`configuration` SET `default_value` = `value`;
+
+#Upgrade the offerings and template table to have actual remove and states
+ALTER TABLE `cloud`.`disk_offering` ADD COLUMN `state` CHAR(40) NOT NULL DEFAULT 'Active' COMMENT 'state for disk offering';
+
+UPDATE `cloud`.`disk_offering` SET `state`='Inactive' WHERE `removed` IS NOT NULL;
+UPDATE `cloud`.`disk_offering` SET `removed`=NULL;
+
+UPDATE `cloud`.`vm_template` SET `state`='Inactive' WHERE `removed` IS NOT NULL;
+UPDATE `cloud`.`vm_template` SET `state`='Active' WHERE `removed` IS NULL;
+UPDATE `cloud`.`vm_template` SET `removed`=NULL;
+
+DROP VIEW IF EXISTS `cloud`.`disk_offering_view`;
+CREATE VIEW `cloud`.`disk_offering_view` AS
+    select
+        disk_offering.id,
+        disk_offering.uuid,
+        disk_offering.name,
+        disk_offering.display_text,
+        disk_offering.disk_size,
+        disk_offering.min_iops,
+        disk_offering.max_iops,
+        disk_offering.created,
+        disk_offering.tags,
+        disk_offering.customized,
+        disk_offering.customized_iops,
+        disk_offering.removed,
+        disk_offering.use_local_storage,
+        disk_offering.system_use,
+        disk_offering.bytes_read_rate,
+        disk_offering.bytes_write_rate,
+        disk_offering.iops_read_rate,
+        disk_offering.iops_write_rate,
+        disk_offering.sort_key,
+        disk_offering.type,
+		disk_offering.display_offering,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path
+    from
+        `cloud`.`disk_offering`
+            left join
+        `cloud`.`domain` ON disk_offering.domain_id = domain.id
+	where
+		disk_offering.state='ACTIVE';
+
+DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
+CREATE VIEW `cloud`.`service_offering_view` AS
+    select 
+        service_offering.id,
+        disk_offering.uuid,
+        disk_offering.name,
+        disk_offering.display_text,
+        disk_offering.created,
+        disk_offering.tags,
+        disk_offering.removed,
+        disk_offering.use_local_storage,
+        disk_offering.system_use,
+        disk_offering.bytes_read_rate,
+        disk_offering.bytes_write_rate,
+        disk_offering.iops_read_rate,
+        disk_offering.iops_write_rate,
+        service_offering.cpu,
+        service_offering.speed,
+        service_offering.ram_size,
+        service_offering.nw_rate,
+        service_offering.mc_rate,
+        service_offering.ha_enabled,
+        service_offering.limit_cpu_use,
+        service_offering.host_tag,
+        service_offering.default_use,
+        service_offering.vm_type,
+        service_offering.sort_key,
+        service_offering.is_volatile,
+        service_offering.deployment_planner,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path
+    from
+        `cloud`.`service_offering`
+            inner join
+        `cloud`.`disk_offering` ON service_offering.id = disk_offering.id
+            left join
+        `cloud`.`domain` ON disk_offering.domain_id = domain.id
+	where
+		disk_offering.state='Active';
+		
+DROP VIEW IF EXISTS `cloud`.`template_view`;
+CREATE VIEW `cloud`.`template_view` AS
+    select 
+        vm_template.id,
+        vm_template.uuid,
+        vm_template.unique_name,
+        vm_template.name,
+        vm_template.public,
+        vm_template.featured,
+        vm_template.type,
+        vm_template.hvm,
+        vm_template.bits,
+        vm_template.url,
+        vm_template.format,
+        vm_template.created,
+        vm_template.checksum,
+        vm_template.display_text,
+        vm_template.enable_password,
+        vm_template.dynamically_scalable,
+        vm_template.guest_os_id,
+        guest_os.uuid guest_os_uuid,
+        guest_os.display_name guest_os_name,
+        vm_template.bootable,
+        vm_template.prepopulate,
+        vm_template.cross_zones,
+        vm_template.hypervisor_type,
+        vm_template.extractable,
+        vm_template.template_tag,
+        vm_template.sort_key,
+        vm_template.removed,
+        vm_template.enable_sshkey,
+        source_template.id source_template_id,
+        source_template.uuid source_template_uuid,
+        account.id account_id,
+        account.uuid account_uuid,
+        account.account_name account_name,
+        account.type account_type,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path,
+        projects.id project_id,
+        projects.uuid project_uuid,
+        projects.name project_name,        
+        data_center.id data_center_id,
+        data_center.uuid data_center_uuid,
+        data_center.name data_center_name,
+        launch_permission.account_id lp_account_id,
+        template_store_ref.store_id,
+		image_store.scope as store_scope,
+        template_store_ref.state,
+        template_store_ref.download_state,
+        template_store_ref.download_pct,
+        template_store_ref.error_str,
+        template_store_ref.size,
+        template_store_ref.destroyed,
+        template_store_ref.created created_on_store,
+        vm_template_details.name detail_name,
+        vm_template_details.value detail_value,
+        resource_tags.id tag_id,
+        resource_tags.uuid tag_uuid,
+        resource_tags.key tag_key,
+        resource_tags.value tag_value,
+        resource_tags.domain_id tag_domain_id,
+        resource_tags.account_id tag_account_id,
+        resource_tags.resource_id tag_resource_id,
+        resource_tags.resource_uuid tag_resource_uuid,
+        resource_tags.resource_type tag_resource_type,
+        resource_tags.customer tag_customer,
+		CONCAT(vm_template.id, '_', IFNULL(data_center.id, 0)) as temp_zone_pair
+    from
+        `cloud`.`vm_template`
+            inner join
+        `cloud`.`guest_os` ON guest_os.id = vm_template.guest_os_id        
+            inner join
+        `cloud`.`account` ON account.id = vm_template.account_id
+            inner join
+        `cloud`.`domain` ON domain.id = account.domain_id
+            left join
+        `cloud`.`projects` ON projects.project_account_id = account.id    
+            left join
+        `cloud`.`vm_template_details` ON vm_template_details.template_id = vm_template.id         
+            left join
+        `cloud`.`vm_template` source_template ON source_template.id = vm_template.source_template_id    
+            left join
+        `cloud`.`template_store_ref` ON template_store_ref.template_id = vm_template.id and template_store_ref.store_role = 'Image'
+            left join
+        `cloud`.`image_store` ON image_store.removed is NULL AND template_store_ref.store_id is not NULL AND image_store.id = template_store_ref.store_id 
+        	left join
+        `cloud`.`template_zone_ref` ON template_zone_ref.template_id = vm_template.id AND template_store_ref.store_id is NULL AND template_zone_ref.removed is null    
+            left join
+        `cloud`.`data_center` ON (image_store.data_center_id = data_center.id OR template_zone_ref.zone_id = data_center.id)
+            left join
+        `cloud`.`launch_permission` ON launch_permission.template_id = vm_template.id
+            left join
+        `cloud`.`resource_tags` ON resource_tags.resource_id = vm_template.id
+            and (resource_tags.resource_type = 'Template' or resource_tags.resource_type='ISO')
+    where
+        vm_template.state='Active';
+
+DROP VIEW IF EXISTS `cloud`.`volume_view`;
+CREATE VIEW `cloud`.`volume_view` AS
+    select
+        volumes.id,
+        volumes.uuid,
+        volumes.name,
+        volumes.device_id,
+        volumes.volume_type,
+        volumes.size,
+        volumes.min_iops,
+        volumes.max_iops,
+        volumes.created,
+        volumes.state,
+        volumes.attached,
+        volumes.removed,
+        volumes.pod_id,
+	volumes.display_volume,
+        volumes.format,
+	volumes.path,
+        account.id account_id,
+        account.uuid account_uuid,
+        account.account_name account_name,
+        account.type account_type,
+        domain.id domain_id,
+        domain.uuid domain_uuid,
+        domain.name domain_name,
+        domain.path domain_path,
+        projects.id project_id,
+        projects.uuid project_uuid,
+        projects.name project_name,
+        data_center.id data_center_id,
+        data_center.uuid data_center_uuid,
+        data_center.name data_center_name,
+	data_center.networktype data_center_type,
+        vm_instance.id vm_id,
+        vm_instance.uuid vm_uuid,
+        vm_instance.name vm_name,
+        vm_instance.state vm_state,
+        vm_instance.vm_type,
+        user_vm.display_name vm_display_name,
+        volume_store_ref.size volume_store_size,
+        volume_store_ref.download_pct,
+        volume_store_ref.download_state,
+        volume_store_ref.error_str,
+        volume_store_ref.created created_on_store,
+        disk_offering.id disk_offering_id,
+        disk_offering.uuid disk_offering_uuid,
+        disk_offering.name disk_offering_name,
+        disk_offering.display_text disk_offering_display_text,
+        disk_offering.use_local_storage,
+        disk_offering.system_use,
+        disk_offering.bytes_read_rate,
+        disk_offering.bytes_write_rate,
+        disk_offering.iops_read_rate,
+        disk_offering.iops_write_rate,
+        storage_pool.id pool_id,
+        storage_pool.uuid pool_uuid,
+        storage_pool.name pool_name,
+        cluster.hypervisor_type,
+        vm_template.id template_id,
+        vm_template.uuid template_uuid,
+        vm_template.extractable,
+        vm_template.type template_type,
+        resource_tags.id tag_id,
+        resource_tags.uuid tag_uuid,
+        resource_tags.key tag_key,
+        resource_tags.value tag_value,
+        resource_tags.domain_id tag_domain_id,
+        resource_tags.account_id tag_account_id,
+        resource_tags.resource_id tag_resource_id,
+        resource_tags.resource_uuid tag_resource_uuid,
+        resource_tags.resource_type tag_resource_type,
+        resource_tags.customer tag_customer,
+        async_job.id job_id,
+        async_job.uuid job_uuid,
+        async_job.job_status job_status,
+        async_job.account_id job_account_id
+    from
+        `cloud`.`volumes`
+            inner join
+        `cloud`.`account` ON volumes.account_id = account.id
+            inner join
+        `cloud`.`domain` ON volumes.domain_id = domain.id
+            left join
+        `cloud`.`projects` ON projects.project_account_id = account.id
+            left join
+        `cloud`.`data_center` ON volumes.data_center_id = data_center.id
+            left join
+        `cloud`.`vm_instance` ON volumes.instance_id = vm_instance.id
+            left join
+        `cloud`.`user_vm` ON user_vm.id = vm_instance.id
+            left join
+        `cloud`.`volume_store_ref` ON volumes.id = volume_store_ref.volume_id
+            left join
+        `cloud`.`disk_offering` ON volumes.disk_offering_id = disk_offering.id
+            left join
+        `cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id
+            left join
+        `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id
+            left join
+        `cloud`.`vm_template` ON volumes.template_id = vm_template.id OR volumes.iso_id = vm_template.id
+            left join
+        `cloud`.`resource_tags` ON resource_tags.resource_id = volumes.id
+            and resource_tags.resource_type = 'Volume'
+            left join
+        `cloud`.`async_job` ON async_job.instance_id = volumes.id
+            and async_job.instance_type = 'Volume'
+            and async_job.job_status = 0;
+            
+DROP VIEW IF EXISTS `cloud`.`storage_pool_view`;
+CREATE VIEW `cloud`.`storage_pool_view` AS
+    select
+        storage_pool.id,
+        storage_pool.uuid,
+        storage_pool.name,
+        storage_pool.status,
+        storage_pool.path,
+        storage_pool.pool_type,
+        storage_pool.host_address,
+        storage_pool.created,
+        storage_pool.removed,
+        storage_pool.capacity_bytes,
+        storage_pool.capacity_iops,
+        storage_pool.scope,
+        storage_pool.hypervisor,
+        storage_pool.storage_provider_name,
+        cluster.id cluster_id,
+        cluster.uuid cluster_uuid,
+        cluster.name cluster_name,
+        cluster.cluster_type,
+        data_center.id data_center_id,
+        data_center.uuid data_center_uuid,
+        data_center.name data_center_name,
+        data_center.networktype data_center_type,
+        host_pod_ref.id pod_id,
+        host_pod_ref.uuid pod_uuid,
+        host_pod_ref.name pod_name,
+        storage_pool_details.name tag,
+        op_host_capacity.used_capacity disk_used_capacity,
+        op_host_capacity.reserved_capacity disk_reserved_capacity,
+        async_job.id job_id,
+        async_job.uuid job_uuid,
+        async_job.job_status job_status,
+        async_job.account_id job_account_id
+    from
+        `cloud`.`storage_pool`
+            left join
+        `cloud`.`cluster` ON storage_pool.cluster_id = cluster.id
+            left join
+        `cloud`.`data_center` ON storage_pool.data_center_id = data_center.id
+            left join
+        `cloud`.`host_pod_ref` ON storage_pool.pod_id = host_pod_ref.id
+            left join
+        `cloud`.`storage_pool_details` ON storage_pool_details.pool_id = storage_pool.id
+            and storage_pool_details.value = 'true'
+            left join
+        `cloud`.`op_host_capacity` ON storage_pool.id = op_host_capacity.host_id
+            and op_host_capacity.capacity_type = 3
+            left join
+        `cloud`.`async_job` ON async_job.instance_id = storage_pool.id
+            and async_job.instance_type = 'StoragePool'
+            and async_job.job_status = 0;