event notificatio service and event bug plug-in changes

This commit is contained in:
Murali Reddy 2012-12-05 10:28:27 +05:30
parent 82f02bac34
commit 900c8b249c
22 changed files with 552 additions and 136 deletions

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.apache.cloudstack.framework.events;
package com.cloud.event;
import java.util.ArrayList;
import java.util.List;
@ -28,18 +28,27 @@ public class EventCategory {
public EventCategory(String categoryName) {
this.eventCategoryName = categoryName;
eventCategories.add(this);
}
public String getName() {
return eventCategoryName;
}
public static List<EventCategory> listAllEventCategory() {
public static List<EventCategory> listAllEventCategories() {
return eventCategories;
}
public static EventCategory getEventCategory(String categoryName) {
for (EventCategory category : eventCategories) {
if (category.getName().equalsIgnoreCase(categoryName)) {
return category;
}
}
return null;
}
public static final EventCategory ACTION_EVENT = new EventCategory("Action Events");
public static final EventCategory ALERT_EVENT = new EventCategory("Alert Event");
public static final EventCategory USAGE_EVENT = new EventCategory("Usage Event");
}

View File

@ -101,6 +101,11 @@
<artifactId>cloud-plugin-host-allocator-random</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-mom-rabbitmq</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>

View File

@ -173,9 +173,9 @@ under the License.
<adapter name="BasicAgentAuthorizer" class="com.cloud.agent.manager.authn.impl.BasicAgentAuthManager"/>
</adapters>
<adapters key="org.apache.cloudstack.framework.events.EventBus">
<adapter name="RabbitMQ Message Broker" class="org.apache.cloudstack.mom.rabbitmq.RabbitMQEventBus">
<param name="server">localhost</param>
<param name="port">55672</param>
<adapter name="RabbitMQMessageBroker" class="org.apache.cloudstack.mom.rabbitmq.RabbitMQEventBus">
<param name="server">127.0.0.1</param>
<param name="port">5672</param>
<param name="username">guest</param>
<param name="password">guest</param>
</adapter>

View File

@ -33,6 +33,11 @@
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${cs.gson.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>

View File

@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.events;
import com.google.gson.Gson;
public class Event {
String category;
String type;
String routingKey;
String description;
String publisher;
String date;
public Event(String category, String type, String routingKey) {
this.category = category;
this.type = type;
this.routingKey = routingKey;
}
public String getCategory() {
return category;
}
public String getType() {
return type;
}
public String getRoutingKey() {
return routingKey;
}
public void setRoutingKey(String routingKey) {
this.routingKey = routingKey;
}
public String getDescription() {
return description;
}
public void setDescription (Object message) {
Gson gson = new Gson();
this.description = gson.toJson(description).toString();
}
public String getEventPublisher() {
return publisher;
}
void setEventPublisher(String source) {
this.publisher = source;
}
public String getDate() {
return date;
}
void setDate(String date) {
this.date = date;
}
}

View File

@ -20,30 +20,37 @@
package org.apache.cloudstack.framework.events;
import com.cloud.utils.component.Adapter;
import java.util.Map;
/**
* Publish and Subscribe provider interface
* Interface to publish and subscribe to CloudStack events
*
*/
public interface EventBus extends Adapter{
/**
* Publish an event
*
* @param category category of the event being published (e.g. action, usage, alert etc)
* @param type type of the event (e.g. vm stop, volume delete etc)
* @param description description of the event
* @return true if the event has been successfully published.
*/
boolean publish(String category, String type, Map<String, String> description);
/**
* Subscribe to events of a category and a type
*
* @param category category of the event being subscribed (e.g. action, usage, alert etc)
* @param type type of the event (e.g. vm stop, volume delete etc)
* @param subscriber class that is intends to receive subscribed event
* @return true if the subscribe has been successfully registered.
* publish an event
*
* @param event event that needs to be published
* @return true if the event has been successfully published on event bus
*/
boolean subscribe(String category, String type, EventSubscriber subscriber);
}
boolean publish(Event event);
/**
* subscribe to events of a category and a type
*
* @param topic defines category and type of the events being subscribed to
* @param subscriber subscriber that intends to receive event notification
* @return true if the subscriber has been successfully registered.
*/
boolean subscribe(EventTopic topic, EventSubscriber subscriber);
/**
* unsubscribe to events of a category and a type
*
* @param topic defines category and type of the events to unsubscribe
* @param subscriber subscriber that intends to unsubscribe from the event notification
* @return true if the subscriber has been successfully unsubscribed.
*/
boolean unsubscribe(EventTopic topic, EventSubscriber subscriber);
}

View File

@ -19,21 +19,18 @@
package org.apache.cloudstack.framework.events;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.AnnotationInterceptor;
import com.cloud.utils.component.ComponentLocator;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
public class EventPublisher implements MethodInterceptor, AnnotationInterceptor<Publish> {
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Enumeration;
public class EventPublishCallback implements MethodInterceptor, AnnotationInterceptor<Publish> {
private static EventBus _eventBus = null;
@ -58,7 +55,7 @@ public class EventPublisher implements MethodInterceptor, AnnotationInterceptor<
public boolean needToIntercept(AnnotatedElement element) {
if (!(element instanceof Method)) {
return false;
}
Method method = (Method)element;
Publish event = method.getAnnotation(Publish.class);
@ -77,9 +74,7 @@ public class EventPublisher implements MethodInterceptor, AnnotationInterceptor<
public void interceptComplete(AnnotatedElement element, Publish event) {
_eventBus = getEventBus();
if (_eventBus != null) {
Map<String, String> description = new HashMap<String, String>();
description.put("description", event.eventDescription());
_eventBus.publish(event.eventCategory(), event.eventType(), description);
}
}
@ -92,7 +87,7 @@ public class EventPublisher implements MethodInterceptor, AnnotationInterceptor<
public Callback getCallback() {
return this;
}
private EventBus getEventBus() {
if (_eventBus == null) {
ComponentLocator locator = ComponentLocator.getLocator("management-server");
@ -104,4 +99,4 @@ public class EventPublisher implements MethodInterceptor, AnnotationInterceptor<
}
return _eventBus;
}
}
}

View File

@ -7,7 +7,7 @@
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@ -19,16 +19,14 @@
package org.apache.cloudstack.framework.events;
import java.util.Map;
public interface EventSubscriber {
/**
* Callback method. EventBus calls this method on occurrence of subscribed event
*
* @param category category of the event being subscribed (e.g. action, usage, alert etc)
*
* @param category category of the event being subscribed (e.g. action, usage, alert etc)
* @param type type of the event (e.g. vm stop, volume delete etc)
* @param description description of the event
*/
void recieve(String category, String type, Map<String, String> description);
void recieve(Event event);
}

View File

@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.events;
public class EventTopic {
String eventCategory;
String eventType;
String bindingKey;
public EventTopic(String eventCategory, String eventType, String bindingKey) {
this.eventCategory = eventCategory;
this.eventType = eventType;
this.bindingKey = bindingKey;
}
public String getEventCategory() {
return eventCategory;
}
public String getEventType() {
return eventType;
}
public String getBindingKey() {
return bindingKey;
}
}

View File

@ -20,10 +20,10 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-mom-rabbitmq</artifactId>
<name>Apache CloudStack RabbitMQ MOM</name>
<name>Apache CloudStack Plugin - RabbitMQ Event Bus</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack</artifactId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

View File

@ -0,0 +1,125 @@
package org.apache.cloudstack.mom.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;
import org.apache.cloudstack.framework.events.Event;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventSubscriber;
import org.apache.cloudstack.framework.events.EventTopic;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import java.util.Map;
@Local(value=EventBus.class)
public class RabbitMQEventBus implements EventBus {
public static final Logger s_logger = Logger.getLogger(RabbitMQEventBus.class);
public Connection _connection = null;
public Channel _channel = null;
private String _rabbitMqHost;
private Integer _port;
private String _username;
private String _password;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_rabbitMqHost = (String) params.get("server");
_port = Integer.parseInt((String) params.get("port"));
_username = (String) params.get("username");
_password = (String) params.get("password");
return true;
}
@Override
public String getName() {
return null;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public boolean publish(Event event) {
String exchangeName = getExchangeName(event.getCategory());
String routingKey = getRoutingKey(event.getType());
String eventDescription = event.getDescription();
try {
createConnection();
createExchange(exchangeName);
publishEventToExchange(exchangeName, routingKey, eventDescription);
} catch (Exception e) {
s_logger.error("Failed to publish event to message broker due to " + e.getMessage());
return false;
}
return true;
}
@Override
public boolean subscribe(EventTopic topic, EventSubscriber subscriber) {
return true;
}
@Override
public boolean unsubscribe(EventTopic topic, EventSubscriber subscriber) {
return true;
}
private String getExchangeName(String eventCategory) {
return "CloudStack " + eventCategory;
}
private String getRoutingKey(String eventType) {
return eventType;
}
private void createConnection() throws Exception {
try {
// obtain a connection to RabbitMQ server
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(_username);
factory.setPassword(_password);
factory.setVirtualHost("/");
factory.setHost(_rabbitMqHost);
factory.setPort(_port);
_connection = factory.newConnection();
_channel = _connection.createChannel();
} catch (Exception e) {
s_logger.error("Failed to create a connection to RabbitMQ server due to " + e.getMessage());
throw e;
}
}
private void createExchange(String eventCategory) throws Exception {
String exchangeName = getExchangeName(eventCategory);
try {
_channel.exchangeDeclare(exchangeName, "topic", true);
} catch (java.io.IOException exception) {
s_logger.error("Failed to create exchange on RabbitMQ server for the event category " + eventCategory);
throw exception;
}
}
private void publishEventToExchange(String exchangeName, String routingKey, String eventDescription) throws Exception {
try {
byte[] messageBodyBytes = eventDescription.getBytes();
_channel.basicPublish(exchangeName, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, messageBodyBytes);
} catch (Exception e) {
s_logger.error("Failed to publish event " + routingKey + " on exchange " + exchangeName +
" of message broker due to " + e.getMessage());
throw e;
}
}
}

View File

@ -1,76 +0,0 @@
package org.apache.cloudstack.mom.rabbitmq;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventCategory;
import org.apache.cloudstack.framework.events.EventSubscriber;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.util.Map;
public class RabbitMQEventBus implements EventBus {
public static final Logger s_logger = Logger.getLogger(RabbitMQEventBus.class);
@Override
public boolean publish(String category, String type, Map<String, String> description) {
return false;
}
@Override
public boolean subscribe(String category, String type, EventSubscriber subscriber) {
return false;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
try {
String rabbitMqHost = (String) params.get("server");
Integer port = (Integer) params.get("port");
String username = (String) params.get("username");
String password = (String) params.get("password");
// obtain a connection to RabbitMQ server
ConnectionFactory factory = new ConnectionFactory();
factory.setUsername(username);
factory.setPassword(password);
factory.setVirtualHost("/");
factory.setHost(rabbitMqHost);
factory.setPort(port);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
// create the exchange for each event category
for (EventCategory category : EventCategory.listAllEventCategory()) {
try {
channel.exchangeDeclare(category.getName(), "topic", true);
} catch (java.io.IOException exception) {
s_logger.debug("Failed to create exchange on RabbitMQ server for the event category " + category.getName());
}
}
} catch (Exception e) {
return false;
}
return true;
}
@Override
public String getName() {
return null;
}
@Override
public boolean start() {
return false;
}
@Override
public boolean stop() {
return false;
}
}

View File

@ -0,0 +1,41 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-plugin-event-notification-service</artifactId>
<name>Apache CloudStack Pluggable Service - Event Notifications</name>
<parent>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloudstack-plugins</artifactId>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-utils</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
</build>
</project>

View File

@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.Events.Notifications;
public class Endpoint {
}

View File

@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.Events.Notifications;
public class EndpointHandler {
}

View File

@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.Events.Notifications;
public interface EventNotificationManager {
}

View File

@ -0,0 +1,71 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.Events.Notifications;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.framework.events.EventTopic;
import javax.naming.ConfigurationException;
import java.util.Map;
import java.util.List;
public class EventNotificationManagerImpl implements EventNotificationManager, EventNotificationService, PluggableService, Manager {
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
return false;
}
@Override
public boolean start() {
return false;
}
@Override
public boolean stop() {
return false;
}
@Override
public String getName() {
return null;
}
@Override
public String getPropertiesFile() {
return null;
}
@Override
public void subscribe(EventTopic topic, Endpoint endpoint) {
}
@Override
public void unsubscribe(EventTopic topic, Endpoint endpoint) {
}
@Override
public List<EventTopic> listSubscribedTopics() {
}
}

View File

@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.Events.Notifications;
import org.apache.cloudstack.framework.events.EventTopic;
import java.util.List;
public interface EventNotificationService {
void subscribe(EventTopic topic, Endpoint endpoint);
void unsubscribe(EventTopic topic, Endpoint endpoint);
List<EventTopic> listSubscribedTopics();
}

View File

@ -22,7 +22,7 @@ import com.cloud.event.ActionEventCallback;
import com.cloud.utils.component.AnnotationInterceptor;
import com.cloud.utils.component.InterceptorLibrary;
import com.cloud.utils.db.DatabaseCallback;
import org.apache.cloudstack.framework.events.EventPublisher;
import org.apache.cloudstack.framework.events.EventPublishCallback;
public class DefaultInterceptorLibrary implements InterceptorLibrary {
@ -30,6 +30,6 @@ public class DefaultInterceptorLibrary implements InterceptorLibrary {
public void addInterceptors(List<AnnotationInterceptor<?>> interceptors) {
interceptors.add(new DatabaseCallback());
interceptors.add(new ActionEventCallback());
interceptors.add(new EventPublisher());
interceptors.add(new EventPublishCallback());
}
}

View File

@ -23,8 +23,8 @@ import com.cloud.utils.component.ComponentLocator;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.apache.cloudstack.framework.events.Event;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventCategory;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
@ -86,7 +86,7 @@ public class ActionEventCallback implements MethodInterceptor, AnnotationInterce
eventDescription += ". "+ctx.getEventDetails();
}
EventUtils.saveStartedActionEvent(userId, accountId, actionEvent.eventType(), eventDescription, startEventId);
publishOnEventBus(userId, accountId, actionEvent.eventType(), Event.State.Started, eventDescription);
publishOnEventBus(userId, accountId, actionEvent.eventType(), com.cloud.event.Event.State.Started, eventDescription);
}
}
return event;
@ -108,11 +108,11 @@ public class ActionEventCallback implements MethodInterceptor, AnnotationInterce
if(actionEvent.create()){
//This start event has to be used for subsequent events of this action
startEventId = EventUtils.saveCreatedActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully created entity for "+eventDescription);
publishOnEventBus(userId, accountId, actionEvent.eventType(), Event.State.Created, "Successfully created entity for " + eventDescription);
publishOnEventBus(userId, accountId, actionEvent.eventType(), com.cloud.event.Event.State.Created, "Successfully created entity for " + eventDescription);
ctx.setStartEventId(startEventId);
} else {
EventUtils.saveActionEvent(userId, accountId, EventVO.LEVEL_INFO, actionEvent.eventType(), "Successfully completed "+eventDescription, startEventId);
publishOnEventBus(userId, accountId, actionEvent.eventType(), Event.State.Completed, "Successfully completed " + eventDescription + startEventId);
publishOnEventBus(userId, accountId, actionEvent.eventType(), com.cloud.event.Event.State.Completed, "Successfully completed " + eventDescription + startEventId);
}
}
}
@ -144,14 +144,16 @@ public class ActionEventCallback implements MethodInterceptor, AnnotationInterce
return this;
}
void publishOnEventBus(long userId, long accountId, String type, Event.State state, String description) {
void publishOnEventBus(long userId, long accountId, String type, com.cloud.event.Event.State state, String description) {
if (getEventBus() != null) {
Map<String, String> eventDescription = new HashMap<String, String>();
eventDescription.put("user", String.valueOf(userId));
eventDescription.put("account", String.valueOf(accountId));
eventDescription.put("state", state.toString());
eventDescription.put("description", description);
_eventBus.publish(EventCategory.ACTION_EVENT, type, eventDescription);
Event event = new Event(EventCategory.ACTION_EVENT.getName(), type, type);
event.setDescription(eventDescription);
_eventBus.publish(event);
}
}

View File

@ -3,7 +3,7 @@ package com.cloud.event;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventCategory;
import org.apache.cloudstack.framework.events.Event;
import java.util.Enumeration;
import java.util.HashMap;
@ -25,7 +25,9 @@ public class AlertGenerator {
eventDescription.put("podId", Long.toString(podId));
eventDescription.put("subject", subject);
eventDescription.put("body", body);
_eventBus.publish(EventCategory.ALERT_EVENT, alertType, eventDescription);
Event event = new Event(EventCategory.ALERT_EVENT.getName(), alertType, alertType);
event.setDescription(eventDescription);
_eventBus.publish(event);
}
}

View File

@ -3,7 +3,7 @@ package com.cloud.event;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.ComponentLocator;
import org.apache.cloudstack.framework.events.EventBus;
import org.apache.cloudstack.framework.events.EventCategory;
import org.apache.cloudstack.framework.events.Event;
import java.util.Enumeration;
import java.util.HashMap;
@ -54,7 +54,9 @@ public class UsageEventGenerator {
}
eventDescription.put("resourceName", resourceName);
eventDescription.put("resourceType", resourceType);
_eventBus.publish(EventCategory.USAGE_EVENT, usageType, eventDescription);
Event event = new Event(EventCategory.USAGE_EVENT.getName(), usageType, usageType);
event.setDescription(eventDescription);
_eventBus.publish(event);
}
}