Search in sources :

Example 1 with MockVolumeVO

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

the class MockStorageManagerImpl method CopyVolume.

@Override
public CopyVolumeAnswer CopyVolume(CopyVolumeCommand cmd) {
    boolean toSecondaryStorage = cmd.toSecondaryStorage();
    MockSecStorageVO sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageURL());
    if (sec == null) {
        return new CopyVolumeAnswer(cmd, false, "can't find secondary storage", null, null);
    }
    MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPool().getUuid());
    if (primaryStorage == null) {
        return new CopyVolumeAnswer(cmd, false, "Can't find primary storage", null, null);
    }
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
    if (volume == null) {
        return new CopyVolumeAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath(), null, null);
    }
    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);
        vol = _mockVolumeDao.persist(vol);
        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);
        vol = _mockVolumeDao.persist(vol);
        return new CopyVolumeAnswer(cmd, true, null, primaryStorage.getMountPoint(), vol.getPath());
    }
}
Also used : CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 2 with MockVolumeVO

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

the class MockStorageManagerImpl method ManageSnapshot.

@Override
public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
    String volPath = cmd.getVolumePath();
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volPath);
    if (volume == null) {
        return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
    }
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
    if (storagePool == null) {
        return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
    }
    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);
    snapshot = _mockVolumeDao.persist(snapshot);
    return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
}
Also used : MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 3 with MockVolumeVO

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

the class MockStorageManagerImpl method Destroy.

@Override
public Answer Destroy(DestroyCommand cmd) {
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolume().getPath());
    if (volume != null) {
        _mockVolumeDao.remove(volume.getId());
    }
    if (cmd.getVmName() != null) {
        MockVm vm = _mockVMDao.findByVmName(cmd.getVmName());
        vm.setState(State.Expunging);
        if (vm != null) {
            MockVMVO vmVo = _mockVMDao.createForUpdate(vm.getId());
            _mockVMDao.update(vm.getId(), vmVo);
        }
    }
    return new Answer(cmd);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) 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) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) 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) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MockVm(com.cloud.simulator.MockVm)

Example 4 with MockVolumeVO

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

the class MockStorageManagerImpl method ComputeChecksum.

@Override
public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
    MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
    if (volume == null) {
        return new Answer(cmd, false, "cant' find volume:" + cmd.getTemplatePath());
    }
    String md5 = null;
    try {
        MessageDigest md = MessageDigest.getInstance("md5");
        md5 = String.format("%032x", new BigInteger(1, md.digest(cmd.getTemplatePath().getBytes())));
    } catch (NoSuchAlgorithmException e) {
        s_logger.debug("failed to gernerate md5:" + e.toString());
    }
    return new Answer(cmd, true, md5);
}
Also used : 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) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) 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) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MessageDigest(java.security.MessageDigest)

Example 5 with MockVolumeVO

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

the class MockStorageManagerImpl method CreatePrivateTemplateFromSnapshot.

@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromSnapshot(CreatePrivateTemplateFromSnapshotCommand cmd) {
    String snapshotUUId = cmd.getSnapshotUuid();
    MockVolumeVO 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);
        }
    }
    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(snapshot.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)

Aggregations

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