use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StorageSystemDataMotionStrategy method handleVolumeMigrationForXenServer.
private void handleVolumeMigrationForXenServer(VolumeInfo srcVolumeInfo, VolumeInfo destVolumeInfo) {
VirtualMachine vm = srcVolumeInfo.getAttachedVM();
if (vm == null || vm.getState() != VirtualMachine.State.Running) {
throw new CloudRuntimeException("Currently, a volume to migrate from non-managed storage to managed storage on XenServer must be attached to " + "a VM in the Running state.");
}
destVolumeInfo.getDataStore().getDriver().createAsync(destVolumeInfo.getDataStore(), destVolumeInfo, null);
destVolumeInfo = _volumeDataFactory.getVolume(destVolumeInfo.getId(), destVolumeInfo.getDataStore());
handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.MIGRATION);
HostVO hostVO = _hostDao.findById(vm.getHostId());
_volumeService.grantAccess(destVolumeInfo, hostVO, destVolumeInfo.getDataStore());
String value = _configDao.getValue(Config.MigrateWait.key());
int waitInterval = NumbersUtil.parseInt(value, Integer.parseInt(Config.MigrateWait.getDefaultValue()));
StoragePool destPool = (StoragePool) dataStoreMgr.getDataStore(destVolumeInfo.getDataStore().getId(), DataStoreRole.Primary);
MigrateVolumeCommand command = new MigrateVolumeCommand(srcVolumeInfo.getId(), srcVolumeInfo.getPath(), destPool, srcVolumeInfo.getAttachedVmName(), srcVolumeInfo.getVolumeType(), waitInterval, null);
Map<String, String> details = new HashMap<>();
details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
details.put(DiskTO.IQN, destVolumeInfo.get_iScsiName());
details.put(DiskTO.STORAGE_HOST, destPool.getHostAddress());
details.put(DiskTO.PROTOCOL_TYPE, (destPool.getPoolType() != null) ? destPool.getPoolType().toString() : null);
command.setDestDetails(details);
EndPoint ep = selector.select(srcVolumeInfo, StorageAction.MIGRATEVOLUME);
Answer answer;
if (ep == null) {
String errMsg = "No remote endpoint to send command to; check if host or SSVM is down";
LOGGER.error(errMsg);
answer = new Answer(command, false, errMsg);
} else {
answer = ep.sendMessage(command);
}
handleQualityOfServiceForVolumeMigration(destVolumeInfo, PrimaryDataStoreDriver.QualityOfServiceState.NO_MIGRATION);
if (answer == null || !answer.getResult()) {
handleFailedVolumeMigration(srcVolumeInfo, destVolumeInfo, hostVO);
throw new CloudRuntimeException("Failed to migrate volume with ID " + srcVolumeInfo.getId() + " to storage pool with ID " + destPool.getId());
} else {
handleSuccessfulVolumeMigration(srcVolumeInfo, destPool, (MigrateVolumeAnswer) answer);
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StorageAllocatorTest method testClusterAllocatorWithTags.
@Test
public void testClusterAllocatorWithTags() {
try {
createDb();
StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true", true);
poolDetailsDao.persist(detailVO);
DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
List<String> tags = new ArrayList<String>();
tags.add("high");
diskOff.setTagsArray(tags);
diskOfferingDao.update(diskOff.getId(), diskOff);
DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
int foundAcct = 0;
for (StoragePoolAllocator allocator : allocators) {
List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
if (!pools.isEmpty()) {
Assert.assertEquals(pools.get(0).getId(), storage.getId());
foundAcct++;
}
}
if (foundAcct > 1 || foundAcct == 0) {
Assert.fail();
}
} catch (Exception e) {
cleanDb();
Assert.fail();
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StorageAllocatorTest method testZoneWideStorageAllocator.
@Test
public void testZoneWideStorageAllocator() {
try {
createDb();
StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
pool.setHypervisor(HypervisorType.KVM);
pool.setScope(ScopeType.ZONE);
pool.setClusterId(null);
pool.setPodId(null);
storagePoolDao.update(pool.getId(), pool);
DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.KVM);
VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
Mockito.when(vmProfile.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
Mockito.when(storageMgr.storagePoolHasEnoughIops(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
int foundAcct = 0;
for (StoragePoolAllocator allocator : allocators) {
List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
if (!pools.isEmpty()) {
Assert.assertEquals(pools.get(0).getId(), storage.getId());
foundAcct++;
}
}
if (foundAcct > 1 || foundAcct == 0) {
Assert.fail();
}
} catch (Exception e) {
cleanDb();
Assert.fail();
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StorageAllocatorTest method testClusterAllocator.
@Test
public void testClusterAllocator() {
try {
createDb();
DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
int foundAcct = 0;
for (StoragePoolAllocator allocator : allocators) {
List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
if (!pools.isEmpty()) {
Assert.assertEquals(pools.get(0).getId(), storage.getId());
foundAcct++;
}
}
if (foundAcct > 1 || foundAcct == 0) {
Assert.fail();
}
} catch (Exception e) {
cleanDb();
Assert.fail();
}
}
use of com.cloud.storage.StoragePool in project cloudstack by apache.
the class StorageAllocatorTest method testClusterAllocatorMultiplePools.
@Test
public void testClusterAllocatorMultiplePools() {
Long newStorageId = null;
try {
createDb();
DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY);
storage = new StoragePoolVO();
storage.setDataCenterId(dcId);
storage.setPodId(podId);
storage.setPoolType(StoragePoolType.NetworkFilesystem);
storage.setClusterId(clusterId);
storage.setStatus(StoragePoolStatus.Up);
storage.setScope(ScopeType.CLUSTER);
storage.setUsedBytes(1000);
storage.setCapacityBytes(20000);
storage.setHostAddress(UUID.randomUUID().toString());
storage.setPath(UUID.randomUUID().toString());
storage.setStorageProviderName(provider.getName());
StoragePoolVO newStorage = storagePoolDao.persist(storage);
newStorageId = newStorage.getId();
DiskProfile profile = new DiskProfile(volume, diskOffering, HypervisorType.XenServer);
VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
int foundAcct = 0;
for (StoragePoolAllocator allocator : allocators) {
List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
if (!pools.isEmpty()) {
Assert.assertEquals(pools.size(), 1);
foundAcct++;
}
}
if (foundAcct > 1 || foundAcct == 0) {
Assert.fail();
}
} catch (Exception e) {
cleanDb();
if (newStorageId != null) {
storagePoolDao.remove(newStorageId);
}
Assert.fail();
}
}
Aggregations