bug 10674: For recurring snapshots when there is quota hit log it and send an email alert.

Reviewed by : Kishan.
This commit is contained in:
Nitin Mehta 2011-12-13 11:21:34 +05:30
parent b30ae76b67
commit 35e2640019
2 changed files with 17 additions and 4 deletions

View File

@ -48,6 +48,7 @@ public interface AlertManager extends Manager {
public static final short ALERT_TYPE_USAGE_SANITY_RESULT = 22;
public static final short ALERT_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 23;
public static final short ALERT_TYPE_LOCAL_STORAGE = 24;
public static final short ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED = 25; // Generated when the resource limit exceeds the limit. Currently used for recurring snapshots only
void clearAlert(short alertType, long dataCenterId, long podId);

View File

@ -40,6 +40,7 @@ import com.cloud.agent.api.ManageSnapshotAnswer;
import com.cloud.agent.api.ManageSnapshotCommand;
import com.cloud.agent.api.downloadSnapshotFromSwiftCommand;
import com.cloud.agent.api.to.SwiftTO;
import com.cloud.alert.AlertManager;
import com.cloud.api.commands.CreateSnapshotPolicyCmd;
import com.cloud.api.commands.DeleteSnapshotPoliciesCmd;
import com.cloud.api.commands.ListRecurringSnapshotScheduleCmd;
@ -167,6 +168,8 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
@Inject
protected AccountManager _accountMgr;
@Inject
private AlertManager _alertMgr;
@Inject
protected ClusterDao _clusterDao;
@Inject
private UsageEventDao _usageEventDao;
@ -1401,9 +1404,19 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
// Verify permissions
_accountMgr.checkAccess(caller, null, volume);
Type snapshotType = getSnapshotType(policyId);
Account owner = _accountMgr.getAccount(volume.getAccountId());
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
try{
_resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
} catch (ResourceAllocationException e){
if (snapshotType == Type.RECURRING){
String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots";
s_logger.warn(msg);
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 0L, 0L, msg,
"Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots; please use updateResourceLimit to increase the limit");
}
throw e;
}
// Determine the name for this snapshot
// Snapshot Name: VMInstancename + volumeName + timeString
@ -1417,8 +1430,7 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma
String snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
// Create the Snapshot object and save it so we can return it to the
// user
Type snapshotType = getSnapshotType(policyId);
// user
HypervisorType hypervisorType = this._volsDao.getHypervisorType(volumeId);
SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), null, snapshotName,
(short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType);