Search in sources :

Example 11 with MockStoragePoolVO

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

the class MockStorageManagerImpl method CreateVolumeFromSnapshot.

@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
    MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
    if (backSnapshot == null) {
        return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
    }
    MockStoragePoolVO primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
    if (primary == null) {
        return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
    }
    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);
    _mockVolumeDao.persist(volume);
    return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
Also used : MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 12 with MockStoragePoolVO

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

the class MockStorageManagerImpl method getLocalStorage.

@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
    MockHost host = _mockHostDao.findByGuid(hostGuid);
    if (storageSize == null) {
        storageSize = DEFAULT_HOST_STORAGE_SIZE;
    }
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByHost(hostGuid);
    if (storagePool == null) {
        String uuid = UUID.randomUUID().toString();
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(uuid);
        storagePool.setMountPoint("/mnt/" + uuid + File.separator);
        storagePool.setCapacity(storageSize);
        storagePool.setHostGuid(hostGuid);
        storagePool.setStorageType(StoragePoolType.Filesystem);
        storagePool = _mockStoragePoolDao.persist(storagePool);
    }
    return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}
Also used : MockHost(com.cloud.simulator.MockHost) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO)

Example 13 with MockStoragePoolVO

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

the class MockStorageManagerImpl method ModifyStoragePool.

@Override
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
    if (storagePool == null) {
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(sf.getUuid());
        storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
        Long size = DEFAULT_HOST_STORAGE_SIZE;
        String path = sf.getPath();
        int index = path.lastIndexOf("/");
        if (index != -1) {
            path = path.substring(index + 1);
            if (path != null) {
                String[] values = path.split("=");
                if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
                    size = Long.parseLong(values[1]);
                }
            }
        }
        storagePool.setCapacity(size);
        storagePool.setStorageType(sf.getType());
        storagePool = _mockStoragePoolDao.persist(storagePool);
    }
    return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
}
Also used : TemplateInfo(com.cloud.storage.template.TemplateInfo) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 14 with MockStoragePoolVO

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

the class MockStorageManagerImpl method CreateStoragePool.

@Override
public Answer CreateStoragePool(CreateStoragePoolCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
    if (storagePool == null) {
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(sf.getUuid());
        storagePool.setMountPoint("/mnt/" + sf.getUuid() + File.separator);
        Long size = DEFAULT_HOST_STORAGE_SIZE;
        String path = sf.getPath();
        int index = path.lastIndexOf("/");
        if (index != -1) {
            path = path.substring(index + 1);
            if (path != null) {
                String[] values = path.split("=");
                if (values.length > 1 && values[0].equalsIgnoreCase("size")) {
                    size = Long.parseLong(values[1]);
                }
            }
        }
        storagePool.setCapacity(size);
        storagePool.setStorageType(sf.getType());
        storagePool = _mockStoragePoolDao.persist(storagePool);
    }
    return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), 0, new HashMap<String, TemplateInfo>());
}
Also used : TemplateInfo(com.cloud.storage.template.TemplateInfo) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO)

Example 15 with MockStoragePoolVO

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

the class MockStorageManagerImpl method primaryStorageDownload.

@Override
public PrimaryStorageDownloadAnswer primaryStorageDownload(PrimaryStorageDownloadCommand cmd) {
    MockVolumeVO template = findVolumeFromSecondary(cmd.getUrl(), cmd.getSecondaryStorageUrl(), MockVolumeType.TEMPLATE);
    if (template == null) {
        return new PrimaryStorageDownloadAnswer("Can't find primary storage");
    }
    MockStoragePoolVO primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
    if (primaryStorage == null) {
        return new PrimaryStorageDownloadAnswer("Can't find primary storage");
    }
    String volumeName = UUID.randomUUID().toString();
    MockVolumeVO newVolume = new MockVolumeVO();
    newVolume.setName(volumeName);
    newVolume.setPath(primaryStorage.getMountPoint() + volumeName);
    newVolume.setPoolId(primaryStorage.getId());
    newVolume.setSize(template.getSize());
    newVolume.setType(MockVolumeType.VOLUME);
    _mockVolumeDao.persist(newVolume);
    return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

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