Search in sources :

Example 6 with MockVolumeVO

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

the class MockStorageManagerImpl method findVolumeFromSecondary.

private MockVolumeVO findVolumeFromSecondary(String path, String ssUrl, MockVolumeType type) {
    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);
    if (volume == null) {
        return null;
    }
    return volume;
}
Also used : MockSecStorageVO(com.cloud.simulator.MockSecStorageVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 7 with MockVolumeVO

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

the class MockStorageManagerImpl method AttachIso.

@Override
public Answer AttachIso(AttachIsoCommand cmd) {
    MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO);
    if (iso == null) {
        return new Answer(cmd, false, "Failed to find the iso: " + cmd.getIsoPath() + "on secondary storage " + cmd.getStoreUrl());
    }
    String vmName = cmd.getVmName();
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockVMVO vm = null;
    try {
        txn.start();
        vm = _mockVMDao.findByVmName(vmName);
        txn.commit();
        if (vm == null) {
            return new Answer(cmd, false, "can't find vm :" + vmName);
        }
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when attaching iso to vm " + vmName, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new Answer(cmd);
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) 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) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 8 with MockVolumeVO

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

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

the class MockStorageManagerImpl method ManageSnapshot.

@Override
public ManageSnapshotAnswer ManageSnapshot(ManageSnapshotCommand cmd) {
    String volPath = cmd.getVolumePath();
    MockVolumeVO volume = null;
    MockStoragePoolVO storagePool = null;
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        volume = _mockVolumeDao.findByStoragePathAndType(volPath);
        if (volume == null) {
            return new ManageSnapshotAnswer(cmd, false, "Can't find the volume");
        }
        storagePool = _mockStoragePoolDao.findById(volume.getPoolId());
        if (storagePool == null) {
            return new ManageSnapshotAnswer(cmd, false, "Can't find the storage pooll");
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Unable to perform snapshot", ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    String mountPoint = storagePool.getMountPoint();
    MockVolumeVO snapshot = new MockVolumeVO();
    snapshot.setName(cmd.getSnapshotName());
    snapshot.setPath(mountPoint + cmd.getSnapshotName());
    snapshot.setSize(volume.getSize());
    snapshot.setPoolId(storagePool.getId());
    snapshot.setType(MockVolumeType.SNAPSHOT);
    snapshot.setStatus(Status.DOWNLOADED);
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        snapshot = _mockVolumeDao.persist(snapshot);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when saving snapshot " + snapshot, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new ManageSnapshotAnswer(cmd, snapshot.getId(), snapshot.getPath(), true, "");
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 10 with MockVolumeVO

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

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