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;
}
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.");
}
}
}
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);
}
}
}
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());
}
}
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");
}
}
}
}
Aggregations