Search in sources :

Example 21 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF1.

// vm on Xenserver, expected exception
@Test(expected = InvalidParameterValueException.class)
public void testBackupSnapshotFromVmSnapshotF1() {
    when(_vmDao.findById(anyLong())).thenReturn(vmMock);
    when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
    Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
    Assert.assertNull(snapshot);
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) Test(org.junit.Test)

Example 22 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF2.

// vm on KVM, first time
@Test
public void testBackupSnapshotFromVmSnapshotF2() {
    when(_vmDao.findById(anyLong())).thenReturn(vmMock);
    when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
    when(_vmSnapshotDao.findById(anyLong())).thenReturn(vmSnapshotMock);
    when(_snapshotStoreDao.findParent(any(DataStoreRole.class), anyLong(), anyLong())).thenReturn(null);
    when(snapshotFactory.getSnapshot(anyLong(), Mockito.any(DataStore.class))).thenReturn(snapshotInfoMock);
    when(storeMock.create(snapshotInfoMock)).thenReturn(snapshotInfoMock);
    when(_snapshotStoreDao.findBySnapshot(anyLong(), any(DataStoreRole.class))).thenReturn(snapshotStoreMock);
    when(_snapshotStoreDao.update(anyLong(), any(SnapshotDataStoreVO.class))).thenReturn(true);
    when(_snapshotDao.update(anyLong(), any(SnapshotVO.class))).thenReturn(true);
    when(vmMock.getAccountId()).thenReturn(2L);
    when(snapshotStrategy.backupSnapshot(any(SnapshotInfo.class))).thenReturn(snapshotInfoMock);
    Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
    Assert.assertNotNull(snapshot);
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) Test(org.junit.Test)

Example 23 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class SnapshotManagerTest method testBackupSnapshotFromVmSnapshotF3.

// vm on KVM, already backed up
@Test(expected = InvalidParameterValueException.class)
public void testBackupSnapshotFromVmSnapshotF3() {
    when(_vmDao.findById(anyLong())).thenReturn(vmMock);
    when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
    when(_vmSnapshotDao.findById(anyLong())).thenReturn(vmSnapshotMock);
    when(_snapshotStoreDao.findParent(any(DataStoreRole.class), anyLong(), anyLong())).thenReturn(snapshotStoreMock);
    when(snapshotStoreMock.getInstallPath()).thenReturn("VM_SNAPSHOT_NAME");
    when(vmSnapshotMock.getName()).thenReturn("VM_SNAPSHOT_NAME");
    Snapshot snapshot = _snapshotMgr.backupSnapshotFromVmSnapshot(TEST_SNAPSHOT_ID, TEST_VM_ID, TEST_VOLUME_ID, TEST_VM_SNAPSHOT_ID);
    Assert.assertNull(snapshot);
}
Also used : DataStoreRole(com.cloud.storage.DataStoreRole) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) Test(org.junit.Test)

Example 24 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class CreateSnapshotCmd method execute.

@Override
public void execute() {
    s_logger.info("VOLSS: createSnapshotCmd starts:" + System.currentTimeMillis());
    CallContext.current().setEventDetails("Volume Id: " + getVolumeUuid());
    final Snapshot snapshot;
    try {
        snapshot = _volumeService.takeSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm());
        if (snapshot != null) {
            final SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
        }
    } catch (final Exception e) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(com.cloud.api.ServerApiException) SnapshotResponse(com.cloud.api.response.SnapshotResponse) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException)

Example 25 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class CreateSnapshotCmd method create.

@Override
public void create() throws ResourceAllocationException {
    final Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName());
    if (snapshot != null) {
        setEntityId(snapshot.getId());
        setEntityUuid(snapshot.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot");
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(com.cloud.api.ServerApiException)

Aggregations

Snapshot (com.cloud.storage.Snapshot)43 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)19 Test (org.junit.Test)11 ServerApiException (org.apache.cloudstack.api.ServerApiException)10 ServerApiException (com.cloud.api.ServerApiException)8 Volume (com.cloud.storage.Volume)8 VolumeVO (com.cloud.storage.VolumeVO)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 SnapshotResponse (com.cloud.api.response.SnapshotResponse)6 Account (com.cloud.user.Account)6 SnapshotResponse (org.apache.cloudstack.api.response.SnapshotResponse)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 DataStoreRole (com.cloud.storage.DataStoreRole)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)3