Skip to content

Commit

Permalink
Additional logging on server-side save&restore actions
Browse files Browse the repository at this point in the history
  • Loading branch information
georgweiss committed Jul 31, 2024
1 parent e44953c commit 7fa8c87
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ public List<SnapshotItem> 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 {
Expand All @@ -147,14 +152,19 @@ public List<SnapshotItem> 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 {
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<RestoreResult> restoreFromSnapshotItems(
@RequestBody List<SnapshotItem> snapshotItems) {
Expand All @@ -51,9 +56,10 @@ public List<RestoreResult> restoreFromSnapshotItems(
@PostMapping(value = "/restore/node", produces = JSON)
public List<RestoreResult> 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());
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
*
Expand All @@ -45,6 +49,8 @@ public class TakeSnapshotController extends BaseController {
@SuppressWarnings("unused")
@GetMapping(value = "/take-snapshot/{configNodeId}", produces = JSON)
public List<SnapshotItem> 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<SnapshotItem> snapshotItems;
try {
Expand Down Expand Up @@ -72,7 +78,7 @@ public List<SnapshotItem> 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<Node> childNodes = nodeDAO.getChildNodes(configNodeId);
if (childNodes.stream().anyMatch(n -> n.getName().equals(_snapshotName) &&
Expand Down

0 comments on commit 7fa8c87

Please sign in to comment.