diff --git a/api/src/com/cloud/api/commands/ListCapacityByTypeCmd.java b/api/src/com/cloud/api/commands/ListCapacityByTypeCmd.java deleted file mode 100755 index 9b1efc094ae..00000000000 --- a/api/src/com/cloud/api/commands/ListCapacityByTypeCmd.java +++ /dev/null @@ -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 . - * - */ - -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 result = _mgr.listCapacityByType(this); - ListResponse response = new ListResponse(); - List capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat); - response.setResponses(capacityResponses); - response.setResponseName(getCommandName()); - this.setResponseObject(response); - } -} diff --git a/api/src/com/cloud/api/commands/ListCapacityCmd.java b/api/src/com/cloud/api/commands/ListCapacityCmd.java index 916523299f0..ba904ba0018 100755 --- a/api/src/com/cloud/api/commands/ListCapacityCmd.java +++ b/api/src/com/cloud/api/commands/ListCapacityCmd.java @@ -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/////////////////// diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 96848d11321..cc375e6e70b 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -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 listCapacities(ListCapacityCmd cmd); - /** - * lists the capacity rows in capacity operations table - * - * @param cmd - * @return List of capacities - */ - List 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. diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 2bc5b6c8deb..1eda52d11f4 100755 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -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 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 { diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 4aa0a0c0c7c..ed28ae784b4 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -1869,8 +1869,8 @@ public class ApiResponseHelper implements ResponseGenerator { @Override public List createCapacityResponse(List result, DecimalFormat format) { List capacityResponses = new ArrayList(); - List summedCapacities = sumCapacities(result); - for (CapacityVO summedCapacity : summedCapacities) { + //List summedCapacities = sumCapacities(result); + for (Capacity summedCapacity : result) { CapacityResponse capacityResponse = new CapacityResponse(); capacityResponse.setCapacityTotal(summedCapacity.getTotalCapacity()); capacityResponse.setCapacityType(summedCapacity.getCapacityType()); diff --git a/server/src/com/cloud/capacity/dao/CapacityDao.java b/server/src/com/cloud/capacity/dao/CapacityDao.java index 265afb67541..9d65fc95b37 100755 --- a/server/src/com/cloud/capacity/dao/CapacityDao.java +++ b/server/src/com/cloud/capacity/dao/CapacityDao.java @@ -28,10 +28,9 @@ public interface CapacityDao extends GenericDao { CapacityVO findByHostIdType(Long hostId, short capacityType); List listClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor); List listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor); - List findCapacityByType(Integer capacityType, Long zoneId, Long podId, - Long clusterId, Long startIndex, Long pageSize); boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId); List findByClusterPodZone(Long zoneId, Long podId, Long clusterId); List findNonSharedStorageForClusterPodZone(Long zoneId,Long podId, Long clusterId); - List orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor); + List orderClustersByAggregateCapacity(long id, short capacityType, boolean isZone, float cpuOverprovisioningFactor); + List findCapacityBy(Integer capacityType, Long zoneId, Long podId, Long clusterId); } diff --git a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java index d6e62d92306..c96f76aee8f 100755 --- a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -94,16 +94,16 @@ public class CapacityDaoImpl extends GenericDaoBase implements } @Override - public List findCapacityByType(Integer capacityType, Long zoneId, Long podId, Long clusterId, Long startIndex, Long pageSize){ + public List 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 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 results = customSearchIncludingRemoved(sc, filter); return results; @@ -242,6 +242,7 @@ public class CapacityDaoImpl extends GenericDaoBase 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 implements public Long getUsedCapacity() { return sumUsed; } + public long getSumReserved() { + return sumReserved; + } public Long getTotalCapacity() { return sumTotal; } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index e0a875c1a3f..a484d4f611f 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -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 listCapacityByType(ListCapacityByTypeCmd cmd) { - - List 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 listCapacities(ListCapacityCmd cmd) { - Filter searchFilter = new Filter(CapacityVO.class, "capacityType", true, null, null); - SearchCriteria sc = _capacityDao.createSearchCriteria(); - List capacities = new LinkedList(); - - 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 summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId); + List capacities = new ArrayList(); - 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;