bug 10848: Minor fixes.

This commit is contained in:
Nitin 2011-10-31 17:00:11 +05:30
parent abb37acbdd
commit bbbfdd52ec
5 changed files with 72 additions and 26 deletions

View File

@ -74,6 +74,7 @@ import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria;
import com.gargoylesoftware.htmlunit.html.xpath.IsDescendantOfContextualFormFunction;
import com.sun.mail.smtp.SMTPMessage;
import com.sun.mail.smtp.SMTPSSLTransport;
import com.sun.mail.smtp.SMTPTransport;
@ -155,16 +156,16 @@ public class AlertManagerImpl implements AlertManager {
_emailAlert = new EmailAlert(emailAddresses, smtpHost, smtpPort, useAuth, smtpUsername, smtpPassword, emailSender, smtpDebug);
String storageCapacityThreshold = _configDao.getValue(Config.StorageCapacityThreshold.key());configs.get("storage.capacity.notificationThreshold");
String cpuCapacityThreshold = _configDao.getValue(Config.CPUCapacityThreshold.key());configs.get("cpu.capacity.notificationThreshold");
String memoryCapacityThreshold = _configDao.getValue(Config.MemoryCapacityThreshold.key());configs.get("memory.capacity.notificationThreshold");
String storageAllocCapacityThreshold = _configDao.getValue(Config.StorageAllocatedCapacityThreshold.key());configs.get("storage.allocated.capacity.notificationThreshold");
String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key());configs.get("public.ip.capacity.notificationThreshold");
String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key());configs.get("private.ip.capacity.notificationThreshold");
String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key());configs.get("secondarystorage.capacity.notificationThreshold");
String vlanCapacityThreshold = _configDao.getValue(Config.VlanCapacityThreshold.key());configs.get("vlan.capacity.notificationThreshold");
String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key());configs.get("directnetwork.public.ip.capacity.notificationThreshold");
String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key());configs.get("directnetwork.public.ip.capacity.notificationThreshold");
String storageCapacityThreshold = _configDao.getValue(Config.StorageCapacityThreshold.key());
String cpuCapacityThreshold = _configDao.getValue(Config.CPUCapacityThreshold.key());
String memoryCapacityThreshold = _configDao.getValue(Config.MemoryCapacityThreshold.key());
String storageAllocCapacityThreshold = _configDao.getValue(Config.StorageAllocatedCapacityThreshold.key());
String publicIPCapacityThreshold = _configDao.getValue(Config.PublicIpCapacityThreshold.key());
String privateIPCapacityThreshold = _configDao.getValue(Config.PrivateIpCapacityThreshold.key());
String secondaryStorageCapacityThreshold = _configDao.getValue(Config.SecondaryStorageCapacityThreshold.key());
String vlanCapacityThreshold = _configDao.getValue(Config.VlanCapacityThreshold.key());
String directNetworkPublicIpCapacityThreshold = _configDao.getValue(Config.DirectNetworkPublicIpCapacityThreshold.key());
String localStorageCapacityThreshold = _configDao.getValue(Config.LocalStorageCapacityThreshold.key());
if (storageCapacityThreshold != null) {
_storageCapacityThreshold = Double.parseDouble(storageCapacityThreshold);
@ -451,7 +452,12 @@ public class AlertManagerImpl implements AlertManager {
// Generate Alerts for Zone Level capacities
for(DataCenterVO dc : dataCenterList){
for (Short capacityType : dataCenterCapacityTypes){
List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), dc.getId(), null, null);
List<SummedCapacity> capacity = new ArrayList<SummedCapacity>();
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), dc.getId(), null, null);
if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
capacity.add(getUsedStats(capacityType, dc.getId(), null, null));
}
if (capacity == null || capacity.size() == 0){
continue;
}
@ -482,12 +488,22 @@ public class AlertManagerImpl implements AlertManager {
// Generate Alerts for Cluster Level capacities
for( ClusterVO cluster : clusterList){
for (Short capacityType : clusterCapacityTypes){
List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
List<SummedCapacity> capacity = new ArrayList<SummedCapacity>();
float overProvFactor = 1f;
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
if (capacityType == Capacity.CAPACITY_TYPE_STORAGE){
capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId()));
}
if (capacity == null || capacity.size() == 0){
continue;
}
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
overProvFactor = ApiDBUtils.getCpuOverprovisioningFactor();
}
double totalCapacity = capacity.get(0).getTotalCapacity();
double usedCapacity = capacity.get(0).getUsedCapacity();
double totalCapacity = capacity.get(0).getTotalCapacity() * overProvFactor;
double usedCapacity = capacity.get(0).getUsedCapacity() + capacity.get(0).getReservedCapacity();
if (totalCapacity != 0 && usedCapacity/totalCapacity > _capacityTypeThresholdMap.get(capacityType)){
generateEmailAlert(ApiDBUtils.findZoneById(cluster.getDataCenterId()), ApiDBUtils.findPodById(cluster.getPodId()), cluster,
totalCapacity, usedCapacity, capacityType);
@ -497,6 +513,21 @@ public class AlertManagerImpl implements AlertManager {
}
private SummedCapacity getUsedStats(short capacityType, long zoneId, Long podId, Long clusterId){
CapacityVO capacity;
if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){
capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId);
}else{
capacity = _storageMgr.getStoragePoolUsedStats(null, clusterId, podId, zoneId);
}
if (capacity != null){
return new SummedCapacity(capacity.getUsedCapacity(), 0, capacity.getTotalCapacity(), capacityType, clusterId, podId);
}else{
return null;
}
}
private void generateEmailAlert(DataCenterVO dc, HostPodVO pod, ClusterVO cluster, double totalCapacity, double usedCapacity, short capacityType){
String msgSubject = null;
@ -558,7 +589,7 @@ public class AlertManagerImpl implements AlertManager {
//Zone Level
case CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE:
msgSubject = "System Alert: Low Available Storage in availablity zone " + dc.getName();
msgSubject = "System Alert: Low Available Secondary Storage in availablity zone " + dc.getName();
totalStr = formatBytesToMegabytes(totalCapacity);
usedStr = formatBytesToMegabytes(usedCapacity);
msgContent = "Available secondary storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
@ -588,6 +619,10 @@ public class AlertManagerImpl implements AlertManager {
}
try {
if (s_logger.isDebugEnabled()){
s_logger.debug(msgSubject);
s_logger.debug(msgContent);
}
_emailAlert.sendAlert(alertType, dc.getId(), podId, clusterId, msgSubject, msgContent);
} catch (Exception ex) {
s_logger.error("Exception in CapacityChecker", ex);

View File

@ -1056,7 +1056,7 @@ public class ApiResponseHelper implements ResponseGenerator {
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
capacityResponses.addAll(getStatsCapacityresponse(null, cluster.getId(), pod.getId(), pod.getDataCenterId()));
clusterResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
}
clusterResponse.setObjectName("cluster");

View File

@ -249,10 +249,20 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
public long sumReserved;
public long sumTotal;
public short capacityType;
public long clusterId;
public long podId;
public Long clusterId;
public Long podId;
public SummedCapacity() {
}
public SummedCapacity(long sumUsed, long sumReserved, long sumTotal,
short capacityType, Long clusterId, Long podId) {
super();
this.sumUsed = sumUsed;
this.sumReserved = sumReserved;
this.sumTotal = sumTotal;
this.capacityType = capacityType;
this.clusterId = clusterId;
this.podId = podId;
}
public Short getCapacityType() {
return capacityType;
}

View File

@ -59,10 +59,10 @@ public enum Config {
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
// Storage

View File

@ -92,10 +92,10 @@ INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-serv
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'project.smtp.useAuth', null, 'If true, use SMTP authentication when sending emails');
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)');
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.');
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.');
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.');
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.');
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.');
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.');
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.');
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.');
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.');
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.');
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' ,
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `template_version` varchar(100) COMMENT 'template version' AFTER role;
ALTER TABLE `cloud`.`domain_router` ADD COLUMN `scripts_version` varchar(100) COMMENT 'scripts version' AFTER template_version;
ALTER TABLE `cloud`.`alert` ADD `cluster_id` bigint unsigned;
DELETE from `cloud`.`op_host_capacity` where capacity_type in (2,4,6);