Search in sources :

Example 6 with MockStoragePoolVO

use of com.cloud.simulator.MockStoragePoolVO in project cloudstack by apache.

the class MockStorageManagerImpl method ManageSnapshot.

@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();
        snapshot = _mockVolumeDao.persist(snapshot);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with MockStoragePoolVO

use of com.cloud.simulator.MockStoragePoolVO in project cloudstack by apache.

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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");
            }
            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 {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with MockStoragePoolVO

use of com.cloud.simulator.MockStoragePoolVO in project cloudstack by apache.

the class MockStorageManagerImpl method DeleteStoragePool.

@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);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 9 with MockStoragePoolVO

use of com.cloud.simulator.MockStoragePoolVO in project cloudstack by apache.

the class MockStorageManagerImpl method CopyVolume.

@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());
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with MockStoragePoolVO

use of com.cloud.simulator.MockStoragePoolVO in project cloudstack by apache.

the class MockStorageManagerImpl method CreateVolumeFromSnapshot.

@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 {
        txn.start();
        _mockVolumeDao.persist(volume);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Aggregations

MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)22 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 URISyntaxException (java.net.URISyntaxException)11 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 ConfigurationException (javax.naming.ConfigurationException)11 MockVolumeVO (com.cloud.simulator.MockVolumeVO)10 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)6 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)6 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)4 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)4 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)4 StoragePoolInfo (com.cloud.agent.api.StoragePoolInfo)4 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)4 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)4 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)4 MockHost (com.cloud.simulator.MockHost)4 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)4 Answer (com.cloud.agent.api.Answer)2 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)2