private void sortSnapshots(List<Snapshot> snapshots) { Collections.sort(snapshots, Comparator.comparing((Snapshot s) -> s.getType() == Snapshot.SnapshotType.ACTIVE).reversed() .thenComparing(Linq.SnapshotByCreationDateCommparer)); }
@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); } }
private String getCreateDateString(Snapshot snapshot) { if (snapshot.getType() == SnapshotType.ACTIVE) { return constants.currentSnapshotLabel(); } return fullDateTimeRenderer.render(snapshot.getCreationDate()); }
private String getDescription(Snapshot snapshot) { String description = SafeHtmlUtils.fromString(snapshot.getDescription()).asString(); if (snapshot.getStatus() == SnapshotStatus.IN_PREVIEW) { List<String> previewedItems = new ArrayList<>(Arrays.asList(constants.vmConfiguration())); previewedItems.addAll(Linq.getDiskAliases(snapshot.getDiskImages())); description = messages.snapshotPreviewing( description, String.join(", ", previewedItems)); //$NON-NLS-1$ } else if (snapshot.getType() == SnapshotType.STATELESS) { description = description + " (" + constants.readonlyLabel() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } else if (snapshot.getType() == SnapshotType.PREVIEW) { description = constants.snapshotDescriptionActiveVmBeforePreview(); } else if (snapshot.getType() == SnapshotType.ACTIVE) { description = constants.snapshotDescriptionActiveVm(); } else if (snapshot.getType() == SnapshotType.REGULAR && !snapshot.getDiskImages().isEmpty()) { description = messages.snapshotPreviewing( description, String.join(", ", Linq.getDiskAliases(snapshot.getDiskImages()))); //$NON-NLS-1$ } else if (snapshot.isVmConfigurationBroken()) { description = description + " (" + constants.brokenVmConfiguration() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } return description; }
private boolean showWarningForByVmSnapshotsValidation(List<Snapshot> snapshots) { for (Snapshot snapshot : snapshots) { if (!validateNewSnapshotByStatus(snapshot.getStatus()) || !validateNewSnapshotByType(snapshot.getType())) { getDescription().setIsAvailable(false); getMemory().setIsAvailable(false); return true; } } return false; }
public VmSnapshotListModel() { setTitle(ConstantsManager.getInstance().getConstants().snapshotsTitle()); setHelpTag(HelpTag.snapshots); setHashName("snapshots"); //$NON-NLS-1$ setNewCommand(new UICommand("New", this)); //$NON-NLS-1$ setPreviewCommand(new UICommand("Preview", this)); //$NON-NLS-1$ setCustomPreviewCommand(new UICommand("CustomPreview", this)); //$NON-NLS-1$ setCommitCommand(new UICommand("Commit", this)); //$NON-NLS-1$ setUndoCommand(new UICommand("Undo", this)); //$NON-NLS-1$ setRemoveCommand(new UICommand("Remove", this)); //$NON-NLS-1$ setCloneVmCommand(new UICommand("CloneVM", this)); //$NON-NLS-1$ setCloneTemplateCommand(new UICommand("CloneTemplate", this)); //$NON-NLS-1$ setCanSelectSnapshot(new EntityModel<>()); getCanSelectSnapshot().setEntity(true); setSnapshotsMap(new HashMap<>()); setVmDisks(new ArrayList<>()); setComparator(Comparator.comparing( (Snapshot s) -> s.getType() == SnapshotType.ACTIVE || s.getType() == SnapshotType.PREVIEW) .thenComparing(Snapshot::getCreationDate) .reversed()); }
public void updateActionAvailability() { if (getItems() == null) { // no need to update action availability return; } VM vm = getEntity(); Snapshot snapshot = getSelectedItem(); List<VM> vmList = vm != null ? Collections.singletonList(vm) : Collections.emptyList(); boolean isVmDown = vm != null && vm.getStatus() == VMStatus.Down; boolean isVmImageLocked = vm != null && vm.getStatus() == VMStatus.ImageLocked; boolean isVmQualifiedForSnapshotMerge = vm != null && vm.getStatus().isQualifiedForSnapshotMerge(); boolean isPreviewing = getItems().stream().anyMatch(s -> s.getStatus() == SnapshotStatus.IN_PREVIEW); boolean isLocked = getItems().stream().anyMatch(s -> s.getStatus() == SnapshotStatus.LOCKED); boolean isSelected = snapshot != null && snapshot.getType() == SnapshotType.REGULAR; boolean isStateless = getItems().stream().anyMatch(s -> s.getType() == SnapshotType.STATELESS); boolean isVmConfigurationBroken = snapshot != null && snapshot.isVmConfigurationBroken(); getCanSelectSnapshot().setEntity(!isPreviewing && !isLocked && !isStateless && ActionUtils.canExecute(vmList, VM.class, ActionType.CreateSnapshotForVm)); getNewCommand().setIsExecutionAllowed(!isPreviewing && !isLocked && !isVmImageLocked && !isStateless); getPreviewCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && isVmDown && !isStateless); getCustomPreviewCommand().setIsExecutionAllowed(getPreviewCommand().getIsExecutionAllowed()); getCommitCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless); getUndoCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless); getRemoveCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isStateless && isVmQualifiedForSnapshotMerge); getCloneVmCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isVmImageLocked && !isStateless && !isVmConfigurationBroken); getCloneTemplateCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isVmImageLocked && !isStateless && !isVmConfigurationBroken); }
snapshotModels.add(snapshotModel); if (snapshot.getType() == Snapshot.SnapshotType.ACTIVE) { activeSnapshotId = snapshot.getId();
@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; }
_writer.writeStartElement("Snapshot"); _writer.writeAttributeString(getOvfUri(), "id", snapshot.getId().toString()); _writer.writeElement("Type", snapshot.getType().name()); _writer.writeElement("Description", snapshot.getDescription()); _writer.writeElement("CreationDate", OvfParser.localDateToUtcDateString(snapshot.getCreationDate()));
@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()); }