Skip to content

Commit

Permalink
Add option to take snashot based on archiver data
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Sep 2, 2024
1 parent 7eaf22d commit 1e23585
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
/**
* Copyright (C) 2024 European Spallation Source ERIC.
* <p>
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.applications.saveandrestore.ui.snapshot;

Expand Down Expand Up @@ -73,6 +59,7 @@
public class SnapshotController extends SaveAndRestoreBaseController {


@SuppressWarnings("unused")
@FXML
private BorderPane borderPane;

Expand Down Expand Up @@ -419,12 +406,14 @@ public void addSnapshot(Node snapshotNode) {

/**
* Launches a date/time picker and then reads from archiver to construct an in-memory {@link Snapshot} used for comparison.
*
* @param configurationNode A {@link Node} of type {@link NodeType#CONFIGURATION}.
*/
public void addSnapshotFromArchiver(Node configurationNode) {
public void addSnapshotFromArchiver() {
disabledUi.set(true);
snapshotTableViewController.takeSnapshot(SnapshotMode.FROM_ARCHIVER, snapshot -> {
if(snapshot == null){
disabledUi.set(false);
return;
}
Platform.runLater(() -> {
try {
snapshotTableViewController.addSnapshot(snapshot);
Expand All @@ -433,45 +422,6 @@ public void addSnapshotFromArchiver(Node configurationNode) {
}
});
});
/*
DateTimePane dateTimePane = new DateTimePane();
Dialog<Instant> timePickerDialog = new Dialog<>();
timePickerDialog.setTitle(Messages.dateTimePickerTitle);
timePickerDialog.getDialogPane().setContent(dateTimePane);
timePickerDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
timePickerDialog.setResultConverter(b -> {
if(b.equals(ButtonType.OK)){
return dateTimePane.getInstant();
}
return null;
});
Optional<Instant> time = timePickerDialog.showAndWait();
if(time.isEmpty()){ // User cancels date/time picker dialog
return;
}
disabledUi.set(true);
JobManager.schedule("Add snapshot from archiver", monitor -> {
List<SnapshotItem> snapshotItems;
try {
snapshotItems = SaveAndRestoreService.getInstance().takeSnapshot(configurationNode.getUniqueId(), time.get());
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Failed to query archiver for data", e);
disabledUi.set(false);
return;
}
Snapshot snapshot = new Snapshot();
snapshot.setSnapshotNode(Node.builder().nodeType(NodeType.SNAPSHOT).name(Messages.archiver).created(new Date(time.get().toEpochMilli())).build());
SnapshotData snapshotData = new SnapshotData();
snapshotData.setUniqueId("anonymous");
snapshotData.setSnapshotItems(snapshotItems);
snapshot.setSnapshotData(snapshotData);
Platform.runLater(() -> {
snapshotTableViewController.addSnapshot(snapshot);
disabledUi.set(false);
});
});
*/
}

private Snapshot getSnapshotFromService(Node snapshotNode) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
/*
* Copyright (C) 2020 European Spallation Source ERIC.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/

package org.phoebus.applications.saveandrestore.ui.snapshot;
Expand All @@ -30,11 +16,13 @@
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.ToolBar;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
Expand All @@ -45,6 +33,7 @@
import javafx.scene.input.KeyEvent;
import javafx.util.converter.DoubleStringConverter;
import org.phoebus.applications.saveandrestore.Messages;
import org.phoebus.applications.saveandrestore.Preferences;
import org.phoebus.applications.saveandrestore.model.Node;
import org.phoebus.applications.saveandrestore.model.NodeType;
import org.phoebus.applications.saveandrestore.model.event.SaveAndRestoreEventReceiver;
Expand All @@ -62,8 +51,10 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;


public class SnapshotControlsViewController extends SaveAndRestoreBaseController {

private static final Logger logger = Logger.getLogger(SnapshotControlsViewController.class.getName());
private SnapshotController snapshotController;

@FXML
Expand All @@ -75,48 +66,68 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController
@FXML
protected Button saveSnapshotButton;

@SuppressWarnings("unused")
@FXML
private Label createdBy;

@SuppressWarnings("unused")
@FXML
private Label createdDate;

@SuppressWarnings("unused")
@FXML
private Label snapshotLastModifiedLabel;

@SuppressWarnings("unused")
@FXML
private Button takeSnapshotButton;

@SuppressWarnings("unused")
@FXML
private Button restoreButton;

@SuppressWarnings("unused")
@FXML
private Spinner<Double> thresholdSpinner;

@SuppressWarnings("unused")
@FXML
private Spinner<Double> multiplierSpinner;

@SuppressWarnings("unused")
@FXML
private TextField filterTextField;

@SuppressWarnings("unused")
@FXML
private CheckBox preserveSelectionCheckBox;

@FXML
protected ToggleButton showLiveReadbackButton;

@SuppressWarnings("unused")
@FXML
private ToggleButton showDeltaPercentageButton;

@FXML
protected ToggleButton hideEqualItemsButton;

@SuppressWarnings("unused")
@FXML
private ToolBar filterToolbar;

@SuppressWarnings("unused")
@FXML
private CheckBox logAction;

@SuppressWarnings("unused")
@FXML
private RadioButton readPVs;

@SuppressWarnings("unused")
@FXML
private RadioButton readFromArchiver;

private List<List<Pattern>> regexPatterns = new ArrayList<>();

protected final SimpleStringProperty snapshotNameProperty = new SimpleStringProperty();
Expand All @@ -140,14 +151,14 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController
*/
protected final SimpleBooleanProperty snapshotDataDirty = new SimpleBooleanProperty(false);

private final SimpleObjectProperty<Node> snapshotNodeProperty = new SimpleObjectProperty();
private final SimpleObjectProperty<Node> snapshotNodeProperty = new SimpleObjectProperty<>();

private final SimpleObjectProperty<SnapshotMode> snapshotModeProperty = new SimpleObjectProperty<>(SnapshotMode.READ_PVS);

public void setSnapshotController(SnapshotController snapshotController) {
this.snapshotController = snapshotController;
}

private SnapshotMode defaultSnapshotMode;

@FXML
public void initialize() {

Expand Down Expand Up @@ -278,17 +289,30 @@ public void initialize() {
}
});

try {
defaultSnapshotMode = SnapshotMode.valueOf(org.phoebus.applications.saveandrestore.Preferences.default_snapshot_mode);
} catch (IllegalArgumentException e) {
Logger.getLogger(SnapshotControlsViewController.class.getName())
.log(Level.WARNING, "No default snapshot mode mapped to \"" +
org.phoebus.applications.saveandrestore.Preferences.default_snapshot_mode
+ "\", falling back to " + SnapshotMode.READ_PVS);
defaultSnapshotMode = SnapshotMode.READ_PVS;
logAction.selectedProperty().bindBidirectional(logActionProperty);

readPVs.setUserData(SnapshotMode.READ_PVS);
readFromArchiver.setUserData(SnapshotMode.FROM_ARCHIVER);

String snapshotModeString = Preferences.default_snapshot_mode;
if (snapshotModeString == null || snapshotModeString.isEmpty()) {
snapshotModeProperty.set(SnapshotMode.READ_PVS);
} else {
try {
snapshotModeProperty.set(SnapshotMode.valueOf(snapshotModeString));
} catch (IllegalArgumentException e) {
logger.log(Level.WARNING, "Unknown snapshot mode \"" + snapshotModeString + "\", defaulting to " + SnapshotMode.READ_PVS);
snapshotModeProperty.set(SnapshotMode.READ_PVS);
}
}

logAction.selectedProperty().bindBidirectional(logActionProperty);
ToggleGroup toggleGroup = new ToggleGroup();
toggleGroup.getToggles().addAll(readPVs, readFromArchiver);
toggleGroup.selectToggle(toggleGroup.getToggles().stream()
.filter(t -> t.getUserData().equals(snapshotModeProperty.get())).findFirst().get());
toggleGroup.selectedToggleProperty().addListener((obs, o, n) -> {
snapshotModeProperty.set((SnapshotMode) n.getUserData());
});
}

public SimpleStringProperty getSnapshotNameProperty() {
Expand All @@ -299,13 +323,15 @@ public SimpleStringProperty getSnapshotCommentProperty() {
return snapshotCommentProperty;
}

@SuppressWarnings("unused")
@FXML
public void takeSnapshot() {
snapshotDataDirty.set(true);
snapshotRestorableProperty.set(false);
snapshotController.takeSnapshot();
}

@SuppressWarnings("unused")
@FXML
public void saveSnapshot(ActionEvent event) {
snapshotController.saveSnapshot(event);
Expand Down Expand Up @@ -351,7 +377,7 @@ public void setSnapshotRestorableProperty(boolean restorable) {
}

public SnapshotMode getDefaultSnapshotMode() {
return defaultSnapshotMode;
return snapshotModeProperty.get();
}

public boolean logAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.phoebus.applications.saveandrestore.ui.snapshot;

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleObjectProperty;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.MenuItem;
Expand All @@ -39,7 +38,6 @@
import org.phoebus.ui.javafx.ImageCache;

import java.io.IOException;
import java.time.Instant;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -50,7 +48,7 @@
* and maintenance.
*
* <p>
* Note that this class is used also to show the snapshot view for {@link Node}s of type {@link NodeType#COMPOSITE_SNAPSHOT}.
* Note that this class is used also to show the snapshot view for {@link Node}s of type {@link NodeType#COMPOSITE_SNAPSHOT}.
* </p>
*/
public class SnapshotTab extends SaveAndRestoreTab {
Expand Down Expand Up @@ -117,12 +115,11 @@ public SnapshotTab(org.phoebus.applications.saveandrestore.model.Node node, Save
});

MenuItem compareSnapshotToArchiverDataMenuItem = new MenuItem(Messages.contextMenuCompareSnapshotWithArchiverData, new ImageView(compareSnapshotIcon));
compareSnapshotToArchiverDataMenuItem.setOnAction(ae ->
addSnapshotFromArchive(((SnapshotController)controller).getSnapshot().getSnapshotNode()));
compareSnapshotToArchiverDataMenuItem.setOnAction(ae -> addSnapshotFromArchive());

getContextMenu().setOnShowing(e -> {
Snapshot snapshot = ((SnapshotController)controller).getSnapshot();
if(snapshot.getSnapshotData().getSnapshotItems().isEmpty()){
Snapshot snapshot = ((SnapshotController) controller).getSnapshot();
if (snapshot.getSnapshotData().getSnapshotItems().isEmpty()) {
compareSnapshotToArchiverDataMenuItem.disableProperty().set(true);
}
compareSnapshotToArchiverDataMenuItem.disableProperty().set(snapshot.getSnapshotNode().getUniqueId() == null);
Expand All @@ -138,18 +135,17 @@ public void updateTabTitle(String name) {

/**
* Set tab image based on node type, and optionally golden tag
*
* @param node A snapshot {@link Node}
*/
private void setTabImage(Node node) {
if(node.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT)){
if (node.getNodeType().equals(NodeType.COMPOSITE_SNAPSHOT)) {
tabGraphicImageProperty.set(ImageRepository.COMPOSITE_SNAPSHOT);
}
else{
} else {
boolean golden = node.getTags() != null && node.getTags().stream().anyMatch(t -> t.getName().equals(Tag.GOLDEN));
if (golden) {
tabGraphicImageProperty.set(ImageRepository.GOLDEN_SNAPSHOT);
}
else {
} else {
tabGraphicImageProperty.set(ImageRepository.SNAPSHOT);
}
}
Expand Down Expand Up @@ -181,8 +177,8 @@ public void addSnapshot(Node node) {
((SnapshotController) controller).addSnapshot(node);
}

private void addSnapshotFromArchive(Node node){
((SnapshotController) controller).addSnapshotFromArchiver(node);
private void addSnapshotFromArchive() {
((SnapshotController) controller).addSnapshotFromArchiver();
}

@Override
Expand Down
Loading

0 comments on commit 1e23585

Please sign in to comment.