Search in sources :

Example 66 with StoragePool

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

the class AncientDataMotionStrategy method migrateVolumeToPool.

protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
    String value = configDao.getValue(Config.MigrateWait.key());
    int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
    VolumeInfo volume = (VolumeInfo) srcData;
    StoragePool srcPool = (StoragePool) dataStoreMgr.getDataStore(srcData.getDataStore().getId(), DataStoreRole.Primary);
    StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destData.getDataStore().getId(), DataStoreRole.Primary);
    MigrateVolumeCommand command = new MigrateVolumeCommand(volume.getId(), volume.getPath(), destPool, volume.getAttachedVmName(), volume.getVolumeType(), waitInterval, volume.getChainInfo());
    if (srcPool.getParent() != 0) {
        command.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
    }
    EndPoint ep = selector.select(srcData, StorageAction.MIGRATEVOLUME);
    Answer answer = null;
    if (ep == null) {
        String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
        s_logger.error(errMsg);
        answer = new Answer(command, false, errMsg);
    } else {
        answer = ep.sendMessage(command);
    }
    if (answer == null || !answer.getResult()) {
        throw new CloudRuntimeException("Failed to migrate volume " + volume + " to storage pool " + destPool);
    } else {
        // Update the volume details after migration.
        VolumeVO volumeVo = volDao.findById(volume.getId());
        Long oldPoolId = volume.getPoolId();
        volumeVo.setPath(((MigrateVolumeAnswer) answer).getVolumePath());
        String chainInfo = ((MigrateVolumeAnswer) answer).getVolumeChainInfo();
        if (chainInfo != null) {
            volumeVo.setChainInfo(chainInfo);
        }
        volumeVo.setPodId(destPool.getPodId());
        volumeVo.setPoolId(destPool.getId());
        volumeVo.setLastPoolId(oldPoolId);
        // For SMB, pool credentials are also stored in the uri query string.  We trim the query string
        // part  here to make sure the credentials do not get stored in the db unencrypted.
        String folder = destPool.getPath();
        if (destPool.getPoolType() == StoragePoolType.SMB && folder != null && folder.contains("?")) {
            folder = folder.substring(0, folder.indexOf("?"));
        }
        volumeVo.setFolder(folder);
        volDao.update(volume.getId(), volumeVo);
    }
    return answer;
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) Answer(com.cloud.agent.api.Answer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) StoragePool(com.cloud.storage.StoragePool) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(org.apache.cloudstack.storage.RemoteHostEndPoint)

Example 67 with StoragePool

use of com.cloud.storage.StoragePool 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 68 with StoragePool

use of com.cloud.storage.StoragePool 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) Answer(com.cloud.agent.api.Answer) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) 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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 69 with StoragePool

use of com.cloud.storage.StoragePool 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 {
        verifyNoSnapshotsOnManagedStorageVolumes(volumeToPool);
        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 {
                StoragePool pool = (StoragePool) entry.getValue();
                String srNameLabel = CitrixHelper.getSRNameLabel(pool.getUuid(), pool.getPoolType(), pool.getPath());
                volumeToStorageUuid.add(new Pair<>(volumeTo, srNameLabel));
            }
        }
        // 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) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.cloud.utils.Pair)

Example 70 with StoragePool

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

the class XenServerStorageMotionStrategy method verifyNoSnapshotsOnManagedStorageVolumes.

private void verifyNoSnapshotsOnManagedStorageVolumes(Map<VolumeInfo, DataStore> volumeToPool) {
    for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
        VolumeInfo volumeInfo = entry.getKey();
        StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
        if (storagePool.isManaged()) {
            List<SnapshotVO> snapshots = getNonDestroyedSnapshots(volumeInfo.getId());
            if (snapshots != null && snapshots.size() > 0) {
                throw new CloudRuntimeException("Cannot perform this action on a volume with one or more snapshots");
            }
        }
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) SnapshotVO(com.cloud.storage.SnapshotVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

StoragePool (com.cloud.storage.StoragePool)234 Answer (com.cloud.agent.api.Answer)81 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)69 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)63 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)56 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)56 Volume (com.cloud.storage.Volume)55 HashMap (java.util.HashMap)47 VolumeVO (com.cloud.storage.VolumeVO)37 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)36 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)35 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)29 DiskProfile (com.cloud.vm.DiskProfile)29 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)28 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)28 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)28 AttachAnswer (com.cloud.storage.command.AttachAnswer)28