Skip to content

Commit b15b28e

Browse files
adding wdt version checking for validate and prepare model actions (#76)
1 parent 3fa9d20 commit b15b28e

File tree

8 files changed

+120
-17
lines changed

8 files changed

+120
-17
lines changed

electron/app/js/wdtPrepareModel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const i18n = require('./i18next.config');
1313
const childProcessExecutor = require('./childProcessExecutor');
1414
const fsUtils = require('./fsUtils');
1515
const { getLogger } = require('./wktLogging');
16-
const { getPrepareModelShellScript, getWdtCustomConfigDirectory, isWdtErrorExitCode } = require('./wktTools');
16+
const { getPrepareModelShellScript, getWdtCustomConfigDirectory, isWdtErrorExitCode, isWdtVersionCompatible} = require('./wktTools');
1717
const { getModelFileContent } = require('./project');
1818
const errorUtils = require('./errorUtils');
1919

20+
const MINIMUM_WDT_PREPARE_VERSION = '2.0.0';
21+
2022
const _secretsFileName = 'k8s_secrets.json';
2123
const _wkoDomainSpecFileName = 'wko-domain.yaml';
2224
const _vzApplicationSpecFileName = 'vz-application.yaml';
@@ -56,6 +58,11 @@ async function prepareModel(currentWindow, stdoutChannel, stderrChannel, prepare
5658
isSuccess: true
5759
};
5860
try {
61+
const versionCheckResult = await isWdtVersionCompatible(MINIMUM_WDT_PREPARE_VERSION);
62+
if (!versionCheckResult.isSuccess) {
63+
return Promise.resolve(versionCheckResult);
64+
}
65+
5966
const exitCode = await childProcessExecutor.executeChildShellScript(currentWindow, getPrepareModelShellScript(),
6067
argList, env, stdoutChannel, { stderrEventName: stderrChannel });
6168

electron/app/js/wdtValidateModel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
const fsUtils = require('./fsUtils');
99
const { getLogger } = require('./wktLogging');
10-
const { getWdtCustomConfigDirectory, getValidateModelShellScript, isWdtErrorExitCode} = require('./wktTools');
10+
const { getWdtCustomConfigDirectory, getValidateModelShellScript, isWdtErrorExitCode, isWdtVersionCompatible} = require('./wktTools');
1111
const childProcessExecutor = require('./childProcessExecutor');
1212
const { getErrorMessage } = require('./errorUtils');
1313

1414
const i18n = require('./i18next.config');
1515

16+
const MINIMUM_WDT_VALIDATE_VERSION = '2.0.0';
17+
1618
async function validateModel(currentWindow, stdoutChannel, stderrChannel, validateConfig) {
1719
const logger = getLogger();
1820
const { javaHome, oracleHome, projectDirectory, modelFiles, variableFiles, archiveFiles } = validateConfig;
@@ -48,6 +50,11 @@ async function validateModel(currentWindow, stdoutChannel, stderrChannel, valida
4850
isSuccess: true
4951
};
5052
try {
53+
const versionCheckResult = await isWdtVersionCompatible(MINIMUM_WDT_VALIDATE_VERSION);
54+
if (!versionCheckResult.isSuccess) {
55+
return Promise.resolve(versionCheckResult);
56+
}
57+
5158
const exitCode = await childProcessExecutor.executeChildShellScript(currentWindow, getValidateModelShellScript(),
5259
argList, env, stdoutChannel, { stderrEventName: stderrChannel });
5360

electron/app/js/wktTools.js

Lines changed: 94 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66
const { dialog } = require('electron');
77
const path = require('path');
88
const fsPromises = require('fs/promises');
9+
10+
const fsUtils = require('./fsUtils');
911
const i18n = require('./i18next.config');
1012
const osUtils = require('./osUtils');
11-
12-
/* global __dirname */
13-
const jsDir = __dirname;
14-
15-
const fsUtils = require(path.join(jsDir, 'fsUtils'));
16-
const {
17-
downloadWdtRelease,
18-
getWdtLatestReleaseName,
19-
getWitLatestReleaseName,
20-
getWkoLatestReleaseImageName,
21-
updateTools
22-
} = require(path.join(jsDir, 'wktToolsInstaller'));
23-
const { getLogger } = require(path.join(jsDir, 'wktLogging'));
13+
const WktApp = require('./wktApp');
14+
const { getLogger } = require('./wktLogging');
15+
const { getErrorMessage } = require('./errorUtils');
16+
const { downloadWdtRelease, getWdtLatestReleaseName, getWitLatestReleaseName, getWkoLatestReleaseImageName,
17+
updateTools } = require('./wktToolsInstaller');
2418

2519
const scriptExtension = osUtils.isWindows() ? '.cmd' : '.sh';
2620
const VERSION_FILE_NAME = 'VERSION.txt';
@@ -64,6 +58,45 @@ function isWitErrorExitCode(exitCode) {
6458
return exitCode !== 0;
6559
}
6660

61+
async function isWdtVersionCompatible(minimumVersion) {
62+
const wdtVersionFileName = path.join(getWdtDirectory(), 'VERSION.txt');
63+
const versionRegex = /^WebLogic Deploy Tooling (?<version>[\d]+.[\d]+.[\d]+(-SNAPSHOT)?)$/;
64+
const result = {
65+
isSuccess: true
66+
};
67+
68+
return new Promise(resolve => {
69+
fsUtils.exists(wdtVersionFileName).then(doesExist => {
70+
if (!doesExist) {
71+
result.isSuccess = false;
72+
result.reason = i18n.t('wkt-tools-wdt-version-file-missing-error', { file: wdtVersionFileName });
73+
return resolve(result);
74+
}
75+
fsPromises.readFile(wdtVersionFileName, {encoding: 'utf8'}).then(contents => {
76+
const matches = contents.trim().match(versionRegex);
77+
const version = matches.groups.version;
78+
if (!version) {
79+
result.isSuccess = false;
80+
result.reason = i18n.t('wkt-tools-wdt-version-file-format-error', { file: wdtVersionFileName });
81+
return resolve(result);
82+
}
83+
84+
if (compareVersions(version, minimumVersion) < 0) {
85+
const wktApp = new WktApp(_wktMode);
86+
result.isSuccess = false;
87+
result.reason = i18n.t('wkt-tools-wdt-version-not-compatible-error',
88+
{ version: version, minimumVersion: minimumVersion, wktuiVersion: wktApp.getApplicationVersion() });
89+
}
90+
resolve(result);
91+
}).catch(err => {
92+
result.isSuccess = false;
93+
result.reason = i18n.t('wkt-tools-wdt-version-file-read-error', { file: wdtVersionFileName, error: getErrorMessage(err) });
94+
return resolve(result);
95+
});
96+
});
97+
});
98+
}
99+
67100
async function getWdtSupportedDomainTypes() {
68101
const typedefsDirectory = path.join(getWdtDirectory(), 'lib', 'typedefs');
69102
return new Promise((resolve, reject) => {
@@ -256,6 +289,52 @@ async function getOptions() {
256289
});
257290
}
258291

292+
function compareVersions(version, minimumVersion) {
293+
const versionComponents = version.split(/[.-]/);
294+
const minimumVersionComponents = minimumVersion.split(/[.-]/);
295+
296+
// Fix up the minimum version components to have the correct number of places...
297+
if (minimumVersionComponents.length !== 4) {
298+
const len = minimumVersionComponents.length;
299+
const isSnapshot = minimumVersionComponents[len - 1] === 'SNAPSHOT';
300+
if (len !== 3 || isSnapshot) {
301+
const missingDigits = isSnapshot ? 4 - len : 3 - len;
302+
const insertPosition = isSnapshot ? len - 2 : len - 1;
303+
for (let i = 0; i < missingDigits; i++) {
304+
minimumVersionComponents.splice(insertPosition, 0, '0');
305+
}
306+
}
307+
}
308+
309+
// Iterate over the version elements now that the minimum version elements is fully specified...
310+
let result = 0;
311+
for (let i = 0; i < 3; i++) {
312+
const versionNumber = Number(versionComponents[i]);
313+
const minVersionNumber = Number(minimumVersionComponents[i]);
314+
315+
if (versionNumber < minVersionNumber) {
316+
result = -1;
317+
break;
318+
} else if (versionNumber > minVersionNumber) {
319+
result = 1;
320+
break;
321+
}
322+
}
323+
324+
if (result === 0) {
325+
const versionIsSnapshot = versionComponents.length === 4;
326+
const minimumVersionIsSnapshot = minimumVersionComponents.length === 4;
327+
if (versionIsSnapshot && !minimumVersionIsSnapshot) {
328+
result = -1;
329+
} else if (!versionIsSnapshot && minimumVersionIsSnapshot) {
330+
result = 1;
331+
}
332+
}
333+
334+
getLogger().debug('compareVersion(%s, %s) returned %d', version, minimumVersion, result);
335+
return result;
336+
}
337+
259338
module.exports = {
260339
checkForUpdates,
261340
downloadLatestWdtInstaller,
@@ -271,5 +350,6 @@ module.exports = {
271350
getWdtSupportedDomainTypes,
272351
initialize,
273352
isWdtErrorExitCode,
274-
isWitErrorExitCode
353+
isWitErrorExitCode,
354+
isWdtVersionCompatible
275355
};

electron/app/locales/en/electron.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
"wdt-discovery-non-zero-exit-code-error-message": "Discover domain script {{script}} exited with non-zero exit code: {{exitCode}}.",
209209
"wdt-discovery-failed-error-message": "Discover domain script {{script}} failed: {{error}};",
210210

211-
"validate-model-error-exit-code-error-message": "Validate Model script exited with {{exitCode}}, which indicates an error.",
211+
"validate-model-error-exit-code-error-message": "Validate Model script exited with {{exitCode}}, which indicates an error",
212212
"validate-model-execution-failed-error-message": "Validate Model script failed: {{error}}",
213213

214214
"prepare-model-unknown-target-type-error-message": "Unable to prepare model with unknown target type: {{wdtTargetType}}.",
@@ -351,6 +351,11 @@
351351
"wdt-archiveType-sharedLibraryDir": "Shared Library Directory",
352352
"wdt-archiveType-fileStore": "File Store Directory",
353353

354+
"wkt-tools-wdt-version-file-missing-error": "Unable to determine the version of WebLogic Deploy Tooling installed because the {{file}} file is not found",
355+
"wkt-tools-wdt-version-file-read-error": "Unable to determine the version of WebLogic Deploy Tooling installed because an error occurred while reading the {{file}} file: {{error}}",
356+
"wkt-tools-wdt-version-file-format-error": "Unable to determine the version of WebLogic Deploy Tooling installed because the {{file}} file is not in the expected format",
357+
"wkt-tools-wdt-version-not-compatible-error": "The installed WebLogic Deploy Tooling version {{version}} does not meet the minimum compatible version {{minimumVersion}} required by WebLogic Kubernetes Toolkit UI version {{wktuiVersion}}",
358+
354359
"project-save-file-already-open-title": "Project File Already Open",
355360
"project-save-file-already-open-message": "The project file {{projectFile}} is already open in another window. Please either close the existing window or select a different project file and try again."
356361
}

tools/wdt-config/dii/targets/vz/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
99
"validation_method" : "lax",
1010
"credentials_output_method" : "script",
11+
"exclude_domain_bin_contents": true,
1112
"wls_credentials_name" : "__weblogic-credentials__",
1213
"additional_secrets": "runtime-encryption-secret",
1314
"additional_output" : "vz-application.yaml"

tools/wdt-config/dii/targets/wko/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
99
"validation_method" : "wktui",
1010
"credentials_output_method" : "json",
11+
"exclude_domain_bin_contents": true,
1112
"wls_credentials_name" : "__weblogic-credentials__",
1213
"additional_secrets": "runtime-encryption-secret",
1314
"additional_output" : "wko-domain.yaml"

tools/wdt-config/mii/targets/vz/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"validation_method" : "wktui",
1010
"credentials_method" : "secrets",
1111
"credentials_output_method" : "script",
12+
"exclude_domain_bin_contents": true,
1213
"wls_credentials_name" : "__weblogic-credentials__",
1314
"additional_secrets": "runtime-encryption-secret",
1415
"additional_output" : "vz-application.yaml"

tools/wdt-config/mii/targets/wko/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"validation_method" : "wktui",
1010
"credentials_method" : "secrets",
1111
"credentials_output_method" : "json",
12+
"exclude_domain_bin_contents": true,
1213
"wls_credentials_name" : "__weblogic-credentials__",
1314
"additional_secrets": "runtime-encryption-secret",
1415
"additional_output" : "wko-domain.yaml"

0 commit comments

Comments
 (0)