Search in sources :

Example 1 with CreateVolumeFromSnapshotAnswer

use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project cloudstack by apache.

the class VmwareResource method execute.

protected Answer execute(CreateVolumeFromSnapshotCommand cmd) {
    String details = null;
    boolean success = false;
    String newVolumeName = UUID.randomUUID().toString();
    try {
        VmwareContext context = getServiceContext();
        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
        return mgr.getStorageManager().execute(this, cmd);
    } catch (Throwable e) {
        details = createLogMessageException(e, cmd);
    }
    return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) VmwareManager(com.cloud.hypervisor.vmware.manager.VmwareManager) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 2 with CreateVolumeFromSnapshotAnswer

use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project cloudstack by apache.

the class MockStorageManagerImpl method CreateVolumeFromSnapshot.

@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
    TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    MockVolumeVO backSnapshot = null;
    MockStoragePoolVO primary = null;
    try {
        txn.start();
        backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
        if (backSnapshot == null) {
            return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
        }
        primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
        if (primary == null) {
            return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
        }
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    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);
    txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
    try {
        txn.start();
        _mockVolumeDao.persist(volume);
        txn.commit();
    } catch (Exception ex) {
        txn.rollback();
        throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
    } finally {
        txn.close();
        txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
        txn.close();
    }
    return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MockStoragePoolVO(com.cloud.simulator.MockStoragePoolVO) MockVolumeVO(com.cloud.simulator.MockVolumeVO) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 3 with CreateVolumeFromSnapshotAnswer

use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer 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 4 with CreateVolumeFromSnapshotAnswer

use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected CreateVolumeFromSnapshotAnswer execute(final CreateVolumeFromSnapshotCommand cmd) {
    try {
        String snapshotPath = cmd.getSnapshotUuid();
        int index = snapshotPath.lastIndexOf("/");
        snapshotPath = snapshotPath.substring(0, index);
        KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(cmd.getSecondaryStorageUrl() + snapshotPath);
        KVMPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(cmd.getSnapshotName());
        String primaryUuid = cmd.getPrimaryStoragePoolNameLabel();
        KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(primaryUuid);
        String volUuid = UUID.randomUUID().toString();
        KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool);
        return new CreateVolumeFromSnapshotAnswer(cmd, true, "", disk.getName());
    } catch (CloudRuntimeException e) {
        return new CreateVolumeFromSnapshotAnswer(cmd, false, e.toString(), null);
    }
}
Also used : KVMStoragePool(com.cloud.agent.storage.KVMStoragePool) KVMPhysicalDisk(com.cloud.agent.storage.KVMPhysicalDisk) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Example 5 with CreateVolumeFromSnapshotAnswer

use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project cosmic by MissionCriticalCloud.

the class LibvirtCreateVolumeFromSnapshotCommandWrapper method execute.

@Override
public Answer execute(final CreateVolumeFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
    try {
        String snapshotPath = command.getSnapshotUuid();
        final int index = snapshotPath.lastIndexOf("/");
        snapshotPath = snapshotPath.substring(0, index);
        final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
        final KvmPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(command.getSnapshotName());
        final String primaryUuid = command.getPrimaryStoragePoolNameLabel();
        final StorageFilerTO pool = command.getPool();
        final KvmStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getType(), primaryUuid);
        final String volUuid = UUID.randomUUID().toString();
        final KvmPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool, 0);
        if (disk == null) {
            throw new NullPointerException("Disk was not successfully copied to the new storage.");
        }
        return new CreateVolumeFromSnapshotAnswer(command, true, "", disk.getName());
    } catch (final CloudRuntimeException e) {
        return new CreateVolumeFromSnapshotAnswer(command, false, e.toString(), null);
    } catch (final Exception e) {
        return new CreateVolumeFromSnapshotAnswer(command, false, e.toString(), null);
    }
}
Also used : KvmStoragePool(com.cloud.hypervisor.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KvmStoragePoolManager(com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)

Aggregations

CreateVolumeFromSnapshotAnswer (com.cloud.agent.api.CreateVolumeFromSnapshotAnswer)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)2 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)2 MockStoragePoolVO (com.cloud.simulator.MockStoragePoolVO)2 MockVolumeVO (com.cloud.simulator.MockVolumeVO)2 KVMPhysicalDisk (com.cloud.agent.storage.KVMPhysicalDisk)1 KVMStoragePool (com.cloud.agent.storage.KVMStoragePool)1 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)1 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)1 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)1 KvmPhysicalDisk (com.cloud.hypervisor.kvm.storage.KvmPhysicalDisk)1 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)1 VmwareManager (com.cloud.hypervisor.vmware.manager.VmwareManager)1 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)1 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 URISyntaxException (java.net.URISyntaxException)1