From 900c8b249ce40f901658dcd07820e8b6636019e1 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 5 Dec 2012 10:28:27 +0530 Subject: [PATCH] event notificatio service and event bug plug-in changes --- .../src/com/cloud/event}/EventCategory.java | 15 ++- client/pom.xml | 5 + client/tomcatconf/components.xml.in | 6 +- framework/events/pom.xml | 5 + .../cloudstack/framework/events/Event.java | 79 +++++++++++ .../cloudstack/framework/events/EventBus.java | 45 ++++--- ...blisher.java => EventPublishCallback.java} | 25 ++-- .../framework/events/EventSubscriber.java | 10 +- .../framework/events/EventTopic.java | 45 +++++++ .../rabbitmq/pom.xml | 4 +- .../mom/rabbitmq/RabbitMQEventBus.java | 125 ++++++++++++++++++ .../mom/rabbitmq/RabbitMQEventBus.java | 76 ----------- plugins/services/event-notification/pom.xml | 41 ++++++ .../Events/Notifications/Endpoint.java | 24 ++++ .../Events/Notifications/EndpointHandler.java | 24 ++++ .../EventNotificationManager.java | 24 ++++ .../EventNotificationManagerImpl.java | 71 ++++++++++ .../EventNotificationService.java | 34 +++++ .../DefaultInterceptorLibrary.java | 4 +- .../com/cloud/event/ActionEventCallback.java | 14 +- .../src/com/cloud/event/AlertGenerator.java | 6 +- .../com/cloud/event/UsageEventGenerator.java | 6 +- 22 files changed, 552 insertions(+), 136 deletions(-) rename {framework/events/src/org/apache/cloudstack/framework/events => api/src/com/cloud/event}/EventCategory.java (78%) create mode 100644 framework/events/src/org/apache/cloudstack/framework/events/Event.java rename framework/events/src/org/apache/cloudstack/framework/events/{EventPublisher.java => EventPublishCallback.java} (88%) create mode 100644 framework/events/src/org/apache/cloudstack/framework/events/EventTopic.java rename plugins/{message-brokers => event-bus}/rabbitmq/pom.xml (94%) create mode 100644 plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java delete mode 100644 plugins/message-brokers/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java create mode 100644 plugins/services/event-notification/pom.xml create mode 100644 plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/Endpoint.java create mode 100644 plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EndpointHandler.java create mode 100644 plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManager.java create mode 100644 plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManagerImpl.java create mode 100644 plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationService.java diff --git a/framework/events/src/org/apache/cloudstack/framework/events/EventCategory.java b/api/src/com/cloud/event/EventCategory.java similarity index 78% rename from framework/events/src/org/apache/cloudstack/framework/events/EventCategory.java rename to api/src/com/cloud/event/EventCategory.java index 11be29b9f5a..a0042dd3cfa 100644 --- a/framework/events/src/org/apache/cloudstack/framework/events/EventCategory.java +++ b/api/src/com/cloud/event/EventCategory.java @@ -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 listAllEventCategory() { + public static List 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"); - } diff --git a/client/pom.xml b/client/pom.xml index 056e560baff..cf1e852258d 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -101,6 +101,11 @@ cloud-plugin-host-allocator-random ${project.version} + + org.apache.cloudstack + cloud-mom-rabbitmq + ${project.version} + mysql mysql-connector-java diff --git a/client/tomcatconf/components.xml.in b/client/tomcatconf/components.xml.in index 10bcd1ecd72..b540aebeb33 100755 --- a/client/tomcatconf/components.xml.in +++ b/client/tomcatconf/components.xml.in @@ -173,9 +173,9 @@ under the License. - - localhost - 55672 + + 127.0.0.1 + 5672 guest guest diff --git a/framework/events/pom.xml b/framework/events/pom.xml index 8da4e4caa46..b75a3dc1cc5 100644 --- a/framework/events/pom.xml +++ b/framework/events/pom.xml @@ -33,6 +33,11 @@ cloud-utils ${project.version} + + com.google.code.gson + gson + ${cs.gson.version} + install diff --git a/framework/events/src/org/apache/cloudstack/framework/events/Event.java b/framework/events/src/org/apache/cloudstack/framework/events/Event.java new file mode 100644 index 00000000000..96d0b76217e --- /dev/null +++ b/framework/events/src/org/apache/cloudstack/framework/events/Event.java @@ -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; + } +} diff --git a/framework/events/src/org/apache/cloudstack/framework/events/EventBus.java b/framework/events/src/org/apache/cloudstack/framework/events/EventBus.java index 8a2478869b4..3782b32aeba 100644 --- a/framework/events/src/org/apache/cloudstack/framework/events/EventBus.java +++ b/framework/events/src/org/apache/cloudstack/framework/events/EventBus.java @@ -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 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); -} \ No newline at end of file + 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); + +} diff --git a/framework/events/src/org/apache/cloudstack/framework/events/EventPublisher.java b/framework/events/src/org/apache/cloudstack/framework/events/EventPublishCallback.java similarity index 88% rename from framework/events/src/org/apache/cloudstack/framework/events/EventPublisher.java rename to framework/events/src/org/apache/cloudstack/framework/events/EventPublishCallback.java index b54757e674a..81c8ac4c2bf 100644 --- a/framework/events/src/org/apache/cloudstack/framework/events/EventPublisher.java +++ b/framework/events/src/org/apache/cloudstack/framework/events/EventPublishCallback.java @@ -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 { +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.util.Enumeration; + +public class EventPublishCallback implements MethodInterceptor, AnnotationInterceptor { 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 description = new HashMap(); - 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; } -} \ No newline at end of file +} diff --git a/framework/events/src/org/apache/cloudstack/framework/events/EventSubscriber.java b/framework/events/src/org/apache/cloudstack/framework/events/EventSubscriber.java index 50a8bd39e17..d69035aede4 100644 --- a/framework/events/src/org/apache/cloudstack/framework/events/EventSubscriber.java +++ b/framework/events/src/org/apache/cloudstack/framework/events/EventSubscriber.java @@ -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 description); + void recieve(Event event); } diff --git a/framework/events/src/org/apache/cloudstack/framework/events/EventTopic.java b/framework/events/src/org/apache/cloudstack/framework/events/EventTopic.java new file mode 100644 index 00000000000..eabcdf60772 --- /dev/null +++ b/framework/events/src/org/apache/cloudstack/framework/events/EventTopic.java @@ -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; + } +} diff --git a/plugins/message-brokers/rabbitmq/pom.xml b/plugins/event-bus/rabbitmq/pom.xml similarity index 94% rename from plugins/message-brokers/rabbitmq/pom.xml rename to plugins/event-bus/rabbitmq/pom.xml index 0956ee8ce9b..6a47983a9b5 100644 --- a/plugins/message-brokers/rabbitmq/pom.xml +++ b/plugins/event-bus/rabbitmq/pom.xml @@ -20,10 +20,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 cloud-mom-rabbitmq - Apache CloudStack RabbitMQ MOM + Apache CloudStack Plugin - RabbitMQ Event Bus org.apache.cloudstack - cloudstack + cloudstack-plugins 4.1.0-SNAPSHOT ../../pom.xml diff --git a/plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java b/plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java new file mode 100644 index 00000000000..a3685e88498 --- /dev/null +++ b/plugins/event-bus/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java @@ -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 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; + } + } +} \ No newline at end of file diff --git a/plugins/message-brokers/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java b/plugins/message-brokers/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java deleted file mode 100644 index b9607e559f9..00000000000 --- a/plugins/message-brokers/rabbitmq/src/org/apache/cloudstack/mom/rabbitmq/RabbitMQEventBus.java +++ /dev/null @@ -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 description) { - return false; - } - - @Override - public boolean subscribe(String category, String type, EventSubscriber subscriber) { - return false; - } - - @Override - public boolean configure(String name, Map 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; - } -} \ No newline at end of file diff --git a/plugins/services/event-notification/pom.xml b/plugins/services/event-notification/pom.xml new file mode 100644 index 00000000000..e2191655a76 --- /dev/null +++ b/plugins/services/event-notification/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + cloud-plugin-event-notification-service + Apache CloudStack Pluggable Service - Event Notifications + + org.apache.cloudstack + cloudstack-plugins + 4.1.0-SNAPSHOT + ../../pom.xml + + + + org.apache.cloudstack + cloud-utils + ${project.version} + + + + install + src + + diff --git a/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/Endpoint.java b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/Endpoint.java new file mode 100644 index 00000000000..c9c80377a7c --- /dev/null +++ b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/Endpoint.java @@ -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 { + +} \ No newline at end of file diff --git a/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EndpointHandler.java b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EndpointHandler.java new file mode 100644 index 00000000000..5969a62f87d --- /dev/null +++ b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EndpointHandler.java @@ -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 { + +} diff --git a/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManager.java b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManager.java new file mode 100644 index 00000000000..8c7e0b257a5 --- /dev/null +++ b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManager.java @@ -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 { + +} \ No newline at end of file diff --git a/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManagerImpl.java b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManagerImpl.java new file mode 100644 index 00000000000..d8901f68bad --- /dev/null +++ b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationManagerImpl.java @@ -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 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 listSubscribedTopics() { + + } +} \ No newline at end of file diff --git a/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationService.java b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationService.java new file mode 100644 index 00000000000..14e655b44f8 --- /dev/null +++ b/plugins/services/event-notification/src/org/apache/cloudstack/Events/Notifications/EventNotificationService.java @@ -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 listSubscribedTopics(); + +} \ No newline at end of file diff --git a/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java b/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java index c5c65e344f6..380552d1ade 100644 --- a/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java +++ b/server/src/com/cloud/configuration/DefaultInterceptorLibrary.java @@ -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> interceptors) { interceptors.add(new DatabaseCallback()); interceptors.add(new ActionEventCallback()); - interceptors.add(new EventPublisher()); + interceptors.add(new EventPublishCallback()); } } diff --git a/server/src/com/cloud/event/ActionEventCallback.java b/server/src/com/cloud/event/ActionEventCallback.java index 95fd2fdc935..93c2fdc23b4 100644 --- a/server/src/com/cloud/event/ActionEventCallback.java +++ b/server/src/com/cloud/event/ActionEventCallback.java @@ -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 eventDescription = new HashMap(); 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); } } diff --git a/server/src/com/cloud/event/AlertGenerator.java b/server/src/com/cloud/event/AlertGenerator.java index 1d3eeea7633..16ef73e5235 100644 --- a/server/src/com/cloud/event/AlertGenerator.java +++ b/server/src/com/cloud/event/AlertGenerator.java @@ -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); } } diff --git a/server/src/com/cloud/event/UsageEventGenerator.java b/server/src/com/cloud/event/UsageEventGenerator.java index 1aab9b24602..edf6a422c22 100644 --- a/server/src/com/cloud/event/UsageEventGenerator.java +++ b/server/src/com/cloud/event/UsageEventGenerator.java @@ -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); } }