Skip to content

Increasing the robustness of the Remote Console backend port handling #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2022
Merged
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
19 changes: 17 additions & 2 deletions electron/app/js/wlRemoteConsoleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

const path = require('path');
const readline = require('readline');
const { app, dialog } = require('electron');
const { app, BrowserWindow, dialog } = require('electron');
const fsPromises = require('fs/promises');

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

let _wlRemoteConsoleChildProcess;
let _wlRemoteConsolePort;

/* global process */
function getWebLogicRemoteConsoleBackendPort() {
return _wlRemoteConsolePort;
}

async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck = false) {
if (_wlRemoteConsoleChildProcess) {
return Promise.resolve();
Expand All @@ -45,6 +50,11 @@ async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck
});
_wlRemoteConsoleChildProcess.on('exit', (code) => {
getLogger().info('WebLogic Remote Console backend process exited with code %s', code);
_wlRemoteConsolePort = undefined;
BrowserWindow.getAllWindows().forEach(win => {
getLogger().debug('Sending new Remote Console backend port %s to Window ID %s', _wlRemoteConsolePort, win.id);
sendToWindow(win, 'set-wrc-backend-port', _wlRemoteConsolePort);
});
});

const stdoutLines = readline.createInterface({ input: _wlRemoteConsoleChildProcess.stdout });
Expand All @@ -58,7 +68,11 @@ async function startWebLogicRemoteConsoleBackend(currentWindow, skipVersionCheck
const matcher = line.match(portRegex);
if (matcher) {
foundPort = true;
sendToWindow(currentWindow, 'set-wrc-backend-port', matcher[1]);
_wlRemoteConsolePort = matcher[1];
BrowserWindow.getAllWindows().forEach(win => {
getLogger().debug('Sending new Remote Console backend port %s to Window ID %s', _wlRemoteConsolePort, win.id);
sendToWindow(win, 'set-wrc-backend-port', _wlRemoteConsolePort);
});
}
}
});
Expand Down Expand Up @@ -505,6 +519,7 @@ async function _getDefaultLocationForLinux() {
module.exports = {
getDefaultDirectoryForOpenDialog,
getDefaultWebLogicRemoteConsoleHome,
getWebLogicRemoteConsoleBackendPort,
setWebLogicRemoteConsoleHomeAndStart,
startWebLogicRemoteConsoleBackend
};
10 changes: 9 additions & 1 deletion electron/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const openSSLUtils = require('./js/openSSLUtils');
const osUtils = require('./js/osUtils');
const { initializeAutoUpdater, registerAutoUpdateListeners, installUpdates, getUpdateInformation } = require('./js/appUpdater');
const { startWebLogicRemoteConsoleBackend, getDefaultDirectoryForOpenDialog, setWebLogicRemoteConsoleHomeAndStart,
getDefaultWebLogicRemoteConsoleHome } = require('./js/wlRemoteConsoleUtils');
getDefaultWebLogicRemoteConsoleHome, getWebLogicRemoteConsoleBackendPort
} = require('./js/wlRemoteConsoleUtils');

const { getHttpsProxyUrl, getBypassProxyHosts } = require('./js/userSettings');
const { sendToWindow } = require('./js/windowUtils');
Expand Down Expand Up @@ -225,10 +226,17 @@ class Main {
}

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

this._startupDialogsShownAlready = true;
} else {
const port = getWebLogicRemoteConsoleBackendPort();
this._logger.debug('Sending Remote Console backend port %s to Window ID %s', port, currentWindow.id);
sendToWindow(currentWindow, 'set-wrc-backend-port', port);
}
});
});
Expand Down
32 changes: 21 additions & 11 deletions webui/src/js/viewModels/model-design-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Licensed under The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/
define(['accUtils', 'utils/i18n', 'knockout', 'models/wkt-project', 'utils/url-catalog', 'utils/view-helper',
'utils/wkt-logger', 'wrc-frontend/core/parsers/yaml', 'wrc-frontend/integration/viewModels/utils',
'wdt-model-designer/loader', 'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojformlayout'],
function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlParser, ViewModelUtils) {
'utils/wkt-logger', 'js-yaml', 'wrc-frontend/integration/viewModels/utils', 'wdt-model-designer/loader',
'ojs/ojinputtext', 'ojs/ojlabel', 'ojs/ojbutton', 'ojs/ojformlayout'],
function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, jsYaml, ViewModelUtils) {
function ModelDesignViewModel() {

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

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

if (this.designer) {
this.createRemoteConsoleProvider(this.designer, true);
if (this.wrcBackendTriggerChange) {
this.wrcBackendTriggerChange = false;
} else {
this.createRemoteConsoleProvider(this.designer, true);
}
}
}, this));

Expand Down Expand Up @@ -134,44 +139,49 @@ function(accUtils, i18n, ko, project, urlCatalog, viewHelper, wktLogger, YamlPar
}

const providerOptions = this.getRemoteConsoleProviderOptions();
// TODO - Do we need to use the Remote Console parser or can we just use js-yaml?
//
YamlParser.parse(providerOptions.fileContents).then(data => {
try {
const data = jsYaml.load(providerOptions.fileContents);
wdtModelDesigner.createProvider(providerOptions.name, data);
}).catch(err => {
} catch (err) {
ViewModelUtils.failureResponseDefaultHandling(err);
});
}
};

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

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

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

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

Expand Down
1 change: 1 addition & 0 deletions webui/src/js/windowStateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ function(wktProject, wktConsole, wdtDiscoverer, dialogHelper, projectIO,
});

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

Expand Down