Skip to content

Commit

Permalink
Remove node usage in startup when using configmgr (#3756)
Browse files Browse the repository at this point in the history
* Remove node usage in startup when using configmgr

Signed-off-by: 1000TurquoisePogs <[email protected]>

* Update config.ts

Signed-off-by: 1000TurquoisePogs <[email protected]>

* Handle null to blank for configmgr update

Signed-off-by: 1000TurquoisePogs <[email protected]>

* Samll trace msgs update

Signed-off-by: Martin Zeithaml <[email protected]>

---------

Signed-off-by: 1000TurquoisePogs <[email protected]>
Signed-off-by: Martin Zeithaml <[email protected]>
Co-authored-by: Martin Zeithaml <[email protected]>
  • Loading branch information
1000TurquoisePogs and Martin-Zeithaml authored Apr 8, 2024
1 parent e8a54e8 commit a2f4c04
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 159 deletions.
1 change: 0 additions & 1 deletion bin/commands/components/install/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as config from '../../../../libs/config';
import * as component from '../../../../libs/component';
import * as varlib from '../../../../libs/var';
import * as java from '../../../../libs/java';
import * as node from '../../../../libs/node';
import * as zosmf from '../../../../libs/zosmf';
import { PathAPI as pathoid } from '../../../../libs/pathoid';

Expand Down
16 changes: 10 additions & 6 deletions bin/commands/internal/start/prepare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ function globalValidate(enabledComponents:string[]): void {
if (runInContainer != 'true') {
// only do these check when it's not running in container

// currently node is always required
let nodeOk = node.validateNodeHome();
if (!nodeOk) {
privateErrors++;
common.printFormattedError('ZWELS', "zwe-internal-start-prepare,global_validate", `Could not validate node home`);
if (enabledComponents.includes('app-server')) {
let nodeOk = node.validateNodeHome();
if (!nodeOk) {
privateErrors++;
common.printFormattedError('ZWELS', "zwe-internal-start-prepare,global_validate", `Could not validate node home`);
}
}

// validate java for some core components
Expand Down Expand Up @@ -438,7 +439,10 @@ export function execute() {
// other extensions need to specify `require_java` in their validate.sh
java.requireJava();
}
node.requireNode();
if (stringlib.itemInList('app-server', std.getenv('ZWE_CLI_PARAMETER_COMPONENT'))) {
// other extensions need to specify `require_node` in their validate.sh
node.requireNode();
}
common.requireZoweYaml();

// overwrite ZWE_PRIVATE_LOG_LEVEL_ZWELS with zowe.launchScript.logLevel config in YAML
Expand Down
81 changes: 43 additions & 38 deletions bin/libs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import * as component from './component';
import * as zosfs from './zos-fs';
import * as sys from './sys';
import * as container from './container';
import * as node from './node';
import * as objUtils from '../utils/ObjUtils';

const cliParameterConfig:string = function() {
Expand All @@ -48,22 +47,6 @@ export function updateZoweConfig(updateObj: any, writeUpdate: boolean, arrayMerg
return configmgr.updateZoweConfig(updateObj, writeUpdate, arrayMergeStrategy);
}

// Convert instance.env to zowe.yaml file
export function convertInstanceEnvToYaml(instanceEnv: string, zoweYaml?: string) {
// we need node for following commands
node.ensureNodeIsOnPath();

if (!zoweYaml) {
shell.execSync('node', `${std.getenv('ROOT_DIR')}/bin/utils/config-converter/src/cli.js`, `env`, `yaml`, instanceEnv);
} else {
shell.execSync('node', `${std.getenv('ROOT_DIR')}/bin/utils/config-converter/src/cli.js`, `env`, `yaml`, instanceEnv, `-o`, zoweYaml);

zosfs.ensureFileEncoding(zoweYaml, "zowe:", 1047);

shell.execSync('chmod', `640`, zoweYaml);
}
}

//////////////////////////////////////////////////////////////
// Check encoding of a file and convert to IBM-1047 if needed.
//
Expand Down Expand Up @@ -95,7 +78,7 @@ export function generateInstanceEnvFromYamlConfig(haInstance: string) {
}

// delete old files to avoid potential issues
common.printFormattedTrace( "ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `deleting old files under ${zwePrivateWorkspaceEnvDir}`);
common.printFormattedTrace( "ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `deleting old files under ${zwePrivateWorkspaceEnvDir}`);
let foundFiles = fs.getFilesInDirectory(zwePrivateWorkspaceEnvDir);
if (foundFiles) {
foundFiles.forEach((file:string)=> {
Expand All @@ -108,27 +91,16 @@ export function generateInstanceEnvFromYamlConfig(haInstance: string) {
}

const components = component.findAllInstalledComponents2();
//TODO use configmgr to write json and ha json, and components json

// prepare .zowe.json and .zowe-<ha-id>.json
common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `config-converter yaml convert --ha ${haInstance} ${cliParameterConfig}`);
let result = shell.execOutSync('node', `${runtimeDirectory}/bin/utils/config-converter/src/cli.js`, `yaml`, `convert`, `--wd`, zwePrivateWorkspaceEnvDir, `--ha`, haInstance, cliParameterConfig, `--verbose`);

common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `- Exit code: ${result.rc}: ${result.out}`);
if ( !fs.fileExists(`${zwePrivateWorkspaceEnvDir}/.zowe.json`)) {
common.printFormattedError( "ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
std.exit(140);
}





let jsonConfig = Object.assign({}, getZoweConfig());
let componentsWithConfigs:string[] = [];
let merger = new objUtils.Merger();
merger.mergeArrays = false;

// convert YAML configurations to backward compatible .instance-<ha-id>.env files
common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `config-converter yaml env --ha ${haInstance}`);
common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `getZoweConfigEnv(${haInstance})`);
const envs = configmgr.getZoweConfigEnv(haInstance);
common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `- Output: ${JSON.stringify(envs, null, 2)}`);
common.printFormattedTrace("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `- Output: ${JSON.stringify(envs, null, 2)}`);
const envKeys = Object.keys(envs);
let envFileArray=[];

Expand All @@ -145,7 +117,7 @@ export function generateInstanceEnvFromYamlConfig(haInstance: string) {
let rc = fs.mkdirp(folderName, 0o700);
if (rc) {
//TODO error code
common.printFormattedError("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `Failed to make env var folder for component=${currentComponent}`);
common.printFormattedError("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `Failed to make env var folder for component=${currentComponent}`);
}
let componentFileArray = [];
componentFileArray.push('#!/bin/sh');
Expand All @@ -163,6 +135,12 @@ export function generateInstanceEnvFromYamlConfig(haInstance: string) {

let flat = [];
if (componentManifest.configs) {
componentsWithConfigs.push(currentComponent);
let currentComponentJson:any = {};
currentComponentJson.components = {};
currentComponentJson.components[currentComponent] = componentManifest.configs;
jsonConfig = merger.merge( jsonConfig, currentComponentJson);

const flattener = new objUtils.Flattener();
flattener.setSeparator('_');
flattener.setKeepArrays(true);
Expand Down Expand Up @@ -195,17 +173,44 @@ export function generateInstanceEnvFromYamlConfig(haInstance: string) {
const componentFileContent = componentFileArray.join('\n');
rc = xplatform.storeFileUTF8(`${folderName}/.instance-${haInstance}.env`, xplatform.AUTO_DETECT, componentFileContent);
if (rc) {
common.printFormattedError("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
common.printFormattedError("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
std.exit(140);
return;
}
});

// we want this, but not at the top level.
let hostname = jsonConfig.hostname;

let haConfig = jsonConfig;
if (haInstance && jsonConfig.haInstances && jsonConfig.haInstances[haInstance]) {
haConfig = merger.merge(jsonConfig.haInstances[haInstance], jsonConfig);
}

haConfig.haInstance = {
id: haInstance,
hostname: hostname
};
delete jsonConfig.hostname;

componentsWithConfigs.forEach((componentName)=> {
let componentConfig = merger.merge(haConfig, { configs: jsonConfig.components[componentName] });
xplatform.storeFileUTF8(`${zwePrivateWorkspaceEnvDir}/${componentName}/.configs-${haInstance}.json`, xplatform.AUTO_DETECT, JSON.stringify(componentConfig, null, 2));
});

xplatform.storeFileUTF8(`${zwePrivateWorkspaceEnvDir}/.zowe.json`, xplatform.AUTO_DETECT, JSON.stringify(jsonConfig, null, 2));
xplatform.storeFileUTF8(`${zwePrivateWorkspaceEnvDir}/.zowe-${haInstance}.json`, xplatform.AUTO_DETECT, JSON.stringify(haConfig, null, 2));

if (!fs.fileExists(`${zwePrivateWorkspaceEnvDir}/.zowe.json`)) {
common.printFormattedError("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
std.exit(140);
}

envFileArray = envFileArray.map((row)=> { return row.endsWith('=null') ? row.substring(0, row.length-5)+'=' : row });
let envFileContent = envFileArray.join('\n');
let rc = xplatform.storeFileUTF8(`${zwePrivateWorkspaceEnvDir}/.instance-${haInstance}.env`, xplatform.AUTO_DETECT, envFileContent);
if (rc) {
common.printFormattedError("ZWELS", "bin/libs/config.ts,generate_instance_env_from_yaml_config", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
common.printFormattedError("ZWELS", "bin/libs/config.ts,generateInstanceEnvFromYamlConfig", `ZWEL0140E: Failed to translate Zowe configuration (${cliParameterConfig}).`);
std.exit(140);
return;
}
Expand Down
114 changes: 0 additions & 114 deletions bin/libs/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,93 +66,10 @@ export function shellReadYamlConfig(yamlFile: string, parentKey: string, key: st
}
}

//NOTE: PARMLIB only supported when destination is zowe.yaml
export function readYaml(file: string, key: string) {
const ZOWE_CONFIG=config.getZoweConfig();
const utils_dir=`${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/utils`;
const jq=`${utils_dir}/njq/src/index.js`;
const fconv=`${utils_dir}/fconv/src/index.js`;

common.printTrace(`- readYaml load content from ${file}`);
if (std.getenv('ZWE_CLI_PARAMETER_CONFIG') == file) {
return fakejq.jqget(ZOWE_CONFIG, key);
} else {
const ZWE_PRIVATE_YAML_CACHE=shell.execOutSync('sh', '-c', `node "${fconv}" --input-format=yaml "${file}" 2>&1`);
let code=ZWE_PRIVATE_YAML_CACHE.rc;
common.printTrace(` * Exit code: ${code}`);
if (code != 0) {
common.printError(" * Output:");
common.printError(stringlib.paddingLeft(ZWE_PRIVATE_YAML_CACHE.out, " "));
return;
}

common.printTrace(`- readYaml ${key} from yaml content`);
const result=shell.execOutSync('sh', '-c', `echo "${ZWE_PRIVATE_YAML_CACHE}" | node "${jq}" -r "${key}" 2>&1`);
code=result.rc;
common.printTrace(` * Exit code: ${code}`);
common.printTrace(" * Output:");
if (result.out) {
common.printTrace(stringlib.paddingLeft(result.out, " "));
}

return result.out
}
}

export function readJson(file: string, key: string):any {
const ZOWE_CONFIG=config.getZoweConfig();
const utils_dir=`${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/utils`;
const jq=`${utils_dir}/njq/src/index.js`;

common.printTrace(`- readJson ${key} from ${file}`);
let result=shell.execOutSync('sh', '-c', `cat "${file}" | node "${jq}" -r "${key}" 2>&1`);
const code = result.rc;
common.printTrace(` * Exit code: ${code}`);
common.printTrace(` * Output:`);
if ( result.out ) {
common.printTrace(stringlib.paddingLeft(result.out, " "));
}

return result.out;
}

export function readJsonString(input: string, key: string): any {
return fakejq.jqget(JSON.parse(input), key);
}

//NOTE: PARMLIB only supported when destination is zowe.yaml
export function updateYaml(file: string, key: string, val: any, expectedSample: string) {
const ZOWE_CONFIG=config.getZoweConfig();
const utils_dir=`${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/utils`;
const config_converter=`${utils_dir}/config-converter/src/cli.js`


common.printMessage(`- update "${key}" with value: ${val}`);
if (std.getenv('ZWE_CLI_PARAMETER_CONFIG') == file) {
updateZoweYaml(file, key, val);
} else {
// TODO what would we write thats not the zowe config? this sounds like an opportunity to disorganize.
let result=shell.execOutSync('sh', '-c', `node "${config_converter}" yaml update "${file}" "${key}" "${val}"`);
const code = result.rc;
if (code == 0) {
common.printTrace(` * Exit code: ${code}`);
common.printTrace(` * Output:`);
if (result.out) {
common.printTrace(stringlib.paddingLeft(result.out, " "));
}
} else {
common.printError(` * Exit code: ${code}`);
common.printError(" * Output:");
if (result.out) {
common.printError(stringlib.paddingLeft(result.out, " "));
}
common.printErrorAndExit(`Error ZWEL0138E: Failed to update key ${key} of file ${file}.`, undefined, 138);
}

zosfs.ensureFileEncoding(file, expectedSample);
}
}

export function updateZoweYaml(file: string, key: string, val: any) {
common.printMessage(`- update zowe config ${file}, key: "${key}" with value: ${val}`);
let [ success, updateObj ] = fakejq.jqset({}, key, val);
Expand All @@ -164,34 +81,3 @@ export function updateZoweYaml(file: string, key: string, val: any) {
common.printError(` * Error`);
}
}

//TODO: PARMLIB not supported.
export function deleteYaml(file: string, key: string, expectedSample: string) {
const ZOWE_CONFIG=config.getZoweConfig();
const utils_dir=`${ZOWE_CONFIG.zowe.runtimeDirectory}/bin/utils`;
const config_converter=`${utils_dir}/config-converter/src/cli.js`

common.printMessage(`- delete \"${key}\"`);
let result=shell.execOutSync('sh', '-c', `node "${config_converter}" yaml delete "${file}" "${key}"`);
const code = result.rc;
if (code == 0) {
common.printTrace(` * Exit code: ${code}`);
common.printTrace(` * Output:`);
if (result.out) {
common.printTrace(stringlib.paddingLeft(result.out, " "));
}
} else {
common.printError(` * Exit code: ${code}`);
common.printError(" * Output:");
if (result.out) {
common.printError(stringlib.paddingLeft(result.out, " "));
}
common.printErrorAndExit(`Error ZWEL0138E: Failed to delete key ${key} of file ${file}.`, undefined, 138);
}

zosfs.ensureFileEncoding(file, expectedSample);
}

export function deleteZoweYaml(file: string, key: string) {
deleteYaml(file, key, "zowe:");
}

0 comments on commit a2f4c04

Please sign in to comment.