Search in sources :

Example 26 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCopyVolumeCommandToSecFalse.

@Test
public void testCopyVolumeCommandToSecFalse() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long volumeId = 1l;
    final int wait = 0;
    final String volumePath = "/vol/path";
    final boolean toSecondaryStorage = false;
    final boolean executeInSequence = false;
    final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
    final String destVolumeName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondary = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(destVolumeName);
    when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
    when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
    when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
    when(primary.getPhysicalDisk(command.getVolumePath() + ".qcow2")).thenReturn(disk);
    when(storagePoolMgr.copyPhysicalDisk(disk, destVolumeName, primary, 0)).thenReturn(disk);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CopyVolumeCommand(com.cloud.legacymodel.communication.command.CopyVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) 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) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 27 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtDeleteStoragePoolCommandWrapper method execute.

@Override
public Answer execute(final DeleteStoragePoolCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        final StorageFilerTO pool = command.getPool();
        final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid());
        return new Answer(command);
    } catch (final CloudRuntimeException e) {
        return new Answer(command, false, e.toString());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO)

Example 28 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO 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 29 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method resize.

@Override
public void resize(final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
    final VolumeObject vol = (VolumeObject) data;
    final StoragePool pool = (StoragePool) data.getDataStore();
    final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
    final CreateCmdResult result = new CreateCmdResult(null, null);
    try {
        final ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
        if (answer != null && answer.getResult()) {
            final long finalSize = answer.getNewSize();
            s_logger.debug("Resize: volume started at size " + vol.getSize() + " and ended at size " + finalSize);
            vol.setSize(finalSize);
            vol.update();
        } else if (answer != null) {
            result.setResult(answer.getDetails());
        } else {
            s_logger.debug("return a null answer, mark it as failed for unknown reason");
            result.setResult("return a null answer, mark it as failed for unknown reason");
        }
    } catch (final Exception e) {
        s_logger.debug("sending resize command failed", e);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(com.cloud.storage.volume.VolumeObject) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException)

Example 30 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testResizeVolumeCommand.

@Test
public void testResizeVolumeCommand() {
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final ResizeVolumeCommand resizeCommand = new ResizeVolumeCommand("Test", pool, 1l, 3l, false, "Tests-1");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(resizeCommand, 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) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)36 Answer (com.cloud.legacymodel.communication.answer.Answer)24 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)21 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)20 Test (org.junit.Test)19 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)16 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)16 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)15 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)15 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)10 StoragePool (com.cloud.legacymodel.storage.StoragePool)10 Connection (com.xensource.xenapi.Connection)9 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)8 ResizeVolumeCommand (com.cloud.legacymodel.communication.command.ResizeVolumeCommand)8 VolumeTO (com.cloud.legacymodel.to.VolumeTO)8 SR (com.xensource.xenapi.SR)8 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)7 CopyVolumeCommand (com.cloud.legacymodel.communication.command.CopyVolumeCommand)5 DiskProfile (com.cloud.legacymodel.storage.DiskProfile)5 HashMap (java.util.HashMap)5