Package com.cloud.simulator

Examples of com.cloud.simulator.MockSecStorageVO


  @Override
  public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
    Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
    MockVolumeVO volume = null;
    MockSecStorageVO sec = null;
    try {
      txn.start();
      volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
      if (volume == null) {
        return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
      }

      sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
      if (sec == null) {
        return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
      }
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Error when creating private template from volume");
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    MockVolumeVO template = new MockVolumeVO();
    String uuid = UUID.randomUUID().toString();
    template.setName(uuid);
    template.setPath(sec.getMountPoint() + uuid);
    template.setPoolId(sec.getId());
    template.setSize(volume.getSize());
    template.setStatus(Status.DOWNLOADED);
    template.setType(MockVolumeType.TEMPLATE);
    txn = Transaction.open(Transaction.SIMULATOR_DB);
    try {
View Full Code Here


  @Override
  public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
    Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
    boolean toSecondaryStorage = cmd.toSecondaryStorage();
    MockSecStorageVO sec = null;
    MockStoragePoolVO primaryStorage = null;
    try {
      txn.start();
      sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
      if (sec == null) {
        return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
      }
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing secondary at "
          + cmd.getSecondaryStorageURL(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    txn = Transaction.open(Transaction.SIMULATOR_DB);
    try {
      txn.start();
      primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
      if (primaryStorage == null) {
        return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
      }
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing primary at "
          + cmd.getPool(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    MockVolumeVO volume = null;
    txn = Transaction.open(Transaction.SIMULATOR_DB);
    try {
      txn.start();
      volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
      if (volume == null) {
        return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
      }
      txn.commit();
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when accessing volume at "
          + cmd.getVolumePath(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }

    String name = UUID.randomUUID().toString();
    if (toSecondaryStorage) {
      MockVolumeVO vol = new MockVolumeVO();
      vol.setName(name);
      vol.setPath(sec.getMountPoint() + name);
      vol.setPoolId(sec.getId());
      vol.setSize(volume.getSize());
      vol.setStatus(Status.DOWNLOADED);
      vol.setType(MockVolumeType.VOLUME);
      txn = Transaction.open(Transaction.SIMULATOR_DB);
      try {
        txn.start();
        vol = _mockVolumeDao.persist(vol);
        txn.commit();
      } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Encountered " + ex.getMessage() + " when persisting volume "
            + vol.getName(), ex);
      } finally {
        txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
      }
      return new CopyVolumeAnswer(cmd, true, null, sec.getMountPoint(), vol.getPath());
    } else {
      MockVolumeVO vol = new MockVolumeVO();
      vol.setName(name);
      vol.setPath(primaryStorage.getMountPoint() + name);
      vol.setPoolId(primaryStorage.getId());
View Full Code Here

    private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            String volumePath = path.replaceAll(ssUrl, "");
            MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
            if (secStorage == null) {
                return null;
            }
            volumePath = secStorage.getMountPoint() + volumePath;
            volumePath = volumePath.replaceAll("//", "/");
            MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
            txn.commit();
            if (volume == null) {
                return null;
View Full Code Here

    }

    @Override
    public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockSecStorageVO storage = null;
        try {
            txn.start();
            storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
            if (storage == null) {
                return new Answer(cmd, false, "can't find the storage");
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
        return new SecStorageSetupAnswer(storage.getMountPoint());
    }
View Full Code Here

    }

    @Override
    public Answer ListVolumes(ListVolumeCommand cmd) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockSecStorageVO storage = null;
        try {
            txn.start();
            storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
            if (storage == null) {
                return new Answer(cmd, false, "Failed to get secondary storage");
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            List<MockVolumeVO> volumes = _mockVolumeDao.findByStorageIdAndType(storage.getId(),
                    MockVolumeType.VOLUME);

            Map<Long, TemplateInfo> templateInfos = new HashMap<Long, TemplateInfo>();
            for (MockVolumeVO volume : volumes) {
                templateInfos.put(volume.getId(), new TemplateInfo(volume.getName(), volume.getPath()
                        .replaceAll(storage.getMountPoint(), ""), volume.getSize(), volume.getSize(), true, false));
            }
            txn.commit();
            return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
View Full Code Here

    }

    @Override
    public Answer ListTemplates(ListTemplateCommand cmd) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockSecStorageVO storage = null;
        try {
            txn.start();
            storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
            if (storage == null) {
                return new Answer(cmd, false, "Failed to get secondary storage");
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(),
                    MockVolumeType.TEMPLATE);

            Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
            for (MockVolumeVO template : templates) {
                templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath()
                        .replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
            }
            txn.commit();
            return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
View Full Code Here

        return new Answer(cmd);
    }

    @Override
    public DownloadAnswer Download(DownloadCommand cmd) {
        MockSecStorageVO ssvo = null;
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
            if (ssvo == null) {
                return new DownloadAnswer("can't find secondary storage",
                        VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error accessing secondary storage " + cmd.getSecUrl(), ex);
        } finally {
            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 {
View Full Code Here

        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        try {
            txn.start();
            if (uuid == null) {
                String secUrl = cmd.getSecUrl();
                MockSecStorageVO secondary = _mockSecStorageDao.findByUrl(secUrl);
                if (secondary == null) {
                    return new GetStorageStatsAnswer(cmd, "Can't find the secondary storage:" + secUrl);
                }
                Long totalUsed = _mockVolumeDao.findTotalStorageId(secondary.getId());
                txn.commit();
                return new GetStorageStatsAnswer(cmd, secondary.getCapacity(), totalUsed);
            } else {
                MockStoragePoolVO pool = _mockStoragePoolDao.findByUuid(uuid);
                if (pool == null) {
                    return new GetStorageStatsAnswer(cmd, "Can't find the pool");
                }
View Full Code Here

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

    }

    @Override
    public void preinstallTemplates(String url, long zoneId) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockSecStorageVO storage = null;
        try {
            txn.start();
            storage = _mockSecStorageDao.findByUrl(url);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }
        if (storage == null) {
            storage = new MockSecStorageVO();
            URI uri;
            try {
                uri = new URI(url);
            } catch (URISyntaxException e) {
                return;
            }

            String nfsHost = uri.getHost();
            String nfsPath = uri.getPath();
            String path = nfsHost + ":" + nfsPath;
            String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;

            storage.setUrl(url);
            storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);

            storage.setMountPoint(dir);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
                txn.start();
                storage = _mockSecStorageDao.persist(storage);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Error when saving storage " + storage, ex);
            } finally {
                txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
            }

            // preinstall default templates into secondary storage
            long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
            MockVolumeVO template = new MockVolumeVO();
            template.setName("simulator-domR");
            template.setPath(storage.getMountPoint() + "template/tmpl/1/10/" + UUID.randomUUID().toString());
            template.setPoolId(storage.getId());
            template.setSize(defaultTemplateSize);
            template.setType(MockVolumeType.TEMPLATE);
            template.setStatus(Status.DOWNLOADED);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
                txn.start();
                template = _mockVolumeDao.persist(template);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Error when saving template " + template, ex);
            } finally {
                txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
            }

            template = new MockVolumeVO();
            template.setName("simulator-Centos");
            template.setPath(storage.getMountPoint() + "template/tmpl/1/11/" + UUID.randomUUID().toString());
            template.setPoolId(storage.getId());
            template.setSize(defaultTemplateSize);
            template.setType(MockVolumeType.TEMPLATE);
            template.setStatus(Status.DOWNLOADED);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
View Full Code Here

TOP

Related Classes of com.cloud.simulator.MockSecStorageVO

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.