Skip to content

Commit a22821a

Browse files
committed
allow users to select client or services based restore
1 parent d12c842 commit a22821a

File tree

6 files changed

+111
-9
lines changed

6 files changed

+111
-9
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public class Preferences {
5757
@Preference
5858
public static String default_snapshot_mode;
5959

60+
/**
61+
* Default restore mode
62+
*/
63+
@Preference
64+
public static String default_restore_mode;
65+
6066
static {
6167
AnnotatedPreferences.initialize(Preferences.class, "/save_and_restore_preferences.properties");
6268
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public void loadSnapshot(Node snapshotNode) {
359359
}
360360

361361
public void restore(ActionEvent actionEvent) {
362-
snapshotTableViewController.restore(snapshotProperty.get(), restoreResultList -> {
362+
snapshotTableViewController.restoreSnapshot(snapshotControlsViewController.getRestoreMode(), snapshotProperty.get(), restoreResultList -> {
363363
if (snapshotControlsViewController.logAction()) {
364364
eventReceivers.forEach(r -> r.snapshotRestored(snapshotProperty.get().getSnapshotNode(), restoreResultList, this::showLoggingError));
365365
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsViewController.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.phoebus.applications.saveandrestore.model.Node;
3838
import org.phoebus.applications.saveandrestore.model.NodeType;
3939
import org.phoebus.applications.saveandrestore.model.event.SaveAndRestoreEventReceiver;
40+
import org.phoebus.applications.saveandrestore.ui.RestoreMode;
4041
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController;
4142
import org.phoebus.applications.saveandrestore.ui.SnapshotMode;
4243
import org.phoebus.ui.docking.DockPane;
@@ -128,6 +129,14 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController
128129
@FXML
129130
private RadioButton readFromArchiver;
130131

132+
@SuppressWarnings("unused")
133+
@FXML
134+
private RadioButton restoreFromClient;
135+
136+
@SuppressWarnings("unused")
137+
@FXML
138+
private RadioButton restoreFromService;
139+
131140
private List<List<Pattern>> regexPatterns = new ArrayList<>();
132141

133142
protected final SimpleStringProperty snapshotNameProperty = new SimpleStringProperty();
@@ -155,6 +164,8 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController
155164

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

167+
private final SimpleObjectProperty<RestoreMode> restoreModeProperty = new SimpleObjectProperty<>(RestoreMode.CLIENT_RESTORE);
168+
158169
public void setSnapshotController(SnapshotController snapshotController) {
159170
this.snapshotController = snapshotController;
160171
}
@@ -313,6 +324,29 @@ public void initialize() {
313324
toggleGroup.selectedToggleProperty().addListener((obs, o, n) -> {
314325
snapshotModeProperty.set((SnapshotMode) n.getUserData());
315326
});
327+
328+
restoreFromClient.setUserData(RestoreMode.CLIENT_RESTORE);
329+
restoreFromService.setUserData(RestoreMode.SERVICE_RESTORE);
330+
331+
String restoreModeString = Preferences.default_restore_mode;
332+
if (restoreModeString == null || restoreModeString.isEmpty()) {
333+
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
334+
} else {
335+
try {
336+
restoreModeProperty.set(RestoreMode.valueOf(restoreModeString));
337+
} catch (IllegalArgumentException e) {
338+
logger.log(Level.WARNING, "Unknown restore mode \"" + restoreModeString + "\", defaulting to " + RestoreMode.CLIENT_RESTORE);
339+
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
340+
}
341+
}
342+
343+
ToggleGroup restoreToggleGroup = new ToggleGroup();
344+
restoreToggleGroup.getToggles().addAll(restoreFromClient, restoreFromService);
345+
restoreToggleGroup.selectToggle(restoreToggleGroup.getToggles().stream()
346+
.filter(t -> t.getUserData().equals(restoreModeProperty.get())).findFirst().get());
347+
restoreToggleGroup.selectedToggleProperty().addListener((obs, o, n) -> {
348+
restoreModeProperty.set((RestoreMode) n.getUserData());
349+
});
316350
}
317351

318352
public SimpleStringProperty getSnapshotNameProperty() {
@@ -379,6 +413,9 @@ public void setSnapshotRestorableProperty(boolean restorable) {
379413
public SnapshotMode getDefaultSnapshotMode() {
380414
return snapshotModeProperty.get();
381415
}
416+
public RestoreMode getRestoreMode() {
417+
return restoreModeProperty.get();
418+
}
382419

383420
public boolean logAction() {
384421
return logActionProperty.get();

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.phoebus.applications.saveandrestore.model.Snapshot;
3333
import org.phoebus.applications.saveandrestore.model.SnapshotData;
3434
import org.phoebus.applications.saveandrestore.model.SnapshotItem;
35+
import org.phoebus.applications.saveandrestore.ui.RestoreMode;
3536
import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService;
3637
import org.phoebus.applications.saveandrestore.ui.SnapshotMode;
3738
import org.phoebus.applications.saveandrestore.ui.Threshold;
@@ -363,13 +364,28 @@ public void hideEqualItems() {
363364
Platform.runLater(() -> updateTable(arrayList));
364365
}
365366

367+
368+
/**
369+
* Restore a snapshot either from the client or from the services
370+
* @param restoreMode
371+
* @param snapshot
372+
* @param consumer
373+
*/
374+
public void restoreSnapshot(RestoreMode restoreMode, Snapshot snapshot, Consumer<List<RestoreResult>> consumer) {
375+
switch (restoreMode) {
376+
case CLIENT_RESTORE -> restoreFromClient(snapshot, consumer);
377+
case SERVICE_RESTORE -> restoreFromService(snapshot, consumer);
378+
default -> throw new IllegalArgumentException("RestoreMode mode " + restoreMode + " not supported");
379+
}
380+
}
381+
366382
/**
367383
* Restores a snapshot through a call to the remote service.
368384
*
369385
* @param snapshot The {@link Snapshot} object subject to restore
370386
* @param completion A handler for the outcome of the restore operation
371387
*/
372-
public void restore(Snapshot snapshot, Consumer<List<RestoreResult>> completion) {
388+
public void restoreFromService(Snapshot snapshot, Consumer<List<RestoreResult>> completion) {
373389
JobManager.schedule("Restore snapshot " + snapshot.getSnapshotNode().getName(), monitor -> {
374390
List<SnapshotItem> itemsToRestore = new ArrayList<>();
375391
List<RestoreResult> restoreResultList = null;
@@ -410,16 +426,23 @@ public void restore(Snapshot snapshot, Consumer<List<RestoreResult>> completion)
410426
* @param completion A handler for the outcome of the restore operation
411427
*/
412428
@SuppressWarnings("unused")
413-
public void restoreFromClient(Snapshot snapshot, Consumer<List<String>> completion) {
429+
public void restoreFromClient(Snapshot snapshot, Consumer<List<RestoreResult>> completion) {
414430
new Thread(() -> {
431+
// TODO merge this list with the restoreResultList
415432
List<String> restoreFailedPVNames = new ArrayList<>();
416433
CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size());
434+
435+
List<RestoreResult> restoreResultList = new ArrayList<>();
436+
417437
snapshot.getSnapshotData().getSnapshotItems()
418438
.forEach(e -> pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly())).setCountDownLatch(countDownLatch));
419439

420440
for (SnapshotItem entry : snapshot.getSnapshotData().getSnapshotItems()) {
421441
TableEntry e = tableEntryItems.get(getPVKey(entry.getConfigPv().getPvName(), entry.getConfigPv().isReadOnly()));
422442

443+
RestoreResult restoreResult = new RestoreResult();
444+
restoreResult.setSnapshotItem(entry);
445+
423446
boolean restorable = e.selectedProperty().get() &&
424447
!e.readOnlyProperty().get() &&
425448
entry.getValue() != null &&
@@ -432,11 +455,15 @@ public void restoreFromClient(Snapshot snapshot, Consumer<List<String>> completi
432455
pv.getPv().write(VTypeHelper.toObject(entry.getValue()));
433456
} catch (Exception writeException) {
434457
restoreFailedPVNames.add(entry.getConfigPv().getPvName());
458+
restoreResult.setErrorMsg(writeException.getMessage());
459+
restoreResultList.add(restoreResult);
435460
} finally {
461+
restoreResultList.add(restoreResult);
436462
pv.countDown();
437463
}
438464
}
439465
} else {
466+
restoreResult.setErrorMsg(entry.getConfigPv().getPvName() + " is not restoreable");
440467
countDownLatch.countDown();
441468
}
442469
}
@@ -457,7 +484,7 @@ public void restoreFromClient(Snapshot snapshot, Consumer<List<String>> completi
457484
"Not all PVs could be restored for {0}: {1}. The following errors occurred:\n{2}",
458485
new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), sb.toString()});
459486
}
460-
completion.accept(restoreFailedPVNames);
487+
completion.accept(restoreResultList);
461488
}).start();
462489
}
463490

app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsView.fxml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
~ Copyright (C) 2024 European Spallation Source ERIC.
55
-->
66

7-
<?import javafx.geometry.*?>
8-
<?import javafx.scene.control.*?>
9-
<?import javafx.scene.layout.*?>
7+
<?import javafx.geometry.Insets?>
8+
<?import javafx.scene.control.Button?>
9+
<?import javafx.scene.control.CheckBox?>
10+
<?import javafx.scene.control.Label?>
11+
<?import javafx.scene.control.RadioButton?>
12+
<?import javafx.scene.control.Spinner?>
13+
<?import javafx.scene.control.TextArea?>
14+
<?import javafx.scene.control.TextField?>
15+
<?import javafx.scene.control.ToggleButton?>
16+
<?import javafx.scene.control.ToolBar?>
17+
<?import javafx.scene.control.Tooltip?>
18+
<?import javafx.scene.layout.ColumnConstraints?>
19+
<?import javafx.scene.layout.GridPane?>
20+
<?import javafx.scene.layout.HBox?>
21+
<?import javafx.scene.layout.Pane?>
22+
<?import javafx.scene.layout.RowConstraints?>
23+
<?import javafx.scene.layout.VBox?>
1024

11-
<VBox maxHeight="1.7976931348623157E308" prefWidth="1188.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotControlsViewController">
25+
<VBox maxHeight="1.7976931348623157E308" prefWidth="1188.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotControlsViewController">
1226
<ToolBar prefHeight="40.0">
1327
<ToggleButton fx:id="showLiveReadbackButton" mnemonicParsing="false">
1428
<tooltip>
@@ -126,6 +140,19 @@
126140
<Tooltip text="%logActionTooltip" />
127141
</tooltip>
128142
</CheckBox>
143+
<HBox GridPane.columnIndex="5" GridPane.rowIndex="2">
144+
<children>
145+
<RadioButton fx:id="restoreFromClient" text="%restoreFromClient">
146+
<HBox.margin>
147+
<Insets right="5.0" />
148+
</HBox.margin>
149+
</RadioButton>
150+
<RadioButton fx:id="restoreFromService" text="%restoreFromService" />
151+
</children>
152+
<GridPane.margin>
153+
<Insets bottom="5.0" left="5.0" top="5.0" />
154+
</GridPane.margin>
155+
</HBox>
129156

130157
</GridPane>
131158
<ToolBar fx:id="filterToolbar" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="40.0" prefWidth="1188.0">

app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ default_search_query=tags=golden
2020
# Defines the default snapshot mode
2121
# READ_PVS: the classic mode where PV values are read from IOCs
2222
# FROM_ARCHIVER: PV values read from archiver at point in time selected by user
23-
default_snapshot_mode=READ_PVS
23+
default_snapshot_mode=READ_PVS
24+
25+
# Defines the default restore mode
26+
# CLIENT_RESTORE: the restore operation is performed by the client
27+
# SERVICE_RESTORE: the restore operation is performed by the server
28+
default_restore_mode=CLIENT_RESTORE

0 commit comments

Comments
 (0)