Search in sources :

Example 1 with Event

use of com.cloud.storage.Volume.Event in project cloudstack by apache.

the class VolumeStateListener method pubishOnEventBus.

private void pubishOnEventBus(String event, String status, Volume vo, State oldState, State newState) {
    String configKey = Config.PublishResourceStateEvent.key();
    String value = _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;
    }
    String resourceName = getEntityFromClassName(Volume.class.getName());
    org.apache.cloudstack.framework.events.Event eventMsg = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(), event, resourceName, vo.getUuid());
    Map<String, String> eventDescription = new HashMap<String, String>();
    eventDescription.put("resource", resourceName);
    eventDescription.put("id", vo.getUuid());
    eventDescription.put("old-state", oldState.name());
    eventDescription.put("new-state", newState.name());
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    eventMsg.setDescription(eventDescription);
    try {
        s_eventBus.publish(eventMsg);
    } catch (EventBusException e) {
        s_logger.warn("Failed to state change event on the the event bus.");
    }
}
Also used : HashMap(java.util.HashMap) EventBus(org.apache.cloudstack.framework.events.EventBus) Date(java.util.Date) Volume(com.cloud.storage.Volume) Event(com.cloud.storage.Volume.Event) EventBusException(org.apache.cloudstack.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

Volume (com.cloud.storage.Volume)1 Event (com.cloud.storage.Volume.Event)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 EventBus (org.apache.cloudstack.framework.events.EventBus)1 EventBusException (org.apache.cloudstack.framework.events.EventBusException)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1