mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10848: ListCapacity - Full rework. This fixes the pagination logic and the capacities are visible till the cluster level.
This commit is contained in:
parent
cfebce78b0
commit
9c20c1b1b6
@ -1,97 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.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.api.commands;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.response.CapacityResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.capacity.Capacity;
|
||||
|
||||
@Implementation(description="Lists capacity By Type.", responseObject=CapacityResponse.class)
|
||||
public class ListCapacityByTypeCmd extends BaseListCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName());
|
||||
private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##");
|
||||
|
||||
private static final String s_name = "listcapacityresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, required=true, description="lists capacity by type")
|
||||
private Integer type;
|
||||
|
||||
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
|
||||
private Long clusterId;
|
||||
|
||||
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
|
||||
private Long podId;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="lists capacity by the Zone ID")
|
||||
private Long zoneId;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public Long getPodId() {
|
||||
return podId;
|
||||
}
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends Capacity> result = _mgr.listCapacityByType(this);
|
||||
ListResponse<CapacityResponse> response = new ListResponse<CapacityResponse>();
|
||||
List<CapacityResponse> capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat);
|
||||
response.setResponses(capacityResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.CapacityResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.capacity.Capacity;
|
||||
@ -42,12 +43,15 @@ public class ListCapacityCmd extends BaseListCmd {
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.LONG, description="lists capacity by the Host ID")
|
||||
private Long hostId;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="lists capacity by the Zone ID")
|
||||
private Long zoneId;
|
||||
|
||||
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
|
||||
private Long podId;
|
||||
|
||||
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
|
||||
private Long clusterId;
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +
|
||||
"* CAPACITY_TYPE_MEMORY = 0" +
|
||||
@ -60,29 +64,26 @@ public class ListCapacityCmd extends BaseListCmd {
|
||||
|
||||
private Integer type;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
|
||||
private Long zoneId;
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public Long getHostId() {
|
||||
return hostId;
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
|
||||
public Long getPodId() {
|
||||
return podId;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
public Long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
|
||||
@ -34,7 +34,6 @@ import com.cloud.api.commands.ListAccountsCmd;
|
||||
import com.cloud.api.commands.ListAlertsCmd;
|
||||
import com.cloud.api.commands.ListAsyncJobsCmd;
|
||||
import com.cloud.api.commands.ListCapabilitiesCmd;
|
||||
import com.cloud.api.commands.ListCapacityByTypeCmd;
|
||||
import com.cloud.api.commands.ListCapacityCmd;
|
||||
import com.cloud.api.commands.ListCfgsByCmd;
|
||||
import com.cloud.api.commands.ListClustersCmd;
|
||||
@ -278,14 +277,6 @@ public interface ManagementService {
|
||||
*/
|
||||
List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
|
||||
|
||||
/**
|
||||
* lists the capacity rows in capacity operations table
|
||||
*
|
||||
* @param cmd
|
||||
* @return List of capacities
|
||||
*/
|
||||
List<? extends Capacity> listCapacityByType(ListCapacityByTypeCmd cmd);
|
||||
|
||||
/**
|
||||
* List the permissions on a template. This will return a list of account names that have been granted permission to launch
|
||||
* instances from the template.
|
||||
|
||||
@ -242,7 +242,7 @@ public class AlertManagerImpl implements AlertManager {
|
||||
s_logger.trace("recalculating system capacity");
|
||||
}
|
||||
|
||||
// Calculate CPU and RAM capacitites
|
||||
// Calculate CPU and RAM capacities
|
||||
// get all hosts...even if they are not in 'UP' state
|
||||
List<HostVO> hosts = _hostDao.listByType(Host.Type.Routing);
|
||||
for (HostVO host : hosts) {
|
||||
@ -458,6 +458,11 @@ public class AlertManagerImpl implements AlertManager {
|
||||
s_logger.error("Exception in CapacityChecker", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void newAlertSystem(){
|
||||
|
||||
}
|
||||
|
||||
class EmailAlert {
|
||||
|
||||
@ -1869,8 +1869,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
@Override
|
||||
public List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format) {
|
||||
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
|
||||
List<CapacityVO> summedCapacities = sumCapacities(result);
|
||||
for (CapacityVO summedCapacity : summedCapacities) {
|
||||
//List<CapacityVO> summedCapacities = sumCapacities(result);
|
||||
for (Capacity summedCapacity : result) {
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity());
|
||||
capacityResponse.setCapacityType(summedCapacity.getCapacityType());
|
||||
|
||||
@ -28,10 +28,9 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
|
||||
CapacityVO findByHostIdType(Long hostId, short capacityType);
|
||||
List<Long> listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor);
|
||||
List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor);
|
||||
List<SummedCapacity> findCapacityByType(Integer capacityType, Long zoneId, Long podId,
|
||||
Long clusterId, Long startIndex, Long pageSize);
|
||||
boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId);
|
||||
List<SummedCapacity> findByClusterPodZone(Long zoneId, Long podId, Long clusterId);
|
||||
List<SummedCapacity> findNonSharedStorageForClusterPodZone(Long zoneId,Long podId, Long clusterId);
|
||||
List<Long> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor);
|
||||
List<Long> orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor);
|
||||
List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId);
|
||||
}
|
||||
|
||||
@ -94,16 +94,16 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SummedCapacity> findCapacityByType(Integer capacityType, Long zoneId, Long podId, Long clusterId, Long startIndex, Long pageSize){
|
||||
public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId){
|
||||
|
||||
SummedCapacitySearch = createSearchBuilder(SummedCapacity.class);
|
||||
SummedCapacitySearch.select("sumUsed", Func.SUM, SummedCapacitySearch.entity().getUsedCapacity());
|
||||
SummedCapacitySearch.select("sumReserved", Func.SUM, SummedCapacitySearch.entity().getReservedCapacity());
|
||||
SummedCapacitySearch.select("sumTotal", Func.SUM, SummedCapacitySearch.entity().getTotalCapacity());
|
||||
SummedCapacitySearch.select("clusterId", Func.NATIVE, SummedCapacitySearch.entity().getClusterId());
|
||||
SummedCapacitySearch.select("podId", Func.NATIVE, SummedCapacitySearch.entity().getPodId());
|
||||
SummedCapacitySearch.select("capacityType", Func.SUM, SummedCapacitySearch.entity().getCapacityType());
|
||||
|
||||
SummedCapacitySearch.and("dcId", SummedCapacitySearch.entity().getDataCenterId(), Op.EQ);
|
||||
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getClusterId(), SummedCapacitySearch.entity().getCapacityType());
|
||||
SummedCapacitySearch.groupBy(SummedCapacitySearch.entity().getCapacityType());
|
||||
|
||||
if (podId != null){
|
||||
SummedCapacitySearch.and("podId", SummedCapacitySearch.entity().getPodId(), Op.EQ);
|
||||
@ -130,7 +130,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
sc.setParameters("capacityType", capacityType);
|
||||
}
|
||||
|
||||
Filter filter = new Filter(CapacityVO.class, null, true, startIndex, pageSize);
|
||||
Filter filter = new Filter(CapacityVO.class, null, true, null, null);
|
||||
List<SummedCapacity> results = customSearchIncludingRemoved(sc, filter);
|
||||
return results;
|
||||
|
||||
@ -242,6 +242,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
|
||||
public static class SummedCapacity {
|
||||
public long sumUsed;
|
||||
public long sumReserved;
|
||||
public long sumTotal;
|
||||
public short capacityType;
|
||||
public long clusterId;
|
||||
@ -254,6 +255,9 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
public Long getUsedCapacity() {
|
||||
return sumUsed;
|
||||
}
|
||||
public long getSumReserved() {
|
||||
return sumReserved;
|
||||
}
|
||||
public Long getTotalCapacity() {
|
||||
return sumTotal;
|
||||
}
|
||||
|
||||
@ -67,7 +67,6 @@ import com.cloud.api.commands.ListAccountsCmd;
|
||||
import com.cloud.api.commands.ListAlertsCmd;
|
||||
import com.cloud.api.commands.ListAsyncJobsCmd;
|
||||
import com.cloud.api.commands.ListCapabilitiesCmd;
|
||||
import com.cloud.api.commands.ListCapacityByTypeCmd;
|
||||
import com.cloud.api.commands.ListCapacityCmd;
|
||||
import com.cloud.api.commands.ListCfgsByCmd;
|
||||
import com.cloud.api.commands.ListClustersCmd;
|
||||
@ -2461,55 +2460,32 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
|
||||
return _alertDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CapacityVO> listCapacityByType(ListCapacityByTypeCmd cmd) {
|
||||
|
||||
List<SummedCapacity> results = _capacityDao.findCapacityByType(cmd.getType(), cmd.getZoneId(), cmd.getPodId(), cmd.getClusterId(), cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
for (SummedCapacity sum : results){
|
||||
s_logger.info("Total - " +sum.sumTotal+ " Used - " +sum.sumUsed+ " cluster " +sum.clusterId+ " pod " +sum.podId);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CapacityVO> listCapacities(ListCapacityCmd cmd) {
|
||||
|
||||
Filter searchFilter = new Filter(CapacityVO.class, "capacityType", true, null, null);
|
||||
SearchCriteria<CapacityVO> sc = _capacityDao.createSearchCriteria();
|
||||
List<CapacityVO> capacities = new LinkedList<CapacityVO>();
|
||||
|
||||
Integer type = cmd.getType();
|
||||
Integer capacityType = cmd.getType();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
Long podId = cmd.getPodId();
|
||||
Long hostId = cmd.getHostId();
|
||||
Long clusterId = cmd.getClusterId();
|
||||
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
|
||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||
|
||||
if (type != null) {
|
||||
sc.addAnd("capacityType", SearchCriteria.Op.EQ, type);
|
||||
}
|
||||
for (SummedCapacity summedCapacity : summedCapacities){
|
||||
CapacityVO capacity = new CapacityVO(null, zoneId, podId, clusterId,
|
||||
summedCapacity.getUsedCapacity(), summedCapacity.getTotalCapacity(), summedCapacity.getCapacityType());
|
||||
|
||||
if (zoneId != null) {
|
||||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
|
||||
capacities.add(capacity);
|
||||
}
|
||||
|
||||
if (podId != null) {
|
||||
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
|
||||
}
|
||||
|
||||
if (hostId != null) {
|
||||
sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
|
||||
}
|
||||
capacities = _capacityDao.search(sc, searchFilter);
|
||||
|
||||
// op_host_Capacity contains only allocated stats and the real time stats are stored "in memory".
|
||||
if (type == null || type == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
|
||||
capacities.addAll(_storageMgr.getSecondaryStorageUsedStats(hostId, podId, zoneId));
|
||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
|
||||
capacities.addAll(_storageMgr.getSecondaryStorageUsedStats(null, podId, zoneId));
|
||||
}
|
||||
if (type == null || type == Capacity.CAPACITY_TYPE_STORAGE) {
|
||||
capacities.addAll(_storageMgr.getStoragePoolUsedStats(hostId, podId, zoneId));
|
||||
if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_STORAGE) {
|
||||
capacities.addAll(_storageMgr.getStoragePoolUsedStats(null, podId, zoneId));
|
||||
}
|
||||
|
||||
return capacities;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user