Skip to content

Commit f85f352

Browse files
committed
adding validate model files action for use with WDT 2.0 validateModel
1 parent 7666265 commit f85f352

File tree

20 files changed

+389
-96
lines changed

20 files changed

+389
-96
lines changed

electron/app/js/fsUtils.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
const fsPromises = require('fs/promises');
@@ -164,6 +164,20 @@ function getAbsolutePath(pathToCheck, baseDirectory) {
164164
return path.normalize(path.join(baseDirectory, pathToCheck));
165165
}
166166

167+
function getAbsolutePathsList(pathsToCheckList, baseDirectory) {
168+
const resultArray = [];
169+
if (pathsToCheckList) {
170+
for (const file of pathsToCheckList) {
171+
if (path.isAbsolute(file)) {
172+
resultArray.push(file);
173+
} else {
174+
resultArray.push(path.join(baseDirectory, file));
175+
}
176+
}
177+
}
178+
return resultArray;
179+
}
180+
167181
// returns the relative path for childPath, only if it is below parentPath.
168182
// returns null for any other case.
169183
function getRelativePath(parentPath, childPath) {
@@ -300,6 +314,7 @@ async function _processDirectoryListing(directory, listing, fileList) {
300314
module.exports = {
301315
exists,
302316
getAbsolutePath,
317+
getAbsolutePathsList,
303318
getRelativePath,
304319
getExecutableFilePath,
305320
getFilesRecursivelyFromDirectory,

electron/app/js/ipcRendererPreload.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
const { contextBridge, ipcRenderer } = require('electron');
@@ -64,6 +64,7 @@ contextBridge.exposeInMainWorld(
6464
'app-update-available',
6565
'blur-focused-item',
6666
'start-prepare-model',
67+
'start-validate-model',
6768
'start-create-image',
6869
'start-create-aux-image',
6970
'start-push-image',
@@ -141,6 +142,7 @@ contextBridge.exposeInMainWorld(
141142
'show-error-message',
142143
'show-info-message',
143144
'prepare-model',
145+
'validate-model',
144146
'verify-files-exist',
145147
'verify-file-exists',
146148
'ok-or-cancel-prompt',

electron/app/js/wdtPrepareModel.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
'use strict';
@@ -30,7 +30,7 @@ async function prepareModel(currentWindow, stdoutChannel, stderrChannel, prepare
3030
const logger = getLogger();
3131
const { javaHome, oracleHome, projectDirectory, modelsSubdirectory, modelFiles, variableFiles, wdtTargetType } = prepareConfig;
3232
const outputDirectory = await fsUtils.createTemporaryDirectory(projectDirectory, 'prepareModel');
33-
const absoluteModelFiles = getAbsolutePathFileList(projectDirectory, modelFiles);
33+
const absoluteModelFiles = fsUtils.getAbsolutePathsList(modelFiles, projectDirectory);
3434

3535
const argList = [
3636
'-oracle_home', oracleHome,
@@ -39,7 +39,7 @@ async function prepareModel(currentWindow, stdoutChannel, stderrChannel, prepare
3939
'-target', wdtTargetType
4040
];
4141

42-
const absoluteVariableFiles = getAbsolutePathFileList(projectDirectory, variableFiles);
42+
const absoluteVariableFiles = fsUtils.getAbsolutePathsList(variableFiles, projectDirectory);
4343
if (absoluteVariableFiles.length > 0) {
4444
argList.push('-variable_file', absoluteVariableFiles.join(','));
4545
}
@@ -188,20 +188,6 @@ async function removeTempDirectory(outputDirectory) {
188188
});
189189
}
190190

191-
function getAbsolutePathFileList(projectDirectory, fileList) {
192-
const resultArray = [];
193-
if (fileList) {
194-
for (const file of fileList) {
195-
if (path.isAbsolute(file)) {
196-
resultArray.push(file);
197-
} else {
198-
resultArray.push(path.join(projectDirectory, file));
199-
}
200-
}
201-
}
202-
return resultArray;
203-
}
204-
205191
async function moveModelFiles(projectDirectory, modelsSubdirectory, outputDirectory, modelFiles) {
206192
const updatedFileMap = new Map();
207193
for (const modelFile of modelFiles) {

electron/app/js/wdtValidateModel.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2022, Oracle and/or its affiliates.
4+
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
5+
*/
6+
'use strict';
7+
8+
const fsUtils = require('./fsUtils');
9+
const { getLogger } = require('./wktLogging');
10+
const { getWdtCustomConfigDirectory, getValidateModelShellScript, isWdtErrorExitCode} = require('./wktTools');
11+
const childProcessExecutor = require('./childProcessExecutor');
12+
const { getErrorMessage } = require('./errorUtils');
13+
14+
const i18n = require('./i18next.config');
15+
16+
async function validateModel(currentWindow, stdoutChannel, stderrChannel, validateConfig) {
17+
const logger = getLogger();
18+
const { javaHome, oracleHome, projectDirectory, modelFiles, variableFiles, archiveFiles } = validateConfig;
19+
20+
const argList = [
21+
'-oracle_home', oracleHome,
22+
'-target_mode', 'offline',
23+
'-method', 'wktui'
24+
];
25+
26+
const absoluteModelFiles = fsUtils.getAbsolutePathsList(modelFiles, projectDirectory);
27+
if (absoluteModelFiles.length > 0) {
28+
argList.push('-model_file', absoluteModelFiles.join(','));
29+
}
30+
31+
const absoluteVariableFiles = fsUtils.getAbsolutePathsList(variableFiles, projectDirectory);
32+
if (absoluteVariableFiles.length > 0) {
33+
argList.push('-variable_file', absoluteVariableFiles.join(','));
34+
}
35+
36+
const absoluteArchiveFiles = fsUtils.getAbsolutePathsList(archiveFiles, projectDirectory);
37+
if (absoluteArchiveFiles.length > 0) {
38+
argList.push('-archive_file', absoluteArchiveFiles.join(','));
39+
}
40+
41+
const env = {
42+
JAVA_HOME: javaHome,
43+
WDT_CUSTOM_CONFIG: getWdtCustomConfigDirectory(validateConfig)
44+
};
45+
getLogger().debug(`Invoking ${getValidateModelShellScript()} with args ${JSON.stringify(argList)} and environment ${JSON.stringify(env)}`);
46+
47+
const results = {
48+
isSuccess: true
49+
};
50+
try {
51+
const exitCode = await childProcessExecutor.executeChildShellScript(currentWindow, getValidateModelShellScript(),
52+
argList, env, stdoutChannel, { stderrEventName: stderrChannel });
53+
54+
if (isWdtErrorExitCode(exitCode)) {
55+
results.isSuccess = false;
56+
results.reason = i18n.t('validate-model-error-exit-code-error-message', { exitCode: exitCode });
57+
logger.error(results.reason);
58+
return Promise.resolve(results);
59+
}
60+
} catch (err) {
61+
results.isSuccess = false;
62+
results.reason = i18n.t('validate-model-execution-failed-error-message', { error: getErrorMessage(err) });
63+
results.error = err;
64+
logger.error(results.reason);
65+
return Promise.resolve(results);
66+
}
67+
return Promise.resolve(results);
68+
}
69+
70+
module.exports = {
71+
validateModel
72+
};

electron/app/js/wktTools.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright (c) 2021, Oracle and/or its affiliates.
3+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
66
const { dialog } = require('electron');
@@ -47,8 +47,12 @@ function getPrepareModelShellScript() {
4747
return path.join(getWdtDirectory(), 'bin', 'prepareModel' + scriptExtension);
4848
}
4949

50-
function getWdtCustomConfigDirectory(prepareConfig) {
51-
const targetDomainLocation = prepareConfig.targetDomainLocation || 'mii';
50+
function getValidateModelShellScript() {
51+
return path.join(getWdtDirectory(), 'bin', 'validateModel' + scriptExtension);
52+
}
53+
54+
function getWdtCustomConfigDirectory(config) {
55+
const targetDomainLocation = config.targetDomainLocation || 'mii';
5256
return path.join(getToolsDirectory(), 'wdt-config', targetDomainLocation);
5357
}
5458

@@ -262,6 +266,7 @@ module.exports = {
262266
getInstalledWdtReleaseName,
263267
getInstalledWitReleaseName,
264268
getLatestWkoImageName,
269+
getValidateModelShellScript,
265270
getWdtCustomConfigDirectory,
266271
getWdtSupportedDomainTypes,
267272
initialize,

electron/app/js/wktWindow.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,23 @@ class WktAppMenu {
227227
id: 'go',
228228
label: `&${i18n.t('menu-go')}`,
229229
submenu: [
230+
{
231+
id: 'validateModel',
232+
label: i18n.t('menu-go-validate-model'),
233+
enabled: !this._hasOpenDialog,
234+
click(item, focusedWindow) {
235+
if (!focusedWindow) {
236+
return dialog.showErrorBox(
237+
i18n.t('menu-go-validate-model-error-title'),
238+
i18n.t('menu-go-validate-model-error-message')
239+
);
240+
}
241+
sendToWindow(focusedWindow,'start-validate-model');
242+
}
243+
},
230244
{
231245
id: 'prepareModel',
232-
label: i18n.t('menu-go-prep-model-for-k8s'),
246+
label: i18n.t('menu-go-prepare-model-for-k8s'),
233247
enabled: !this._hasOpenDialog,
234248
click(item, focusedWindow) {
235249
if (!focusedWindow) {

electron/app/locales/en/electron.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
"menu-edit-selectAll": "Select All",
2828

2929
"menu-go": "Go",
30-
"menu-go-prep-model-for-k8s": "Prepare Model for Kubernetes",
30+
"menu-go-validate-model": "Validate Model Files",
31+
"menu-go-validate-model-error-title": "No Active Project Window",
32+
"menu-go-validate-model-error-message": "Cannot run Validate Model since there is no active window, and therefore no project with a model to validate.",
33+
"menu-go-prepare-model-for-k8s": "Prepare Model for Kubernetes",
3134
"menu-go-prepare-model-error-title": "No Active Project Window",
3235
"menu-go-prepare-model-error-message": "Cannot run Prepare Model since there is no active window, and therefore no project with a model to prepare.",
3336
"menu-go-create-image": "Create Primary Image",
@@ -205,6 +208,9 @@
205208
"wdt-discovery-non-zero-exit-code-error-message": "Discover domain script {{script}} exited with non-zero exit code: {{exitCode}}.",
206209
"wdt-discovery-failed-error-message": "Discover domain script {{script}} failed: {{error}};",
207210

211+
"validate-model-error-exit-code-error-message": "Validate Model script exited with {{exitCode}}, which indicates an error.",
212+
"validate-model-execution-failed-error-message": "Validate Model script failed: {{error}}",
213+
208214
"prepare-model-unknown-target-type-error-message": "Unable to prepare model with unknown target type: {{wdtTargetType}}.",
209215
"prepare-model-empty-target-type-error-message": "Unable to prepare model with an unspecified target type.",
210216
"prepare-model-invalid-java-home-error-message": "Unable to prepare model with invalid Java Home directory: {{javaHome}}.",

electron/app/locales/en/webui.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,22 @@
799799
"wdt-discoverer-offline-discovery-failed-error-prefix": "Unable to discover domain {{domainHome}} in offline mode",
800800
"wdt-discoverer-online-discovery-failed-error-prefix": "Unable to discover domain {{adminUrl}} in online mode",
801801

802+
"wdt-validator-aborted-error-title": "Validate Model Aborted",
803+
"wdt-validator-domain-in-pv-message": "Validate Model has no meaning when the target domain location is an externally created Kubernetes persistent volume.",
804+
"wdt-validator-invalid-java-home-error-prefix": "Unable to validate model due to the Java Home being invalid",
805+
"wdt-validator-invalid-oracle-home-error-prefix": "Unable to validate model due to the Oracle Home being invalid",
806+
"wdt-validator-project-not-saved-error-prefix": "Unable to validate model because project save failed",
807+
"wdt-validator-no-model-to-use-message": "The project file {{projectFile}} has no model to validate.",
808+
"wdt-validator-invalid-model-file-message": "The project file {{projectFile}} has references to one or more model files that do not exist: {{invalidFileList}}",
809+
"wdt-validator-invalid-variable-file-message": "The project file {{projectFile}} has references to one or more model variable files that do not exist: {{invalidFileList}}",
810+
"wdt-validator-invalid-archive-file-message": "The project file {{projectFile}} has references to one or more model archive files that do not exist: {{invalidFileList}}",
811+
"wdt-validator-validate-in-progress": "Validating Model",
812+
"wdt-validator-validate-failed-error-title": "Validate Model Failed",
813+
"wdt-validator-validate-failed-error-message": "Validate Model failed: {{error}}. See Console window output for more information.",
814+
"wdt-validator-validate-catch-all-error-message": "Validate Model failed with an unexpected error: {{error}}",
815+
"wdt-validator-validate-complete-title": "Validate Model Complete",
816+
"wdt-validator-validate-complete-message": "Validate Model successfully prepared the model.",
817+
802818
"wdt-preparer-aborted-error-title": "Prepare Model Aborted",
803819
"wdt-preparer-domain-in-pv-message": "Prepare Model has no meaning when the target domain location is an externally created Kubernetes persistent volume.",
804820
"wdt-preparer-invalid-java-home-error-prefix": "Unable to prepare model due to the Java Home being invalid",
@@ -943,6 +959,8 @@
943959
"aux-image-pusher-create-failed-title":"Push Image Failed",
944960
"aux-image-pusher-create-failed-error-message":"Unable to push image {{imageTag}}: {{error}}.",
945961

962+
"model-page-button-validateModel": "Validate Model",
963+
"model-page-hints-validateModel": "Validate Model Files",
946964
"model-page-button-prepareModel": "Prepare Model",
947965
"model-page-hints-prepareModel": "Prepare Model for Kubernetes",
948966
"model-page-model-editor-contents": "Model Editor Contents",
@@ -1118,6 +1136,7 @@
11181136
"flow-online-discover-model-name": "Discover Model Online",
11191137
"flow-offline-discover-model-name": "Discover Model Offline",
11201138
"flow-discover-domain-in-progress": "Discovering domain",
1139+
"flow-validate-model-name": "Validate Model",
11211140
"flow-prepare-model-name": "Prepare Model",
11221141
"flow-inspect-base-image-name": "Inspect Base Image",
11231142
"flow-create-image-name": "Create Primary Image",

electron/app/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,11 @@ class Main {
629629
return prepareModel(event.sender.getOwnerBrowserWindow(), WKT_CONSOLE_STDOUT_CHANNEL, WKT_CONSOLE_STDERR_CHANNEL, prepareConfig);
630630
});
631631

632+
ipcMain.handle('validate-model', async (event, validateConfig) => {
633+
const { validateModel } = require('./js/wdtValidateModel');
634+
return validateModel(event.sender.getOwnerBrowserWindow(), WKT_CONSOLE_STDOUT_CHANNEL, WKT_CONSOLE_STDERR_CHANNEL, validateConfig);
635+
});
636+
632637
ipcMain.handle('verify-files-exist', async (event, baseDirectory, ...files) => {
633638
this._logger.debug(...files);
634639
return fsUtils.verifyFilesExist(baseDirectory, ...files);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"model_filters" : {
33
"discover": [
4-
{ "name": "vz_prep", "path": "@@TARGET_CONFIG_DIR@@/vz_filter.py" }
4+
{ "name": "vz_prep", "path": "@@TARGET_CONFIG_DIR@@/vz_filter.py" },
5+
{ "id": "wko_filter" }
56
]
67
},
78
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},

0 commit comments

Comments
 (0)