use of com.cloud.vm.DiskProfile in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method copyVolumeFromSecToPrimary.
@DB
public VolumeInfo copyVolumeFromSecToPrimary(final VolumeInfo volume, final VirtualMachine vm, final VirtualMachineTemplate template, final DataCenter dc, final Pod pod, final Long clusterId, final ServiceOffering offering, final DiskOffering diskOffering, final List<StoragePool> avoids, final long size, final HypervisorType hyperType) throws NoTransitionException {
final HashSet<StoragePool> avoidPools = new HashSet<>(avoids);
final DiskProfile dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
dskCh.setHyperType(vm.getHypervisorType());
// Find a suitable storage to create volume on
final StoragePool destPool = findStoragePool(dskCh, dc, pod, clusterId, null, vm, avoidPools);
final DataStore destStore = dataStoreMgr.getDataStore(destPool.getId(), DataStoreRole.Primary);
final AsyncCallFuture<VolumeService.VolumeApiResult> future = volService.copyVolume(volume, destStore);
try {
final VolumeService.VolumeApiResult result = future.get();
if (result.isFailed()) {
s_logger.debug("copy volume failed: " + result.getResult());
throw new CloudRuntimeException("copy volume failed: " + result.getResult());
}
return result.getVolume();
} catch (final InterruptedException e) {
s_logger.debug("Failed to copy volume: " + volume.getId(), e);
throw new CloudRuntimeException("Failed to copy volume", e);
} catch (final ExecutionException e) {
s_logger.debug("Failed to copy volume: " + volume.getId(), e);
throw new CloudRuntimeException("Failed to copy volume", e);
}
}
use of com.cloud.vm.DiskProfile in project cosmic by MissionCriticalCloud.
the class VolumeOrchestrator method createVolume.
@DB
public VolumeInfo createVolume(VolumeInfo volume, final VirtualMachine vm, final VirtualMachineTemplate template, final DataCenter dc, final Pod pod, final Long clusterId, final ServiceOffering offering, final DiskOffering diskOffering, final List<StoragePool> avoids, final long size, final HypervisorType hyperType) {
// update the volume's hv_ss_reserve (hypervisor snapshot reserve) from a disk offering (used for managed storage)
volume = volService.updateHypervisorSnapshotReserveForVolume(diskOffering, volume.getId(), hyperType);
StoragePool pool = null;
DiskProfile dskCh = null;
if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO != template.getFormat()) {
dskCh = createDiskCharacteristics(volume, template, dc, offering);
} else {
dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
}
if (diskOffering != null && diskOffering.isCustomized()) {
dskCh.setSize(size);
}
dskCh.setHyperType(hyperType);
final HashSet<StoragePool> avoidPools = new HashSet<>(avoids);
pool = findStoragePool(dskCh, dc, pod, clusterId, vm.getHostId(), vm, avoidPools);
if (pool == null) {
s_logger.warn("Unable to find suitable primary storage when creating volume " + volume.getName());
throw new CloudRuntimeException("Unable to find suitable primary storage when creating volume " + volume.getName());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Trying to create " + volume + " on " + pool);
}
final DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary);
for (int i = 0; i < 2; i++) {
// retry one more time in case of template reload is required for Vmware case
AsyncCallFuture<VolumeService.VolumeApiResult> future = null;
final boolean isNotCreatedFromTemplate = volume.getTemplateId() == null ? true : false;
if (isNotCreatedFromTemplate) {
future = volService.createVolumeAsync(volume, store);
} else {
final TemplateInfo templ = tmplFactory.getTemplate(template.getId(), DataStoreRole.Image);
future = volService.createVolumeFromTemplateAsync(volume, store.getId(), templ);
}
try {
final VolumeService.VolumeApiResult result = future.get();
if (result.isFailed()) {
if (result.getResult().contains("request template reload") && (i == 0)) {
s_logger.debug("Retry template re-deploy for vmware");
continue;
} else {
s_logger.debug("create volume failed: " + result.getResult());
throw new CloudRuntimeException("create volume failed:" + result.getResult());
}
}
return result.getVolume();
} catch (final InterruptedException e) {
s_logger.error("create volume failed", e);
throw new CloudRuntimeException("create volume failed", e);
} catch (final ExecutionException e) {
s_logger.error("create volume failed", e);
throw new CloudRuntimeException("create volume failed", e);
}
}
throw new CloudRuntimeException("create volume failed even after template re-deploy");
}
use of com.cloud.vm.DiskProfile in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreateCommand.
@Test
public void testCreateCommand() {
final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final String templateUrl = "http://template";
final boolean executeInSequence = false;
final CreateCommand command = new CreateCommand(diskCharacteristics, templateUrl, pool, executeInSequence);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.getType()).thenReturn(StoragePoolType.CLVM);
when(libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.vm.DiskProfile in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreateCommandCLVM.
@Test
public void testCreateCommandCLVM() {
final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
final String templateUrl = "http://template";
final boolean executeInSequence = false;
final CreateCommand command = new CreateCommand(diskCharacteristics, templateUrl, pool, executeInSequence);
final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk baseVol = Mockito.mock(KvmPhysicalDisk.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.getPhysicalDisk(command.getTemplateUrl())).thenReturn(baseVol);
when(poolManager.createDiskFromTemplate(baseVol, diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), primary, 0)).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
use of com.cloud.vm.DiskProfile in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testExecuteCreateCommand.
@Test
public void testExecuteCreateCommand() {
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final DiskProfile diskProfile = Mockito.mock(DiskProfile.class);
final CreateCommand createCommand = new CreateCommand(diskProfile, "", poolVO, false);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(createCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations