Skip to content
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

[TEST] zwe install - tmp config #4057

Open
wants to merge 2 commits into
base: v3.x/staging
Choose a base branch
from
Open
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 bin/commands/install/.parameters
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
allow-overwrite,allow-overwritten||boolean|||||Allow overwritten existing MVS data set.
dataset-prefix,ds-prefix||string|||||Install Zowe to this dataset prefix.\nIf you specify this value, --config is not required.
dry-run||boolean|||||Prints out existing JCL templates but does not generate resolved JCL.
16 changes: 16 additions & 0 deletions bin/commands/install/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
This program and the accompanying materials are made available
under the terms of the Eclipse Public License v2.0 which
accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zowe Project.
*/

import * as index from './index';
import * as configmgr from '../../libs/configmgr';

index.execute();
configmgr.cleanupTempDir();
163 changes: 29 additions & 134 deletions bin/commands/install/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,143 +10,38 @@
#
# Copyright Contributors to the Zowe Project.
#######################################################################

print_level0_message "Install Zowe MVS data sets"

###############################
# constants
# keep in sync with workflows/templates/smpe-install/ZWE3ALOC.vtl
cust_ds_list="${ZWE_PRIVATE_DS_SZWESAMP}|Zowe sample library|dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks
${ZWE_PRIVATE_DS_SZWEAUTH}|Zowe authorized load library|dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks
${ZWE_PRIVATE_DS_SZWELOAD}|Zowe load library|dsntype(library) dsorg(po) recfm(u) lrecl(0) blksize(32760) unit(sysallda) space(30,15) tracks
${ZWE_PRIVATE_DS_SZWEEXEC}|Zowe executable utilities library|dsntype(library) dsorg(po) recfm(f b) lrecl(80) unit(sysallda) space(15,15) tracks"

###############################
# validation
if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX}" ]; then
prefix="${ZWE_CLI_PARAMETER_DATASET_PREFIX}"
else
require_zowe_yaml

# read prefix and validate
prefix=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.prefix")
if [ -z "${prefix}" ]; then
print_error_and_exit "Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file." "" 157

CEE_RO="XPLINK(ON),HEAPPOOLS(OFF),HEAPPOOLS64(OFF)"

# https://www.ibm.com/docs/en/zos/3.1.0?topic=descriptions-sh-invoke-shell
# ${parameter+word}
# Expands to word, provided that parameter is defined.

if [ -n "${ZWE_CLI_PARAMETER_DATASET_PREFIX+foo}" ]; then
tmp_config=$(create_tmp_file)
echo "zowe:" > "${tmp_config}"
echo " setup:" >> "${tmp_config}"
echo " dataset:" >> "${tmp_config}"
echo " prefix: ${ZWE_CLI_PARAMETER_DATASET_PREFIX}" >> "${tmp_config}"
if [ -z "${ZWE_CLI_PARAMETER_CONFIG}" ]; then
export ZWE_CLI_PARAMETER_CONFIG="${tmp_config}"
else
# What if also --config is used?
# Will ignore it or use it?
fi
fi

###############################
# create data sets if they do not exist
print_message "Create MVS data sets if they do not exist"
while read -r line; do
ds=$(echo "${line}" | awk -F"|" '{print $1}')
name=$(echo "${line}" | awk -F"|" '{print $2}')
spec=$(echo "${line}" | awk -F"|" '{print $3}')

# check existence
ds_existence=$(is_data_set_exists "${prefix}.${ds}")
if [ "${ds_existence}" = "true" ]; then
if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then
# warning
print_message "Warning ZWEL0300W: ${prefix}.${ds} already exists. Members in this data set will be overwritten."
else
# print_error_and_exit "Error ZWEL0158E: ${prefix}.${ds} already exists." "" 158
# warning
print_message "Warning ZWEL0301W: ${prefix}.${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite."
fi
else
print_message "Creating ${name} - ${prefix}.${ds}"
create_data_set "${prefix}.${ds}" "${spec}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
if [ -z "${ZWE_PRIVATE_TMP_MERGED_YAML_DIR}" ]; then
# user-facing command, use tmpdir to not mess up workspace permissions
export ZWE_PRIVATE_TMP_MERGED_YAML_DIR=1
fi
if [ -n "${ZWE_CLI_PARAMETER_CONFIG}" ]; then
_CEE_RUNOPTS="${CEE_RO}" ${ZWE_zowe_runtimeDirectory}/bin/utils/configmgr -script "${ZWE_zowe_runtimeDirectory}/bin/commands/install/cli.js"
saveRC=$?
if [ -n "${tmp_config}" ]; then
rm "${tmp_config}"
fi
done <<EOF
$(echo "${cust_ds_list}")
EOF
print_message

if [ "${ds_existence}" = "true" ] && [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" != "true" ]; then
print_level1_message "Zowe MVS data sets installation skipped."
exit $saveRC
else
###############################
# copy members
cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWESAMP}"
for mb in $(find . -type f); do
print_message "Copy files/${ZWE_PRIVATE_DS_SZWESAMP}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}"
copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
done

cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWEEXEC}"
for mb in $(find . -type f); do
print_message "Copy files/${ZWE_PRIVATE_DS_SZWEEXEC}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}"
copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEEXEC}" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
done

# prepare MVS for launcher
cd "${ZWE_zowe_runtimeDirectory}/components/launcher"
print_message "Copy components/launcher/samplib/ZWESLSTC to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}"
copy_to_data_set "samplib/ZWESLSTC" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
print_message "Copy components/launcher/bin/zowe_launcher to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}"
copy_to_data_set "bin/zowe_launcher" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}(ZWELNCH)" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi

# copy in configmgr rexx edition
cd "${ZWE_zowe_runtimeDirectory}/files/${ZWE_PRIVATE_DS_SZWELOAD}"
for mb in $(find . -type f); do
print_message "Copy files/${ZWE_PRIVATE_DS_SZWELOAD}/$(basename ${mb}) to ${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}"
copy_to_data_set "${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWELOAD}" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
done

# FIXME: move these parts to zss commands.install?
# FIXME: ZWESIPRG is in zowe-install-packaging
cd "${ZWE_zowe_runtimeDirectory}/components/zss"
zss_samplib="ZWESAUX=ZWESASTC ZWESIP00 ZWESIS01=ZWESISTC ZWESISCH"
for mb in ${zss_samplib}; do
mb_from=$(echo "${mb}" | awk -F= '{print $1}')
mb_to=$(echo "${mb}" | awk -F= '{print $2}')
if [ -z "${mb_to}" ]; then
mb_to="${mb_from}"
fi
print_message "Copy components/zss/SAMPLIB/${mb_from} to ${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})"
copy_to_data_set "SAMPLIB/${mb_from}" "${prefix}.${ZWE_PRIVATE_DS_SZWESAMP}(${mb_to})" "" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
done
zss_loadlib="ZWESIS01 ZWESAUX ZWESISDL"
for mb in ${zss_loadlib}; do
print_message "Copy components/zss/LOADLIB/${mb} to ${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}"
copy_to_data_set "LOADLIB/${mb}" "${prefix}.${ZWE_PRIVATE_DS_SZWEAUTH}" "-X" "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}"
if [ $? -ne 0 ]; then
print_error_and_exit "Error ZWEL0111E: Command aborts with error." "" 111
fi
done
print_message

###############################
# exit message
print_level1_message "Zowe MVS data sets are installed successfully."
print_error_and_exit "Error ZWEL0108E: Zowe YAML config file is required." "" 108
fi


print_message "Zowe installation completed. In order to use Zowe, you need to run \"zwe init\" command to initialize Zowe instance."
print_message "- Type \"zwe init --help\" to get more information."
print_message
print_message "You can also run individual init sub-commands: mvs, certificate, security, vsam, apfauth, and stc."
print_message "- Type \"zwe init <sub-command> --help\" (for example, \"zwe init stc --help\") to get more information."
print_message
132 changes: 132 additions & 0 deletions bin/commands/install/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
This program and the accompanying materials are made available
under the terms of the Eclipse Public License v2.0 which
accompanies this distribution, and is available at
https://www.eclipse.org/legal/epl-v20.html

SPDX-License-Identifier: EPL-2.0

Copyright Contributors to the Zowe Project.
*/

import * as std from 'cm_std';
import * as xplatform from 'xplatform';
import * as common from '../../libs/common';
import * as config from '../../libs/config';
import * as fs from '../../libs/fs';
import * as zosdataset from '../../libs/zos-dataset';

// **********************************
// This would be moved to zos-dataset
function validDatasetName(dsn: string): boolean {
common.printTrace(`- validDatasetName for "${dsn}"`);
if (!dsn || dsn.length < 1 || dsn.length > 44) {
common.printTrace(' * dataset null, empty or > 44 chars');
return false;
}
const result = !!dsn.match(/^([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}(\.([A-Z\$\#\@]){1}([A-Z0-9\$\#\@\-]){0,7}){0,11}$/g);
common.printTrace(` * regex match: ${result}`);
return result;
}
// This would be moved to zos-dataset
// **********************************

export function execute(): void {

common.printLevel1Message("Install Zowe MVS data sets");

common.requireZoweYaml();
const zoweConfig = config.getZoweConfig();

const prefix = zoweConfig.zowe.setup?.dataset?.prefix;
if (!prefix) {
common.printErrorAndExit(`Error ZWEL0157E: Zowe dataset prefix (zowe.setup.dataset.prefix) is not defined in Zowe YAML configuration file.`, undefined, 157);
}

let runtime = zoweConfig.zowe?.runtimeDirectory;
const runtimeEnv = std.getenv('ZWE_zowe_runtimeDirectory');
if (!runtime) {
runtime = runtimeEnv;
} else {
// We need clean path for xplatform.loadFileUTF8, otherwise will fail for e.g. /zowe/./files/SZWESAMP//ZWEINSTL
runtime = fs.convertToAbsolutePath(runtime);
if (runtime != runtimeEnv) {
common.printErrorAndExit(`Error ZWEL0105E: The Zowe YAML config file is associated to Zowe runtime "${runtime}", which is not same as where zwe command is located "${runtimeEnv}".`, undefined, 105);
}
}

const ZWEINSTL=`${runtime}/files/SZWESAMP/ZWEINSTL`;
const DATASETS = [ 'SZWEAUTH', 'SZWEEXEC', 'SZWELOAD', 'SZWESAMP' ];
const allowOverwrite = std.getenv("ZWE_CLI_PARAMETER_ALLOW_OVERWRITE") == 'true' ? true : false;
const dryRun = std.getenv("ZWE_CLI_PARAMETER_DRY_RUN") == 'true' ? true : false;
let skipJCL = false;

for (let ds in DATASETS) {
if (zosdataset.isDatasetExists(`${prefix}.${DATASETS[ds]}`)) {
if (allowOverwrite == false) {
common.printMessage(`Warning ZWEL0301W: ${prefix}.${DATASETS[ds]} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite.`);
skipJCL = true;
} else {
common.printMessage(`Warning ZWEL0300W: ${prefix}.${DATASETS[ds]} already exists. Members in this data set will be overwritten.`);
// **************************************************************
console.log(`FAKE: tsocmd "DELETE '${prefix}.${DATASETS[ds]}'"`);
// **************************************************************
}
}
}

if (skipJCL) {
common.printLevel1Message("Zowe MVS data sets installation skipped.");
std.exit(0);
}

let jclContents = xplatform.loadFileUTF8(ZWEINSTL, xplatform.AUTO_DETECT);
if (!jclContents) {
common.printErrorAndExit(`Error ZWEL0159E Failed to modify ${ZWEINSTL}.`, undefined, 159);
}

// Make string from array or convert possible number to string
let jclHeader = zoweConfig.zowe.environments?.jclHeader;
if (jclHeader !== undefined && jclHeader !== null && jclHeader !== '') {
jclHeader = Array.isArray(jclHeader) ? jclHeader.join("\n"): jclHeader.toString();
jclContents = jclContents.replace(/\/\/ZWEINSTL JOB/gi, `//ZWEINSTL JOB ${jclHeader.replace(/[$]/g, '$$$$')}`);
}

jclContents = jclContents.replace(/\{zowe\.setup\.dataset\.prefix\}/gi, prefix.replace(/[$]/g, '$$$$'));
jclContents = jclContents.replace(/\{zowe\.runtimeDirectory\}/gi, runtime.replace(/[$]/g, '$$$$'));

common.printMessage(`Template JCL: ${ZWEINSTL}`);
common.printMessage('--- JCL content ---');
common.printMessage(jclContents);
common.printMessage('--- End of JCL ---');

if (dryRun) {
common.printMessage('JCL not submitted, command run with "--dry-run" flag.');
common.printMessage('To perform command, re-run command without "--dry-run" flag, or submit the JCL directly.');
} else {
common.printMessage('Submitting Job ZWEINSTL');
// **************************************************************
// submitJob and waitForJob implemented in 3718 (migrate2JCL)
const result = {
rc: 0,
jobcccode: 123,
jobcctext: "JCL ESM error"
};
// const jobid = zosJes.submitJob(jclContents, true, true);
// const result = zosJes.waitForJob(jobid);
// **************************************************************

common.printMessage(`Job completed with RC=${result.rc}`);
if (result.rc == 0) {
common.printLevel1Message("Zowe MVS data sets are installed successfully.");
common.printMessage("Zowe installation completed. In order to use Zowe, you need to run \"zwe init\" command to initialize Zowe instance.");
common.printMessage("- Type \"zwe init --help\" to get more information.\n\n");
common.printMessage("You can also run individual init sub-commands: generate, mvs, certificate, security, vsam, apfauth, and stc.");
common.printMessage("- Type \"zwe init <sub-command> --help\" (for example, \"zwe init stc --help\") to get more information.\n\n");
common.printMessage("Zowe JCL generated successfully");
} else {
common.printMessage(`Zowe JCL submitted with errors, check job log. Job completion code=${result.jobcccode}, Job completion text=${result.jobcctext}`);
}
}

}
Loading