Skip to content

Commit 3cc8189

Browse files
authored
Merge pull request #2425 from ControlSystemStudio/CSSTUDIO-1771
Handle connection failure to logbook service
2 parents d122bd3 + 08d4296 commit 3cc8189

File tree

7 files changed

+233
-155
lines changed

7 files changed

+233
-155
lines changed

app/logbook/olog/client-es/src/main/java/org/phoebus/olog/es/api/OlogClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,10 @@ public void authenticate(String username, String password) throws Exception {
514514
throw e;
515515
}
516516
}
517+
518+
@Override
519+
public String serviceInfo(){
520+
ClientResponse clientResponse = service.path("").get(ClientResponse.class);
521+
return clientResponse.getEntity(String.class);
522+
}
517523
}

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class Messages
4343
SearchAvailableItems,
4444
SelectFile,
4545
SelectFolder,
46+
ServiceConnectionErrorTitle,
47+
ServiceConnectionErrorBody,
4648
ShowHideDetails,
4749
Tags,
4850
TagsTitle,

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/write/LogEntryEditorController.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.phoebus.logbook.olog.ui.HelpViewer;
5959
import org.phoebus.logbook.olog.ui.LogbookUIPreferences;
6060
import org.phoebus.logbook.olog.ui.PreviewViewer;
61+
import org.phoebus.logbook.olog.ui.menu.SendToLogBookApp;
6162
import org.phoebus.olog.es.api.OlogProperties;
6263
import org.phoebus.olog.es.api.model.OlogLog;
6364
import org.phoebus.security.store.SecureStore;
@@ -88,7 +89,9 @@ public class LogEntryEditorController {
8889
private final Logger logger = Logger.getLogger(LogEntryEditorController.class.getName());
8990

9091
@FXML
91-
private VBox root;
92+
private VBox editorPane;
93+
@FXML
94+
private VBox errorPane;
9295
@FXML
9396
private Button submitButton;
9497
@FXML
@@ -185,6 +188,7 @@ public class LogEntryEditorController {
185188
*/
186189
private String originalTitle = "";
187190

191+
188192
public LogEntryEditorController(LogEntry logEntry, LogEntry inReplyTo, LogEntryCompletionHandler logEntryCompletionHandler) {
189193
this.replyTo = inReplyTo;
190194
this.completionHandler = logEntryCompletionHandler;
@@ -205,17 +209,29 @@ public LogEntryEditorController(LogEntry logEntry, LogEntry inReplyTo, LogEntryC
205209
this.logEntry = logEntry;
206210
}
207211
}
208-
212+
209213
@FXML
210214
public void initialize() {
211-
completionMessageLabel.setText("");
215+
216+
// This could be configured in the fxml, but then these UI components would not be visible
217+
// in Scene Builder.
218+
completionMessageLabel.textProperty().set("");
219+
progressIndicator.visibleProperty().bind(submissionInProgress);
220+
221+
// Remote log service not reachable, so show error pane.
222+
if (!checkConnectivity()) {
223+
errorPane.visibleProperty().set(true);
224+
editorPane.disableProperty().set(true);
225+
return;
226+
}
227+
212228
submitButton.disableProperty().bind(Bindings.createBooleanBinding(() ->
213229
!inputValid.get() || submissionInProgress.get(),
214230
inputValid, submissionInProgress));
215231
completionMessageLabel.visibleProperty()
216232
.bind(Bindings.createBooleanBinding(() -> completionMessageLabel.textProperty().isNotEmpty().get() && !submissionInProgress.get(),
217233
completionMessageLabel.textProperty(), submissionInProgress));
218-
progressIndicator.visibleProperty().bind(submissionInProgress);
234+
219235
cancelButton.disableProperty().bind(submissionInProgress);
220236
attachmentsEditorController.setTextArea(textArea);
221237

@@ -390,7 +406,7 @@ public void initialize() {
390406
public void cancel() {
391407
// Need to clear selections.
392408
SelectionService.getInstance().clearSelection("");
393-
((LogEntryEditorStage) cancelButton.getScene().getWindow()).handleCloseEditor(isDirty, root);
409+
((LogEntryEditorStage) cancelButton.getScene().getWindow()).handleCloseEditor(isDirty, editorPane);
394410
}
395411

396412
@FXML
@@ -676,4 +692,20 @@ private void updateDropDown(ContextMenu contextMenu, String itemName, boolean it
676692
public boolean isDirty() {
677693
return isDirty;
678694
}
695+
696+
/**
697+
* Checks connectivity to remote service by querying the info end-point. If connection fails,
698+
* connectionError property is set to <code>true</code>, which should set opacity of the editor pane, and
699+
* set visibility of error pane.
700+
*/
701+
private boolean checkConnectivity() {
702+
LogClient logClient = LogService.getInstance().getLogFactories().get(LogbookPreferences.logbook_factory).getLogClient();
703+
try {
704+
logClient.serviceInfo();
705+
return true;
706+
} catch (Exception e) {
707+
Logger.getLogger(SendToLogBookApp.class.getName()).warning("Failed to query logbook service, it may be off-line.");
708+
return false;
709+
}
710+
}
679711
}

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/LogEntryTableView.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</Button>
3838
<ComboBox fx:id="query" editable="true" maxWidth="1.7976931348623157E308" GridPane.columnIndex="2" GridPane.hgrow="ALWAYS" GridPane.vgrow="NEVER">
3939
<tooltip>
40-
<Tooltip text="%SearchToolTip"/>
40+
<Tooltip text="%SearchToolTip" />
4141
</tooltip>
4242
<GridPane.margin>
4343
<Insets bottom="10.0" top="10.0" />

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ BrowseButton=Browse
99
Cancel=Cancel
1010
CancelTooltip=Cancel the current entry.
1111
Clear=Clear
12+
Close=Close
1213
Clear_Tooltip=Clear the selected items list.
1314
ClipboardButton=Clipboard
1415
ClipboardButtonTooltip=Add files or image data from clipboard
@@ -74,6 +75,7 @@ SelectFolder=Select Folder
7475
SelectFile=Select Image File
7576
SelectLevelTooltip=Select the log entry level.
7677
SelectLogEntry=Select Log Entry
78+
ServiceConnectionError=Unable to connect to the logbook service
7779
ShowHelp=Show Help
7880
ShowHideDetails=Show/Hide Details
7981
SortAscending=Sort ascending on date

0 commit comments

Comments
 (0)