bug CS-14530: Whenver adding a new capacity check the state of the resource - if its disabled/enabled.

Reviewed By: Kishan
This commit is contained in:
Nitin Mehta 2012-04-19 14:24:12 +05:30
parent b31f383398
commit e04822eb70
6 changed files with 73 additions and 15 deletions

View File

@ -59,7 +59,7 @@ public class CapacityVO implements Capacity {
private short capacityType;
@Column(name="capacity_state")
private CapacityState capacityState = CapacityState.Enabled;
private CapacityState capacityState;
@Column(name=GenericDao.CREATED_COLUMN)
protected Date created;
@ -82,6 +82,7 @@ public class CapacityVO implements Capacity {
this.totalCapacity = totalCapacity;
this.capacityType = capacityType;
this.updateTime = new Date();
this.capacityState = CapacityState.Enabled;
}
public CapacityVO(Long dataCenterId, Long podId, Long clusterId, short capacityType, float usedPercentage) {
@ -90,6 +91,7 @@ public class CapacityVO implements Capacity {
this.clusterId = clusterId;
this.capacityType = capacityType;
this.usedPercentage = usedPercentage;
this.capacityState = CapacityState.Enabled;
}
@Override

View File

@ -39,10 +39,12 @@ import com.cloud.alert.dao.AlertDao;
import com.cloud.api.ApiDBUtils;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityManager;
import com.cloud.capacity.CapacityState;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.capacity.dao.CapacityDaoImpl.SummedCapacity;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenter.NetworkType;
@ -57,6 +59,7 @@ import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.resource.ResourceManager;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolVO;
@ -97,6 +100,7 @@ public class AlertManagerImpl implements AlertManager {
@Inject private StoragePoolDao _storagePoolDao;
@Inject private ConfigurationDao _configDao;
@Inject private ResourceManager _resourceMgr;
@Inject private ConfigurationManager _configMgr;
private Timer _timer = null;
private float _cpuOverProvisioningFactor = 1;
@ -319,15 +323,15 @@ public class AlertManagerImpl implements AlertManager {
// Calculate new Public IP capacity for Virtual Network
if (datacenter.getNetworkType() == NetworkType.Advanced){
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP);
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, datacenter.getAllocationState());
}
// Calculate new Public IP capacity for Direct Attached Network
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP);
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP, datacenter.getAllocationState());
if (datacenter.getNetworkType() == NetworkType.Advanced){
//Calculate VLAN's capacity
createOrUpdateVlanCapacity(dcId);
createOrUpdateVlanCapacity(dcId, datacenter.getAllocationState());
}
}
@ -342,7 +346,7 @@ public class AlertManagerImpl implements AlertManager {
long podId = pod.getId();
long dcId = pod.getDataCenterId();
createOrUpdateIpCapacity(dcId, podId, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
createOrUpdateIpCapacity(dcId, podId, CapacityVO.CAPACITY_TYPE_PRIVATE_IP, _configMgr.findPodAllocationState(pod));
}
if (s_logger.isDebugEnabled()) {
@ -355,7 +359,9 @@ public class AlertManagerImpl implements AlertManager {
}
}
private void createOrUpdateVlanCapacity(long dcId) {
private void createOrUpdateVlanCapacity(long dcId, AllocationState capacityState) {
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
@ -369,8 +375,11 @@ public class AlertManagerImpl implements AlertManager {
int allocatedVlans = _dcDao.countZoneVlans(dcId, true);
if (capacities.size() == 0){
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN);
_capacityDao.persist(newPublicIPCapacity);
CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN);
if (capacityState == AllocationState.Disabled){
newVlanCapacity.setCapacityState(CapacityState.Disabled);
}
_capacityDao.persist(newVlanCapacity);
}else if ( !(capacities.get(0).getUsedCapacity() == allocatedVlans
&& capacities.get(0).getTotalCapacity() == totalVlans) ){
CapacityVO capacity = capacities.get(0);
@ -382,7 +391,7 @@ public class AlertManagerImpl implements AlertManager {
}
public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType, AllocationState capacityState){
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
@ -407,6 +416,9 @@ public class AlertManagerImpl implements AlertManager {
if (capacities.size() == 0){
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
if (capacityState == AllocationState.Disabled){
newPublicIPCapacity.setCapacityState(CapacityState.Disabled);
}
_capacityDao.persist(newPublicIPCapacity);
}else if ( !(capacities.get(0).getUsedCapacity() == allocatedIPs
&& capacities.get(0).getTotalCapacity() == totalIPs) ){

View File

@ -32,14 +32,17 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.api.ApiDBUtils;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.exception.ConnectionException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.resource.ResourceListener;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ServerResource;
@ -94,7 +97,9 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
@Inject
StorageManager _storageMgr;
@Inject
SwiftManager _swiftMgr;
SwiftManager _swiftMgr;
@Inject
ConfigurationManager _configMgr;
private int _vmCapacityReleaseInterval;
private ScheduledExecutorService _executor;
@ -479,7 +484,7 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
@DB
@Override
public void updateCapacityForHost(HostVO host){
// prep the service offerings
// prepare the service offerings
List<ServiceOfferingVO> offerings = _offeringsDao.listAllIncludingRemoved();
Map<Long, ServiceOfferingVO> offeringsMap = new HashMap<Long, ServiceOfferingVO>();
for (ServiceOfferingVO offering : offerings) {
@ -557,12 +562,15 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
}
}else {
Transaction txn = Transaction.currentTxn();
CapacityState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(host.getClusterId())) == AllocationState.Disabled ?
CapacityState.Disabled : CapacityState.Enabled;
txn.start();
CapacityVO capacity = new CapacityVO(host.getId(),
host.getDataCenterId(), host.getPodId(), host.getClusterId(), usedMemory,
host.getTotalMemory(),
CapacityVO.CAPACITY_TYPE_MEMORY);
capacity.setReservedCapacity(reservedMemory);
capacity.setCapacityState(capacityState);
_capacityDao.persist(capacity);
capacity = new CapacityVO(
@ -574,6 +582,7 @@ public class CapacityManagerImpl implements CapacityManager, StateListener<State
(long)(host.getCpus().longValue() * host.getSpeed().longValue()),
CapacityVO.CAPACITY_TYPE_CPU);
capacity.setReservedCapacity(reservedCpu);
capacity.setCapacityState(capacityState);
_capacityDao.persist(capacity);
txn.commit();

View File

@ -34,6 +34,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.user.Account;
@ -220,4 +221,8 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
void checkPodCidrSubnets(long zoneId, Long podIdToBeSkipped, String cidr);
AllocationState findPodAllocationState(HostPodVO pod);
AllocationState findClusterAllocationState(ClusterVO cluster);
}

View File

@ -38,6 +38,7 @@ import org.apache.log4j.Logger;
import com.cloud.acl.SecurityChecker;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.ApiConstants.LDAPParams;
import com.cloud.api.commands.CreateDiskOfferingCmd;
import com.cloud.api.commands.CreateNetworkOfferingCmd;
@ -123,6 +124,7 @@ import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.org.Grouping;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectManager;
import com.cloud.service.ServiceOfferingVO;
@ -2706,7 +2708,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
}
private boolean validPod(long podId) {
return (_podDao.findById(podId) != null);
}
@ -3642,7 +3644,31 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
public ClusterVO getCluster(long id) {
return _clusterDao.findById(id);
}
@Override
public AllocationState findClusterAllocationState(ClusterVO cluster){
if(cluster.getAllocationState() == AllocationState.Disabled){
return AllocationState.Disabled;
}else if(ApiDBUtils.findPodById(cluster.getPodId()).getAllocationState() == AllocationState.Disabled){
return AllocationState.Disabled;
}else {
DataCenterVO zone = ApiDBUtils.findZoneById(cluster.getDataCenterId());
return zone.getAllocationState();
}
}
@Override
public AllocationState findPodAllocationState(HostPodVO pod){
if(pod.getAllocationState() == AllocationState.Disabled){
return AllocationState.Disabled;
}else {
DataCenterVO zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
return zone.getAllocationState();
}
}
private boolean allowIpRangeOverlap(VlanVO vlan, boolean forVirtualNetwork, long networkId) {
// FIXME - delete restriction for virtual network in the future
if (vlan.getVlanType() == VlanType.DirectAttached && !forVirtualNetwork) {

View File

@ -75,6 +75,7 @@ import com.cloud.api.commands.UpdateStoragePoolCmd;
import com.cloud.api.commands.UploadVolumeCmd;
import com.cloud.async.AsyncJobManager;
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityState;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.CheckPointManager;
@ -121,6 +122,7 @@ import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.network.NetworkManager;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.org.Grouping;
import com.cloud.org.Grouping.AllocationState;
import com.cloud.projects.Project.ListProjectResourcesCriteria;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceState;
@ -1997,14 +1999,16 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
long totalOverProvCapacity;
if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
totalOverProvCapacity = _overProvisioningFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All
// this for the inaccuracy of floats for big number multiplication.
totalOverProvCapacity = _overProvisioningFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All this for the inaccuracy of floats for big number multiplication.
} else {
totalOverProvCapacity = storagePool.getCapacityBytes();
}
if (capacities.size() == 0) {
CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
CapacityState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(storagePool.getClusterId())) == AllocationState.Disabled ?
CapacityState.Disabled : CapacityState.Enabled;
capacity.setCapacityState(capacityState);
_capacityDao.persist(capacity);
} else {
CapacityVO capacity = capacities.get(0);
@ -2024,7 +2028,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " + capacityType + " , DataCenterId - "
+ storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
}
@Override
public List<Long> getUpHostsInPool(long poolId) {
SearchCriteria<Long> sc = UpHostsInPoolSearch.create();