use of com.cloud.vm.snapshot.VMSnapshotVO in project cloudstack by apache.
the class DefaultVMSnapshotStrategy method finalizeDelete.
protected void finalizeDelete(VMSnapshotVO vmSnapshot, List<VolumeObjectTO> volumeTOs) {
// update volumes path
updateVolumePath(volumeTOs);
// update children's parent snapshots
List<VMSnapshotVO> children = vmSnapshotDao.listByParent(vmSnapshot.getId());
for (VMSnapshotVO child : children) {
child.setParent(vmSnapshot.getParent());
vmSnapshotDao.persist(child);
}
// update current snapshot
VMSnapshotVO current = vmSnapshotDao.findCurrentSnapshotByVmId(vmSnapshot.getVmId());
if (current != null && current.getId() == vmSnapshot.getId() && vmSnapshot.getParent() != null) {
VMSnapshotVO parent = vmSnapshotDao.findById(vmSnapshot.getParent());
parent.setCurrent(true);
vmSnapshotDao.persist(parent);
}
vmSnapshot.setCurrent(false);
vmSnapshotDao.persist(vmSnapshot);
}
use of com.cloud.vm.snapshot.VMSnapshotVO in project cloudstack by apache.
the class DefaultVMSnapshotStrategy method finalizeCreate.
protected void finalizeCreate(VMSnapshotVO vmSnapshot, List<VolumeObjectTO> volumeTOs) {
// update volumes path
updateVolumePath(volumeTOs);
vmSnapshot.setCurrent(true);
// change current snapshot
if (vmSnapshot.getParent() != null) {
VMSnapshotVO previousCurrent = vmSnapshotDao.findById(vmSnapshot.getParent());
previousCurrent.setCurrent(false);
vmSnapshotDao.persist(previousCurrent);
}
vmSnapshotDao.persist(vmSnapshot);
}
use of com.cloud.vm.snapshot.VMSnapshotVO in project cloudstack by apache.
the class UserVmManagerTest method testRestoreVMF4.
// Test restoreVM on providing new template Id, when VM is in running state
@Test
public void testRestoreVMF4() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
doReturn(VirtualMachine.State.Running).when(_vmMock).getState();
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_volsDao.findByInstanceAndType(314L, Volume.Type.ROOT)).thenReturn(_rootVols);
doReturn(false).when(_rootVols).isEmpty();
when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
doReturn(3L).when(_volumeMock).getTemplateId();
doReturn(ImageFormat.VHD).when(_templateMock).getFormat();
when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
when(_storageMgr.allocateDuplicateVolume(_volumeMock, 14L)).thenReturn(_volumeMock);
when(_templateMock.getGuestOSId()).thenReturn(5L);
doNothing().when(_vmMock).setGuestOSId(anyLong());
doNothing().when(_vmMock).setTemplateId(3L);
when(_vmDao.update(314L, _vmMock)).thenReturn(true);
when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
when(_volumeMock.getId()).thenReturn(3L);
doNothing().when(_volsDao).detachVolume(anyLong());
List<VMSnapshotVO> mockList = mock(List.class);
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(mockList);
when(mockList.size()).thenReturn(0);
when(_templateMock.getUuid()).thenReturn("b1a3626e-72e0-4697-8c7c-a110940cc55d");
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
StoragePoolVO storagePool = new StoragePoolVO();
storagePool.setManaged(false);
when(_storagePoolDao.findById(anyLong())).thenReturn(storagePool);
CallContext.register(user, account);
try {
_userVmMgr.restoreVMInternal(_account, _vmMock, 14L);
} finally {
CallContext.unregister();
}
}
use of com.cloud.vm.snapshot.VMSnapshotVO in project cloudstack by apache.
the class UserVmManagerTest method testRestoreVMF5.
// Test restoreVM on providing new ISO Id, when VM(deployed using ISO) is in running state
@Test
public void testRestoreVMF5() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
doReturn(VirtualMachine.State.Running).when(_vmMock).getState();
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_volsDao.findByInstanceAndType(314L, Volume.Type.ROOT)).thenReturn(_rootVols);
doReturn(false).when(_rootVols).isEmpty();
when(_rootVols.get(eq(0))).thenReturn(_volumeMock);
doReturn(null).when(_volumeMock).getTemplateId();
doReturn(3L).when(_vmMock).getIsoId();
doReturn(ImageFormat.ISO).when(_templateMock).getFormat();
when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _templateMock);
when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
doNothing().when(_vmMock).setIsoId(14L);
when(_templateMock.getGuestOSId()).thenReturn(5L);
doNothing().when(_vmMock).setGuestOSId(anyLong());
doNothing().when(_vmMock).setTemplateId(3L);
when(_vmDao.update(314L, _vmMock)).thenReturn(true);
when(_storageMgr.allocateDuplicateVolume(_volumeMock, null)).thenReturn(_volumeMock);
doNothing().when(_volsDao).attachVolume(anyLong(), anyLong(), anyLong());
when(_volumeMock.getId()).thenReturn(3L);
doNothing().when(_volsDao).detachVolume(anyLong());
List<VMSnapshotVO> mockList = mock(List.class);
when(_vmSnapshotDao.findByVm(anyLong())).thenReturn(mockList);
when(mockList.size()).thenReturn(0);
when(_templateMock.getUuid()).thenReturn("b1a3626e-72e0-4697-8c7c-a110940cc55d");
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
StoragePoolVO storagePool = new StoragePoolVO();
storagePool.setManaged(false);
when(_storagePoolDao.findById(anyLong())).thenReturn(storagePool);
CallContext.register(user, account);
try {
_userVmMgr.restoreVMInternal(_account, _vmMock, 14L);
} finally {
CallContext.unregister();
}
verify(_vmMock, times(1)).setIsoId(14L);
}
use of com.cloud.vm.snapshot.VMSnapshotVO in project cloudstack by apache.
the class StorageSystemSnapshotStrategy method takeHypervisorSnapshot.
private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) {
VirtualMachine virtualMachine = volumeInfo.getAttachedVM();
if (virtualMachine != null && VirtualMachine.State.Running.equals(virtualMachine.getState())) {
String vmSnapshotName = UUID.randomUUID().toString().replace("-", "");
VMSnapshotVO vmSnapshotVO = new VMSnapshotVO(virtualMachine.getAccountId(), virtualMachine.getDomainId(), virtualMachine.getId(), vmSnapshotName, vmSnapshotName, vmSnapshotName, virtualMachine.getServiceOfferingId(), VMSnapshot.Type.Disk, null);
VMSnapshot vmSnapshot = vmSnapshotDao.persist(vmSnapshotVO);
if (vmSnapshot == null) {
throw new CloudRuntimeException("Unable to allocate a VM snapshot object");
}
vmSnapshot = vmSnapshotService.createVMSnapshot(virtualMachine.getId(), vmSnapshot.getId(), true);
if (vmSnapshot == null) {
throw new CloudRuntimeException("Unable to create a hypervisor-side snapshot");
}
try {
Thread.sleep(60000);
} catch (Exception ex) {
s_logger.warn(ex.getMessage(), ex);
}
return vmSnapshot;
}
// We didn't need to take a hypervisor-side snapshot. Return 'null' to indicate this.
return null;
}
Aggregations