Skip to content

updating Remote Console version compatibility check logic #110

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 5, 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
1 change: 1 addition & 0 deletions electron/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/node_modules
/app/web
/app/staged-themes
/app/webui.json
/wktui.log
/wktui-*.log
/.docker
Expand Down
29 changes: 20 additions & 9 deletions electron/app/js/wlRemoteConsoleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ const { getLogger } = require('./wktLogging');
const osUtils = require('./osUtils');
const { sendToWindow } = require('./windowUtils');
const { spawnDaemonChildProcess } = require('./childProcessExecutor');
const { wlRemoteConsoleFrontendVersion } = require('../webui.json');

// TODO - Change this to the correct version once the RC version changes to 2.3.0...
const MIN_VERSION = '2.2.0';
const MIN_VERSION_COMPONENTS = MIN_VERSION.split('.').map((item) => { return Number(item); });
let _wlRemoteConsoleChildProcess;


Expand Down Expand Up @@ -98,7 +96,7 @@ async function setWebLogicRemoteConsoleHomeAndStart(currentWindow, rcHome) {
startWebLogicRemoteConsoleBackend(currentWindow, true).then(() => resolve() );
} else {
const message = i18n.t('wrc-version-incompatible-message',
{ rcVersion: isCompatibleResult['version'], minVersion: MIN_VERSION });
{ backendVersion: isCompatibleResult['version'], frontendVersion: wlRemoteConsoleFrontendVersion });
dialog.showErrorBox(title, message);
return resolve();
}
Expand Down Expand Up @@ -167,7 +165,7 @@ async function _getWebLogicRemoteConsoleHome(skipVersionCheck = false) {
resolve(rcHome);
} else {
const message = i18n.t('wrc-version-incompatible-message',
{ rcVersion: isCompatibleResult['version'], minVersion: MIN_VERSION });
{ backendVersion: isCompatibleResult['version'], frontendVersion: wlRemoteConsoleFrontendVersion });
reject(new Error(message));
}
}).catch(err => reject(err));
Expand Down Expand Up @@ -344,6 +342,8 @@ async function _verifyVersionCompatibility(packageJsonFile, executablePath) {
if (packageJson.version) {
result['version'] = packageJson.version;
result['isCompatible'] = _verifyVersionNumberCompatibility(packageJson.version);
getLogger().debug('Remote Console Compatibility check found wrc-jet-pack %s and backend version %s to %s compatible.',
wlRemoteConsoleFrontendVersion, packageJson.version, result['isCompatible'] ? 'be' : 'not be');
resolve(result);
} else {
const message = i18n.t('wrc-package-json-missing-version', { packageJsonFile: packageJsonFile });
Expand Down Expand Up @@ -379,19 +379,30 @@ async function _verifyVersionCompatibility(packageJsonFile, executablePath) {
}
}

function _verifyVersionNumberCompatibility(actualVersion) {
const versionComponents = actualVersion.split('.').map((item) => { return Number(item); });
// The agreed contract with the WebLogic Remote Console team is that the
// frontend and backend version numbers <major>.<minor> versions must be the
// same. As such, we will ignore the patch level and any qualifiers.
//
function _verifyVersionNumberCompatibility(backendVersion) {
const frontendVersionComponents =
_stripVersionQualifiers(wlRemoteConsoleFrontendVersion).split('.').map((item) => { return Number(item); });
const backendVersionComponents =
_stripVersionQualifiers(backendVersion).split('.').map((item) => { return Number(item); });

let versionIsCompatible = true;
for (let i = 0; i < 3; i++) {
if (versionComponents[i] < MIN_VERSION_COMPONENTS[i]) {
for (let i = 0; i < 2; i++) {
if (backendVersionComponents[i] !== frontendVersionComponents[i]) {
versionIsCompatible = false;
break;
}
}
return versionIsCompatible;
}

function _stripVersionQualifiers(version) {
return version.split('-')[0];
}

async function _getLocationFromPreferencesFile() {
const autoPrefsLocation = path.join(app.getPath('appData'), 'weblogic-remote-console', 'auto-prefs.json');

Expand Down
2 changes: 1 addition & 1 deletion electron/app/locales/en/electron.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
"wrc-package-json-missing-version": "Unable to determine the WebLogic Remote Console version because the {{packageJsonFile}} file was missing the version element.",
"wrc-package-json-existence-check-failed": "Unable to determine the WebLogic Remote Console version because the existence check for {{packageJsonFile}} failed: {{error}}.",
"wrc-app-image-file-version-no-match": "Unable to determine the WebLogic Remote Console version because the location {{rcHome}} AppImage file name {{filename}} does not match the expected filename pattern needed to extract the version number.",
"wrc-version-incompatible-message": "The WebLogic Remote Console version {{rcVersion}} does not meet the minimum version requirement of {{minVersion}}.",
"wrc-version-incompatible-message": "The installed WebLogic Remote Console version {{backendVersion}} is not compatible with the WebLogic Kubernetes Toolkit UI embedded Model Design view component version {{frontendVersion}} because the major and minor versions do not match.",
"wrc-version-verification-failed": "Unable to start the WebLogic Remote Console backend because an error occurred while trying to determine the version compatibility: {{error}}",
"wrc-home-not-exist": "Unable to start the WebLogic Remote Console backend because the configured location {{rcHome}} does not exist."
}
50 changes: 50 additions & 0 deletions webui/scripts/hooks/after_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const path = require('path');
const purgeLocations = [
path.normalize(path.join(__dirname, '..', '..', 'web', 'test'))
];

const webuiJsonDirectory = path.normalize(path.join(__dirname, '..', '..', 'web'));
const webuiJsonFile = path.join(webuiJsonDirectory, 'webui.json');

const sourceDirectories = [
path.normalize(path.join(__dirname, '..', '..', 'web'))
// path.normalize(path.join(__dirname, '..', '..', 'staged-themes'))
Expand All @@ -31,6 +35,11 @@ module.exports = function (configObj) {
}
}

// Write the webui.json file that contains data
// that the electron side needs during startup.
//
const webuiJsonCreated = await generateWebuiJsonFile(webuiJsonDirectory);

if (configObj.buildType === 'release') {
console.log('Consolidating files for building the release');
for (const sourceDirectory of sourceDirectories) {
Expand All @@ -39,7 +48,14 @@ module.exports = function (configObj) {
await copyDirectoryRecursively(sourceDirectory, targetDirectory);
}
}
} else {
if (webuiJsonCreated) {
await copyFileToDirectory(webuiJsonFile, targetDirectory);
}
}



resolve(configObj);
});
};
Expand Down Expand Up @@ -85,3 +101,37 @@ async function isDirectory(path) {

return !result ? result: result.isDirectory();
}

async function generateWebuiJsonFile() {
const contents = {
// This default value should never be required once the npm dependency actually exists.
wlRemoteConsoleFrontendVersion: getRemoteConsoleFrontendVersion() || '2.3.0',
};

if (!fs.existsSync(targetDirectory)) {
await mkdir(targetDirectory);
}

return new Promise((resolve, reject) => {
fsPromises.writeFile(webuiJsonFile, JSON.stringify(contents, null, 2), {
encoding: 'utf8',
mode: 0o644
}).then(() => {
resolve(true)
}).catch(err => {
console.error(`Failed to write ${webuiJsonFile} file: ${err}`);
resolve(false);
});
});
}

function getRemoteConsoleFrontendVersion() {
let version;
try {
const packageLock = require('../../package-lock.json');
version = packageLock?.packages?.['node_modules/@oracle/wrc-jet-pack']?.version;
} catch {
// fall through to return undefined...
}
return version;
}