CLOUDSTACK-4908: CPU socket count of host Adding cpu socket count of the host in hostresponse

Signed-off-by: Koushik Das <koushik@apache.org>
This commit is contained in:
Harikrishna Patnala 2013-11-05 16:00:43 +05:30 committed by Koushik Das
parent 3a91500173
commit a286dec098
18 changed files with 170 additions and 3 deletions

View File

@ -106,6 +106,11 @@ public interface Host extends StateObject<Status>, Identity, InternalIdentity {
*/ */
Long getTotalMemory(); Long getTotalMemory();
/**
* @return # of cpu sockets in a machine.
*/
Integer getCpuSockets();
/** /**
* @return # of cores in a machine. Note two cpus with two cores each returns 4. * @return # of cores in a machine. Note two cpus with two cores each returns 4.
*/ */

View File

@ -21,6 +21,7 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandJobType; import org.apache.cloudstack.api.ApiCommandJobType;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
@ -88,6 +89,9 @@ public class ListHostsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.HA_HOST, type=CommandType.BOOLEAN, description="if true, list only hosts dedicated to HA") @Parameter(name=ApiConstants.HA_HOST, type=CommandType.BOOLEAN, description="if true, list only hosts dedicated to HA")
private Boolean haHost; private Boolean haHost;
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, description="hypervisor type of host: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator")
private String hypervisor;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
/////////////////// Accessors /////////////////////// /////////////////// Accessors ///////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -128,6 +132,10 @@ public class ListHostsCmd extends BaseListCmd {
return virtualMachineId; return virtualMachineId;
} }
public HypervisorType getHypervisor() {
return HypervisorType.getType(hypervisor);
}
public EnumSet<HostDetails> getDetails() throws InvalidParameterValueException { public EnumSet<HostDetails> getDetails() throws InvalidParameterValueException {
EnumSet<HostDetails> dv; EnumSet<HostDetails> dv;
if (viewDetails==null || viewDetails.size() <=0){ if (viewDetails==null || viewDetails.size() <=0){

View File

@ -72,6 +72,9 @@ public class HostResponse extends BaseResponse {
@SerializedName(ApiConstants.HYPERVISOR) @Param(description="the host hypervisor") @SerializedName(ApiConstants.HYPERVISOR) @Param(description="the host hypervisor")
private HypervisorType hypervisor; private HypervisorType hypervisor;
@SerializedName("cpusockets") @Param(description="the number of CPU sockets on the host")
private Integer cpuSockets;
@SerializedName("cpunumber") @Param(description="the CPU number of the host") @SerializedName("cpunumber") @Param(description="the CPU number of the host")
private Integer cpuNumber; private Integer cpuNumber;
@ -225,6 +228,10 @@ public class HostResponse extends BaseResponse {
this.hypervisor = hypervisor; this.hypervisor = hypervisor;
} }
public void setCpuSockets(Integer cpuSockets) {
this.cpuSockets = cpuSockets;
}
public void setCpuNumber(Integer cpuNumber) { public void setCpuNumber(Integer cpuNumber) {
this.cpuNumber = cpuNumber; this.cpuNumber = cpuNumber;
} }

View File

@ -42,6 +42,7 @@ public class StartupRoutingCommand extends StartupCommand {
return host; return host;
} }
} }
Integer cpuSockets;
int cpus; int cpus;
long speed; long speed;
long memory; long memory;
@ -133,6 +134,10 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr
_clusterVMStates = allStates; _clusterVMStates = allStates;
} }
public Integer getCpuSockets() {
return cpuSockets;
}
public int getCpus() { public int getCpus() {
return cpus; return cpus;
} }
@ -165,6 +170,10 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr
this.speed = speed; this.speed = speed;
} }
public void setCpuSockets(Integer cpuSockets) {
this.cpuSockets = cpuSockets;
}
public void setCpus(int cpus) { public void setCpus(int cpus) {
this.cpus = cpus; this.cpus = cpus;
} }

View File

@ -86,6 +86,10 @@ public class CheckOnHostCommandTest {
public Long getTotalMemory() { public Long getTotalMemory() {
return 100000000000L; return 100000000000L;
}
public Integer getCpuSockets() {
return 1;
}; };
public Integer getCpus() { public Integer getCpus() {
@ -289,6 +293,12 @@ public class CheckOnHostCommandTest {
assertTrue(m == 100000000000L); assertTrue(m == 100000000000L);
} }
@Test
public void testGetCpuSockets() {
Integer cpuSockets = host.getCpuSockets();
assertTrue(cpuSockets == 1);
}
@Test @Test
public void testGetCpus() { public void testGetCpus() {
int cpus = host.getCpus(); int cpus = host.getCpus();

View File

@ -325,6 +325,9 @@ public class EngineHostVO implements EngineHost, Identity {
@Column(name="pod_id") @Column(name="pod_id")
private Long podId; private Long podId;
@Column(name="cpu_sockets")
private Integer cpuSockets;
@Column(name="cpus") @Column(name="cpus")
private Integer cpus; private Integer cpus;
@ -648,6 +651,11 @@ public class EngineHostVO implements EngineHost, Identity {
this.guid = guid; this.guid = guid;
} }
@Override
public Integer getCpuSockets() {
return cpuSockets;
}
@Override @Override
public Integer getCpus() { public Integer getCpus() {
return cpus; return cpus;

View File

@ -321,6 +321,9 @@ public class HostVO implements Host {
@Column(name="pod_id") @Column(name="pod_id")
private Long podId; private Long podId;
@Column(name="cpu_sockets")
private Integer cpuSockets;
@Column(name="cpus") @Column(name="cpus")
private Integer cpus; private Integer cpus;
@ -501,6 +504,10 @@ public class HostVO implements Host {
this.privateIpAddress = ipAddress; this.privateIpAddress = ipAddress;
} }
public void setCpuSockets(Integer cpuSockets) {
this.cpuSockets = cpuSockets;
}
public void setCpus(Integer cpus) { public void setCpus(Integer cpus) {
this.cpus = cpus; this.cpus = cpus;
} }
@ -621,6 +628,11 @@ public class HostVO implements Host {
this.guid = guid; this.guid = guid;
} }
@Override
public Integer getCpuSockets() {
return cpuSockets;
}
@Override @Override
public Integer getCpus() { public Integer getCpus() {
return cpus; return cpus;

View File

@ -3986,6 +3986,7 @@ ServerResource {
(Long) info.get(4), (String) info.get(3), _hypervisorType, (Long) info.get(4), (String) info.get(3), _hypervisorType,
RouterPrivateIpStrategy.HostLocal); RouterPrivateIpStrategy.HostLocal);
cmd.setStateChanges(changes); cmd.setStateChanges(changes);
cmd.setCpuSockets((Integer)info.get(5));
fillNetworkInformation(cmd); fillNetworkInformation(cmd);
_privateIp = cmd.getPrivateIpAddress(); _privateIp = cmd.getPrivateIpAddress();
cmd.getHostDetails().putAll(getVersionStrings()); cmd.getHostDetails().putAll(getVersionStrings());
@ -4311,6 +4312,7 @@ ServerResource {
long speed = 0; long speed = 0;
long cpus = 0; long cpus = 0;
long ram = 0; long ram = 0;
int cpuSockets = 0;
String cap = null; String cap = null;
try { try {
Connect conn = LibvirtConnection.getConnection(); Connect conn = LibvirtConnection.getConnection();
@ -4334,6 +4336,7 @@ ServerResource {
speed = hosts.mhz; speed = hosts.mhz;
} }
cpuSockets = hosts.sockets;
cpus = hosts.cpus; cpus = hosts.cpus;
ram = hosts.memory * 1024L; ram = hosts.memory * 1024L;
LibvirtCapXMLParser parser = new LibvirtCapXMLParser(); LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
@ -4366,8 +4369,9 @@ ServerResource {
// 768M // 768M
dom0ram = Math.max(dom0ram, _dom0MinMem); dom0ram = Math.max(dom0ram, _dom0MinMem);
info.add(dom0ram); info.add(dom0ram);
info.add(cpuSockets);
s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram
+ ", dom0ram=" + dom0ram); + ", dom0ram=" + dom0ram + ", cpu sockets=" + cpuSockets);
return info; return info;
} }

View File

@ -6040,6 +6040,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
cmd.setCaps("hvm"); cmd.setCaps("hvm");
cmd.setDom0MinMemory(0); cmd.setDom0MinMemory(0);
cmd.setSpeed(summary.getCpuSpeed()); cmd.setSpeed(summary.getCpuSpeed());
cmd.setCpuSockets(summary.getCpuSockets());
cmd.setCpus((int) summary.getCpuCount()); cmd.setCpus((int) summary.getCpuCount());
cmd.setMemory(summary.getMemoryBytes()); cmd.setMemory(summary.getMemoryBytes());
} }

View File

@ -4829,7 +4829,10 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
if (_host.cpus <= 0) { if (_host.cpus <= 0) {
throw new CloudRuntimeException("Cannot get the numbers of cpu from XenServer host " + _host.ip); throw new CloudRuntimeException("Cannot get the numbers of cpu from XenServer host " + _host.ip);
} }
Map<String, String> cpuInfo = myself.getCpuInfo(conn);
if (cpuInfo.get("socket_count") != null) {
_host.cpuSockets = Integer.parseInt(cpuInfo.get("socket_count"));
}
for (final HostCpu hc : hcs) { for (final HostCpu hc : hcs) {
_host.speed = hc.getSpeed(conn).intValue(); _host.speed = hc.getSpeed(conn).intValue();
break; break;
@ -5974,6 +5977,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
cmd.setCaps(caps.toString()); cmd.setCaps(caps.toString());
cmd.setSpeed(_host.speed); cmd.setSpeed(_host.speed);
cmd.setCpuSockets(_host.cpuSockets);
cmd.setCpus(_host.cpus); cmd.setCpus(_host.cpus);
HostMetrics hm = host.getMetrics(conn); HostMetrics hm = host.getMetrics(conn);
@ -8074,6 +8078,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
public String storagePif2; public String storagePif2;
public String pool; public String pool;
public int speed; public int speed;
public Integer cpuSockets;
public int cpus; public int cpus;
public String product_version; public String product_version;
public String localSRuuid; public String localSRuuid;

View File

@ -26,6 +26,7 @@ import java.util.Set;
import javax.ejb.Local; import javax.ejb.Local;
import javax.inject.Inject; import javax.inject.Inject;
import com.cloud.hypervisor.Hypervisor;
import org.apache.cloudstack.acl.ControlledEntity.ACLType; import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO; import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
import org.apache.cloudstack.affinity.AffinityGroupResponse; import org.apache.cloudstack.affinity.AffinityGroupResponse;
@ -1530,6 +1531,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
Object haHosts = cmd.getHaHost(); Object haHosts = cmd.getHaHost();
Long startIndex = cmd.getStartIndex(); Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal(); Long pageSize = cmd.getPageSizeVal();
Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize); Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
@ -1544,6 +1546,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ); sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ); sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ); sb.and("resourceState", sb.entity().getResourceState(), SearchCriteria.Op.EQ);
sb.and("hypervisor_type", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
String haTag = _haMgr.getHaTag(); String haTag = _haMgr.getHaTag();
if (haHosts != null && haTag != null && !haTag.isEmpty()) { if (haHosts != null && haTag != null && !haTag.isEmpty()) {
@ -1599,6 +1602,9 @@ public class QueryManagerImpl extends ManagerBase implements QueryService {
sc.setParameters("tag", haTag); sc.setParameters("tag", haTag);
} }
if (hypervisorType != HypervisorType.None && hypervisorType != HypervisorType.Any) {
sc.setParameters("hypervisor_type", hypervisorType);
}
// search host details by ids // search host details by ids
Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter); Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
Integer count = uniqueHostPair.second(); Integer count = uniqueHostPair.second();

View File

@ -78,6 +78,7 @@ public class HostJoinDaoImpl extends GenericDaoBase<HostJoinVO, Long> implements
hostResponse.setId(host.getUuid()); hostResponse.setId(host.getUuid());
hostResponse.setCapabilities(host.getCapabilities()); hostResponse.setCapabilities(host.getCapabilities());
hostResponse.setClusterId(host.getClusterUuid()); hostResponse.setClusterId(host.getClusterUuid());
hostResponse.setCpuSockets(host.getCpuSockets());
hostResponse.setCpuNumber(host.getCpus()); hostResponse.setCpuNumber(host.getCpus());
hostResponse.setZoneId(host.getZoneUuid()); hostResponse.setZoneId(host.getZoneUuid());
hostResponse.setDisconnectedOn(host.getDisconnectedOn()); hostResponse.setDisconnectedOn(host.getDisconnectedOn());

View File

@ -98,6 +98,9 @@ public class HostJoinVO extends BaseViewVO implements InternalIdentity, Identity
@Column(name="mgmt_server_id") @Column(name="mgmt_server_id")
private Long managementServerId; private Long managementServerId;
@Column(name="cpu_sockets")
private Integer cpuSockets;
@Column(name="cpus") @Column(name="cpus")
private Integer cpus; private Integer cpus;
@ -249,6 +252,10 @@ public class HostJoinVO extends BaseViewVO implements InternalIdentity, Identity
return managementServerId; return managementServerId;
} }
public Integer getCpuSockets() {
return cpuSockets;
}
public Integer getCpus() { public Integer getCpus() {
return cpus; return cpus;
} }

View File

@ -1926,6 +1926,7 @@ public class ResourceManagerImpl extends ManagerBase implements ResourceManager,
host.setType(com.cloud.host.Host.Type.Routing); host.setType(com.cloud.host.Host.Type.Routing);
host.setDetails(details); host.setDetails(details);
host.setCaps(ssCmd.getCapabilities()); host.setCaps(ssCmd.getCapabilities());
host.setCpuSockets(ssCmd.getCpuSockets());
host.setCpus(ssCmd.getCpus()); host.setCpus(ssCmd.getCpus());
host.setTotalMemory(ssCmd.getMemory()); host.setTotalMemory(ssCmd.getMemory());
host.setSpeed(ssCmd.getSpeed()); host.setSpeed(ssCmd.getSpeed());

View File

@ -461,6 +461,80 @@ CREATE VIEW `cloud`.`storage_pool_view` AS
and async_job.instance_type = 'StoragePool' and async_job.instance_type = 'StoragePool'
and async_job.job_status = 0; and async_job.job_status = 0;
ALTER TABLE `cloud`.`host` ADD COLUMN `cpu_sockets` int(10) unsigned DEFAULT NULL COMMENT "the number of CPU sockets on the host" AFTER pod_id;
DROP VIEW IF EXISTS `cloud`.`host_view`;
CREATE VIEW `cloud`.`host_view` AS
select
host.id,
host.uuid,
host.name,
host.status,
host.disconnected,
host.type,
host.private_ip_address,
host.version,
host.hypervisor_type,
host.hypervisor_version,
host.capabilities,
host.last_ping,
host.created,
host.removed,
host.resource_state,
host.mgmt_server_id,
host.cpu_sockets,
host.cpus,
host.speed,
host.ram,
cluster.id cluster_id,
cluster.uuid cluster_uuid,
cluster.name cluster_name,
cluster.cluster_type,
data_center.id data_center_id,
data_center.uuid data_center_uuid,
data_center.name data_center_name,
data_center.networktype data_center_type,
host_pod_ref.id pod_id,
host_pod_ref.uuid pod_uuid,
host_pod_ref.name pod_name,
host_tags.tag,
guest_os_category.id guest_os_category_id,
guest_os_category.uuid guest_os_category_uuid,
guest_os_category.name guest_os_category_name,
mem_caps.used_capacity memory_used_capacity,
mem_caps.reserved_capacity memory_reserved_capacity,
cpu_caps.used_capacity cpu_used_capacity,
cpu_caps.reserved_capacity cpu_reserved_capacity,
async_job.id job_id,
async_job.uuid job_uuid,
async_job.job_status job_status,
async_job.account_id job_account_id
from
`cloud`.`host`
left join
`cloud`.`cluster` ON host.cluster_id = cluster.id
left join
`cloud`.`data_center` ON host.data_center_id = data_center.id
left join
`cloud`.`host_pod_ref` ON host.pod_id = host_pod_ref.id
left join
`cloud`.`host_details` ON host.id = host_details.host_id
and host_details.name = 'guest.os.category.id'
left join
`cloud`.`guest_os_category` ON guest_os_category.id = CONVERT( host_details.value , UNSIGNED)
left join
`cloud`.`host_tags` ON host_tags.host_id = host.id
left join
`cloud`.`op_host_capacity` mem_caps ON host.id = mem_caps.host_id
and mem_caps.capacity_type = 0
left join
`cloud`.`op_host_capacity` cpu_caps ON host.id = cpu_caps.host_id
and cpu_caps.capacity_type = 1
left join
`cloud`.`async_job` ON async_job.instance_id = host.id
and async_job.instance_type = 'Host'
and async_job.job_status = 0;
CREATE TABLE `cloud`.`firewall_rule_details` ( CREATE TABLE `cloud`.`firewall_rule_details` (
`id` bigint unsigned NOT NULL auto_increment, `id` bigint unsigned NOT NULL auto_increment,
`firewall_rule_id` bigint unsigned NOT NULL COMMENT 'Firewall rule id', `firewall_rule_id` bigint unsigned NOT NULL COMMENT 'Firewall rule id',

View File

@ -913,6 +913,7 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
summary.setCpuCount(hardwareSummary.getNumCpuThreads()); summary.setCpuCount(hardwareSummary.getNumCpuThreads());
summary.setMemoryBytes(hardwareSummary.getMemorySize()); summary.setMemoryBytes(hardwareSummary.getMemorySize());
summary.setCpuSpeed(hardwareSummary.getCpuMhz()); summary.setCpuSpeed(hardwareSummary.getCpuMhz());
summary.setCpuSockets((int)hardwareSummary.getNumCpuPkgs());
if(s_logger.isTraceEnabled()) if(s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done"); s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done");

View File

@ -21,7 +21,6 @@ import com.vmware.vim25.ComputeResourceSummary;
import com.vmware.vim25.ManagedObjectReference; import com.vmware.vim25.ManagedObjectReference;
import com.vmware.vim25.ObjectContent; import com.vmware.vim25.ObjectContent;
import com.vmware.vim25.VirtualMachineConfigSpec; import com.vmware.vim25.VirtualMachineConfigSpec;
import com.cloud.hypervisor.vmware.util.VmwareContext; import com.cloud.hypervisor.vmware.util.VmwareContext;
/** /**

View File

@ -20,6 +20,7 @@ public class VmwareHypervisorHostResourceSummary {
private long memoryBytes; private long memoryBytes;
private long cpuCount; private long cpuCount;
private long cpuSpeed; private long cpuSpeed;
private Integer cpuSockets;
public VmwareHypervisorHostResourceSummary() { public VmwareHypervisorHostResourceSummary() {
} }
@ -47,4 +48,12 @@ public class VmwareHypervisorHostResourceSummary {
public void setCpuSpeed(long cpuSpeed) { public void setCpuSpeed(long cpuSpeed) {
this.cpuSpeed = cpuSpeed; this.cpuSpeed = cpuSpeed;
} }
public Integer getCpuSockets() {
return cpuSockets;
}
public void setCpuSockets(Integer cpuSockets) {
this.cpuSockets = cpuSockets;
}
} }