You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2023/11/17 09:28:04 UTC

(cloudstack) branch main updated: Database VIEW management via separated files (#7417)

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new adbb5520ca5 Database VIEW management via separated files (#7417)
adbb5520ca5 is described below

commit adbb5520ca51572c2d840ff2a0782505ef82d972
Author: Daniel Augusto Veronezi Salvador <38...@users.noreply.github.com>
AuthorDate: Fri Nov 17 06:27:53 2023 -0300

    Database VIEW management via separated files (#7417)
    
    Co-authored-by: Daniel Augusto Veronezi Salvador <gu...@apache.org>
---
 .../com/cloud/upgrade/DatabaseUpgradeChecker.java  |  28 ++
 .../resources/META-INF/db/schema-41810to41900.sql  | 424 ---------------------
 .../META-INF/db/views/cloud.async_job_view.sql     | 129 +++++++
 .../META-INF/db/views/cloud.data_center_view.sql   |  59 +++
 .../META-INF/db/views/cloud.disk_offering_view.sql |  82 ++++
 .../META-INF/db/views/cloud.domain_router_view.sql | 126 ++++++
 .../db/views/cloud.network_offering_view.sql       |  85 +++++
 .../db/views/cloud.service_offering_view.sql       | 114 ++++++
 .../META-INF/db/views/cloud.snapshot_view.sql      | 107 ++++++
 .../META-INF/db/views/cloud.template_view.sql      | 131 +++++++
 .../META-INF/db/views/cloud.user_view.sql          |  65 ++++
 .../META-INF/db/views/cloud.user_vm_view.sql       | 215 +++++++++++
 utils/src/main/java/com/cloud/utils/FileUtil.java  |  33 ++
 13 files changed, 1174 insertions(+), 424 deletions(-)

diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
index 21331f654e3..697782dc1db 100644
--- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
+++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java
@@ -22,15 +22,18 @@ import static com.google.common.collect.ObjectArrays.concat;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.nio.file.Paths;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Date;
+import java.util.List;
 
 import javax.inject.Inject;
 
+import com.cloud.utils.FileUtil;
 import org.apache.cloudstack.utils.CloudStackVersion;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.log4j.Logger;
@@ -123,6 +126,7 @@ import com.google.common.annotations.VisibleForTesting;
 public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
     private static final Logger s_logger = Logger.getLogger(DatabaseUpgradeChecker.class);
     private final DatabaseVersionHierarchy hierarchy;
+    private static final String VIEWS_DIRECTORY = Paths.get("META-INF", "db", "views").toString();
 
     @Inject
     VersionDao _dao;
@@ -363,9 +367,33 @@ public class DatabaseUpgradeChecker implements SystemIntegrityChecker {
                 txn.close();
             }
         }
+
+        executeViewScripts();
         updateSystemVmTemplates(upgrades);
     }
 
+    protected void executeViewScripts() {
+        s_logger.info(String.format("Executing VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY));
+        List<String> filesPathUnderViewsDirectory = FileUtil.getFilesPathsUnderResourceDirectory(VIEWS_DIRECTORY);
+
+        try (TransactionLegacy txn = TransactionLegacy.open("execute-view-scripts")) {
+            Connection conn = txn.getConnection();
+
+            for (String filePath : filesPathUnderViewsDirectory) {
+                s_logger.debug(String.format("Executing VIEW script [%s].", filePath));
+
+                InputStream viewScript = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
+                runScript(conn, viewScript);
+            }
+
+            s_logger.info(String.format("Finished execution of VIEW scripts that are under resource directory [%s].", VIEWS_DIRECTORY));
+        } catch (SQLException e) {
+            String message = String.format("Unable to execute VIEW scripts due to [%s].", e.getMessage());
+            s_logger.error(message, e);
+            throw new CloudRuntimeException(message, e);
+        }
+    }
+
     @Override
     public void check() {
         GlobalLock lock = GlobalLock.getInternLock("DatabaseUpgrade");
diff --git a/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql b/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql
index f2585deea1a..c79e99cfecd 100644
--- a/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql
+++ b/engine/schema/src/main/resources/META-INF/db/schema-41810to41900.sql
@@ -21,116 +21,6 @@
 
 ALTER TABLE `cloud`.`mshost` MODIFY COLUMN `state` varchar(25);
 
-DROP VIEW IF EXISTS `cloud`.`async_job_view`;
-CREATE VIEW `cloud`.`async_job_view` AS
-    select
-        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,
-        user.id user_id,
-        user.uuid user_uuid,
-        async_job.id,
-        async_job.uuid,
-        async_job.job_cmd,
-        async_job.job_status,
-        async_job.job_process_status,
-        async_job.job_result_code,
-        async_job.job_result,
-        async_job.created,
-        async_job.removed,
-        async_job.instance_type,
-        async_job.instance_id,
-        async_job.job_executing_msid,
-        CASE
-            WHEN async_job.instance_type = 'Volume' THEN volumes.uuid
-            WHEN
-                async_job.instance_type = 'Template'
-                    or async_job.instance_type = 'Iso'
-            THEN
-                vm_template.uuid
-            WHEN
-                async_job.instance_type = 'VirtualMachine'
-                    or async_job.instance_type = 'ConsoleProxy'
-                    or async_job.instance_type = 'SystemVm'
-                    or async_job.instance_type = 'DomainRouter'
-            THEN
-                vm_instance.uuid
-            WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid
-            WHEN async_job.instance_type = 'Host' THEN host.uuid
-            WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid
-            WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid
-            WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid
-            WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid
-            WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid
-            WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid
-            WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid
-            WHEN async_job.instance_type = 'Account' THEN acct.uuid
-            WHEN async_job.instance_type = 'User' THEN us.uuid
-            WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid
-            WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid
-            WHEN async_job.instance_type = 'Counter' THEN counter.uuid
-            WHEN async_job.instance_type = 'Condition' THEN conditions.uuid
-            WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid
-            WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid
-            WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid
-            ELSE null
-        END instance_uuid
-    from
-        `cloud`.`async_job`
-            left join
-        `cloud`.`account` ON async_job.account_id = account.id
-            left join
-        `cloud`.`domain` ON domain.id = account.domain_id
-            left join
-        `cloud`.`user` ON async_job.user_id = user.id
-            left join
-        `cloud`.`volumes` ON async_job.instance_id = volumes.id
-            left join
-        `cloud`.`vm_template` ON async_job.instance_id = vm_template.id
-            left join
-        `cloud`.`vm_instance` ON async_job.instance_id = vm_instance.id
-            left join
-        `cloud`.`snapshots` ON async_job.instance_id = snapshots.id
-            left join
-        `cloud`.`host` ON async_job.instance_id = host.id
-            left join
-        `cloud`.`storage_pool` ON async_job.instance_id = storage_pool.id
-            left join
-        `cloud`.`user_ip_address` ON async_job.instance_id = user_ip_address.id
-            left join
-        `cloud`.`security_group` ON async_job.instance_id = security_group.id
-            left join
-        `cloud`.`physical_network` ON async_job.instance_id = physical_network.id
-            left join
-        `cloud`.`physical_network_traffic_types` ON async_job.instance_id = physical_network_traffic_types.id
-            left join
-        `cloud`.`physical_network_service_providers` ON async_job.instance_id = physical_network_service_providers.id
-            left join
-        `cloud`.`firewall_rules` ON async_job.instance_id = firewall_rules.id
-            left join
-        `cloud`.`account` acct ON async_job.instance_id = acct.id
-            left join
-        `cloud`.`user` us ON async_job.instance_id = us.id
-            left join
-        `cloud`.`static_routes` ON async_job.instance_id = static_routes.id
-            left join
-        `cloud`.`vpc_gateways` ON async_job.instance_id = vpc_gateways.id
-            left join
-        `cloud`.`counter` ON async_job.instance_id = counter.id
-            left join
-        `cloud`.`conditions` ON async_job.instance_id = conditions.id
-            left join
-        `cloud`.`autoscale_policies` ON async_job.instance_id = autoscale_policies.id
-            left join
-        `cloud`.`autoscale_vmprofiles` ON async_job.instance_id = autoscale_vmprofiles.id
-            left join
-        `cloud`.`autoscale_vmgroups` ON async_job.instance_id = autoscale_vmgroups.id;
-
 -- Invalidate existing console_session records
 UPDATE `cloud`.`console_session` SET removed=now();
 -- Modify acquired column in console_session to datetime type
@@ -246,203 +136,6 @@ CREATE TABLE IF NOT EXISTS `cloud`.`vnf_template_details` (
     CONSTRAINT `fk_vnf_template_details__template_id` FOREIGN KEY (`template_id`) REFERENCES `vm_template` (`id`) ON DELETE CASCADE
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
-DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
-CREATE
-    VIEW `user_vm_view` AS
-SELECT
-    `vm_instance`.`id` AS `id`,
-    `vm_instance`.`name` AS `name`,
-    `user_vm`.`display_name` AS `display_name`,
-    `user_vm`.`user_data` AS `user_data`,
-    `account`.`id` AS `account_id`,
-    `account`.`uuid` AS `account_uuid`,
-    `account`.`account_name` AS `account_name`,
-    `account`.`type` AS `account_type`,
-    `domain`.`id` AS `domain_id`,
-    `domain`.`uuid` AS `domain_uuid`,
-    `domain`.`name` AS `domain_name`,
-    `domain`.`path` AS `domain_path`,
-    `projects`.`id` AS `project_id`,
-    `projects`.`uuid` AS `project_uuid`,
-    `projects`.`name` AS `project_name`,
-    `instance_group`.`id` AS `instance_group_id`,
-    `instance_group`.`uuid` AS `instance_group_uuid`,
-    `instance_group`.`name` AS `instance_group_name`,
-    `vm_instance`.`uuid` AS `uuid`,
-    `vm_instance`.`user_id` AS `user_id`,
-    `vm_instance`.`last_host_id` AS `last_host_id`,
-    `vm_instance`.`vm_type` AS `type`,
-    `vm_instance`.`limit_cpu_use` AS `limit_cpu_use`,
-    `vm_instance`.`created` AS `created`,
-    `vm_instance`.`state` AS `state`,
-    `vm_instance`.`update_time` AS `update_time`,
-    `vm_instance`.`removed` AS `removed`,
-    `vm_instance`.`ha_enabled` AS `ha_enabled`,
-    `vm_instance`.`hypervisor_type` AS `hypervisor_type`,
-    `vm_instance`.`instance_name` AS `instance_name`,
-    `vm_instance`.`guest_os_id` AS `guest_os_id`,
-    `vm_instance`.`display_vm` AS `display_vm`,
-    `guest_os`.`uuid` AS `guest_os_uuid`,
-    `vm_instance`.`pod_id` AS `pod_id`,
-    `host_pod_ref`.`uuid` AS `pod_uuid`,
-    `vm_instance`.`private_ip_address` AS `private_ip_address`,
-    `vm_instance`.`private_mac_address` AS `private_mac_address`,
-    `vm_instance`.`vm_type` AS `vm_type`,
-    `data_center`.`id` AS `data_center_id`,
-    `data_center`.`uuid` AS `data_center_uuid`,
-    `data_center`.`name` AS `data_center_name`,
-    `data_center`.`is_security_group_enabled` AS `security_group_enabled`,
-    `data_center`.`networktype` AS `data_center_network_type`,
-    `host`.`id` AS `host_id`,
-    `host`.`uuid` AS `host_uuid`,
-    `host`.`name` AS `host_name`,
-    `host`.`cluster_id` AS `cluster_id`,
-    `host`.`status` AS `host_status`,
-    `host`.`resource_state` AS `host_resource_state`,
-    `vm_template`.`id` AS `template_id`,
-    `vm_template`.`uuid` AS `template_uuid`,
-    `vm_template`.`name` AS `template_name`,
-    `vm_template`.`type` AS `template_type`,
-    `vm_template`.`display_text` AS `template_display_text`,
-    `vm_template`.`enable_password` AS `password_enabled`,
-    `iso`.`id` AS `iso_id`,
-    `iso`.`uuid` AS `iso_uuid`,
-    `iso`.`name` AS `iso_name`,
-    `iso`.`display_text` AS `iso_display_text`,
-    `service_offering`.`id` AS `service_offering_id`,
-    `service_offering`.`uuid` AS `service_offering_uuid`,
-    `disk_offering`.`uuid` AS `disk_offering_uuid`,
-    `disk_offering`.`id` AS `disk_offering_id`,
-    (CASE
-         WHEN ISNULL(`service_offering`.`cpu`) THEN `custom_cpu`.`value`
-         ELSE `service_offering`.`cpu`
-        END) AS `cpu`,
-    (CASE
-         WHEN ISNULL(`service_offering`.`speed`) THEN `custom_speed`.`value`
-         ELSE `service_offering`.`speed`
-        END) AS `speed`,
-    (CASE
-         WHEN ISNULL(`service_offering`.`ram_size`) THEN `custom_ram_size`.`value`
-         ELSE `service_offering`.`ram_size`
-        END) AS `ram_size`,
-    `backup_offering`.`uuid` AS `backup_offering_uuid`,
-    `backup_offering`.`id` AS `backup_offering_id`,
-    `service_offering`.`name` AS `service_offering_name`,
-    `disk_offering`.`name` AS `disk_offering_name`,
-    `backup_offering`.`name` AS `backup_offering_name`,
-    `storage_pool`.`id` AS `pool_id`,
-    `storage_pool`.`uuid` AS `pool_uuid`,
-    `storage_pool`.`pool_type` AS `pool_type`,
-    `volumes`.`id` AS `volume_id`,
-    `volumes`.`uuid` AS `volume_uuid`,
-    `volumes`.`device_id` AS `volume_device_id`,
-    `volumes`.`volume_type` AS `volume_type`,
-    `security_group`.`id` AS `security_group_id`,
-    `security_group`.`uuid` AS `security_group_uuid`,
-    `security_group`.`name` AS `security_group_name`,
-    `security_group`.`description` AS `security_group_description`,
-    `nics`.`id` AS `nic_id`,
-    `nics`.`uuid` AS `nic_uuid`,
-    `nics`.`device_id` AS `nic_device_id`,
-    `nics`.`network_id` AS `network_id`,
-    `nics`.`ip4_address` AS `ip_address`,
-    `nics`.`ip6_address` AS `ip6_address`,
-    `nics`.`ip6_gateway` AS `ip6_gateway`,
-    `nics`.`ip6_cidr` AS `ip6_cidr`,
-    `nics`.`default_nic` AS `is_default_nic`,
-    `nics`.`gateway` AS `gateway`,
-    `nics`.`netmask` AS `netmask`,
-    `nics`.`mac_address` AS `mac_address`,
-    `nics`.`broadcast_uri` AS `broadcast_uri`,
-    `nics`.`isolation_uri` AS `isolation_uri`,
-    `vpc`.`id` AS `vpc_id`,
-    `vpc`.`uuid` AS `vpc_uuid`,
-    `networks`.`uuid` AS `network_uuid`,
-    `networks`.`name` AS `network_name`,
-    `networks`.`traffic_type` AS `traffic_type`,
-    `networks`.`guest_type` AS `guest_type`,
-    `user_ip_address`.`id` AS `public_ip_id`,
-    `user_ip_address`.`uuid` AS `public_ip_uuid`,
-    `user_ip_address`.`public_ip_address` AS `public_ip_address`,
-    `ssh_details`.`value` AS `keypair_names`,
-    `resource_tags`.`id` AS `tag_id`,
-    `resource_tags`.`uuid` AS `tag_uuid`,
-    `resource_tags`.`key` AS `tag_key`,
-    `resource_tags`.`value` AS `tag_value`,
-    `resource_tags`.`domain_id` AS `tag_domain_id`,
-    `domain`.`uuid` AS `tag_domain_uuid`,
-    `domain`.`name` AS `tag_domain_name`,
-    `resource_tags`.`account_id` AS `tag_account_id`,
-    `account`.`account_name` AS `tag_account_name`,
-    `resource_tags`.`resource_id` AS `tag_resource_id`,
-    `resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
-    `resource_tags`.`resource_type` AS `tag_resource_type`,
-    `resource_tags`.`customer` AS `tag_customer`,
-    `async_job`.`id` AS `job_id`,
-    `async_job`.`uuid` AS `job_uuid`,
-    `async_job`.`job_status` AS `job_status`,
-    `async_job`.`account_id` AS `job_account_id`,
-    `affinity_group`.`id` AS `affinity_group_id`,
-    `affinity_group`.`uuid` AS `affinity_group_uuid`,
-    `affinity_group`.`name` AS `affinity_group_name`,
-    `affinity_group`.`description` AS `affinity_group_description`,
-    `autoscale_vmgroups`.`id` AS `autoscale_vmgroup_id`,
-    `autoscale_vmgroups`.`uuid` AS `autoscale_vmgroup_uuid`,
-    `autoscale_vmgroups`.`name` AS `autoscale_vmgroup_name`,
-    `vm_instance`.`dynamically_scalable` AS `dynamically_scalable`,
-    `user_data`.`id` AS `user_data_id`,
-    `user_data`.`uuid` AS `user_data_uuid`,
-    `user_data`.`name` AS `user_data_name`,
-    `user_vm`.`user_data_details` AS `user_data_details`,
-    `vm_template`.`user_data_link_policy` AS `user_data_policy`
-FROM
-    (((((((((((((((((((((((((((((((((((`user_vm`
-        JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
-            AND ISNULL(`vm_instance`.`removed`))))
-        JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
-        JOIN `domain` ON ((`vm_instance`.`domain_id` = `domain`.`id`)))
-        LEFT JOIN `guest_os` ON ((`vm_instance`.`guest_os_id` = `guest_os`.`id`)))
-        LEFT JOIN `host_pod_ref` ON ((`vm_instance`.`pod_id` = `host_pod_ref`.`id`)))
-        LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
-        LEFT JOIN `instance_group_vm_map` ON ((`vm_instance`.`id` = `instance_group_vm_map`.`instance_id`)))
-        LEFT JOIN `instance_group` ON ((`instance_group_vm_map`.`group_id` = `instance_group`.`id`)))
-        LEFT JOIN `data_center` ON ((`vm_instance`.`data_center_id` = `data_center`.`id`)))
-        LEFT JOIN `host` ON ((`vm_instance`.`host_id` = `host`.`id`)))
-        LEFT JOIN `vm_template` ON ((`vm_instance`.`vm_template_id` = `vm_template`.`id`)))
-        LEFT JOIN `vm_template` `iso` ON ((`iso`.`id` = `user_vm`.`iso_id`)))
-        LEFT JOIN `volumes` ON ((`vm_instance`.`id` = `volumes`.`instance_id`)))
-        LEFT JOIN `service_offering` ON ((`vm_instance`.`service_offering_id` = `service_offering`.`id`)))
-        LEFT JOIN `disk_offering` `svc_disk_offering` ON ((`volumes`.`disk_offering_id` = `svc_disk_offering`.`id`)))
-        LEFT JOIN `disk_offering` ON ((`volumes`.`disk_offering_id` = `disk_offering`.`id`)))
-        LEFT JOIN `backup_offering` ON ((`vm_instance`.`backup_offering_id` = `backup_offering`.`id`)))
-        LEFT JOIN `storage_pool` ON ((`volumes`.`pool_id` = `storage_pool`.`id`)))
-        LEFT JOIN `security_group_vm_map` ON ((`vm_instance`.`id` = `security_group_vm_map`.`instance_id`)))
-        LEFT JOIN `security_group` ON ((`security_group_vm_map`.`security_group_id` = `security_group`.`id`)))
-        LEFT JOIN `user_data` ON ((`user_data`.`id` = `user_vm`.`user_data_id`)))
-        LEFT JOIN `nics` ON (((`vm_instance`.`id` = `nics`.`instance_id`)
-        AND ISNULL(`nics`.`removed`))))
-        LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
-        LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
-        AND ISNULL(`vpc`.`removed`))))
-        LEFT JOIN `user_ip_address` ON ((`user_ip_address`.`vm_id` = `vm_instance`.`id`)))
-        LEFT JOIN `user_vm_details` `ssh_details` ON (((`ssh_details`.`vm_id` = `vm_instance`.`id`)
-        AND (`ssh_details`.`name` = 'SSH.KeyPairNames'))))
-        LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_instance`.`id`)
-        AND (`resource_tags`.`resource_type` = 'UserVm'))))
-        LEFT JOIN `async_job` ON (((`async_job`.`instance_id` = `vm_instance`.`id`)
-        AND (`async_job`.`instance_type` = 'VirtualMachine')
-        AND (`async_job`.`job_status` = 0))))
-        LEFT JOIN `affinity_group_vm_map` ON ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`)))
-        LEFT JOIN `affinity_group` ON ((`affinity_group_vm_map`.`affinity_group_id` = `affinity_group`.`id`)))
-        LEFT JOIN `autoscale_vmgroup_vm_map` ON ((`autoscale_vmgroup_vm_map`.`instance_id` = `vm_instance`.`id`)))
-        LEFT JOIN `autoscale_vmgroups` ON ((`autoscale_vmgroup_vm_map`.`vmgroup_id` = `autoscale_vmgroups`.`id`)))
-        LEFT JOIN `user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `vm_instance`.`id`)
-        AND (`custom_cpu`.`name` = 'CpuNumber'))))
-        LEFT JOIN `user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `vm_instance`.`id`)
-        AND (`custom_speed`.`name` = 'CpuSpeed'))))
-        LEFT JOIN `user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `vm_instance`.`id`)
-        AND (`custom_ram_size`.`name` = 'memory'))));
-
 -- Add tables for Cluster DRS
 DROP TABLE IF EXISTS `cloud`.`cluster_drs_plan`;
 CREATE TABLE `cloud`.`cluster_drs_plan` (
@@ -503,120 +196,3 @@ ALTER TABLE `cloud`.`snapshot_store_ref`
     ADD COLUMN `error_str` varchar(255) DEFAULT NULL COMMENT 'the error message when the snapshot download occurs' AFTER `download_pct`,
     ADD COLUMN `local_path` varchar(255) DEFAULT NULL COMMENT 'the path of the snapshot download' AFTER `error_str`,
     ADD COLUMN `display` tinyint(1) unsigned NOT NULL DEFAULT 1  COMMENT '1 implies store reference is available for listing' AFTER `error_str`;
-
--- Create snapshot_view
-DROP VIEW IF EXISTS `cloud`.`snapshot_view`;
-CREATE VIEW `cloud`.`snapshot_view` AS
-     SELECT
-         `snapshots`.`id` AS `id`,
-         `snapshots`.`uuid` AS `uuid`,
-         `snapshots`.`name` AS `name`,
-         `snapshots`.`status` AS `status`,
-         `snapshots`.`disk_offering_id` AS `disk_offering_id`,
-         `snapshots`.`snapshot_type` AS `snapshot_type`,
-         `snapshots`.`type_description` AS `type_description`,
-         `snapshots`.`size` AS `size`,
-         `snapshots`.`created` AS `created`,
-         `snapshots`.`removed` AS `removed`,
-         `snapshots`.`location_type` AS `location_type`,
-         `snapshots`.`hypervisor_type` AS `hypervisor_type`,
-         `account`.`id` AS `account_id`,
-         `account`.`uuid` AS `account_uuid`,
-         `account`.`account_name` AS `account_name`,
-         `account`.`type` AS `account_type`,
-         `domain`.`id` AS `domain_id`,
-         `domain`.`uuid` AS `domain_uuid`,
-         `domain`.`name` AS `domain_name`,
-         `domain`.`path` AS `domain_path`,
-         `projects`.`id` AS `project_id`,
-         `projects`.`uuid` AS `project_uuid`,
-         `projects`.`name` AS `project_name`,
-         `volumes`.`id` AS `volume_id`,
-         `volumes`.`uuid` AS `volume_uuid`,
-         `volumes`.`name` AS `volume_name`,
-         `volumes`.`volume_type` AS `volume_type`,
-         `volumes`.`size` AS `volume_size`,
-         `data_center`.`id` AS `data_center_id`,
-         `data_center`.`uuid` AS `data_center_uuid`,
-         `data_center`.`name` AS `data_center_name`,
-         `snapshot_store_ref`.`store_id` AS `store_id`,
-         IFNULL(`image_store`.`uuid`, `storage_pool`.`uuid`) AS `store_uuid`,
-         IFNULL(`image_store`.`name`, `storage_pool`.`name`) AS `store_name`,
-         `snapshot_store_ref`.`store_role` AS `store_role`,
-         `snapshot_store_ref`.`state` AS `store_state`,
-         `snapshot_store_ref`.`download_state` AS `download_state`,
-         `snapshot_store_ref`.`download_pct` AS `download_pct`,
-         `snapshot_store_ref`.`error_str` AS `error_str`,
-         `snapshot_store_ref`.`size` AS `store_size`,
-         `snapshot_store_ref`.`created` AS `created_on_store`,
-         `resource_tags`.`id` AS `tag_id`,
-         `resource_tags`.`uuid` AS `tag_uuid`,
-         `resource_tags`.`key` AS `tag_key`,
-         `resource_tags`.`value` AS `tag_value`,
-         `resource_tags`.`domain_id` AS `tag_domain_id`,
-         `domain`.`uuid` AS `tag_domain_uuid`,
-         `domain`.`name` AS `tag_domain_name`,
-         `resource_tags`.`account_id` AS `tag_account_id`,
-         `account`.`account_name` AS `tag_account_name`,
-         `resource_tags`.`resource_id` AS `tag_resource_id`,
-         `resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
-         `resource_tags`.`resource_type` AS `tag_resource_type`,
-         `resource_tags`.`customer` AS `tag_customer`,
-          CONCAT(`snapshots`.`id`,
-                 '_',
-                 IFNULL(`snapshot_store_ref`.`store_role`, 'UNKNOWN'),
-                 '_',
-                 IFNULL(`snapshot_store_ref`.`store_id`, 0)) AS `snapshot_store_pair`
-     FROM
-         ((((((((((`snapshots`
-         JOIN `account` ON ((`account`.`id` = `snapshots`.`account_id`)))
-         JOIN `domain` ON ((`domain`.`id` = `account`.`domain_id`)))
-         LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
-         LEFT JOIN `volumes` ON ((`volumes`.`id` = `snapshots`.`volume_id`)))
-         LEFT JOIN `snapshot_store_ref` ON (((`snapshot_store_ref`.`snapshot_id` = `snapshots`.`id`)
-             AND (`snapshot_store_ref`.`state` != 'Destroyed')
-             AND (`snapshot_store_ref`.`display` = 1))))
-         LEFT JOIN `image_store` ON ((ISNULL(`image_store`.`removed`)
-             AND (`snapshot_store_ref`.`store_role` = 'Image')
-             AND (`snapshot_store_ref`.`store_id` IS NOT NULL)
-             AND (`image_store`.`id` = `snapshot_store_ref`.`store_id`))))
-         LEFT JOIN `storage_pool` ON ((ISNULL(`storage_pool`.`removed`)
-             AND (`snapshot_store_ref`.`store_role` = 'Primary')
-             AND (`snapshot_store_ref`.`store_id` IS NOT NULL)
-             AND (`storage_pool`.`id` = `snapshot_store_ref`.`store_id`))))
-         LEFT JOIN `snapshot_zone_ref` ON (((`snapshot_zone_ref`.`snapshot_id` = `snapshots`.`id`)
-             AND ISNULL(`snapshot_store_ref`.`store_id`)
-             AND ISNULL(`snapshot_zone_ref`.`removed`))))
-         LEFT JOIN `data_center` ON (((`image_store`.`data_center_id` = `data_center`.`id`)
-             OR (`storage_pool`.`data_center_id` = `data_center`.`id`)
-             OR (`snapshot_zone_ref`.`zone_id` = `data_center`.`id`))))
-         LEFT JOIN `resource_tags` ON ((`resource_tags`.`resource_id` = `snapshots`.`id`)
-             AND (`resource_tags`.`resource_type` = 'Snapshot')));
-
-UPDATE `cloud`.`configuration` SET
-    `options` = concat(`options`, ',OAUTH2'),
-    `default_value` = concat(`default_value`, ',OAUTH2'),
-    `value` = concat(`value`, ',OAUTH2')
-WHERE `name` = 'user.authenticators.order' ;
-
-UPDATE `cloud`.`configuration` SET
-    `options` = concat(`options`, ',OAUTH2Auth'),
-    `default_value` = concat(`default_value`, ',OAUTH2Auth'),
-    `value` = concat(`value`, ',OAUTH2Auth')
-where `name` = 'pluggableApi.authenticators.order' ;
-
--- Create table for OAuth provider details
-DROP TABLE IF EXISTS `cloud`.`oauth_provider`;
-CREATE TABLE `cloud`.`oauth_provider` (
-  `id` bigint unsigned NOT NULL auto_increment COMMENT 'id',
-  `uuid` varchar(40) NOT NULL COMMENT 'unique identifier',
-  `description` varchar(1024) COMMENT 'description of the provider',
-  `provider` varchar(40) NOT NULL COMMENT 'name of the provider',
-  `client_id` varchar(255) NOT NULL COMMENT 'client id which is configured in the provider',
-  `secret_key` varchar(255) NOT NULL COMMENT 'secret key which is configured in the provider',
-  `redirect_uri` varchar(255) NOT NULL COMMENT 'redirect uri which is configured in the provider',
-  `enabled` int(1) NOT NULL DEFAULT 1 COMMENT 'Enabled or disabled',
-  `created` datetime NOT NULL COMMENT 'date created',
-  `removed` datetime COMMENT 'date removed if not null',
-  PRIMARY KEY (`id`)
-  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.async_job_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.async_job_view.sql
new file mode 100644
index 00000000000..8e941a04e8e
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.async_job_view.sql
@@ -0,0 +1,129 @@
+-- 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.
+
+-- VIEW `cloud`.`async_job_view`;
+
+DROP VIEW IF EXISTS `cloud`.`async_job_view`;
+
+CREATE VIEW `cloud`.`async_job_view` AS
+select
+    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,
+    user.id user_id,
+    user.uuid user_uuid,
+    async_job.id,
+    async_job.uuid,
+    async_job.job_cmd,
+    async_job.job_status,
+    async_job.job_process_status,
+    async_job.job_result_code,
+    async_job.job_result,
+    async_job.created,
+    async_job.removed,
+    async_job.instance_type,
+    async_job.instance_id,
+    async_job.job_executing_msid,
+    CASE
+        WHEN async_job.instance_type = 'Volume' THEN volumes.uuid
+        WHEN
+                    async_job.instance_type = 'Template'
+                or async_job.instance_type = 'Iso'
+            THEN
+            vm_template.uuid
+        WHEN
+                    async_job.instance_type = 'VirtualMachine'
+                or async_job.instance_type = 'ConsoleProxy'
+                or async_job.instance_type = 'SystemVm'
+                or async_job.instance_type = 'DomainRouter'
+            THEN
+            vm_instance.uuid
+        WHEN async_job.instance_type = 'Snapshot' THEN snapshots.uuid
+        WHEN async_job.instance_type = 'Host' THEN host.uuid
+        WHEN async_job.instance_type = 'StoragePool' THEN storage_pool.uuid
+        WHEN async_job.instance_type = 'IpAddress' THEN user_ip_address.uuid
+        WHEN async_job.instance_type = 'SecurityGroup' THEN security_group.uuid
+        WHEN async_job.instance_type = 'PhysicalNetwork' THEN physical_network.uuid
+        WHEN async_job.instance_type = 'TrafficType' THEN physical_network_traffic_types.uuid
+        WHEN async_job.instance_type = 'PhysicalNetworkServiceProvider' THEN physical_network_service_providers.uuid
+        WHEN async_job.instance_type = 'FirewallRule' THEN firewall_rules.uuid
+        WHEN async_job.instance_type = 'Account' THEN acct.uuid
+        WHEN async_job.instance_type = 'User' THEN us.uuid
+        WHEN async_job.instance_type = 'StaticRoute' THEN static_routes.uuid
+        WHEN async_job.instance_type = 'PrivateGateway' THEN vpc_gateways.uuid
+        WHEN async_job.instance_type = 'Counter' THEN counter.uuid
+        WHEN async_job.instance_type = 'Condition' THEN conditions.uuid
+        WHEN async_job.instance_type = 'AutoScalePolicy' THEN autoscale_policies.uuid
+        WHEN async_job.instance_type = 'AutoScaleVmProfile' THEN autoscale_vmprofiles.uuid
+        WHEN async_job.instance_type = 'AutoScaleVmGroup' THEN autoscale_vmgroups.uuid
+        ELSE null
+        END instance_uuid
+from
+    `cloud`.`async_job`
+        left join
+    `cloud`.`account` ON async_job.account_id = account.id
+        left join
+    `cloud`.`domain` ON domain.id = account.domain_id
+        left join
+    `cloud`.`user` ON async_job.user_id = user.id
+        left join
+    `cloud`.`volumes` ON async_job.instance_id = volumes.id
+        left join
+    `cloud`.`vm_template` ON async_job.instance_id = vm_template.id
+        left join
+    `cloud`.`vm_instance` ON async_job.instance_id = vm_instance.id
+        left join
+    `cloud`.`snapshots` ON async_job.instance_id = snapshots.id
+        left join
+    `cloud`.`host` ON async_job.instance_id = host.id
+        left join
+    `cloud`.`storage_pool` ON async_job.instance_id = storage_pool.id
+        left join
+    `cloud`.`user_ip_address` ON async_job.instance_id = user_ip_address.id
+        left join
+    `cloud`.`security_group` ON async_job.instance_id = security_group.id
+        left join
+    `cloud`.`physical_network` ON async_job.instance_id = physical_network.id
+        left join
+    `cloud`.`physical_network_traffic_types` ON async_job.instance_id = physical_network_traffic_types.id
+        left join
+    `cloud`.`physical_network_service_providers` ON async_job.instance_id = physical_network_service_providers.id
+        left join
+    `cloud`.`firewall_rules` ON async_job.instance_id = firewall_rules.id
+        left join
+    `cloud`.`account` acct ON async_job.instance_id = acct.id
+        left join
+    `cloud`.`user` us ON async_job.instance_id = us.id
+        left join
+    `cloud`.`static_routes` ON async_job.instance_id = static_routes.id
+        left join
+    `cloud`.`vpc_gateways` ON async_job.instance_id = vpc_gateways.id
+        left join
+    `cloud`.`counter` ON async_job.instance_id = counter.id
+        left join
+    `cloud`.`conditions` ON async_job.instance_id = conditions.id
+        left join
+    `cloud`.`autoscale_policies` ON async_job.instance_id = autoscale_policies.id
+        left join
+    `cloud`.`autoscale_vmprofiles` ON async_job.instance_id = autoscale_vmprofiles.id
+        left join
+    `cloud`.`autoscale_vmgroups` ON async_job.instance_id = autoscale_vmgroups.id;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.data_center_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.data_center_view.sql
new file mode 100644
index 00000000000..c34df4f1cbf
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.data_center_view.sql
@@ -0,0 +1,59 @@
+-- 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.
+
+-- VIEW `cloud`.`data_center_view`;
+
+DROP VIEW IF EXISTS `cloud`.`data_center_view`;
+
+CREATE VIEW `cloud`.`data_center_view` AS
+select
+    data_center.id,
+    data_center.uuid,
+    data_center.name,
+    data_center.is_security_group_enabled,
+    data_center.is_local_storage_enabled,
+    data_center.description,
+    data_center.dns1,
+    data_center.dns2,
+    data_center.ip6_dns1,
+    data_center.ip6_dns2,
+    data_center.internal_dns1,
+    data_center.internal_dns2,
+    data_center.guest_network_cidr,
+    data_center.domain,
+    data_center.networktype,
+    data_center.allocation_state,
+    data_center.zone_token,
+    data_center.dhcp_provider,
+    data_center.type,
+    data_center.removed,
+    data_center.sort_key,
+    domain.id domain_id,
+    domain.uuid domain_uuid,
+    domain.name domain_name,
+    domain.path domain_path,
+    dedicated_resources.affinity_group_id,
+    dedicated_resources.account_id,
+    affinity_group.uuid affinity_group_uuid
+from
+    `cloud`.`data_center`
+        left join
+    `cloud`.`domain` ON data_center.domain_id = domain.id
+        left join
+    `cloud`.`dedicated_resources` ON data_center.id = dedicated_resources.data_center_id
+        left join
+    `cloud`.`affinity_group` ON dedicated_resources.affinity_group_id = affinity_group.id;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql
new file mode 100644
index 00000000000..10dd3c2f9de
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.disk_offering_view.sql
@@ -0,0 +1,82 @@
+-- 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.
+
+-- VIEW `cloud`.`disk_offering_view`;
+
+DROP VIEW IF EXISTS `cloud`.`disk_offering_view`;
+
+CREATE VIEW `cloud`.`disk_offering_view` AS
+SELECT
+    `disk_offering`.`id` AS `id`,
+    `disk_offering`.`uuid` AS `uuid`,
+    `disk_offering`.`name` AS `name`,
+    `disk_offering`.`display_text` AS `display_text`,
+    `disk_offering`.`provisioning_type` AS `provisioning_type`,
+    `disk_offering`.`disk_size` AS `disk_size`,
+    `disk_offering`.`min_iops` AS `min_iops`,
+    `disk_offering`.`max_iops` AS `max_iops`,
+    `disk_offering`.`created` AS `created`,
+    `disk_offering`.`tags` AS `tags`,
+    `disk_offering`.`customized` AS `customized`,
+    `disk_offering`.`customized_iops` AS `customized_iops`,
+    `disk_offering`.`removed` AS `removed`,
+    `disk_offering`.`use_local_storage` AS `use_local_storage`,
+    `disk_offering`.`hv_ss_reserve` AS `hv_ss_reserve`,
+    `disk_offering`.`bytes_read_rate` AS `bytes_read_rate`,
+    `disk_offering`.`bytes_read_rate_max` AS `bytes_read_rate_max`,
+    `disk_offering`.`bytes_read_rate_max_length` AS `bytes_read_rate_max_length`,
+    `disk_offering`.`bytes_write_rate` AS `bytes_write_rate`,
+    `disk_offering`.`bytes_write_rate_max` AS `bytes_write_rate_max`,
+    `disk_offering`.`bytes_write_rate_max_length` AS `bytes_write_rate_max_length`,
+    `disk_offering`.`iops_read_rate` AS `iops_read_rate`,
+    `disk_offering`.`iops_read_rate_max` AS `iops_read_rate_max`,
+    `disk_offering`.`iops_read_rate_max_length` AS `iops_read_rate_max_length`,
+    `disk_offering`.`iops_write_rate` AS `iops_write_rate`,
+    `disk_offering`.`iops_write_rate_max` AS `iops_write_rate_max`,
+    `disk_offering`.`iops_write_rate_max_length` AS `iops_write_rate_max_length`,
+    `disk_offering`.`cache_mode` AS `cache_mode`,
+    `disk_offering`.`sort_key` AS `sort_key`,
+    `disk_offering`.`compute_only` AS `compute_only`,
+    `disk_offering`.`display_offering` AS `display_offering`,
+    `disk_offering`.`state` AS `state`,
+    `disk_offering`.`disk_size_strictness` AS `disk_size_strictness`,
+    `vsphere_storage_policy`.`value` AS `vsphere_storage_policy`,
+    `disk_offering`.`encrypt` AS `encrypt`,
+    GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
+    GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
+    GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
+    GROUP_CONCAT(DISTINCT(domain.path)) AS domain_path,
+    GROUP_CONCAT(DISTINCT(zone.id)) AS zone_id,
+    GROUP_CONCAT(DISTINCT(zone.uuid)) AS zone_uuid,
+    GROUP_CONCAT(DISTINCT(zone.name)) AS zone_name
+FROM
+    `cloud`.`disk_offering`
+        LEFT JOIN
+    `cloud`.`disk_offering_details` AS `domain_details` ON `domain_details`.`offering_id` = `disk_offering`.`id` AND `domain_details`.`name`='domainid'
+        LEFT JOIN
+    `cloud`.`domain` AS `domain` ON FIND_IN_SET(`domain`.`id`, `domain_details`.`value`)
+        LEFT JOIN
+    `cloud`.`disk_offering_details` AS `zone_details` ON `zone_details`.`offering_id` = `disk_offering`.`id` AND `zone_details`.`name`='zoneid'
+        LEFT JOIN
+    `cloud`.`data_center` AS `zone` ON FIND_IN_SET(`zone`.`id`, `zone_details`.`value`)
+        LEFT JOIN
+    `cloud`.`disk_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`offering_id` = `disk_offering`.`id`
+        AND `vsphere_storage_policy`.`name` = 'storagepolicy'
+WHERE
+        `disk_offering`.`state`='Active'
+GROUP BY
+    `disk_offering`.`id`;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_router_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_router_view.sql
new file mode 100644
index 00000000000..70394e8fd6d
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.domain_router_view.sql
@@ -0,0 +1,126 @@
+-- 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.
+
+-- VIEW `cloud`.`domain_router_view`;
+
+DROP VIEW IF EXISTS `cloud`.`domain_router_view`;
+
+CREATE VIEW `cloud`.`domain_router_view` AS
+select
+    vm_instance.id id,
+    vm_instance.name name,
+    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,
+    vm_instance.uuid uuid,
+    vm_instance.created created,
+    vm_instance.state state,
+    vm_instance.removed removed,
+    vm_instance.pod_id pod_id,
+    vm_instance.instance_name instance_name,
+    host_pod_ref.uuid pod_uuid,
+    data_center.id data_center_id,
+    data_center.uuid data_center_uuid,
+    data_center.name data_center_name,
+    data_center.networktype data_center_network_type,
+    data_center.dns1 dns1,
+    data_center.dns2 dns2,
+    data_center.ip6_dns1 ip6_dns1,
+    data_center.ip6_dns2 ip6_dns2,
+    host.id host_id,
+    host.uuid host_uuid,
+    host.name host_name,
+    host.hypervisor_type,
+    host.cluster_id cluster_id,
+    host.status host_status,
+    host.resource_state host_resource_state,
+    vm_template.id template_id,
+    vm_template.uuid template_uuid,
+    service_offering.id service_offering_id,
+    service_offering.uuid service_offering_uuid,
+    service_offering.name service_offering_name,
+    nics.id nic_id,
+    nics.uuid nic_uuid,
+    nics.network_id network_id,
+    nics.ip4_address ip_address,
+    nics.ip6_address ip6_address,
+    nics.ip6_gateway ip6_gateway,
+    nics.ip6_cidr ip6_cidr,
+    nics.default_nic is_default_nic,
+    nics.gateway gateway,
+    nics.netmask netmask,
+    nics.mac_address mac_address,
+    nics.broadcast_uri broadcast_uri,
+    nics.isolation_uri isolation_uri,
+    nics.mtu mtu,
+    vpc.id vpc_id,
+    vpc.uuid vpc_uuid,
+    vpc.name vpc_name,
+    networks.uuid network_uuid,
+    networks.name network_name,
+    networks.network_domain network_domain,
+    networks.traffic_type traffic_type,
+    networks.guest_type guest_type,
+    async_job.id job_id,
+    async_job.uuid job_uuid,
+    async_job.job_status job_status,
+    async_job.account_id job_account_id,
+    domain_router.template_version template_version,
+    domain_router.scripts_version scripts_version,
+    domain_router.is_redundant_router is_redundant_router,
+    domain_router.redundant_state redundant_state,
+    domain_router.stop_pending stop_pending,
+    domain_router.role role,
+    domain_router.software_version software_version
+from
+    `cloud`.`domain_router`
+        inner join
+    `cloud`.`vm_instance` ON vm_instance.id = domain_router.id
+        inner join
+    `cloud`.`account` ON vm_instance.account_id = account.id
+        inner join
+    `cloud`.`domain` ON vm_instance.domain_id = domain.id
+        left join
+    `cloud`.`host_pod_ref` ON vm_instance.pod_id = host_pod_ref.id
+        left join
+    `cloud`.`projects` ON projects.project_account_id = account.id
+        left join
+    `cloud`.`data_center` ON vm_instance.data_center_id = data_center.id
+        left join
+    `cloud`.`host` ON vm_instance.host_id = host.id
+        left join
+    `cloud`.`vm_template` ON vm_instance.vm_template_id = vm_template.id
+        left join
+    `cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id
+        left join
+    `cloud`.`nics` ON vm_instance.id = nics.instance_id and nics.removed is null
+        left join
+    `cloud`.`networks` ON nics.network_id = networks.id
+        left join
+    `cloud`.`vpc` ON domain_router.vpc_id = vpc.id and vpc.removed is null
+        left join
+    `cloud`.`async_job` ON async_job.instance_id = vm_instance.id
+        and async_job.instance_type = 'DomainRouter'
+        and async_job.job_status = 0;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql
new file mode 100644
index 00000000000..8ba291e154c
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.network_offering_view.sql
@@ -0,0 +1,85 @@
+-- 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.
+
+-- VIEW `cloud`.`network_offering_view`;
+
+DROP VIEW IF EXISTS `cloud`.`network_offering_view`;
+
+CREATE VIEW `cloud`.`network_offering_view` AS
+SELECT
+    `network_offerings`.`id` AS `id`,
+    `network_offerings`.`uuid` AS `uuid`,
+    `network_offerings`.`name` AS `name`,
+    `network_offerings`.`unique_name` AS `unique_name`,
+    `network_offerings`.`display_text` AS `display_text`,
+    `network_offerings`.`nw_rate` AS `nw_rate`,
+    `network_offerings`.`mc_rate` AS `mc_rate`,
+    `network_offerings`.`traffic_type` AS `traffic_type`,
+    `network_offerings`.`tags` AS `tags`,
+    `network_offerings`.`system_only` AS `system_only`,
+    `network_offerings`.`specify_vlan` AS `specify_vlan`,
+    `network_offerings`.`service_offering_id` AS `service_offering_id`,
+    `network_offerings`.`conserve_mode` AS `conserve_mode`,
+    `network_offerings`.`created` AS `created`,
+    `network_offerings`.`removed` AS `removed`,
+    `network_offerings`.`default` AS `default`,
+    `network_offerings`.`availability` AS `availability`,
+    `network_offerings`.`dedicated_lb_service` AS `dedicated_lb_service`,
+    `network_offerings`.`shared_source_nat_service` AS `shared_source_nat_service`,
+    `network_offerings`.`sort_key` AS `sort_key`,
+    `network_offerings`.`redundant_router_service` AS `redundant_router_service`,
+    `network_offerings`.`state` AS `state`,
+    `network_offerings`.`guest_type` AS `guest_type`,
+    `network_offerings`.`elastic_ip_service` AS `elastic_ip_service`,
+    `network_offerings`.`eip_associate_public_ip` AS `eip_associate_public_ip`,
+    `network_offerings`.`elastic_lb_service` AS `elastic_lb_service`,
+    `network_offerings`.`specify_ip_ranges` AS `specify_ip_ranges`,
+    `network_offerings`.`inline` AS `inline`,
+    `network_offerings`.`is_persistent` AS `is_persistent`,
+    `network_offerings`.`internal_lb` AS `internal_lb`,
+    `network_offerings`.`public_lb` AS `public_lb`,
+    `network_offerings`.`egress_default_policy` AS `egress_default_policy`,
+    `network_offerings`.`concurrent_connections` AS `concurrent_connections`,
+    `network_offerings`.`keep_alive_enabled` AS `keep_alive_enabled`,
+    `network_offerings`.`supports_streched_l2` AS `supports_streched_l2`,
+    `network_offerings`.`supports_public_access` AS `supports_public_access`,
+    `network_offerings`.`supports_vm_autoscaling` AS `supports_vm_autoscaling`,
+    `network_offerings`.`for_vpc` AS `for_vpc`,
+    `network_offerings`.`for_tungsten` AS `for_tungsten`,
+    `network_offerings`.`service_package_id` AS `service_package_id`,
+    GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
+    GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
+    GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
+    GROUP_CONCAT(DISTINCT(domain.path)) AS domain_path,
+    GROUP_CONCAT(DISTINCT(zone.id)) AS zone_id,
+    GROUP_CONCAT(DISTINCT(zone.uuid)) AS zone_uuid,
+    GROUP_CONCAT(DISTINCT(zone.name)) AS zone_name,
+    `offering_details`.value AS internet_protocol
+FROM
+    `cloud`.`network_offerings`
+        LEFT JOIN
+    `cloud`.`network_offering_details` AS `domain_details` ON `domain_details`.`network_offering_id` = `network_offerings`.`id` AND `domain_details`.`name`='domainid'
+        LEFT JOIN
+    `cloud`.`domain` AS `domain` ON FIND_IN_SET(`domain`.`id`, `domain_details`.`value`)
+        LEFT JOIN
+    `cloud`.`network_offering_details` AS `zone_details` ON `zone_details`.`network_offering_id` = `network_offerings`.`id` AND `zone_details`.`name`='zoneid'
+        LEFT JOIN
+    `cloud`.`data_center` AS `zone` ON FIND_IN_SET(`zone`.`id`, `zone_details`.`value`)
+        LEFT JOIN
+    `cloud`.`network_offering_details` AS `offering_details` ON `offering_details`.`network_offering_id` = `network_offerings`.`id` AND `offering_details`.`name`='internetProtocol'
+GROUP BY
+    `network_offerings`.`id`;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql
new file mode 100644
index 00000000000..e859af482b4
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.service_offering_view.sql
@@ -0,0 +1,114 @@
+-- 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.
+
+-- VIEW `cloud`.`service_offering_view`;
+
+DROP VIEW IF EXISTS `cloud`.`service_offering_view`;
+
+CREATE VIEW `cloud`.`service_offering_view` AS
+SELECT
+    `service_offering`.`id` AS `id`,
+    `service_offering`.`uuid` AS `uuid`,
+    `service_offering`.`name` AS `name`,
+    `service_offering`.`display_text` AS `display_text`,
+    `disk_offering`.`provisioning_type` AS `provisioning_type`,
+    `service_offering`.`created` AS `created`,
+    `disk_offering`.`tags` AS `tags`,
+    `service_offering`.`removed` AS `removed`,
+    `disk_offering`.`use_local_storage` AS `use_local_storage`,
+    `service_offering`.`system_use` AS `system_use`,
+    `disk_offering`.`id` AS `disk_offering_id`,
+    `disk_offering`.`name` AS `disk_offering_name`,
+    `disk_offering`.`uuid` AS `disk_offering_uuid`,
+    `disk_offering`.`display_text` AS `disk_offering_display_text`,
+    `disk_offering`.`customized_iops` AS `customized_iops`,
+    `disk_offering`.`min_iops` AS `min_iops`,
+    `disk_offering`.`max_iops` AS `max_iops`,
+    `disk_offering`.`hv_ss_reserve` AS `hv_ss_reserve`,
+    `disk_offering`.`bytes_read_rate` AS `bytes_read_rate`,
+    `disk_offering`.`bytes_read_rate_max` AS `bytes_read_rate_max`,
+    `disk_offering`.`bytes_read_rate_max_length` AS `bytes_read_rate_max_length`,
+    `disk_offering`.`bytes_write_rate` AS `bytes_write_rate`,
+    `disk_offering`.`bytes_write_rate_max` AS `bytes_write_rate_max`,
+    `disk_offering`.`bytes_write_rate_max_length` AS `bytes_write_rate_max_length`,
+    `disk_offering`.`iops_read_rate` AS `iops_read_rate`,
+    `disk_offering`.`iops_read_rate_max` AS `iops_read_rate_max`,
+    `disk_offering`.`iops_read_rate_max_length` AS `iops_read_rate_max_length`,
+    `disk_offering`.`iops_write_rate` AS `iops_write_rate`,
+    `disk_offering`.`iops_write_rate_max` AS `iops_write_rate_max`,
+    `disk_offering`.`iops_write_rate_max_length` AS `iops_write_rate_max_length`,
+    `disk_offering`.`cache_mode` AS `cache_mode`,
+    `disk_offering`.`disk_size` AS `root_disk_size`,
+    `disk_offering`.`encrypt` AS `encrypt_root`,
+    `service_offering`.`cpu` AS `cpu`,
+    `service_offering`.`speed` AS `speed`,
+    `service_offering`.`ram_size` AS `ram_size`,
+    `service_offering`.`nw_rate` AS `nw_rate`,
+    `service_offering`.`mc_rate` AS `mc_rate`,
+    `service_offering`.`ha_enabled` AS `ha_enabled`,
+    `service_offering`.`limit_cpu_use` AS `limit_cpu_use`,
+    `service_offering`.`host_tag` AS `host_tag`,
+    `service_offering`.`default_use` AS `default_use`,
+    `service_offering`.`vm_type` AS `vm_type`,
+    `service_offering`.`sort_key` AS `sort_key`,
+    `service_offering`.`is_volatile` AS `is_volatile`,
+    `service_offering`.`deployment_planner` AS `deployment_planner`,
+    `service_offering`.`dynamic_scaling_enabled` AS `dynamic_scaling_enabled`,
+    `service_offering`.`disk_offering_strictness` AS `disk_offering_strictness`,
+    `vsphere_storage_policy`.`value` AS `vsphere_storage_policy`,
+    GROUP_CONCAT(DISTINCT(domain.id)) AS domain_id,
+    GROUP_CONCAT(DISTINCT(domain.uuid)) AS domain_uuid,
+    GROUP_CONCAT(DISTINCT(domain.name)) AS domain_name,
+    GROUP_CONCAT(DISTINCT(domain.path)) AS domain_path,
+    GROUP_CONCAT(DISTINCT(zone.id)) AS zone_id,
+    GROUP_CONCAT(DISTINCT(zone.uuid)) AS zone_uuid,
+    GROUP_CONCAT(DISTINCT(zone.name)) AS zone_name,
+    IFNULL(`min_compute_details`.`value`, `cpu`) AS min_cpu,
+    IFNULL(`max_compute_details`.`value`, `cpu`) AS max_cpu,
+    IFNULL(`min_memory_details`.`value`, `ram_size`) AS min_memory,
+    IFNULL(`max_memory_details`.`value`, `ram_size`) AS max_memory
+FROM
+    `cloud`.`service_offering`
+        INNER JOIN
+    `cloud`.`disk_offering_view` AS `disk_offering` ON service_offering.disk_offering_id = disk_offering.id
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `domain_details` ON `domain_details`.`service_offering_id` = `service_offering`.`id` AND `domain_details`.`name`='domainid'
+        LEFT JOIN
+    `cloud`.`domain` AS `domain` ON FIND_IN_SET(`domain`.`id`, `domain_details`.`value`)
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `zone_details` ON `zone_details`.`service_offering_id` = `service_offering`.`id` AND `zone_details`.`name`='zoneid'
+        LEFT JOIN
+    `cloud`.`data_center` AS `zone` ON FIND_IN_SET(`zone`.`id`, `zone_details`.`value`)
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `min_compute_details` ON `min_compute_details`.`service_offering_id` = `service_offering`.`id`
+        AND `min_compute_details`.`name` = 'mincpunumber'
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `max_compute_details` ON `max_compute_details`.`service_offering_id` = `service_offering`.`id`
+        AND `max_compute_details`.`name` = 'maxcpunumber'
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `min_memory_details` ON `min_memory_details`.`service_offering_id` = `service_offering`.`id`
+        AND `min_memory_details`.`name` = 'minmemory'
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `max_memory_details` ON `max_memory_details`.`service_offering_id` = `service_offering`.`id`
+        AND `max_memory_details`.`name` = 'maxmemory'
+        LEFT JOIN
+    `cloud`.`service_offering_details` AS `vsphere_storage_policy` ON `vsphere_storage_policy`.`service_offering_id` = `service_offering`.`id`
+        AND `vsphere_storage_policy`.`name` = 'storagepolicy'
+WHERE
+        `service_offering`.`state`='Active'
+GROUP BY
+    `service_offering`.`id`;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.snapshot_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.snapshot_view.sql
new file mode 100644
index 00000000000..c6b8d6b4d05
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.snapshot_view.sql
@@ -0,0 +1,107 @@
+-- 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.
+
+-- VIEW `cloud`.`snapshot_view`;
+
+DROP VIEW IF EXISTS `cloud`.`snapshot_view`;
+
+CREATE VIEW `cloud`.`snapshot_view` AS
+SELECT
+    `snapshots`.`id` AS `id`,
+    `snapshots`.`uuid` AS `uuid`,
+    `snapshots`.`name` AS `name`,
+    `snapshots`.`status` AS `status`,
+    `snapshots`.`disk_offering_id` AS `disk_offering_id`,
+    `snapshots`.`snapshot_type` AS `snapshot_type`,
+    `snapshots`.`type_description` AS `type_description`,
+    `snapshots`.`size` AS `size`,
+    `snapshots`.`created` AS `created`,
+    `snapshots`.`removed` AS `removed`,
+    `snapshots`.`location_type` AS `location_type`,
+    `snapshots`.`hypervisor_type` AS `hypervisor_type`,
+    `account`.`id` AS `account_id`,
+    `account`.`uuid` AS `account_uuid`,
+    `account`.`account_name` AS `account_name`,
+    `account`.`type` AS `account_type`,
+    `domain`.`id` AS `domain_id`,
+    `domain`.`uuid` AS `domain_uuid`,
+    `domain`.`name` AS `domain_name`,
+    `domain`.`path` AS `domain_path`,
+    `projects`.`id` AS `project_id`,
+    `projects`.`uuid` AS `project_uuid`,
+    `projects`.`name` AS `project_name`,
+    `volumes`.`id` AS `volume_id`,
+    `volumes`.`uuid` AS `volume_uuid`,
+    `volumes`.`name` AS `volume_name`,
+    `volumes`.`volume_type` AS `volume_type`,
+    `volumes`.`size` AS `volume_size`,
+    `data_center`.`id` AS `data_center_id`,
+    `data_center`.`uuid` AS `data_center_uuid`,
+    `data_center`.`name` AS `data_center_name`,
+    `snapshot_store_ref`.`store_id` AS `store_id`,
+    IFNULL(`image_store`.`uuid`, `storage_pool`.`uuid`) AS `store_uuid`,
+    IFNULL(`image_store`.`name`, `storage_pool`.`name`) AS `store_name`,
+    `snapshot_store_ref`.`store_role` AS `store_role`,
+    `snapshot_store_ref`.`state` AS `store_state`,
+    `snapshot_store_ref`.`download_state` AS `download_state`,
+    `snapshot_store_ref`.`download_pct` AS `download_pct`,
+    `snapshot_store_ref`.`error_str` AS `error_str`,
+    `snapshot_store_ref`.`size` AS `store_size`,
+    `snapshot_store_ref`.`created` AS `created_on_store`,
+    `resource_tags`.`id` AS `tag_id`,
+    `resource_tags`.`uuid` AS `tag_uuid`,
+    `resource_tags`.`key` AS `tag_key`,
+    `resource_tags`.`value` AS `tag_value`,
+    `resource_tags`.`domain_id` AS `tag_domain_id`,
+    `domain`.`uuid` AS `tag_domain_uuid`,
+    `domain`.`name` AS `tag_domain_name`,
+    `resource_tags`.`account_id` AS `tag_account_id`,
+    `account`.`account_name` AS `tag_account_name`,
+    `resource_tags`.`resource_id` AS `tag_resource_id`,
+    `resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
+    `resource_tags`.`resource_type` AS `tag_resource_type`,
+    `resource_tags`.`customer` AS `tag_customer`,
+    CONCAT(`snapshots`.`id`,
+           '_',
+           IFNULL(`snapshot_store_ref`.`store_role`, 'UNKNOWN'),
+           '_',
+           IFNULL(`snapshot_store_ref`.`store_id`, 0)) AS `snapshot_store_pair`
+FROM
+    ((((((((((`snapshots`
+        JOIN `account` ON ((`account`.`id` = `snapshots`.`account_id`)))
+        JOIN `domain` ON ((`domain`.`id` = `account`.`domain_id`)))
+        LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
+        LEFT JOIN `volumes` ON ((`volumes`.`id` = `snapshots`.`volume_id`)))
+        LEFT JOIN `snapshot_store_ref` ON (((`snapshot_store_ref`.`snapshot_id` = `snapshots`.`id`)
+        AND (`snapshot_store_ref`.`state` != 'Destroyed')
+        AND (`snapshot_store_ref`.`display` = 1))))
+        LEFT JOIN `image_store` ON ((ISNULL(`image_store`.`removed`)
+        AND (`snapshot_store_ref`.`store_role` = 'Image')
+        AND (`snapshot_store_ref`.`store_id` IS NOT NULL)
+        AND (`image_store`.`id` = `snapshot_store_ref`.`store_id`))))
+        LEFT JOIN `storage_pool` ON ((ISNULL(`storage_pool`.`removed`)
+        AND (`snapshot_store_ref`.`store_role` = 'Primary')
+        AND (`snapshot_store_ref`.`store_id` IS NOT NULL)
+        AND (`storage_pool`.`id` = `snapshot_store_ref`.`store_id`))))
+        LEFT JOIN `snapshot_zone_ref` ON (((`snapshot_zone_ref`.`snapshot_id` = `snapshots`.`id`)
+        AND ISNULL(`snapshot_store_ref`.`store_id`)
+        AND ISNULL(`snapshot_zone_ref`.`removed`))))
+        LEFT JOIN `data_center` ON (((`image_store`.`data_center_id` = `data_center`.`id`)
+        OR (`storage_pool`.`data_center_id` = `data_center`.`id`)
+        OR (`snapshot_zone_ref`.`zone_id` = `data_center`.`id`))))
+        LEFT JOIN `resource_tags` ON ((`resource_tags`.`resource_id` = `snapshots`.`id`)
+        AND (`resource_tags`.`resource_type` = 'Snapshot')));
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql
new file mode 100644
index 00000000000..40b416b16de
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.template_view.sql
@@ -0,0 +1,131 @@
+-- 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.
+
+-- VIEW `cloud`.`template_view`;
+
+DROP VIEW IF EXISTS `cloud`.`template_view`;
+
+CREATE VIEW `cloud`.`template_view` AS
+SELECT
+    `vm_template`.`id` AS `id`,
+    `vm_template`.`uuid` AS `uuid`,
+    `vm_template`.`unique_name` AS `unique_name`,
+    `vm_template`.`name` AS `name`,
+    `vm_template`.`public` AS `public`,
+    `vm_template`.`featured` AS `featured`,
+    `vm_template`.`type` AS `type`,
+    `vm_template`.`hvm` AS `hvm`,
+    `vm_template`.`bits` AS `bits`,
+    `vm_template`.`url` AS `url`,
+    `vm_template`.`format` AS `format`,
+    `vm_template`.`created` AS `created`,
+    `vm_template`.`checksum` AS `checksum`,
+    `vm_template`.`display_text` AS `display_text`,
+    `vm_template`.`enable_password` AS `enable_password`,
+    `vm_template`.`dynamically_scalable` AS `dynamically_scalable`,
+    `vm_template`.`state` AS `template_state`,
+    `vm_template`.`guest_os_id` AS `guest_os_id`,
+    `guest_os`.`uuid` AS `guest_os_uuid`,
+    `guest_os`.`display_name` AS `guest_os_name`,
+    `vm_template`.`bootable` AS `bootable`,
+    `vm_template`.`prepopulate` AS `prepopulate`,
+    `vm_template`.`cross_zones` AS `cross_zones`,
+    `vm_template`.`hypervisor_type` AS `hypervisor_type`,
+    `vm_template`.`extractable` AS `extractable`,
+    `vm_template`.`template_tag` AS `template_tag`,
+    `vm_template`.`sort_key` AS `sort_key`,
+    `vm_template`.`removed` AS `removed`,
+    `vm_template`.`enable_sshkey` AS `enable_sshkey`,
+    `parent_template`.`id` AS `parent_template_id`,
+    `parent_template`.`uuid` AS `parent_template_uuid`,
+    `source_template`.`id` AS `source_template_id`,
+    `source_template`.`uuid` AS `source_template_uuid`,
+    `account`.`id` AS `account_id`,
+    `account`.`uuid` AS `account_uuid`,
+    `account`.`account_name` AS `account_name`,
+    `account`.`type` AS `account_type`,
+    `domain`.`id` AS `domain_id`,
+    `domain`.`uuid` AS `domain_uuid`,
+    `domain`.`name` AS `domain_name`,
+    `domain`.`path` AS `domain_path`,
+    `projects`.`id` AS `project_id`,
+    `projects`.`uuid` AS `project_uuid`,
+    `projects`.`name` AS `project_name`,
+    `data_center`.`id` AS `data_center_id`,
+    `data_center`.`uuid` AS `data_center_uuid`,
+    `data_center`.`name` AS `data_center_name`,
+    `launch_permission`.`account_id` AS `lp_account_id`,
+    `template_store_ref`.`store_id` AS `store_id`,
+    `image_store`.`scope` AS `store_scope`,
+    `template_store_ref`.`state` AS `state`,
+    `template_store_ref`.`download_state` AS `download_state`,
+    `template_store_ref`.`download_pct` AS `download_pct`,
+    `template_store_ref`.`error_str` AS `error_str`,
+    `template_store_ref`.`size` AS `size`,
+    `template_store_ref`.physical_size AS `physical_size`,
+    `template_store_ref`.`destroyed` AS `destroyed`,
+    `template_store_ref`.`created` AS `created_on_store`,
+    `vm_template_details`.`name` AS `detail_name`,
+    `vm_template_details`.`value` AS `detail_value`,
+    `resource_tags`.`id` AS `tag_id`,
+    `resource_tags`.`uuid` AS `tag_uuid`,
+    `resource_tags`.`key` AS `tag_key`,
+    `resource_tags`.`value` AS `tag_value`,
+    `resource_tags`.`domain_id` AS `tag_domain_id`,
+    `domain`.`uuid` AS `tag_domain_uuid`,
+    `domain`.`name` AS `tag_domain_name`,
+    `resource_tags`.`account_id` AS `tag_account_id`,
+    `account`.`account_name` AS `tag_account_name`,
+    `resource_tags`.`resource_id` AS `tag_resource_id`,
+    `resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
+    `resource_tags`.`resource_type` AS `tag_resource_type`,
+    `resource_tags`.`customer` AS `tag_customer`,
+    CONCAT(`vm_template`.`id`,
+           '_',
+           IFNULL(`data_center`.`id`, 0)) AS `temp_zone_pair`,
+    `vm_template`.`direct_download` AS `direct_download`,
+    `vm_template`.`deploy_as_is` AS `deploy_as_is`,
+    `user_data`.`id` AS `user_data_id`,
+    `user_data`.`uuid` AS `user_data_uuid`,
+    `user_data`.`name` AS `user_data_name`,
+    `user_data`.`params` AS `user_data_params`,
+    `vm_template`.`user_data_link_policy` AS `user_data_policy`
+FROM
+    (((((((((((((`vm_template`
+        JOIN `guest_os` ON ((`guest_os`.`id` = `vm_template`.`guest_os_id`)))
+        JOIN `account` ON ((`account`.`id` = `vm_template`.`account_id`)))
+        JOIN `domain` ON ((`domain`.`id` = `account`.`domain_id`)))
+        LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
+        LEFT JOIN `vm_template_details` ON ((`vm_template_details`.`template_id` = `vm_template`.`id`)))
+        LEFT JOIN `vm_template` `source_template` ON ((`source_template`.`id` = `vm_template`.`source_template_id`)))
+        LEFT JOIN `template_store_ref` ON (((`template_store_ref`.`template_id` = `vm_template`.`id`)
+            AND (`template_store_ref`.`store_role` = 'Image')
+            AND (`template_store_ref`.`destroyed` = 0))))
+        LEFT JOIN `vm_template` `parent_template` ON ((`parent_template`.`id` = `vm_template`.`parent_template_id`)))
+        LEFT JOIN `image_store` ON ((ISNULL(`image_store`.`removed`)
+            AND (`template_store_ref`.`store_id` IS NOT NULL)
+            AND (`image_store`.`id` = `template_store_ref`.`store_id`))))
+        LEFT JOIN `template_zone_ref` ON (((`template_zone_ref`.`template_id` = `vm_template`.`id`)
+            AND ISNULL(`template_store_ref`.`store_id`)
+            AND ISNULL(`template_zone_ref`.`removed`))))
+        LEFT JOIN `data_center` ON (((`image_store`.`data_center_id` = `data_center`.`id`)
+            OR (`template_zone_ref`.`zone_id` = `data_center`.`id`))))
+        LEFT JOIN `launch_permission` ON ((`launch_permission`.`template_id` = `vm_template`.`id`)))
+        LEFT JOIN `user_data` ON ((`user_data`.`id` = `vm_template`.`user_data_id`))
+        LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_template`.`id`)
+        AND ((`resource_tags`.`resource_type` = 'Template')
+            OR (`resource_tags`.`resource_type` = 'ISO')))));
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.user_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_view.sql
new file mode 100644
index 00000000000..7eedc03712b
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_view.sql
@@ -0,0 +1,65 @@
+-- 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.
+
+-- VIEW `cloud`.`user_view`;
+
+DROP VIEW IF EXISTS `cloud`.`user_view`;
+
+CREATE VIEW `cloud`.`user_view` AS
+select
+    user.id,
+    user.uuid,
+    user.username,
+    user.password,
+    user.firstname,
+    user.lastname,
+    user.email,
+    user.state,
+    user.api_key,
+    user.secret_key,
+    user.created,
+    user.removed,
+    user.timezone,
+    user.registration_token,
+    user.is_registered,
+    user.incorrect_login_attempts,
+    user.source,
+    user.default,
+    account.id account_id,
+    account.uuid account_uuid,
+    account.account_name account_name,
+    account.type account_type,
+    account.role_id account_role_id,
+    domain.id domain_id,
+    domain.uuid domain_uuid,
+    domain.name domain_name,
+    domain.path domain_path,
+    async_job.id job_id,
+    async_job.uuid job_uuid,
+    async_job.job_status job_status,
+    async_job.account_id job_account_id,
+    user.is_user_2fa_enabled is_user_2fa_enabled
+from
+    `cloud`.`user`
+        inner join
+    `cloud`.`account` ON user.account_id = account.id
+        inner join
+    `cloud`.`domain` ON account.domain_id = domain.id
+        left join
+    `cloud`.`async_job` ON async_job.instance_id = user.id
+        and async_job.instance_type = 'User'
+        and async_job.job_status = 0;
diff --git a/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql
new file mode 100644
index 00000000000..7a057dc0330
--- /dev/null
+++ b/engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql
@@ -0,0 +1,215 @@
+-- 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.
+
+-- VIEW `cloud`.`user_vm_view`;
+
+DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
+
+CREATE VIEW `user_vm_view` AS
+SELECT
+    `vm_instance`.`id` AS `id`,
+    `vm_instance`.`name` AS `name`,
+    `user_vm`.`display_name` AS `display_name`,
+    `user_vm`.`user_data` AS `user_data`,
+    `account`.`id` AS `account_id`,
+    `account`.`uuid` AS `account_uuid`,
+    `account`.`account_name` AS `account_name`,
+    `account`.`type` AS `account_type`,
+    `domain`.`id` AS `domain_id`,
+    `domain`.`uuid` AS `domain_uuid`,
+    `domain`.`name` AS `domain_name`,
+    `domain`.`path` AS `domain_path`,
+    `projects`.`id` AS `project_id`,
+    `projects`.`uuid` AS `project_uuid`,
+    `projects`.`name` AS `project_name`,
+    `instance_group`.`id` AS `instance_group_id`,
+    `instance_group`.`uuid` AS `instance_group_uuid`,
+    `instance_group`.`name` AS `instance_group_name`,
+    `vm_instance`.`uuid` AS `uuid`,
+    `vm_instance`.`user_id` AS `user_id`,
+    `vm_instance`.`last_host_id` AS `last_host_id`,
+    `vm_instance`.`vm_type` AS `type`,
+    `vm_instance`.`limit_cpu_use` AS `limit_cpu_use`,
+    `vm_instance`.`created` AS `created`,
+    `vm_instance`.`state` AS `state`,
+    `vm_instance`.`update_time` AS `update_time`,
+    `vm_instance`.`removed` AS `removed`,
+    `vm_instance`.`ha_enabled` AS `ha_enabled`,
+    `vm_instance`.`hypervisor_type` AS `hypervisor_type`,
+    `vm_instance`.`instance_name` AS `instance_name`,
+    `vm_instance`.`guest_os_id` AS `guest_os_id`,
+    `vm_instance`.`display_vm` AS `display_vm`,
+    `guest_os`.`uuid` AS `guest_os_uuid`,
+    `vm_instance`.`pod_id` AS `pod_id`,
+    `host_pod_ref`.`uuid` AS `pod_uuid`,
+    `vm_instance`.`private_ip_address` AS `private_ip_address`,
+    `vm_instance`.`private_mac_address` AS `private_mac_address`,
+    `vm_instance`.`vm_type` AS `vm_type`,
+    `data_center`.`id` AS `data_center_id`,
+    `data_center`.`uuid` AS `data_center_uuid`,
+    `data_center`.`name` AS `data_center_name`,
+    `data_center`.`is_security_group_enabled` AS `security_group_enabled`,
+    `data_center`.`networktype` AS `data_center_network_type`,
+    `host`.`id` AS `host_id`,
+    `host`.`uuid` AS `host_uuid`,
+    `host`.`name` AS `host_name`,
+    `host`.`cluster_id` AS `cluster_id`,
+    `host`.`status` AS `host_status`,
+    `host`.`resource_state` AS `host_resource_state`,
+    `vm_template`.`id` AS `template_id`,
+    `vm_template`.`uuid` AS `template_uuid`,
+    `vm_template`.`name` AS `template_name`,
+    `vm_template`.`type` AS `template_type`,
+    `vm_template`.`display_text` AS `template_display_text`,
+    `vm_template`.`enable_password` AS `password_enabled`,
+    `iso`.`id` AS `iso_id`,
+    `iso`.`uuid` AS `iso_uuid`,
+    `iso`.`name` AS `iso_name`,
+    `iso`.`display_text` AS `iso_display_text`,
+    `service_offering`.`id` AS `service_offering_id`,
+    `service_offering`.`uuid` AS `service_offering_uuid`,
+    `disk_offering`.`uuid` AS `disk_offering_uuid`,
+    `disk_offering`.`id` AS `disk_offering_id`,
+    (CASE
+         WHEN ISNULL(`service_offering`.`cpu`) THEN `custom_cpu`.`value`
+         ELSE `service_offering`.`cpu`
+        END) AS `cpu`,
+    (CASE
+         WHEN ISNULL(`service_offering`.`speed`) THEN `custom_speed`.`value`
+         ELSE `service_offering`.`speed`
+        END) AS `speed`,
+    (CASE
+         WHEN ISNULL(`service_offering`.`ram_size`) THEN `custom_ram_size`.`value`
+         ELSE `service_offering`.`ram_size`
+        END) AS `ram_size`,
+    `backup_offering`.`uuid` AS `backup_offering_uuid`,
+    `backup_offering`.`id` AS `backup_offering_id`,
+    `service_offering`.`name` AS `service_offering_name`,
+    `disk_offering`.`name` AS `disk_offering_name`,
+    `backup_offering`.`name` AS `backup_offering_name`,
+    `storage_pool`.`id` AS `pool_id`,
+    `storage_pool`.`uuid` AS `pool_uuid`,
+    `storage_pool`.`pool_type` AS `pool_type`,
+    `volumes`.`id` AS `volume_id`,
+    `volumes`.`uuid` AS `volume_uuid`,
+    `volumes`.`device_id` AS `volume_device_id`,
+    `volumes`.`volume_type` AS `volume_type`,
+    `security_group`.`id` AS `security_group_id`,
+    `security_group`.`uuid` AS `security_group_uuid`,
+    `security_group`.`name` AS `security_group_name`,
+    `security_group`.`description` AS `security_group_description`,
+    `nics`.`id` AS `nic_id`,
+    `nics`.`uuid` AS `nic_uuid`,
+    `nics`.`device_id` AS `nic_device_id`,
+    `nics`.`network_id` AS `network_id`,
+    `nics`.`ip4_address` AS `ip_address`,
+    `nics`.`ip6_address` AS `ip6_address`,
+    `nics`.`ip6_gateway` AS `ip6_gateway`,
+    `nics`.`ip6_cidr` AS `ip6_cidr`,
+    `nics`.`default_nic` AS `is_default_nic`,
+    `nics`.`gateway` AS `gateway`,
+    `nics`.`netmask` AS `netmask`,
+    `nics`.`mac_address` AS `mac_address`,
+    `nics`.`broadcast_uri` AS `broadcast_uri`,
+    `nics`.`isolation_uri` AS `isolation_uri`,
+    `vpc`.`id` AS `vpc_id`,
+    `vpc`.`uuid` AS `vpc_uuid`,
+    `networks`.`uuid` AS `network_uuid`,
+    `networks`.`name` AS `network_name`,
+    `networks`.`traffic_type` AS `traffic_type`,
+    `networks`.`guest_type` AS `guest_type`,
+    `user_ip_address`.`id` AS `public_ip_id`,
+    `user_ip_address`.`uuid` AS `public_ip_uuid`,
+    `user_ip_address`.`public_ip_address` AS `public_ip_address`,
+    `ssh_details`.`value` AS `keypair_names`,
+    `resource_tags`.`id` AS `tag_id`,
+    `resource_tags`.`uuid` AS `tag_uuid`,
+    `resource_tags`.`key` AS `tag_key`,
+    `resource_tags`.`value` AS `tag_value`,
+    `resource_tags`.`domain_id` AS `tag_domain_id`,
+    `domain`.`uuid` AS `tag_domain_uuid`,
+    `domain`.`name` AS `tag_domain_name`,
+    `resource_tags`.`account_id` AS `tag_account_id`,
+    `account`.`account_name` AS `tag_account_name`,
+    `resource_tags`.`resource_id` AS `tag_resource_id`,
+    `resource_tags`.`resource_uuid` AS `tag_resource_uuid`,
+    `resource_tags`.`resource_type` AS `tag_resource_type`,
+    `resource_tags`.`customer` AS `tag_customer`,
+    `async_job`.`id` AS `job_id`,
+    `async_job`.`uuid` AS `job_uuid`,
+    `async_job`.`job_status` AS `job_status`,
+    `async_job`.`account_id` AS `job_account_id`,
+    `affinity_group`.`id` AS `affinity_group_id`,
+    `affinity_group`.`uuid` AS `affinity_group_uuid`,
+    `affinity_group`.`name` AS `affinity_group_name`,
+    `affinity_group`.`description` AS `affinity_group_description`,
+    `autoscale_vmgroups`.`id` AS `autoscale_vmgroup_id`,
+    `autoscale_vmgroups`.`uuid` AS `autoscale_vmgroup_uuid`,
+    `autoscale_vmgroups`.`name` AS `autoscale_vmgroup_name`,
+    `vm_instance`.`dynamically_scalable` AS `dynamically_scalable`,
+    `user_data`.`id` AS `user_data_id`,
+    `user_data`.`uuid` AS `user_data_uuid`,
+    `user_data`.`name` AS `user_data_name`,
+    `user_vm`.`user_data_details` AS `user_data_details`,
+    `vm_template`.`user_data_link_policy` AS `user_data_policy`
+FROM
+    (((((((((((((((((((((((((((((((((((`user_vm`
+        JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
+            AND ISNULL(`vm_instance`.`removed`))))
+        JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
+        JOIN `domain` ON ((`vm_instance`.`domain_id` = `domain`.`id`)))
+        LEFT JOIN `guest_os` ON ((`vm_instance`.`guest_os_id` = `guest_os`.`id`)))
+        LEFT JOIN `host_pod_ref` ON ((`vm_instance`.`pod_id` = `host_pod_ref`.`id`)))
+        LEFT JOIN `projects` ON ((`projects`.`project_account_id` = `account`.`id`)))
+        LEFT JOIN `instance_group_vm_map` ON ((`vm_instance`.`id` = `instance_group_vm_map`.`instance_id`)))
+        LEFT JOIN `instance_group` ON ((`instance_group_vm_map`.`group_id` = `instance_group`.`id`)))
+        LEFT JOIN `data_center` ON ((`vm_instance`.`data_center_id` = `data_center`.`id`)))
+        LEFT JOIN `host` ON ((`vm_instance`.`host_id` = `host`.`id`)))
+        LEFT JOIN `vm_template` ON ((`vm_instance`.`vm_template_id` = `vm_template`.`id`)))
+        LEFT JOIN `vm_template` `iso` ON ((`iso`.`id` = `user_vm`.`iso_id`)))
+        LEFT JOIN `volumes` ON ((`vm_instance`.`id` = `volumes`.`instance_id`)))
+        LEFT JOIN `service_offering` ON ((`vm_instance`.`service_offering_id` = `service_offering`.`id`)))
+        LEFT JOIN `disk_offering` `svc_disk_offering` ON ((`volumes`.`disk_offering_id` = `svc_disk_offering`.`id`)))
+        LEFT JOIN `disk_offering` ON ((`volumes`.`disk_offering_id` = `disk_offering`.`id`)))
+        LEFT JOIN `backup_offering` ON ((`vm_instance`.`backup_offering_id` = `backup_offering`.`id`)))
+        LEFT JOIN `storage_pool` ON ((`volumes`.`pool_id` = `storage_pool`.`id`)))
+        LEFT JOIN `security_group_vm_map` ON ((`vm_instance`.`id` = `security_group_vm_map`.`instance_id`)))
+        LEFT JOIN `security_group` ON ((`security_group_vm_map`.`security_group_id` = `security_group`.`id`)))
+        LEFT JOIN `user_data` ON ((`user_data`.`id` = `user_vm`.`user_data_id`)))
+        LEFT JOIN `nics` ON (((`vm_instance`.`id` = `nics`.`instance_id`)
+        AND ISNULL(`nics`.`removed`))))
+        LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
+        LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
+        AND ISNULL(`vpc`.`removed`))))
+        LEFT JOIN `user_ip_address` ON ((`user_ip_address`.`vm_id` = `vm_instance`.`id`)))
+        LEFT JOIN `user_vm_details` `ssh_details` ON (((`ssh_details`.`vm_id` = `vm_instance`.`id`)
+        AND (`ssh_details`.`name` = 'SSH.KeyPairNames'))))
+        LEFT JOIN `resource_tags` ON (((`resource_tags`.`resource_id` = `vm_instance`.`id`)
+        AND (`resource_tags`.`resource_type` = 'UserVm'))))
+        LEFT JOIN `async_job` ON (((`async_job`.`instance_id` = `vm_instance`.`id`)
+        AND (`async_job`.`instance_type` = 'VirtualMachine')
+        AND (`async_job`.`job_status` = 0))))
+        LEFT JOIN `affinity_group_vm_map` ON ((`vm_instance`.`id` = `affinity_group_vm_map`.`instance_id`)))
+        LEFT JOIN `affinity_group` ON ((`affinity_group_vm_map`.`affinity_group_id` = `affinity_group`.`id`)))
+        LEFT JOIN `autoscale_vmgroup_vm_map` ON ((`autoscale_vmgroup_vm_map`.`instance_id` = `vm_instance`.`id`)))
+        LEFT JOIN `autoscale_vmgroups` ON ((`autoscale_vmgroup_vm_map`.`vmgroup_id` = `autoscale_vmgroups`.`id`)))
+        LEFT JOIN `user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `vm_instance`.`id`)
+        AND (`custom_cpu`.`name` = 'CpuNumber'))))
+        LEFT JOIN `user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `vm_instance`.`id`)
+        AND (`custom_speed`.`name` = 'CpuSpeed'))))
+        LEFT JOIN `user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `vm_instance`.`id`)
+        AND (`custom_ram_size`.`name` = 'memory'))));
diff --git a/utils/src/main/java/com/cloud/utils/FileUtil.java b/utils/src/main/java/com/cloud/utils/FileUtil.java
index d9bf0817687..3521453a631 100644
--- a/utils/src/main/java/com/cloud/utils/FileUtil.java
+++ b/utils/src/main/java/com/cloud/utils/FileUtil.java
@@ -21,9 +21,18 @@ package com.cloud.utils;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.ssh.SshHelper;
@@ -57,4 +66,28 @@ public class FileUtil {
         }
         throw new CloudRuntimeException(finalErrMsg);
     }
+
+    public static List<String> getFilesPathsUnderResourceDirectory(String resourceDirectory) {
+        s_logger.info(String.format("Searching for files under resource directory [%s].", resourceDirectory));
+
+        URL resourceDirectoryUrl = Thread.currentThread().getContextClassLoader().getResource(resourceDirectory);
+        if (resourceDirectoryUrl == null) {
+            throw new CloudRuntimeException(String.format("Resource directory [%s] does not exist or is empty.", resourceDirectory));
+        }
+
+        URI resourceDirectoryUri;
+        try {
+            resourceDirectoryUri = resourceDirectoryUrl.toURI();
+        } catch (URISyntaxException e) {
+            throw new CloudRuntimeException(String.format("Unable to get URI from URL [%s].", resourceDirectoryUrl), e);
+        }
+
+        try (FileSystem fs = FileSystems.newFileSystem(resourceDirectoryUri, Collections.emptyMap());
+                Stream<Path> paths = Files.walk(fs.getPath(resourceDirectory))) {
+            return paths.filter(Files::isRegularFile).map(Path::toString).collect(Collectors.toList());
+        } catch (IOException e) {
+            throw new CloudRuntimeException(String.format("Error while trying to list files under resource directory [%s].", resourceDirectoryUri), e);
+        }
+    }
+
 }