diff --git a/api/src/com/cloud/api/ResponseGenerator.java b/api/src/com/cloud/api/ResponseGenerator.java index ac0c254b765..c0d3f722b57 100755 --- a/api/src/com/cloud/api/ResponseGenerator.java +++ b/api/src/com/cloud/api/ResponseGenerator.java @@ -139,7 +139,7 @@ public interface ResponseGenerator { LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer); - PodResponse createPodResponse(Pod pod); + PodResponse createPodResponse(Pod pod, Boolean showCapacities); ZoneResponse createZoneResponse(DataCenter dataCenter); diff --git a/api/src/com/cloud/api/commands/CreatePodCmd.java b/api/src/com/cloud/api/commands/CreatePodCmd.java old mode 100644 new mode 100755 index 173eb78d383..ea5cfddad94 --- a/api/src/com/cloud/api/commands/CreatePodCmd.java +++ b/api/src/com/cloud/api/commands/CreatePodCmd.java @@ -111,7 +111,7 @@ public class CreatePodCmd extends BaseCmd { public void execute(){ Pod result = _configService.createPod(this); if (result != null) { - PodResponse response = _responseGenerator.createPodResponse(result); + PodResponse response = _responseGenerator.createPodResponse(result, false); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/commands/ListPodsByCmd.java b/api/src/com/cloud/api/commands/ListPodsByCmd.java old mode 100644 new mode 100755 index a5fe5a18fbd..e42949609ed --- a/api/src/com/cloud/api/commands/ListPodsByCmd.java +++ b/api/src/com/cloud/api/commands/ListPodsByCmd.java @@ -53,8 +53,10 @@ public class ListPodsByCmd extends BaseListCmd { @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="list pods by allocation state") private String allocationState; - - + + @Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the pods") + private Boolean showCapacities; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -75,6 +77,10 @@ public class ListPodsByCmd extends BaseListCmd { return allocationState; } + public Boolean getShowCapacities() { + return showCapacities; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -90,7 +96,7 @@ public class ListPodsByCmd extends BaseListCmd { ListResponse response = new ListResponse(); List podResponses = new ArrayList(); for (Pod pod : result) { - PodResponse podResponse = _responseGenerator.createPodResponse(pod); + PodResponse podResponse = _responseGenerator.createPodResponse(pod, showCapacities); podResponse.setObjectName("pod"); podResponses.add(podResponse); } diff --git a/api/src/com/cloud/api/commands/UpdatePodCmd.java b/api/src/com/cloud/api/commands/UpdatePodCmd.java old mode 100644 new mode 100755 index 249fbc66ddd..c83bcf9beca --- a/api/src/com/cloud/api/commands/UpdatePodCmd.java +++ b/api/src/com/cloud/api/commands/UpdatePodCmd.java @@ -110,7 +110,7 @@ public class UpdatePodCmd extends BaseCmd { public void execute(){ Pod result = _configService.editPod(this); if (result != null) { - PodResponse response = _responseGenerator.createPodResponse(result); + PodResponse response = _responseGenerator.createPodResponse(result,false); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { diff --git a/api/src/com/cloud/api/response/ClusterResponse.java b/api/src/com/cloud/api/response/ClusterResponse.java index aea3b729256..2b03039316f 100755 --- a/api/src/com/cloud/api/response/ClusterResponse.java +++ b/api/src/com/cloud/api/response/ClusterResponse.java @@ -57,7 +57,7 @@ public class ClusterResponse extends BaseResponse { @SerializedName("managedstate") @Param(description="whether this cluster is managed by cloudstack") private String managedState; - @SerializedName("capacity") @Param(description="", responseObject = CapacityResponse.class) + @SerializedName("capacity") @Param(description="the capacity of the Cluster", responseObject = CapacityResponse.class) private List capacitites; public Long getId() { diff --git a/api/src/com/cloud/api/response/PodResponse.java b/api/src/com/cloud/api/response/PodResponse.java old mode 100644 new mode 100755 index 74a09ae31ea..3fb81eeefe0 --- a/api/src/com/cloud/api/response/PodResponse.java +++ b/api/src/com/cloud/api/response/PodResponse.java @@ -17,6 +17,8 @@ */ package com.cloud.api.response; +import java.util.List; + import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @@ -45,9 +47,12 @@ public class PodResponse extends BaseResponse { @SerializedName("endip") @Param(description="the ending IP for the Pod") private String endIp; - @SerializedName("allocationstate") @Param(description="the allocation state of the cluster") + @SerializedName("allocationstate") @Param(description="the allocation state of the Pod") private String allocationState; + @SerializedName("capacity") @Param(description="the capacity of the Pod", responseObject = CapacityResponse.class) + private List capacitites; + public Long getId() { return id; } @@ -118,5 +123,13 @@ public class PodResponse extends BaseResponse { public void setAllocationState(String allocationState) { this.allocationState = allocationState; - } + } + + public List getCapacitites() { + return capacitites; + } + + public void setCapacitites(List capacitites) { + this.capacitites = capacitites; + } } diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index f8aba311ba9..23b2cad2101 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -244,7 +244,7 @@ public class ApiDBUtils { } public static List getCapacityByClusterPodZone(Long zoneId, Long podId, Long clusterId){ - return _capacityDao.findByClusterPodZone(null,null,clusterId); + return _capacityDao.findByClusterPodZone(zoneId,podId,clusterId); } public static List getCapacityByPod(){ diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index f5713c54009..b1911ddb9fd 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -756,7 +756,7 @@ public class ApiResponseHelper implements ResponseGenerator { } @Override - public PodResponse createPodResponse(Pod pod) { + public PodResponse createPodResponse(Pod pod, Boolean showCapacities) { String[] ipRange = new String[2]; if (pod.getDescription() != null && pod.getDescription().length() > 0) { ipRange = pod.getDescription().split("-"); @@ -774,6 +774,18 @@ public class ApiResponseHelper implements ResponseGenerator { podResponse.setEndIp(((ipRange.length > 1) && (ipRange[1] != null)) ? ipRange[1] : ""); podResponse.setGateway(pod.getGateway()); podResponse.setAllocationState(pod.getAllocationState().toString()); + if (showCapacities != null && showCapacities){ + List capacities = ApiDBUtils.getCapacityByClusterPodZone(null,pod.getId(),null); + Set capacityResponses = new HashSet(); + for (CapacityVO capacity : capacities){ + CapacityResponse capacityResponse = new CapacityResponse(); + capacityResponse.setCapacityType(capacity.getCapacityType()); + capacityResponse.setCapacityUsed(capacity.getUsedCapacity()); + capacityResponse.setCapacityTotal(capacity.getTotalCapacity()); + capacityResponses.add(capacityResponse); + } + podResponse.setCapacitites(new ArrayList(capacityResponses)); + } podResponse.setObjectName("pod"); return podResponse; }