Skip to content

Commit 87c9c23

Browse files
Increasing the robustness of the Remote Console backend port handling (#117)
* making sure that all windows get the backend port notifications * switching new window handling strategy
1 parent 0e64b4e commit 87c9c23

File tree

4 files changed

+48
-14
lines changed

4 files changed

+48
-14
lines changed

electron/app/js/wlRemoteConsoleUtils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const path = require('path');
99
const readline = require('readline');
10-
const { app, dialog } = require('electron');
10+
const { app, BrowserWindow, dialog } = require('electron');
1111
const fsPromises = require('fs/promises');
1212

1313
const userSettings = require('./userSettings');
@@ -21,8 +21,13 @@ const { spawnDaemonChildProcess } = require('./childProcessExecutor');
2121
const { wlRemoteConsoleFrontendVersion } = require('../webui.json');
2222

2323
let _wlRemoteConsoleChildProcess;
24+
let _wlRemoteConsolePort;
2425

2526
/* global process */
27+
function getWebLogicRemoteConsoleBackendPort() {
28+
return _wlRemoteConsolePort;
29+
}
30+
2631
async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck = false) {
2732
if (_wlRemoteConsoleChildProcess) {
2833
return Promise.resolve();
@@ -45,6 +50,11 @@ async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck
4550
});
4651
_wlRemoteConsoleChildProcess.on('exit', (code) => {
4752
getLogger().info('WebLogic Remote Console backend process exited with code %s', code);
53+
_wlRemoteConsolePort = undefined;
54+
BrowserWindow.getAllWindows().forEach(win => {
55+
getLogger().debug('Sending new Remote Console backend port %s to Window ID %s', _wlRemoteConsolePort, win.id);
56+
sendToWindow(win, 'set-wrc-backend-port', _wlRemoteConsolePort);
57+
});
4858
});
4959

5060
const stdoutLines = readline.createInterface({ input: _wlRemoteConsoleChildProcess.stdout });
@@ -58,7 +68,11 @@ async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck
5868
const matcher = line.match(portRegex);
5969
if (matcher) {
6070
foundPort = true;
61-
sendToWindow(currentWindow, 'set-wrc-backend-port', matcher[1]);
71+
_wlRemoteConsolePort = matcher[1];
72+
BrowserWindow.getAllWindows().forEach(win => {
73+
getLogger().debug('Sending new Remote Console backend port %s to Window ID %s', _wlRemoteConsolePort, win.id);
74+
sendToWindow(win, 'set-wrc-backend-port', _wlRemoteConsolePort);
75+
});
6276
}
6377
}
6478
});
@@ -505,6 +519,7 @@ async function _getDefaultLocationForLinux() {
505519
module.exports = {
506520
getDefaultDirectoryForOpenDialog,
507521
getDefaultWebLogicRemoteConsoleHome,
522+
getWebLogicRemoteConsoleBackendPort,
508523
setWebLogicRemoteConsoleHomeAndStart,
509524
startWebLogicRemoteConsoleBackend
510525
};

electron/app/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const openSSLUtils = require('./js/openSSLUtils');
3535
const osUtils = require('./js/osUtils');
3636
const { initializeAutoUpdater, registerAutoUpdateListeners, installUpdates, getUpdateInformation } = require('./js/appUpdater');
3737
const { startWebLogicRemoteConsoleBackend, getDefaultDirectoryForOpenDialog, setWebLogicRemoteConsoleHomeAndStart,
38-
getDefaultWebLogicRemoteConsoleHome } = require('./js/wlRemoteConsoleUtils');
38+
getDefaultWebLogicRemoteConsoleHome, getWebLogicRemoteConsoleBackendPort
39+
} = require('./js/wlRemoteConsoleUtils');
3940

4041
const { getHttpsProxyUrl, getBypassProxyHosts } = require('./js/userSettings');
4142
const { sendToWindow } = require('./js/windowUtils');
@@ -225,10 +226,17 @@ class Main {
225226
}
226227

227228
sendToWindow(currentWindow, 'show-startup-dialogs', startupInformation);
229+
const port = getWebLogicRemoteConsoleBackendPort();
230+
this._logger.debug('Sending Remote Console backend port %s to Window ID %s', port, currentWindow.id);
231+
sendToWindow(currentWindow, 'set-wrc-backend-port', port);
228232
});
229233
}
230234

231235
this._startupDialogsShownAlready = true;
236+
} else {
237+
const port = getWebLogicRemoteConsoleBackendPort();
238+
this._logger.debug('Sending Remote Console backend port %s to Window ID %s', port, currentWindow.id);
239+
sendToWindow(currentWindow, 'set-wrc-backend-port', port);
232240
}
233241
});
234242
});

webui/src/js/viewModels/model-design-view.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
55
*/
66
define(['accUtils', 'utils/i18n', 'knockout', 'models/wkt-project', 'utils/url-catalog', 'utils/view-helper',
7-
'utils/wkt-logger', 'wrc-frontend/core/parsers/yaml', 'wrc-frontend/integration/viewModels/utils',
8-
'wdt-model-designer/loader', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojformlayout'],
9-
function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlParser, ViewModelUtils) {
7+
'utils/wkt-logger', 'js-yaml', 'wrc-frontend/integration/viewModels/utils', 'wdt-model-designer/loader',
8+
'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojformlayout'],
9+
function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, jsYaml, ViewModelUtils) {
1010
function ModelDesignViewModel() {
1111

1212
let subscriptions = [];
@@ -15,6 +15,7 @@ function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlPar
1515
this.designer = undefined;
1616
this.dataProvider = {};
1717
this.disableStartButton = ko.observable(false);
18+
this.wrcBackendTriggerChange = false;
1819

1920
this.connected = () => {
2021
accUtils.announce('Model design view loaded.', 'assertive');
@@ -29,7 +30,11 @@ function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlPar
2930
wktLogger.debug('Model Design View got event for Model contents changed');
3031

3132
if (this.designer) {
32-
this.createRemoteConsoleProvider(this.designer, true);
33+
if (this.wrcBackendTriggerChange) {
34+
this.wrcBackendTriggerChange = false;
35+
} else {
36+
this.createRemoteConsoleProvider(this.designer, true);
37+
}
3338
}
3439
}, this));
3540

@@ -134,44 +139,49 @@ function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlPar
134139
}
135140

136141
const providerOptions = this.getRemoteConsoleProviderOptions();
137-
// TODO - Do we need to use the Remote Console parser or can we just use js-yaml?
138-
//
139-
YamlParser.parse(providerOptions.fileContents).then(data => {
142+
try {
143+
const data = jsYaml.load(providerOptions.fileContents);
140144
wdtModelDesigner.createProvider(providerOptions.name, data);
141-
}).catch(err => {
145+
} catch (err) {
142146
ViewModelUtils.failureResponseDefaultHandling(err);
143-
});
147+
}
144148
};
145149

146150
// Triggered when WDT Model File provider has been activated with the WRC backend.
147151
//
148152
this.providerActivated = (event) => {
149153
this.dataProvider = event.detail.value;
154+
wktLogger.debug('Received providerActivated event with dataProvider = %s', JSON.stringify(this.dataProvider));
150155
this.designer.selectLastVisitedSlice();
151156
};
152157

153158
// Triggered when changes have been downloaded from the WRC backend, for the active WDT Model File provider.
154159
//
155160
this.changesAutoDownloaded = (event) => {
156-
wktLogger.debug('changesAutoDownloaded event: %s', event.detail.value);
161+
wktLogger.debug('Received changesAutoDownloaded event with modelContent = %s', event.detail.value);
162+
this.wrcBackendTriggerChange = true;
157163
this.project.wdtModel.modelContent(event.detail.value);
158164
};
159165

160166
// Triggered when WDT Model File provider has been deactivated with the WRC backend.
161167
//
162168
this.providerDeactivated = (event) => {
163169
const result = event.detail.value;
170+
wktLogger.debug('Received providerDeactivated event with dataProvider = %s', JSON.stringify(result));
164171
delete result.data;
165172
this.dataProvider = {state: 'disconnected'};
166173
};
167174

168175
// Triggered when WDT Model Designer has lost its connection to the WRC backend.
169176
//
170177
this.connectionLostRefused = (event) => {
171-
wktLogger.debug('connectionLostRefused: backendUrl=%s', event.detail.value);
178+
wktLogger.debug('Received connectionLostRefused event with backendUrl = %s', event.detail.value);
172179
if (this.designer) {
173180
this.designer.visible = false;
174181
}
182+
// Technically, this should not be needed since the electron side should be pushing this port
183+
// change to the window when the backend process exits, but it doesn't hurt anything.
184+
//
175185
this.project.wdtModel.internal.wlRemoteConsolePort(undefined);
176186
};
177187

webui/src/js/windowStateUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ function(wktProject, wktConsole, wdtDiscoverer, dialogHelper, projectIO,
256256
});
257257

258258
window.api.ipc.receive('set-wrc-backend-port', (port) => {
259+
wktLogger.debug('Received Remote Console backend port %s', port);
259260
wktProject.wdtModel.internal.wlRemoteConsolePort(port);
260261
});
261262

0 commit comments

Comments
 (0)