Skip to content

Commit bbbfdd5

Browse files
bug 10848: Minor fixes.
1 parent abb37ac commit bbbfdd5

5 files changed

Lines changed: 72 additions & 26 deletions

File tree

server/src/com/cloud/alert/AlertManagerImpl.java

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.cloud.utils.component.Inject;
7575
import com.cloud.utils.db.DB;
7676
import com.cloud.utils.db.SearchCriteria;
77+
import com.gargoylesoftware.htmlunit.html.xpath.IsDescendantOfContextualFormFunction;
7778
import com.sun.mail.smtp.SMTPMessage;
7879
import com.sun.mail.smtp.SMTPSSLTransport;
7980
import com.sun.mail.smtp.SMTPTransport;
@@ -155,16 +156,16 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
155156
_emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug);
156157

157158

158-
String storageCapacityThreshold = _configDao.getValue(Config.StorageCapacityThreshold.key());configs.get("storage.capacity.notificationThreshold");
159-
String cpuCapacityThreshold = _configDao.getValue(Config.CPUCapacityThreshold.key());configs.get("cpu.capacity.notificationThreshold");
160-
String memoryCapacityThreshold = _configDao.getValue(Config.MemoryCapacityThreshold.key());configs.get("memory.capacity.notificationThreshold");
161-
String storageAllocCapacityThreshold = _configDao.getValue(Config.StorageAllocatedCapacityThreshold.key());configs.get("storage.allocated.capacity.notificationThreshold");
162-
String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key());configs.get("public.ip.capacity.notificationThreshold");
163-
String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key());configs.get("private.ip.capacity.notificationThreshold");
164-
String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key());configs.get("secondarystorage.capacity.notificationThreshold");
165-
String vlanCapacityThreshold = _configDao.getValue(Config.VlanCapacityThreshold.key());configs.get("vlan.capacity.notificationThreshold");
166-
String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key());configs.get("directnetwork.public.ip.capacity.notificationThreshold");
167-
String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key());configs.get("directnetwork.public.ip.capacity.notificationThreshold");
159+
String storageCapacityThreshold = _configDao.getValue(Config.StorageCapacityThreshold.key());
160+
String cpuCapacityThreshold = _configDao.getValue(Config.CPUCapacityThreshold.key());
161+
String memoryCapacityThreshold = _configDao.getValue(Config.MemoryCapacityThreshold.key());
162+
String storageAllocCapacityThreshold = _configDao.getValue(Config.StorageAllocatedCapacityThreshold.key());
163+
String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key());
164+
String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key());
165+
String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key());
166+
String vlanCapacityThreshold = _configDao.getValue(Config.VlanCapacityThreshold.key());
167+
String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key());
168+
String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key());
168169

169170
if (storageCapacityThreshold != null) {
170171
_storageCapacityThreshold = Double.parseDouble(storageCapacityThreshold);
@@ -451,7 +452,12 @@ public void checkForAlerts(){
451452
// Generate Alerts for Zone Level capacities
452453
for(DataCenterVO dc : dataCenterList){
453454
for (Short capacityType : dataCenterCapacityTypes){
454-
List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), dc.getId(), null, null);
455+
List<SummedCapacity> capacity = new ArrayList<SummedCapacity>();
456+
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), dc.getId(), null, null);
457+
458+
if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
459+
capacity.add(getUsedStats(capacityType, dc.getId(), null, null));
460+
}
455461
if (capacity == null || capacity.size() == 0){
456462
continue;
457463
}
@@ -482,12 +488,22 @@ public void checkForAlerts(){
482488
// Generate Alerts for Cluster Level capacities
483489
for( ClusterVO cluster : clusterList){
484490
for (Short capacityType : clusterCapacityTypes){
485-
List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
491+
List<SummedCapacity> capacity = new ArrayList<SummedCapacity>();
492+
float overProvFactor = 1f;
493+
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
494+
495+
if (capacityType == Capacity.CAPACITY_TYPE_STORAGE){
496+
capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId()));
497+
}
486498
if (capacity == null || capacity.size() == 0){
487499
continue;
500+
}
501+
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
502+
overProvFactor = ApiDBUtils.getCpuOverprovisioningFactor();
488503
}
489-
double totalCapacity = capacity.get(0).getTotalCapacity();
490-
double usedCapacity = capacity.get(0).getUsedCapacity();
504+
505+
double totalCapacity = capacity.get(0).getTotalCapacity() * overProvFactor;
506+
double usedCapacity = capacity.get(0).getUsedCapacity() + capacity.get(0).getReservedCapacity();
491507
if (totalCapacity != 0 && usedCapacity/totalCapacity > _capacityTypeThresholdMap.get(capacityType)){
492508
generateEmailAlert(ApiDBUtils.findZoneById(cluster.getDataCenterId()), ApiDBUtils.findPodById(cluster.getPodId()), cluster,
493509
totalCapacity, usedCapacity, capacityType);
@@ -497,6 +513,21 @@ public void checkForAlerts(){
497513

498514
}
499515

516+
private SummedCapacity getUsedStats(short capacityType, long zoneId, Long podId, Long clusterId){
517+
CapacityVO capacity;
518+
if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
519+
capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId);
520+
}else{
521+
capacity = _storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId);
522+
}
523+
if (capacity != null){
524+
return new SummedCapacity(capacity.getUsedCapacity(), 0, capacity.getTotalCapacity(), capacityType, clusterId, podId);
525+
}else{
526+
return null;
527+
}
528+
529+
}
530+
500531
private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluster, double totalCapacity, double usedCapacity, short capacityType){
501532

502533
String msgSubject = null;
@@ -558,7 +589,7 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
558589

559590
//Zone Level
560591
case CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE:
561-
msgSubject = "System Alert: Low Available Storage in availablity zone " + dc.getName();
592+
msgSubject = "System Alert: Low Available Secondary Storage in availablity zone " + dc.getName();
562593
totalStr = formatBytesToMegabytes(totalCapacity);
563594
usedStr = formatBytesToMegabytes(usedCapacity);
564595
msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
@@ -588,6 +619,10 @@ private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluste
588619
}
589620

590621
try {
622+
if (s_logger.isDebugEnabled()){
623+
s_logger.debug(msgSubject);
624+
s_logger.debug(msgContent);
625+
}
591626
_emailAlert.sendAlert(alertType, dc.getId(), podId, clusterId, msgSubject, msgContent);
592627
} catch (Exception ex) {
593628
s_logger.error("Exception in CapacityChecker", ex);

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ public ClusterResponse createClusterResponse(Cluster cluster, Boolean showCapaci
10561056
capacityResponses.add(capacityResponse);
10571057
}
10581058
// Do it for stats as well.
1059-
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
1059+
capacityResponses.addAll(getStatsCapacityresponse(null, cluster.getId(), pod.getId(), pod.getDataCenterId()));
10601060
clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
10611061
}
10621062
clusterResponse.setObjectName("cluster");

server/src/com/cloud/capacity/dao/CapacityDaoImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,20 @@ public static class SummedCapacity {
249249
public long sumReserved;
250250
public long sumTotal;
251251
public short capacityType;
252-
public long clusterId;
253-
public long podId;
252+
public Long clusterId;
253+
public Long podId;
254254
public SummedCapacity() {
255255
}
256+
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
257+
short capacityType, Long clusterId, Long podId) {
258+
super();
259+
this.sumUsed = sumUsed;
260+
this.sumReserved = sumReserved;
261+
this.sumTotal = sumTotal;
262+
this.capacityType = capacityType;
263+
this.clusterId = clusterId;
264+
this.podId = podId;
265+
}
256266
public Short getCapacityType() {
257267
return capacityType;
258268
}

server/src/com/cloud/configuration/Config.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public enum Config {
5959
VlanCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.vlan.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.", null),
6060
DirectNetworkPublicIpCapacityThreshold("Alert", ManagementServer.class, Float.class, "zone.directnetwork.publicip.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", null),
6161
LocalStorageCapacityThreshold("Alert", ManagementServer.class, Float.class, "cluster.localStorage.capacity.notificationthreshold", "0.75", "Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.", null),
62-
StorageAllocatedCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available.", null),
63-
StorageCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the cluster for low storage available.", null),
64-
CPUCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available.", null),
65-
MemoryCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low memory available.", null),
62+
StorageAllocatedCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null),
63+
StorageCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "pool.storage.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of storage utilization above which allocators will disable using the cluster for low storage available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null),
64+
CPUCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.cpu.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null),
65+
MemoryCapacityDisableThreshold("Alert", ManagementServer.class, Float.class, "cluster.memory.allocated.capacity.disablethreshold", "0.85", "Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.", null),
6666

6767

6868
// Storage

setup/db/db/schema-2213to30.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-serv
9292
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'project.smtp.useAuth', null, 'If true, use SMTP authentication when sending emails');
9393
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'project.smtp.username', null, 'Username for SMTP authentication (applies only if project.smtp.useAuth is true)');
9494

95-
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'cluster.memory.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available.');
96-
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'cluster.cpu.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available.');
97-
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'pool.storage.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available.');
98-
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'pool.storage.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available.');
95+
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'cluster.memory.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of memory utilization above which allocators will disable using the cluster for low memory available. Keep the corresponding notification threshold lower than this to be notified beforehand.');
96+
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'cluster.cpu.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of cpu utilization above which allocators will disable using the cluster for low cpu available. Keep the corresponding notification threshold lower than this to be notified beforehand.');
97+
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'pool.storage.allocated.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available. Keep the corresponding notification threshold lower than this to be notified beforehand.');
98+
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'pool.storage.capacity.disablethreshold' , .85, 'Percentage (as a value between 0 and 1) of allocated storage utilization above which allocators will disable using the cluster for low allocated storage available. Keep the corresponding notification threshold lower than this to be notified beforehand.');
9999
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'zone.vlan.capacity.notificationthreshold' , .75, 'Percentage (as a value between 0 and 1) of Zone Vlan utilization above which alerts will be sent about low number of Zone Vlans.');
100100
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'cluster.localStorage.capacity.notificationthreshold' , .75, 'Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.');
101101
INSERT IGNORE INTO configuration VALUES ('Alert', 'DEFAULT', 'management-server', 'zone.directnetwork.publicip.capacity.notificationthreshold' , .75, 'Percentage (as a value between 0 and 1) of Direct Network Public Ip Utilization above which alerts will be sent about low number of direct network public ips.');
@@ -116,3 +116,4 @@ update configuration set name = 'pod.privateip.capacity.notificationthreshold' ,
116116
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `template_version` varchar(100) COMMENT 'template version' AFTER role;
117117
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `scripts_version` varchar(100) COMMENT 'scripts version' AFTER template_version;
118118
ALTER TABLE `cloud`.`alert` ADD `cluster_id` bigint unsigned;
119+
DELETE from `cloud`.`op_host_capacity` where capacity_type in (2,4,6);

0 commit comments

Comments
 (0)