Search in sources :

Example 11 with EventBusException

use of org.apache.cloudstack.framework.events.EventBusException in project cloudstack by apache.

the class AlertGenerator method publishAlertOnEventBus.

public static void publishAlertOnEventBus(String alertType, long dataCenterId, Long podId, String subject, String body) {
    String configKey = Config.PublishAlertEvent.key();
    String value = s_configDao.getValue(configKey);
    boolean configValue = Boolean.parseBoolean(value);
    if (!configValue)
        return;
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.ALERT_EVENT.getName(), alertType, null, null);
    Map<String, String> eventDescription = new HashMap<String, String>();
    DataCenterVO dc = s_dcDao.findById(dataCenterId);
    HostPodVO pod = s_podDao.findById(podId);
    eventDescription.put("event", alertType);
    if (dc != null) {
        eventDescription.put("dataCenterId", dc.getUuid());
    } else {
        eventDescription.put("dataCenterId", null);
    }
    if (pod != null) {
        eventDescription.put("podId", pod.getUuid());
    } else {
        eventDescription.put("podId", null);
    }
    eventDescription.put("subject", subject);
    eventDescription.put("body", body);
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    event.setDescription(eventDescription);
    try {
        s_eventBus.publish(event);
    } catch (EventBusException e) {
        s_logger.warn("Failed to publish alert on the the event bus.");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) EventBus(org.apache.cloudstack.framework.events.EventBus) HostPodVO(com.cloud.dc.HostPodVO) Date(java.util.Date) EventBusException(org.apache.cloudstack.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

EventBusException (org.apache.cloudstack.framework.events.EventBusException)11 HashMap (java.util.HashMap)7 EventBus (org.apache.cloudstack.framework.events.EventBus)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 SimpleDateFormat (java.text.SimpleDateFormat)6 Date (java.util.Date)6 Account (com.cloud.user.Account)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 AlreadyClosedException (com.rabbitmq.client.AlreadyClosedException)3 Channel (com.rabbitmq.client.Channel)3 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)3 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)3 ConfigurationException (javax.naming.ConfigurationException)3 EventSubscriber (org.apache.cloudstack.framework.events.EventSubscriber)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 User (com.cloud.user.User)2 Connection (com.rabbitmq.client.Connection)2 UUID (java.util.UUID)2 Event (org.apache.cloudstack.framework.events.Event)2