Skip to content

Commit

Permalink
Use the save and restore utility to do both client and server restores
Browse files Browse the repository at this point in the history
  • Loading branch information
shroffk committed Oct 14, 2024
1 parent 41323f2 commit 8f7eace
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
7 changes: 7 additions & 0 deletions app/save-and-restore/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<artifactId>save-and-restore-model</artifactId>
<version>4.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>save-and-restore-util</artifactId>
<version>4.7.4-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.phoebus</groupId>
<artifactId>app-display-model</artifactId>
Expand Down Expand Up @@ -76,6 +82,7 @@
<scope>test</scope>
</dependency>


</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.phoebus.applications.saveandrestore.ui.VNoData;
import org.phoebus.applications.saveandrestore.ui.VTypePair;
import org.phoebus.core.vtypes.VDisconnectedData;
import org.phoebus.core.vtypes.VTypeHelper;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.saveandrestore.util.SnapshotUtil;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
import org.phoebus.ui.time.DateTimePane;
Expand All @@ -50,13 +50,10 @@
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.regex.Pattern;
Expand All @@ -83,6 +80,7 @@ public class SnapshotTableViewController extends BaseSnapshotTableViewController

private final SimpleBooleanProperty compareViewEnabled = new SimpleBooleanProperty(false);

private SnapshotUtil snapshotUtil;

@FXML
public void initialize() {
Expand Down Expand Up @@ -147,6 +145,8 @@ public void initialize() {
valueColumn.visibleProperty().bind(compareViewEnabled.not());

compareViewEnabled.addListener((ob, o, n) -> snapshotTableView.layout());

snapshotUtil = new SnapshotUtil();
}

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

List<SnapshotItem> itemsToRestore = new ArrayList<>();
List<RestoreResult> restoreResultList = new ArrayList<>();

snapshot.getSnapshotData().getSnapshotItems()
.forEach(e -> pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly())).setCountDownLatch(countDownLatch));

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

RestoreResult restoreResult = new RestoreResult();
restoreResult.setSnapshotItem(entry);

boolean restorable = e.selectedProperty().get() &&
!e.readOnlyProperty().get() &&
entry.getValue() != null &&
!entry.getValue().equals(VNoData.INSTANCE);

if (restorable) {
final SaveAndRestorePV pv = pvs.get(getPVKey(e.pvNameProperty().get(), e.readOnlyProperty().get()));
if (entry.getValue() != null) {
try {
pv.getPv().write(VTypeHelper.toObject(entry.getValue()));
} catch (Exception writeException) {
restoreResult.setErrorMsg(writeException.getMessage());
restoreResultList.add(restoreResult);
} finally {
pv.countDown();
}
}
} else {
restoreResult.setErrorMsg(entry.getConfigPv().getPvName() + " is not restoreable");
countDownLatch.countDown();
itemsToRestore.add(entry);
}
}

try {
countDownLatch.await(10, TimeUnit.MINUTES);
} catch (InterruptedException e) {
LOGGER.log(Level.INFO, "Encountered InterruptedException", e);
restoreResultList = snapshotUtil.restore(itemsToRestore);
} catch (Exception e) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(Messages.errorActionFailed);
alert.setContentText(e.getMessage());
alert.setHeaderText(Messages.restoreFailed);
DialogHelper.positionDialog(alert, snapshotTableView, -150, -150);
alert.showAndWait();
});
}

// Legacy
if (restoreResultList.isEmpty()) {
LOGGER.log(Level.FINE, "Restored snapshot {0}", snapshot.getSnapshotNode().getName());
} else {
Expand Down

0 comments on commit 8f7eace

Please sign in to comment.