Examples of MockStoragePoolVO


Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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();
            throw new CloudRuntimeException("Error when modifying storage pool " + cmd.getPool().getPath(), ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    @Override
    public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
        StorageFilerTO sf = cmd.getPool();
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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();
            throw new CloudRuntimeException("Error when creating storage pool " + cmd.getPool().getPath(), ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
        return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateProp>());
    }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

                }
                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");
                }
                Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
                if (totalUsed == null) {
                    totalUsed = 0L;
                }
                txn.commit();
                return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
            }
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
        } finally {
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

    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();
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;
    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.simulator.MockStoragePoolVO

  @Override
  public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd) {
    Transaction txn = Transaction.open(Transaction.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

Examples of com.cloud.simulator.MockStoragePoolVO

  @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();
      throw new CloudRuntimeException("Error when modifying storage pool " + cmd.getPool().getPath(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }
    return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
  }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

  @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();
      throw new CloudRuntimeException("Error when creating storage pool " + cmd.getPool().getPath(), ex);
    } finally {
      txn.close();
            txn = Transaction.open(Transaction.CLOUD_DB);
            txn.close();
    }
    return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
  }
View Full Code Here

Examples of com.cloud.simulator.MockStoragePoolVO

        }
        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");
        }
        Long totalUsed = _mockVolumeDao.findTotalStorageId(pool.getId());
        if (totalUsed == null) {
          totalUsed = 0L;
        }
        txn.commit();
        return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
      }
    } catch (Exception ex) {
      txn.rollback();
      throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
    } finally {
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;
    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();
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.