Search in sources :

Example 86 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class VmHandler method createNextRunSnapshot.

/**
 * @param objectWithEditableDeviceFields object with fields annotated with {@link EditableDeviceOnVmStatusField},
 *                                       usually a command parameters object
 */
public void createNextRunSnapshot(VM existingVm, VmStatic newVmStatic, Object objectWithEditableDeviceFields, CompensationContext compensationContext) {
    // first remove existing snapshot
    Snapshot runSnap = snapshotDao.get(existingVm.getId(), Snapshot.SnapshotType.NEXT_RUN);
    if (runSnap != null) {
        snapshotDao.remove(runSnap.getId());
    }
    final VM newVm = new VM();
    newVm.setStaticData(newVmStatic);
    // create new snapshot with new configuration
    snapshotsManager.addSnapshot(Guid.newGuid(), "Next Run configuration snapshot", Snapshot.SnapshotStatus.OK, Snapshot.SnapshotType.NEXT_RUN, newVm, true, null, null, null, Collections.emptyList(), vmDeviceUtils.getVmDevicesForNextRun(existingVm, objectWithEditableDeviceFields, existingVm.getDefaultDisplayType()), compensationContext);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 87 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class GetVmConfigurationBySnapshotQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Snapshot snapshot = snapshotDao.get(getParameters().getId(), getUserID(), getParameters().isFiltered());
    VM vm = null;
    if (snapshot == null) {
        log.warn("Snapshot '{}' does not exist", getParameters().getId());
    } else {
        vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
    }
    getQueryReturnValue().setReturnValue(vm);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 88 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class GetVmNextRunConfigurationQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Snapshot snapshot = snapshotDao.get(getParameters().getId(), Snapshot.SnapshotType.NEXT_RUN, getUserID(), getParameters().isFiltered());
    if (snapshot != null) {
        VM vm = snapshotVmConfigurationHelper.getVmFromConfiguration(snapshot.getVmConfiguration(), snapshot.getVmId(), snapshot.getId());
        // update information that is not saved in the config
        vmHandler.updateDisksFromDb(vm);
        vmHandler.updateVmGuestAgentVersion(vm);
        vmHandler.updateNetworkInterfacesFromDb(vm);
        vmHandler.updateVmStatistics(vm);
        getQueryReturnValue().setReturnValue(vm);
    } else {
        // in case no next_run return static configuration
        super.executeQueryCommand();
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 89 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class TryBackToAllSnapshotsOfVmCommandTest method setUp.

@Before
public void setUp() {
    vm = new VM();
    vm.setId(cmd.getParameters().getVmId());
    when(vmDao.get(cmd.getParameters().getVmId())).thenReturn(vm);
    Snapshot snapshot = new Snapshot();
    snapshot.setId(cmd.getParameters().getDstSnapshotId());
    snapshot.setVmId(cmd.getParameters().getVmId());
    when(snapshotDao.get(cmd.getParameters().getDstSnapshotId())).thenReturn(snapshot);
    doNothing().when(cmd).updateVmDisksFromDb();
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) VM(org.ovirt.engine.core.common.businessentities.VM) Before(org.junit.Before)

Example 90 with Snapshot

use of org.ovirt.engine.core.common.businessentities.Snapshot in project ovirt-engine by oVirt.

the class GetAllDiskSnapshotsByStorageDomainIdQueryTest method setUpDaoMocks.

private void setUpDaoMocks() {
    Guid snapshotId = Guid.newGuid();
    Snapshot snapshot = new Snapshot(snapshotId, SnapshotStatus.OK, Guid.newGuid(), null, SnapshotType.REGULAR, snapshotDescription, new Date(), "");
    DiskImage disk1 = new DiskImage();
    disk1.setVmSnapshotId(snapshotId);
    DiskImage disk2 = new DiskImage();
    disk2.setVmSnapshotId(snapshotId);
    DiskImage disk3 = new DiskImage();
    disk3.setActive(true);
    List<DiskImage> diskImages = Arrays.asList(disk1, disk2, disk3);
    List<Snapshot> snapshots = Collections.singletonList(snapshot);
    when(diskImageDao.getAllSnapshotsForStorageDomain(storageDoaminId)).thenReturn(diskImages);
    when(snapshotDaoMock.getAllByStorageDomain(storageDoaminId)).thenReturn(snapshots);
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) Guid(org.ovirt.engine.core.compat.Guid) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Aggregations

Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)96 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)33 VM (org.ovirt.engine.core.common.businessentities.VM)32 Guid (org.ovirt.engine.core.compat.Guid)30 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)15 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)12 List (java.util.List)11 SnapshotStatus (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus)9 Collections (java.util.Collections)8 Date (java.util.Date)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 SnapshotType (org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType)8 EngineException (org.ovirt.engine.core.common.errors.EngineException)8 ActionType (org.ovirt.engine.core.common.action.ActionType)7 DiskStorageType (org.ovirt.engine.core.common.businessentities.storage.DiskStorageType)6 EngineMessage (org.ovirt.engine.core.common.errors.EngineMessage)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5