Search in sources :

Example 11 with DiskProfile

use of com.cloud.legacymodel.storage.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(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(primary.getType()).thenReturn(StoragePoolType.CLVM);
    when(this.libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) CreateCommand(com.cloud.legacymodel.communication.command.CreateCommand) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 12 with DiskProfile

use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.

the class LibvirtCreateCommandWrapper method execute.

@Override
public Answer execute(final CreateCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final StorageFilerTO pool = command.getPool();
    final DiskProfile dskch = command.getDiskCharacteristics();
    KvmPhysicalDisk baseVol = null;
    KvmStoragePool primaryPool = null;
    KvmPhysicalDisk vol = null;
    final long disksize;
    try {
        final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid());
        disksize = dskch.getSize();
        if (command.getTemplateUrl() != null) {
            if (primaryPool.getType() == StoragePoolType.CLVM) {
                vol = libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primaryPool, dskch.getPath());
            } else if (primaryPool.getType() == StoragePoolType.LVM) {
                vol = libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primaryPool, dskch.getPath());
            } else {
                baseVol = primaryPool.getPhysicalDisk(command.getTemplateUrl());
                vol = storagePoolMgr.createDiskFromTemplate(baseVol, dskch.getPath(), dskch.getProvisioningType(), primaryPool, 0);
            }
            if (vol == null) {
                return new Answer(command, false, " Can't create storage volume on storage pool");
            }
        } else {
            vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getProvisioningType(), dskch.getSize());
            if (vol == null) {
                return new Answer(command, false, " Can't create Physical Disk");
            }
        }
        final VolumeTO volume = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null, null, null);
        volume.setBytesReadRate(dskch.getBytesReadRate());
        volume.setBytesWriteRate(dskch.getBytesWriteRate());
        volume.setIopsReadRate(dskch.getIopsReadRate());
        volume.setIopsWriteRate(dskch.getIopsWriteRate());
        volume.setIopsTotalRate(dskch.getIopsTotalRate());
        volume.setCacheMode(dskch.getCacheMode());
        return new CreateAnswer(command, volume);
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to create volume: " + e.toString());
        return new CreateAnswer(command, e);
    }
}
Also used : CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile)

Example 13 with DiskProfile

use of com.cloud.legacymodel.storage.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, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) CreateCommand(com.cloud.legacymodel.communication.command.CreateCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with DiskProfile

use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method moveVolume.

@Override
public VolumeInfo moveVolume(final VolumeInfo volume, final long destPoolDcId, final Long destPoolPodId, final Long destPoolClusterId, final HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException {
    // Find a destination storage pool with the specified criteria
    final DiskOffering diskOffering = this._entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    final DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
    dskCh.setHyperType(dataDiskHyperType);
    final DataCenter destPoolDataCenter = this._entityMgr.findById(DataCenter.class, destPoolDcId);
    final Pod destPoolPod = this._entityMgr.findById(Pod.class, destPoolPodId);
    final StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<>());
    if (destPool == null) {
        throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to.");
    }
    final Volume newVol = migrateVolume(volume, destPool);
    return this.volFactory.getVolume(newVol.getId());
}
Also used : DiskOffering(com.cloud.legacymodel.storage.DiskOffering) DataCenter(com.cloud.legacymodel.dc.DataCenter) StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) Volume(com.cloud.legacymodel.storage.Volume) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiskProfile(com.cloud.legacymodel.storage.DiskProfile)

Example 15 with DiskProfile

use of com.cloud.legacymodel.storage.DiskProfile in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method hasSuitablePoolsForVolume.

private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) {
    final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
    final ExcludeList avoid = new ExcludeList();
    for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
        final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
        if (poolList != null && !poolList.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.legacymodel.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) StoragePoolAllocator(com.cloud.engine.subsystem.api.storage.StoragePoolAllocator)

Aggregations

DiskProfile (com.cloud.legacymodel.storage.DiskProfile)15 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)7 StoragePool (com.cloud.legacymodel.storage.StoragePool)7 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)5 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)5 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)5 VolumeVO (com.cloud.storage.VolumeVO)5 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)4 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)4 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)4 StoragePoolAllocator (com.cloud.engine.subsystem.api.storage.StoragePoolAllocator)4 Answer (com.cloud.legacymodel.communication.answer.Answer)4 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)3 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)3 VolumeService (com.cloud.engine.subsystem.api.storage.VolumeService)3