bug 10774: Introduce percentage in list commands and cluster id in alert table

This commit is contained in:
Nitin 2011-10-25 14:20:12 +05:30
parent b336a8b813
commit f85d558b6e
6 changed files with 69 additions and 14 deletions

15
core/src/com/cloud/alert/AlertVO.java Normal file → Executable file
View File

@ -40,8 +40,11 @@ public class AlertVO implements Alert{
private long id;
@Column(name="type")
private short type;
private short type;
@Column(name="cluster_id")
private Long clusterId = null;
@Column(name="pod_id")
private Long podId = null;
@ -92,7 +95,13 @@ public class AlertVO implements Alert{
this.subject = subject;
}
@Override
public Long getClusterId() {
return clusterId;
}
public void setClusterId(Long clusterId) {
this.clusterId = clusterId;
}
@Override
public Long getPodId() {
return podId;
}

View File

@ -261,7 +261,7 @@ public class AlertManagerImpl implements AlertManager {
// shouldn't we have a type/severity as part of the API so that severe errors get sent right away?
try {
if (_emailAlert != null) {
_emailAlert.sendAlert(alertType, dataCenterId, podId, subject, body);
_emailAlert.sendAlert(alertType, dataCenterId, podId, null, subject, body);
}
} catch (Exception ex) {
s_logger.error("Problem sending email alert", ex);
@ -503,6 +503,8 @@ public class AlertManagerImpl implements AlertManager {
String usedStr;
String pctStr = formatPercent(usedCapacity/totalCapacity);
short alertType = -1;
Long podId = pod == null ? null : pod.getId();
Long clusterId = cluster == null ? null : cluster.getId();
switch (capacityType) {
@ -584,7 +586,7 @@ public class AlertManagerImpl implements AlertManager {
}
try {
_emailAlert.sendAlert(alertType, dc.getId(), null, msgSubject, msgContent);
_emailAlert.sendAlert(alertType, dc.getId(), podId, clusterId, msgSubject, msgContent);
} catch (Exception ex) {
s_logger.error("Exception in CapacityChecker", ex);
}
@ -683,7 +685,7 @@ public class AlertManagerImpl implements AlertManager {
}
// TODO: make sure this handles SSL transport (useAuth is true) and regular
public void sendAlert(short alertType, long dataCenterId, Long podId, String subject, String content) throws MessagingException, UnsupportedEncodingException {
public void sendAlert(short alertType, long dataCenterId, Long podId, Long clusterId, String subject, String content) throws MessagingException, UnsupportedEncodingException {
AlertVO alert = null;
if ((alertType != AlertManager.ALERT_TYPE_HOST) &&
(alertType != AlertManager.ALERT_TYPE_USERVM) &&
@ -691,14 +693,15 @@ public class AlertManagerImpl implements AlertManager {
(alertType != AlertManager.ALERT_TYPE_CONSOLE_PROXY) &&
(alertType != AlertManager.ALERT_TYPE_STORAGE_MISC) &&
(alertType != AlertManager.ALERT_TYPE_MANAGMENT_NODE)) {
alert = _alertDao.getLastAlert(alertType, dataCenterId, podId);
alert = _alertDao.getLastAlert(alertType, dataCenterId, podId, clusterId);
}
if (alert == null) {
// set up a new alert
AlertVO newAlert = new AlertVO();
newAlert.setType(alertType);
newAlert.setSubject(subject);
newAlert.setSubject(subject);
newAlert.setClusterId(clusterId);
newAlert.setPodId(podId);
newAlert.setDataCenterId(dataCenterId);
newAlert.setSentCount(1); // initialize sent count to 1 since we are now sending an alert
@ -737,7 +740,7 @@ public class AlertManagerImpl implements AlertManager {
public void clearAlert(short alertType, long dataCenterId, Long podId) {
if (alertType != -1) {
AlertVO alert = _alertDao.getLastAlert(alertType, dataCenterId, podId);
AlertVO alert = _alertDao.getLastAlert(alertType, dataCenterId, podId, null);
if (alert != null) {
AlertVO updatedAlert = _alertDao.createForUpdate();
updatedAlert.setResolved(new Date());

2
server/src/com/cloud/alert/dao/AlertDao.java Normal file → Executable file
View File

@ -22,5 +22,7 @@ import com.cloud.alert.AlertVO;
import com.cloud.utils.db.GenericDao;
public interface AlertDao extends GenericDao<AlertVO, Long> {
AlertVO getLastAlert(short type, long dataCenterId, Long podId, Long clusterId);
// This is for backward compatibility
AlertVO getLastAlert(short type, long dataCenterId, Long podId);
}

23
server/src/com/cloud/alert/dao/AlertDaoImpl.java Normal file → Executable file
View File

@ -30,7 +30,7 @@ import com.cloud.utils.db.SearchCriteria;
@Local(value = { AlertDao.class })
public class AlertDaoImpl extends GenericDaoBase<AlertVO, Long> implements AlertDao {
@Override
public AlertVO getLastAlert(short type, long dataCenterId, Long podId) {
public AlertVO getLastAlert(short type, long dataCenterId, Long podId, Long clusterId) {
Filter searchFilter = new Filter(AlertVO.class, "createdDate", Boolean.FALSE, Long.valueOf(1), Long.valueOf(1));
SearchCriteria<AlertVO> sc = createSearchCriteria();
@ -38,6 +38,9 @@ public class AlertDaoImpl extends GenericDaoBase<AlertVO, Long> implements Alert
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, Long.valueOf(dataCenterId));
if (podId != null) {
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
}
if (clusterId != null) {
sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
}
List<AlertVO> alerts = listBy(sc, searchFilter);
@ -45,5 +48,23 @@ public class AlertDaoImpl extends GenericDaoBase<AlertVO, Long> implements Alert
return alerts.get(0);
}
return null;
}
@Override
public AlertVO getLastAlert(short type, long dataCenterId, Long podId) {
Filter searchFilter = new Filter(AlertVO.class, "createdDate", Boolean.FALSE, Long.valueOf(1), Long.valueOf(1));
SearchCriteria<AlertVO> sc = createSearchCriteria();
sc.addAnd("type", SearchCriteria.Op.EQ, Short.valueOf(type));
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, Long.valueOf(dataCenterId));
if (podId != null) {
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
}
List<AlertVO> alerts = listBy(sc, searchFilter);
if ((alerts != null) && !alerts.isEmpty()) {
return alerts.get(0);
}
return null;
}
}

View File

@ -181,7 +181,7 @@ import com.cloud.vm.dao.UserVmData.SecurityGroupData;
public class ApiResponseHelper implements ResponseGenerator {
public final Logger s_logger = Logger.getLogger(ApiResponseHelper.class);
private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##");
@Override
public UserResponse createUserResponse(User user) {
@ -760,7 +760,12 @@ public class ApiResponseHelper implements ResponseGenerator {
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
}else{
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
@ -810,6 +815,11 @@ public class ApiResponseHelper implements ResponseGenerator {
}else{
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
@ -840,7 +850,12 @@ public class ApiResponseHelper implements ResponseGenerator {
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
@ -1033,7 +1048,11 @@ public class ApiResponseHelper implements ResponseGenerator {
}else{
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentUsed(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentUsed(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.

View File

@ -1110,6 +1110,7 @@ CREATE TABLE `cloud`.`op_host_capacity` (
CREATE TABLE `cloud`.`alert` (
`id` bigint unsigned NOT NULL auto_increment,
`type` int(1) unsigned NOT NULL,
`cluster_id` bigint unsigned,
`pod_id` bigint unsigned,
`data_center_id` bigint unsigned NOT NULL,
`subject` varchar(999) COMMENT 'according to SMTP spec, max subject length is 1000 including the CRLF character, so allow enough space to fit long pod/zone/host names',