Search in sources :

Example 1 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO 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 MockSecStorageVO

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

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    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());
        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;
        }
        return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO)

Example 3 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO 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)

Example 4 with MockSecStorageVO

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

the class MockStorageManagerImpl method findVolumeFromSecondary.

private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
    String volumePath = path.replaceAll(ssUrl, "");
    MockSecStorageVO secStorage = _mockSecStorageDao.findByUrl(ssUrl);
    if (secStorage == null) {
        return null;
    }
    volumePath = secStorage.getMountPoint() + volumePath;
    volumePath = volumePath.replaceAll("//", "/");
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(volumePath);
    if (volume == null) {
        return null;
    }
    return volume;
}
Also used : MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 5 with MockSecStorageVO

use of com.cloud.simulator.MockSecStorageVO 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)

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