use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.
the class MetricsServiceImpl method listZoneMetrics.
@Override
public List<ZoneMetricsResponse> listZoneMetrics(List<ZoneResponse> zoneResponses) {
final List<ZoneMetricsResponse> metricsResponses = new ArrayList<>();
for (final ZoneResponse zoneResponse : zoneResponses) {
ZoneMetricsResponse metricsResponse = new ZoneMetricsResponse();
try {
BeanUtils.copyProperties(metricsResponse, zoneResponse);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate zone metrics response");
}
final DataCenter zone = dataCenterDao.findByUuid(zoneResponse.getId());
if (zone == null) {
continue;
}
final Long zoneId = zone.getId();
// Thresholds
final Double cpuThreshold = AlertManager.CPUCapacityThreshold.value();
final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.value();
final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.value();
final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.value();
// CPU and memory capacities
final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, zoneId, null);
final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, zoneId, null);
final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
for (final Cluster cluster : clusterDao.listClustersByDcId(zoneId)) {
metrics.incrTotalResources();
if (cluster.getAllocationState() == Grouping.AllocationState.Enabled && cluster.getManagedState() == Managed.ManagedState.Managed) {
metrics.incrUpResources();
}
for (final HostJoinVO host : hostJoinDao.findByClusterId(cluster.getId(), Host.Type.Routing)) {
updateHostMetrics(metrics, host);
}
}
metricsResponse.setState(zoneResponse.getAllocationState());
metricsResponse.setResource(metrics.getUpResources(), metrics.getTotalResources());
// CPU
metricsResponse.setCpuTotal(metrics.getTotalCpu());
metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), metrics.getTotalCpu());
if (metrics.getCpuUsedPercentage() > 0L) {
metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
}
// Memory
metricsResponse.setMemTotal(metrics.getTotalMemory());
metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), metrics.getTotalMemory());
if (metrics.getMemoryUsed() > 0L) {
metricsResponse.setMemUsed(metrics.getMemoryUsed(), metrics.getTotalMemory());
metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), metrics.getMemoryUsed(), metrics.getTotalHosts());
}
// CPU thresholds
metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuThreshold);
metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuDisableThreshold);
// Memory thresholds
metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryThreshold);
metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryDisableThreshold);
metricsResponses.add(metricsResponse);
}
return metricsResponses;
}
use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.
the class ViewResponseHelper method createHostForMigrationResponse.
public static List<HostForMigrationResponse> createHostForMigrationResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
Hashtable<Long, HostForMigrationResponse> vrDataList = new Hashtable<Long, HostForMigrationResponse>();
// Initialise the vrdatalist with the input data
for (HostJoinVO vr : hosts) {
HostForMigrationResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this vm
vrData = ApiDBUtils.newHostForMigrationResponse(vr, details);
} else {
// update tags
vrData = ApiDBUtils.fillHostForMigrationDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<HostForMigrationResponse>(vrDataList.values());
}
use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.
the class ViewResponseHelper method createHostResponse.
public static List<HostResponse> createHostResponse(EnumSet<HostDetails> details, HostJoinVO... hosts) {
Hashtable<Long, HostResponse> vrDataList = new Hashtable<Long, HostResponse>();
// Initialise the vrdatalist with the input data
for (HostJoinVO vr : hosts) {
HostResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this vm
vrData = ApiDBUtils.newHostResponse(vr, details);
} else {
// update tags
vrData = ApiDBUtils.fillHostDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<HostResponse>(vrDataList.values());
}
use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.
the class MetricsServiceImpl method listClusterMetrics.
@Override
public List<ClusterMetricsResponse> listClusterMetrics(List<ClusterResponse> clusterResponses) {
final List<ClusterMetricsResponse> metricsResponses = new ArrayList<>();
for (final ClusterResponse clusterResponse : clusterResponses) {
ClusterMetricsResponse metricsResponse = new ClusterMetricsResponse();
try {
BeanUtils.copyProperties(metricsResponse, clusterResponse);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to generate cluster metrics response");
}
final Cluster cluster = clusterDao.findByUuid(clusterResponse.getId());
if (cluster == null) {
continue;
}
final Long clusterId = cluster.getId();
// Thresholds
final Double cpuThreshold = AlertManager.CPUCapacityThreshold.valueIn(clusterId);
final Double memoryThreshold = AlertManager.MemoryCapacityThreshold.valueIn(clusterId);
final Float cpuDisableThreshold = DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.valueIn(clusterId);
final Float memoryDisableThreshold = DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.valueIn(clusterId);
final Double cpuOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "cpuOvercommitRatio"));
final Double memoryOvercommitRatio = findRatioValue(ApiDBUtils.findClusterDetails(clusterId, "memoryOvercommitRatio"));
// CPU and memory capacities
final CapacityDaoImpl.SummedCapacity cpuCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_CPU, null, clusterId);
final CapacityDaoImpl.SummedCapacity memoryCapacity = getCapacity((int) Capacity.CAPACITY_TYPE_MEMORY, null, clusterId);
final Metrics metrics = new Metrics(cpuCapacity, memoryCapacity);
for (final HostJoinVO host : hostJoinDao.findByClusterId(clusterId, Host.Type.Routing)) {
if (host.getStatus() == Status.Up) {
metrics.incrUpResources();
}
metrics.incrTotalResources();
updateHostMetrics(metrics, host);
}
metricsResponse.setState(clusterResponse.getAllocationState(), clusterResponse.getManagedState());
metricsResponse.setResources(metrics.getUpResources(), metrics.getTotalResources());
// CPU
metricsResponse.setCpuTotal(metrics.getTotalCpu());
metricsResponse.setCpuAllocated(metrics.getCpuAllocated(), metrics.getTotalCpu());
if (metrics.getCpuUsedPercentage() > 0L) {
metricsResponse.setCpuUsed(metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
metricsResponse.setCpuMaxDeviation(metrics.getMaximumCpuUsage(), metrics.getCpuUsedPercentage(), metrics.getTotalHosts());
}
// Memory
metricsResponse.setMemTotal(metrics.getTotalMemory());
metricsResponse.setMemAllocated(metrics.getMemoryAllocated(), metrics.getTotalMemory());
if (metrics.getMemoryUsed() > 0L) {
metricsResponse.setMemUsed(metrics.getMemoryUsed(), metrics.getTotalMemory());
metricsResponse.setMemMaxDeviation(metrics.getMaximumMemoryUsage(), metrics.getMemoryUsed(), metrics.getTotalHosts());
}
// CPU thresholds
metricsResponse.setCpuUsageThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuThreshold);
metricsResponse.setCpuUsageDisableThreshold(metrics.getCpuUsedPercentage(), metrics.getTotalHosts(), cpuDisableThreshold);
metricsResponse.setCpuAllocatedThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuThreshold);
metricsResponse.setCpuAllocatedDisableThreshold(metrics.getCpuAllocated(), metrics.getTotalCpu(), cpuOvercommitRatio, cpuDisableThreshold);
// Memory thresholds
metricsResponse.setMemoryUsageThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryThreshold);
metricsResponse.setMemoryUsageDisableThreshold(metrics.getMemoryUsed(), metrics.getTotalMemory(), memoryDisableThreshold);
metricsResponse.setMemoryAllocatedThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryThreshold);
metricsResponse.setMemoryAllocatedDisableThreshold(metrics.getMemoryAllocated(), metrics.getTotalMemory(), memoryOvercommitRatio, memoryDisableThreshold);
metricsResponses.add(metricsResponse);
}
return metricsResponses;
}
use of com.cloud.api.query.vo.HostJoinVO in project cloudstack by apache.
the class QueryManagerImpl method searchForServersInternal.
public Pair<List<HostJoinVO>, Integer> searchForServersInternal(ListHostsCmd cmd) {
Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object name = cmd.getHostName();
Object type = cmd.getType();
Object state = cmd.getState();
Object pod = cmd.getPodId();
Object cluster = cmd.getClusterId();
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Object outOfBandManagementEnabled = cmd.isOutOfBandManagementEnabled();
Object powerState = cmd.getHostOutOfBandManagementPowerState();
Object resourceState = cmd.getResourceState();
Object haHosts = cmd.getHaHost();
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
Hypervisor.HypervisorType hypervisorType = cmd.getHypervisor();
Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
SearchBuilder<HostJoinVO> sb = _hostJoinDao.createSearchBuilder();
// select distinct
sb.select(null, Func.DISTINCT, sb.entity().getId());
// ids
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.LIKE);
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getZoneId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
sb.and("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
sb.and("oobmEnabled", sb.entity().isOutOfBandManagementEnabled(), SearchCriteria.Op.EQ);
sb.and("powerState", sb.entity().getOutOfBandManagementPowerState(), 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();
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
if ((Boolean) haHosts) {
sb.and("tag", sb.entity().getTag(), SearchCriteria.Op.EQ);
} else {
sb.and().op("tag", sb.entity().getTag(), SearchCriteria.Op.NEQ);
sb.or("tagNull", sb.entity().getTag(), SearchCriteria.Op.NULL);
sb.cp();
}
}
SearchCriteria<HostJoinVO> sc = sb.create();
if (keyword != null) {
SearchCriteria<HostJoinVO> ssc = _hostJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
sc.addAnd("name", SearchCriteria.Op.SC, ssc);
}
if (id != null) {
sc.setParameters("id", id);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");
}
if (type != null) {
sc.setParameters("type", "%" + type);
}
if (state != null) {
sc.setParameters("status", state);
}
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (pod != null) {
sc.setParameters("podId", pod);
}
if (cluster != null) {
sc.setParameters("clusterId", cluster);
}
if (outOfBandManagementEnabled != null) {
sc.setParameters("oobmEnabled", outOfBandManagementEnabled);
}
if (powerState != null) {
sc.setParameters("powerState", powerState);
}
if (resourceState != null) {
sc.setParameters("resourceState", resourceState);
}
if (haHosts != null && haTag != null && !haTag.isEmpty()) {
sc.setParameters("tag", haTag);
}
if (hypervisorType != HypervisorType.None && hypervisorType != HypervisorType.Any) {
sc.setParameters("hypervisor_type", hypervisorType);
}
// search host details by ids
Pair<List<HostJoinVO>, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
Integer count = uniqueHostPair.second();
if (count.intValue() == 0) {
// handle empty result cases
return uniqueHostPair;
}
List<HostJoinVO> uniqueHosts = uniqueHostPair.first();
Long[] hostIds = new Long[uniqueHosts.size()];
int i = 0;
for (HostJoinVO v : uniqueHosts) {
hostIds[i++] = v.getId();
}
List<HostJoinVO> hosts = _hostJoinDao.searchByIds(hostIds);
return new Pair<List<HostJoinVO>, Integer>(hosts, count);
}
Aggregations