From 7fa8c87b1ec282606a73f40b75c76bef732eadb5 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 31 Jul 2024 10:28:56 +0200 Subject: [PATCH] Additional logging on server-side save&restore actions --- .../saveandrestore/epics/SnapshotUtil.java | 22 ++++++++++++++----- .../SnapshotRestoreController.java | 8 ++++++- .../controllers/TakeSnapshotController.java | 8 ++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java index 7b4cd53765..000c251276 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java @@ -116,14 +116,19 @@ public List takeSnapshot(ConfigurationData configurationData) { pv = PVPool.getPV(configPv.getPvName()); pv.onValueEvent().subscribe(value -> { if (!VTypeHelper.isDisconnected(value)) { - pvValues.put(configPv.getPvName(), value); countDownLatch.countDown(); } }); if (!countDownLatch.await(connectionTimeout, TimeUnit.MILLISECONDS)) { + LOG.log(Level.WARNING, "Connection to PV '" + configPv.getPvName() + + "' timed out after " + connectionTimeout + " ms."); pvValues.put(configPv.getPvName(), null); } + else{ + pvValues.put(configPv.getPvName(), pv.read()); + } } catch (Exception e) { + LOG.log(Level.WARNING, "Failed to read PV '" + configPv.getPvName() + "'", e); pvValues.put(configPv.getPvName(), null); countDownLatch.countDown(); } finally { @@ -147,14 +152,19 @@ public List takeSnapshot(ConfigurationData configurationData) { pv = PVPool.getPV(configPv.getReadbackPvName()); pv.onValueEvent().subscribe(value -> { if (!VTypeHelper.isDisconnected(value)) { - readbackPvValues.put(configPv.getPvName(), value); countDownLatch.countDown(); } }); if (!countDownLatch.await(connectionTimeout, TimeUnit.MILLISECONDS)) { + LOG.log(Level.WARNING, "Connection to read-back PV '" + configPv.getReadbackPvName() + + "' timed out after " + connectionTimeout + " ms."); readbackPvValues.put(configPv.getPvName(), null); } + else{ + readbackPvValues.put(configPv.getPvName(), pv.read()); + } } catch (Exception e) { + LOG.log(Level.WARNING, "Failed to read read-back PV '" + configPv.getReadbackPvName() + "'", e); readbackPvValues.put(configPv.getPvName(), null); countDownLatch.countDown(); } finally { @@ -226,18 +236,20 @@ public Void call() { } }); if (!countDownLatch.await(connectionTimeout, TimeUnit.MILLISECONDS)) { + LOG.log(Level.WARNING, "Connection to PV '" + snapshotItem.getConfigPv().getPvName() + + "' timed out after " + connectionTimeout + "ms."); RestoreResult restoreResult = new RestoreResult(); restoreResult.setSnapshotItem(snapshotItem); - restoreResult.setErrorMsg("No monitor event from PV " + snapshotItem.getConfigPv().getPvName()); + restoreResult.setErrorMsg("No monitor event from PV '" + snapshotItem.getConfigPv().getPvName() + "'"); restoreResultList.add(restoreResult); } else { pv.write(VTypeHelper.toObject(snapshotItem.getValue())); } } catch (Exception e) { - LOG.log(Level.WARNING, "Failed to write to PV " + snapshotItem.getConfigPv().getPvName(), e); + LOG.log(Level.WARNING, "Failed to write to PV '" + snapshotItem.getConfigPv().getPvName() + "'", e); RestoreResult restoreResult = new RestoreResult(); restoreResult.setSnapshotItem(snapshotItem); - restoreResult.setErrorMsg(e.getMessage()); + restoreResult.setErrorMsg("Failed to write to PV '" + snapshotItem.getConfigPv().getPvName() + "', cause: " + e.getMessage()); restoreResultList.add(restoreResult); countDownLatch.countDown(); } diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java index 5e1253ab85..52831baa19 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java @@ -17,6 +17,7 @@ */ package org.phoebus.service.saveandrestore.web.controllers; +import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.RestoreResult; import org.phoebus.applications.saveandrestore.model.SnapshotItem; import org.phoebus.service.saveandrestore.epics.SnapshotUtil; @@ -28,6 +29,8 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * {@link RestController} performing server-side restore operation. @@ -42,6 +45,8 @@ public class SnapshotRestoreController extends BaseController { @Autowired private SnapshotUtil snapshotUtil; + private static final Logger LOG = Logger.getLogger(SnapshotRestoreController.class.getName()); + @PostMapping(value = "/restore/items", produces = JSON) public List restoreFromSnapshotItems( @RequestBody List snapshotItems) { @@ -51,9 +56,10 @@ public List restoreFromSnapshotItems( @PostMapping(value = "/restore/node", produces = JSON) public List restoreFromSnapshotNode( @RequestParam(value = "nodeId") String nodeId){ + Node snapshotNode = nodeDAO.getNode(nodeId); + LOG.log(Level.INFO, "Restore requested for snapshot '" + snapshotNode.getName() + "'"); var snapshot = nodeDAO.getSnapshotData(nodeId); return snapshotUtil.restore(snapshot.getSnapshotItems()); } - } diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java index 3496d17b62..f04d7166bb 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java @@ -22,6 +22,8 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; @RestController public class TakeSnapshotController extends BaseController { @@ -35,6 +37,8 @@ public class TakeSnapshotController extends BaseController { private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + private static final Logger LOG = Logger.getLogger(TakeSnapshotController.class.getName()); + /** * Take a snapshot based on the {@link org.phoebus.applications.saveandrestore.model.Configuration}'s unique id. * @@ -45,6 +49,8 @@ public class TakeSnapshotController extends BaseController { @SuppressWarnings("unused") @GetMapping(value = "/take-snapshot/{configNodeId}", produces = JSON) public List takeSnapshot(@PathVariable String configNodeId) { + Node configNode = nodeDAO.getNode(configNodeId); + LOG.log(Level.INFO, "Take snapshot for configuration '" + configNode.getName() + "'"); ConfigurationData configurationData = nodeDAO.getConfigurationData(configNodeId); List snapshotItems; try { @@ -72,7 +78,7 @@ public List takeSnapshot(@PathVariable String configNodeId) { public Snapshot takeSnapshotAndSave(@PathVariable String configNodeId, @RequestParam(name = "name", required = false) String snapshotName, @RequestParam(name = "comment", required = false) String comment) { - if (snapshotName != null) { + if (snapshotName != null) { String _snapshotName = snapshotName; List childNodes = nodeDAO.getChildNodes(configNodeId); if (childNodes.stream().anyMatch(n -> n.getName().equals(_snapshotName) &&