Search in sources :

Example 86 with StoragePoolVO

use of com.cloud.storage.datastore.db.StoragePoolVO in project cosmic by MissionCriticalCloud.

the class SnapshotManagerImpl method supportedByHypervisor.

private boolean supportedByHypervisor(final VolumeInfo volume) {
    final HypervisorType hypervisorType;
    final StoragePoolVO storagePool = _storagePoolDao.findById(volume.getDataStore().getId());
    final ScopeType scope = storagePool.getScope();
    if (scope.equals(ScopeType.ZONE)) {
        hypervisorType = storagePool.getHypervisor();
    } else {
        hypervisorType = volume.getHypervisorType();
    }
    if (hypervisorType.equals(HypervisorType.KVM)) {
        List<HostVO> hosts = null;
        if (scope.equals(ScopeType.CLUSTER)) {
            final ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId());
            hosts = _resourceMgr.listAllHostsInCluster(cluster.getId());
        } else if (scope.equals(ScopeType.ZONE)) {
            hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, volume.getDataCenterId());
        }
        if (hosts != null && !hosts.isEmpty()) {
            final HostVO host = hosts.get(0);
            if (!hostSupportSnapsthotForVolume(host, volume)) {
                throw new CloudRuntimeException("KVM Snapshot is not supported: " + host.getId());
            }
        }
    }
    // if volume is attached to a vm in destroyed or expunging state; disallow
    if (volume.getInstanceId() != null) {
        final UserVmVO userVm = _vmDao.findById(volume.getInstanceId());
        if (userVm != null) {
            if (userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) {
                throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volume.getId() + " is associated with vm:" + userVm.getInstanceName() + " is in " + userVm.getState().toString() + " state");
            }
            if (userVm.getHypervisorType() == HypervisorType.KVM) {
                final List<SnapshotVO> activeSnapshots = _snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
                if (activeSnapshots.size() > 0) {
                    throw new InvalidParameterValueException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
                }
            }
            final List<VMSnapshotVO> activeVMSnapshots = _vmSnapshotDao.listByInstanceId(userVm.getId(), VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging);
            if (activeVMSnapshots.size() > 0) {
                throw new CloudRuntimeException("There is other active vm snapshot tasks on the instance to which the volume is attached, please try again later");
            }
        }
    }
    return true;
}
Also used : ScopeType(com.cloud.storage.ScopeType) UserVmVO(com.cloud.vm.UserVmVO) ClusterVO(com.cloud.dc.ClusterVO) HostVO(com.cloud.host.HostVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO)

Aggregations

StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)86 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)22 Test (org.junit.Test)18 HostVO (com.cloud.host.HostVO)15 VolumeVO (com.cloud.storage.VolumeVO)15 ArrayList (java.util.ArrayList)15 Answer (com.cloud.agent.api.Answer)14 Account (com.cloud.user.Account)13 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)11 StoragePool (com.cloud.storage.StoragePool)10 AttachAnswer (com.cloud.storage.command.AttachAnswer)10 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 RebootAnswer (com.cloud.agent.api.RebootAnswer)8 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)8 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)8