Skip to content

Commit d67b87d

Browse files
committed
- added auto-initialization if user calls kernel methods; checks for existence of user's manager config, and if it is missing triggers the previous 'init' logic
- added preview of affected paths within init function, and asks user for confirmation that they wish to make these changes - this should only occur the first time the user leverages the system
1 parent 400c58b commit d67b87d

2 files changed

Lines changed: 118 additions & 6 deletions

File tree

Deploy.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# deploying the ICRN kernel manager services
22

3+
## get the most recent changes moved to campus cluster
4+
5+
36
## Changes needed to ICRN containers in dev
47

58

icrn_manager

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ ICRN_USER_KERNEL_BASE=${ICRN_USER_KERNEL_BASE:-${ICRN_USER_BASE}/${icrn_kernels}
2121
ICRN_USER_CATALOG=${ICRN_USER_CATALOG:-${ICRN_USER_KERNEL_BASE}/user_catalog.json}
2222

2323
if [ ! -e ${ICRN_MANAGER_CONFIG} ]; then
24-
# if manager config json doesn't exist, we need to be in the 'init' call
25-
if [ ! "$2" = "init" ]; then
26-
echo "You must run 'icrn_manager kernels init' prior to leveraging this tool."
27-
exit 1
28-
fi
29-
# if the config doesn't exist, it will be created and populated during the init call
24+
# Note: Auto-initialization will be handled in kernels() function
25+
# This section sets up default paths for when config doesn't exist yet
3026
ICRN_KERNEL_REPOSITORY=$central_catalog_default
3127
ICRN_R_KERNELS=${ICRN_KERNEL_REPOSITORY}"/r_kernels"
3228
ICRN_PYTHON_KERNELS=${ICRN_KERNEL_REPOSITORY}"/python_kernels"
@@ -846,6 +842,80 @@ function kernels__init() # create base resources
846842
echo ""
847843
echo "central catalog location will be: ${central_repository}"
848844
echo ""
845+
846+
# Determine which paths will be affected
847+
ICRN_MANAGER_CONFIG=${ICRN_MANAGER_CONFIG:-${ICRN_USER_BASE}/manager_config.json}
848+
849+
echo "The following paths will be created or modified:"
850+
echo ""
851+
852+
local paths_to_create=()
853+
local paths_to_overwrite=()
854+
855+
# Check ICRN_USER_BASE
856+
if [ ! -e "${ICRN_USER_BASE}/" ]; then
857+
paths_to_create+=("${ICRN_USER_BASE}/ (directory)")
858+
fi
859+
860+
# Check ICRN_USER_KERNEL_BASE
861+
if [ ! -e "${ICRN_USER_KERNEL_BASE}" ]; then
862+
paths_to_create+=("${ICRN_USER_KERNEL_BASE} (directory)")
863+
fi
864+
865+
# Check language-specific subdirectories
866+
if [ ! -e "${ICRN_USER_KERNEL_BASE}/r" ]; then
867+
paths_to_create+=("${ICRN_USER_KERNEL_BASE}/r (directory)")
868+
fi
869+
870+
if [ ! -e "${ICRN_USER_KERNEL_BASE}/python" ]; then
871+
paths_to_create+=("${ICRN_USER_KERNEL_BASE}/python (directory)")
872+
fi
873+
874+
# Check ICRN_USER_CATALOG
875+
if [ ! -e "${ICRN_USER_CATALOG}" ]; then
876+
paths_to_create+=("${ICRN_USER_CATALOG} (file)")
877+
fi
878+
879+
# Check ICRN_MANAGER_CONFIG
880+
if [ ! -e "${ICRN_MANAGER_CONFIG}" ]; then
881+
paths_to_create+=("${ICRN_MANAGER_CONFIG} (file)")
882+
elif [ -n "$overwrite" ]; then
883+
paths_to_overwrite+=("${ICRN_MANAGER_CONFIG} (file - will update central catalog path)")
884+
fi
885+
886+
# Display paths that will be created
887+
if [ ${#paths_to_create[@]} -gt 0 ]; then
888+
echo "Paths that will be CREATED:"
889+
for path in "${paths_to_create[@]}"; do
890+
echo " - $path"
891+
done
892+
echo ""
893+
fi
894+
895+
# Display paths that will be overwritten/modified
896+
if [ ${#paths_to_overwrite[@]} -gt 0 ]; then
897+
echo "Paths that will be MODIFIED:"
898+
for path in "${paths_to_overwrite[@]}"; do
899+
echo " - $path"
900+
done
901+
echo ""
902+
fi
903+
904+
# If nothing will be created or modified, inform user
905+
if [ ${#paths_to_create[@]} -eq 0 ] && [ ${#paths_to_overwrite[@]} -eq 0 ]; then
906+
echo "All required paths already exist. No changes will be made."
907+
echo ""
908+
return 0
909+
fi
910+
911+
# Ask for confirmation
912+
read -r -p "Do you want to proceed with these changes? [y/N] " response
913+
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
914+
echo "Initialization cancelled."
915+
exit 0
916+
fi
917+
echo ""
918+
849919
# check for existence of
850920
#~{HOME}/.icrn/
851921
#~{HOME}/.icrn/icrn_kernels/
@@ -940,6 +1010,32 @@ function kernels__init() # create base resources
9401010
echo ""
9411011
}
9421012

1013+
# Check if initialization is needed and perform it automatically if required
1014+
#
1015+
# This function checks if the ICRN Manager has been initialized by verifying
1016+
# the existence of the manager configuration file. If not initialized, it
1017+
# automatically calls kernels__init with the default central repository path.
1018+
#
1019+
# Parameters:
1020+
# None
1021+
#
1022+
# Returns:
1023+
# 0 if initialization was performed, 1 if already initialized
1024+
#
1025+
# Side effects:
1026+
# - Calls kernels__init() if configuration is missing
1027+
# - Creates user directories and configuration files
1028+
function check_and_init_if_needed()
1029+
{
1030+
if [ ! -e "${ICRN_MANAGER_CONFIG}" ]; then
1031+
echo "ICRN Manager not initialized. Auto-initializing with default settings..."
1032+
echo ""
1033+
kernels__init
1034+
return 0
1035+
fi
1036+
return 1
1037+
}
1038+
9431039
# Main launcher function for kernel management subcommands.
9441040
#
9451041
# This function routes kernel-related subcommands to their respective handler functions.
@@ -961,6 +1057,19 @@ function kernels__init() # create base resources
9611057
function kernels() # launcher
9621058
{
9631059
local cmdname=$1; shift
1060+
1061+
# Auto-initialize if needed (skip for 'init' command itself)
1062+
if [ "$cmdname" != "init" ]; then
1063+
check_and_init_if_needed
1064+
# After auto-init, reload config variables since they may have changed
1065+
if [ -e "${ICRN_MANAGER_CONFIG}" ]; then
1066+
ICRN_KERNEL_REPOSITORY=$(jq -r ".\"icrn_central_catalog_path\"" "${ICRN_MANAGER_CONFIG}")
1067+
ICRN_R_KERNELS=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_r_kernels\"" "${ICRN_MANAGER_CONFIG}")
1068+
ICRN_PYTHON_KERNELS=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_python_kernels\"" "${ICRN_MANAGER_CONFIG}")
1069+
ICRN_KERNEL_CATALOG=${ICRN_KERNEL_REPOSITORY}"/"$(jq -r ".\"icrn_kernel_catalog\"" "${ICRN_MANAGER_CONFIG}")
1070+
fi
1071+
fi
1072+
9641073
if [ -z "$cmdname" ]; then
9651074
echo ""
9661075
echo Error: No subcommand specified.

0 commit comments

Comments
 (0)