@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()); }
Snapshot snapshot = new Snapshot(vmConfiguration != null); snapshot.setId(new Guid(node.attributes.get("ovf:id").getValue())); snapshot.setVmId(_vm.getId()); snapshot.setType(SnapshotType.valueOf(selectSingleNode(node, "Type", _xmlNS).innerText)); snapshot.setStatus(SnapshotStatus.OK); snapshot.setDescription(selectSingleNode(node, "Description", _xmlNS).innerText); XmlNode memory = selectSingleNode(node, "Memory", _xmlNS); if (memory != null) { List<Guid> guids = Guid.createGuidListFromString(memory.innerText); snapshot.setMemoryDiskId(guids.get(2)); snapshot.setMetadataDiskId(guids.get(4)); OvfParser.utcDateStringToLocalDate(selectSingleNode(node, "CreationDate", _xmlNS).innerText); if (creationDate != null) { snapshot.setCreationDate(creationDate); snapshot.setVmConfiguration(vmConfiguration == null ? null : new String(Base64.decodeBase64(vmConfiguration.innerText))); snapshot.setAppList(appList.innerText);
@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; }
@Override protected org.ovirt.engine.core.common.businessentities.Snapshot getEntity(int index) { org.ovirt.engine.core.common.businessentities.Snapshot entity = new org.ovirt.engine.core.common.businessentities.Snapshot(); entity.setId(SNAPSHOT_IDS[index]); entity.setCreationDate(SNAPSHOT_DATES[index]); entity.setDescription(DESCRIPTIONS[index]); entity.setType(SnapshotType.REGULAR); entity.setVmId(VM_ID); return entity; }
private org.ovirt.engine.core.common.businessentities.Snapshot createSnapshot(int index) { org.ovirt.engine.core.common.businessentities.Snapshot result = new org.ovirt.engine.core.common.businessentities.Snapshot(); result.setId(GUIDS[index]); result.setDescription("snap1"); return result; }
@Override public Snapshot mapRow(ResultSet rs, int rowNum) throws SQLException { Snapshot snapshot = createInitialSnapshotEntity(rs); snapshot.setId(getGuidDefaultEmpty(rs, "snapshot_id")); snapshot.setVmId(getGuidDefaultEmpty(rs, "vm_id")); snapshot.setType(SnapshotType.valueOf(rs.getString("snapshot_type"))); snapshot.setStatus(SnapshotStatus.valueOf(rs.getString("status"))); snapshot.setDescription(rs.getString("description")); snapshot.setCreationDate(new Date(rs.getTimestamp("creation_date").getTime())); snapshot.setAppList(rs.getString("app_list")); snapshot.setVmConfiguration(rs.getString("vm_configuration")); snapshot.setMemoryDiskId(getGuid(rs, "memory_dump_disk_id")); snapshot.setMetadataDiskId(getGuid(rs, "memory_metadata_disk_id")); snapshot.setVmConfigurationBroken(rs.getBoolean("vm_configuration_broken")); return 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())); if (snapshot.containsMemory()) { DiskImage memoryDump = memoryDisks.get(snapshot.getMemoryDiskId()); DiskImage memoryConf = memoryDisks.get(snapshot.getMetadataDiskId()); String memoryVolume = String.format("%1$s,%2$s,%3$s,%4$s,%5$s,%6$s", memoryDump.getStorageIds().get(0), if (snapshot.getAppList() != null) { _writer.writeElement("ApplicationList", snapshot.getAppList()); if (snapshot.getVmConfiguration() != null) { _writer.writeElement("VmConfiguration", Base64.encodeBase64String(snapshot.getVmConfiguration().getBytes()));
@Override public Object getQueryableId() { return getId(); }
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; }
@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); } }
@Test public void getOneSnapshotsByMemoryDump() { Snapshot snapshot = new Snapshot(); snapshot.setMemoryDiskId(EXISTING_MEMORY_DUMP_DISK_ID); snapshot.setMetadataDiskId(Guid.newGuid()); assertEquals(1, dao.getNumOfSnapshotsByDisks(snapshot)); }
populates.add("true"); String ovfData = "data"; org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot0 = new org.ovirt.engine.core.common.businessentities.Snapshot(); resultSnapshot0.setVmConfiguration(ovfData); resultSnapshot0.setId(SNAPSHOT_IDS[0]); org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot1 = new org.ovirt.engine.core.common.businessentities.Snapshot(); resultSnapshot1.setVmConfiguration(ovfData); resultSnapshot1.setId(SNAPSHOT_IDS[1]); when(httpHeaders.getRequestHeader(BackendResource.POPULATE)).thenReturn(populates); UriInfo uriInfo = setUpUriExpectations(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; }
sortSnapshots(snapshots); Guid userSelectedSnapshotId = getSnapshotModel().getEntity().getId(); snapshotModel.setEntity(snapshot); snapshotModel.getMemory().setEntity(false); snapshotModel.setDisks((ArrayList<DiskImage>) snapshot.getDiskImages()); snapshotModels.add(snapshotModel); if (snapshot.getType() == Snapshot.SnapshotType.ACTIVE) { activeSnapshotId = snapshot.getId(); snapshotModel.getLeaseExists().setEntity(snapshot.getId() != activeSnapshotId); getSnapshotLeaseDomainsMap().put(snapshot.getId(), leaseStorageDomainId); } else { snapshotModel.getLeaseExists().setEntity(null); getSnapshotLeaseDomainsMap().put(snapshot.getId(), null);
private void commit() { if (getEntity() != null) { if (getWindow() != null) { return; } Snapshot snapshot = getSelectedItem(); ConfirmationModel model = new ConfirmationModel(); setWindow(model); model.setTitle(ConstantsManager.getInstance().getConstants().commitSnapshotTitle()); model.setHelpTag(HelpTag.commit_snapshot); model.setHashName("commit_snapshot"); //$NON-NLS-1$ model.setMessage(ConstantsManager.getInstance() .getMessages() .areYouSureYouWantToCommitSnapshot( DateTimeFormat.getFormat(DATE_FORMAT).format(snapshot.getCreationDate()), snapshot.getDescription())); model.getCommands().add(UICommand.createDefaultOkUiCommand("OnCommit", this)); //$NON-NLS-1$ model.getCommands().add(UICommand.createCancelUiCommand("Cancel", this)); //$NON-NLS-1$ } }
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); }
private String getCreateDateString(Snapshot snapshot) { if (snapshot.getType() == SnapshotType.ACTIVE) { return constants.currentSnapshotLabel(); } return fullDateTimeRenderer.render(snapshot.getCreationDate()); }
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()); }