cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [1/2] CLOUDSTACK-5261: support for alert publishing via Root admin web api
Date Wed, 04 Dec 2013 01:28:28 GMT
Updated Branches:
  refs/heads/4.3 8367a8fae -> b315ca189


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 806e3af..85c5bc1 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -960,7 +960,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements
V
                             String context = "Site-to-site Vpn Connection to " + gw.getName()
+ " on router " + router.getHostName() +
                                     "(id: " + router.getId() + ") " + " just switch from
" + oldState + " to " + conn.getState();
                             s_logger.info(context);
-                            _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
+                            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
                                     router.getDataCenterId(), router.getPodIdToDeployIn(),
title, context);
                         }
                     } finally {
@@ -1023,7 +1023,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                         " just switch from " + prevState + " to " + currState;
                 s_logger.info(context);
                 if (currState == RedundantState.MASTER) {
-                    _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
+                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
                             router.getDataCenterId(), router.getPodIdToDeployIn(), title,
context);
                 }
             }
@@ -1040,7 +1040,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug(title);
                 }
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
                         backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(),
title, title);
                 try {
                     rebootRouter(backupRouter.getId(), true);
@@ -1130,8 +1130,8 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                         String title = "More than one redundant virtual router is in MASTER
state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
                         String context =  "Virtual router (name: " + router.getHostName()
+ ", id: " + router.getId() + " and router (name: "
                                 + dupRouter.getHostName() + ", id: " + router.getId() + ")
are both in MASTER state! If the problem persist, restart both of routers. ";
-                        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(),
router.getPodIdToDeployIn(), title, context);
-                        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterId(),
dupRouter.getPodIdToDeployIn(), title, context);
+                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
+                        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
dupRouter.getDataCenterId(), dupRouter.getPodIdToDeployIn(), title, context);
                         s_logger.warn(context);
                     } else {
                             networkRouterMaps.put(routerGuestNtwkId, router);
@@ -3491,7 +3491,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
         }
         String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would
be stopped after connecting back, due to " + reason;
         String context =  "Virtual router (name: " + disconnectedRouter.getInstanceName()
+ ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to:
" + reason;
-        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
+        _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
                 disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(),
title, context);
         disconnectedRouter.setStopPending(true);
         disconnectedRouter = _routerDao.persist(disconnectedRouter);
@@ -3510,7 +3510,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase
implements V
                 }
             } else {
                 String t = "Can't bump up virtual router " + connectedRouter.getInstanceName()
+ "'s priority due to it's already bumped up!";
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,
                         connectedRouter.getDataCenterId(), connectedRouter.getPodIdToDeployIn(),
t, t);
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index 269f04f..c0e9ad7 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -255,7 +255,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         long numToDecrement = (delta.length == 0) ? 1 : delta[0].longValue();
 
         if (!updateResourceCountForAccount(accountId, type, false, numToDecrement)) {
-            _alertMgr.sendAlert(AlertManager.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L, "Failed
to decrement resource count of type " + type + " for account id=" + accountId,
+            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPDATE_RESOURCE_COUNT,
0L, 0L, "Failed to decrement resource count of type " + type + " for account id=" + accountId,
                     "Failed to decrement resource count of type " + type + " for account
id=" + accountId + "; use updateResourceCount API to recalculate/fix the problem");
         }
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java
index ff664bc..1761e52 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -60,6 +60,7 @@ import org.apache.cloudstack.api.command.admin.account.DisableAccountCmd;
 import org.apache.cloudstack.api.command.admin.account.EnableAccountCmd;
 import org.apache.cloudstack.api.command.admin.account.LockAccountCmd;
 import org.apache.cloudstack.api.command.admin.account.UpdateAccountCmd;
+import org.apache.cloudstack.api.command.admin.alert.GenerateAlertCmd;
 import org.apache.cloudstack.api.command.admin.autoscale.CreateCounterCmd;
 import org.apache.cloudstack.api.command.admin.autoscale.DeleteCounterCmd;
 import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
@@ -2288,6 +2289,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         Object id = cmd.getId();
         Object type = cmd.getType();
         Object keyword = cmd.getKeyword();
+        Object name = cmd.getName();
 
         Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(),
null);
         if (id != null) {
@@ -2307,6 +2309,10 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         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);
         Pair<List<AlertVO>, Integer> result = _alertDao.searchAndCount(sc, searchFilter);
@@ -2891,6 +2897,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
         cmdList.add(ListSslCertsCmd.class);
         cmdList.add(AssignCertToLoadBalancerCmd.class);
         cmdList.add(RemoveCertFromLoadBalancerCmd.class);
+        cmdList.add(GenerateAlertCmd.class);
         return cmdList;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
index 4f6a455..4cabd55 100755
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -1083,7 +1083,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
             if (snapshotType != Type.MANUAL){
                 String msg = "Snapshot resource limit exceeded for account id : " + owner.getId()
+ ". Failed to create recurring snapshots";
                 s_logger.warn(msg);
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L,
msg,
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPDATE_RESOURCE_COUNT,
0L, 0L, msg,
                         "Snapshot resource limit exceeded for account id : " + owner.getId()
+ ". Failed to create recurring snapshots; please use updateResourceLimit to increase the
limit");
             }
             throw e;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index 37b346f..d630fd5 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1820,7 +1820,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                     }
                 }
                 String msg = "Failed to deploy Vm with Id: " + vmId + ", on Host with Id:
" + hostId;
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
 
                 // Get serviceOffering for Virtual Machine
                 ServiceOfferingVO offering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
@@ -4233,14 +4233,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
         if (srcExplDedicated && !destExplDedicated) {
             //raise an alert
             String msg = "VM is being migrated from a explicitly dedicated host " + srcHost.getName()
+" to non-dedicated host " + destHost.getName();
-            _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
msg, msg);
+            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
             s_logger.warn(msg);
         }
         //if srcHost is non dedicated but destination Host is explicitly dedicated
         if (!srcExplDedicated && destExplDedicated) {
             //raise an alert
             String msg = "VM is being migrated from a non dedicated host " + srcHost.getName()
+ " to a explicitly dedicated host "+ destHost.getName();
-            _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
msg, msg);
+            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
             s_logger.warn(msg);
         }
 
@@ -4249,13 +4249,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
             if((accountOfDedicatedHost(srcHost) != null) && (accountOfDedicatedHost(srcHost)!=
accountOfDedicatedHost(destHost))) {
                 String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly
dedicated to account " + accountOfDedicatedHost(srcHost) +
                         " to host " + destHost.getName() + " explicitly dedicated to account
" + accountOfDedicatedHost(destHost);
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
                 s_logger.warn(msg);
             }
             if((domainOfDedicatedHost(srcHost) != null) && (domainOfDedicatedHost(srcHost)!=
domainOfDedicatedHost(destHost))) {
                 String msg = "VM is being migrated from host " + srcHost.getName() + " explicitly
dedicated to domain " + domainOfDedicatedHost(srcHost) +
                         " to host " + destHost.getName() + " explicitly dedicated to domain
" + domainOfDedicatedHost(destHost);
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
                 s_logger.warn(msg);
             }
         }
@@ -4294,7 +4294,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                     }
                 }
             }
-            _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(), vm.getPodIdToDeployIn(),
msg, msg);
+            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
             s_logger.warn(msg);
 
         } else {
@@ -4317,12 +4317,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
                 } else {
                     msg = "VM is being migrated from implicitly dedicated host " + srcHost.getName()
+ " to shared host " + destHost.getName();
                 }
-                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
+                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
                 s_logger.warn(msg);
             } else {
                 if (destImplDedicated) {
                     msg = "VM is being migrated from shared host " + srcHost.getName() +
" to implicitly dedicated host " + destHost.getName();
-                    _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
+                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USERVM, vm.getDataCenterId(),
vm.getPodIdToDeployIn(), msg, msg);
                     s_logger.warn(msg);
                 }
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/server/test/com/cloud/alert/MockAlertManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/alert/MockAlertManagerImpl.java b/server/test/com/cloud/alert/MockAlertManagerImpl.java
index f0c67f9..597d479 100644
--- a/server/test/com/cloud/alert/MockAlertManagerImpl.java
+++ b/server/test/com/cloud/alert/MockAlertManagerImpl.java
@@ -63,7 +63,7 @@ public class MockAlertManagerImpl extends ManagerBase implements AlertManager
{
      * @see com.cloud.alert.AlertManager#clearAlert(short, long, long)
      */
     @Override
-    public void clearAlert(short alertType, long dataCenterId, long podId) {
+    public void clearAlert(AlertType alertType, long dataCenterId, long podId) {
         // TODO Auto-generated method stub
 
     }
@@ -72,7 +72,7 @@ public class MockAlertManagerImpl extends ManagerBase implements AlertManager
{
      * @see com.cloud.alert.AlertManager#sendAlert(short, long, java.lang.Long, java.lang.String,
java.lang.String)
      */
     @Override
-    public void sendAlert(short alertType, long dataCenterId, Long podId, String subject,
String body) {
+    public void sendAlert(AlertType alertType, long dataCenterId, Long podId, String subject,
String body) {
         // TODO Auto-generated method stub
 
     }
@@ -86,4 +86,10 @@ public class MockAlertManagerImpl extends ManagerBase implements AlertManager
{
 
     }
 
+    @Override
+    public boolean generateAlert(AlertType alertType, long dataCenterId, Long podId, String
msg) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/setup/db/db/schema-421to430.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-421to430.sql b/setup/db/db/schema-421to430.sql
index dae1d2c..a9c850f 100644
--- a/setup/db/db/schema-421to430.sql
+++ b/setup/db/db/schema-421to430.sql
@@ -799,3 +799,7 @@ CREATE TABLE `cloud`.`network_acl_item_details` (
   PRIMARY KEY (`id`),
   CONSTRAINT `fk_network_acl_item_details__network_acl_item_id` FOREIGN KEY `fk_network_acl_item_details__network_acl_item_id`(`network_acl_item_id`)
REFERENCES `network_acl_item`(`id`) ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+ALTER TABLE `cloud`.`alert` ADD COLUMN `name` varchar(255) DEFAULT NULL COMMENT 'name of
the alert';
+

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/usage/src/com/cloud/usage/UsageAlertManagerImpl.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageAlertManagerImpl.java b/usage/src/com/cloud/usage/UsageAlertManagerImpl.java
index 0786742..01e6bec 100644
--- a/usage/src/com/cloud/usage/UsageAlertManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageAlertManagerImpl.java
@@ -24,14 +24,15 @@ import java.util.Properties;
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.mail.Authenticator;
+import javax.mail.Message.RecipientType;
 import javax.mail.MessagingException;
 import javax.mail.PasswordAuthentication;
 import javax.mail.Session;
 import javax.mail.URLName;
-import javax.mail.Message.RecipientType;
 import javax.mail.internet.InternetAddress;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -40,13 +41,10 @@ import com.cloud.alert.AlertVO;
 import com.cloud.alert.dao.AlertDao;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.component.ManagerBase;
-
 import com.sun.mail.smtp.SMTPMessage;
 import com.sun.mail.smtp.SMTPSSLTransport;
 import com.sun.mail.smtp.SMTPTransport;
 
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-
 @Component
 @Local(value={AlertManager.class})
 public class UsageAlertManagerImpl extends ManagerBase implements AlertManager {
@@ -86,10 +84,10 @@ public class UsageAlertManagerImpl extends ManagerBase implements AlertManager
{
     }
 
     @Override
-    public void clearAlert(short alertType, long dataCenterId, long podId) {
+    public void clearAlert(AlertType alertType, long dataCenterId, long podId) {
         try {
             if (_emailAlert != null) {
-                _emailAlert.clearAlert(alertType, dataCenterId, podId);
+                _emailAlert.clearAlert(alertType.getType(), dataCenterId, podId);
             }
         } catch (Exception ex) {
             s_logger.error("Problem clearing email alert", ex);
@@ -97,7 +95,7 @@ public class UsageAlertManagerImpl extends ManagerBase implements AlertManager
{
     }
 
     @Override
-    public void sendAlert(short alertType, long dataCenterId, Long podId, String subject,
String body) {
+    public void sendAlert(AlertType alertType, long dataCenterId, Long podId, String subject,
String body) {
         // TODO:  queue up these messages and send them as one set of issues once a certain
number of issues is reached?  If that's the case,
         //         shouldn't we have a type/severity as part of the API so that severe errors
get sent right away?
         try {
@@ -175,29 +173,30 @@ public class UsageAlertManagerImpl extends ManagerBase 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 {
+        protected void sendAlert(AlertType alertType, long dataCenterId, Long podId, String
subject, String content) throws MessagingException, UnsupportedEncodingException {
             s_alertsLogger.warn(" alertType:: " + alertType + " // dataCenterId:: " + dataCenterId
+ " // podId:: " +
                 podId + " // clusterId:: " + null + " // message:: " + subject);
             AlertVO alert = null;
-            if ((alertType != AlertManager.ALERT_TYPE_HOST) &&
-                (alertType != AlertManager.ALERT_TYPE_USERVM) &&
-                (alertType != AlertManager.ALERT_TYPE_DOMAIN_ROUTER) &&
-                (alertType != AlertManager.ALERT_TYPE_CONSOLE_PROXY) &&
-                (alertType != AlertManager.ALERT_TYPE_SSVM) &&
-                (alertType != AlertManager.ALERT_TYPE_STORAGE_MISC) &&
-                (alertType != AlertManager.ALERT_TYPE_MANAGMENT_NODE)) {
-                alert = _alertDao.getLastAlert(alertType, dataCenterId, podId);
+            if ((alertType != AlertManager.AlertType.ALERT_TYPE_HOST) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_USERVM) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_SSVM) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC) &&
+                (alertType != AlertManager.AlertType.ALERT_TYPE_MANAGMENT_NODE)) {
+                alert = _alertDao.getLastAlert(alertType.getType(), dataCenterId, podId);
             }
 
             if (alert == null) {
                 // set up a new alert
                 AlertVO newAlert = new AlertVO();
-                newAlert.setType(alertType);
+                newAlert.setType(alertType.getType());
                 newAlert.setSubject(subject);
                 newAlert.setPodId(podId);
                 newAlert.setDataCenterId(dataCenterId);
                 newAlert.setSentCount(1); // initialize sent count to 1 since we are now
sending an alert
                 newAlert.setLastSent(new Date());
+                newAlert.setName(alertType.getName());
                 _alertDao.persist(newAlert);
             } else {
                 if (s_logger.isDebugEnabled()) {
@@ -247,4 +246,14 @@ public class UsageAlertManagerImpl extends ManagerBase implements AlertManager
{
         // TODO Auto-generated method stub
         
     }
+
+    @Override
+    public boolean generateAlert(AlertType alertType, long dataCenterId, Long podId, String
msg) {
+        try {
+            sendAlert(alertType, dataCenterId, podId, msg, msg);
+            return true;
+        } catch (Exception ex) {
+            s_logger.warn("Failed to generate an alert of type=" + alertType + "; msg=" +
msg);
+            return false;
+        }    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b315ca18/usage/src/com/cloud/usage/UsageManagerImpl.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java
index 407237c..8b3127d 100644
--- a/usage/src/com/cloud/usage/UsageManagerImpl.java
+++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
@@ -784,9 +784,9 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
                 // switch back to CLOUD_DB
                 TransactionLegacy swap = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
                 if(!success){
-                    _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SERVER_RESULT, 0, new
Long(0), "Usage job failed. Job id: "+job.getId(), "Usage job failed. Job id: "+job.getId());
+                    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USAGE_SERVER_RESULT,
0, new Long(0), "Usage job failed. Job id: "+job.getId(), "Usage job failed. Job id: "+job.getId());
                 } else {
-                    _alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SERVER_RESULT, 0,
0);
+                    _alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_USAGE_SERVER_RESULT,
0, 0);
                 }
                 swap.close();
                 
@@ -1806,9 +1806,9 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager,
Runna
             try {
                 String errors = usc.runSanityCheck();
                 if(errors.length() > 0){
-                   _alertMgr.sendAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0, new
Long(0), "Usage Sanity Check failed", errors);
+                   _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_USAGE_SANITY_RESULT,
0, new Long(0), "Usage Sanity Check failed", errors);
                 } else {
-                    _alertMgr.clearAlert(AlertManager.ALERT_TYPE_USAGE_SANITY_RESULT, 0,
0);
+                    _alertMgr.clearAlert(AlertManager.AlertType.ALERT_TYPE_USAGE_SANITY_RESULT,
0, 0);
                 }
             } catch (SQLException e) {
                 s_logger.error("Error in sanity check", e);


Mime
View raw message