@Override public void render(Context context, SnapshotModel snapshotModel, SafeHtmlBuilder sb) { if (!snapshotModel.getEntity().isVmConfigurationBroken()) { super.render(context, snapshotModel, sb); } else { sb.appendEscaped(constants.notAvailableLabel()); } } };
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; }
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); }
@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()); }