Skip to content

Commit 8f7eace

Browse files
committed
Use the save and restore utility to do both client and server restores
1 parent 41323f2 commit 8f7eace

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

app/save-and-restore/app/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<artifactId>save-and-restore-model</artifactId>
2222
<version>4.7.4-SNAPSHOT</version>
2323
</dependency>
24+
<dependency>
25+
<groupId>org.phoebus</groupId>
26+
<artifactId>save-and-restore-util</artifactId>
27+
<version>4.7.4-SNAPSHOT</version>
28+
<scope>compile</scope>
29+
</dependency>
2430
<dependency>
2531
<groupId>org.phoebus</groupId>
2632
<artifactId>app-display-model</artifactId>
@@ -76,6 +82,7 @@
7682
<scope>test</scope>
7783
</dependency>
7884

85+
7986
</dependencies>
8087
<build>
8188
<resources>

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

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import org.phoebus.applications.saveandrestore.ui.VNoData;
4141
import org.phoebus.applications.saveandrestore.ui.VTypePair;
4242
import org.phoebus.core.vtypes.VDisconnectedData;
43-
import org.phoebus.core.vtypes.VTypeHelper;
4443
import org.phoebus.framework.jobs.JobManager;
44+
import org.phoebus.saveandrestore.util.SnapshotUtil;
4545
import org.phoebus.ui.dialog.DialogHelper;
4646
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
4747
import org.phoebus.ui.time.DateTimePane;
@@ -50,13 +50,10 @@
5050
import java.text.SimpleDateFormat;
5151
import java.time.Instant;
5252
import java.util.ArrayList;
53-
import java.util.Collections;
5453
import java.util.Comparator;
5554
import java.util.Date;
5655
import java.util.List;
5756
import java.util.Optional;
58-
import java.util.concurrent.CountDownLatch;
59-
import java.util.concurrent.TimeUnit;
6057
import java.util.function.Consumer;
6158
import java.util.logging.Level;
6259
import java.util.regex.Pattern;
@@ -83,6 +80,7 @@ public class SnapshotTableViewController extends BaseSnapshotTableViewController
8380

8481
private final SimpleBooleanProperty compareViewEnabled = new SimpleBooleanProperty(false);
8582

83+
private SnapshotUtil snapshotUtil;
8684

8785
@FXML
8886
public void initialize() {
@@ -147,6 +145,8 @@ public void initialize() {
147145
valueColumn.visibleProperty().bind(compareViewEnabled.not());
148146

149147
compareViewEnabled.addListener((ob, o, n) -> snapshotTableView.layout());
148+
149+
snapshotUtil = new SnapshotUtil();
150150
}
151151

152152
public void setSnapshotController(SnapshotController snapshotController) {
@@ -429,48 +429,36 @@ public void restoreFromService(Snapshot snapshot, Consumer<List<RestoreResult>>
429429
@SuppressWarnings("unused")
430430
public void restoreFromClient(Snapshot snapshot, Consumer<List<RestoreResult>> completion) {
431431
new Thread(() -> {
432-
CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size());
433432

433+
List<SnapshotItem> itemsToRestore = new ArrayList<>();
434434
List<RestoreResult> restoreResultList = new ArrayList<>();
435435

436-
snapshot.getSnapshotData().getSnapshotItems()
437-
.forEach(e -> pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly())).setCountDownLatch(countDownLatch));
438-
439436
for (SnapshotItem entry : snapshot.getSnapshotData().getSnapshotItems()) {
440437
TableEntry e = tableEntryItems.get(getPVKey(entry.getConfigPv().getPvName(), entry.getConfigPv().isReadOnly()));
441438

442-
RestoreResult restoreResult = new RestoreResult();
443-
restoreResult.setSnapshotItem(entry);
444-
445439
boolean restorable = e.selectedProperty().get() &&
446440
!e.readOnlyProperty().get() &&
447441
entry.getValue() != null &&
448442
!entry.getValue().equals(VNoData.INSTANCE);
449443

450444
if (restorable) {
451-
final SaveAndRestorePV pv = pvs.get(getPVKey(e.pvNameProperty().get(), e.readOnlyProperty().get()));
452-
if (entry.getValue() != null) {
453-
try {
454-
pv.getPv().write(VTypeHelper.toObject(entry.getValue()));
455-
} catch (Exception writeException) {
456-
restoreResult.setErrorMsg(writeException.getMessage());
457-
restoreResultList.add(restoreResult);
458-
} finally {
459-
pv.countDown();
460-
}
461-
}
462-
} else {
463-
restoreResult.setErrorMsg(entry.getConfigPv().getPvName() + " is not restoreable");
464-
countDownLatch.countDown();
445+
itemsToRestore.add(entry);
465446
}
466447
}
467448

468449
try {
469-
countDownLatch.await(10, TimeUnit.MINUTES);
470-
} catch (InterruptedException e) {
471-
LOGGER.log(Level.INFO, "Encountered InterruptedException", e);
450+
restoreResultList = snapshotUtil.restore(itemsToRestore);
451+
} catch (Exception e) {
452+
Platform.runLater(() -> {
453+
Alert alert = new Alert(Alert.AlertType.ERROR);
454+
alert.setTitle(Messages.errorActionFailed);
455+
alert.setContentText(e.getMessage());
456+
alert.setHeaderText(Messages.restoreFailed);
457+
DialogHelper.positionDialog(alert, snapshotTableView, -150, -150);
458+
alert.showAndWait();
459+
});
472460
}
473-
461+
// Legacy
474462
if (restoreResultList.isEmpty()) {
475463
LOGGER.log(Level.FINE, "Restored snapshot {0}", snapshot.getSnapshotNode().getName());
476464
} else {

0 commit comments

Comments
 (0)