Skip to content

Commit 75832c8

Browse files
mlsorensenchipchilders
authored andcommitted
CLOUDSTACK-2281: Fix NPE in the planner, in the case that pool ID cannot be looked up in database when deploying a VM
This fixes a null pointer if selected pool on which to deploy is unable to be looked up via id. Used the same coding style found in the original code (large if/else block). If this is accepted, I'll fix master too. This patch doesn't apply cleanly, but the code is very similar. Testing: Fixed broken system, tested against devcloud to ensure that it didn't break a stock/fresh install (advanced zone with 3 storage pools). Restarted VMs to ensure that the planner still functioned that way as well. Signed-off-by: Chip Childers <chip.childers@gmail.com>
1 parent 7d877ce commit 75832c8

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

‎server/src/com/cloud/deploy/FirstFitPlanner.java‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -746,37 +746,43 @@ protected Pair<Map<Volume, List<StoragePool>>, List<Volume>> findSuitablePoolsFo
746746
//If the plan specifies a poolId, it means that this VM's ROOT volume is ready and the pool should be reused.
747747
//In this case, also check if rest of the volumes are ready and can be reused.
748748
if(plan.getPoolId() != null){
749-
s_logger.debug("Volume has pool already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId());
749+
s_logger.debug("Volume has pool(" + plan.getPoolId() + ") already allocated, checking if pool can be reused, poolId: "+toBeCreated.getPoolId());
750750
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
751751
StoragePoolVO pool;
752752
if(toBeCreated.getPoolId() != null){
753+
s_logger.debug("finding pool by id '" + toBeCreated.getPoolId() + "'");
753754
pool = _storagePoolDao.findById(toBeCreated.getPoolId());
754755
}else{
756+
s_logger.debug("finding pool by id '" + plan.getPoolId() + "'");
755757
pool = _storagePoolDao.findById(plan.getPoolId());
756758
}
757-
758-
if(!pool.isInMaintenance()){
759-
if(!avoid.shouldAvoid(pool)){
760-
long exstPoolDcId = pool.getDataCenterId();
761-
762-
long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
763-
long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
764-
if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){
765-
s_logger.debug("Planner need not allocate a pool for this volume since its READY");
766-
suitablePools.add(pool);
767-
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
768-
if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
769-
readyAndReusedVolumes.add(toBeCreated);
759+
760+
if(pool != null){
761+
if(!pool.isInMaintenance()){
762+
if(!avoid.shouldAvoid(pool)){
763+
long exstPoolDcId = pool.getDataCenterId();
764+
765+
long exstPoolPodId = pool.getPodId() != null ? pool.getPodId() : -1;
766+
long exstPoolClusterId = pool.getClusterId() != null ? pool.getClusterId() : -1;
767+
if(plan.getDataCenterId() == exstPoolDcId && plan.getPodId() == exstPoolPodId && plan.getClusterId() == exstPoolClusterId){
768+
s_logger.debug("Planner need not allocate a pool for this volume since its READY");
769+
suitablePools.add(pool);
770+
suitableVolumeStoragePools.put(toBeCreated, suitablePools);
771+
if (!(toBeCreated.getState() == Volume.State.Allocated || toBeCreated.getState() == Volume.State.Creating)) {
772+
readyAndReusedVolumes.add(toBeCreated);
773+
}
774+
continue;
775+
}else{
776+
s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume");
770777
}
771-
continue;
772778
}else{
773-
s_logger.debug("Pool of the volume does not fit the specified plan, need to reallocate a pool for this volume");
779+
s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume");
774780
}
775781
}else{
776-
s_logger.debug("Pool of the volume is in avoid set, need to reallocate a pool for this volume");
782+
s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume");
777783
}
778784
}else{
779-
s_logger.debug("Pool of the volume is in maintenance, need to reallocate a pool for this volume");
785+
s_logger.debug("Unable to find pool by provided id");
780786
}
781787
}
782788

0 commit comments

Comments
 (0)