Search in sources :

Example 11 with MockVolumeVO

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

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

the class MockStorageManagerImpl method ComputeChecksum.

@Override
public Answer ComputeChecksum(ComputeChecksumCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        MockVolumeVO volume = _mockVolumeDao.findByName(cmd.getTemplatePath());
        if (volume == null) {
            return new Answer(cmd, false, "cant' find volume:" + cmd.getTemplatePath());
        }
        String md5 = null;
        try {
            MessageDigest md = MessageDigest.getInstance("md5");
            md5 = String.format("%032x", new BigInteger(1, md.digest(cmd.getTemplatePath().getBytes())));
        } catch (NoSuchAlgorithmException e) {
            s_logger.debug("failed to gernerate md5:" + e.toString());
        }
        txn.commit();
        return new Answer(cmd, true, md5);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
}
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) 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) BigInteger(java.math.BigInteger) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MockVolumeVO(com.cloud.simulator.MockVolumeVO) MessageDigest(java.security.MessageDigest)

Example 13 with MockVolumeVO

use of com.cloud.simulator.MockVolumeVO 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 14 with MockVolumeVO

use of com.cloud.simulator.MockVolumeVO 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) 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 15 with MockVolumeVO

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

the class MockStorageManagerImpl method Delete.

@Override
public Answer Delete(DeleteCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getData().getPath());
        if (template == null) {
            return new Answer(cmd, false, "can't find object to delete:" + cmd.getData().getPath());
        }
        _mockVolumeDao.remove(template.getId());
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when deleting object");
    } 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) 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) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

MockVolumeVO (com.cloud.simulator.MockVolumeVO)37 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)19 PrimaryStorageDownloadAnswer (com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)18 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)18 URISyntaxException (java.net.URISyntaxException)18 MockSecStorageVO (com.cloud.simulator.MockSecStorageVO)17 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 ConfigurationException (javax.naming.ConfigurationException)17 CreatePrivateTemplateAnswer (com.cloud.agent.api.storage.CreatePrivateTemplateAnswer)16 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)16 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)14 CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)14 ManageSnapshotAnswer (com.cloud.agent.api.ManageSnapshotAnswer)14 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)14 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)14 Answer (com.cloud.agent.api.Answer)12 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)12 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)12 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)12 ListTemplateAnswer (com.cloud.agent.api.storage.ListTemplateAnswer)12