Search in sources :

Example 51 with DataStore

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

the class SnapshotDataFactoryImpl method listSnapshotOnCache.

@Override
public List<SnapshotInfo> listSnapshotOnCache(long snapshotId) {
    List<SnapshotDataStoreVO> cacheSnapshots = snapshotStoreDao.listOnCache(snapshotId);
    List<SnapshotInfo> snapObjs = new ArrayList<SnapshotInfo>();
    for (SnapshotDataStoreVO cacheSnap : cacheSnapshots) {
        long storeId = cacheSnap.getDataStoreId();
        DataStore store = storeMgr.getDataStore(storeId, DataStoreRole.ImageCache);
        SnapshotInfo tmplObj = getSnapshot(snapshotId, store);
        snapObjs.add(tmplObj);
    }
    return snapObjs;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO) ArrayList(java.util.ArrayList)

Example 52 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore 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 53 with DataStore

use of org.apache.cloudstack.engine.subsystem.api.storage.DataStore 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)

Example 54 with DataStore

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

the class XenServerStorageMotionStrategy method migrateVmWithVolumesWithinCluster.

private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with its volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto);
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) 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 + ". " + answer.getDetails());
        } 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 : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 55 with DataStore

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

the class XenServerStorageMotionStrategy method handleManagedVolumesAfterFailedMigration.

private void handleManagedVolumesAfterFailedMigration(Map<VolumeInfo, DataStore> volumeToPool, Host destHost) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
        if (storagePool.isManaged()) {
            final Map<String, String> details = new HashMap<>();
            details.put(DeleteStoragePoolCommand.DATASTORE_NAME, getBasicIqn(volumeInfo.getId()));
            final DeleteStoragePoolCommand cmd = new DeleteStoragePoolCommand();
            cmd.setDetails(details);
            cmd.setRemoveDatastore(true);
            final Answer answer = agentMgr.easySend(destHost.getId(), cmd);
            if (answer == null || !answer.getResult()) {
                String errMsg = "Error interacting with host (related to handleManagedVolumesAfterFailedMigration)" + (StringUtils.isNotBlank(answer.getDetails()) ? ": " + answer.getDetails() : "");
                s_logger.error(errMsg);
                // regardless of the success or lack thereof concerning this method
                return;
            }
            final PrimaryDataStoreDriver pdsd = (PrimaryDataStoreDriver) volumeInfo.getDataStore().getDriver();
            VolumeDetailVO volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_REVOKE_ACCESS, Boolean.TRUE.toString(), false);
            volumeDetailsDao.persist(volumeDetailVo);
            pdsd.revokeAccess(volumeInfo, destHost, volumeInfo.getDataStore());
            volumeDetailVo = new VolumeDetailVO(volumeInfo.getId(), PrimaryDataStoreDriver.BASIC_DELETE_FAILURE, Boolean.TRUE.toString(), false);
            volumeDetailsDao.persist(volumeDetailVo);
            pdsd.deleteAsync(volumeInfo.getDataStore(), volumeInfo, null);
        }
    }
}
Also used : MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) Answer(com.cloud.agent.api.Answer) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) StoragePool(com.cloud.storage.StoragePool) HashMap(java.util.HashMap) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) VolumeDetailVO(com.cloud.storage.VolumeDetailVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)158 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)52 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)49 ExecutionException (java.util.concurrent.ExecutionException)37 VolumeVO (com.cloud.storage.VolumeVO)30 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)24 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)24 VMTemplateVO (com.cloud.storage.VMTemplateVO)22 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)22 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)22 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)18 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)17 VolumeApiResult (org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult)17 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)16 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 Pair (com.cloud.utils.Pair)13