From 1fc0afe3f2204d4c1e4df90ceedda3b23dd5cff5 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Wed, 8 Feb 2012 11:50:55 +0530 Subject: [PATCH] Bug 13059: Remove the listTipConsumedResources api and introduced a sortbyusage flag in the listCapacity call. Reviewed-By: Kishan --- api/src/com/cloud/api/ApiConstants.java | 1 + .../cloud/api/commands/ListCapacityCmd.java | 8 +- .../commands/ListTopConsumedResources.java | 122 ------------------ .../com/cloud/server/ManagementService.java | 3 +- .../cloud/server/ManagementServerImpl.java | 8 +- 5 files changed, 13 insertions(+), 129 deletions(-) delete mode 100755 api/src/com/cloud/api/commands/ListTopConsumedResources.java diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 510a743120e..8a4df5bbc3f 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -172,6 +172,7 @@ public class ApiConstants { public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid"; public static final String SNAPSHOT_TYPE = "snapshottype"; public static final String SOURCE_ZONE_ID = "sourcezoneid"; + public static final String SORT_BY_USAGE = "sortbyusage"; public static final String START_DATE = "startdate"; public static final String START_IP = "startip"; public static final String START_PORT = "startport"; diff --git a/api/src/com/cloud/api/commands/ListCapacityCmd.java b/api/src/com/cloud/api/commands/ListCapacityCmd.java index ce4b09564a8..a2551f9bfe1 100755 --- a/api/src/com/cloud/api/commands/ListCapacityCmd.java +++ b/api/src/com/cloud/api/commands/ListCapacityCmd.java @@ -28,7 +28,6 @@ import com.cloud.api.BaseListCmd; import com.cloud.api.IdentityMapper; 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; @@ -60,8 +59,8 @@ public class ListCapacityCmd extends BaseListCmd { @Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities and fetch the latest") private Boolean fetchLatest; - @Parameter(name=ApiConstants.RESOURCE_STATE, type=CommandType.BOOLEAN, description="list capacities by resource state. Resource state represents current state determined by admin of the resource, value can be one of [Enabled, Disabled, Maintenance]") - private Boolean resourceState; + @Parameter(name=ApiConstants.SORT_BY_USAGE, type=CommandType.BOOLEAN, description="if true then lists the top consumed resources at various hierarchy level") + private Boolean sortByUsage; @Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" + "* CAPACITY_TYPE_MEMORY = 0" + @@ -101,6 +100,9 @@ public class ListCapacityCmd extends BaseListCmd { return type; } + public Boolean getSortByUsage() { + return sortByUsage; + } ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// diff --git a/api/src/com/cloud/api/commands/ListTopConsumedResources.java b/api/src/com/cloud/api/commands/ListTopConsumedResources.java deleted file mode 100755 index a26da14e679..00000000000 --- a/api/src/com/cloud/api/commands/ListTopConsumedResources.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Copyright (C) 2011 Citrix Systems, 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.IdentityMapper; -import com.cloud.api.Implementation; -import com.cloud.api.Parameter; -import com.cloud.api.ServerApiException; -import com.cloud.api.BaseCmd.CommandType; -import com.cloud.api.response.CapacityResponse; -import com.cloud.api.response.ListResponse; -import com.cloud.capacity.Capacity; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.NetworkRuleConflictException; -import com.cloud.exception.ResourceAllocationException; -import com.cloud.exception.ResourceUnavailableException; - -@Implementation(description="Lists all the system wide capacities.", responseObject=CapacityResponse.class) -public class ListTopConsumedResources 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 ///////////////////// - ///////////////////////////////////////////////////// - - @IdentityMapper(entityTableName="data_center") - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID") - private Long zoneId; - - @IdentityMapper(entityTableName="host_pod_ref") - @Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID") - private Long podId; - - @IdentityMapper(entityTableName="cluster") - @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" + - "* CAPACITY_TYPE_CPU = 1" + - "* CAPACITY_TYPE_STORAGE = 2" + - "* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" + - "* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" + - "* CAPACITY_TYPE_PRIVATE_IP = 5" + - "* CAPACITY_TYPE_SECONDARY_STORAGE = 6" + - "* CAPACITY_TYPE_VLAN = 7" + - "* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" + - "* CAPACITY_TYPE_LOCAL_STORAGE = 9.") - - private Integer type; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public Long getZoneId() { - return zoneId; - } - - public Long getPodId() { - return podId; - } - - public Long getClusterId() { - return clusterId; - } - - public Integer getType() { - return type; - } - - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - - @Override - public String getCommandName() { - return s_name; - } - - @Override - public void execute(){ - List result = _mgr.listTopConsumedResources(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/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java index 0bf3188f1d3..74d69fec09f 100755 --- a/api/src/com/cloud/server/ManagementService.java +++ b/api/src/com/cloud/server/ManagementService.java @@ -50,7 +50,6 @@ import com.cloud.api.commands.ListServiceOfferingsCmd; import com.cloud.api.commands.ListStoragePoolsCmd; import com.cloud.api.commands.ListSystemVMsCmd; import com.cloud.api.commands.ListTemplatesCmd; -import com.cloud.api.commands.ListTopConsumedResources; import com.cloud.api.commands.ListVMGroupsCmd; import com.cloud.api.commands.ListVlanIpRangesCmd; import com.cloud.api.commands.ListZonesByCmd; @@ -441,6 +440,6 @@ public interface ManagementService { * @param cmd * @return List of capacities */ - List listTopConsumedResources(ListTopConsumedResources cmd); + List listTopConsumedResources(ListCapacityCmd cmd); } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 561228a8ca0..f9d26482aa5 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -84,7 +84,6 @@ import com.cloud.api.commands.ListServiceOfferingsCmd; import com.cloud.api.commands.ListStoragePoolsCmd; import com.cloud.api.commands.ListSystemVMsCmd; import com.cloud.api.commands.ListTemplatesCmd; -import com.cloud.api.commands.ListTopConsumedResources; import com.cloud.api.commands.ListVMGroupsCmd; import com.cloud.api.commands.ListVlanIpRangesCmd; import com.cloud.api.commands.ListZonesByCmd; @@ -1939,7 +1938,7 @@ public class ManagementServerImpl implements ManagementServer { } @Override - public List listTopConsumedResources(ListTopConsumedResources cmd) { + public List listTopConsumedResources(ListCapacityCmd cmd) { Integer capacityType = cmd.getType(); Long zoneId = cmd.getZoneId(); @@ -2042,11 +2041,16 @@ public class ManagementServerImpl implements ManagementServer { Long podId = cmd.getPodId(); Long clusterId = cmd.getClusterId(); Boolean fetchLatest = cmd.getFetchLatest(); + Boolean sortByUsage = cmd.getSortByUsage(); zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId); if (fetchLatest != null && fetchLatest){ _alertMgr.recalculateCapacity(); } + + if (sortByUsage != null && sortByUsage){ + return listTopConsumedResources(cmd); + } List summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId); List capacities = new ArrayList();