Search in sources :

Example 11 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VmwareStorageMotionStrategy method updateVolumesAfterMigration.

private void updateVolumesAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        boolean updated = false;
        VolumeInfo volume = entry.getKey();
        StoragePool pool = (StoragePool) entry.getValue();
        for (VolumeObjectTO volumeTo : volumeTos) {
            if (volume.getId() == volumeTo.getId()) {
                VolumeVO volumeVO = volDao.findById(volume.getId());
                Long oldPoolId = volumeVO.getPoolId();
                volumeVO.setPath(volumeTo.getPath());
                if (volumeTo.getChainInfo() != null) {
                    volumeVO.setChainInfo(volumeTo.getChainInfo());
                }
                volumeVO.setLastPoolId(oldPoolId);
                volumeVO.setFolder(pool.getPath());
                volumeVO.setPodId(pool.getPodId());
                volumeVO.setPoolId(pool.getId());
                volDao.update(volume.getId(), volumeVO);
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("Volume path wasn't updated for volume " + volume + " after it was migrated.");
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map)

Example 12 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class ElastistorPrimaryDataStoreDriver method deleteAsync.

@Override
public void deleteAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CommandResult> callback) {
    String errMsg = null;
    StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
    if (!(storagePool.isManaged())) {
        super.deleteAsync(dataStore, dataObject, callback);
        return;
    }
    if (dataObject.getType() == DataObjectType.VOLUME) {
        VolumeInfo volumeInfo = (VolumeInfo) dataObject;
        long storagePoolId = dataStore.getId();
        boolean result = false;
        try {
            result = ElastistorUtil.deleteElastistorVolume(volumeInfo.getUuid());
        } catch (Throwable e) {
            e.printStackTrace();
            CommandResult result2 = new CommandResult();
            result2.setResult(e.toString());
            callback.complete(result2);
        }
        if (result) {
            long usedBytes = storagePool.getUsedBytes();
            long capacityIops = storagePool.getCapacityIops();
            usedBytes -= volumeInfo.getSize();
            capacityIops += volumeInfo.getMaxIops();
            storagePool.setUsedBytes(usedBytes < 0 ? 0 : usedBytes);
            storagePool.setCapacityIops(capacityIops < 0 ? 0 : capacityIops);
            _storagePoolDao.update(storagePoolId, storagePool);
        } else {
            errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
        }
    } else {
        errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to deleteAsync";
    }
    CommandResult result = new CommandResult();
    result.setResult(errMsg);
    callback.complete(result);
}
Also used : StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 13 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeOrchestrator method migrateVolumes.

@Override
public void migrateVolumes(VirtualMachine vm, VirtualMachineTO vmTo, Host srcHost, Host destHost, Map<Volume, StoragePool> volumeToPool) {
    // Check if all the vms being migrated belong to the vm.
    // Check if the storage pool is of the right type.
    // Create a VolumeInfo to DataStore map too.
    Map<VolumeInfo, DataStore> volumeMap = new HashMap<VolumeInfo, DataStore>();
    for (Map.Entry<Volume, StoragePool> entry : volumeToPool.entrySet()) {
        Volume volume = entry.getKey();
        StoragePool storagePool = entry.getValue();
        StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(storagePool.getId(), DataStoreRole.Primary);
        if (volume.getInstanceId() != vm.getId()) {
            throw new CloudRuntimeException("Volume " + volume + " that has to be migrated doesn't belong to the" + " instance " + vm);
        }
        if (destPool == null) {
            throw new CloudRuntimeException("Failed to find the destination storage pool " + storagePool.getId());
        }
        volumeMap.put(volFactory.getVolume(volume.getId()), (DataStore) destPool);
    }
    AsyncCallFuture<CommandResult> future = volService.migrateVolumes(volumeMap, vmTo, srcHost, destHost);
    try {
        CommandResult result = future.get();
        if (result.isFailed()) {
            s_logger.debug("Failed to migrated vm " + vm + " along with its volumes. " + result.getResult());
            throw new CloudRuntimeException("Failed to migrated vm " + vm + " along with its volumes. ");
        }
    } catch (InterruptedException e) {
        s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to migrated vm " + vm + " along with its volumes.", e);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CommandResult(org.apache.cloudstack.storage.command.CommandResult) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class VolumeOrchestrator method prepare.

@Override
public void prepare(VirtualMachineProfile vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException {
    if (dest == null) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("DeployDestination cannot be null, cannot prepare Volumes for the vm: " + vm);
        }
        throw new CloudRuntimeException("Unable to prepare Volume for vm because DeployDestination is null, vm:" + vm);
    }
    // don't allow to start vm that doesn't have a root volume
    if (_volsDao.findByInstanceAndType(vm.getId(), Volume.Type.ROOT).isEmpty()) {
        throw new CloudRuntimeException("Unable to prepare volumes for vm as ROOT volume is missing");
    }
    List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId());
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Checking if we need to prepare " + vols.size() + " volumes for " + vm);
    }
    List<VolumeTask> tasks = getTasks(vols, dest.getStorageForDisks(), vm);
    Volume vol = null;
    StoragePool pool = null;
    for (VolumeTask task : tasks) {
        if (task.type == VolumeTaskType.NOP) {
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            vol = task.volume;
        } else if (task.type == VolumeTaskType.MIGRATE) {
            pool = (StoragePool) dataStoreMgr.getDataStore(task.pool.getId(), DataStoreRole.Primary);
            vol = migrateVolume(task.volume, pool);
        } else if (task.type == VolumeTaskType.RECREATE) {
            Pair<VolumeVO, DataStore> result = recreateVolume(task.volume, vm, dest);
            pool = (StoragePool) dataStoreMgr.getDataStore(result.second().getId(), DataStoreRole.Primary);
            vol = result.first();
        }
        VolumeInfo volumeInfo = volFactory.getVolume(vol.getId());
        DataTO volTO = volumeInfo.getTO();
        DiskTO disk = storageMgr.getDiskWithThrottling(volTO, vol.getVolumeType(), vol.getDeviceId(), vol.getPath(), vm.getServiceOfferingId(), vol.getDiskOfferingId());
        DataStore dataStore = dataStoreMgr.getDataStore(vol.getPoolId(), DataStoreRole.Primary);
        disk.setDetails(getDetails(volumeInfo, dataStore));
        vm.addDisk(disk);
        // If hypervisor is vSphere, check for clone type setting.
        if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
            // retrieve clone flag.
            UserVmCloneType cloneType = UserVmCloneType.linked;
            Boolean value = CapacityManager.VmwareCreateCloneFull.valueIn(vol.getPoolId());
            if (value != null && value) {
                cloneType = UserVmCloneType.full;
            }
            try {
                UserVmCloneSettingVO cloneSettingVO = _vmCloneSettingDao.findByVmId(vm.getId());
                if (cloneSettingVO != null) {
                    if (!cloneSettingVO.getCloneType().equals(cloneType.toString())) {
                        cloneSettingVO.setCloneType(cloneType.toString());
                        _vmCloneSettingDao.update(cloneSettingVO.getVmId(), cloneSettingVO);
                    }
                } else {
                    UserVmCloneSettingVO vmCloneSettingVO = new UserVmCloneSettingVO(vm.getId(), cloneType.toString());
                    _vmCloneSettingDao.persist(vmCloneSettingVO);
                }
            } catch (Throwable e) {
                s_logger.debug("[NSX_PLUGIN_LOG] ERROR: " + e.getMessage());
            }
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) UserVmCloneSettingVO(com.cloud.vm.UserVmCloneSettingVO) DataTO(com.cloud.agent.api.to.DataTO) VolumeVO(com.cloud.storage.VolumeVO) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DiskTO(com.cloud.agent.api.to.DiskTO)

Example 15 with VolumeInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo in project cloudstack by apache.

the class XenserverSnapshotStrategy method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    if (canHandle(snapshot, SnapshotOperation.REVERT) == StrategyPriority.CANT_HANDLE) {
        throw new CloudRuntimeException("Reverting not supported. Create a template or volume based on the snapshot instead.");
    }
    SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshot.getId());
    if (snapshotVO == null) {
        throw new CloudRuntimeException("Failed to get lock on snapshot:" + snapshot.getId());
    }
    try {
        VolumeInfo volumeInfo = snapshot.getBaseVolume();
        StoragePool store = (StoragePool) volumeInfo.getDataStore();
        if (store != null && store.getStatus() != StoragePoolStatus.Up) {
            snapshot.processEvent(Event.OperationFailed);
            throw new CloudRuntimeException("store is not in up state");
        }
        volumeInfo.stateTransit(Volume.Event.RevertSnapshotRequested);
        boolean result = false;
        try {
            result = snapshotSvr.revertSnapshot(snapshot);
            if (!result) {
                s_logger.debug("Failed to revert snapshot: " + snapshot.getId());
                throw new CloudRuntimeException("Failed to revert snapshot: " + snapshot.getId());
            }
        } finally {
            if (result) {
                volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
            } else {
                volumeInfo.stateTransit(Volume.Event.OperationFailed);
            }
        }
        return result;
    } finally {
        if (snapshotVO != null) {
            snapshotDao.releaseFromLockTable(snapshot.getId());
        }
    }
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) StoragePool(com.cloud.storage.StoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)

Aggregations

VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)51 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)50 VolumeVO (com.cloud.storage.VolumeVO)36 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 ExecutionException (java.util.concurrent.ExecutionException)22 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)19 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)19 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)18 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)13 Map (java.util.Map)13 SnapshotVO (com.cloud.storage.SnapshotVO)12 DB (com.cloud.utils.db.DB)12 Test (org.testng.annotations.Test)12 Account (com.cloud.user.Account)11