4040import com .cloud .agent .api .ManageSnapshotCommand ;
4141import com .cloud .agent .api .downloadSnapshotFromSwiftCommand ;
4242import com .cloud .agent .api .to .SwiftTO ;
43+ import com .cloud .alert .AlertManager ;
4344import com .cloud .api .commands .CreateSnapshotPolicyCmd ;
4445import com .cloud .api .commands .DeleteSnapshotPoliciesCmd ;
4546import com .cloud .api .commands .ListRecurringSnapshotScheduleCmd ;
@@ -167,6 +168,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
167168 @ Inject
168169 protected AccountManager _accountMgr ;
169170 @ Inject
171+ private AlertManager _alertMgr ;
172+ @ Inject
170173 protected ClusterDao _clusterDao ;
171174 @ Inject
172175 private UsageEventDao _usageEventDao ;
@@ -1401,9 +1404,19 @@ public SnapshotVO allocSnapshot(Long volumeId, Long policyId) throws ResourceAll
14011404
14021405 // Verify permissions
14031406 _accountMgr .checkAccess (caller , null , volume );
1404-
1407+ Type snapshotType = getSnapshotType ( policyId );
14051408 Account owner = _accountMgr .getAccount (volume .getAccountId ());
1406- _resourceLimitMgr .checkResourceLimit (owner , ResourceType .snapshot );
1409+ try {
1410+ _resourceLimitMgr .checkResourceLimit (owner , ResourceType .snapshot );
1411+ } catch (ResourceAllocationException e ){
1412+ if (snapshotType == Type .RECURRING ){
1413+ String msg = "Snapshot resource limit exceeded for account id : " + owner .getId () + ". Failed to create recurring snapshots" ;
1414+ s_logger .warn (msg );
1415+ _alertMgr .sendAlert (AlertManager .ALERT_TYPE_UPDATE_RESOURCE_COUNT , 0L , 0L , msg ,
1416+ "Snapshot resource limit exceeded for account id : " + owner .getId () + ". Failed to create recurring snapshots; please use updateResourceLimit to increase the limit" );
1417+ }
1418+ throw e ;
1419+ }
14071420
14081421 // Determine the name for this snapshot
14091422 // Snapshot Name: VMInstancename + volumeName + timeString
@@ -1417,8 +1430,7 @@ public SnapshotVO allocSnapshot(Long volumeId, Long policyId) throws ResourceAll
14171430 String snapshotName = vmDisplayName + "_" + volume .getName () + "_" + timeString ;
14181431
14191432 // Create the Snapshot object and save it so we can return it to the
1420- // user
1421- Type snapshotType = getSnapshotType (policyId );
1433+ // user
14221434 HypervisorType hypervisorType = this ._volsDao .getHypervisorType (volumeId );
14231435 SnapshotVO snapshotVO = new SnapshotVO (volume .getDataCenterId (), volume .getAccountId (), volume .getDomainId (), volume .getId (), volume .getDiskOfferingId (), null , snapshotName ,
14241436 (short ) snapshotType .ordinal (), snapshotType .name (), volume .getSize (), hypervisorType );
0 commit comments