Examples of Rados


Examples of com.ceph.rados.Rados

             * It will stop doing so if the amount of time spend is longer then
             * cmds.timeout
             */
            if (primaryPool.getType() == StoragePoolType.RBD) {
                try {
                    Rados r = new Rados(primaryPool.getAuthUserName());
                    r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                    r.confSet("key", primaryPool.getAuthSecret());
                    r.connect();
                    s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                    IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                    Rbd rbd = new Rbd(io);
                    RbdImage image = rbd.open(snapshotDisk.getName(), snapshotName);

                    long startTime = System.currentTimeMillis() / 1000;

                    File snapDir = new File(snapshotDestPath);
                    s_logger.debug("Attempting to create " + snapDir.getAbsolutePath() + " recursively");
                    FileUtils.forceMkdir(snapDir);

                    File snapFile = new File(snapshotDestPath + "/" + snapshotName);
                    s_logger.debug("Backing up RBD snapshot to " + snapFile.getAbsolutePath());
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(snapFile));
                    int chunkSize = 4194304;
                    long offset = 0;
                    while(true) {
                        byte[] buf = new byte[chunkSize];

                        int bytes = image.read(offset, buf, chunkSize);
                        if (bytes <= 0) {
                            break;
                        }
                        bos.write(buf, 0, bytes);
                        offset += bytes;
                    }
                    s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to  " + snapFile.getAbsolutePath() + ". Bytes written: " + offset);
                    bos.close();

                    s_logger.debug("Attempting to remove snapshot RBD " + snapshotName + " from image " + snapshotDisk.getName());
                    image.snapRemove(snapshotName);

                    r.ioCtxDestroy(io);
                } catch (RadosException e) {
                    s_logger.error("A RADOS operation failed. The error was: " + e.getMessage());
                    return new CopyCmdAnswer(e.toString());
                } catch (RbdException e) {
                    s_logger.error("A RBD operation on " + snapshotDisk.getName() + " failed. The error was: " + e.getMessage());
View Full Code Here

Examples of com.ceph.rados.Rados

                 * barriers properly (>2.6.32) this won't be any different then pulling the power
                 * cord out of a running machine.
                 */
                if (primaryPool.getType() == StoragePoolType.RBD) {
                    try {
                        Rados r = new Rados(primaryPool.getAuthUserName());
                        r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                        r.confSet("key", primaryPool.getAuthSecret());
                        r.connect();
                        s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                        IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                        Rbd rbd = new Rbd(io);
                        RbdImage image = rbd.open(disk.getName());

                        s_logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName);
                        image.snapCreate(snapshotName);

                        rbd.close(image);
                        r.ioCtxDestroy(io);
                    } catch (Exception e) {
                        s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage());
                    }
                } else {
                    /* VM is not running, create a snapshot by ourself */
 
View Full Code Here

Examples of com.ceph.rados.Rados

            format = PhysicalDiskFormat.RAW;

            try {
                s_logger.info("Creating RBD image " + pool.getSourceDir() + "/" + name + " with size " + size);

                Rados r = new Rados(pool.getAuthUserName());
                r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort());
                r.confSet("key", pool.getAuthSecret());
                r.connect();
                s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                IoCTX io = r.ioCtxCreate(pool.getSourceDir());
                Rbd rbd = new Rbd(io);
                rbd.create(name, size, this.rbdFeatures, this.rbdOrder);

                r.ioCtxDestroy(io);
            } catch (RadosException e) {
                throw new CloudRuntimeException(e.toString());
            } catch (RbdException e) {
                throw new CloudRuntimeException(e.toString());
            }
View Full Code Here

Examples of com.ceph.rados.Rados

        if (pool.getType() == StoragePoolType.RBD) {
            try {
                s_logger.info("Unprotecting and Removing RBD snapshots of image "
                               + pool.getSourcePort() + "/" + uuid + " prior to removing the image");

                Rados r = new Rados(pool.getAuthUserName());
                r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort());
                r.confSet("key", pool.getAuthSecret());
                r.connect();
                s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                IoCTX io = r.ioCtxCreate(pool.getSourceDir());
                Rbd rbd = new Rbd(io);
                RbdImage image = rbd.open(uuid);
                List<RbdSnapInfo> snaps = image.snapList();
                for (RbdSnapInfo snap : snaps) {
                    image.snapUnprotect(snap.name);
                    image.snapRemove(snap.name);
                }

                rbd.close(image);
                r.ioCtxDestroy(io);
            } catch (RadosException e) {
                throw new CloudRuntimeException(e.toString());
            } catch (RbdException e) {
                throw new CloudRuntimeException(e.toString());
            }
View Full Code Here

Examples of com.ceph.rados.Rados

                    try {
                        if ((srcPool.getSourceHost().equals(destPool.getSourceHost())) && (srcPool.getSourceDir().equals(destPool.getSourceDir()))) {
                            /* We are on the same Ceph cluster, but we require RBD format 2 on the source image */
                            s_logger.debug("Trying to perform a RBD clone (layering) since we are operating in the same storage pool");

                            Rados r = new Rados(srcPool.getAuthUserName());
                            r.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort());
                            r.confSet("key", srcPool.getAuthSecret());
                            r.connect();
                            s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                            IoCTX io = r.ioCtxCreate(srcPool.getSourceDir());
                            Rbd rbd = new Rbd(io);
                            RbdImage srcImage = rbd.open(template.getName());

                            if (srcImage.isOldFormat()) {
                                /* The source image is RBD format 1, we have to do a regular copy */
                                s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName()
                                               + " is RBD format 1. We have to perform a regular copy (" + template.getVirtualSize() + " bytes)");

                                rbd.create(disk.getName(), template.getVirtualSize(), this.rbdFeatures, this.rbdOrder);
                                RbdImage destImage = rbd.open(disk.getName());

                                s_logger.debug("Starting to copy " + srcImage.getName() " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir());
                                rbd.copy(srcImage, destImage);

                                s_logger.debug("Finished copying " + srcImage.getName() " to " + destImage.getName() + " in Ceph pool " + srcPool.getSourceDir());
                                rbd.close(destImage);
                            } else {
                                s_logger.debug("The source image " + srcPool.getSourceDir() + "/" + template.getName()
                                               + " is RBD format 2. We will perform a RBD clone using snapshot "
                                               + this.rbdTemplateSnapName);
                                /* The source image is format 2, we can do a RBD snapshot+clone (layering) */
                                rbd.clone(template.getName(), this.rbdTemplateSnapName, io, disk.getName(), this.rbdFeatures, this.rbdOrder);
                                s_logger.debug("Succesfully cloned " + template.getName() + "@" + this.rbdTemplateSnapName + " to " + disk.getName());
                            }

                            rbd.close(srcImage);
                            r.ioCtxDestroy(io);
                        } else {
                            /* The source pool or host is not the same Ceph cluster, we do a simple copy with Qemu-Img */
                            s_logger.debug("Both the source and destination are RBD, but not the same Ceph cluster. Performing a copy");

                            Rados rSrc = new Rados(srcPool.getAuthUserName());
                            rSrc.confSet("mon_host", srcPool.getSourceHost() + ":" + srcPool.getSourcePort());
                            rSrc.confSet("key", srcPool.getAuthSecret());
                            rSrc.connect();
                            s_logger.debug("Succesfully connected to source Ceph cluster at " + rSrc.confGet("mon_host"));

                            Rados rDest = new Rados(destPool.getAuthUserName());
                            rDest.confSet("mon_host", destPool.getSourceHost() + ":" + destPool.getSourcePort());
                            rDest.confSet("key", destPool.getAuthSecret());
                            rDest.connect();
                            s_logger.debug("Succesfully connected to source Ceph cluster at " + rDest.confGet("mon_host"));

                            IoCTX sIO = rSrc.ioCtxCreate(srcPool.getSourceDir());
                            Rbd sRbd = new Rbd(sIO);

                            IoCTX dIO = rDest.ioCtxCreate(destPool.getSourceDir());
                            Rbd dRbd = new Rbd(dIO);

                            s_logger.debug("Creating " + disk.getName() + " on the destination cluster " + rDest.confGet("mon_host")
                                           + " in pool " + destPool.getSourceDir());
                            dRbd.create(disk.getName(), template.getVirtualSize(), this.rbdFeatures, this.rbdOrder);

                            RbdImage srcImage = sRbd.open(template.getName());
                            RbdImage destImage = dRbd.open(disk.getName());

                            s_logger.debug("Copying " + template.getName() + " from Ceph cluster " + rSrc.confGet("mon_host") + " to " + disk.getName()
                                           + " on cluster " + rDest.confGet("mon_host"));
                            sRbd.copy(srcImage, destImage);

                            sRbd.close(srcImage);
                            dRbd.close(destImage);

                            rSrc.ioCtxDestroy(sIO);
                            rDest.ioCtxDestroy(dIO);
                        }
                    } catch (RadosException e) {
                        s_logger.error("Failed to perform a RADOS action on the Ceph cluster, the error was: " + e.getMessage());
                        disk = null;
                    } catch (RbdException e) {
View Full Code Here

Examples of com.ceph.rados.Rados

                    // Source file is RAW, we can write directly to RBD
                    sourceFile = sourcePath;
                }

                // We now convert the temporary file to a RBD image with format 2
                Rados r = new Rados(destPool.getAuthUserName());
                r.confSet("mon_host", destPool.getSourceHost() + ":" + destPool.getSourcePort());
                r.confSet("key", destPool.getAuthSecret());
                r.connect();
                s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                IoCTX io = r.ioCtxCreate(destPool.getSourceDir());
                Rbd rbd = new Rbd(io);

                s_logger.debug("Creating RBD image " + name + " in Ceph pool " + destPool.getSourceDir() + " with RBD format 2");
                rbd.create(name, disk.getVirtualSize(), this.rbdFeatures, this.rbdOrder);

                RbdImage image = rbd.open(name);

                File fh = new File(sourceFile);
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(fh));

                int chunkSize = 4194304;
                long offset = 0;
                s_logger.debug("Reading file " + sourceFile + " (" + fh.length() + " bytes) into RBD image " + name + " in chunks of " + chunkSize + " bytes");
                while(true) {
                    byte[] buf = new byte[chunkSize];

                    int bytes = bis.read(buf);
                    if (bytes <= 0) {
                        break;
                    }
                    image.write(buf, offset, bytes);
                    offset += bytes;
                }
                s_logger.debug("Completed writing " + sourceFile + " to RBD image " + name + ". Bytes written: " + offset);
                bis.close();

                if (useTmpFile) {
                    s_logger.debug("Removing temporary file " + sourceFile);
                    fh.delete();
                }

                /* Snapshot the image and protect that snapshot so we can clone (layer) from it */
                s_logger.debug("Creating RBD snapshot " + this.rbdTemplateSnapName + " on image " + name);
                image.snapCreate(this.rbdTemplateSnapName);
                s_logger.debug("Protecting RBD snapshot " + this.rbdTemplateSnapName + " on image " + name);
                image.snapProtect(this.rbdTemplateSnapName);

                rbd.close(image);
                r.ioCtxDestroy(io);
            } catch (QemuImgException e) {
                s_logger.error("Failed to do a temp convert from " + srcFile.getFileName() + " to "
                        + destFile.getFileName() + " the error was: " + e.getMessage());
                newDisk = null;
            } catch (RadosException e) {
View Full Code Here

Examples of com.ceph.rados.Rados

             *
             * Future fix would be to hand this over to libvirt
             */
            if (pool.getType() == StoragePoolType.RBD) {
                try {
                    Rados r = new Rados(pool.getAuthUserName());
                    r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort());
                    r.confSet("key", pool.getAuthSecret());
                    r.connect();
                    s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                    IoCTX io = r.ioCtxCreate(pool.getSourceDir());
                    Rbd rbd = new Rbd(io);
                    RbdImage image = rbd.open(vol.getName());

                    s_logger.debug("Resizing RBD volume " + vol.getName() " to " + newSize + " bytes");
                    image.resize(newSize);
                    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());
View Full Code Here

Examples of com.ceph.rados.Rados

                 * barriers properly (>2.6.32) this won't be any different then pulling the power
                 * cord out of a running machine.
                 */
                if (primaryPool.getType() == StoragePoolType.RBD) {
                    try {
                        Rados r = new Rados(primaryPool.getAuthUserName());
                        r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                        r.confSet("key", primaryPool.getAuthSecret());
                        r.connect();
                        s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                        IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                        Rbd rbd = new Rbd(io);
                        RbdImage image = rbd.open(disk.getName());

                        if (cmd.getCommandSwitch().equalsIgnoreCase(
                            ManageSnapshotCommand.CREATE_SNAPSHOT)) {
                            s_logger.debug("Attempting to create RBD snapshot " + disk.getName() + "@" + snapshotName);
                            image.snapCreate(snapshotName);
                        } else {
                            s_logger.debug("Attempting to remove RBD snapshot " + disk.getName() + "@" + snapshotName);
                            image.snapRemove(snapshotName);
                        }

                        rbd.close(image);
                        r.ioCtxDestroy(io);
                    } catch (Exception e) {
                        s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage());
                    }
                } else {
                    /* VM is not running, create a snapshot by ourself */
 
View Full Code Here

Examples of com.ceph.rados.Rados

             * It will stop doing so if the amount of time spend is longer then
             * cmds.timeout
             */
            if (primaryPool.getType() == StoragePoolType.RBD) {
                try {
                    Rados r = new Rados(primaryPool.getAuthUserName());
                    r.confSet("mon_host", primaryPool.getSourceHost() + ":" + primaryPool.getSourcePort());
                    r.confSet("key", primaryPool.getAuthSecret());
                    r.connect();
                    s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                    IoCTX io = r.ioCtxCreate(primaryPool.getSourceDir());
                    Rbd rbd = new Rbd(io);
                    RbdImage image = rbd.open(snapshotDisk.getName(), snapshotName);

                    long startTime = System.currentTimeMillis() / 1000;

                    File fh = new File(snapshotDestPath);
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fh));
                    int chunkSize = 4194304;
                    long offset = 0;
                    s_logger.debug("Backuping up RBD snapshot " + snapshotName + " to  " + snapshotDestPath);
                    while(true) {
                        byte[] buf = new byte[chunkSize];

                        int bytes = image.read(offset, buf, chunkSize);
                        if (bytes <= 0) {
                            break;
                        }
                        bos.write(buf, 0, bytes);
                        offset += bytes;
                    }
                    s_logger.debug("Completed backing up RBD snapshot " + snapshotName + " to  " + snapshotDestPath + ". Bytes written: " + offset);
                    bos.close();
                    r.ioCtxDestroy(io);
                } catch (RadosException e) {
                    s_logger.error("A RADOS operation failed. The error was: " + e.getMessage());
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                } catch (RbdException e) {
                    s_logger.error("A RBD operation on " + snapshotDisk.getName() + " failed. The error was: " + e.getMessage());
View Full Code Here

Examples of com.ceph.rados.Rados

            format = PhysicalDiskFormat.RAW;

            try {
                s_logger.info("Creating RBD image " + pool.getSourceDir() + "/" + name + " with size " + size);

                Rados r = new Rados(pool.getAuthUserName());
                r.confSet("mon_host", pool.getSourceHost() + ":" + pool.getSourcePort());
                r.confSet("key", pool.getAuthSecret());
                r.connect();
                s_logger.debug("Succesfully connected to Ceph cluster at " + r.confGet("mon_host"));

                IoCTX io = r.ioCtxCreate(pool.getSourceDir());
                Rbd rbd = new Rbd(io);
                rbd.create(name, size, this.rbdFeatures, this.rbdOrder);

                r.ioCtxDestroy(io);
            } catch (RadosException e) {
                throw new CloudRuntimeException(e.toString());
            } catch (RbdException e) {
                throw new CloudRuntimeException(e.toString());
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.