use of com.cloud.host.HostVO in project cloudstack by apache.
the class EndpointSelectorTest method testMixZonePrimaryStorages.
@Test
public void testMixZonePrimaryStorages() {
Long srcStoreId = null;
Long destStoreId = imageStore.getId();
DataStore store = createPrimaryDataStore(ScopeType.ZONE);
srcStoreId = store.getId();
HostVO host = createHost(Hypervisor.HypervisorType.VMware);
addStorageToHost(store, host);
store = createPrimaryDataStore(ScopeType.ZONE);
host = createHost(Hypervisor.HypervisorType.VMware);
addStorageToHost(store, host);
Long xenStoreId = null;
store = createPrimaryDataStore(ScopeType.CLUSTER);
xenStoreId = store.getId();
host = createHost(Hypervisor.HypervisorType.XenServer);
addStorageToHost(store, host);
store = createPrimaryDataStore(ScopeType.CLUSTER);
host = createHost(Hypervisor.HypervisorType.XenServer);
addStorageToHost(store, host);
ZoneScope srcScope = new ZoneScope(dcId);
DataStore srcStore = mock(DataStore.class);
DataStore destStore = mock(DataStore.class);
when(srcStore.getScope()).thenReturn(srcScope);
when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
when(srcStore.getId()).thenReturn(srcStoreId);
when(destStore.getScope()).thenReturn(srcScope);
when(destStore.getRole()).thenReturn(DataStoreRole.Image);
when(destStore.getId()).thenReturn(destStoreId);
DataObject srcObj = mock(DataObject.class);
DataObject destObj = mock(DataObject.class);
when(srcObj.getDataStore()).thenReturn(srcStore);
when(destObj.getDataStore()).thenReturn(destStore);
EndPoint ep = endPointSelector.select(srcObj, destObj);
Assert.assertTrue(ep != null);
Long hostId = ep.getId();
HostVO newHost = hostDao.findById(hostId);
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
when(srcStore.getRole()).thenReturn(DataStoreRole.Image);
when(srcStore.getId()).thenReturn(destStoreId);
when(destStore.getId()).thenReturn(srcStoreId);
when(destStore.getRole()).thenReturn(DataStoreRole.Primary);
ep = endPointSelector.select(srcObj, destObj);
Assert.assertTrue(ep != null);
hostId = ep.getId();
newHost = hostDao.findById(hostId);
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.VMware);
ClusterScope clusterScope = new ClusterScope(clusterId, podId, dcId);
when(srcStore.getRole()).thenReturn(DataStoreRole.Primary);
when(srcStore.getScope()).thenReturn(clusterScope);
when(srcStore.getId()).thenReturn(xenStoreId);
ep = endPointSelector.select(srcStore);
Assert.assertTrue(ep != null);
newHost = hostDao.findById(ep.getId());
Assert.assertTrue(newHost.getHypervisorType() == Hypervisor.HypervisorType.XenServer);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleVolumeMigrationForKVM.
private void handleVolumeMigrationForKVM(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
VirtualMachine vm = srcVolumeInfo.getAttachedVM();
if (vm != null && vm.getState() != VirtualMachine.State.Stopped) {
throw new CloudRuntimeException("Currently, if a volume to migrate from non-managed storage to managed storage on KVM is attached to " + "a VM, the VM must be in the Stopped state.");
}
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
VolumeVO volumeVO = _volumeDao.findById(destVolumeInfo.getId());
volumeVO.setPath(volumeVO.get_iScsiName());
_volumeDao.update(volumeVO.getId(), volumeVO);
destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
long srcStoragePoolId = srcVolumeInfo.getPoolId();
StoragePoolVO srcStoragePoolVO = _storagePoolDao.findById(srcStoragePoolId);
HostVO hostVO;
if (srcStoragePoolVO.getClusterId() != null) {
hostVO = getHostInCluster(srcStoragePoolVO.getClusterId());
} else {
hostVO = getHost(destVolumeInfo.getDataCenterId(), HypervisorType.KVM, false);
}
// migrate the volume via the hypervisor
migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from non-managed storage to managed storage");
volumeVO = _volumeDao.findById(destVolumeInfo.getId());
volumeVO.setFormat(ImageFormat.QCOW2);
_volumeDao.update(volumeVO.getId(), volumeVO);
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleCreateManagedVolumeFromManagedSnapshot.
private void handleCreateManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
boolean useCloning = true;
try {
verifyFormat(snapshotInfo);
HostVO hostVO = getHost(snapshotInfo);
boolean usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
boolean computeClusterSupportsVolumeClone = true;
if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(hostVO.getClusterId());
if (usingBackendSnapshot && !computeClusterSupportsVolumeClone) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + hostVO.getClusterId();
LOGGER.warn(noSupportForResignErrMsg);
throw new CloudRuntimeException(noSupportForResignErrMsg);
}
}
boolean canStorageSystemCreateVolumeFromVolume = canStorageSystemCreateVolumeFromVolume(snapshotInfo.getDataStore().getId());
useCloning = usingBackendSnapshot || (canStorageSystemCreateVolumeFromVolume && computeClusterSupportsVolumeClone);
VolumeDetailVO volumeDetail = null;
if (useCloning) {
volumeDetail = new VolumeDetailVO(volumeInfo.getId(), "cloneOfSnapshot", String.valueOf(snapshotInfo.getId()), false);
volumeDetail = volumeDetailsDao.persist(volumeDetail);
}
// at this point, the snapshotInfo and volumeInfo should have the same disk offering ID (so either one should be OK to get a DiskOfferingVO instance)
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId());
SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
_volumeService.updateHypervisorSnapshotReserveForVolume(diskOffering, volumeInfo.getId(), snapshot.getHypervisorType());
AsyncCallFuture<VolumeApiResult> future = _volumeService.createVolumeAsync(volumeInfo, volumeInfo.getDataStore());
VolumeApiResult result = future.get();
if (volumeDetail != null) {
volumeDetailsDao.remove(volumeDetail.getId());
}
if (result.isFailed()) {
LOGGER.warn("Failed to create a volume: " + result.getResult());
throw new CloudRuntimeException(result.getResult());
}
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
volumeInfo.processEvent(Event.MigrationRequested);
volumeInfo = _volumeDataFactory.getVolume(volumeInfo.getId(), volumeInfo.getDataStore());
if (HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType()) || HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
if (useCloning) {
Map<String, String> extraDetails = null;
if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
extraDetails = new HashMap<>();
String extraDetailsVmdk = getSnapshotProperty(snapshotInfo.getId(), DiskTO.VMDK);
extraDetails.put(DiskTO.VMDK, extraDetailsVmdk);
}
copyCmdAnswer = performResignature(volumeInfo, hostVO, extraDetails);
// If using VMware, have the host rescan its software HBA if dynamic discovery is in use.
if (HypervisorType.VMware.equals(snapshotInfo.getHypervisorType())) {
disconnectHostFromVolume(hostVO, volumeInfo.getPoolId(), volumeInfo.get_iScsiName());
}
} else {
// asking for a XenServer host here so we don't always prefer to use XenServer hosts that support resigning
// even when we don't need those hosts to do this kind of copy work
hostVO = getHost(snapshotInfo.getDataCenterId(), snapshotInfo.getHypervisorType(), false);
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
copyCmdAnswer = performCopyOfVdi(volumeInfo, snapshotInfo, hostVO);
}
verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
} else if (HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
VolumeObjectTO newVolume = new VolumeObjectTO();
newVolume.setSize(volumeInfo.getSize());
newVolume.setPath(volumeInfo.get_iScsiName());
newVolume.setFormat(volumeInfo.getFormat());
copyCmdAnswer = new CopyCmdAnswer(newVolume);
} else {
throw new CloudRuntimeException("Unsupported hypervisor type");
}
} catch (Exception ex) {
errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateManagedVolumeFromManagedSnapshot': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
if (useCloning) {
handleQualityOfServiceForVolumeMigration(volumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
}
if (copyCmdAnswer == null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleCreateNonManagedVolumeFromManagedSnapshot.
private void handleCreateNonManagedVolumeFromManagedSnapshot(SnapshotInfo snapshotInfo, VolumeInfo volumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
if (!HypervisorType.XenServer.equals(snapshotInfo.getHypervisorType())) {
String errMsg = "Creating a volume on non-managed storage from a snapshot on managed storage is currently only supported with XenServer.";
handleError(errMsg, callback);
}
long volumeStoragePoolId = volumeInfo.getDataStore().getId();
StoragePoolVO volumeStoragePoolVO = _storagePoolDao.findById(volumeStoragePoolId);
if (volumeStoragePoolVO.getClusterId() == null) {
String errMsg = "To create a non-managed volume from a managed snapshot, the destination storage pool must be cluster scoped.";
handleError(errMsg, callback);
}
String errMsg = null;
CopyCmdAnswer copyCmdAnswer = null;
boolean usingBackendSnapshot = false;
try {
snapshotInfo.processEvent(Event.CopyingRequested);
usingBackendSnapshot = usingBackendSnapshotFor(snapshotInfo);
if (usingBackendSnapshot) {
boolean computeClusterSupportsVolumeClone = clusterDao.getSupportsResigning(volumeStoragePoolVO.getClusterId());
if (!computeClusterSupportsVolumeClone) {
String noSupportForResignErrMsg = "Unable to locate an applicable host with which to perform a resignature operation : Cluster ID = " + volumeStoragePoolVO.getClusterId();
LOGGER.warn(noSupportForResignErrMsg);
throw new CloudRuntimeException(noSupportForResignErrMsg);
}
createVolumeFromSnapshot(snapshotInfo);
HostVO hostVO = getHost(snapshotInfo.getDataCenterId(), HypervisorType.XenServer, true);
copyCmdAnswer = performResignature(snapshotInfo, hostVO, null, true);
verifyCopyCmdAnswer(copyCmdAnswer, snapshotInfo);
}
int primaryStorageDownloadWait = StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value();
CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), volumeInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
if (!usingBackendSnapshot) {
long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
_volumeService.grantAccess(snapshotInfo, hostVO, snapshotDataStore);
}
Map<String, String> srcDetails = getSnapshotDetails(snapshotInfo);
copyCommand.setOptions(srcDetails);
copyCmdAnswer = (CopyCmdAnswer) agentManager.send(hostVO.getId(), copyCommand);
if (!copyCmdAnswer.getResult()) {
errMsg = copyCmdAnswer.getDetails();
LOGGER.warn(errMsg);
throw new CloudRuntimeException(errMsg);
}
} catch (Exception ex) {
errMsg = "Copy operation failed in 'StorageSystemDataMotionStrategy.handleCreateNonManagedVolumeFromManagedSnapshot': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
try {
HostVO hostVO = getHostInCluster(volumeStoragePoolVO.getClusterId());
long snapshotStoragePoolId = snapshotInfo.getDataStore().getId();
DataStore snapshotDataStore = dataStoreMgr.getDataStore(snapshotStoragePoolId, DataStoreRole.Primary);
_volumeService.revokeAccess(snapshotInfo, hostVO, snapshotDataStore);
} catch (Exception e) {
LOGGER.debug("Failed to revoke access from dest volume", e);
}
if (usingBackendSnapshot) {
deleteVolumeFromSnapshot(snapshotInfo);
}
try {
if (StringUtils.isEmpty(errMsg)) {
snapshotInfo.processEvent(Event.OperationSuccessed);
} else {
snapshotInfo.processEvent(Event.OperationFailed);
}
} catch (Exception ex) {
LOGGER.warn("Error processing snapshot event: " + ex.getMessage(), ex);
}
if (copyCmdAnswer == null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
use of com.cloud.host.HostVO in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleVolumeMigrationFromManagedStorageToNonManagedStorage.
private void handleVolumeMigrationFromManagedStorageToNonManagedStorage(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo, AsyncCompletionCallback<CopyCommandResult> callback) {
String errMsg = null;
try {
if (!ImageFormat.QCOW2.equals(srcVolumeInfo.getFormat())) {
throw new CloudRuntimeException("Currently, only the KVM hypervisor type is supported for the migration of a volume " + "from managed storage to non-managed storage.");
}
HypervisorType hypervisorType = HypervisorType.KVM;
VirtualMachine vm = srcVolumeInfo.getAttachedVM();
if (vm != null && vm.getState() != VirtualMachine.State.Stopped) {
throw new CloudRuntimeException("Currently, if a volume to migrate from managed storage to non-managed storage is attached to " + "a VM, the VM must be in the Stopped state.");
}
long destStoragePoolId = destVolumeInfo.getPoolId();
StoragePoolVO destStoragePoolVO = _storagePoolDao.findById(destStoragePoolId);
HostVO hostVO;
if (destStoragePoolVO.getClusterId() != null) {
hostVO = getHostInCluster(destStoragePoolVO.getClusterId());
} else {
hostVO = getHost(destVolumeInfo.getDataCenterId(), hypervisorType, false);
}
setCertainVolumeValuesNull(destVolumeInfo.getId());
// migrate the volume via the hypervisor
String path = migrateVolumeForKVM(srcVolumeInfo, destVolumeInfo, hostVO, "Unable to migrate the volume from managed storage to non-managed storage");
updateVolumePath(destVolumeInfo.getId(), path);
} catch (Exception ex) {
errMsg = "Migration operation failed in 'StorageSystemDataMotionStrategy.handleVolumeMigrationFromManagedStorageToNonManagedStorage': " + ex.getMessage();
throw new CloudRuntimeException(errMsg);
} finally {
CopyCmdAnswer copyCmdAnswer;
if (errMsg != null) {
copyCmdAnswer = new CopyCmdAnswer(errMsg);
} else {
destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
DataTO dataTO = destVolumeInfo.getTO();
copyCmdAnswer = new CopyCmdAnswer(dataTO);
}
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
result.setResult(errMsg);
callback.complete(result);
}
}
Aggregations