Search in sources :

Example 16 with MockStoragePoolVO

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

the class MockStorageManagerImpl method createVolume.

@Override
public CreateAnswer createVolume(CreateCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    DiskProfile dskch = cmd.getDiskCharacteristics();
    MockStoragePoolVO storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
    if (storagePool == null) {
        return new CreateAnswer(cmd, "Failed to find storage pool: " + sf.getUuid());
    }
    String volumeName = UUID.randomUUID().toString();
    MockVolumeVO volume = new MockVolumeVO();
    volume.setPoolId(storagePool.getId());
    volume.setName(volumeName);
    volume.setPath(storagePool.getMountPoint() + volumeName);
    volume.setSize(dskch.getSize());
    volume.setType(MockVolumeType.VOLUME);
    volume = _mockVolumeDao.persist(volume);
    VolumeTO volumeTo = new VolumeTO(cmd.getVolumeId(), dskch.getType(), sf.getType(), sf.getUuid(), volume.getName(), storagePool.getMountPoint(), volume.getPath(), volume.getSize(), null);
    return new CreateAnswer(cmd, volumeTo);
}
Also used : CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) VolumeTO(com.cloud.agent.api.to.VolumeTO) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) DiskProfile(com.cloud.vm.DiskProfile)

Example 17 with MockStoragePoolVO

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

the class MockStorageManagerImpl method ModifyStoragePool.

@Override
public ModifyStoragePoolAnswer ModifyStoragePool(ModifyStoragePoolCommand cmd) {
    StorageFilerTO sf = cmd.getPool();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockStoragePoolVO storagePool = null;
    try {
        txn.start();
        storagePool = _mockStoragePoolDao.findByUuid(sf.getUuid());
        if (storagePool == null) {
            storagePool = new MockStoragePoolVO();
            storagePool.setUuid(sf.getUuid());
            storagePool.setMountPoint("/mnt/" + sf.getUuid());
            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);
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when modifying storage pool " + cmd.getPool().getPath(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new ModifyStoragePoolAnswer(cmd, storagePool.getCapacity(), storagePool.getCapacity(), new HashMap<String, TemplateProp>());
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 18 with MockStoragePoolVO

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

the class MockStorageManagerImpl method getLocalStorage.

@Override
public StoragePoolInfo getLocalStorage(String hostGuid, Long storageSize) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockHost host = null;
    try {
        txn.start();
        host = _mockHostDao.findByGuid(hostGuid);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (storageSize == null) {
        storageSize = DEFAULT_HOST_STORAGE_SIZE;
    }
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockStoragePoolVO storagePool = null;
    try {
        txn.start();
        storagePool = _mockStoragePoolDao.findByHost(hostGuid);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding storagePool " + storagePool, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (storagePool == null) {
        String uuid = UUID.randomUUID().toString();
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(uuid);
        storagePool.setMountPoint("/mnt/" + uuid);
        storagePool.setCapacity(storageSize);
        storagePool.setHostGuid(hostGuid);
        storagePool.setStorageType(StoragePoolType.Filesystem);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.persist(storagePool);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
    }
    return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), 0);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 19 with MockStoragePoolVO

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

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");
    }
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockStoragePoolVO primaryStorage = null;
    try {
        txn.start();
        primaryStorage = _mockStoragePoolDao.findByUuid(cmd.getPoolUuid());
        txn.commit();
        if (primaryStorage == null) {
            return new PrimaryStorageDownloadAnswer("Can't find primary storage");
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding primary storagee " + cmd.getPoolUuid(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    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);
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        _mockVolumeDao.persist(newVolume);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when saving volume " + newVolume, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new PrimaryStorageDownloadAnswer(newVolume.getPath(), newVolume.getSize());
}
Also used : PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with MockStoragePoolVO

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

the class MockStorageManagerImpl method getLocalStorage.

@Override
public StoragePoolInfo getLocalStorage(String hostGuid) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockHost host = null;
    MockStoragePoolVO storagePool = null;
    try {
        txn.start();
        host = _mockHostDao.findByGuid(hostGuid);
        storagePool = _mockStoragePoolDao.findByHost(hostGuid);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to find host " + hostGuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    if (storagePool == null) {
        String uuid = UUID.randomUUID().toString();
        storagePool = new MockStoragePoolVO();
        storagePool.setUuid(uuid);
        storagePool.setMountPoint("/mnt/" + uuid);
        storagePool.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
        storagePool.setHostGuid(hostGuid);
        storagePool.setStorageType(StoragePoolType.Filesystem);
        txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
        try {
            txn.start();
            storagePool = _mockStoragePoolDao.persist(storagePool);
            txn.commit();
        } catch (Exception ex) {
            txn.rollback();
            throw new CloudRuntimeException("Error when saving storagePool " + storagePool, ex);
        } finally {
            txn.close();
            txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
            txn.close();
        }
    }
    return new StoragePoolInfo(storagePool.getUuid(), host.getPrivateIpAddress(), storagePool.getMountPoint(), storagePool.getMountPoint(), storagePool.getPoolType(), storagePool.getCapacity(), storagePool.getCapacity());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) MockHost(com.cloud.simulator.MockHost) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

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