From d49326235434c211701bde84621dc1af7e797d0a Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Fri, 20 Apr 2012 10:34:15 +0530 Subject: [PATCH] bug CS-14530: Whwnever creating an agent of type Routing update the capacity state as there is a transition in the resource state of the host. Reviewed By: Kishan --- .../com/cloud/resource/ResourceManagerImpl.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 871aef984c4..7dba91792dd 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -43,6 +43,7 @@ import com.cloud.agent.manager.AgentAttache; import com.cloud.agent.manager.allocator.PodAllocator; import com.cloud.agent.transport.Request; import com.cloud.api.ApiConstants; +import com.cloud.api.ApiDBUtils; import com.cloud.api.commands.AddClusterCmd; import com.cloud.api.commands.AddHostCmd; import com.cloud.api.commands.AddSecondaryStorageCmd; @@ -60,6 +61,7 @@ import com.cloud.capacity.dao.CapacityDao; import com.cloud.cluster.ClusterManager; import com.cloud.cluster.ManagementServerNode; import com.cloud.configuration.Config; +import com.cloud.configuration.ConfigurationManager; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.ClusterDetailsDao; import com.cloud.dc.ClusterVO; @@ -95,6 +97,7 @@ import com.cloud.network.dao.IPAddressDao; import com.cloud.org.Cluster; import com.cloud.org.Grouping; import com.cloud.org.Managed; +import com.cloud.org.Grouping.AllocationState; import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.GuestOSCategoryVO; import com.cloud.storage.StorageManager; @@ -201,6 +204,8 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma protected Adapters _podAllocators = null; @Inject protected VMTemplateDao _templateDao; + @Inject + protected ConfigurationManager _configMgr; protected long _nodeId = ManagementServerNode.getManagementServerId(); @@ -1036,7 +1041,14 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma } // TO DO - Make it more granular and have better conversion into capacity type - _capacityDao.updateCapacityState(null, null, null, host.getId(), nextState.toString()); + if(host.getType() == Type.Routing && host.getClusterId() != null){ + AllocationState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId())); + if (capacityState == AllocationState.Enabled && nextState != ResourceState.Enabled){ + capacityState = AllocationState.Disabled; + } + _capacityDao.updateCapacityState(null, null, null, host.getId(), capacityState.toString()); + } + return _hostDao.updateResourceState(currentState, event, nextState, host); }