From d33278250dd5d33529aebe67b7e4a461e64e77e2 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Fri, 8 Aug 2014 09:42:05 -0700 Subject: [PATCH] CLOUDSTACK-7264:NPE while creating scheduled/recurring snapshots for the removed account with cleanup_needed=1. --- .../storage/snapshot/SnapshotSchedulerImpl.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index ba3d63a55fa..599e906a436 100644 --- a/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -52,7 +52,9 @@ import com.cloud.storage.dao.SnapshotDao; import com.cloud.storage.dao.SnapshotPolicyDao; import com.cloud.storage.dao.SnapshotScheduleDao; import com.cloud.storage.dao.VolumeDao; +import com.cloud.user.Account; import com.cloud.user.User; +import com.cloud.user.dao.AccountDao; import com.cloud.utils.DateUtil; import com.cloud.utils.DateUtil.IntervalType; import com.cloud.utils.NumbersUtil; @@ -84,6 +86,8 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu protected ConfigurationDao _configDao; @Inject protected ApiDispatcher _dispatcher; + @Inject + protected AccountDao _acctDao; protected AsyncJobDispatcher _asyncDispatcher; @@ -235,6 +239,14 @@ public class SnapshotSchedulerImpl extends ManagerBase implements SnapshotSchedu // this volume is not attached continue; } + Account volAcct = _acctDao.findById(volume.getAccountId()); + if (volAcct == null || volAcct.getState() == Account.State.disabled) { + // this account has been removed, so don't trigger recurring snapshot + if (s_logger.isDebugEnabled()) { + s_logger.debug("Skip snapshot for volume " + volume.getUuid() + " since its account has been removed or disabled"); + } + continue; + } if (_snapshotPolicyDao.findById(policyId) == null) { _snapshotScheduleDao.remove(snapshotToBeExecuted.getId()); }