mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
bug 11051: ListClusters - Introduce a flag 'showCapacitites'. When its true it will start displaying all the capacitites (as objects in the response) for the respective cluster.
This commit is contained in:
parent
9c5587601f
commit
4a5f6faca2
@ -157,6 +157,7 @@ public class ApiConstants {
|
||||
public static final String SENT = "sent";
|
||||
public static final String SENT_BYTES = "sentbytes";
|
||||
public static final String SERVICE_OFFERING_ID = "serviceofferingid";
|
||||
public static final String SHOW_CAPACITIES = "showcapacities";
|
||||
public static final String SIZE = "size";
|
||||
public static final String SNAPSHOT_ID = "snapshotid";
|
||||
public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";
|
||||
|
||||
@ -149,7 +149,7 @@ public interface ResponseGenerator {
|
||||
|
||||
StoragePoolResponse createStoragePoolResponse(StoragePool pool);
|
||||
|
||||
ClusterResponse createClusterResponse(Cluster cluster);
|
||||
ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities);
|
||||
|
||||
FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule);
|
||||
|
||||
|
||||
2
api/src/com/cloud/api/commands/AddClusterCmd.java
Normal file → Executable file
2
api/src/com/cloud/api/commands/AddClusterCmd.java
Normal file → Executable file
@ -129,7 +129,7 @@ public class AddClusterCmd extends BaseCmd {
|
||||
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
|
||||
if (result != null) {
|
||||
for (Cluster cluster : result) {
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster);
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
|
||||
clusterResponses.add(clusterResponse);
|
||||
}
|
||||
} else {
|
||||
|
||||
10
api/src/com/cloud/api/commands/ListClustersCmd.java
Normal file → Executable file
10
api/src/com/cloud/api/commands/ListClustersCmd.java
Normal file → Executable file
@ -66,6 +66,8 @@ public class ListClustersCmd extends BaseListCmd {
|
||||
@Parameter(name=ApiConstants.MANAGED_STATE, type=CommandType.STRING, description="whether this cluster is managed by cloudstack")
|
||||
private String managedState;
|
||||
|
||||
@Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the clusters")
|
||||
private Boolean showCapacities;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
@ -109,11 +111,15 @@ public class ListClustersCmd extends BaseListCmd {
|
||||
}
|
||||
|
||||
|
||||
public Boolean getShowCapacities() {
|
||||
return showCapacities;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
@ -124,7 +130,7 @@ public class ListClustersCmd extends BaseListCmd {
|
||||
ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
|
||||
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
|
||||
for (Cluster cluster : result) {
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster);
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster,showCapacities);
|
||||
clusterResponse.setObjectName("cluster");
|
||||
clusterResponses.add(clusterResponse);
|
||||
}
|
||||
|
||||
2
api/src/com/cloud/api/commands/UpdateClusterCmd.java
Normal file → Executable file
2
api/src/com/cloud/api/commands/UpdateClusterCmd.java
Normal file → Executable file
@ -109,7 +109,7 @@ public class UpdateClusterCmd extends BaseCmd {
|
||||
|
||||
Cluster result = _resourceService.updateCluster(cluster, getClusterType(), getHypervisor(), getAllocationState(), getManagedstate());
|
||||
if (result != null) {
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster);
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
|
||||
clusterResponse.setResponseName(getCommandName());
|
||||
this.setResponseObject(clusterResponse);
|
||||
} else {
|
||||
|
||||
13
api/src/com/cloud/api/response/ClusterResponse.java
Normal file → Executable file
13
api/src/com/cloud/api/response/ClusterResponse.java
Normal file → Executable file
@ -17,6 +17,9 @@
|
||||
*/
|
||||
package com.cloud.api.response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
@ -54,6 +57,8 @@ 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)
|
||||
private List<CapacityResponse> capacitites;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -134,4 +139,12 @@ public class ClusterResponse extends BaseResponse {
|
||||
public void setManagedState(String managedState) {
|
||||
this.managedState = managedState;
|
||||
}
|
||||
|
||||
public List<CapacityResponse> getCapacitites() {
|
||||
return capacitites;
|
||||
}
|
||||
|
||||
public void setCapacitites(ArrayList<CapacityResponse> arrayList) {
|
||||
this.capacitites = arrayList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,6 +26,8 @@ import com.cloud.agent.AgentManager;
|
||||
import com.cloud.api.response.UserVmResponse;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationService;
|
||||
import com.cloud.configuration.ResourceCount.ResourceType;
|
||||
@ -136,6 +138,7 @@ public class ApiDBUtils {
|
||||
private static AccountDao _accountDao;
|
||||
private static AccountVlanMapDao _accountVlanMapDao;
|
||||
private static ClusterDao _clusterDao;
|
||||
private static CapacityDao _capacityDao;
|
||||
private static DiskOfferingDao _diskOfferingDao;
|
||||
private static DomainDao _domainDao;
|
||||
private static DomainRouterDao _domainRouterDao;
|
||||
@ -182,6 +185,7 @@ public class ApiDBUtils {
|
||||
_accountDao = locator.getDao(AccountDao.class);
|
||||
_accountVlanMapDao = locator.getDao(AccountVlanMapDao.class);
|
||||
_clusterDao = locator.getDao(ClusterDao.class);
|
||||
_capacityDao = locator.getDao(CapacityDao.class);
|
||||
_diskOfferingDao = locator.getDao(DiskOfferingDao.class);
|
||||
_domainDao = locator.getDao(DomainDao.class);
|
||||
_domainRouterDao = locator.getDao(DomainRouterDao.class);
|
||||
@ -239,6 +243,15 @@ public class ApiDBUtils {
|
||||
return _ms.getMemoryOrCpuCapacityByHost(poolId, capacityType);
|
||||
}
|
||||
|
||||
public static List<CapacityVO> getCapacityByClusterPodZone(Long zoneId, Long podId, Long clusterId){
|
||||
return _capacityDao.findByClusterPodZone(null,null,clusterId);
|
||||
}
|
||||
|
||||
public static List<CapacityVO> getCapacityByPod(){
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Long getPodIdForVlan(long vlanDbId) {
|
||||
return _ms.getPodIdForVlan(vlanDbId);
|
||||
}
|
||||
|
||||
@ -964,7 +964,7 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClusterResponse createClusterResponse(Cluster cluster) {
|
||||
public ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapacities) {
|
||||
ClusterResponse clusterResponse = new ClusterResponse();
|
||||
clusterResponse.setId(cluster.getId());
|
||||
clusterResponse.setName(cluster.getName());
|
||||
@ -980,6 +980,18 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId());
|
||||
clusterResponse.setZoneName(zone.getName());
|
||||
if (showCapacities != null && showCapacities){
|
||||
List<CapacityVO> capacities = ApiDBUtils.getCapacityByClusterPodZone(null,null,cluster.getId());
|
||||
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
|
||||
for (CapacityVO capacity : capacities){
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
|
||||
capacityResponses.add(capacityResponse);
|
||||
}
|
||||
clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
|
||||
}
|
||||
clusterResponse.setObjectName("cluster");
|
||||
return clusterResponse;
|
||||
}
|
||||
|
||||
@ -31,4 +31,5 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
|
||||
List<SummedCapacity> findCapacityByType(short capacityType, Long zoneId, Long podId,
|
||||
Long clusterId, Long startIndex, Long pageSize);
|
||||
boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId);
|
||||
List<CapacityVO> findByClusterPodZone(Long zoneId, Long podId, Long clusterId);
|
||||
}
|
||||
|
||||
@ -244,6 +244,24 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
||||
public SummedCapacity() {
|
||||
}
|
||||
}
|
||||
public List<CapacityVO> findByClusterPodZone(Long zoneId, Long podId, Long clusterId){
|
||||
|
||||
SearchCriteria<CapacityVO> sc = _allFieldsSearch.create();
|
||||
if (zoneId != null) {
|
||||
sc.setParameters("zoneId", zoneId);
|
||||
}
|
||||
|
||||
if (podId != null) {
|
||||
sc.setParameters("podId", podId);
|
||||
}
|
||||
|
||||
if (clusterId != null) {
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
}
|
||||
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBy(Short capacityType, Long zoneId, Long podId, Long clusterId) {
|
||||
SearchCriteria<CapacityVO> sc = _allFieldsSearch.create();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user