Search in sources :

Example 11 with MockSecStorageVO

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

the class MockStorageManagerImpl method ListVolumes.

@Override
public Answer ListVolumes(ListVolumeCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockSecStorageVO storage = null;
    try {
        txn.start();
        storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
        if (storage == null) {
            return new Answer(cmd, false, "Failed to get secondary storage");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when finding sec storage " + cmd.getSecUrl(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        List<MockVolumeVO> volumes = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.VOLUME);
        Map<Long, TemplateProp> templateInfos = new HashMap<Long, TemplateProp>();
        for (MockVolumeVO volume : volumes) {
            templateInfos.put(volume.getId(), new TemplateProp(volume.getName(), volume.getPath().replaceAll(storage.getMountPoint(), ""), volume.getSize(), volume.getSize(), true, false));
        }
        txn.commit();
        return new ListVolumeAnswer(cmd.getSecUrl(), 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) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) 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) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 12 with MockSecStorageVO

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

the class MockStorageManagerImpl method handleConfigDriveIso.

@Override
public Answer handleConfigDriveIso(HandleConfigDriveIsoCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockSecStorageVO sec;
    try {
        txn.start();
        sec = _mockSecStorageDao.findByUrl(cmd.getDestStore().getUrl());
        if (sec == null) {
            return new Answer(cmd, false, "can't find secondary storage");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when creating config drive.");
    } 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() + cmd.getIsoFile());
    template.setPoolId(sec.getId());
    template.setSize((long) (Math.random() * 200L) + 200L);
    template.setStatus(Status.DOWNLOADED);
    template.setType(MockVolumeType.ISO);
    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 config drive " + template.getName(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new Answer(cmd);
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) 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) 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 13 with MockSecStorageVO

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

the class MockStorageManagerImpl method SecStorageSetup.

@Override
public Answer SecStorageSetup(SecStorageSetupCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockSecStorageVO storage = null;
    try {
        txn.start();
        storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
        if (storage == null) {
            return new Answer(cmd, false, "can't find the storage");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when setting up sec storage" + cmd.getSecUrl(), ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new SecStorageSetupAnswer(storage.getMountPoint());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) 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) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 14 with MockSecStorageVO

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

the class MockStorageManagerImpl method ListTemplates.

@Override
public Answer ListTemplates(ListTemplateCommand cmd) {
    MockSecStorageVO storage = _mockSecStorageDao.findByUrl(cmd.getSecUrl());
    if (storage == null) {
        return new Answer(cmd, false, "Failed to get secondary storage");
    }
    List<MockVolumeVO> templates = _mockVolumeDao.findByStorageIdAndType(storage.getId(), MockVolumeType.TEMPLATE);
    Map<String, TemplateInfo> templateInfos = new HashMap<String, TemplateInfo>();
    for (MockVolumeVO template : templates) {
        templateInfos.put(template.getName(), new TemplateInfo(template.getName(), template.getPath().replaceAll(storage.getMountPoint(), ""), template.getSize(), template.getSize(), true, false));
    }
    return new ListTemplateAnswer(cmd.getSecUrl(), templateInfos);
}
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) TemplateInfo(com.cloud.storage.template.TemplateInfo) HashMap(java.util.HashMap) ListTemplateAnswer(com.cloud.agent.api.storage.ListTemplateAnswer) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 15 with MockSecStorageVO

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

the class MockStorageManagerImpl method preinstallTemplates.

@Override
public void preinstallTemplates(String url, long zoneId) {
    MockSecStorageVO 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/9/" + UUID.randomUUID().toString());
        template.setPoolId(storage.getId());
        template.setSize(defaultTemplateSize);
        template.setType(MockVolumeType.TEMPLATE);
        template.setStatus(Status.DOWNLOADED);
        _mockVolumeDao.persist(template);
        template = new MockVolumeVO();
        template.setName("simulator-Centos");
        template.setPath(storage.getMountPoint() + "template/tmpl/1/10/" + UUID.randomUUID().toString());
        template.setPoolId(storage.getId());
        template.setSize(defaultTemplateSize);
        template.setType(MockVolumeType.TEMPLATE);
        template.setStatus(Status.DOWNLOADED);
        _mockVolumeDao.persist(template);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URI(java.net.URI)

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