Search in sources :

Example 16 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method CreatePrivateTemplateFromVolume.

@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
    if (volume == null) {
        return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
    }
    MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
    if (sec == null) {
        return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
    }
    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);
    template = _mockVolumeDao.persist(template);
    return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
Also used : CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO)

Example 17 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.

the class MockStorageManagerImpl method Download.

@Override
public DownloadAnswer Download(DownloadCommand cmd) {
    MockSecStorageVO ssvo = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
    if (ssvo == null) {
        return new DownloadAnswer("can't find secondary storage", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
    }
    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);
    volume = _mockVolumeDao.persist(volume);
    return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
}
Also used : MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 18 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO in project CloudStack-archive by CloudStack-extras.

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 = _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();
    MockVolumeVO snapshot = _mockVolumeDao.findByStoragePathAndType(snapshotPath);
    if (snapshot == null) {
        return new BackupSnapshotAnswer(cmd, false, "can't find snapshot" + snapshotPath, null, true);
    }
    String secStorageUrl = cmd.getSecondaryStorageUrl();
    MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(secStorageUrl);
    if (secStorage == null) {
        return new BackupSnapshotAnswer(cmd, false, "can't find sec storage" + snapshotPath, null, true);
    }
    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);
    newsnapshot = _mockVolumeDao.persist(newsnapshot);
    return new BackupSnapshotAnswer(cmd, true, null, newsnapshot.getName(), true);
}
Also used : BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO)

Example 19 with MockSecStorageVO

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

the class MockStorageManagerImpl method CreatePrivateTemplateFromSnapshot.

@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockVolumeVO snapshot = null;
    MockSecStorageVO sec = null;
    try {
        txn.start();
        String snapshotUUId = cmd.getSnapshotUuid();
        snapshot = _mockVolumeDao.findByName(snapshotUUId);
        if (snapshot == null) {
            snapshotUUId = cmd.getSnapshotName();
            snapshot = _mockVolumeDao.findByName(snapshotUUId);
            if (snapshot == null) {
                return new CreatePrivateTemplateAnswer(cmd, false, "can't find snapshot:" + snapshotUUId);
            }
        }
        sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
        if (sec == null) {
            return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
        }
        txn.commit();
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.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(snapshot.getSize());
    template.setStatus(Status.DOWNLOADED);
    template.setType(MockVolumeType.TEMPLATE);
    txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new CreatePrivateTemplateAnswer(cmd, true, "", template.getName(), template.getSize(), template.getSize(), template.getName(), ImageFormat.QCOW2);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) 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)

Example 20 with MockSecStorageVO

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

the class MockStorageManagerImpl method Download.

@Override
public DownloadAnswer Download(DownloadCommand cmd) {
    MockSecStorageVO ssvo = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.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 = TransactionLegacy.open(TransactionLegacy.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 = 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();
    }
    return new DownloadAnswer(String.valueOf(volume.getId()), 0, "Downloading", Status.DOWNLOAD_IN_PROGRESS, cmd.getName(), cmd.getName(), volume.getSize(), volume.getSize(), null);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) 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