mirror of https://github.com/apache/cloudstack.git
bug 10774: On removing storage, local storage, cluster handle deletion of corresponding op_host_capacity rows.
This commit is contained in:
parent
70aae9666b
commit
b336a8b813
|
|
@ -36,6 +36,12 @@ public class CapacityResponse extends BaseResponse {
|
|||
|
||||
@SerializedName("podname") @Param(description="the Pod name")
|
||||
private String podName;
|
||||
|
||||
@SerializedName(ApiConstants.CLUSTER_ID) @Param(description="the Cluster ID")
|
||||
private Long clusterId;
|
||||
|
||||
@SerializedName("clustername") @Param(description="the Cluster name")
|
||||
private String clusterName;
|
||||
|
||||
@SerializedName("capacityused") @Param(description="the capacity currently in use")
|
||||
private Long capacityUsed;
|
||||
|
|
@ -86,7 +92,23 @@ public class CapacityResponse extends BaseResponse {
|
|||
this.podName = podName;
|
||||
}
|
||||
|
||||
public Long getCapacityUsed() {
|
||||
public Long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public void setClusterId(Long clusterId) {
|
||||
this.clusterId = clusterId;
|
||||
}
|
||||
|
||||
public String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
|
||||
public void setClusterName(String clusterName) {
|
||||
this.clusterName = clusterName;
|
||||
}
|
||||
|
||||
public Long getCapacityUsed() {
|
||||
return capacityUsed;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,9 @@ public interface AlertManager extends Manager {
|
|||
public static final short ALERT_TYPE_STORAGE_DELETE = 20;
|
||||
public static final short ALERT_TYPE_UPDATE_RESOURCE_COUNT = 21; // Generated when we fail to update the resource count
|
||||
public static final short ALERT_TYPE_USAGE_SANITY_RESULT = 22;
|
||||
public static final short ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 23;
|
||||
public static final short ALERT_TYPE_LOCAL_STORAGE = 24;
|
||||
|
||||
|
||||
void clearAlert(short alertType, long dataCenterId, long podId);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ import com.cloud.configuration.dao.ConfigurationDao;
|
|||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
|
|
@ -313,19 +314,23 @@ public class AlertManagerImpl implements AlertManager {
|
|||
//implementing the same
|
||||
|
||||
// Calculate new Public IP capacity for Virtual Network
|
||||
s_logger.trace("Executing public ip capacity update for Virtual Network");
|
||||
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP);
|
||||
s_logger.trace("Done with public ip capacity update for Virtual Network");
|
||||
if (datacenter.getNetworkType() == NetworkType.Advanced){
|
||||
s_logger.trace("Executing public ip capacity update for Virtual Network");
|
||||
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP);
|
||||
s_logger.trace("Done with public ip capacity update for Virtual Network");
|
||||
}
|
||||
|
||||
// Calculate new Public IP capacity for Direct Attached Network
|
||||
s_logger.trace("Executing public ip capacity update for Direct Attached Network");
|
||||
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP);
|
||||
s_logger.trace("Done with public ip capacity update for Direct Attached Network");
|
||||
|
||||
//Calculate VLAN's capacity
|
||||
s_logger.trace("Executing VLAN capacity update");
|
||||
createOrUpdateVlanCapacity(dcId);
|
||||
s_logger.trace("Executing VLAN capacity update");
|
||||
if (datacenter.getNetworkType() == NetworkType.Advanced){
|
||||
//Calculate VLAN's capacity
|
||||
s_logger.trace("Executing VLAN capacity update");
|
||||
createOrUpdateVlanCapacity(dcId);
|
||||
s_logger.trace("Executing VLAN capacity update");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -497,6 +502,7 @@ public class AlertManagerImpl implements AlertManager {
|
|||
String totalStr;
|
||||
String usedStr;
|
||||
String pctStr = formatPercent(usedCapacity/totalCapacity);
|
||||
short alertType = -1;
|
||||
|
||||
switch (capacityType) {
|
||||
|
||||
|
|
@ -506,30 +512,35 @@ public class AlertManagerImpl implements AlertManager {
|
|||
totalStr = formatBytesToMegabytes(totalCapacity);
|
||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
||||
msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_MEMORY;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_CPU:
|
||||
msgSubject = "System Alert: Low Unallocated CPU in cluster " +cluster.getName()+ " pod " +pod.getName()+ " of availablity zone " + dc.getName();
|
||||
totalStr = _dfWhole.format(totalCapacity);
|
||||
usedStr = _dfWhole.format(usedCapacity);
|
||||
msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_CPU;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_STORAGE:
|
||||
msgSubject = "System Alert: Low Available Storage in cluster " +cluster.getName()+ " pod " +pod.getName()+ " of availablity zone " + dc.getName();
|
||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
||||
msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_STORAGE;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED:
|
||||
msgSubject = "System Alert: Remaining unallocated Storage is low in cluster " +cluster.getName()+ " pod " +pod.getName()+ " of availablity zone " + dc.getName();
|
||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
||||
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_STORAGE_ALLOCATED;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_LOCAL_STORAGE:
|
||||
msgSubject = "System Alert: Remaining unallocated Local Storage is low in cluster " +cluster.getName()+ " pod " +pod.getName()+ " of availablity zone " + dc.getName();
|
||||
totalStr = formatBytesToMegabytes(totalCapacity);
|
||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
||||
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_LOCAL_STORAGE;
|
||||
break;
|
||||
|
||||
//Pod Level
|
||||
|
|
@ -538,6 +549,7 @@ public class AlertManagerImpl implements AlertManager {
|
|||
totalStr = Double.toString(totalCapacity);
|
||||
usedStr = Double.toString(usedCapacity);
|
||||
msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_PRIVATE_IP;
|
||||
break;
|
||||
|
||||
//Zone Level
|
||||
|
|
@ -546,29 +558,33 @@ public class AlertManagerImpl implements AlertManager {
|
|||
totalStr = formatBytesToMegabytes(totalCapacity);
|
||||
usedStr = formatBytesToMegabytes(usedCapacity);
|
||||
msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_SECONDARY_STORAGE;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP:
|
||||
msgSubject = "System Alert: Number of unallocated virtual network public IPs is low in availablity zone " + dc.getName();
|
||||
totalStr = Double.toString(totalCapacity);
|
||||
usedStr = Double.toString(usedCapacity);
|
||||
msgContent = "Number of unallocated public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_VIRTUAL_NETWORK_PUBLIC_IP;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP:
|
||||
msgSubject = "System Alert: Number of unallocated direct attached public IPs is low in availablity zone " + dc.getName();
|
||||
totalStr = Double.toString(totalCapacity);
|
||||
usedStr = Double.toString(usedCapacity);
|
||||
msgContent = "Number of unallocated direct attached public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP;
|
||||
break;
|
||||
case CapacityVO.CAPACITY_TYPE_VLAN:
|
||||
msgSubject = "System Alert: Number of unallocated VLANs is low in availablity zone " + dc.getName();
|
||||
totalStr = Double.toString(totalCapacity);
|
||||
usedStr = Double.toString(usedCapacity);
|
||||
msgContent = "Number of unallocated VLANs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
|
||||
alertType = ALERT_TYPE_VLAN;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
_emailAlert.sendAlert(capacityType, dc.getId(), null, msgSubject, msgContent);
|
||||
_emailAlert.sendAlert(alertType, dc.getId(), null, msgSubject, msgContent);
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception in CapacityChecker", ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -350,7 +350,15 @@ public class ApiDBUtils {
|
|||
public static StorageStats getSecondaryStorageStatistics(long id) {
|
||||
return _statsCollector.getStorageStats(id);
|
||||
}
|
||||
|
||||
public static CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId){
|
||||
return _storageMgr.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId);
|
||||
}
|
||||
|
||||
public static CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId){
|
||||
return _storageMgr.getSecondaryStorageUsedStats(hostId, zoneId);
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////////////////////
|
||||
// Dao methods //
|
||||
// ///////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -763,6 +763,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
capacityResponses.add(capacityResponse);
|
||||
}
|
||||
// Do it for stats as well.
|
||||
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
|
||||
podResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
|
||||
}
|
||||
podResponse.setObjectName("pod");
|
||||
|
|
@ -810,6 +812,9 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
capacityResponses.add(capacityResponse);
|
||||
}
|
||||
// Do it for stats as well.
|
||||
capacityResponses.addAll(getStatsCapacityresponse(null, null, null, dataCenter.getId()));
|
||||
|
||||
zoneResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
|
||||
}
|
||||
|
||||
|
|
@ -823,6 +828,25 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
return zoneResponse;
|
||||
}
|
||||
|
||||
private List<CapacityResponse> getStatsCapacityresponse(Long poolId, Long clusterId, Long podId, Long zoneId){
|
||||
List<CapacityVO> capacities = new ArrayList<CapacityVO>();
|
||||
capacities.add(ApiDBUtils.getStoragePoolUsedStats(poolId, clusterId, podId, zoneId));
|
||||
if(clusterId == null && podId == null){
|
||||
capacities.add(ApiDBUtils.getSecondaryStorageUsedStats(poolId, zoneId));
|
||||
}
|
||||
|
||||
List<CapacityResponse> capacityResponses = new ArrayList<CapacityResponse>();
|
||||
for (CapacityVO capacity : capacities){
|
||||
CapacityResponse capacityResponse = new CapacityResponse();
|
||||
capacityResponse.setCapacityType(capacity.getCapacityType());
|
||||
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
|
||||
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
|
||||
capacityResponses.add(capacityResponse);
|
||||
}
|
||||
|
||||
return capacityResponses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeResponse createVolumeResponse(Volume volume) {
|
||||
VolumeResponse volResponse = new VolumeResponse();
|
||||
|
|
@ -1012,6 +1036,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
|
||||
capacityResponses.add(capacityResponse);
|
||||
}
|
||||
// Do it for stats as well.
|
||||
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
|
||||
clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
|
||||
}
|
||||
clusterResponse.setObjectName("cluster");
|
||||
|
|
@ -1877,15 +1903,23 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
capacityResponse.setCapacityUsed(summedCapacity.getUsedCapacity());
|
||||
if (summedCapacity.getPodId() != null) {
|
||||
capacityResponse.setPodId(summedCapacity.getPodId());
|
||||
if (summedCapacity.getPodId() > 0) {
|
||||
HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
|
||||
if (pod != null) {
|
||||
capacityResponse.setPodName(pod.getName());
|
||||
}
|
||||
} else {
|
||||
capacityResponse.setPodName("All");
|
||||
HostPodVO pod = ApiDBUtils.findPodById(summedCapacity.getPodId());
|
||||
if (pod != null) {
|
||||
capacityResponse.setPodName(pod.getName());
|
||||
}
|
||||
}
|
||||
if (summedCapacity.getClusterId() != null) {
|
||||
capacityResponse.setClusterId(summedCapacity.getClusterId());
|
||||
ClusterVO cluster = ApiDBUtils.findClusterById(summedCapacity.getClusterId());
|
||||
if (cluster != null) {
|
||||
capacityResponse.setClusterName(cluster.getName());
|
||||
if (summedCapacity.getPodId() == null){
|
||||
long podId = cluster.getPodId();
|
||||
capacityResponse.setPodId(podId);
|
||||
capacityResponse.setPodName(ApiDBUtils.findPodById(podId).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
capacityResponse.setZoneId(summedCapacity.getDataCenterId());
|
||||
capacityResponse.setZoneName(ApiDBUtils.findZoneById(summedCapacity.getDataCenterId()).getName());
|
||||
if (summedCapacity.getTotalCapacity() != 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue