Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/save-and-restore/app/doc/images/compare-snapshots-view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/operation-failed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/restore-failed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/restore-with-scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/snapshot-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/snapshot-restore-filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/snapshot-restore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/snapshot-taken.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/snapshot-threshold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/save-and-restore/app/doc/images/toggle-delta-zero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/save-and-restore/app/doc/images/toggle-readback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/save-and-restore/app/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,14 @@ Prior to restore user has the option to:

Restoring from a composite snapshot works in the same manner as the restore operation from a single-snapshot.

The preference setting ``org.phoebus.applications.saveandrestore/default_restore_mode`` selects the preferred
mode of a restore operation, i.e. to let the Phoebus client perform the restore operation, or to delegate that
to the service. Note though that a restore operation on the service requires a dedicated user role. In case
``org.phoebus.applications.saveandrestore/default_restore_mode`` is set to ``SERVICE_RESTORE``,
but user is not authorized to call the service to perform a restore operation, the UI will indicate it thus:

.. image:: images/restore-mode-invalid.png

Filter PV items in list
^^^^^^^^^^^^^^^^^^^^^^^
The list of items in the snapshot view can be filtered based on the PV name. See screenshot for highlighted UI element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import javax.ws.rs.core.MultivaluedMap;
import java.util.List;
import java.util.Optional;

/**
* Implementations of this interface shall handle the communication to the save-and-restore service.
Expand Down Expand Up @@ -275,4 +276,10 @@ public interface SaveAndRestoreClient {
* @return A {@link List} of {@link SnapshotItem}s carrying snapshot values read by the service.
*/
List<SnapshotItem> takeSnapshot(String configurationNodeId);

/**
* @return An empty {@link Optional} if user is not yet authenticated, otherwise a value
* indicating if user is authorized to call server side restore operations.
*/
Optional<Boolean> serverRestoreAuthorized();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.time.Duration;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -665,6 +666,29 @@
});
}

@Override
public Optional<Boolean> serverRestoreAuthorized(){
String basicAuthenticationHeader = getBasicAuthenticationHeader();
if(basicAuthenticationHeader == null){ // User not signed in
return Optional.empty();
}
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(Preferences.jmasarServiceUrl + "/server-restore-authorized"))
.header("Authorization", basicAuthenticationHeader)
.POST(HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
return Optional.of(false);
}

return Optional.of(OBJECT_MAPPER.readValue(response.body(), Boolean.class));
} catch (Exception e) {

Check warning on line 687 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaH5qCouFpA4IEPfcKkA&open=AaH5qCouFpA4IEPfcKkA&pullRequest=4035
throw new RuntimeException(e);
}
}

private <T> T getCall(String relativeUrl, Class<T> clazz) {
HttpResponse<String> response = getCall(relativeUrl);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public Filter fromString(String s) {
saveAndRestoreService.setConnectCallback(this::handleWebSocketConnected);
saveAndRestoreService.setDisconnectCallback(this::handleWebSocketDisconnected);
saveAndRestoreService.connectWebSocket();

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -517,4 +518,12 @@ public void handleWebSocketMessage(String message) {
}
}

/**
* @return <code>false</code> if user is not yet authenticated or is not
* authorized to call restore operations on the server.
*/
public Optional<Boolean> serverRestoreAuthorized(){
return saveAndRestoreClient.serverRestoreAuthorized();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import org.phoebus.saveandrestore.util.Threshold;
import org.phoebus.saveandrestore.util.Utilities;
import org.phoebus.saveandrestore.util.VNoData;
import org.phoebus.security.tokens.ScopedAuthenticationToken;
import org.phoebus.ui.application.ContextMenuHelper;
import org.phoebus.ui.dialog.DialogHelper;
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
Expand Down Expand Up @@ -202,14 +203,6 @@
@FXML
private RadioButton readFromArchiver;

@SuppressWarnings("unused")
@FXML
private RadioButton restoreFromClient;

@SuppressWarnings("unused")
@FXML
private RadioButton restoreFromService;

@SuppressWarnings("unused")
@FXML
private TooltipTableColumn<String> pvNameColumn;
Expand All @@ -229,6 +222,9 @@
@FXML
private TableColumn<TableEntry, ActionResult> actionResultColumn;

@FXML
private Label invalidConfigLabel;

@SuppressWarnings("unused")
@FXML
private TableColumn<TableEntry, ActionResult> actionResultReadbackColumn;
Expand Down Expand Up @@ -348,6 +344,13 @@
*/
protected final SimpleBooleanProperty disabledUi = new SimpleBooleanProperty(false);

/**
* Used to manage UI components based on preferred restore mode (client or service) and
* actual user authorization for server restore operations. Initially this is true,
* but checks are performed to verify this.
*/
private final SimpleBooleanProperty serverRestoreSettingsConsistent = new SimpleBooleanProperty(true);

/**
* The {@link Snapshot} object holding the data for this controller.
*/
Expand Down Expand Up @@ -419,8 +422,10 @@
logAction.visibleProperty().set(ServiceLoader.load(SaveAndRestoreEventReceiver.class).iterator().hasNext());

restoreButton.disableProperty().bind(Bindings.createBooleanBinding(() ->
snapshotRestorableProperty.not().get() ||
userIdentity.isNull().get(), snapshotRestorableProperty, userIdentity));
snapshotRestorableProperty.not().get() || serverRestoreSettingsConsistent.not().get() ||
userIdentity.isNull().get(), snapshotRestorableProperty, userIdentity, serverRestoreSettingsConsistent));

invalidConfigLabel.visibleProperty().bind(serverRestoreSettingsConsistent.not());

SpinnerValueFactory<Double> thresholdSpinnerValueFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 999.0, 0.0, 0.01);
thresholdSpinnerValueFactory.setConverter(new DoubleStringConverter());
Expand Down Expand Up @@ -505,26 +510,13 @@
toggleGroup.selectedToggleProperty().addListener((obs, o, n) ->
snapshotModeProperty.set((SnapshotMode) n.getUserData()));

restoreFromClient.setUserData(RestoreMode.CLIENT_RESTORE);
restoreFromService.setUserData(RestoreMode.SERVICE_RESTORE);

String restoreModeString = Preferences.default_restore_mode;
if (restoreModeString == null || restoreModeString.isEmpty()) {
try {
restoreModeProperty.set(RestoreMode.valueOf(Preferences.default_restore_mode.toUpperCase()));
} catch (IllegalArgumentException e) {
LOGGER.log(Level.WARNING, "Unknown restore mode \"" + Preferences.default_restore_mode + "\", defaulting to " + RestoreMode.CLIENT_RESTORE);

Check warning on line 516 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers or lambda should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AaH5qCivFpA4IEPfcKj_&open=AaH5qCivFpA4IEPfcKj_&pullRequest=4035
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
} else {
try {
restoreModeProperty.set(RestoreMode.valueOf(restoreModeString));
} catch (IllegalArgumentException e) {
LOGGER.log(Level.WARNING, "Unknown restore mode \"" + restoreModeString + "\", defaulting to " + RestoreMode.CLIENT_RESTORE);
restoreModeProperty.set(RestoreMode.CLIENT_RESTORE);
}
}

ToggleGroup restoreToggleGroup = new ToggleGroup();
restoreToggleGroup.getToggles().addAll(restoreFromClient, restoreFromService);
restoreToggleGroup.selectToggle(restoreToggleGroup.getToggles().stream()
.filter(t -> t.getUserData().equals(restoreModeProperty.get())).findFirst().get());
restoreToggleGroup.selectedToggleProperty().addListener((obs, o, n) -> restoreModeProperty.set((RestoreMode) n.getUserData()));
checkRestoreMode();

snapshotTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY_FLEX_LAST_COLUMN);
snapshotTableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Expand Down Expand Up @@ -917,7 +909,7 @@
selectedColumn.visibleProperty().set(true);
tabTitleProperty.setValue(snapshotNode.getName());
tabIdProperty.setValue(snapshotNode.getUniqueId());
snapshotRestorableProperty.set(true);
snapshotRestorableProperty.setValue(true);
setTabImage(snapshotNode);
});
updateUi();
Expand Down Expand Up @@ -1653,4 +1645,28 @@

}
}

/**
* If preference is set to {@link RestoreMode#SERVICE_RESTORE}, this method will check with
* the service if the current user is authorized to perform server side restore. If not authorized,
* UI elements are updated accordingly.
*/
private void checkRestoreMode(){
if(restoreModeProperty.get().equals(RestoreMode.CLIENT_RESTORE)){
serverRestoreSettingsConsistent.setValue(true);
return;
}

JobManager.schedule("Check server restore authorization", monitor -> {
Optional<Boolean> serverRestoreAuthorizedOptional = saveAndRestoreService.serverRestoreAuthorized();
serverRestoreSettingsConsistent.setValue(serverRestoreAuthorizedOptional.isPresent() &&
serverRestoreAuthorizedOptional.get());
});
}

@Override
public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens) {
super.secureStoreChanged(validTokens);
checkRestoreMode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ restoreFailed=Restore operation failed
restoreFailedPVs=Failed to write the following PVs:
restoreFromClient=From client
restoreFromService=From service
restoreSettingsInconsistent=User not authorized for server side restore.
SaveAndRestore=Save And Restore
save=Save
saveAsFilter=Save As Filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,14 @@ This is the contents of the top portion of a snapshot tab. Since tabs are added
save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
-->

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.ProgressIndicator?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import java.lang.String?>
<?import org.phoebus.applications.saveandrestore.ui.snapshot.TooltipTableColumn?>
<?import org.phoebus.applications.saveandrestore.ui.snapshot.DividerTableColumn?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import org.phoebus.applications.saveandrestore.ui.snapshot.*?>

<StackPane xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotController">
<StackPane xmlns="http://javafx.com/javafx/17.0.12" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.phoebus.applications.saveandrestore.ui.snapshot.SnapshotController">
<BorderPane fx:id="borderPane" style="-fx-background-color: #f4f4f4;">
<top>
<VBox>
Expand Down Expand Up @@ -154,20 +133,11 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
<Tooltip text="%logActionTooltip" />
</tooltip>
</CheckBox>
<HBox GridPane.columnIndex="5" GridPane.rowIndex="2">
<children>
<RadioButton fx:id="restoreFromClient" text="%restoreFromClient">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</RadioButton>
<RadioButton fx:id="restoreFromService" text="%restoreFromService" />
</children>
<GridPane.margin>
<Insets bottom="5.0" left="5.0" top="5.0" />
</GridPane.margin>
</HBox>

<Label fx:id="invalidConfigLabel" text="%restoreSettingsInconsistent" visible="false" GridPane.columnIndex="5" GridPane.rowIndex="2">
<GridPane.margin>
<Insets left="5.0" />
</GridPane.margin>
</Label>
</GridPane>
<ToolBar fx:id="filterToolbar" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="40.0" prefWidth="1188.0">
<CheckBox fx:id="preserveSelectionCheckBox" mnemonicParsing="false" text="%preserveSelection" />
Expand All @@ -183,7 +153,7 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
<center>
<TableView fx:id="snapshotTableView" editable="true" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
<columns>
<TableColumn fx:id="actionResultColumn" visible="false" editable="false" maxWidth="40" prefWidth="40" resizable="false" style="-fx-alignment: TOP-CENTER;" >
<TableColumn fx:id="actionResultColumn" editable="false" maxWidth="40" prefWidth="40" resizable="false" style="-fx-alignment: TOP-CENTER;" visible="false">
<cellValueFactory>
<PropertyValueFactory property="actionResult" />
</cellValueFactory>
Expand Down Expand Up @@ -264,7 +234,7 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.

<TableColumn fx:id="readbackColumn" minWidth="300.0" prefWidth="500.0" sortable="false" styleClass="snapshot-table-centered" text="%tableColumnReadback">
<columns>
<TableColumn fx:id="actionResultReadbackColumn" visible="false" editable="false" maxWidth="40" prefWidth="40" resizable="false" style="-fx-alignment: TOP-CENTER;" >
<TableColumn fx:id="actionResultReadbackColumn" editable="false" maxWidth="40" prefWidth="40" resizable="false" style="-fx-alignment: TOP-CENTER;" visible="false">
<cellValueFactory>
<PropertyValueFactory property="actionResultReadback" />
</cellValueFactory>
Expand Down Expand Up @@ -292,6 +262,6 @@ save-and-restore UI, this fxml does not make use of TabPane and Tab elements.
</center>
</BorderPane>
<VBox fx:id="progressIndicator" alignment="CENTER" focusTraversable="true">
<ProgressIndicator visible="false"/>
<ProgressIndicator visible="false" />
</VBox>
</StackPane>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ default_snapshot_name_date_format=
# - `FROM_ARCHIVER`: PV values read from archiver at point in time selected by user
default_snapshot_mode=READ_PVS

# Defines the default restore mode.
# Defines the wanted restore mode. If `SERVICE_RESTORE` is selected,
# runtime checks are done to ensure user is authorized to call server side restore.
#
# - `CLIENT_RESTORE`: the restore operation is performed by the client
# - `SERVICE_RESTORE`: the restore operation is performed by the server
Expand Down
Loading