Search in sources :

Example 21 with MockVolumeVO

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

the class MockStorageManagerImpl method CreateVolumeFromSnapshot.

@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
    MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
    if (backSnapshot == null) {
        return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
    }
    MockStoragePoolVO primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
    if (primary == null) {
        return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
    }
    String uuid = UUID.randomUUID().toString();
    MockVolumeVO volume = new MockVolumeVO();
    volume.setName(uuid);
    volume.setPath(primary.getMountPoint() + uuid);
    volume.setPoolId(primary.getId());
    volume.setSize(backSnapshot.getSize());
    volume.setStatus(Status.DOWNLOADED);
    volume.setType(MockVolumeType.VOLUME);
    _mockVolumeDao.persist(volume);
    return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
Also used : MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 22 with MockVolumeVO

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

the class MockStorageManagerImpl method DeleteTemplate.

@Override
public Answer DeleteTemplate(DeleteTemplateCommand cmd) {
    MockVolumeVO template = _mockVolumeDao.findByStoragePathAndType(cmd.getTemplatePath());
    if (template == null) {
        return new Answer(cmd, false, "can't find template:" + cmd.getTemplatePath());
    }
    _mockVolumeDao.remove(template.getId());
    return new Answer(cmd);
}
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) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 23 with MockVolumeVO

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

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();
    MockVMVO vm = _mockVMDao.findByVmName(vmName);
    if (vm == null) {
        return new Answer(cmd, false, "can't vm :" + vmName);
    }
    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) 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) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

Example 24 with MockVolumeVO

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

the class MockStorageManagerImpl method DownloadProcess.

@Override
public DownloadAnswer DownloadProcess(DownloadProgressCommand cmd) {
    String volumeId = cmd.getJobId();
    MockVolumeVO volume = _mockVolumeDao.findById(Long.parseLong(volumeId));
    if (volume == null) {
        return new DownloadAnswer("Can't find the downloading volume", Status.ABANDONED);
    }
    long size = Math.min(volume.getSize() + DEFAULT_TEMPLATE_SIZE / 5, DEFAULT_TEMPLATE_SIZE);
    volume.setSize(size);
    double volumeSize = volume.getSize();
    double pct = volumeSize / DEFAULT_TEMPLATE_SIZE;
    if (pct >= 1.0) {
        volume.setStatus(Status.DOWNLOADED);
        _mockVolumeDao.update(volume.getId(), volume);
        return new DownloadAnswer(cmd.getJobId(), 100, cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED, volume.getPath(), volume.getName());
    } else {
        _mockVolumeDao.update(volume.getId(), volume);
        return new DownloadAnswer(cmd.getJobId(), (int) (pct * 100.0), cmd, com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS, volume.getPath(), volume.getName());
    }
}
Also used : MockVolumeVO(com.cloud.simulator.MockVolumeVO) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer)

Example 25 with MockVolumeVO

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

the class MockStorageManagerImpl method AttachVolume.

@Override
public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) {
    String poolid = cmd.getPoolUuid();
    String volumeName = cmd.getVolumeName();
    MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath());
    if (volume == null) {
        return new AttachVolumeAnswer(cmd, "Can't find volume:" + volumeName + "on pool:" + poolid);
    }
    String vmName = cmd.getVmName();
    MockVMVO vm = _mockVMDao.findByVmName(vmName);
    if (vm == null) {
        return new AttachVolumeAnswer(cmd, "can't vm :" + vmName);
    }
    return new AttachVolumeAnswer(cmd, cmd.getDeviceId());
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) MockVolumeVO(com.cloud.simulator.MockVolumeVO)

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