Hello, I am attaching the final patch( *CLOUDSTACK-3272-Changes-to-allow-publishing-of-event.txt*) with this mail, it has the changes based on the global config parameters (mentioned below) events would be published or not based on the very parameter.
"publish.action.events" "publish.alert.events" "publish.resource.state.events" "publish.usage.events" "publish.async.job.events" Kindly let me know your comments. -- Thanks and Regards, *Sonal Ojha* * Senior Engineer Product Development * SunGard IT Availability Mobile +91-9922412645* E-Mail: sonal.o...@sungard.com
From d520f5cc1731a8c5e687bb5f76aed520c90e198f Mon Sep 17 00:00:00 2001 From: sonal_ojha <sonal.o...@sungard.com> Date: Thu, 27 Feb 2014 20:50:26 +0530 Subject: [PATCH] CLOUDSTACK-3272 Changes to allow publishing of events on the eventbus based on the global config parameter --- .../cloudstack/mom/rabbitmq/RabbitMQEventBus.java | 23 +++++++++++++++++++++- server/src/com/cloud/configuration/Config.java | 7 ++++++- server/src/com/cloud/test/DatabaseConfig.java | 15 ++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) 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 index 478c8d7..8e2b081 100644 --- 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 @@ -19,8 +19,10 @@ package org.apache.cloudstack.mom.rabbitmq; +import com.cloud.configuration.Config; import com.rabbitmq.client.*; +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.events.*; import org.apache.cloudstack.managed.context.ManagedContextRunnable; import org.apache.log4j.Logger; @@ -29,6 +31,7 @@ import com.cloud.utils.Ternary; import com.cloud.utils.component.ManagerBase; import javax.ejb.Local; +import javax.inject.Inject; import javax.naming.ConfigurationException; import java.io.IOException; @@ -68,6 +71,9 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { private static DisconnectHandler disconnectHandler; private static final Logger s_logger = Logger.getLogger(RabbitMQEventBus.class); + @Inject + ConfigurationDao _configDao; + @Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { @@ -233,7 +239,22 @@ public class RabbitMQEventBus extends ManagerBase implements EventBus { // publish event on to the exchange created on AMQP server @Override public void publish(Event event) throws EventBusException { - + String configKey = ""; + String categoryName = event.getEventCategory(); + if (categoryName == "ActionEvent") + configKey = Config.PublishActionEvent.key(); + else if (categoryName == "AlertEvent") + configKey = Config.PublishAlertEvent.key(); + else if (categoryName == "UsageEvent") + configKey = Config.PublishUsageEvent.key(); + else if (categoryName == "ResourceStateEvent") + configKey = Config.PublishResourceStateEvent.key(); + else if (categoryName == "AsyncJobEvent") + configKey = Config.PublishAsynJobEvent.key(); + + boolean configValue = Boolean.parseBoolean(_configDao.getValue(configKey)); + if (! configValue) + return; String routingKey = createRoutingKey(event); String eventDescription = event.getDescription(); diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 2d55f46..13ecb65 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -421,7 +421,12 @@ public enum Config { UCSSyncBladeInterval("Advanced", ManagementServer.class, Integer.class, "ucs.sync.blade.interval", "3600", "the interval cloudstack sync with UCS manager for available blades in case user remove blades from chassis without notifying CloudStack", null), - ManagementServerVendor("Advanced", ManagementServer.class, String.class, "mgt.server.vendor", "ACS", "the vendor of management server", null); + ManagementServerVendor("Advanced", ManagementServer.class, String.class, "mgt.server.vendor", "ACS", "the vendor of management server", null), + PublishActionEvent("Advanced", ManagementServer.class, Boolean.class, "publish.action.events", "true", "enable or disable publishing of action events on the event bus", null), + PublishAlertEvent("Advanced", ManagementServer.class, Boolean.class, "publish.alert.events", "true", "enable or disable publishing of alert events on the event bus", null), + PublishResourceStateEvent("Advanced", ManagementServer.class, Boolean.class, "publish.resource.state.events", "true", "enable or disable publishing of alert events on the event bus", null), + PublishUsageEvent("Advanced", ManagementServer.class, Boolean.class, "publish.usage.events", "true", "enable or disable publishing of usage events on the event bus", null), + PublishAsynJobEvent("Advanced", ManagementServer.class, Boolean.class, "publish.async.job.events", "true", "enable or disable publishing of usage events on the event bus", null); private final String _category; private final Class<?> _componentClass; diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java index 9370218..9786c8e 100755 --- a/server/src/com/cloud/test/DatabaseConfig.java +++ b/server/src/com/cloud/test/DatabaseConfig.java @@ -225,6 +225,11 @@ public class DatabaseConfig { s_configurationDescriptions.put("snapshot.test.weeks.per.month", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("snapshot.test.months.per.year", "Set it to a smaller value to take more recurring snapshots"); s_configurationDescriptions.put("hypervisor.type", "The type of hypervisor that this deployment will use."); + s_configurationDescriptions.put("publish.action.events", "enable or disable to control the publishing of action events on the event bus"); + s_configurationDescriptions.put("publish.alert.events", "enable or disable to control the publishing of alert events on the event bus"); + s_configurationDescriptions.put("publish.resource.state.events", "enable or disable to control the publishing of resource state events on the event bus"); + s_configurationDescriptions.put("publish.usage.events", "enable or disable to control the publishing of usage events on the event bus"); + s_configurationDescriptions.put("publish.async.job.events", "enable or disable to control the publishing of async job events on the event bus"); s_configurationComponents.put("host.stats.interval", "management-server"); @@ -298,6 +303,11 @@ public class DatabaseConfig { s_configurationComponents.put("snapshot.test.weeks.per.month", "SnapshotManager"); s_configurationComponents.put("snapshot.test.months.per.year", "SnapshotManager"); s_configurationComponents.put("hypervisor.type", "ManagementServer"); + s_configurationComponents.put("publish.action.events", "management-server"); + s_configurationComponents.put("publish.alert.events", "management-server"); + s_configurationComponents.put("publish.resource.state.events", "management-server"); + s_configurationComponents.put("publish.usage.events", "management-server"); + s_configurationComponents.put("publish.async.job.events", "management-server"); s_defaultConfigurationValues.put("host.stats.interval", "60000"); @@ -340,6 +350,11 @@ public class DatabaseConfig { s_defaultConfigurationValues.put("init", "false"); s_defaultConfigurationValues.put("cpu.overprovisioning.factor", "1"); s_defaultConfigurationValues.put("mem.overprovisioning.factor", "1"); + s_defaultConfigurationValues.put("publish.action.events", "true"); + s_defaultConfigurationValues.put("publish.alert.events", "true"); + s_defaultConfigurationValues.put("publish.resource.state.events", "true"); + s_defaultConfigurationValues.put("publish.usage.events", "true"); + s_defaultConfigurationValues.put("publish.async.job.events", "true"); } protected DatabaseConfig() { -- 1.8.0.msysgit.0