Search in sources :

Example 1 with ResizeVolumeAnswer

use of com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer in project cosmic by MissionCriticalCloud.

the class CitrixResizeVolumeCommandWrapper method execute.

@Override
public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final String volid = command.getPath();
    final long newSize = command.getNewSize();
    try {
        final VDI vdi = citrixResourceBase.getVDIbyUuid(conn, volid);
        vdi.resize(conn, newSize);
        return new ResizeVolumeAnswer(command, true, "success", newSize);
    } catch (final Exception e) {
        s_logger.warn("Unable to resize volume", e);
        final String error = "failed to resize volume:" + e;
        return new ResizeVolumeAnswer(command, false, error);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) VDI(com.xensource.xenapi.VDI) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer)

Example 2 with ResizeVolumeAnswer

use of com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtResizeVolumeCommandWrapper method execute.

@Override
public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String volid = command.getPath();
    final long newSize = command.getNewSize();
    final long currentSize = command.getCurrentSize();
    final String vmInstanceName = command.getInstanceName();
    final boolean shrinkOk = command.getShrinkOk();
    final StorageFilerTO spool = command.getPool();
    if (currentSize == newSize) {
        s_logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize);
        return new ResizeVolumeAnswer(command, true, "success", currentSize);
    }
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    final KvmStoragePool pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
    final KvmPhysicalDisk vol = pool.getPhysicalDisk(volid);
    final String path = vol.getPath();
    s_logger.debug("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + vol.getFormat() + "," + vmInstanceName + "," + shrinkOk);
    if (pool.getType() == StoragePoolType.RBD) {
        s_logger.debug("Volume " + path + " is on a RBD storage pool. No need to query for additional information.");
    } else if (pool.getType() == StoragePoolType.LVM || pool.getType() == StoragePoolType.CLVM) {
        s_logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume.");
        final LVM lvm = new LVM(command.getWait());
        try {
            // 1. Resize the logical volume
            lvm.resize(newSize, vol.getPath());
            // 2. If the volume is attached to a virtualmachine, notify libvirt domain of the size change
            libvirtBlockResize(libvirtComputingResource, newSize, vmInstanceName, vol);
        } catch (final LVMException e) {
            // First step went wrong, nothing to clean up. Just return that it didn't work out.
            return new ResizeVolumeAnswer(command, false, e.toString());
        } catch (final LibvirtException e) {
            // Second step went wrong, we should resize the volume back to how it was!
            try {
                lvm.resize(currentSize, vol.getPath());
            } catch (final LVMException e1) {
                s_logger.error("Unable to reverse lv resize: " + e1);
            }
            return new ResizeVolumeAnswer(command, false, e.toString());
        }
    } else if (pool.getType() == StoragePoolType.NetworkFilesystem) {
        if (vol.getFormat() == PhysicalDiskFormat.QCOW2 && shrinkOk) {
            return new ResizeVolumeAnswer(command, false, "Unable to shrink volumes of type " + PhysicalDiskFormat.QCOW2);
        }
        try {
            final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
            final Connect connection = libvirtUtilitiesHelper.getConnection();
            final StorageVol storageVol = connection.storageVolLookupByPath(vol.getPath());
            final VirtualMachine.PowerState state = libvirtComputingResource.getVmState(libvirtUtilitiesHelper.getConnection(), vmInstanceName);
            if (state == VirtualMachine.PowerState.PowerOn) {
                libvirtBlockResize(libvirtComputingResource, newSize, vmInstanceName, vol);
            } else {
                final int flags = shrinkOk ? StorageVol.ResizeFlags.SHRINK : 0;
                storageVol.resize(newSize, flags);
            }
        } catch (final LibvirtException e) {
            return new ResizeVolumeAnswer(command, false, e.toString());
        }
    }
    /* fetch new size as seen from libvirt, don't want to assume anything */
    pool.refresh();
    final long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
    s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
    return new ResizeVolumeAnswer(command, true, "success", finalSize);
}
Also used : LVM(com.cloud.agent.resource.kvm.storage.utils.LVM) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) LibvirtException(org.libvirt.LibvirtException) StorageVol(org.libvirt.StorageVol) LVMException(com.cloud.agent.resource.kvm.storage.utils.LVMException) Connect(org.libvirt.Connect) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 3 with ResizeVolumeAnswer

use of com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer 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)

Aggregations

ResizeVolumeAnswer (com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer)3 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)2 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)1 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)1 LVM (com.cloud.agent.resource.kvm.storage.utils.LVM)1 LVMException (com.cloud.agent.resource.kvm.storage.utils.LVMException)1 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)1 ResizeVolumeCommand (com.cloud.legacymodel.communication.command.ResizeVolumeCommand)1 StorageUnavailableException (com.cloud.legacymodel.exceptions.StorageUnavailableException)1 StoragePool (com.cloud.legacymodel.storage.StoragePool)1 VirtualMachine (com.cloud.legacymodel.vm.VirtualMachine)1 ResizeVolumePayload (com.cloud.storage.ResizeVolumePayload)1 VolumeObject (com.cloud.storage.volume.VolumeObject)1 Connection (com.xensource.xenapi.Connection)1 VDI (com.xensource.xenapi.VDI)1 Connect (org.libvirt.Connect)1 LibvirtException (org.libvirt.LibvirtException)1 StorageVol (org.libvirt.StorageVol)1