Search in sources :

Example 1 with AlertVO

use of com.cloud.alert.AlertVO in project cloudstack by apache.

the class ManagementServerImpl method searchForAlerts.

@Override
public Pair<List<? extends Alert>, Integer> searchForAlerts(final ListAlertsCmd cmd) {
    final Filter searchFilter = new Filter(AlertVO.class, "lastSent", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchCriteria<AlertVO> sc = _alertDao.createSearchCriteria();
    final Object id = cmd.getId();
    final Object type = cmd.getType();
    final Object keyword = cmd.getKeyword();
    final Object name = cmd.getName();
    final Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), null);
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (zoneId != null) {
        sc.addAnd("data_center_id", SearchCriteria.Op.EQ, zoneId);
    }
    if (keyword != null) {
        final SearchCriteria<AlertVO> ssc = _alertDao.createSearchCriteria();
        ssc.addOr("subject", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("subject", SearchCriteria.Op.SC, ssc);
    }
    if (type != null) {
        sc.addAnd("type", SearchCriteria.Op.EQ, type);
    }
    if (name != null) {
        sc.addAnd("name", SearchCriteria.Op.EQ, name);
    }
    sc.addAnd("archived", SearchCriteria.Op.EQ, false);
    final Pair<List<AlertVO>, Integer> result = _alertDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends Alert>, Integer>(result.first(), result.second());
}
Also used : AlertVO(com.cloud.alert.AlertVO) Filter(com.cloud.utils.db.Filter) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair)

Example 2 with AlertVO

use of com.cloud.alert.AlertVO in project cloudstack by apache.

the class AlertDaoImpl method archiveAlert.

@Override
public boolean archiveAlert(List<Long> ids, String type, Date startDate, Date endDate, Long zoneId) {
    SearchCriteria<AlertVO> sc = AlertSearchByIdsAndType.create();
    if (ids != null) {
        sc.setParameters("id", ids.toArray(new Object[ids.size()]));
    }
    if (type != null) {
        sc.setParameters("type", type);
    }
    if (zoneId != null) {
        sc.setParameters("data_center_id", zoneId);
    }
    if (startDate != null && endDate != null) {
        sc.setParameters("createdDateB", startDate, endDate);
    } else if (endDate != null) {
        sc.setParameters("createdDateL", endDate);
    }
    sc.setParameters("archived", false);
    boolean result = true;
    ;
    List<AlertVO> alerts = listBy(sc);
    if (ids != null && alerts.size() < ids.size()) {
        result = false;
        return result;
    }
    if (alerts != null && !alerts.isEmpty()) {
        TransactionLegacy txn = TransactionLegacy.currentTxn();
        txn.start();
        for (AlertVO alert : alerts) {
            alert = lockRow(alert.getId(), true);
            alert.setArchived(true);
            update(alert.getId(), alert);
            txn.commit();
        }
        txn.close();
    }
    return result;
}
Also used : AlertVO(com.cloud.alert.AlertVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy)

Example 3 with AlertVO

use of com.cloud.alert.AlertVO in project cloudstack by apache.

the class AlertDaoImpl method getLastAlert.

@Override
public AlertVO getLastAlert(short type, long dataCenterId, Long podId, Long clusterId) {
    Filter searchFilter = new Filter(AlertVO.class, "createdDate", Boolean.FALSE, Long.valueOf(0), 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));
    sc.addAnd("archived", SearchCriteria.Op.EQ, false);
    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);
    if ((alerts != null) && !alerts.isEmpty()) {
        return alerts.get(0);
    }
    return null;
}
Also used : AlertVO(com.cloud.alert.AlertVO) Filter(com.cloud.utils.db.Filter)

Aggregations

AlertVO (com.cloud.alert.AlertVO)3 Filter (com.cloud.utils.db.Filter)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)1 SSHKeyPair (com.cloud.user.SSHKeyPair)1 Pair (com.cloud.utils.Pair)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1