Search in sources :

Example 6 with Type

use of com.cloud.storage.Snapshot.Type in project cloudstack by apache.

the class SnapshotManagerImpl method allocSnapshot.

@Override
public Snapshot allocSnapshot(Long volumeId, Long policyId, String snapshotName, Snapshot.LocationType locationType) throws ResourceAllocationException {
    Account caller = CallContext.current().getCallingAccount();
    VolumeInfo volume = volFactory.getVolume(volumeId);
    supportedByHypervisor(volume);
    // Verify permissions
    _accountMgr.checkAccess(caller, null, true, volume);
    Type snapshotType = getSnapshotType(policyId);
    Account owner = _accountMgr.getAccount(volume.getAccountId());
    try {
        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
        _resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, new Long(volume.getSize()).longValue());
    } catch (ResourceAllocationException e) {
        if (snapshotType != Type.MANUAL) {
            String msg = "Snapshot resource limit exceeded for account id : " + owner.getId() + ". Failed to create recurring snapshots";
            s_logger.warn(msg);
            _alertMgr.sendAlert(AlertManager.AlertType.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
    String timeString = DateUtil.getDateDisplayString(DateUtil.GMT_TIMEZONE, new Date(), DateUtil.YYYYMMDD_FORMAT);
    VMInstanceVO vmInstance = _vmDao.findById(volume.getInstanceId());
    String vmDisplayName = "detached";
    if (vmInstance != null) {
        vmDisplayName = vmInstance.getHostName();
    }
    if (snapshotName == null)
        snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
    HypervisorType hypervisorType = HypervisorType.None;
    StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());
    if (storagePool.getScope() == ScopeType.ZONE) {
        hypervisorType = storagePool.getHypervisor();
        // at the time being, managed storage only supports XenServer, ESX(i), and KVM (i.e. not Hyper-V), so the VHD file type can be mapped to XenServer
        if (storagePool.isManaged() && HypervisorType.Any.equals(hypervisorType)) {
            if (ImageFormat.VHD.equals(volume.getFormat())) {
                hypervisorType = HypervisorType.XenServer;
            } else if (ImageFormat.OVA.equals(volume.getFormat())) {
                hypervisorType = HypervisorType.VMware;
            } else if (ImageFormat.QCOW2.equals(volume.getFormat())) {
                hypervisorType = HypervisorType.KVM;
            }
        }
    } else {
        hypervisorType = volume.getHypervisorType();
    }
    SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), snapshotName, (short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), volume.getMinIops(), volume.getMaxIops(), hypervisorType, locationType);
    SnapshotVO snapshot = _snapshotDao.persist(snapshotVO);
    if (snapshot == null) {
        throw new CloudRuntimeException("Failed to create snapshot for volume: " + volume.getId());
    }
    _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.snapshot);
    _resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
    return snapshot;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) Account(com.cloud.user.Account) ScopeType(com.cloud.storage.ScopeType) Type(com.cloud.storage.Snapshot.Type) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ResourceType(com.cloud.configuration.Resource.ResourceType) IntervalType(com.cloud.utils.DateUtil.IntervalType) ResourceObjectType(com.cloud.server.ResourceTag.ResourceObjectType) StoragePoolType(com.cloud.storage.Storage.StoragePoolType) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) Date(java.util.Date)

Aggregations

ResourceType (com.cloud.configuration.Resource.ResourceType)6 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)6 ResourceObjectType (com.cloud.server.ResourceTag.ResourceObjectType)6 ScopeType (com.cloud.storage.ScopeType)6 Type (com.cloud.storage.Snapshot.Type)6 SnapshotVO (com.cloud.storage.SnapshotVO)5 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)5 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)4 Account (com.cloud.user.Account)4 IntervalType (com.cloud.utils.DateUtil.IntervalType)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 VolumeVO (com.cloud.storage.VolumeVO)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 ResourceTagVO (com.cloud.tags.ResourceTagVO)2 Pair (com.cloud.utils.Pair)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2