Examples of MockStoragePoolVO


Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public StoragePoolInfo getLocalStorage(String hostGuid) {
        Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
        MockHost host = null;
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            host = _mockHostDao.findByGuid(hostGuid);
            storagePool = _mockStoragePoolDao.findByHost(hostGuid);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
        } finally {
            txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
        }

        if (storagePool == null) {
            String uuid = UUID.randomUUID().toString();
            storagePool = new MockStoragePoolVO();
            storagePool.setUuid(uuid);
            storagePool.setMountPoint("/mnt/" + uuid + File.separator);
            storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
            storagePool.setHostGuid(hostGuid);
            storagePool.setStorageType(StoragePoolType.Filesystem);
            txn = Transaction.open(Transaction.SIMULATOR_DB);
            try {
                txn.start();
                storagePool = _mockStoragePoolDao.persist(storagePool);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
            } finally {
                txn.close();
                txn = Transaction.open(Transaction.CLOUD_DB);
                txn.close();
            }
        }
        return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(),
                storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

  @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());
      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, primaryStorage.getMountPoint(), vol.getPath());
    }
  }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
        String volPath = cmd.getVolumePath();
        MockVolumeVO volume = null;
        MockStoragePoolVO storagePool = null;
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        MockVolumeVO backSnapshot = null;
        MockStoragePoolVO primary = null;
        try {
            txn.start();
            backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
            if (backSnapshot == null) {
                return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
            }

            primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
            if (primary == null) {
                return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
            }
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }

        String uuid = UUID.randomUUID().toString();
        MockVolumeVO volume = new MockVolumeVO();

        volume.setName(uuid);
        volume.setPath(primary.getMountPoint() + uuid);
        volume.setPoolId(primary.getId());
        volume.setSize(backSnapshot.getSize());
        volume.setStatus(Status.DOWNLOADED);
        volume.setType(MockVolumeType.VOLUME);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public StoragePoolInfo getLocalStorage(String hostGuid) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        MockHost host = null;
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            host = _mockHostDao.findByGuid(hostGuid);
            storagePool = _mockStoragePoolDao.findByHost(hostGuid);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }

        if (storagePool == null) {
            String uuid = UUID.randomUUID().toString();
            storagePool = new MockStoragePoolVO();
            storagePool.setUuid(uuid);
            storagePool.setMountPoint("/mnt/" + uuid + File.separator);
            storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
            storagePool.setHostGuid(hostGuid);
            storagePool.setStorageType(StoragePoolType.Filesystem);
            txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
            try {
                txn.start();
                storagePool = _mockStoragePoolDao.persist(storagePool);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
            } finally {
                txn.close();
                txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
                txn.close();
            }
        }
        return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(),
            storagePool.getPoolType(), storagePool.getCapacity(), 0);
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

        }
        if (storageSize == null) {
            storageSize = DEFAULT_HOST_STORAGE_SIZE;
        }
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        MockStoragePoolVO storagePool = null;
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.findByHost(hostGuid);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        if (storagePool == null) {
            String uuid = UUID.randomUUID().toString();
            storagePool = new MockStoragePoolVO();
            storagePool.setUuid(uuid);
            storagePool.setMountPoint("/mnt/" + uuid + File.separator);
            storagePool.setCapacity(storageSize);
            storagePool.setHostGuid(hostGuid);
            storagePool.setStorageType(StoragePoolType.Filesystem);
            txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
            try {
                txn.start();
                storagePool = _mockStoragePoolDao.persist(storagePool);
                txn.commit();
            } catch (Exception ex) {
                txn.rollback();
                throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
            } finally {
                txn.close();
                txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
                txn.close();
            }
        }
        return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(),
            storagePool.getPoolType(), storagePool.getCapacity(), 0);
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }

        txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }

        MockVolumeVO volume = null;
        txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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());
            vol.setSize(volume.getSize());
            vol.setStatus(Status.DOWNLOADED);
            vol.setType(MockVolumeType.VOLUME);
            txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
                txn.close();
            }
            return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
        }
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

        if (template == null) {
            return new PrimaryStorageDownloadAnswer("Can't find primary storage");
        }

        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public CreateAnswer createVolume(CreateCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        DiskProfile dskch = cmd.getDiskCharacteristics();
        MockStoragePoolVO storagePool = null;
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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.simulator.MockStoragePoolVO

    @Override
    public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            MockStoragePoolVO storage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
            if (storage == null) {
                return new Answer(cmd, false, "can't find storage pool:" + cmd.getPool().getUuid());
            }
            _mockStoragePoolDao.remove(storage.getId());
            txn.commit();
            return new Answer(cmd);
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when deleting storage pool " + cmd.getPool().getPath(), ex);
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.