CLOUDSTACK-4757. List templates - Include Datadisk templates in listTemplates 
response.
And for Datadisk templates include reference to parent template that it belongs 
to.


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

Branch: refs/heads/multiple-disk-ova
Commit: 5db1bca606ca0f93452c49a362564552771709eb
Parents: 902f231
Author: Likitha Shetty <likitha.she...@citrix.com>
Authored: Tue Apr 22 11:36:03 2014 +0530
Committer: Likitha Shetty <likitha.she...@citrix.com>
Committed: Fri May 2 17:51:31 2014 +0530

----------------------------------------------------------------------
 .../api/response/TemplateResponse.java          |   8 ++
 .../com/cloud/storage/dao/VMTemplateDao.java    |   2 +
 .../cloud/storage/dao/VMTemplateDaoImpl.java    |  19 +++-
 .../storage/image/store/TemplateObject.java     |   5 +
 .../storage/image/TemplateEntityImpl.java       |   6 ++
 .../api/query/dao/TemplateJoinDaoImpl.java      |   4 +
 .../com/cloud/api/query/vo/TemplateJoinVO.java  |  14 +++
 setup/db/db/schema-440to450.sql                 | 103 +++++++++++++++++++
 8 files changed, 159 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/TemplateResponse.java 
b/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
index 3e21043..6177513 100644
--- a/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
@@ -187,6 +187,10 @@ public class TemplateResponse extends BaseResponse 
implements ControlledViewEnti
     @Param(description = "true if template contains XS/VMWare tools inorder to 
support dynamic scaling of VM cpu/memory")
     private Boolean isDynamicallyScalable;
 
+    @SerializedName("parenttemplateid")
+    @Param(description = "if Datadisk template, then id of the root disk 
template this template belongs to")
+    private String parentTemplateId;
+
     public TemplateResponse() {
         //  zones = new LinkedHashSet<TemplateZoneResponse>();
         tags = new LinkedHashSet<ResourceTagResponse>();
@@ -361,4 +365,8 @@ public class TemplateResponse extends BaseResponse 
implements ControlledViewEnti
     public String getZoneId() {
         return zoneId;
     }
+
+    public void setParentTemplateId(String parentTemplateId) {
+        this.parentTemplateId = parentTemplateId;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java 
b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
index 2b815d8..44ffcbe 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDao.java
@@ -75,4 +75,6 @@ public interface VMTemplateDao extends 
GenericDao<VMTemplateVO, Long> {
     void loadDetails(VMTemplateVO tmpl);
 
     void saveDetails(VMTemplateVO tmpl);
+
+    List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java 
b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
index 401a4a2..c96e2b1 100755
--- a/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VMTemplateDaoImpl.java
@@ -28,11 +28,12 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.host.Host;
@@ -98,6 +99,7 @@ public class VMTemplateDaoImpl extends 
GenericDaoBase<VMTemplateVO, Long> implem
     protected SearchBuilder<VMTemplateVO> NameSearch;
     protected SearchBuilder<VMTemplateVO> TmpltsInZoneSearch;
     protected SearchBuilder<VMTemplateVO> ActiveTmpltSearch;
+    protected SearchBuilder<VMTemplateVO> ParentTemplateIdSearch;
     private SearchBuilder<VMTemplateVO> PublicSearch;
     private SearchBuilder<VMTemplateVO> NameAccountIdSearch;
     private SearchBuilder<VMTemplateVO> PublicIsoSearch;
@@ -278,6 +280,14 @@ public class VMTemplateDaoImpl extends 
GenericDaoBase<VMTemplateVO, Long> implem
     }
 
     @Override
+    public List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId) {
+        SearchCriteria<VMTemplateVO> sc = ParentTemplateIdSearch.create();
+        sc.setParameters("parentTemplateId", parentTemplatetId);
+        sc.setParameters("state", VirtualMachineTemplate.State.Active);
+        return listBy(sc);
+    }
+
+    @Override
     public boolean configure(String name, Map<String, Object> params) throws 
ConfigurationException {
         boolean result = super.configure(name, params);
 
@@ -387,6 +397,11 @@ public class VMTemplateDaoImpl extends 
GenericDaoBase<VMTemplateVO, Long> implem
         CountTemplatesByAccount.and("state", 
CountTemplatesByAccount.entity().getState(), SearchCriteria.Op.EQ);
         CountTemplatesByAccount.done();
 
+        ParentTemplateIdSearch = createSearchBuilder();
+        ParentTemplateIdSearch.and("parentTemplateId", 
ParentTemplateIdSearch.entity().getParentTemplateId(), SearchCriteria.Op.EQ);
+        ParentTemplateIdSearch.and("state", 
ParentTemplateIdSearch.entity().getState(), SearchCriteria.Op.EQ);
+        ParentTemplateIdSearch.done();
+
         //        updateStateSearch = this.createSearchBuilder();
         //        updateStateSearch.and("id", 
updateStateSearch.entity().getId(), Op.EQ);
         //        updateStateSearch.and("state", 
updateStateSearch.entity().getState(), Op.EQ);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
 
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
index 5649028..a28498f 100644
--- 
a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
+++ 
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
@@ -467,4 +467,9 @@ public class TemplateObject implements TemplateInfo {
     public Class<?> getEntityType() {
         return VirtualMachineTemplate.class;
     }
+
+    @Override
+    public Long getParentTemplateId() {
+        return imageVO.getParentTemplateId();
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
----------------------------------------------------------------------
diff --git 
a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
 
b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
index c1aa8c2..5e038b8 100644
--- 
a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
+++ 
b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
@@ -290,4 +290,10 @@ public class TemplateEntityImpl implements TemplateEntity {
     public Class<?> getEntityType() {
         return VirtualMachineTemplate.class;
     }
+
+    @Override
+    public Long getParentTemplateId() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java 
b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index 80ef0f6..d245d17 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -180,6 +180,10 @@ public class TemplateJoinDaoImpl extends 
GenericDaoBase<TemplateJoinVO, Long> im
         }
         templateResponse.setTemplateTag(template.getTemplateTag());
 
+        if (template.getParentTemplateId() != null) {
+            
templateResponse.setParentTemplateId(template.getParentTemplateUuid());
+        }
+
         // set details map
         if (template.getDetailName() != null) {
             Map<String, String> details = new HashMap<String, String>();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java 
b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
index 834a9ce..62a103f 100644
--- a/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
+++ b/server/src/com/cloud/api/query/vo/TemplateJoinVO.java
@@ -209,6 +209,12 @@ public class TemplateJoinVO extends BaseViewVO implements 
ControlledViewEntity {
     @Column(name = "destroyed")
     boolean destroyed = false;
 
+    @Column(name = "parent_template_id")
+    private Long parentTemplateId;
+
+    @Column(name = "parent_template_uuid")
+    private String parentTemplateUuid;
+
     @Column(name = "lp_account_id")
     private Long sharedAccountId;
 
@@ -543,6 +549,14 @@ public class TemplateJoinVO extends BaseViewVO implements 
ControlledViewEntity {
         return templateState;
     }
 
+    public Long getParentTemplateId() {
+        return parentTemplateId;
+    }
+
+    public String getParentTemplateUuid() {
+        return parentTemplateUuid;
+    }
+
     @Override
     public Class<?> getEntityType() {
         return VirtualMachineTemplate.class;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5db1bca6/setup/db/db/schema-440to450.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-440to450.sql b/setup/db/db/schema-440to450.sql
index 1fbb312..2493482 100644
--- a/setup/db/db/schema-440to450.sql
+++ b/setup/db/db/schema-440to450.sql
@@ -225,3 +225,106 @@ CREATE VIEW `cloud`.`volume_view` AS
             and async_job.job_status = 0;
 
 ALTER TABLE `cloud`.`vm_template` ADD COLUMN `parent_template_id` bigint(20) 
unsigned DEFAULT NULL COMMENT 'If datadisk template, then id of the root 
template this template belongs to';
+
+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.state template_state,
+        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,
+        parent_template.id parent_template_id,
+        parent_template.uuid parent_template_uuid,
+        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`
+            left 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' and 
template_store_ref.destroyed=0
+            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`.`vm_template` parent_template ON parent_template.id = 
vm_template.parent_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');

Reply via email to