cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject git commit: updated refs/heads/master to 4b89a45
Date Wed, 07 May 2014 05:09:39 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 23c7a893e -> 4b89a45e5


CLOUDSTACK-3272 Latest changes to add global configuration parameters to control the publishing
of events on the message bus


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4b89a45e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4b89a45e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4b89a45e

Branch: refs/heads/master
Commit: 4b89a45e571a34dff0191d501089aa9b1046bc08
Parents: 23c7a89
Author: root <root@devcloud.apache.org>
Authored: Tue May 6 04:59:23 2014 +0000
Committer: Murali Reddy <muralimmreddy@gmail.com>
Committed: Wed May 7 10:09:03 2014 +0530

----------------------------------------------------------------------
 .../src/com/cloud/event/UsageEventUtils.java         | 11 ++++++++++-
 .../src/com/cloud/network/NetworkStateListener.java  | 11 ++++++++++-
 .../engine/orchestration/NetworkOrchestrator.java    |  2 +-
 server/src/com/cloud/configuration/Config.java       |  7 ++++++-
 server/src/com/cloud/event/ActionEventUtils.java     | 11 +++++++++++
 server/src/com/cloud/event/AlertGenerator.java       | 11 +++++++++++
 .../src/com/cloud/network/IpAddressManagerImpl.java  |  2 +-
 server/src/com/cloud/storage/StorageManagerImpl.java |  2 +-
 .../storage/listener/SnapshotStateListener.java      | 11 +++++++++++
 .../cloud/storage/listener/VolumeStateListener.java  | 12 ++++++++++--
 server/src/com/cloud/test/DatabaseConfig.java        | 15 +++++++++++++++
 server/src/com/cloud/vm/UserVmManagerImpl.java       |  2 +-
 server/src/com/cloud/vm/UserVmStateListener.java     | 12 +++++++++++-
 .../cloudstack/affinity/AffinityApiUnitTest.java     |  6 ++++++
 14 files changed, 105 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/engine/components-api/src/com/cloud/event/UsageEventUtils.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/event/UsageEventUtils.java b/engine/components-api/src/com/cloud/event/UsageEventUtils.java
index f1707bd..69892d6 100644
--- a/engine/components-api/src/com/cloud/event/UsageEventUtils.java
+++ b/engine/components-api/src/com/cloud/event/UsageEventUtils.java
@@ -28,6 +28,7 @@ import javax.inject.Inject;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.Event;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
@@ -46,6 +47,7 @@ public class UsageEventUtils {
     private static DataCenterDao s_dcDao;
     private static final Logger s_logger = Logger.getLogger(UsageEventUtils.class);
     protected static EventBus s_eventBus = null;
+    protected static ConfigurationDao s_configDao;
 
     @Inject
     UsageEventDao usageEventDao;
@@ -53,6 +55,8 @@ public class UsageEventUtils {
     AccountDao accountDao;
     @Inject
     DataCenterDao dcDao;
+    @Inject
+    ConfigurationDao configDao;
 
     public UsageEventUtils() {
     }
@@ -62,6 +66,7 @@ public class UsageEventUtils {
         s_usageEventDao = usageEventDao;
         s_accountDao = accountDao;
         s_dcDao = dcDao;
+        s_configDao = configDao;
     }
 
     public static void publishUsageEvent(String usageType, long accountId, long zoneId, long
resourceId, String resourceName, Long offeringId, Long templateId,
@@ -161,7 +166,11 @@ public class UsageEventUtils {
     }
 
     private static void publishUsageEvent(String usageEventType, Long accountId, Long zoneId,
String resourceType, String resourceUUID) {
-
+        String configKey = "publish.usage.events";
+        String value = s_configDao.getValue(configKey);
+        boolean configValue = Boolean.parseBoolean(value);
+        if( !configValue)
+            return;
         try {
             s_eventBus = ComponentContext.getComponent(EventBus.class);
         } catch (NoSuchBeanDefinitionException nbe) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/engine/components-api/src/com/cloud/network/NetworkStateListener.java
----------------------------------------------------------------------
diff --git a/engine/components-api/src/com/cloud/network/NetworkStateListener.java b/engine/components-api/src/com/cloud/network/NetworkStateListener.java
index 0a5e033..c86f782 100644
--- a/engine/components-api/src/com/cloud/network/NetworkStateListener.java
+++ b/engine/components-api/src/com/cloud/network/NetworkStateListener.java
@@ -27,6 +27,7 @@ import javax.inject.Inject;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
@@ -44,14 +45,17 @@ public class NetworkStateListener implements StateListener<State, Event,
Network
     protected UsageEventDao _usageEventDao;
     @Inject
     protected NetworkDao _networkDao;
+    @Inject
+    protected ConfigurationDao _configDao;
 
     protected static EventBus s_eventBus = null;
 
     private static final Logger s_logger = Logger.getLogger(NetworkStateListener.class);
 
-    public NetworkStateListener(UsageEventDao usageEventDao, NetworkDao networkDao) {
+    public NetworkStateListener(UsageEventDao usageEventDao, NetworkDao networkDao, ConfigurationDao
configDao) {
         _usageEventDao = usageEventDao;
         _networkDao = networkDao;
+        _configDao = configDao;
     }
 
     @Override
@@ -68,6 +72,11 @@ public class NetworkStateListener implements StateListener<State, Event,
Network
 
     private void pubishOnEventBus(String event, String status, Network vo, State oldState,
State newState) {
 
+        String configKey = "publish.resource.state.events";
+        String value = _configDao.getValue(configKey);
+        boolean configValue = Boolean.parseBoolean(value);
+        if(!configValue)
+            return;
         try {
             s_eventBus = ComponentContext.getComponent(EventBus.class);
         } catch (NoSuchBeanDefinitionException nbe) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 96dafe9..0ad6d34 100755
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -574,7 +574,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
         _agentMgr.registerForHostEvents(this, true, false, true);
 
-        Network.State.getStateMachine().registerListener(new NetworkStateListener(_usageEventDao,
_networksDao));
+        Network.State.getStateMachine().registerListener(new NetworkStateListener(_usageEventDao,
_networksDao, _configDao));
 
         s_logger.info("Network Manager is configured.");
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 89f47d4..e500cd5 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -1915,7 +1915,12 @@ public enum Config {
             "timeout in seconds for each Virtual Router command being aggregated. The final
aggregation command timeout would be determined by this timeout * commands counts ",
             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;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/event/ActionEventUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/ActionEventUtils.java b/server/src/com/cloud/event/ActionEventUtils.java
index 363bb93..a30ec48 100755
--- a/server/src/com/cloud/event/ActionEventUtils.java
+++ b/server/src/com/cloud/event/ActionEventUtils.java
@@ -32,9 +32,11 @@ import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
 import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
+import com.cloud.configuration.Config;
 import com.cloud.domain.Domain;
 import com.cloud.event.dao.EventDao;
 import com.cloud.server.ManagementService;
@@ -56,6 +58,7 @@ public class ActionEventUtils {
     protected static UserDao s_userDao;
     protected static EventBus s_eventBus = null;
     protected static EntityManager s_entityMgr;
+    protected static ConfigurationDao s_configDao;
 
     public static final String EventDetails = "event_details";
     public static final String EventId = "event_id";
@@ -73,6 +76,8 @@ public class ActionEventUtils {
     ProjectDao projectDao;
     @Inject
     EntityManager entityMgr;
+    @Inject
+    ConfigurationDao configDao;
 
     public ActionEventUtils() {
     }
@@ -84,6 +89,7 @@ public class ActionEventUtils {
         s_userDao = userDao;
         s_projectDao = projectDao;
         s_entityMgr = entityMgr;
+        s_configDao = configDao;
     }
 
     public static Long onActionEvent(Long userId, Long accountId, Long domainId, String type,
String description) {
@@ -183,6 +189,11 @@ public class ActionEventUtils {
     }
 
     private static void publishOnEventBus(long userId, long accountId, String eventCategory,
String eventType, Event.State state, String description) {
+        String configKey = Config.PublishActionEvent.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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/event/AlertGenerator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/event/AlertGenerator.java b/server/src/com/cloud/event/AlertGenerator.java
index 5982eea..85c6075 100644
--- a/server/src/com/cloud/event/AlertGenerator.java
+++ b/server/src/com/cloud/event/AlertGenerator.java
@@ -29,9 +29,11 @@ import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 import org.springframework.stereotype.Component;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
+import com.cloud.configuration.Config;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.HostPodVO;
 import com.cloud.dc.dao.DataCenterDao;
@@ -46,11 +48,14 @@ public class AlertGenerator {
     private static DataCenterDao s_dcDao;
     private static HostPodDao s_podDao;
     protected static EventBus s_eventBus = null;
+    protected static ConfigurationDao s_configDao;
 
     @Inject
     DataCenterDao dcDao;
     @Inject
     HostPodDao podDao;
+    @Inject
+    ConfigurationDao configDao;
 
     public AlertGenerator() {
     }
@@ -62,6 +67,12 @@ public class AlertGenerator {
     }
 
     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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/network/IpAddressManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/IpAddressManagerImpl.java b/server/src/com/cloud/network/IpAddressManagerImpl.java
index 746221f..dc3a7ad 100644
--- a/server/src/com/cloud/network/IpAddressManagerImpl.java
+++ b/server/src/com/cloud/network/IpAddressManagerImpl.java
@@ -398,7 +398,7 @@ public class IpAddressManagerImpl extends ManagerBase implements IpAddressManage
         AssignIpAddressFromPodVlanSearch.join("vlan", podVlanSearch, podVlanSearch.entity().getId(),
AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
         AssignIpAddressFromPodVlanSearch.done();
 
-        Network.State.getStateMachine().registerListener(new NetworkStateListener(_usageEventDao,
_networksDao));
+        Network.State.getStateMachine().registerListener(new NetworkStateListener(_usageEventDao,
_networksDao, _configDao));
 
         s_logger.info("Network Manager is configured.");
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index c27a457..95e037c 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -488,7 +488,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         LocalStorageSearch.and("type", LocalStorageSearch.entity().getPoolType(), SearchCriteria.Op.IN);
         LocalStorageSearch.done();
 
-        Volume.State.getStateMachine().registerListener(new VolumeStateListener());
+        Volume.State.getStateMachine().registerListener(new VolumeStateListener(_configDao));
 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/storage/listener/SnapshotStateListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/listener/SnapshotStateListener.java b/server/src/com/cloud/storage/listener/SnapshotStateListener.java
index 45f0c5d..d995a82 100644
--- a/server/src/com/cloud/storage/listener/SnapshotStateListener.java
+++ b/server/src/com/cloud/storage/listener/SnapshotStateListener.java
@@ -22,12 +22,16 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.inject.Inject;
+
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
+import com.cloud.configuration.Config;
 import com.cloud.event.EventCategory;
 import com.cloud.server.ManagementService;
 import com.cloud.storage.Snapshot;
@@ -40,6 +44,8 @@ import com.cloud.utils.fsm.StateListener;
 public class SnapshotStateListener implements StateListener<State, Event, SnapshotVO>
{
 
     protected static EventBus s_eventBus = null;
+    @Inject
+    private ConfigurationDao _configDao;
 
     private static final Logger s_logger = Logger.getLogger(VolumeStateListener.class);
 
@@ -61,6 +67,11 @@ public class SnapshotStateListener implements StateListener<State, Event,
Snapsh
 
     private void pubishOnEventBus(String event, String status, Snapshot 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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/storage/listener/VolumeStateListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/listener/VolumeStateListener.java b/server/src/com/cloud/storage/listener/VolumeStateListener.java
index 1ab2755..1911a48 100644
--- a/server/src/com/cloud/storage/listener/VolumeStateListener.java
+++ b/server/src/com/cloud/storage/listener/VolumeStateListener.java
@@ -25,9 +25,11 @@ import java.util.Map;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 import org.apache.cloudstack.framework.events.EventBusException;
 
+import com.cloud.configuration.Config;
 import com.cloud.event.EventCategory;
 import com.cloud.server.ManagementService;
 import com.cloud.storage.Volume;
@@ -39,11 +41,12 @@ import com.cloud.utils.fsm.StateListener;
 public class VolumeStateListener implements StateListener<State, Event, Volume> {
 
     protected static EventBus s_eventBus = null;
+    protected ConfigurationDao _configDao;
 
     private static final Logger s_logger = Logger.getLogger(VolumeStateListener.class);
 
-    public VolumeStateListener() {
-
+    public VolumeStateListener(ConfigurationDao configDao) {
+        this._configDao = configDao;
     }
 
     @Override
@@ -60,6 +63,11 @@ public class VolumeStateListener implements StateListener<State, Event,
Volume>
 
     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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/test/DatabaseConfig.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/test/DatabaseConfig.java b/server/src/com/cloud/test/DatabaseConfig.java
index 07e4348..1c9b0db 100755
--- a/server/src/com/cloud/test/DatabaseConfig.java
+++ b/server/src/com/cloud/test/DatabaseConfig.java
@@ -234,6 +234,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");
         s_configurationComponents.put("storage.stats.interval", "management-server");
@@ -306,6 +311,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");
         s_defaultConfigurationValues.put("storage.stats.interval", "60000");
@@ -347,6 +357,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() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/vm/UserVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java
index dbca21b..fac5635 100755
--- a/server/src/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/com/cloud/vm/UserVmManagerImpl.java
@@ -1611,7 +1611,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager,
Vir
 
         _itMgr.registerGuru(VirtualMachine.Type.User, this);
 
-        VirtualMachine.State.getStateMachine().registerListener(new UserVmStateListener(_usageEventDao,
_networkDao, _nicDao, _offeringDao, _vmDao, this));
+        VirtualMachine.State.getStateMachine().registerListener(new UserVmStateListener(_usageEventDao,
_networkDao, _nicDao, _offeringDao, _vmDao, this, _configDao));
 
         String value = _configDao.getValue(Config.SetVmInternalNameUsingDisplayName.key());
         _instanceNameFlag = (value == null) ? false : Boolean.parseBoolean(value);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/src/com/cloud/vm/UserVmStateListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/UserVmStateListener.java b/server/src/com/cloud/vm/UserVmStateListener.java
index 6631ca3..a0088b8 100644
--- a/server/src/com/cloud/vm/UserVmStateListener.java
+++ b/server/src/com/cloud/vm/UserVmStateListener.java
@@ -29,8 +29,10 @@ import com.cloud.vm.dao.UserVmDao;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
 
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.events.EventBus;
 
+import com.cloud.configuration.Config;
 import com.cloud.event.EventCategory;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventUtils;
@@ -52,17 +54,20 @@ public class UserVmStateListener implements StateListener<State, VirtualMachine.
     @Inject protected ServiceOfferingDao _offeringDao;
     @Inject protected UserVmDao _userVmDao;
     @Inject protected UserVmManager _userVmMgr;
+    @Inject protected ConfigurationDao _configDao;
     private static final Logger s_logger = Logger.getLogger(UserVmStateListener.class);
 
     protected static EventBus s_eventBus = null;
 
-    public UserVmStateListener(UsageEventDao usageEventDao, NetworkDao networkDao, NicDao
nicDao, ServiceOfferingDao offeringDao, UserVmDao userVmDao, UserVmManager userVmMgr) {
+    public UserVmStateListener(UsageEventDao usageEventDao, NetworkDao networkDao, NicDao
nicDao, ServiceOfferingDao offeringDao, UserVmDao userVmDao, UserVmManager userVmMgr,
+            ConfigurationDao configDao) {
         this._usageEventDao = usageEventDao;
         this._networkDao = networkDao;
         this._nicDao = nicDao;
         this._offeringDao = offeringDao;
         this._userVmDao = userVmDao;
         this._userVmMgr = userVmMgr;
+        this._configDao = configDao;
     }
 
     @Override
@@ -113,6 +118,11 @@ public class UserVmStateListener implements StateListener<State, VirtualMachine.
 
     private void pubishOnEventBus(String event, String status, VirtualMachine vo, VirtualMachine.State
oldState, VirtualMachine.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) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4b89a45e/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
index e7581d6..7bfe351 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -57,6 +57,7 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.cloudstack.context.CallContext;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.framework.messagebus.MessageBus;
 import org.apache.cloudstack.test.utils.SpringUtils;
 
@@ -298,6 +299,11 @@ public class AffinityApiUnitTest {
             return Mockito.mock(MessageBus.class);
         }
 
+        @Bean
+        public ConfigurationDao configDao() {
+            return Mockito.mock(ConfigurationDao.class);
+        }
+
         public static class Library implements TypeFilter {
 
             @Override


Mime
View raw message