Search in sources :

Example 31 with DiskProfile

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);
    }
}
Also used : StoragePool(com.cloud.storage.StoragePool) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) DiskProfile(com.cloud.vm.DiskProfile) HashSet(java.util.HashSet) DB(com.cloud.utils.db.DB)

Example 32 with DiskProfile

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");
}
Also used : StoragePool(com.cloud.storage.StoragePool) DiskProfile(com.cloud.vm.DiskProfile) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeService(com.cloud.engine.subsystem.api.storage.VolumeService) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) DB(com.cloud.utils.db.DB)

Example 33 with DiskProfile

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());
}
Also used : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CreateCommand(com.cloud.agent.api.storage.CreateCommand) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) DiskProfile(com.cloud.vm.DiskProfile) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test)

Example 34 with DiskProfile

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());
}
Also used : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) CreateCommand(com.cloud.agent.api.storage.CreateCommand) KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) DiskProfile(com.cloud.vm.DiskProfile) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test)

Example 35 with DiskProfile

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());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) Answer(com.cloud.agent.api.Answer) AttachAnswer(com.cloud.storage.command.AttachAnswer) CreateCommand(com.cloud.agent.api.storage.CreateCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DiskProfile(com.cloud.vm.DiskProfile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

DiskProfile (com.cloud.vm.DiskProfile)49 StoragePool (com.cloud.storage.StoragePool)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)16 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)16 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)16 Test (org.junit.Test)16 Volume (com.cloud.storage.Volume)15 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)14 Answer (com.cloud.agent.api.Answer)12 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)12 ArrayList (java.util.ArrayList)12 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)12 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)11 Pair (com.cloud.utils.Pair)10 VolumeTO (com.cloud.agent.api.to.VolumeTO)9 VolumeVO (com.cloud.storage.VolumeVO)9 HashSet (java.util.HashSet)9 CreateCommand (com.cloud.agent.api.storage.CreateCommand)8