mirror of https://github.com/apache/cloudstack.git
bug 11311: lis host takes in a additional parameter to fine tune the details, the default behavious is still unchanged.
This commit is contained in:
parent
88ec85f86a
commit
488ac8238e
|
|
@ -310,5 +310,8 @@ public class ApiConstants {
|
|||
all, capacity, events, stats, min;
|
||||
}
|
||||
|
||||
public enum VMDetails {
|
||||
all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants.HostDetails;
|
||||
import com.cloud.api.ApiConstants.VMDetails;
|
||||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.response.AccountResponse;
|
||||
import com.cloud.api.response.AsyncJobResponse;
|
||||
|
|
@ -146,7 +147,7 @@ public interface ResponseGenerator {
|
|||
|
||||
List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms);
|
||||
|
||||
List<UserVmResponse> createUserVmResponse(String objectName, int details, UserVm... userVms);
|
||||
List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm... userVms);
|
||||
|
||||
SystemVmResponse createSystemVmResponse(VirtualMachine systemVM);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -26,9 +28,12 @@ import com.cloud.api.BaseListCmd;
|
|||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ApiConstants.VMDetails;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.api.response.UserVmResponse;
|
||||
import com.cloud.async.AsyncJob;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.uservm.UserVm;
|
||||
|
||||
@Implementation(description="List the virtual machines owned by the account.", responseObject=UserVmResponse.class)
|
||||
|
|
@ -94,9 +99,10 @@ public class ListVMsCmd extends BaseListCmd {
|
|||
@IdentityMapper(entityTableName="projects")
|
||||
@Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="list vms by project")
|
||||
private Long projectId;
|
||||
|
||||
@Parameter(name=ApiConstants.DETAILS, type=CommandType.INTEGER, description="bits for querying required vm details")
|
||||
private Integer details_mask;
|
||||
|
||||
@Parameter(name=ApiConstants.DETAILS, type=CommandType.LIST, collectionType=CommandType.STRING, description="comma separated list of host details requested, value can be a list of [all, group, nics, stats, secgrp, tmpl, servoff, iso, volume, min]" )
|
||||
private List<String> viewDetails;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -166,9 +172,27 @@ public class ListVMsCmd extends BaseListCmd {
|
|||
return projectId;
|
||||
}
|
||||
|
||||
public int getDetailsMask() {
|
||||
return details_mask == null ? 0 : details_mask;
|
||||
|
||||
public EnumSet<VMDetails> getDetails() throws InvalidParameterValueException {
|
||||
EnumSet<VMDetails> dv;
|
||||
if (viewDetails==null || viewDetails.size() <=0){
|
||||
dv = EnumSet.of(VMDetails.all);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
ArrayList<VMDetails> dc = new ArrayList<VMDetails>();
|
||||
for (String detail: viewDetails){
|
||||
dc.add(VMDetails.valueOf(detail));
|
||||
}
|
||||
dv = EnumSet.copyOf(dc);
|
||||
}
|
||||
catch (IllegalArgumentException e){
|
||||
throw new InvalidParameterValueException("The details parameter contains a non permitted value. The allowed values are " + EnumSet.allOf(VMDetails.class));
|
||||
}
|
||||
}
|
||||
return dv;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -185,7 +209,14 @@ public class ListVMsCmd extends BaseListCmd {
|
|||
public void execute(){
|
||||
List<? extends UserVm> result = _userVmService.searchForUserVMs(this);
|
||||
ListResponse<UserVmResponse> response = new ListResponse<UserVmResponse>();
|
||||
List<UserVmResponse> vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetailsMask(), result.toArray(new UserVm[result.size()]));
|
||||
EnumSet<VMDetails> details = getDetails();
|
||||
List<UserVmResponse> vmResponses;
|
||||
if (details.contains(VMDetails.all)){ // for all use optimized version
|
||||
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", result.toArray(new UserVm[result.size()]));
|
||||
}
|
||||
else {
|
||||
vmResponses = _responseGenerator.createUserVmResponse("virtualmachine", getDetails(), result.toArray(new UserVm[result.size()]));
|
||||
}
|
||||
response.setResponses(vmResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
|
|
|
|||
|
|
@ -18,11 +18,13 @@
|
|||
|
||||
package com.cloud.api;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.api.ApiConstants.VMDetails;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
|
|
@ -672,8 +674,8 @@ public class ApiDBUtils {
|
|||
return _firewallCidrsDao.getSourceCidrs(id);
|
||||
}
|
||||
|
||||
public static Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> vmData, int details){
|
||||
return _userVmDao.listVmDetails(vmData, details);
|
||||
public static Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> vmData){
|
||||
return _userVmDao.listVmDetails(vmData);
|
||||
}
|
||||
|
||||
public static Account getProjectOwner(long projectId) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import org.apache.log4j.Logger;
|
|||
import com.cloud.acl.ControlledEntity;
|
||||
import com.cloud.acl.ControlledEntity.ACLType;
|
||||
import com.cloud.api.ApiConstants.HostDetails;
|
||||
import com.cloud.api.ApiConstants.VMDetails;
|
||||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.response.AccountResponse;
|
||||
import com.cloud.api.response.ApiResponseSerializer;
|
||||
|
|
@ -142,6 +143,7 @@ import com.cloud.network.security.EgressRule;
|
|||
import com.cloud.network.security.IngressRule;
|
||||
import com.cloud.network.security.SecurityGroup;
|
||||
import com.cloud.network.security.SecurityGroupRules;
|
||||
import com.cloud.network.security.SecurityGroupVO;
|
||||
import com.cloud.offering.DiskOffering;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
|
|
@ -183,6 +185,7 @@ import com.cloud.utils.StringUtils;
|
|||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
|
@ -1174,14 +1177,235 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms) {
|
||||
return createUserVmResponse(objectName, 0, userVms);
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, EnumSet<VMDetails> details, UserVm...userVms) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Map<Long, DataCenter> dataCenters = new HashMap<Long, DataCenter>();
|
||||
Map<Long, Host> hosts = new HashMap<Long, Host>();
|
||||
Map<Long, VMTemplateVO> templates = new HashMap<Long, VMTemplateVO>();
|
||||
Map<Long, ServiceOffering> serviceOfferings = new HashMap<Long, ServiceOffering>();
|
||||
Map<Long, Network> networks = new HashMap<Long, Network>();
|
||||
|
||||
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
|
||||
|
||||
for (UserVm userVm : userVms) {
|
||||
UserVmResponse userVmResponse = new UserVmResponse();
|
||||
Account acct = ApiDBUtils.findAccountById(Long.valueOf(userVm.getAccountId()));
|
||||
if (acct != null) {
|
||||
userVmResponse.setAccountName(acct.getAccountName());
|
||||
userVmResponse.setDomainId(acct.getDomainId());
|
||||
userVmResponse.setDomainName(ApiDBUtils.findDomainById(acct.getDomainId()).getName());
|
||||
}
|
||||
|
||||
userVmResponse.setId(userVm.getId());
|
||||
userVmResponse.setName(userVm.getHostName());
|
||||
userVmResponse.setCreated(userVm.getCreated());
|
||||
|
||||
if (userVm.getState() != null) {
|
||||
userVmResponse.setState(userVm.getState().toString());
|
||||
}
|
||||
|
||||
userVmResponse.setHaEnable(userVm.isHaEnabled());
|
||||
|
||||
if (userVm.getDisplayName() != null) {
|
||||
userVmResponse.setDisplayName(userVm.getDisplayName());
|
||||
} else {
|
||||
userVmResponse.setDisplayName(userVm.getHostName());
|
||||
}
|
||||
|
||||
|
||||
if (userVm.getPassword() != null) {
|
||||
userVmResponse.setPassword(userVm.getPassword());
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.group)){
|
||||
InstanceGroupVO group = ApiDBUtils.findInstanceGroupForVM(userVm.getId());
|
||||
if (group != null) {
|
||||
userVmResponse.setGroup(group.getName());
|
||||
userVmResponse.setGroupId(group.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Data Center Info
|
||||
DataCenter zone = dataCenters.get(userVm.getDataCenterIdToDeployIn());
|
||||
if (zone == null) {
|
||||
zone = ApiDBUtils.findZoneById(userVm.getDataCenterIdToDeployIn());
|
||||
dataCenters.put(zone.getId(), zone);
|
||||
}
|
||||
|
||||
userVmResponse.setZoneId(zone.getId());
|
||||
userVmResponse.setZoneName(zone.getName());
|
||||
|
||||
|
||||
// if user is an admin, display host id
|
||||
if (((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN)) && (userVm.getHostId() != null)) {
|
||||
Host host = hosts.get(userVm.getHostId());
|
||||
|
||||
if (host == null) {
|
||||
host = ApiDBUtils.findHostById(userVm.getHostId());
|
||||
hosts.put(host.getId(), host);
|
||||
}
|
||||
|
||||
userVmResponse.setHostId(host.getId());
|
||||
userVmResponse.setHostName(host.getName());
|
||||
}
|
||||
|
||||
if(userVm.getHypervisorType() != null){
|
||||
userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)){
|
||||
// Template Info
|
||||
VMTemplateVO template = templates.get(userVm.getTemplateId());
|
||||
if (template == null) {
|
||||
template = ApiDBUtils.findTemplateById(userVm.getTemplateId());
|
||||
if (template != null) {
|
||||
templates.put(template.getId(), template);
|
||||
}
|
||||
}
|
||||
|
||||
if (template != null) {
|
||||
userVmResponse.setTemplateId(userVm.getTemplateId());
|
||||
userVmResponse.setTemplateName(template.getName());
|
||||
userVmResponse.setTemplateDisplayText(template.getDisplayText());
|
||||
userVmResponse.setPasswordEnabled(template.getEnablePassword());
|
||||
} else {
|
||||
userVmResponse.setTemplateId(-1L);
|
||||
userVmResponse.setTemplateName("ISO Boot");
|
||||
userVmResponse.setTemplateDisplayText("ISO Boot");
|
||||
userVmResponse.setPasswordEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)){
|
||||
// ISO Info
|
||||
VMTemplateVO iso = templates.get(userVm.getIsoId());
|
||||
if (iso == null) {
|
||||
iso = ApiDBUtils.findTemplateById(userVm.getIsoId());
|
||||
if (iso != null) {
|
||||
templates.put(iso.getId(), iso);
|
||||
}
|
||||
}
|
||||
|
||||
if (iso != null) {
|
||||
userVmResponse.setIsoId(iso.getId());
|
||||
userVmResponse.setIsoName(iso.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)){
|
||||
// Service Offering Info
|
||||
ServiceOffering offering = serviceOfferings.get(userVm.getServiceOfferingId());
|
||||
|
||||
if (offering == null) {
|
||||
offering = ApiDBUtils.findServiceOfferingById(userVm.getServiceOfferingId());
|
||||
serviceOfferings.put(offering.getId(), offering);
|
||||
}
|
||||
|
||||
userVmResponse.setServiceOfferingId(offering.getId());
|
||||
userVmResponse.setServiceOfferingName(offering.getName());
|
||||
userVmResponse.setCpuNumber(offering.getCpu());
|
||||
userVmResponse.setCpuSpeed(offering.getSpeed());
|
||||
userVmResponse.setMemory(offering.getRamSize());
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)){
|
||||
VolumeVO rootVolume = ApiDBUtils.findRootVolume(userVm.getId());
|
||||
if (rootVolume != null) {
|
||||
userVmResponse.setRootDeviceId(rootVolume.getDeviceId());
|
||||
String rootDeviceType = "Not created";
|
||||
if (rootVolume.getPoolId() != null) {
|
||||
StoragePoolVO storagePool = ApiDBUtils.findStoragePoolById(rootVolume.getPoolId());
|
||||
rootDeviceType = storagePool.getPoolType().toString();
|
||||
}
|
||||
userVmResponse.setRootDeviceType(rootDeviceType);
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)){
|
||||
// stats calculation
|
||||
DecimalFormat decimalFormat = new DecimalFormat("#.##");
|
||||
String cpuUsed = null;
|
||||
VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
|
||||
if (vmStats != null) {
|
||||
float cpuUtil = (float) vmStats.getCPUUtilization();
|
||||
cpuUsed = decimalFormat.format(cpuUtil) + "%";
|
||||
userVmResponse.setCpuUsed(cpuUsed);
|
||||
|
||||
Double networkKbRead = Double.valueOf(vmStats.getNetworkReadKBs());
|
||||
userVmResponse.setNetworkKbsRead(networkKbRead.longValue());
|
||||
|
||||
Double networkKbWrite = Double.valueOf(vmStats.getNetworkWriteKBs());
|
||||
userVmResponse.setNetworkKbsWrite(networkKbWrite.longValue());
|
||||
}
|
||||
}
|
||||
|
||||
userVmResponse.setGuestOsId(userVm.getGuestOSId());
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)){
|
||||
// security groups - list only when zone is security group enabled
|
||||
if (zone.isSecurityGroupEnabled()) {
|
||||
List<SecurityGroupVO> securityGroups = ApiDBUtils.getSecurityGroupsForVm(userVm.getId());
|
||||
List<SecurityGroupResponse> securityGroupResponse = new ArrayList<SecurityGroupResponse>();
|
||||
for(SecurityGroupVO grp : securityGroups) {
|
||||
SecurityGroupResponse resp = new SecurityGroupResponse();
|
||||
resp.setId(grp.getId());
|
||||
resp.setName(grp.getName());
|
||||
resp.setDescription(grp.getDescription());
|
||||
resp.setObjectName("securitygroup");
|
||||
securityGroupResponse.add(resp);
|
||||
}
|
||||
userVmResponse.setSecurityGroupList(securityGroupResponse);
|
||||
}
|
||||
}
|
||||
|
||||
if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)){
|
||||
List<NicProfile> nicProfiles = ApiDBUtils.getNics(userVm);
|
||||
List<NicResponse> nicResponses = new ArrayList<NicResponse>();
|
||||
for (NicProfile singleNicProfile : nicProfiles) {
|
||||
NicResponse nicResponse = new NicResponse();
|
||||
nicResponse.setId(singleNicProfile.getId());
|
||||
nicResponse.setIpaddress(singleNicProfile.getIp4Address());
|
||||
nicResponse.setGateway(singleNicProfile.getGateway());
|
||||
nicResponse.setNetmask(singleNicProfile.getNetmask());
|
||||
nicResponse.setNetworkid(singleNicProfile.getNetworkId());
|
||||
if (acct.getType() == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
if (singleNicProfile.getBroadCastUri() != null) {
|
||||
nicResponse.setBroadcastUri(singleNicProfile.getBroadCastUri().toString());
|
||||
}
|
||||
if (singleNicProfile.getIsolationUri() != null) {
|
||||
nicResponse.setIsolationUri(singleNicProfile.getIsolationUri().toString());
|
||||
}
|
||||
}
|
||||
|
||||
//Long networkId = singleNicProfile.getNetworkId();
|
||||
Network network = networks.get(singleNicProfile.getNetworkId());
|
||||
if (network == null) {
|
||||
network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
|
||||
networks.put(singleNicProfile.getNetworkId(), network);
|
||||
}
|
||||
|
||||
nicResponse.setTrafficType(network.getTrafficType().toString());
|
||||
nicResponse.setType(network.getGuestType().toString());
|
||||
nicResponse.setIsDefault(singleNicProfile.isDefaultNic());
|
||||
nicResponse.setObjectName("nic");
|
||||
nicResponses.add(nicResponse);
|
||||
}
|
||||
userVmResponse.setNics(nicResponses);
|
||||
}
|
||||
|
||||
userVmResponse.setObjectName(objectName);
|
||||
vmResponses.add(userVmResponse);
|
||||
}
|
||||
|
||||
return vmResponses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, int details, UserVm... userVms) {
|
||||
public List<UserVmResponse> createUserVmResponse(String objectName, UserVm... userVms) {
|
||||
Account caller = UserContext.current().getCaller();
|
||||
boolean caller_is_admin = ((caller == null) || (caller.getType() == Account.ACCOUNT_TYPE_ADMIN));
|
||||
|
||||
|
|
@ -1192,7 +1416,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
vmDataList.put(userVm.getId(), userVmData);
|
||||
}
|
||||
|
||||
vmDataList = ApiDBUtils.listVmDetails(vmDataList, details);
|
||||
vmDataList = ApiDBUtils.listVmDetails(vmDataList);
|
||||
|
||||
//initialize vmresponse from vmdatalist
|
||||
List<UserVmResponse> vmResponses = new ArrayList<UserVmResponse>();
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2011 Citrix.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.vm.dao;
|
||||
|
||||
|
||||
public class DetailsMask {
|
||||
public final static int FULL_DETAILS=0;
|
||||
|
||||
public final static int BASIC_DETAILS=1;
|
||||
public final static int NICS_DETAILS=2;
|
||||
public final static int STATISTICS_DETAILS=4;
|
||||
public final static int SECURITY_GROUP_DETAILS=8;
|
||||
|
||||
public final static int TEMPLATE_DETAILS=16;
|
||||
public final static int SERVICE_OFFERING_DETAILS=32;
|
||||
public final static int ISO_DETAILS=64;
|
||||
public final static int VOLUME_DETAILS=128;
|
||||
|
||||
int _mask;
|
||||
|
||||
public DetailsMask(int i){
|
||||
_mask = i;
|
||||
}
|
||||
|
||||
private final String[] strings = new String[] {
|
||||
"basic", "nics", "stats", "secgrp",
|
||||
"tmpl", "servoff", "iso", "volume"
|
||||
};
|
||||
|
||||
private final int[] values = new int[] {
|
||||
1, 2, 4, 8,
|
||||
16, 32, 64, 128,
|
||||
256, 512, 1024, 2048,
|
||||
4096, 8192, 16384, 32768,
|
||||
65536, 131072, 262144, 524288
|
||||
};
|
||||
|
||||
public int intValue(String str) {
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
if (str.equals(strings[i])) {
|
||||
return values[i];
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public String stringValue(int mvId) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (mvId == values[i]) {
|
||||
return strings[i];
|
||||
}
|
||||
else if ( (mvId & values[i]) == values[i]) {
|
||||
buf.append(strings[i]).append("|");
|
||||
}
|
||||
}
|
||||
if (buf.length() == 0) {
|
||||
return "";
|
||||
}
|
||||
return buf.deleteCharAt(buf.length() - 1).toString();
|
||||
}
|
||||
|
||||
public boolean idValid(int mvId) {
|
||||
if (mvId > 128 || mvId < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAllDetails(){
|
||||
return (_mask == 0);
|
||||
}
|
||||
|
||||
public boolean isBasicDetails(){
|
||||
return (_mask & BASIC_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isNicsDetails(){
|
||||
return (_mask & NICS_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isStatsDetails(){
|
||||
return (_mask & STATISTICS_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isSecurityGroupDetails(){
|
||||
return (_mask & STATISTICS_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isTemplateDetails(){
|
||||
return (_mask & TEMPLATE_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isServiceOfferingDetails(){
|
||||
return (_mask & SERVICE_OFFERING_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isIsoDetails(){
|
||||
return (_mask & ISO_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
public boolean isVolumeDetails(){
|
||||
return (_mask & VOLUME_DETAILS ) > 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -18,9 +18,11 @@
|
|||
package com.cloud.vm.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants.VMDetails;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
|
@ -70,5 +72,5 @@ public interface UserVmDao extends GenericDao<UserVmVO, Long> {
|
|||
List<Long> listPodIdsHavingVmsforAccount(long zoneId, long accountId);
|
||||
public Long countAllocatedVMsForAccount(long accountId);
|
||||
|
||||
Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmData, int details);
|
||||
Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmData);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,33 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT = "SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') " +
|
||||
"GROUP BY pod_id HAVING count(id) > 0 ORDER BY count(id) DESC";
|
||||
|
||||
private static String VM_DETAILS = "select vm_instance.id, " +
|
||||
"account.id, account.account_name, account.type, domain.name, instance_group.id, instance_group.name," +
|
||||
"data_center.id, data_center.name, data_center.is_security_group_enabled, host.id, host.name, " +
|
||||
"vm_template.id, vm_template.name, vm_template.display_text, iso.id, iso.name, " +
|
||||
"vm_template.enable_password, service_offering.id, disk_offering.name, storage_pool.id, storage_pool.pool_type, " +
|
||||
"service_offering.cpu, service_offering.speed, service_offering.ram_size, volumes.id, volumes.device_id, volumes.volume_type, security_group.id, security_group.name, " +
|
||||
"security_group.description, nics.id, nics.ip4_address, nics.gateway, nics.network_id, nics.netmask, nics.mac_address, nics.broadcast_uri, nics.isolation_uri, " +
|
||||
"networks.traffic_type, networks.guest_type, networks.is_default from vm_instance " +
|
||||
"left join account on vm_instance.account_id=account.id " +
|
||||
"left join domain on vm_instance.domain_id=domain.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 user_vm on vm_instance.id=user_vm.id " +
|
||||
"left join vm_template iso on iso.id=user_vm.iso_id " +
|
||||
"left join service_offering on vm_instance.service_offering_id=service_offering.id " +
|
||||
"left join disk_offering on vm_instance.service_offering_id=disk_offering.id " +
|
||||
"left join volumes on vm_instance.id=volumes.instance_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 nics on vm_instance.id=nics.instance_id " +
|
||||
"left join networks on nics.network_id=networks.id " +
|
||||
"where vm_instance.id in (";
|
||||
|
||||
private static final int VM_DETAILS_BATCH_SIZE=100;
|
||||
|
||||
protected final UserVmDetailsDaoImpl _detailsDao = ComponentLocator.inject(UserVmDetailsDaoImpl.class);
|
||||
|
|
@ -318,11 +345,9 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmDataHash, int details){
|
||||
public Hashtable<Long, UserVmData> listVmDetails(Hashtable<Long, UserVmData> userVmDataHash){
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
PreparedStatement pstmt = null;
|
||||
DetailSql sql = new DetailSql(details);
|
||||
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
try {
|
||||
int curr_index=0;
|
||||
|
|
@ -330,7 +355,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
List<UserVmData> userVmDataList = new ArrayList(userVmDataHash.values());
|
||||
|
||||
if (userVmDataList.size() > VM_DETAILS_BATCH_SIZE){
|
||||
pstmt = txn.prepareStatement(sql.getSql() + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE));
|
||||
pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(VM_DETAILS_BATCH_SIZE));
|
||||
while ( (curr_index + VM_DETAILS_BATCH_SIZE) <= userVmDataList.size()){
|
||||
// set the vars value
|
||||
for (int k=1,j=curr_index;j<curr_index+VM_DETAILS_BATCH_SIZE;j++,k++){
|
||||
|
|
@ -356,7 +381,7 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
|
||||
if (curr_index < userVmDataList.size()){
|
||||
int batch_size = (userVmDataList.size() - curr_index);
|
||||
pstmt = txn.prepareStatement(sql.getSql() + getQueryBatchAppender(batch_size));
|
||||
pstmt = txn.prepareStatement(VM_DETAILS + getQueryBatchAppender(batch_size));
|
||||
// set the vars value
|
||||
for (int k=1,j=curr_index;j<curr_index+batch_size;j++,k++){
|
||||
pstmt.setLong(k, userVmDataList.get(j).getId());
|
||||
|
|
@ -379,9 +404,9 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
if (pstmt!=null)pstmt.close();
|
||||
return userVmDataHash;
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("DB Exception on: " + sql.getSql(), e);
|
||||
throw new CloudRuntimeException("DB Exception on: " + VM_DETAILS, e);
|
||||
} catch (Throwable e) {
|
||||
throw new CloudRuntimeException("Caught: " + sql.getSql(), e);
|
||||
throw new CloudRuntimeException("Caught: " + VM_DETAILS, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -513,52 +538,5 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
|
|||
return customSearch(sc, null).get(0);
|
||||
}
|
||||
|
||||
|
||||
public static class DetailSql {
|
||||
private final DetailsMask _details;
|
||||
|
||||
private static String VM_DETAILS = "select vm_instance.id, " +
|
||||
"account.id, account.account_name, account.type, domain.name, instance_group.id, instance_group.name," +
|
||||
"data_center.id, data_center.name, data_center.is_security_group_enabled, host.id, host.name, " +
|
||||
"vm_template.id, vm_template.name, vm_template.display_text, iso.id, iso.name, " +
|
||||
"vm_template.enable_password, service_offering.id, disk_offering.name, storage_pool.id, storage_pool.pool_type, " +
|
||||
"service_offering.cpu, service_offering.speed, service_offering.ram_size, volumes.id, volumes.device_id, volumes.volume_type, security_group.id, security_group.name, " +
|
||||
"security_group.description, nics.id, nics.ip4_address, nics.gateway, nics.network_id, nics.netmask, nics.mac_address, nics.broadcast_uri, nics.isolation_uri, " +
|
||||
"networks.traffic_type, networks.guest_type, networks.is_default from vm_instance " +
|
||||
"left join account on vm_instance.account_id=account.id " +
|
||||
"left join domain on vm_instance.domain_id=domain.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 user_vm on vm_instance.id=user_vm.id " +
|
||||
"left join vm_template iso on iso.id=user_vm.iso_id " +
|
||||
"left join service_offering on vm_instance.service_offering_id=service_offering.id " +
|
||||
"left join disk_offering on vm_instance.service_offering_id=disk_offering.id " +
|
||||
"left join volumes on vm_instance.id=volumes.instance_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 nics on vm_instance.id=nics.instance_id " +
|
||||
"left join networks on nics.network_id=networks.id " +
|
||||
"where vm_instance.id in (";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public DetailSql(int details){
|
||||
_details = new DetailsMask(details);
|
||||
}
|
||||
|
||||
public String getSql(){
|
||||
return VM_DETAILS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue