Skip to content

Commit

Permalink
Reduce duplicate code in each init phase
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Feb 8, 2024
1 parent 41bb33a commit 15f0163
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 243 deletions.
23 changes: 1 addition & 22 deletions bin/commands/init/certificate/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,8 @@ 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
fi
# read JCL library and validate
jcllib=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.jcllib")
does_jcl_exist=$(is_data_set_exists "${jcllib}")
if [ -z "${does_jcl_exist}" ]; then
zwecli_inline_execute_command init generate
fi

# should be created, but may take time to discover.
if [ -z "${does_jcl_exist}" ]; then
does_jcl_exist=
for secs in 1 5 10 ; do
does_jcl_exist=$(is_data_set_exists "${jcllib}")
if [ -z "${does_jcl_exist}" ]; then
sleep ${secs}
else
break
fi
done

if [ -z "${does_jcl_exist}" ]; then
print_error_and_exit "Error ZWEL0999E: ${jcllib} does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command." "" 999
fi
fi
jcllib=$(verify_generated_jcl)

security_product=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.product")
security_users_zowe=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.users.zowe")
Expand Down
36 changes: 22 additions & 14 deletions bin/commands/init/mvs/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ print_level1_message "Initialize Zowe custom data sets"
###############################
# constants
cust_ds_list="parmlib|Zowe parameter library
jcllib|Zowe JCL library
authLoadlib|Zowe authorized load library
authPluginLib|Zowe authorized plugin library"

Expand Down Expand Up @@ -47,23 +46,32 @@ while read -r line; do
else
print_error_and_exit "Error ZWEL0157E: ${name} (zowe.setup.dataset.${key}) is not defined in Zowe YAML configuration file." "" 157
fi
elif [ "${key}" = "authLoadlib" ]; then
if [ "${ds}" = "${prefix}.SZWESAMP" ]; then
fi

if [ "${key}" = "authLoadlib" ]; then
if [ "${ds}" = "${prefix}.SZWEAUTH" ]; then
run_aloadlib_create="false"
else
run_aloadlib_create="true"
# check existence
ds_existence=$(is_data_set_exists "${ds}")
if [ "${ds_existence}" = "true" ]; then
if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then
print_message "Warning ZWEL0300W: ${ds} already exists. Members in this data set will be overwritten."
else
print_message "Warning ZWEL0301W: ${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite."
fi
fi
fi
fi
# check existence
ds_existence=$(is_data_set_exists "${ds}")
if [ "${ds_existence}" = "true" ]; then
if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then
# warning
print_message "Warning ZWEL0300W: ${ds} already exists. Members in this data set will be overwritten."
else
# print_error_and_exit "Error ZWEL0158E: ${ds} already exists." "" 158
# warning
print_message "Warning ZWEL0301W: ${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite."
else
# check existence
ds_existence=$(is_data_set_exists "${ds}")
if [ "${ds_existence}" = "true" ]; then
if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then
print_message "Warning ZWEL0300W: ${ds} already exists. Members in this data set will be overwritten."
else
print_message "Warning ZWEL0301W: ${ds} already exists and will not be overwritten. For upgrades, you must use --allow-overwrite."
fi
fi
fi
done <<EOF
Expand Down
140 changes: 16 additions & 124 deletions bin/commands/init/security/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,136 +22,28 @@ 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
fi
security_product=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.product")
if [ -z "${security_product}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.product) is not defined in Zowe YAML configuration file." "" 157
fi

# read JCL library and validate
jcllib=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.jcllib")
does_jcl_exist=$(is_data_set_exists "${jcllib}(ZWEI${security_product})")
if [ -z "${does_jcl_exist}" ]; then
zwecli_inline_execute_command init generate
fi
jcllib=$(verify_generated_jcl)

validation_list="product groups.admin groups.stc groups.sysProg users.zowe users.zis stcs.zowe stcs.zis stcs.aux"

# should be created, but may take time to discover.
if [ -z "${does_jcl_exist}" ]; then
does_jcl_exist=
for secs in 1 5 10 ; do
does_jcl_exist=$(is_data_set_exists "${jcllib}(ZWEI${security_product})")
if [ -z "${does_jcl_exist}" ]; then
sleep ${secs}
else
break
for item in ${validation_list}; do
result=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.${item}")
if [ -z "${result}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.${item}) is not defined in Zowe YAML configuration file." "" 157
fi
done

if [ -z "${does_jcl_exist}" ]; then
print_error_and_exit "Error ZWEL0999E: ${jcllib}(ZWEI${security_product}) does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command." "" 999
fi
fi


security_groups_admin=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.groups.admin")
if [ -z "${security_groups_admin}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.groups.admin) is not defined in Zowe YAML configuration file." "" 157
fi
security_groups_stc=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.groups.stc")
if [ -z "${security_groups_stc}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.groups.stc) is not defined in Zowe YAML configuration file." "" 157
fi
security_groups_sysProg=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.groups.sysProg")
if [ -z "${security_groups_sysProg}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.groups.sysProg) is not defined in Zowe YAML configuration file." "" 157
fi
security_users_zowe=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.users.zowe")
if [ -z "${security_users_zowe}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.users.zowe) is not defined in Zowe YAML configuration file." "" 157
fi
security_users_zis=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.users.zis")
if [ -z "${security_users_zis}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.users.zis) is not defined in Zowe YAML configuration file." "" 157
fi
security_stcs_zowe=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.stcs.zowe")
if [ -z "${security_stcs_zowe}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.stcs.zowe) is not defined in Zowe YAML configuration file." "" 157
fi
security_stcs_zis=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.stcs.zis")
if [ -z "${security_stcs_zis}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.stcs.zis) is not defined in Zowe YAML configuration file." "" 157
fi
security_stcs_aux=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.stcs.aux")
if [ -z "${security_stcs_aux}" ]; then
print_error_and_exit "Error ZWEL0157E: (zowe.setup.security.stcs.aux) is not defined in Zowe YAML configuration file." "" 157
fi


jcl_contents=$(cat "//'${jcllib}(ZWEI${security_product})'")

print_message "Template JCL: ${prefix}.SZWESAMP(ZWEI${security_product}) , Executable JCL: ${jcllib}(ZWEI${security_product})"
print_message "--- JCL Content ---"
print_message "$jcl_contents"
print_message "--- End of JCL ---"
###############################
# submit job
print_and_handle_jcl "//'${jcllib}(ZWEI${security_product})'" "ZWEI${security_product}" "${jcllib}" "${prefix}" "false" "${ZWE_CLI_PARAMETER_IGNORE_SECURITY_FAILURES}"
print_message ""
print_message "WARNING: Due to the limitation of the ZWESECUR job, exit with 0 does not mean"
print_message " the job is fully successful. Please check the job log to determine"
print_message " if there are any inline errors."
print_message ""
print_level2_message "Command run successfully."

job_has_failures=
if [ "${ZWE_CLI_PARAMETER_SECURITY_DRY_RUN}" = "true" ]; then
print_message "JCL not submitted, command run with dry run flag."
print_message "To perform command, re-run command without dry run flag, or submit the JCL directly"
else
###############################
# submit job
print_message "Submitting Job ZWEI${security_product}"
jobid=$(submit_job "//'${jcllib}(ZWEI${security_product})'")
code=$?
if [ ${code} -ne 0 ]; then
job_has_failures=true
if [ "${ZWE_CLI_PARAMETER_IGNORE_SECURITY_FAILURES}" = "true" ]; then
print_error "Warning ZWEL0161W: Failed to run JCL ${jcllib}(ZWEI${security_product})."
# skip wait for job status step
jobid=
else
print_error_and_exit "Error ZWEL0161E: Failed to run JCL ${jcllib}(ZWEI${security_product})." "" 161
fi
fi

if [ -n "${jobid}" ]; then
print_debug "- job id ${jobid}"
jobstate=$(wait_for_job "${jobid}")
code=$?
if [ ${code} -eq 1 ]; then
job_has_failures=true
if [ "${ZWE_CLI_PARAMETER_IGNORE_SECURITY_FAILURES}" = "true" ]; then
print_error "Warning ZWEL0162W: Failed to find job ${jobid} result."
else
print_error_and_exit "Error ZWEL0162E: Failed to find job ${jobid} result." "" 162
fi
fi
jobname=$(echo "${jobstate}" | awk -F, '{print $2}')
jobcctext=$(echo "${jobstate}" | awk -F, '{print $3}')
jobcccode=$(echo "${jobstate}" | awk -F, '{print $4}')
if [ ${code} -eq 0 ]; then
print_message "- Job ${jobname}(${jobid}) ends with code ${jobcccode} (${jobcctext})."

print_message ""
print_message "WARNING: Due to the limitation of the ZWESECUR job, exit with 0 does not mean"
print_message " the job is fully successful. Please check the job log to determine"
print_message " if there are any inline errors."
print_message ""
else
job_has_failures=true
if [ "${ZWE_CLI_PARAMETER_IGNORE_SECURITY_FAILURES}" = "true" ]; then
print_error "Warning ZWEL0163W: Job ${jobname}(${jobid}) ends with code ${jobcccode} (${jobcctext})."
else
print_error_and_exit "Error ZWEL0163E: Job ${jobname}(${jobid}) ends with code ${jobcccode} (${jobcctext})." "" 163
fi
fi
fi
fi

###############################
# exit message
if [ "${job_has_failures}" = "true" ]; then
print_level2_message "Failed to apply Zowe security configurations. Please check job log for details."
else
print_level2_message "Command run successfully."
fi
65 changes: 3 additions & 62 deletions bin/commands/init/stc/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,8 @@ proclib=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.proclib")
if [ -z "${proclib}" ]; then
print_error_and_exit "Error ZWEL0157E: PROCLIB (zowe.setup.dataset.proclib) is not defined in Zowe YAML configuration file." "" 157
fi
# read JCL library and validate
jcllib=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.dataset.jcllib")
does_jcl_exist=$(is_data_set_exists "${jcllib}(ZWEISTC)")
if [ -z "${does_jcl_exist}" ]; then
zwecli_inline_execute_command init generate
fi

# should be created, but may take time to discover.
if [ -z "${does_jcl_exist}" ]; then
does_jcl_exist=
for secs in 1 5 10 ; do
does_jcl_exist=$(is_data_set_exists "${jcllib}(ZWEISTC)")
if [ -z "${does_jcl_exist}" ]; then
sleep ${secs}
else
break
fi
done

if [ -z "${does_jcl_exist}" ]; then
print_error_and_exit "Error ZWEL0999E: ${jcllib}(ZWEISTC) does not exist, cannot run. Run 'zwe init', 'zwe init generate', or submit JCL ${prefix}.SZWESAMP(ZWEGENER) before running this command." "" 999
fi
fi

jcllib=$(verify_generated_jcl)

security_stcs_zowe=$(read_yaml "${ZWE_CLI_PARAMETER_CONFIG}" ".zowe.setup.security.stcs.zowe")
if [ -z "${security_stcs_zowe}" ]; then
Expand All @@ -72,11 +50,8 @@ for mb in ${target_proclibs}; do
stc_existence=$(is_data_set_exists "${proclib}(${mb})")
if [ "${stc_existence}" = "true" ]; then
if [ "${ZWE_CLI_PARAMETER_ALLOW_OVERWRITE}" = "true" ]; then
# warning
print_message "Warning ZWEL0300W: ${proclib}(${mb}) already exists. This data set member will be overwritten during configuration."
else
# print_error_and_exit "Error ZWEL0158E: ${proclib}(${mb}) already exists." "" 158
# warning
print_message "Warning ZWEL0301W: ${proclib}(${mb}) already exists and will not be overwritten. For upgrades, you must use --allow-overwrite."
fi
fi
Expand All @@ -95,43 +70,9 @@ else
# so, we have to have some conditional logic somewhere. until figuring out how to fix this in ZWEGENER, i am putting it here...
jcl_edit=$(cat "${jcl_file}" | sed "s/ZWESLSTC,ZWESLSTC/ZWESLSTC/" | sed "s/ZWESISTC,ZWESISTC/ZWESISTC/" | sed "s/ZWESASTC,ZWESASTC/ZWESASTC/")
echo "${jcl_edit}" > "${jcl_file}"
jcl_contents=$(cat "${jcl_file}")

print_message "Template JCL: ${prefix}.SZWESAMP(ZWEISTC) , Executable JCL: ${jcllib}(ZWEISTC)"
print_message "--- JCL Content ---"
print_message "$jcl_contents"
print_message "--- End of JCL ---"

if [ -z "${ZWE_CLI_PARAMETER_DRY_RUN}" ]; then
print_message "Submitting Job ZWEISTC"
jobid=$(submit_job $jcl_file)
code=$?
if [ ${code} -ne 0 ]; then
print_error_and_exit "Error ZWEL0161E: Failed to run JCL ${jcllib}(ZWEISTC)." "" 161
fi
print_debug "- job id ${jobid}"

jobstate=$(wait_for_job "${jobid}")
code=$?
rm $jcl_file
if [ ${code} -eq 1 ]; then
print_error_and_exit "Error ZWEL0162E: Failed to find job ${jobid} result." "" 162
fi
jobname=$(echo "${jobstate}" | awk -F, '{print $2}')
jobcctext=$(echo "${jobstate}" | awk -F, '{print $3}')
jobcccode=$(echo "${jobstate}" | awk -F, '{print $4}')

if [ "${code}" -eq 0 ]; then
print_level2_message "Zowe main started tasks are installed successfully."
else
print_error_and_exit "Error ZWEL0163E: Job ${jobname}(${jobid}) ends with code ${jobcccode} (${jobcctext})." "" 163
fi
else
print_message "JCL not submitted, command run with dry run flag."
print_message "To perform command, re-run command without dry run flag, or submit the JCL directly"
print_level2_message "Command run successfully."
rm $jcl_file
fi
print_and_handle_jcl "${jcl_file}" "ZWEISTC" "${jcllib}" "${prefix}" "true"
print_level2_message "Zowe main started tasks are installed successfully."
fi


Loading

0 comments on commit 15f0163

Please sign in to comment.