Skip to content

Commit

Permalink
Merge pull request #464 from yeunga/cadc-12356
Browse files Browse the repository at this point in the history
Cadc 12356 Add support for desktop-app to Skaha API
  • Loading branch information
brianmajor authored Jul 21, 2023
2 parents 51893f7 + 85744a2 commit e91c3a2
Show file tree
Hide file tree
Showing 27 changed files with 992 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ LABEL io.k8s.description="Headless VNC Container with Xfce window manager, firef
io.openshift.non-scalable=true

# BM: Install fonts so remote displays work
RUN yum update -y && yum install -y xorg-x11-fonts* gedit rsync gimp gimp-gmic
RUN yum update -y && yum install -y xorg-x11-fonts* gedit rsync gimp gimp-gmic gnome-terminal epel-release
RUN yum update -y && yum install -y jq

## Connection ports for controlling the UI:
# VNC port:5901
Expand Down
2 changes: 1 addition & 1 deletion containers/session-containers/skaha-desktop/VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## deployable containers have a semantic and build tag
# semantic version tag: major.minor
# build version tag: timestamp
TAGS="1.0.2 $(date -u +"%Y%m%dT%H%M%S")"
TAGS="1.1.0 $(date -u +"%Y%m%dT%H%M%S")"
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,25 @@
</Or>
<Not><Category>Settings</Category></Not>
<Not><Category>Screensaver</Category></Not>
<Not><Category>TerminalEmulator</Category></Not>
<Not><Filename>gpk-application.desktop</Filename></Not>
<Not><Filename>gpk-update-viewer.desktop</Filename></Not>
<Not><Filename>xfce4-session-logout.desktop</Filename></Not>
</And>
</Include>
<Exclude>
<Or>
<Filename>xfce4-session-logout.desktop</Filename>
</Or>
</Exclude>
</Menu>

<Menu>
<Name>Other</Name>
<Directory>xfce-other.directory</Directory>
<OnlyUnallocated/>
<Include>
<All/>
<And>
<Or>
<All/>
</Or>
<Not><Category>TerminalEmulator</Category></Not>
</And>
</Include>
</Menu>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ init () {
mkdir -p ${XFCE_DESKTOP_DIR_PARENT}
ln -s ${DESKTOP_DIR} ${XFCE_DESKTOP_DIR}
fi

# sleep-forever.sh is used on desktop-app start up, refer to start-software-sh.template
cp /skaha-system/sleep-forever.sh ${EXECUTABLE_DIR}/.
}

build_resolution_items () {
Expand Down Expand Up @@ -131,11 +134,15 @@ build_menu_item () {
name=$2
category=$3
executable="${EXECUTABLE_DIR}/${name}.sh"
start_executable="${EXECUTABLE_DIR}/start-${name}.sh"
desktop="${DESKTOP_DIR}/${name}.desktop"
cp ${STARTUP_DIR}/software-sh.template $executable
cp ${STARTUP_DIR}/start-software-sh.template ${start_executable}
cp ${STARTUP_DIR}/software-category.template $desktop
sed -i -e "s#(IMAGE_ID)#${image_id}#g" $executable
sed -i -e "s#(NAME)#${name}#g" $executable
sed -i -e "s#(IMAGE_ID)#${image_id}#g" ${start_executable}
sed -i -e "s#(NAME)#${name}#g" ${start_executable}
sed -i -e "s#(NAME)#${name}#g" $desktop
sed -i -e "s#(EXECUTABLE)#${EXECUTABLE_DIR}#g" $desktop
sed -i -e "s#(CATEGORY)#${category}#g" $desktop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# sleep forever
while true; do
sleep 1000
done
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

/opt/shibboleth/bin/curl -v -L -k -E ${HOME}/.ssl/cadcproxy.pem -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://${skaha_hostname}/skaha/v0/session/${VNC_PW}/app
gnome-terminal -q --title="(NAME) launcher" -- ${HOME}/.local/skaha/bin/start-(NAME).sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/bin/bash

handle_error() {
echo "$1"
echo "Please enter Ctl+C when you are ready to exit the xterm."
${HOME}/.local/skaha/bin/sleep-forever.sh &
wait
exit 1
}

get_resource_options() {
resources=`curl -s -L -k -E ${HOME}/.ssl/cadcproxy.pem https://${skaha_hostname}/skaha/v0/context`
core_default=`echo $resources | jq .defaultCores`
core_options=`echo $resources | jq .availableCores[] | tr '\n' ' '`
ram_default=`echo $resources | jq .defaultRAM`
ram_options=`echo $resources | jq .availableRAM[] | tr '\n' ' '`
}

get_cores() {
local core_list=( ${core_options} )
for v in "${core_list[@]}"; do
local core_map[$v]=1
done

cores=${core_default}
local c=0
read -p "Please enter the number of cores (${core_options}) [${core_default}]: " input_cores
while (( c < 3 )); do
if [[ -z "${input_cores}" ]]; then
cores=${core_default}
echo "${cores}"
break
elif [[ -n "${core_map[${input_cores}]}" ]]; then
cores=${input_cores}
break
else
read -p "Please enter the number of cores (${core_options}) [${core_default}]: " input_cores
c=$(( c + 1 ))
fi
done

if (( c > 2 )); then
handle_error "Failed to get the number of cores from user."
fi
}

get_ram() {
local ram_list=( ${ram_options} )
for v in "${ram_list[@]}"; do
local ram_map[$v]=1
done

ram=${ram_default}
local c=0
read -p "Please enter the amount of memory in GB (${ram_options}) [${ram_default}]: " input_ram
while (( c < 3 )); do
if [[ -z "${input_ram}" ]]; then
ram=${ram_default}
echo "${ram}"
break
elif [[ -n "${ram_map[${input_ram}]}" ]]; then
ram=${input_ram}
break
else
read -p "Please enter the amount of memory in GB (${ram_options}) [${ram_default}]: " input_ram
c=$(( c + 1 ))
fi
done

if (( c > 2 )); then
handle_error "Failed to get the amount of ram from user."
fi
}

prompt_user() {
while true; do
read -p "Do you want to specify resources for (NAME)? (y/n) [n]" yn
if [[ -z "${yn}" || ${yn} == "n" || ${yn} == "N" ]]; then
echo "Launching (NAME)..."
app_id=`curl -s -L -k -E ${HOME}/.ssl/cadcproxy.pem -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://${skaha_hostname}/skaha/v0/session/${VNC_PW}/app`
break
elif [[ ${yn} == "y" || ${yn} == "Y" ]]; then
get_resource_options || handle_error "Error obtaining resource defaults or options."
get_cores || handle_error "Error obtaining the number of cores to allocate."
get_ram || handle_error "Error obtaining the amount of ram to allocate."
echo "Launching (NAME)..."
app_id=`curl -s -L -k -E ${HOME}/.ssl/cadcproxy.pem -d "cores=${cores}" -d "ram=$ram" -d "image=(IMAGE_ID)" --data-urlencode "param=(NAME)" https://${skaha_hostname}/skaha/v0/session/${VNC_PW}/app`
break
else
echo invalid response
fi
done
}

launch_app() {
get_resource_options || handle_error "Error obtaining resource defaults or options."
prompt_user || handle_error "Error prompting user inputs."
}

get_status() {
curl_out=""
status=""
local n=0
sleep 1
curl_out=`curl -s -L -k -E ${HOME}/.ssl/cadcproxy.pem https://${skaha_hostname}/skaha/v0/session/${VNC_PW}/app/$1`
while [[ ${curl_out} != *"status"* ]]; do
n=$(( n + 1 ))
if test $n -eq 10 ; then
echo "Failed to get status, ${curl_out}, retrying..."
n=0
fi
sleep 1
curl_out=`curl -s -L -k -E ${HOME}/.ssl/cadcproxy.pem https://${skaha_hostname}/skaha/v0/session/${VNC_PW}/app/$1`
done
}

check_status() {
get_status $1
status=`echo ${curl_out} | jq .status`
echo "status: ${status}"
local count=0
while [[ ${status} == *"Pending"* ]]
do
count=$(( $count + 1 ))
get_status $1
status=`echo ${curl_out} | jq .status`
if test $count -eq 10 ; then
echo "status: ${status}"
count=0
fi
done

if [[ ${status} == *"Running"* ]]; then
echo "Successfully launched app."
sleep 1
else
handle_error "Failed to launch app, status is ${status}."
fi
}

launch_app
check_status ${app_id}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ configMapGenerator:
files:
- config/start-desktop.sh
- config/build-menu.sh
- config/sleep-forever.sh
- name: templates
files:
- config/templates/skaha-resolutions.properties
- config/templates/xfce-directory.template
- config/templates/xfce-applications-menu-item.template
- config/templates/software-sh.template
- config/templates/start-software-sh.template
- config/templates/software-category.template
- config/templates/resolution-sh.template
- config/templates/resolution-desktop.template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ ca.nrc.cadc.auth.PrincipalExtractor.enableClientCertHeader=true
ca.nrc.cadc.util.Log4jInit.messageOnly=true
# (default: ca.nrc.cadc.auth.NoOpIdentityManager)
ca.nrc.cadc.auth.IdentityManager=ca.nrc.cadc.auth.ACIdentityManager

Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Defines the resources available to science containers
###

# Default number of cores when not specified
# Default number of requested cores when not specified
cores-default-request = 1

# Default maximum number of cores when not specified
cores-default-limit = 16

# Default number of cores (request=limit) when not specified
cores-default = 2

# Default cores for headless jobs
cores-default-headless = 1

# Default memory (RAM) in GB when not specified
# Default requested memory (RAM) in GB when not specified
mem-gb-default-request = 4

# Default maximum memory (RAM) in GB when not specified
mem-gb-default-limit = 192

# Default memory (RAM) in GB (request=limit) when not specified
mem-gb-default = 16

# Default RAM for headless jobs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Job
metadata:
labels:
canfar-net-sessionID: "${skaha.sessionid}"
canfar-net-appID: "${software.appid}"
canfar-net-sessionType: "${skaha.sessiontype}"
canfar-net-userid: "${skaha.userid}"
name: "${software.jobname}"
Expand All @@ -14,6 +15,7 @@ spec:
metadata:
labels:
canfar-net-sessionID: "${skaha.sessionid}"
canfar-net-appID: "${software.appid}"
canfar-net-sessionType: "${skaha.sessiontype}"
canfar-net-userid: "${skaha.userid}"
job-name: "${software.jobname}"
Expand Down Expand Up @@ -51,12 +53,12 @@ spec:
imagePullPolicy: Always
resources:
requests:
memory: "4Gi"
cpu: "1"
memory: "${software.requests.ram}"
cpu: "${software.requests.cores}"
ephemeral-storage: "20Gi"
limits:
memory: "192Gi"
cpu: "16"
memory: "${software.limits.ram}"
cpu: "${software.limits.cores}"
ephemeral-storage: "200Gi"
ports:
- containerPort: 6000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
value: "ivo://cadc.nrc.ca/gms?skaha-users"
- name: skaha.adminsgroup
value: "ivo://cadc.nrc.ca/gms?skaha-admins"
image: images.canfar.net/skaha-system/skaha:0.11.1
image: images.canfar.net/skaha-system/skaha:0.12.0
imagePullPolicy: Always
#imagePullPolicy: IfNotPresent
name: skaha-tomcat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Defines the resources available to science containers
###

# Default number of cores when not specified
# Default number of requested cores when not specified
cores-default-request = 1

# Default maximum number of cores when not specified
cores-default-limit = 8

# Default number of cores (request=limit) when not specified
cores-default = 2

# Default cores for headless jobs
cores-default-headless = 1

# Default memory (RAM) in GB when not specified
# Default requested memory (RAM) in GB when not specified
mem-gb-default-request = 4

# Default maximum memory (RAM) in GB when not specified
mem-gb-default-limit = 192

# Default memory (RAM) in GB (request=limit) when not specified
mem-gb-default = 16

# Default RAM for headless jobs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: Job
metadata:
labels:
canfar-net-sessionID: "${skaha.sessionid}"
canfar-net-appID: "${software.appid}"
canfar-net-sessionType: "${skaha.sessiontype}"
canfar-net-userid: "${skaha.userid}"
name: "${software.jobname}"
Expand All @@ -14,6 +15,7 @@ spec:
metadata:
labels:
canfar-net-sessionID: "${skaha.sessionid}"
canfar-net-appID: "${software.appid}"
canfar-net-sessionType: "${skaha.sessiontype}"
canfar-net-userid: "${skaha.userid}"
job-name: "${software.jobname}"
Expand Down Expand Up @@ -51,12 +53,12 @@ spec:
imagePullPolicy: Always
resources:
requests:
memory: "4Gi"
cpu: "1"
memory: "${software.requests.ram}"
cpu: "${software.requests.cores}"
ephemeral-storage: "20Gi"
limits:
memory: "192Gi"
cpu: "8"
memory: "${software.limits.ram}"
cpu: "${software.limits.cores}"
ephemeral-storage: "200Gi"
ports:
- containerPort: 6000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
value: "345600"
- name: skaha.defaultquotagb
value: "10"
image: images-rc.canfar.net/skaha-system/skaha:0.11.1
image: images-rc.canfar.net/skaha-system/skaha:0.12.0
resources:
requests:
memory: "4Gi"
Expand Down
2 changes: 1 addition & 1 deletion skaha/VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## deployable containers have a semantic and build tag
# semantic version tag: major.minor
# build version tag: timestamp
TAGS="0.11.1 $(date -u +"%Y%m%dT%H%M%S")"
TAGS="0.12.0 $(date -u +"%Y%m%dT%H%M%S")"
Loading

0 comments on commit e91c3a2

Please sign in to comment.