Search in sources :

Example 21 with MockSecStorageVO

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

the class MockStorageManagerImpl method BackupSnapshot.

@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;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)21 MockVolumeVO (com.cloud.simulator.MockVolumeVO)18 URISyntaxException (java.net.URISyntaxException)13 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 ConfigurationException (javax.naming.ConfigurationException)12 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)9 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)7 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)7 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)7 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)7 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)7 Answer (com.cloud.agent.api.Answer)5 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)5 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)5 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)5 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)5 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)5 ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)5