Search in sources :

Example 56 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class StorageOrchestrator method handleSnapshotMigration.

private void handleSnapshotMigration(Long srcDataStoreId, Date start, Date end, MigrationPolicy policy, List<Future<AsyncCallFuture<DataObjectResult>>> futures, Map<Long, Pair<Long, Long>> storageCapacities, ThreadPoolExecutor executor) {
    DataStore srcDatastore = dataStoreManager.getDataStore(srcDataStoreId, DataStoreRole.Image);
    List<SnapshotDataStoreVO> snaps = snapshotDataStoreDao.findSnapshots(srcDataStoreId, start, end);
    if (!snaps.isEmpty()) {
        for (SnapshotDataStoreVO snap : snaps) {
            SnapshotVO snapshotVO = snapshotDao.findById(snap.getSnapshotId());
            SnapshotInfo snapshotInfo = snapshotFactory.getSnapshot(snapshotVO.getSnapshotId(), DataStoreRole.Image);
            SnapshotInfo parentSnapshot = snapshotInfo.getParent();
            if (parentSnapshot == null && policy == MigrationPolicy.COMPLETE) {
                List<Long> dstores = migrationHelper.sortDataStores(storageCapacities);
                Long storeId = dstores.get(0);
                if (storeId.equals(srcDataStoreId)) {
                    storeId = dstores.get(1);
                }
                DataStore datastore = dataStoreManager.getDataStore(storeId, DataStoreRole.Image);
                futures.add(executor.submit(new MigrateDataTask(snapshotInfo, srcDatastore, datastore)));
            }
            if (parentSnapshot != null) {
                DataStore parentDS = dataStoreManager.getDataStore(parentSnapshot.getDataStore().getId(), DataStoreRole.Image);
                if (parentDS.getId() != snapshotInfo.getDataStore().getId()) {
                    futures.add(executor.submit(new MigrateDataTask(snapshotInfo, srcDatastore, parentDS)));
                }
            }
        }
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 57 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project CloudStack-archive by CloudStack-extras.

the class SnapshotDaoTest method testListBy.

public void testListBy() {
    SnapshotDaoImpl dao = ComponentLocator.inject(SnapshotDaoImpl.class);
    List<SnapshotVO> snapshots = dao.listByInstanceId(3, Snapshot.Status.BackedUp);
    for (SnapshotVO snapshot : snapshots) {
        Assert.assertTrue(snapshot.getStatus() == Snapshot.Status.BackedUp);
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotDaoImpl(com.cloud.storage.dao.SnapshotDaoImpl)

Example 58 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class TemplateManagerImpl method templateIsDeleteable.

@Override
public boolean templateIsDeleteable(VMTemplateHostVO templateHostRef) {
    VMTemplateVO template = _tmpltDao.findByIdIncludingRemoved(templateHostRef.getTemplateId());
    long templateId = template.getId();
    HostVO secondaryStorageHost = _hostDao.findById(templateHostRef.getHostId());
    long zoneId = secondaryStorageHost.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    // Check if there are VMs running in the template host ref's zone that
    // use the template
    List<VMInstanceVO> nonExpungedVms = _vmInstanceDao.listNonExpungedByZoneAndTemplate(zoneId, templateId);
    if (!nonExpungedVms.isEmpty()) {
        s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are non-expunged VMs deployed from this template.");
        return false;
    }
    List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(templateId);
    // check if there is any VM using this ISO.
    if (!userVmUsingIso.isEmpty()) {
        s_logger.debug("ISO " + template.getName() + " in zone " + zone.getName() + " is not deleteable because it is attached to " + userVmUsingIso.size() + " VMs");
        return false;
    }
    // Check if there are any snapshots for the template in the template
    // host ref's zone
    List<VolumeVO> volumes = _volumeDao.findByTemplateAndZone(templateId, zoneId);
    for (VolumeVO volume : volumes) {
        List<SnapshotVO> snapshots = _snapshotDao.listByVolumeIdVersion(volume.getId(), "2.1");
        if (!snapshots.isEmpty()) {
            s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are 2.1 snapshots using this template.");
            return false;
        }
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) SnapshotVO(com.cloud.storage.SnapshotVO) VolumeVO(com.cloud.storage.VolumeVO) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) VMTemplateHostVO(com.cloud.storage.VMTemplateHostVO) HostVO(com.cloud.host.HostVO)

Example 59 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cloudstack by apache.

the class StorageSystemDataMotionStrategy method handleCreateVolumeFromSnapshotBothOnStorageSystem.

private void handleCreateVolumeFromSnapshotBothOnStorageSystem(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
    CopyCmdAnswer copyCmdAnswer = null;
    String errMsg = null;
    try {
        HostVO hostVO = getHost(snapshotInfo);
        boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
        boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
        if (usingBackendSnapshot && !computeClusterSupportsResign) {
            String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
            LOGGER.warn(noSupportForResignErrMsg);
            throw new CloudRuntimeException(noSupportForResignErrMsg);
        }
        boolean canStorageSystemCreateVolumeFromVolume = canStorageSystemCreateVolumeFromVolume(snapshotInfo);
        boolean useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsResign);
        VolumeDetailVO volumeDetail = null;
        if (useCloning) {
            volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), false);
            volumeDetail = volumeDetailsDao.persist(volumeDetail);
        }
        // at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
        DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
        SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
        // update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
        _volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
        AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
        VolumeApiResult result = future.get();
        if (volumeDetail != null) {
            volumeDetailsDao.remove(volumeDetail.getId());
        }
        if (result.isFailed()) {
            LOGGER.warn("Failed to create a volume: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        volumeInfo.processEvent(Event.MigrationRequested);
        volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
        if (useCloning) {
            copyCmdAnswer = performResignature(volumeInfo, hostVO);
        } else {
            // asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning
            // even when we don't need those hosts to do this kind of copy work
            hostVO = getHost(snapshotInfo.getDataCenterId(), false);
            copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && !StringUtils.isEmpty(copyCmdAnswer.getDetails())) {
                errMsg = copyCmdAnswer.getDetails();
            } else {
                errMsg = "Unable to create volume from snapshot";
            }
        }
    } catch (Exception ex) {
        errMsg = ex.getMessage() != null ? ex.getMessage() : "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateVolumeFromSnapshotBothOnStorageSystem'";
    }
    CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) HostVO(com.cloud.host.HostVO) TimeoutException(java.util.concurrent.TimeoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 60 with SnapshotVO

use of com.cloud.storage.SnapshotVO in project cosmic by MissionCriticalCloud.

the class ResourceLimitManagerImpl method configure.

@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    ResourceCountSearch = _resourceCountDao.createSearchBuilder();
    ResourceCountSearch.and("id", ResourceCountSearch.entity().getId(), SearchCriteria.Op.IN);
    ResourceCountSearch.and("accountId", ResourceCountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
    ResourceCountSearch.and("domainId", ResourceCountSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
    ResourceCountSearch.done();
    templateSizeSearch = _vmTemplateStoreDao.createSearchBuilder(SumCount.class);
    templateSizeSearch.select("sum", Func.SUM, templateSizeSearch.entity().getSize());
    templateSizeSearch.and("downloadState", templateSizeSearch.entity().getDownloadState(), Op.EQ);
    templateSizeSearch.and("destroyed", templateSizeSearch.entity().getDestroyed(), Op.EQ);
    final SearchBuilder<VMTemplateVO> join1 = _vmTemplateDao.createSearchBuilder();
    join1.and("accountId", join1.entity().getAccountId(), Op.EQ);
    templateSizeSearch.join("templates", join1, templateSizeSearch.entity().getTemplateId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
    templateSizeSearch.done();
    snapshotSizeSearch = _snapshotDataStoreDao.createSearchBuilder(SumCount.class);
    snapshotSizeSearch.select("sum", Func.SUM, snapshotSizeSearch.entity().getPhysicalSize());
    snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ);
    snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ);
    final SearchBuilder<SnapshotVO> join2 = _snapshotDao.createSearchBuilder();
    join2.and("accountId", join2.entity().getAccountId(), Op.EQ);
    snapshotSizeSearch.join("snapshots", join2, snapshotSizeSearch.entity().getSnapshotId(), join2.entity().getId(), JoinBuilder.JoinType.INNER);
    snapshotSizeSearch.done();
    _resourceCountCheckInterval = NumbersUtil.parseInt(_configDao.getValue(Config.ResourceCountCheckInterval.key()), 0);
    if (_resourceCountCheckInterval > 0) {
        _rcExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("ResourceCountChecker"));
    }
    try {
        projectResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPublicIPs.key())));
        projectResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSnapshots.key())));
        projectResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectTemplates.key())));
        projectResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectUserVms.key())));
        projectResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVolumes.key())));
        projectResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectNetworks.key())));
        projectResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectVpcs.key())));
        projectResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectCpus.key())));
        projectResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectMemory.key())));
        projectResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectPrimaryStorage.key())));
        projectResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxProjectSecondaryStorage.key())));
        accountResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key())));
        accountResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key())));
        accountResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key())));
        accountResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key())));
        accountResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key())));
        accountResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountNetworks.key())));
        accountResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVpcs.key())));
        accountResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountCpus.key())));
        accountResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountMemory.key())));
        accountResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPrimaryStorage.key())));
        accountResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSecondaryStorage.key())));
        domainResourceLimitMap.put(Resource.ResourceType.public_ip, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPublicIPs.key())));
        domainResourceLimitMap.put(Resource.ResourceType.snapshot, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSnapshots.key())));
        domainResourceLimitMap.put(Resource.ResourceType.template, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainTemplates.key())));
        domainResourceLimitMap.put(Resource.ResourceType.user_vm, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainUserVms.key())));
        domainResourceLimitMap.put(Resource.ResourceType.volume, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVolumes.key())));
        domainResourceLimitMap.put(Resource.ResourceType.network, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainNetworks.key())));
        domainResourceLimitMap.put(Resource.ResourceType.vpc, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainVpcs.key())));
        domainResourceLimitMap.put(Resource.ResourceType.cpu, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainCpus.key())));
        domainResourceLimitMap.put(Resource.ResourceType.memory, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainMemory.key())));
        domainResourceLimitMap.put(Resource.ResourceType.primary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainPrimaryStorage.key())));
        domainResourceLimitMap.put(Resource.ResourceType.secondary_storage, Long.parseLong(_configDao.getValue(Config.DefaultMaxDomainSecondaryStorage.key())));
    } catch (final NumberFormatException e) {
        s_logger.error("NumberFormatException during configuration", e);
        throw new ConfigurationException("Configuration failed due to NumberFormatException, see log for the stacktrace");
    }
    return true;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) ConfigurationException(javax.naming.ConfigurationException) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) VMTemplateVO(com.cloud.storage.VMTemplateVO) SumCount(com.cloud.storage.dao.VolumeDaoImpl.SumCount)

Aggregations

SnapshotVO (com.cloud.storage.SnapshotVO)105 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)29 VolumeVO (com.cloud.storage.VolumeVO)28 Account (com.cloud.user.Account)22 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 ArrayList (java.util.ArrayList)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)16 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)16 HostVO (com.cloud.host.HostVO)15 VMTemplateVO (com.cloud.storage.VMTemplateVO)15 DB (com.cloud.utils.db.DB)14 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)12 ConfigurationException (javax.naming.ConfigurationException)12 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 UserVmVO (com.cloud.vm.UserVmVO)10 VMInstanceVO (com.cloud.vm.VMInstanceVO)10 ActionEvent (com.cloud.event.ActionEvent)9