CLOUDSTACK-4757. List templates - Include Datadisk templates in listTemplates response.

And for Datadisk templates include reference to parent template that it belongs to.
This commit is contained in:
Likitha Shetty 2014-04-22 11:36:03 +05:30
parent 902f231e07
commit 5db1bca606
8 changed files with 159 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -75,4 +75,6 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
void loadDetails(VMTemplateVO tmpl);
void saveDetails(VMTemplateVO tmpl);
List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId);
}

View File

@ -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;
@ -277,6 +279,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
return listBy(sc);
}
@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);

View File

@ -467,4 +467,9 @@ public class TemplateObject implements TemplateInfo {
public Class<?> getEntityType() {
return VirtualMachineTemplate.class;
}
@Override
public Long getParentTemplateId() {
return imageVO.getParentTemplateId();
}
}

View File

@ -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;
}
}

View File

@ -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>();

View File

@ -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;

View File

@ -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');