Package com.cloud.simulator

Examples of com.cloud.simulator.MockVolumeVO


            if (secStorage == null) {
                return null;
            }
            volumePath = secStorage.getMountPoint() + volumePath;
            volumePath = volumePath.replaceAll("//", "/");
            MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
            txn.commit();
            if (volume == null) {
                return null;
            }
            return volume;
View Full Code Here


        }
    }

    @Override
    public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
        MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(),
                MockVolumeType.TEMPLATE);
        if (template == null) {
            return new PrimaryStorageDownloadAnswer("Can't find primary storage");
        }

        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockStoragePoolVO primaryStorage = null;
        try {
            txn.start();
            primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
            txn.commit();
            if (primaryStorage == null) {
                return new PrimaryStorageDownloadAnswer("Can't find primary storage");
            }
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

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

            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

        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            String poolid = cmd.getPoolUuid();
            String volumeName = cmd.getVolumeName();
            MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
            if (volume == null) {
                return new AttachVolumeAnswer(cmd, "Can't find volume:" + volumeName + "on pool:" + poolid);
            }

            String vmName = cmd.getVmName();
View Full Code Here

        }
    }

    @Override
    public Answer AttachIso(AttachIsoCommand cmd) {
        MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO);
        if (iso == null) {
            return new Answer(cmd, false, "Failed to find the iso: " + cmd.getIsoPath() + "on secondary storage "
                    + cmd.getStoreUrl());
        }
View Full Code Here

    @Override
    public Answer Destroy(DestroyCommand cmd) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
            if (volume != null) {
                _mockVolumeDao.remove(volume.getId());
            }

            if (cmd.getVmName() != null) {
                MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
                vm.setState(State.Expunging);
View Full Code Here

            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        MockVolumeVO volume = new MockVolumeVO();
        volume.setPoolId(ssvo.getId());
        volume.setName(cmd.getName());
        volume.setPath(ssvo.getMountPoint() + cmd.getName());
        volume.setSize(0);
        volume.setType(MockVolumeType.TEMPLATE);
        volume.setStatus(Status.DOWNLOAD_IN_PROGRESS);
        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();
        }
        return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS,
                cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
    }
View Full Code Here

    public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            String volumeId = cmd.getJobId();
            MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
            if (volume == null) {
                return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
            }

            long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
            volume.setSize(size);

            double volumeSize = volume.getSize();
            double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
            if (pct >= 1.0) {
                volume.setStatus(Status.DOWNLOADED);
                _mockVolumeDao.update(volume.getId(), volume);
                txn.commit();
                return new DownloadAnswer(cmd.getJobId(), 100, cmd,
                        com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(),
                        volume.getName());
            } else {
                _mockVolumeDao.update(volume.getId(), volume);
                txn.commit();
                return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd,
                        com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(),
                        volume.getName());
            }
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error during download job " + cmd.getJobId(), ex);
        } finally {
View Full Code Here

    }

    @Override
    public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
        String volPath = cmd.getVolumePath();
        MockVolumeVO volume = null;
        MockStoragePoolVO storagePool = null;
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            volume = _mockVolumeDao.findByStoragePathAndType(volPath);
            if (volume == null) {
                return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
            }
            storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
            if (storagePool == null) {
                return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to perform snapshot", ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        String mountPoint = storagePool.getMountPoint();
        MockVolumeVO snapshot = new MockVolumeVO();

        snapshot.setName(cmd.getSnapshotName());
        snapshot.setPath(mountPoint + cmd.getSnapshotName());
        snapshot.setSize(volume.getSize());
        snapshot.setPoolId(storagePool.getId());
        snapshot.setType(MockVolumeType.SNAPSHOT);
        snapshot.setStatus(Status.DOWNLOADED);
        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            snapshot = _mockVolumeDao.persist(snapshot);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
    }
View Full Code Here

    @Override
    public BackupSnapshotAnswer BackupSnapshot(BackupSnapshotCommand cmd, SimulatorInfo info) {
        // emulate xenserver backupsnapshot, if the base volume is deleted, then
        // backupsnapshot failed
        MockVolumeVO volume = null;
        MockVolumeVO snapshot = null;
        MockSecStorageVO secStorage = null;
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
            if (volume == null) {
                return new BackupSnapshotAnswer(cmd, false, "Can't find base volume: " + cmd.getVolumePath(), null,
                        true);
            }
            String snapshotPath = cmd.getSnapshotUuid();
            snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
            if (snapshot == null) {
                return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
            }

            String secStorageUrl = cmd.getSecondaryStorageUrl();
            secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
            if (secStorage == null) {
                return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when backing up snapshot");
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        MockVolumeVO newsnapshot = new MockVolumeVO();
        String name = UUID.randomUUID().toString();
        newsnapshot.setName(name);
        newsnapshot.setPath(secStorage.getMountPoint() + name);
        newsnapshot.setPoolId(secStorage.getId());
        newsnapshot.setSize(snapshot.getSize());
        newsnapshot.setStatus(Status.DOWNLOADED);
        newsnapshot.setType(MockVolumeType.SNAPSHOT);
        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            snapshot = _mockVolumeDao.persist(snapshot);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when backing up snapshot " + newsnapshot, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
    }
View Full Code Here

TOP

Related Classes of com.cloud.simulator.MockVolumeVO

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.