Examples of StorageFilerTO


Examples of com.cloud.agent.api.to.StorageFilerTO

            that it always sets copyToSecondary to true

         */
        boolean copyToSecondary = cmd.toSecondaryStorage();
        String volumePath = cmd.getVolumePath();
        StorageFilerTO pool = cmd.getPool();
        String secondaryStorageUrl = cmd.getSecondaryStorageURL();
        KVMStoragePool secondaryStoragePool = null;
        KVMStoragePool primaryPool = null;
        try {
            try {
                primaryPool = _storagePoolMgr.getStoragePool(
                     pool.getType(),
                     pool.getUuid());
            } catch (CloudRuntimeException e) {
                if (e.getMessage().contains("not found")) {
                    primaryPool = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
                                      cmd.getPool().getHost(), cmd.getPool().getPort(),
                                      cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

    protected Storage.StorageResourceType getStorageResourceType() {
        return Storage.StorageResourceType.STORAGE_POOL;
    }

    protected Answer execute(CreateCommand cmd) {
        StorageFilerTO pool = cmd.getPool();
        DiskProfile dskch = cmd.getDiskCharacteristics();
        KVMPhysicalDisk BaseVol = null;
        KVMStoragePool primaryPool = null;
        KVMPhysicalDisk vol = null;
        long disksize;
        try {
            primaryPool = _storagePoolMgr.getStoragePool(pool.getType(),
                    pool.getUuid());
            disksize = dskch.getSize();

            if (cmd.getTemplateUrl() != null) {
                if(primaryPool.getType() == StoragePoolType.CLVM) {
                    vol = templateToPrimaryDownload(cmd.getTemplateUrl(),primaryPool);
                } else {
                    BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
                    vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID
                            .randomUUID().toString(), primaryPool);
                }
                if (vol == null) {
                    return new Answer(cmd, false,
                            " Can't create storage volume on storage pool");
                }
            } else {
                vol = primaryPool.createPhysicalDisk(UUID.randomUUID()
                        .toString(), dskch.getSize());
            }
            VolumeTO volume = new VolumeTO(cmd.getVolumeId(), dskch.getType(),
                    pool.getType(), pool.getUuid(), pool.getPath(),
                    vol.getName(), vol.getName(), disksize, null);
            volume.setBytesReadRate(dskch.getBytesReadRate());
            volume.setBytesWriteRate(dskch.getBytesWriteRate());
            volume.setIopsReadRate(dskch.getIopsReadRate());
            volume.setIopsWriteRate(dskch.getIopsWriteRate());
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        String volid = cmd.getPath();
        long newSize = cmd.getNewSize();
        long currentSize = cmd.getCurrentSize();
        String vmInstanceName = cmd.getInstanceName();
        boolean shrinkOk = cmd.getShrinkOk();
        StorageFilerTO spool = cmd.getPool();

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

            /**
             * RBD volumes can't be resized via a Bash script or via libvirt
             *
             * libvirt-java doesn't implemented resizing volumes, so we have to do this manually
             *
             * 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());
                }
            } 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;
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
    }

    @Override
    public CreateAnswer createVolume(CreateCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        DiskProfile dskch = cmd.getDiskCharacteristics();
        MockStoragePoolVO storagePool = null;
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
            txn.commit();
            if (storagePool == null) {
                return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
            }
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding storage " + sf.getUuid(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        String volumeName = UUID.randomUUID().toString();
        MockVolumeVO volume = new MockVolumeVO();
        volume.setPoolId(storagePool.getId());
        volume.setName(volumeName);
        volume.setPath(storagePool.getMountPoint() + volumeName);
        volume.setSize(dskch.getSize());
        volume.setType(MockVolumeType.VOLUME);
        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            volume = _mockVolumeDao.persist(volume);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving volume " + volume, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(),
                volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);

        return new CreateAnswer(cmd, volumeTo);
    }
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        }
    }

    @Override
    public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
            if (storagePool == null) {
                storagePool = new MockStoragePoolVO();
                storagePool.setUuid(sf.getUuid());
                storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);

                Long size = DEFAULT_HOST_STORAGE_SIZE;
                String path = sf.getPath();
                int index = path.lastIndexOf("/");
                if (index != -1) {
                    path = path.substring(index + 1);
                    if (path != null) {
                        String values[] = path.split("=");
                        if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
                            size = Long.parseLong(values[1]);
                        }
                    }
                }
                storagePool.setCapacity(size);
                storagePool.setStorageType(sf.getType());
                storagePool = _mockStoragePoolDao.persist(storagePool);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
    }

    @Override
    public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
            if (storagePool == null) {
                storagePool = new MockStoragePoolVO();
                storagePool.setUuid(sf.getUuid());
                storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);

                Long size = DEFAULT_HOST_STORAGE_SIZE;
                String path = sf.getPath();
                int index = path.lastIndexOf("/");
                if (index != -1) {
                    path = path.substring(index + 1);
                    if (path != null) {
                        String values[] = path.split("=");
                        if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
                            size = Long.parseLong(values[1]);
                        }
                    }
                }
                storagePool.setCapacity(size);
                storagePool.setStorageType(sf.getType());
                storagePool = _mockStoragePoolDao.persist(storagePool);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

    public void resize(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
        VolumeObject vol = (VolumeObject) data;
        StoragePool pool = (StoragePool) data.getDataStore();
        ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();

        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);
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        public CreateVolumeOVACommand(String secUrl, String volPath, String volName, StoragePool pool, int wait) {
        this.secUrl = secUrl;
        this.volPath = volPath;
        this.volName = volName;
        this.pool = new StorageFilerTO(pool);
        setWait(wait);
   }
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

            }
        }
    }
    protected Answer execute(CreateStoragePoolCommand cmd) {
        Connection conn = this.hypervisorResource.getConnection();
        StorageFilerTO pool = cmd.getPool();
        try {
            if (pool.getType() == StoragePoolType.NetworkFilesystem) {
                getNfsSR(conn, pool);
            } else if (pool.getType() == StoragePoolType.IscsiLUN) {
                getIscsiSR(conn, pool);
            } else if (pool.getType() == StoragePoolType.PreSetup) {
            } else {
                return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
            }
            return new Answer(cmd, true, "success");
        } catch (Exception e) {
            String msg = "Catch Exception " + e.getClass().getName() + ", create StoragePool failed due to " + e.toString() + " on host:" + this.hypervisorResource.getHost().uuid + " pool: " + pool.getHost() + pool.getPath();
            s_logger.warn(msg, e);
            return new Answer(cmd, false, msg);
        }

    }
View Full Code Here

Examples of com.cloud.agent.api.to.StorageFilerTO

        try {
            Map<VolumeTO, StorageFilerTO> volumeToFilerto = new HashMap<VolumeTO, StorageFilerTO>();
            for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                VolumeInfo volume = entry.getKey();
                VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
                StorageFilerTO filerTo = new StorageFilerTO((StoragePool)entry.getValue());
                volumeToFilerto.put(volumeTo, filerTo);
            }

            // Migration across cluster needs to be done in three phases.
            // 1. Send a migrate receive command to the destination host so that it is ready to receive a vm.
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.