Package com.cloud.agent.api.storage

Examples of com.cloud.agent.api.storage.ResizeVolumeAnswer


        long newSize = cmd.getNewSize();

        try {
            VDI vdi = getVDIbyUuid(conn, volid);
            vdi.resize(conn, newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", newSize);
        } catch (Exception e) {
            s_logger.warn("Unable to resize volume",e);
            String error = "failed to resize volume:"  +e;
            return new ResizeVolumeAnswer(cmd, false, error );
        }
    }
View Full Code Here


                deleteWorkerVm(vmMo, vmdkDataStorePath);
            }
            if (newSize < oldSize){
                throw new Exception("VMware doesn't support shrinking volume from larger size: " + oldSize+ " MB to a smaller size: " + newSize + " MB");
            } else if(newSize == oldSize){
                return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
            }
            disk.setCapacityInKB(newSize);

            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
            deviceConfigSpec.setDevice(disk);
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
            if (!vmMo.configureVm(vmConfigSpec)) {
                if (useWorkerVm == true) {
                    deleteWorkerVm(vmMo, vmdkDataStorePath);
                }
                throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
            }
            if (useWorkerVm == true) {
                deleteWorkerVm(vmMo, vmdkDataStorePath);
            }
            return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
        } catch (Exception e) {
            s_logger.error("Unable to resize volume",e);
            String error = "failed to resize volume:"  +e;
            return new ResizeVolumeAnswer(cmd, false, error );
        }
    }
View Full Code Here

                    rbd.close(image);

                    r.ioCtxDestroy(io);
                    s_logger.debug("Succesfully resized RBD volume " + vol.getName() " to " + newSize + " bytes");
                } catch (RadosException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                } catch (RbdException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                }
            } else {
                if (type == null) {
                    return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '"
                                    + pool.getType() + "' and volume format '" + vol.getFormat() + "'");
                } else if (type.equals("QCOW2") && shrinkOk) {
                    return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type);
                }

                s_logger.debug("got to the stage where we execute the volume resize, params:"
                            + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);
                final Script resizecmd = new Script(_resizeVolumePath,
                            _cmdsTimeout, s_logger);
                resizecmd.add("-s",String.valueOf(newSize));
                resizecmd.add("-c",String.valueOf(currentSize));
                resizecmd.add("-p",path);
                resizecmd.add("-t",type);
                resizecmd.add("-r",String.valueOf(shrinkOk));
                resizecmd.add("-v",vmInstanceName);
                String result = resizecmd.execute();

                if (result != null) {
                    return new ResizeVolumeAnswer(cmd, false, result);
                }
            }

            /* fetch new size as seen from libvirt, don't want to assume anything */
            pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
            s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", finalSize);
        } catch (CloudRuntimeException e) {
            String error = "failed to resize volume: " + e;
            s_logger.debug(error);
            return new ResizeVolumeAnswer(cmd, false, error);
        }

    }
View Full Code Here

        ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(),
                resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
        CreateCmdResult result = new CreateCmdResult(null, null);
        try {
            ResizeVolumeAnswer answer = (ResizeVolumeAnswer) this.storageMgr.sendToPool(pool, resizeParameter.hosts,
                    resizeCmd);
            if (answer != null && answer.getResult()) {
                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");
            }
View Full Code Here

                    rbd.close(image);

                    r.ioCtxDestroy(io);
                    s_logger.debug("Succesfully resized RBD volume " + vol.getName() " to " + newSize + " bytes");
                } catch (RadosException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                } catch (RbdException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                }
            } else {
                if (type == null) {
                    return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '"
                                    + pool.getType() + "' and volume format '" + vol.getFormat() + "'");
                } else if (type.equals("QCOW2") && shrinkOk) {
                    return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type);
                }

                s_logger.debug("got to the stage where we execute the volume resize, params:"
                            + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);
                final Script resizecmd = new Script(_resizeVolumePath,
                            _cmdsTimeout, s_logger);
                resizecmd.add("-s",String.valueOf(newSize));
                resizecmd.add("-c",String.valueOf(currentSize));
                resizecmd.add("-p",path);
                resizecmd.add("-t",type);
                resizecmd.add("-r",String.valueOf(shrinkOk));
                resizecmd.add("-v",vmInstanceName);
                String result = resizecmd.execute();

                if (result != null) {
                    return new ResizeVolumeAnswer(cmd, false, result);
                }
            }

            /* fetch new size as seen from libvirt, don't want to assume anything */
            pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
            s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", finalSize);
        } catch (CloudRuntimeException e) {
            String error = "failed to resize volume: " + e;
            s_logger.debug(error);
            return new ResizeVolumeAnswer(cmd, false, error);
        }

    }
View Full Code Here

            VirtualDisk disk = vdisk.first();
            long oldSize = disk.getCapacityInKB();
            if (newSize < oldSize){
                throw new Exception("VMware doesn't support shrinking volume from larger size: " + oldSize+ " MB to a smaller size: " + newSize + " MB");
            } else if(newSize == oldSize){
                return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
            }
            disk.setCapacityInKB(newSize);

            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
            deviceConfigSpec.setDevice(disk);
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
            if (!vmMo.configureVm(vmConfigSpec)) {
                throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
            }

            return new ResizeVolumeAnswer(cmd, true, "success", newSize*1024);
        } catch (Exception e) {
            s_logger.error("Unable to resize volume",e);
            String error = "failed to resize volume:"  +e;
            return new ResizeVolumeAnswer(cmd, false, error );
        }
    }
View Full Code Here

        long newSize = cmd.getNewSize();

        try {
            VDI vdi = getVDIbyUuid(conn, volid);
            vdi.resize(conn, newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", newSize);
        } catch (Exception e) {
            s_logger.warn("Unable to resize volume", e);
            String error = "failed to resize volume:" + e;
            return new ResizeVolumeAnswer(cmd, false, error);
        }
    }
View Full Code Here

        ResizeVolumeCommand resizeCmd =
                new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk,
                        resizeParameter.instanceName);
        CreateCmdResult result = new CreateCmdResult(null, null);
        try {
            ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
            if (answer != null && answer.getResult()) {
                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");
            }
View Full Code Here

            VirtualDisk disk = vdisk.first();
            long oldSize = disk.getCapacityInKB();
            if (newSize < oldSize) {
                throw new Exception("VMware doesn't support shrinking volume from larger size: " + oldSize + " MB to a smaller size: " + newSize + " MB");
            } else if (newSize == oldSize) {
                return new ResizeVolumeAnswer(cmd, true, "success", newSize * 1024);
            }
            disk.setCapacityInKB(newSize);

            VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
            VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
            deviceConfigSpec.setDevice(disk);
            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
            vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
            if (!vmMo.configureVm(vmConfigSpec)) {
                throw new Exception("Failed to configure VM to resize disk. vmName: " + vmName);
            }

            return new ResizeVolumeAnswer(cmd, true, "success", newSize * 1024);
        } catch (Exception e) {
            s_logger.error("Unable to resize volume", e);
            String error = "failed to resize volume:" + e;
            return new ResizeVolumeAnswer(cmd, false, error);
        }
    }
View Full Code Here

        StorageFilerTO spool = cmd.getPool();

        if ( currentSize == newSize) {
            // nothing to do
            s_logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", currentSize);
        }

        try {
            KVMStoragePool pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            KVMPhysicalDisk vol = pool.getPhysicalDisk(volid);
            String path = vol.getPath();
            String type = getResizeScriptType(pool, vol);

            if (type == null) {
                return new ResizeVolumeAnswer(cmd, false, "Unsupported volume format: pool type '" + pool.getType() + "' and volume format '" + vol.getFormat() + "'");
            } else if (type.equals("QCOW2") && shrinkOk) {
                return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type);
            }

            s_logger.debug("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);

            /* libvirt doesn't support resizing (C)LVM devices, so we have to do that via a Bash script */
            if (pool.getType() != StoragePoolType.CLVM) {
                s_logger.debug("Volume " + path +  " can be resized by libvirt. Asking libvirt to resize the volume.");
                try {
                    Connect conn = LibvirtConnection.getConnection();
                    StorageVol v = conn.storageVolLookupByPath(path);
                    int flags = 0;

                    if (conn.getLibVirVersion() > 1001000 && vol.getFormat() == PhysicalDiskFormat.RAW) {
                        flags = 1;
                    }
                    if (shrinkOk) {
                        flags = 4;
                    }

                    v.resize(newSize, flags);
                } catch (LibvirtException e) {
                    return new ResizeVolumeAnswer(cmd, false, e.toString());
                }
            } else {
                s_logger.debug("Volume " + path + " is of the type LVM and can not be resized using libvirt. Invoking resize script.");
                final Script resizecmd = new Script(_resizeVolumePath, _cmdsTimeout, s_logger);
                resizecmd.add("-s", String.valueOf(newSize));
                resizecmd.add("-c", String.valueOf(currentSize));
                resizecmd.add("-p", path);
                resizecmd.add("-t", type);
                resizecmd.add("-r", String.valueOf(shrinkOk));
                resizecmd.add("-v", vmInstanceName);
                String result = resizecmd.execute();

                if (result != null) {
                    return new ResizeVolumeAnswer(cmd, false, result);
                }
            }

            /* fetch new size as seen from libvirt, don't want to assume anything */
            pool = _storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
            long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
            s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
            return new ResizeVolumeAnswer(cmd, true, "success", finalSize);
        } catch (CloudRuntimeException e) {
            String error = "failed to resize volume: " + e;
            s_logger.debug(error);
            return new ResizeVolumeAnswer(cmd, false, error);
        }

    }
View Full Code Here

TOP

Related Classes of com.cloud.agent.api.storage.ResizeVolumeAnswer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.