mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-7981: listVirtualMachine is too slow in case of duplicate
resource tags due to joining user_vm_details to user_vm_view.
This commit is contained in:
parent
86576593be
commit
bf8dd828f5
@ -240,6 +240,8 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
@Param(description = "the list of resource tags associated with vm", responseObject = ResourceTagResponse.class)
|
||||
private Set<ResourceTagResponse> tags;
|
||||
|
||||
transient Set<Long> tagIds;
|
||||
|
||||
@SerializedName(ApiConstants.DETAILS)
|
||||
@Param(description = "Vm details in key/value pairs.", since = "4.2.1")
|
||||
private Map details;
|
||||
@ -272,6 +274,7 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
securityGroupList = new LinkedHashSet<SecurityGroupResponse>();
|
||||
nics = new LinkedHashSet<NicResponse>();
|
||||
tags = new LinkedHashSet<ResourceTagResponse>();
|
||||
tagIds = new LinkedHashSet<Long>();
|
||||
affinityGroupList = new LinkedHashSet<AffinityGroupResponse>();
|
||||
}
|
||||
|
||||
@ -723,6 +726,10 @@ public class UserVmResponse extends BaseResponse implements ControlledEntityResp
|
||||
this.instanceName = instanceName;
|
||||
}
|
||||
|
||||
public boolean containTag(Long tagId) {
|
||||
return tagIds.contains(tagId);
|
||||
}
|
||||
|
||||
public void setTags(Set<ResourceTagResponse> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
@ -1633,12 +1633,7 @@ public class ApiDBUtils {
|
||||
}
|
||||
|
||||
public static ResourceTagJoinVO findResourceTagViewById(Long tagId) {
|
||||
List<ResourceTagJoinVO> tags = s_tagJoinDao.searchByIds(tagId);
|
||||
if (tags != null && tags.size() > 0) {
|
||||
return tags.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return s_tagJoinDao.searchById(tagId);
|
||||
}
|
||||
|
||||
public static EventResponse newEventResponse(EventJoinVO ve) {
|
||||
|
||||
@ -34,4 +34,6 @@ public interface ResourceTagJoinDao extends GenericDao<ResourceTagJoinVO, Long>
|
||||
List<ResourceTagJoinVO> searchByIds(Long... ids);
|
||||
|
||||
List<ResourceTagJoinVO> listBy(String resourceUUID, ResourceObjectType resourceType);
|
||||
|
||||
ResourceTagJoinVO searchById(Long id);
|
||||
}
|
||||
|
||||
@ -145,6 +145,15 @@ public class ResourceTagJoinDaoImpl extends GenericDaoBase<ResourceTagJoinVO, Lo
|
||||
return uvList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceTagJoinVO searchById(Long id) {
|
||||
SearchCriteria<ResourceTagJoinVO> sc = tagIdSearch.create();
|
||||
sc.setParameters("id", id);
|
||||
List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
|
||||
assert vms != null && vms.size() == 1 : "No tag found for tag id " + id;
|
||||
return vms.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceTagJoinVO newResourceTagView(ResourceTag vr) {
|
||||
|
||||
|
||||
@ -262,7 +262,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
|
||||
|
||||
// update tag information
|
||||
long tag_id = userVm.getTagId();
|
||||
if (tag_id > 0) {
|
||||
if (tag_id > 0 && !userVmResponse.containTag(tag_id)) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if (vtag != null) {
|
||||
userVmResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
@ -350,7 +350,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBase<UserVmJoinVO, Long> implem
|
||||
}
|
||||
|
||||
long tag_id = uvo.getTagId();
|
||||
if (tag_id > 0) {
|
||||
if (tag_id > 0 && !userVmData.containTag(tag_id)) {
|
||||
ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
|
||||
if (vtag != null) {
|
||||
userVmData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
|
||||
|
||||
@ -31,7 +31,6 @@ import javax.persistence.Transient;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.server.ResourceTag.ResourceObjectType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
@ -346,34 +345,6 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
||||
@Column(name = "tag_id")
|
||||
private long tagId;
|
||||
|
||||
@Column(name = "tag_uuid")
|
||||
private String tagUuid;
|
||||
|
||||
@Column(name = "tag_key")
|
||||
private String tagKey;
|
||||
|
||||
@Column(name = "tag_value")
|
||||
private String tagValue;
|
||||
|
||||
@Column(name = "tag_domain_id")
|
||||
private long tagDomainId;
|
||||
|
||||
@Column(name = "tag_account_id")
|
||||
private long tagAccountId;
|
||||
|
||||
@Column(name = "tag_resource_id")
|
||||
private long tagResourceId;
|
||||
|
||||
@Column(name = "tag_resource_uuid")
|
||||
private String tagResourceUuid;
|
||||
|
||||
@Column(name = "tag_resource_type")
|
||||
@Enumerated(value = EnumType.STRING)
|
||||
private ResourceObjectType tagResourceType;
|
||||
|
||||
@Column(name = "tag_customer")
|
||||
private String tagCustomer;
|
||||
|
||||
@Column(name = "affinity_group_id")
|
||||
private long affinityGroupId;
|
||||
|
||||
@ -397,11 +368,6 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
||||
@Column(name = "dynamically_scalable")
|
||||
private boolean isDynamicallyScalable;
|
||||
|
||||
@Column(name = "detail_name")
|
||||
private String detailName;
|
||||
|
||||
@Column(name = "detail_value")
|
||||
private String detailValue;
|
||||
|
||||
public UserVmJoinVO() {
|
||||
}
|
||||
@ -780,42 +746,6 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
||||
return tagId;
|
||||
}
|
||||
|
||||
public String getTagUuid() {
|
||||
return tagUuid;
|
||||
}
|
||||
|
||||
public String getTagKey() {
|
||||
return tagKey;
|
||||
}
|
||||
|
||||
public String getTagValue() {
|
||||
return tagValue;
|
||||
}
|
||||
|
||||
public long getTagDomainId() {
|
||||
return tagDomainId;
|
||||
}
|
||||
|
||||
public long getTagAccountId() {
|
||||
return tagAccountId;
|
||||
}
|
||||
|
||||
public long getTagResourceId() {
|
||||
return tagResourceId;
|
||||
}
|
||||
|
||||
public String getTagResourceUuid() {
|
||||
return tagResourceUuid;
|
||||
}
|
||||
|
||||
public ResourceObjectType getTagResourceType() {
|
||||
return tagResourceType;
|
||||
}
|
||||
|
||||
public String getTagCustomer() {
|
||||
return tagCustomer;
|
||||
}
|
||||
|
||||
public boolean isLimitCpuUse() {
|
||||
return limitCpuUse;
|
||||
}
|
||||
@ -902,13 +832,6 @@ public class UserVmJoinVO extends BaseViewVO implements ControlledViewEntity {
|
||||
return isDynamicallyScalable;
|
||||
}
|
||||
|
||||
public String getDetailName() {
|
||||
return detailName;
|
||||
}
|
||||
|
||||
public String getDetailValue() {
|
||||
return detailValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getEntityType() {
|
||||
|
||||
@ -543,6 +543,198 @@ CREATE VIEW `cloud`.`domain_router_view` AS
|
||||
and async_job.instance_type = 'DomainRouter'
|
||||
and async_job.job_status = 0;
|
||||
|
||||
DROP VIEW IF EXISTS `cloud`.`user_vm_view`;
|
||||
CREATE VIEW `cloud`.`user_vm_view` AS
|
||||
select
|
||||
vm_instance.id id,
|
||||
vm_instance.name name,
|
||||
user_vm.display_name display_name,
|
||||
user_vm.user_data user_data,
|
||||
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,
|
||||
instance_group.id instance_group_id,
|
||||
instance_group.uuid instance_group_uuid,
|
||||
instance_group.name instance_group_name,
|
||||
vm_instance.uuid uuid,
|
||||
vm_instance.last_host_id last_host_id,
|
||||
vm_instance.vm_type type,
|
||||
vm_instance.vnc_password vnc_password,
|
||||
vm_instance.limit_cpu_use limit_cpu_use,
|
||||
vm_instance.created created,
|
||||
vm_instance.state state,
|
||||
vm_instance.removed removed,
|
||||
vm_instance.ha_enabled ha_enabled,
|
||||
vm_instance.hypervisor_type hypervisor_type,
|
||||
vm_instance.instance_name instance_name,
|
||||
vm_instance.guest_os_id guest_os_id,
|
||||
vm_instance.display_vm display_vm,
|
||||
guest_os.uuid guest_os_uuid,
|
||||
vm_instance.pod_id pod_id,
|
||||
host_pod_ref.uuid pod_uuid,
|
||||
vm_instance.private_ip_address private_ip_address,
|
||||
vm_instance.private_mac_address private_mac_address,
|
||||
vm_instance.vm_type vm_type,
|
||||
data_center.id data_center_id,
|
||||
data_center.uuid data_center_uuid,
|
||||
data_center.name data_center_name,
|
||||
data_center.is_security_group_enabled security_group_enabled,
|
||||
data_center.networktype data_center_type,
|
||||
host.id host_id,
|
||||
host.uuid host_uuid,
|
||||
host.name host_name,
|
||||
vm_template.id template_id,
|
||||
vm_template.uuid template_uuid,
|
||||
vm_template.name template_name,
|
||||
vm_template.display_text template_display_text,
|
||||
vm_template.enable_password password_enabled,
|
||||
iso.id iso_id,
|
||||
iso.uuid iso_uuid,
|
||||
iso.name iso_name,
|
||||
iso.display_text iso_display_text,
|
||||
service_offering.id service_offering_id,
|
||||
svc_disk_offering.uuid service_offering_uuid,
|
||||
disk_offering.uuid disk_offering_uuid,
|
||||
disk_offering.id disk_offering_id,
|
||||
Case
|
||||
When (`cloud`.`service_offering`.`cpu` is null) then (`custom_cpu`.`value`)
|
||||
Else ( `cloud`.`service_offering`.`cpu`)
|
||||
End as `cpu`,
|
||||
Case
|
||||
When (`cloud`.`service_offering`.`speed` is null) then (`custom_speed`.`value`)
|
||||
Else ( `cloud`.`service_offering`.`speed`)
|
||||
End as `speed`,
|
||||
Case
|
||||
When (`cloud`.`service_offering`.`ram_size` is null) then (`custom_ram_size`.`value`)
|
||||
Else ( `cloud`.`service_offering`.`ram_size`)
|
||||
END as `ram_size`,
|
||||
svc_disk_offering.name service_offering_name,
|
||||
disk_offering.name disk_offering_name,
|
||||
storage_pool.id pool_id,
|
||||
storage_pool.uuid pool_uuid,
|
||||
storage_pool.pool_type pool_type,
|
||||
volumes.id volume_id,
|
||||
volumes.uuid volume_uuid,
|
||||
volumes.device_id volume_device_id,
|
||||
volumes.volume_type volume_type,
|
||||
security_group.id security_group_id,
|
||||
security_group.uuid security_group_uuid,
|
||||
security_group.name security_group_name,
|
||||
security_group.description security_group_description,
|
||||
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,
|
||||
vpc.id vpc_id,
|
||||
vpc.uuid vpc_uuid,
|
||||
networks.uuid network_uuid,
|
||||
networks.name network_name,
|
||||
networks.traffic_type traffic_type,
|
||||
networks.guest_type guest_type,
|
||||
user_ip_address.id public_ip_id,
|
||||
user_ip_address.uuid public_ip_uuid,
|
||||
user_ip_address.public_ip_address public_ip_address,
|
||||
ssh_keypairs.keypair_name keypair_name,
|
||||
resource_tags.id tag_id,
|
||||
async_job.id job_id,
|
||||
async_job.uuid job_uuid,
|
||||
async_job.job_status job_status,
|
||||
async_job.account_id job_account_id,
|
||||
affinity_group.id affinity_group_id,
|
||||
affinity_group.uuid affinity_group_uuid,
|
||||
affinity_group.name affinity_group_name,
|
||||
affinity_group.description affinity_group_description,
|
||||
vm_instance.dynamically_scalable dynamically_scalable
|
||||
|
||||
from
|
||||
`cloud`.`user_vm`
|
||||
inner join
|
||||
`cloud`.`vm_instance` ON vm_instance.id = user_vm.id
|
||||
and vm_instance.removed is NULL
|
||||
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`.`guest_os` ON vm_instance.guest_os_id = guest_os.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`.`instance_group_vm_map` ON vm_instance.id = instance_group_vm_map.instance_id
|
||||
left join
|
||||
`cloud`.`instance_group` ON instance_group_vm_map.group_id = instance_group.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`.`vm_template` iso ON iso.id = user_vm.iso_id
|
||||
left join
|
||||
`cloud`.`service_offering` ON vm_instance.service_offering_id = service_offering.id
|
||||
left join
|
||||
`cloud`.`disk_offering` svc_disk_offering ON vm_instance.service_offering_id = svc_disk_offering.id
|
||||
left join
|
||||
`cloud`.`disk_offering` ON vm_instance.disk_offering_id = disk_offering.id
|
||||
left join
|
||||
`cloud`.`volumes` ON vm_instance.id = volumes.instance_id
|
||||
left join
|
||||
`cloud`.`storage_pool` ON volumes.pool_id = storage_pool.id
|
||||
left join
|
||||
`cloud`.`security_group_vm_map` ON vm_instance.id = security_group_vm_map.instance_id
|
||||
left join
|
||||
`cloud`.`security_group` ON security_group_vm_map.security_group_id = security_group.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 networks.vpc_id = vpc.id and vpc.removed is null
|
||||
left join
|
||||
`cloud`.`user_ip_address` ON user_ip_address.vm_id = vm_instance.id
|
||||
left join
|
||||
`cloud`.`user_vm_details` as ssh_details ON ssh_details.vm_id = vm_instance.id
|
||||
and ssh_details.name = 'SSH.PublicKey'
|
||||
left join
|
||||
`cloud`.`ssh_keypairs` ON ssh_keypairs.public_key = ssh_details.value
|
||||
left join
|
||||
`cloud`.`resource_tags` ON resource_tags.resource_id = vm_instance.id
|
||||
and resource_tags.resource_type = 'UserVm'
|
||||
left join
|
||||
`cloud`.`async_job` ON async_job.instance_id = vm_instance.id
|
||||
and async_job.instance_type = 'VirtualMachine'
|
||||
and async_job.job_status = 0
|
||||
left join
|
||||
`cloud`.`affinity_group_vm_map` ON vm_instance.id = affinity_group_vm_map.instance_id
|
||||
left join
|
||||
`cloud`.`affinity_group` ON affinity_group_vm_map.affinity_group_id = affinity_group.id
|
||||
left join
|
||||
`cloud`.`user_vm_details` `custom_cpu` ON (((`custom_cpu`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_cpu`.`name` = 'CpuNumber')))
|
||||
left join
|
||||
`cloud`.`user_vm_details` `custom_speed` ON (((`custom_speed`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_speed`.`name` = 'CpuSpeed')))
|
||||
left join
|
||||
`cloud`.`user_vm_details` `custom_ram_size` ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`) and (`custom_ram_size`.`name` = 'memory')));
|
||||
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`guest_os` (id, uuid, category_id, display_name, created) VALUES (231, UUID(), 1, 'CentOS 5 (32-bit)', utc_timestamp());
|
||||
INSERT IGNORE INTO `cloud`.`guest_os` (id, uuid, category_id, display_name, created) VALUES (232, UUID(), 1, 'CentOS 5 (64-bit)', utc_timestamp());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user