Search in sources :

Example 6 with MockSecStorageVO

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

the class MockStorageManagerImpl method preinstallTemplates.

@Override
public void preinstallTemplates(String url, long zoneId) {
    MockSecStorageVO storage = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        storage = _mockSecStorageDao.findByUrl(url);
        if (storage == null) {
            storage = new MockSecStorageVO();
            URI uri;
            try {
                uri = new URI(url);
            } catch (URISyntaxException e) {
                return;
            }
            String nfsHost = uri.getHost();
            String nfsPath = uri.getPath();
            String path = nfsHost + ":" + nfsPath;
            String dir = "/mnt/" + UUID.nameUUIDFromBytes(path.getBytes()).toString() + File.separator;
            storage.setUrl(url);
            storage.setCapacity(DEFAULT_HOST_STORAGE_SIZE);
            storage.setMountPoint(dir);
            storage = _mockSecStorageDao.persist(storage);
            // preinstall default templates into secondary storage
            long defaultTemplateSize = 2 * 1024 * 1024 * 1024L;
            MockVolumeVO template = new MockVolumeVO();
            template.setName("simulator-domR");
            template.setPath(storage.getMountPoint() + "template/tmpl/1/100/" + UUID.randomUUID().toString());
            template.setPoolId(storage.getId());
            template.setSize(defaultTemplateSize);
            template.setType(MockVolumeType.TEMPLATE);
            template.setStatus(Status.DOWNLOADED);
            template = _mockVolumeDao.persist(template);
            template = new MockVolumeVO();
            template.setName("simulator-Centos");
            template.setPath(storage.getMountPoint() + "template/tmpl/1/111/" + UUID.randomUUID().toString());
            template.setPoolId(storage.getId());
            template.setSize(defaultTemplateSize);
            template.setType(MockVolumeType.TEMPLATE);
            template.setStatus(Status.DOWNLOADED);
            template = _mockVolumeDao.persist(template);
            txn.commit();
        }
    } catch (Exception ex) {
        throw new CloudRuntimeException("Unable to find sec storage at " + url, ex);
    } finally {
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) URISyntaxException(java.net.URISyntaxException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with MockSecStorageVO

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

the class MockStorageManagerImpl method GetStorageStats.

@Override
public GetStorageStatsAnswer GetStorageStats(GetStorageStatsCommand cmd) {
    String uuid = cmd.getStorageId();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        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());
            txn.commit();
            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;
            }
            txn.commit();
            return new GetStorageStatsAnswer(cmd, pool.getCapacity(), totalUsed);
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("DBException during storage stats collection for pool " + uuid, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with MockSecStorageVO

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

the class MockStorageManagerImpl method findVolumeFromSecondary.

private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        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);
        txn.commit();
        if (volume == null) {
            return null;
        }
        return volume;
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to find volume " + path + " on secondary " + ssUrl, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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)

Example 9 with MockSecStorageVO

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

the class MockStorageManagerImpl method ListTemplates.

@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
    DataStoreTO store = cmd.getDataStore();
    if (!(store instanceof NfsTO)) {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
    MockSecStorageVO storage = null;
    String nfsUrl = ((NfsTO) store).getUrl();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    storage = _mockSecStorageDao.findByUrl(nfsUrl);
    try {
        txn.start();
        List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
        Map<String, TemplateProp> templateInfos = new HashMap<String, TemplateProp>();
        for (MockVolumeVO template : templates) {
            templateInfos.put(template.getName(), new TemplateProp(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
        }
        return new ListTemplateAnswer(nfsUrl, templateInfos);
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding template on sec storage " + storage.getId(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) HashMap(java.util.HashMap) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) NfsTO(com.cloud.agent.api.to.NfsTO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) 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) 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) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) UploadStatusAnswer(org.apache.cloudstack.storage.command.UploadStatusAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 10 with MockSecStorageVO

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

the class MockStorageManagerImpl method CreatePrivateTemplateFromVolume.

@Override
public CreatePrivateTemplateAnswer CreatePrivateTemplateFromVolume(CreatePrivateTemplateFromVolumeCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockVolumeVO volume = null;
    MockSecStorageVO sec = null;
    try {
        txn.start();
        volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
        if (volume == null) {
            return new CreatePrivateTemplateAnswer(cmd, false, "cant' find volume" + cmd.getVolumePath());
        }
        sec = _mockSecStorageDao.findByUrl(cmd.getSecondaryStorageUrl());
        if (sec == null) {
            return new CreatePrivateTemplateAnswer(cmd, false, "can't find secondary storage");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when creating private template from volume");
    } 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(volume.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("Encountered " + ex.getMessage() + " when persisting template " + template.getName(), 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)

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