CLOUDSTACK-3047 java.lang.NullPointerException encountered when executing capacityChecker thread.

Changes:
- Added null check around clusterId, since its possible to have null clusterId for storagepool and host records
This commit is contained in:
Prachi Damle 2013-07-02 16:36:03 -07:00
parent 1bdb80a20b
commit 8780fef05a
2 changed files with 24 additions and 9 deletions

View File

@ -47,6 +47,7 @@ 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;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.ConnectionException;
import com.cloud.host.Host;
@ -623,15 +624,21 @@ public class CapacityManagerImpl extends ManagerBase implements CapacityManager,
}
}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);
CapacityState capacityState = CapacityState.Enabled;
if (host.getClusterId() != null) {
ClusterVO cluster = ApiDBUtils.findClusterById(host.getClusterId());
if (cluster != null) {
capacityState = _configMgr.findClusterAllocationState(cluster) == AllocationState.Disabled ? CapacityState.Disabled
: CapacityState.Enabled;
capacity.setCapacityState(capacityState);
}
}
_capacityDao.persist(capacity);
capacity = new CapacityVO(

View File

@ -892,16 +892,24 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
if (capacities.size() == 0) {
CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(),
storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
AllocationState allocationState = null;
if (storagePool.getScope() == ScopeType.ZONE) {
DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
allocationState = dc.getAllocationState();
AllocationState allocationState = dc.getAllocationState();
CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
: CapacityState.Enabled;
capacity.setCapacityState(capacityState);
} else {
allocationState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(storagePool.getClusterId()));
if (storagePool.getClusterId() != null) {
ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
if (cluster != null) {
AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled
: CapacityState.Enabled;
capacity.setCapacityState(capacityState);
}
}
}
CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
capacity.setCapacityState(capacityState);
_capacityDao.persist(capacity);
} else {
CapacityVO capacity = capacities.get(0);