Search in sources :

Example 21 with VolumeInfo

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

the class VolumeTestVmware method testCreateDataDisk.

@Test
public void testCreateDataDisk() {
    DataStore primaryStore = createPrimaryDataStore();
    primaryStoreId = primaryStore.getId();
    primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
    VolumeVO volume = createVolume(null, primaryStore.getId());
    VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
    this.volumeService.createVolumeAsync(volInfo, primaryStore);
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Test(org.testng.annotations.Test)

Example 22 with VolumeInfo

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

the class StorageSystemSnapshotStrategy method takeSnapshot.

@Override
@DB
public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
    VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
    if (volumeInfo.getFormat() != ImageFormat.VHD) {
        throw new CloudRuntimeException("Only the " + ImageFormat.VHD.toString() + " image type is currently supported.");
    }
    SnapshotVO snapshotVO = snapshotDao.acquireInLockTable(snapshotInfo.getId());
    if (snapshotVO == null) {
        throw new CloudRuntimeException("Failed to acquire lock on the following snapshot: " + snapshotInfo.getId());
    }
    SnapshotResult result = null;
    SnapshotInfo snapshotOnPrimary = null;
    SnapshotInfo backedUpSnapshot = null;
    try {
        volumeInfo.stateTransit(Volume.Event.SnapshotRequested);
        // only XenServer is currently supported
        HostVO hostVO = getHost(volumeInfo.getId());
        boolean canStorageSystemCreateVolumeFromSnapshot = canStorageSystemCreateVolumeFromSnapshot(volumeInfo.getPoolId());
        boolean computeClusterSupportsResign = clusterDao.getSupportsResigning(hostVO.getClusterId());
        if (canStorageSystemCreateVolumeFromSnapshot && computeClusterSupportsResign) {
            SnapshotDetailsVO snapshotDetail = new SnapshotDetailsVO(snapshotInfo.getId(), "takeSnapshot", Boolean.TRUE.toString(), false);
            snapshotDetailsDao.persist(snapshotDetail);
        }
        result = snapshotSvr.takeSnapshot(snapshotInfo);
        if (result.isFailed()) {
            s_logger.debug("Failed to take a snapshot: " + result.getResult());
            throw new CloudRuntimeException(result.getResult());
        }
        if (!canStorageSystemCreateVolumeFromSnapshot || !computeClusterSupportsResign) {
            performSnapshotAndCopyOnHostSide(volumeInfo, snapshotInfo);
        }
        snapshotOnPrimary = result.getSnapshot();
        backedUpSnapshot = backupSnapshot(snapshotOnPrimary);
        updateLocationTypeInDb(backedUpSnapshot);
    } finally {
        if (result != null && result.isSuccess()) {
            volumeInfo.stateTransit(Volume.Event.OperationSucceeded);
            if (snapshotOnPrimary != null && snapshotInfo.getLocationType() == Snapshot.LocationType.SECONDARY) {
                // remove the snapshot on primary storage
                try {
                    snapshotSvr.deleteSnapshot(snapshotOnPrimary);
                } catch (Exception e) {
                    s_logger.warn("Failed to clean up snapshot on primary Id:" + snapshotOnPrimary.getId() + " " + e.getMessage());
                }
            }
        } else {
            volumeInfo.stateTransit(Volume.Event.OperationFailed);
        }
    }
    snapshotDao.releaseFromLockTable(snapshotInfo.getId());
    return backedUpSnapshot;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) SnapshotDetailsVO(com.cloud.storage.dao.SnapshotDetailsVO) HostVO(com.cloud.host.HostVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 23 with VolumeInfo

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

the class VolumeTestVmware method testCreateTemplateFromVolume.

@Test
public void testCreateTemplateFromVolume() {
    DataStore primaryStore = createPrimaryDataStore();
    primaryStoreId = primaryStore.getId();
    primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
    VolumeVO volume = createVolume(null, primaryStore.getId());
    VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
    AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeAsync(volInfo, primaryStore);
    try {
        VolumeApiResult result = future.get();
        AssertJUnit.assertTrue(result.isSuccess());
        volInfo = result.getVolume();
        VMTemplateVO templateVO = createTemplateInDb();
        TemplateInfo tmpl = this.templateFactory.getTemplate(templateVO.getId(), DataStoreRole.Image);
        DataStore imageStore = this.dataStoreMgr.getImageStore(this.dcId);
        this.imageService.createTemplateFromVolumeAsync(volInfo, tmpl, imageStore);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) VolumeVO(com.cloud.storage.VolumeVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VMTemplateVO(com.cloud.storage.VMTemplateVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) VolumeApiResult(org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 24 with VolumeInfo

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

the class XenServerStorageMotionStrategy method updateVolumePathsAfterMigration.

private void updateVolumePathsAfterMigration(Map<VolumeInfo, DataStore> volumeToPool, List<VolumeObjectTO> volumeTos, Host srcHost) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = (StoragePool) entry.getValue();
        boolean updated = false;
        for (VolumeObjectTO volumeTo : volumeTos) {
            if (volumeInfo.getId() == volumeTo.getId()) {
                if (storagePool.isManaged()) {
                    handleManagedVolumePostMigration(volumeInfo, srcHost, volumeTo);
                } else {
                    VolumeVO volumeVO = volDao.findById(volumeInfo.getId());
                    Long oldPoolId = volumeVO.getPoolId();
                    volumeVO.setPath(volumeTo.getPath());
                    volumeVO.setFolder(storagePool.getPath());
                    volumeVO.setPodId(storagePool.getPodId());
                    volumeVO.setPoolId(storagePool.getId());
                    volumeVO.setLastPoolId(oldPoolId);
                    volDao.update(volumeInfo.getId(), volumeVO);
                }
                updated = true;
                break;
            }
        }
        if (!updated) {
            s_logger.error("The volume path wasn't updated for volume '" + volumeInfo + "' 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with VolumeInfo

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

the class XenServerStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.

private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    try {
        List<Pair<VolumeTO, String>> volumeToStorageUuid = new ArrayList<>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volumeInfo = entry.getKey();
            StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
            VolumeTO volumeTo = new VolumeTO(volumeInfo, storagePool);
            if (storagePool.isManaged()) {
                String iqn = handleManagedVolumePreMigration(volumeInfo, storagePool, destHost);
                volumeToStorageUuid.add(new Pair<>(volumeTo, iqn));
            } else {
                volumeToStorageUuid.add(new Pair<>(volumeTo, ((StoragePool) entry.getValue()).getPath()));
            }
        }
        // Migration across cluster needs to be done in three phases.
        // 1. Send a migrate receive command to the destination host so that it is ready to receive a vm.
        // 2. Send a migrate send command to the source host. This actually migrates the vm to the destination.
        // 3. Complete the process. Update the volume details.
        MigrateWithStorageReceiveCommand receiveCmd = new MigrateWithStorageReceiveCommand(to, volumeToStorageUuid);
        MigrateWithStorageReceiveAnswer receiveAnswer = (MigrateWithStorageReceiveAnswer) agentMgr.send(destHost.getId(), receiveCmd);
        if (receiveAnswer == null) {
            s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!receiveAnswer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        }
        MigrateWithStorageSendCommand sendCmd = new MigrateWithStorageSendCommand(to, receiveAnswer.getVolumeToSr(), receiveAnswer.getNicToNetwork(), receiveAnswer.getToken());
        MigrateWithStorageSendAnswer sendAnswer = (MigrateWithStorageSendAnswer) agentMgr.send(srcHost.getId(), sendCmd);
        if (sendAnswer == null) {
            handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
            s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!sendAnswer.getResult()) {
            handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        }
        MigrateWithStorageCompleteCommand command = new MigrateWithStorageCompleteCommand(to);
        MigrateWithStorageCompleteAnswer answer = (MigrateWithStorageCompleteAnswer) agentMgr.send(destHost.getId(), command);
        if (answer == null) {
            s_logger.error("Migration with storage of vm " + vm + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!answer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos(), srcHost);
        }
        return answer;
    } catch (OperationTimedoutException e) {
        s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
        throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) StoragePool(com.cloud.storage.StoragePool) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) ArrayList(java.util.ArrayList) MigrateWithStorageCompleteCommand(com.cloud.agent.api.MigrateWithStorageCompleteCommand) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageReceiveCommand(com.cloud.agent.api.MigrateWithStorageReceiveCommand) VolumeTO(com.cloud.agent.api.to.VolumeTO) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) MigrateWithStorageSendCommand(com.cloud.agent.api.MigrateWithStorageSendCommand) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

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