@Override public Object getQueryableId() { return getId(); }
@Override public void setItems(Collection<Snapshot> value) { List<Snapshot> snapshots = value != null ? new ArrayList<>(value) : new ArrayList<>(); snapshots.forEach(snapshot -> { SnapshotModel snapshotModel = snapshotsMap.computeIfAbsent(snapshot.getId(), id -> new SnapshotModel()); snapshotModel.setEntity(snapshot); }); // Filter active snapshot when in preview mode boolean hasNoPreviewSnapshot = snapshots.stream().noneMatch(s -> s.getType() == SnapshotType.PREVIEW); snapshots = snapshots.stream().filter( snapshot -> snapshot.getType() != SnapshotType.ACTIVE || hasNoPreviewSnapshot ).sorted(comparator).collect(Collectors.toList()); if (snapshots.stream().anyMatch(s -> s.getStatus() == SnapshotStatus.IN_PREVIEW)) { updatePreviewedDiskSnapshots(snapshots); } else { updateItems(snapshots); } }
@Override protected boolean canEdit(SnapshotModel snapshotModel) { // prevent from selecting more then one leases in case many snapshots have leases if (snapshotModel.getLeaseExists() != null) { SnapshotModel result = previewSnapshotModel.getSnapshots() .getItems() .stream() .filter(model -> model.getEntity().getId() != snapshotModel.getEntity().getId()) .filter(model -> model.getLeaseExists().getEntity() != null) .filter(model -> model.getLeaseExists().getEntity()) .findFirst().orElse(null); return result == null; } return false; }
public Guid getSelectedLease() { SnapshotModel selectedLeaseSnapshotModel = getSnapshots().getItems() .stream() .filter(model -> model.getLeaseExists().getEntity() != null) .filter(model -> model.getLeaseExists().getEntity()) .findFirst() .orElse(null); return selectedLeaseSnapshotModel != null ? getSnapshotLeaseDomainsMap().get(selectedLeaseSnapshotModel.getEntity().getId()) : null; }
protected org.ovirt.engine.core.common.businessentities.Snapshot getSnapshotById(Guid id) { //TODO: move to 'GetSnapshotBySnapshotId' once Backend supplies it. for (org.ovirt.engine.core.common.businessentities.Snapshot snapshot : getBackendCollection(QueryType.GetAllVmSnapshotsByVmId, new IdQueryParameters(parentId))) { if (snapshot.getId().equals(id)) { return snapshot; } } return null; }
@Override protected org.ovirt.engine.core.common.businessentities.Snapshot getEntity(int index) { org.ovirt.engine.core.common.businessentities.Snapshot snapshot = mock(org.ovirt.engine.core.common.businessentities.Snapshot.class); when(snapshot.getId()).thenReturn(GUIDS[index]); when(snapshot.getDescription()).thenReturn(DESCRIPTIONS[index]); return snapshot; }
public SnapshotModel getSnapshotModelById(Guid id) { for (SnapshotModel snapshotModel : getSnapshots().getItems()) { if (snapshotModel.getEntity().getId().equals(id)) { return snapshotModel; } } return null; }
public void clearLeaseSelection(Guid selectedSnapshotModel) { for (SnapshotModel snapshotModel : getSnapshots().getItems()) { if (!selectedSnapshotModel.equals(snapshotModel.getEntity().getId()) && snapshotModel.getLeaseExists().getEntity() != null) { snapshotModel.getLeaseExists().setEntity(false); } } }
private void customPreview() { VM vm = getEntity(); if (vm == null) { return; } PreviewSnapshotModel model = new PreviewSnapshotModel(vm, getSelectedItem().getId()); model.setVmId(vm.getId()); model.initialize(); // Update according to the selected snapshot Snapshot selectedSnapshot = getSelectedItem(); if (selectedSnapshot != null) { model.setSnapshotModel(getSnapshotsMap().get(selectedSnapshot.getId())); } setWindow(model); model.setTitle(ConstantsManager.getInstance().getConstants().customPreviewSnapshotTitle()); model.setHelpTag(HelpTag.custom_preview_snapshot); model.setHashName("custom_preview_snapshot"); //$NON-NLS-1$ addCommands(model, "OnCustomPreview"); //$NON-NLS-1$ }
public void updateVmConfiguration(final AsyncCallback<Void> onUpdateAsyncCallback) { Snapshot snapshot = getEntity(); if (snapshot == null) { return; } AsyncDataProvider.getInstance().getVmConfigurationBySnapshot(new AsyncQuery<>(vm -> { Snapshot snapshot1 = getEntity(); if (vm != null && snapshot1 != null) { setVm(vm); setDisks(vm.getDiskList()); setNics(vm.getInterfaces()); setApps(Arrays.asList(snapshot1.getAppList() != null ? snapshot1.getAppList().split(",") : new String[]{})); //$NON-NLS-1$ Collections.sort(getDisks(), new DiskByDiskAliasComparator()); Collections.sort(getNics(), new LexoNumericNameableComparator<>()); } onUpdateAsyncCallback.onSuccess(null); }), snapshot.getId()); }
private void onRemove() { Snapshot snapshot = getSelectedItem(); if (snapshot == null) { cancel(); return; } VM vm = getEntity(); if (vm != null) { Frontend.getInstance().runAction(ActionType.RemoveSnapshot, new RemoveSnapshotParameters(snapshot.getId(), vm.getId()), null, null); } getCanSelectSnapshot().setEntity(false); cancel(); }
private void runTryBackToAllSnapshotsOfVm(final Model model, VM vm, Snapshot snapshot, boolean memory, List<DiskImage> disks, boolean isRestoreLease, Guid leaseDomainId) { if (model != null) { model.startProgress(); } TryBackToAllSnapshotsOfVmParameters params = new TryBackToAllSnapshotsOfVmParameters( vm.getId(), snapshot.getId(), memory, disks); if (leaseDomainId != null) { params.setDstLeaseDomainId(leaseDomainId); } params.setRestoreLease(isRestoreLease); Frontend.getInstance().runAction(ActionType.TryBackToAllSnapshotsOfVm, params, result -> { if (model != null) { model.stopProgress(); } if (result.getReturnValue().getSucceeded()) { cancel(); } }); }
@Test public void testRemoveWithoutPermissions() { for (Snapshot s : snapshotDao.getAll()) { snapshotDao.remove(s.getId()); } int numberOfPermissionsBeforeRemove = permissionsDao.getAllForEntity(getExistingEntityId()).size(); dao.remove(getExistingEntityId(), false); VmStatic result = dao.get(getExistingEntityId()); assertNull(result); assertEquals(numberOfPermissionsBeforeRemove, permissionsDao.getAllForEntity(getExistingEntityId()).size(), "vm permissions changed during remove although shouldnt have."); }
@Test @Override public void testRemove() { for (Snapshot s : snapshotDao.getAll()) { snapshotDao.remove(s.getId()); } dao.remove(getExistingEntityId()); VmStatic result = dao.get(getExistingEntityId()); assertNull(result); assertEquals(0, permissionsDao.getAllForEntity(getExistingEntityId()).size(), "vm permissions wasn't removed"); }
public void selectSnapshot(Guid id) { SnapshotModel snapshotModel = getSnapshotModelById(id); if (snapshotModel == null) { return; } for (SnapshotModel model : getSnapshots().getItems()) { if (model.getEntity().getId().equals(id) && model.getLeaseExists().getEntity() != null) { model.getLeaseExists().setEntity(true); } else if (model.getLeaseExists().getEntity() != null) { model.getLeaseExists().setEntity(false); } } getSnapshots().setSelectedItem(snapshotModel); setSnapshotModel(snapshotModel); for (DiskImage diskImage : snapshotModel.getDisks()) { ListModel diskListModel = diskSnapshotsMap.get(diskImage.getId()); diskListModel.setSelectedItem(diskImage); } } }
private void postNameUniqueCheck(VM vm) { UnitVmModel model = (UnitVmModel) getWindow(); VM newVm = buildVmOnNewTemplate(model, vm); AddVmTemplateFromSnapshotParameters parameters = new AddVmTemplateFromSnapshotParameters(newVm.getStaticData(), model.getName().getEntity(), model.getDescription().getEntity(), getSelectedItem().getId()); BuilderExecutor.build(model, parameters, new UnitToAddVmTemplateParametersBuilder()); model.startProgress(); Frontend.getInstance().runAction(ActionType.AddVmTemplateFromSnapshot, parameters, result -> { VmSnapshotListModel vmSnapshotListModel = (VmSnapshotListModel) result.getState(); vmSnapshotListModel.getWindow().stopProgress(); ActionReturnValue returnValueBase = result.getReturnValue(); if (returnValueBase != null && returnValueBase.getSucceeded()) { vmSnapshotListModel.cancel(); } }, this); }
@Override protected MapSqlParameterSource createFullParametersMapper(Snapshot entity) { return createIdParameterMapper(entity.getId()) .addValue("vm_id", entity.getVmId()) .addValue("snapshot_type", EnumUtils.nameOrNull(entity.getType())) .addValue("status", EnumUtils.nameOrNull(entity.getStatus())) .addValue("description", entity.getDescription()) .addValue("creation_date", entity.getCreationDate()) .addValue("app_list", entity.getAppList()) .addValue("vm_configuration", entity.getVmConfiguration()) .addValue("memory_dump_disk_id", entity.getMemoryDiskId()) .addValue("memory_metadata_disk_id", entity.getMetadataDiskId()) .addValue("vm_configuration_broken", entity.isVmConfigurationBroken()); }
@Mapping(from = org.ovirt.engine.core.common.businessentities.Snapshot.class, to = Snapshot.class) public static Snapshot map(org.ovirt.engine.core.common.businessentities.Snapshot entity, Snapshot template) { Snapshot model = template != null ? template : new Snapshot(); model.setId(entity.getId().toString()); if (entity.getDescription() != null) { model.setDescription(entity.getDescription()); } if (entity.getCreationDate() != null) { model.setDate(DateMapper.map(entity.getCreationDate(), null)); } if (entity.getStatus() != null) { model.setSnapshotStatus(map(entity.getStatus(), null)); } if (entity.getType() != null) { model.setSnapshotType(map(entity.getType(), null)); } model.setPersistMemorystate(entity.containsMemory()); return model; }