Skip to content

Commit

Permalink
update khiops-env to display error (#284) (#346)
Browse files Browse the repository at this point in the history
* Update khiops-env to display error on Linux

On Linux, the khiops-env script doesn't print anything in the stdout/err anymore (it is already the case on windows).
It only populates environment variables if possible.
In case of errors (java or mpi) it populates 2 new variables KHIOPS_MPI_ERROR and KHIOPS_JAVA_ERROR

The khiops script use notify-send to diplay errors to users. It implies a new dependency in the khiops package: libnotify on rocky and libnotify-bin on debian.
Errors are also logs into /var/log/syslog by using the 'logger' command.
  • Loading branch information
bruno-at-orange authored Aug 12, 2024
1 parent adcfcc0 commit ed5d7e9
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 57 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pack-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:

build:
runs-on: ubuntu-latest
defaults:
Expand Down Expand Up @@ -77,6 +78,8 @@ jobs:
test:
needs: build
runs-on: ubuntu-latest
env:
DEBIAN_FRONTEND: noninteractive
defaults:
run:
shell: bash
Expand All @@ -103,7 +106,6 @@ jobs:
path: artifacts
- name: Install Khiops core
run: |
export DEBIAN_FRONTEND="noninteractive"
apt-get update
dpkg -i ./artifacts/khiops-core* || true
apt-get -f install -y
Expand All @@ -120,6 +122,8 @@ jobs:
test-kni:
needs: build
runs-on: ubuntu-latest
env:
DEBIAN_FRONTEND: noninteractive
defaults:
run:
shell: bash
Expand Down
68 changes: 62 additions & 6 deletions packaging/linux/common/khiops
Original file line number Diff line number Diff line change
@@ -1,15 +1,71 @@
#!/bin/bash

# Run Khiops tool
# see the khiops_env script for full documentation on the environment variables used by Khiops
# see the khiops-env script for full documentation on the environment variables used by Khiops



error() {
if [ -f /dev/log ]; then
logger "$*" --tag khiops --stderr
fi
if [ -n "$DISPLAY" ]
then
notify-send "Khiops" "$*" -i /usr/share/pixmaps/khiops.png -u normal;
fi
exit 1;
}


warning() {
if [ -f /dev/log ]; then
logger "$*" --tag khiops --stderr
fi
if [ -n "$DISPLAY" ]
then
notify-send "Khiops" "$*" -i /usr/share/pixmaps/khiops.png -u normal;
fi
}

if [[ ! -f /usr/bin/khiops-env ]]; then
echo "/usr/bin/khiops-env is missing"
exit 1
error "/usr/bin/khiops-env is missing"
fi

# initialize Khiops env variables
source /usr/bin/khiops-env --env > /dev/null
# initialize Khiops environment
source /usr/bin/khiops-env

# Test if batch mode from parameters
KHIOPS_BATCH_MODE=false
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "-b" ] || [ ${!i} = "-h" ] || [ ${!i} = "-s" ] || [ ${!i} = "-v" ]; then
KHIOPS_BATCH_MODE=true
break
fi
done;


if [[ ! -e $KHIOPS_PATH/MODL ]]; then
error "Binary not found ($KHIOPS_PATH/MODL)"
fi

# Test multiple possible errors with the java GUI
if [ "$KHIOPS_BATCH_MODE" = false ]; then
if [ -z "$DISPLAY" ]; then
error "GUI is not available, please use the '-b' flag"
elif [ -z "$KHIOPS_JAVA_PATH" ]; then
if [ -z "$KHIOPS_JAVA_ERROR" ]; then
error "The khiops GUI is not configured properly. Please (re)install the 'khiops' package."
else
error "$KHIOPS_JAVA_ERROR"
fi
fi
fi

# Display error with mpi configuration
if [ -n "$KHIOPS_MPI_ERROR" ]; then
warning "$KHIOPS_MPI_ERROR"
fi

export CLASSPATH=$CLASSPATH:$KHIOPS_CLASSPATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$KHIOPS_JAVA_PATH
Expand All @@ -23,4 +79,4 @@ else
$KHIOPS_MPI_COMMAND MODL "$@"
fi

exit $?
exit $?
93 changes: 52 additions & 41 deletions packaging/linux/common/khiops-env.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,49 @@

help()
{
echo "Usage: khiops-env [-h] [--env]"
echo "khiops-env is an internal script intended to be used by Khiops tool and Khiops'"
echo "wrappers only."
echo "Usage: khiops-env [-h, --help] [--env]"
echo "khiops-env is an internal script intended to be used by Khiops tool and Khiops wrappers only."
echo "If the --env flag is used, the environment list is printed in the standard output"
echo
echo "The following variables are used to set the path and classpath"
echo "for the prerequisite of Khiops."
echo "The following variables are used to set the path and classpath for the prerequisite of Khiops."
echo
echo "KHIOPS_PATH: path of Khiops executable, to add in path"
echo "KHIOPS_MPI_COMMAND: MPI command to call the Khiops tool"
echo "KHIOPS_JAVA_PATH: path of Java tool, to add in path"
echo "KHIOPS_CLASSPATH: Khiops java libraries, to add in classpath"
echo
echo "If they are not already defined, the following variables used by"
echo "Khiops are set:"
echo "In case of configuration problems, the variables KHIOPS_JAVA_ERROR and KHIOPS_MPI_ERROR contains error messages"
echo
echo "KHIOPS_LAST_RUN_DIR: directory where Khiops writes output command"
echo " file and log (when not defined with -e and -o)"
echo "KHIOPS_PROC_NUMBER: processes number launched by Khiops (it's"
echo " default value corresponds to the number of physical cores of"
echo " the computer plus one)"
echo "If they are not already defined, the following variables used by Khiops are set:"
echo
echo "The following variables are not defined by default and can be used to"
echo "change some default properties of Khiops:"
echo "KHIOPS_LAST_RUN_DIR: directory where Khiops writes output command file and log"
echo " (when not defined with -e and -o)"
echo "KHIOPS_PROC_NUMBER: processes number launched by Khiops (it's default value corresponds to the"
echo " number of physical cores of the computer plus one)"
echo
echo "KHIOPS_TMP_DIR: Khiops' temporary directory location (default : the"
echo " system default) This location can be modified from the tool as well"
echo "KHIOPS_MEMORY_LIMIT: Khiops' memory limit in MB (default : the system's memory limit)."
echo " The minimum value is 100 MB; this setting is ignored if it is above the system's memory limit."
echo " It can only be reduced from the tool."
echo "The following variables are not defined by default and can be used to change some default"
echo " properties of Khiops:"
echo
echo "KHIOPS_TMP_DIR: Khiops temporary directory location (default: the system default)."
echo " This location can be modified from the tool as well"
echo "KHIOPS_MEMORY_LIMIT: Khiops memory limit in MB (default: the system memory limit)."
echo " The minimum value is 100 MB; this setting is ignored if it is above the system's memory limit."
echo " It can only be reduced from the tool."
echo "KHIOPS_API_MODE: standard or api mode for the management of output result files created by Khiops"
echo " In standard mode, the result files are stored in the train database directory,"
echo " unless an absolute path is specified, and the file extension is forced if necessary."
echo " In api mode, the result files are stored in the current working directory, using the specified results as is."
echo " . default behavior if not set: standard mode"
echo " . set to 'true' to force standard mode"
echo " . set to 'false' to force api mode"
echo "KHIOPS_RAW_GUI: graphical user interface for file name selection"
echo " . default behavior if not set: depending on the file drivers available for Khiops"
echo " . set to 'true' to allow file name selection with uri schemas"
echo " . set to 'false' to allow local file name selection only with a file selection dialog"
}

[[ $# == 0 ]] && help && exit 1
[[ $# == 1 && $1 == "-h" ]] && help && exit 0
[[ $# == 1 && $1 != "--env" ]] && help && exit 1

[[ $# == 1 && $1 == "--help" ]] && help && exit 0

if [[ -z $KHIOPS_LAST_RUN_DIR ]]; then
export KHIOPS_LAST_RUN_DIR=/tmp/khiops/$USER
Expand All @@ -59,18 +62,20 @@ fi

# Set java environment if Khiops GUI is installed
if [ -f "/usr/share/khiops/khiops.jar" ]; then
if [ -z "$JAVA_HOME" ] && [ -f /usr/bin/java ]; then
if [[ -z $JAVA_HOME ]] && [ -f /usr/bin/java ]; then
JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::" )
fi
if [ ! -d "$JAVA_HOME" ]; then
echo "The JAVA_HOME directory doesn't exist (${JAVA_HOME})."
if [[ ! -d $JAVA_HOME ]]; then
KHIOPS_JAVA_ERROR="The JAVA_HOME directory doesn't exist ($JAVA_HOME)."
unset JAVA_HOME
fi
if [ -n "$JAVA_HOME" ]; then
KHIOPS_JAVA_PATH=$(find -L "$JAVA_HOME" -name libjvm.so | xargs dirname)
KHIOPS_CLASSPATH=/usr/share/khiops/norm.jar:/usr/share/khiops/khiops.jar
else
echo "Java not found. Khiops cannot launch a graphical interface. Please install a Java Runtime Environment (>= 1.8)."
JVM_PATH=$(find -L "$JAVA_HOME" -name libjvm.so 2> /dev/null )
if [[ -z $JVM_PATH ]]; then
KHIOPS_JAVA_ERROR="libjvm.so not found in JAVA_HOME ($JAVA_HOME)"
else
KHIOPS_JAVA_PATH=$(dirname "$JVM_PATH")
KHIOPS_CLASSPATH=/usr/share/khiops/norm.jar:/usr/share/khiops/khiops.jar
fi
fi
fi

Expand All @@ -85,8 +90,8 @@ if command -v mpiexec &> /dev/null
then
KHIOPS_MPI_COMMAND="mpiexec @KHIOPS_MPI_EXTRA_FLAG@ @MPIEXEC_NUMPROC_FLAG@ $KHIOPS_PROC_NUMBER"
else
echo "We didn't find mpiexec in the regular path. Parallel computation is unavailable: Khiops is launched in serial"
KHIOPS_MPI_COMMAND=""
KHIOPS_MPI_ERROR="We didn't find mpiexec in the regular path. Parallel computation is unavailable: Khiops is launched in serial"
KHIOPS_MPI_COMMAND=""
fi

# without more than 2 procs, we use the serial khiops
Expand All @@ -96,12 +101,18 @@ fi

KHIOPS_PATH=/usr/bin

echo KHIOPS_PATH "$KHIOPS_PATH"
echo KHIOPS_MPI_COMMAND "$KHIOPS_MPI_COMMAND"
echo KHIOPS_JAVA_PATH "$KHIOPS_JAVA_PATH"
echo KHIOPS_CLASSPATH "$KHIOPS_CLASSPATH"
echo KHIOPS_LAST_RUN_DIR "$KHIOPS_LAST_RUN_DIR"
echo KHIOPS_PROC_NUMBER "$KHIOPS_PROC_NUMBER"
echo KHIOPS_TMP_DIR "$KHIOPS_TMP_DIR"
echo KHIOPS_MEMORY_LIMIT "$KHIOPS_MEMORY_LIMIT"

if [ "$1" = "--env" ];
then
echo KHIOPS_PATH "$KHIOPS_PATH"
echo KHIOPS_MPI_COMMAND "$KHIOPS_MPI_COMMAND"
echo KHIOPS_JAVA_PATH "$KHIOPS_JAVA_PATH"
echo KHIOPS_CLASSPATH "$KHIOPS_CLASSPATH"
echo KHIOPS_LAST_RUN_DIR "$KHIOPS_LAST_RUN_DIR"
echo KHIOPS_PROC_NUMBER "$KHIOPS_PROC_NUMBER"
echo KHIOPS_TMP_DIR "$KHIOPS_TMP_DIR"
echo KHIOPS_MEMORY_LIMIT "$KHIOPS_MEMORY_LIMIT"
echo KHIOPS_API_MODE "$KHIOPS_API_MODE"
echo KHIOPS_RAW_GUI "$KHIOPS_RAW_GUI"
echo KHIOPS_JAVA_ERROR "$KHIOPS_JAVA_ERROR"
echo KHIOPS_MPI_ERROR "$KHIOPS_MPI_ERROR"
fi
62 changes: 55 additions & 7 deletions packaging/linux/common/khiops_coclustering
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@
#!/bin/bash

# Run Khiops Coclustering tool
# see the khiops_env script for full documentation on the environment variables used by Khiops Coclustering
# Run Khiops tool
# see the khiops-env script for full documentation on the environment variables used by Khiops



error() {
logger "$*" --tag khiops --stderr
if [ -n "$DISPLAY" ]
then
notify-send "Khiops" "$*" -i /usr/share/pixmaps/khiops.png -u normal;
fi
exit 1;
}


warning() {
logger "$*" --tag khiops --stderr
if [ -n "$DISPLAY" ]
then
notify-send "Khiops" "$*" -i /usr/share/pixmaps/khiops.png -u normal;
fi
}

if [[ ! -f /usr/bin/khiops-env ]]; then
echo "/usr/bin/khiops-env is missing"
exit 1
error "/usr/bin/khiops-env is missing"
fi

# initialize Khiops environment
source /usr/bin/khiops-env ""

# Test if batch mode from parameters
KHIOPS_BATCH_MODE=false
for ((i=1;i<=$#;i++));
do
if [ ${!i} = "-b" ] || [ ${!i} = "-h" ] || [ ${!i} = "-s" ] || [ ${!i} = "-v" ]; then
KHIOPS_BATCH_MODE=true
break
fi
done;


if [[ ! -e $KHIOPS_PATH/MODL_Coclustering ]]; then
error "Binary not found ($KHIOPS_PATH/MODL_Coclustering)"
fi

# Test multiple possible errors with the java GUI
if [ "$KHIOPS_BATCH_MODE" = false ]; then
if [ -z "$DISPLAY" ]; then
error "GUI is not available, please use the '-b' flag"
elif [ -z "$KHIOPS_JAVA_PATH" ]; then
if [ -z "$KHIOPS_JAVA_ERROR" ]; then
error "The khiops GUI is not configured properly. Please (re)install the 'khiops' package."
else
error "$KHIOPS_JAVA_ERROR"
fi
fi
fi

# initialize Khiops env variables
source /usr/bin/khiops-env --env > /dev/null

export CLASSPATH=$CLASSPATH:$KHIOPS_CLASSPATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$KHIOPS_JAVA_PATH
Expand All @@ -23,4 +71,4 @@ else
MODL_Coclustering "$@"
fi

exit $?
exit $?
4 changes: 2 additions & 2 deletions packaging/packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ elseif("${MPI_IMPL}" STREQUAL "intel")
set(CPACK_DEBIAN_KHIOPS_CORE_PACKAGE_DEPENDS "intel-hpckit")
endif()
set(CPACK_DEBIAN_KHIOPS_PACKAGE_DEPENDS
"khiops-core (=${KHIOPS_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}), default-jre (>=1.8)")
"khiops-core (=${KHIOPS_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}), default-jre (>=1.8), libnotify-bin")
set(CPACK_DEBIAN_KNI_TRANSFER_PACKAGE_DEPENDS "kni (=${KHIOPS_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE})")

# packages recommends
Expand Down Expand Up @@ -175,7 +175,7 @@ set(CPACK_RPM_KHIOPS_CORE_PACKAGE_OBSOLETES "khiops-core <= 10.2.1-2")

# packages requires
set(CPACK_RPM_KHIOPS_PACKAGE_REQUIRES "khiops-core = ${KHIOPS_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}")
set(CPACK_RPM_KHIOPS_PACKAGE_REQUIRES "java >= 1.8")
set(CPACK_RPM_KHIOPS_PACKAGE_REQUIRES "java >= 1.8, libnotify")
set(CPACK_RPM_KHIOPS_CORE_PACKAGE_REQUIRES "util-linux")
set(CPACK_RPM_KNI_TRANSFER_PACKAGE_REQUIRES "kni")

Expand Down

0 comments on commit ed5d7e9

Please sign in to comment.