Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openmpp/main
Browse files Browse the repository at this point in the history
  • Loading branch information
esseff committed Mar 4, 2021
2 parents 8fce11c + b25c384 commit ba7d5dc
Show file tree
Hide file tree
Showing 12 changed files with 30,501 additions and 19,788 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Please note:
not all changes commented here, please use GitHub commits history for more details.

2021_03_02:
make sure model trace file truncated on new model run
add Linux shell script to start ompp_ui
pass browser user language to backend web-service
fix language code bug in openMpp R package
use OS independent build of openMpp R package

2021_02_09:
raise runtime error if entity time uninitialized (non-finite when entering simulation)
fix: c++ compiler error sometimes occurred with min_over, max_over
Expand Down
159 changes: 159 additions & 0 deletions bin/ompp_ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env bash
#
# It does:
# cd $OM_ROOT
# # start oms in a new terminal window:
# gnome-terminal -e "OM_ROOT=$PWD bin/oms -oms.Listen localhost:4040 -oms.LogRequest"
# # open UI in browser:
# xdg-open http://localhost:4040
#
# Environment:
# OM_ROOT - openM++ root folder, default is a parent dir: ..
# OMS_PORT - oms web-service port to listen, default: 4040
# OM_X_TERMINAL - which x-terminal to use, default: x-terminal-emulator or gnome-terminal

# set -e
set -m

# set openM++ root folder
#
self=$(basename $0)

if [ -z "$OM_ROOT" ] ;
then

echo "Set openM++ root directory: OM_ROOT"

if [ -x "${self}" ] ;
then
echo "pushd .."
pushd ..
fi

OM_ROOT="$PWD"

fi

echo "OM_ROOT = $OM_ROOT"

# check if OM_ROOT directory exist
#
if [ ! -d "$OM_ROOT" ] ;
then
echo "ERROR: openM++ directory not exist: $OM_ROOT"
echo -n "Press Enter to exit..."
read any
exit 1
fi

[ "$OM_ROOT" != "$PWD" ] && pushd $OM_ROOT

export OM_ROOT="$PWD"

# check if OM_ROOT is openM++ root
#
if [ ! -x "bin/oms" ] || [ ! -d "log" ] || [ ! -d "models/bin" ] ;
then
echo "ERROR: openM++ UI not found at: $OM_ROOT"
echo -n "Press Enter to exit..."
read any
exit 1
fi

# log configuration
#
OMPP_UI_SH_LOG="${OM_ROOT}/log/${self}.log"

echo "Log: $OMPP_UI_SH_LOG"
echo "OM_ROOT = $OM_ROOT" >"$OMPP_UI_SH_LOG"

# which x-terminal to use: x-terminal-emulator, gnome-terminal, konsole
#
if [ -z "${OM_X_TERMINAL}" ] && command -v x-terminal-emulator >/dev/null 2>&1 ;
then
OM_X_TERMINAL="x-terminal-emulator"
fi
if [ -z "${OM_X_TERMINAL}" ] && command -v xfce4-terminal >/dev/null 2>&1 ;
then
OM_X_TERMINAL="xfce4-terminal"
fi
if [ -z "${OM_X_TERMINAL}" ] && command -v gnome-terminal >/dev/null 2>&1 ;
then
OM_X_TERMINAL="gnome-terminal"
fi
if [ -z "${OM_X_TERMINAL}" ] && command -v konsole >/dev/null 2>&1 ;
then
OM_X_TERMINAL="konsole"
fi
if [ -z "${OM_X_TERMINAL}" ] ;
then
echo "ERROR not found any of: x-terminal-emulator, gnome-terminal, konsole and OM_X_TERMINAL not set" | tee -a "$OMPP_UI_SH_LOG"
echo -n "Press Enter to exit..."
read any
exit 1
fi

# set oms port to listen
#
[ -z "$OMS_PORT" ] && OMS_PORT=4040

export OMS_PORT
echo "OMS_PORT = $OMS_PORT" | tee -a "$OMPP_UI_SH_LOG"

lsof -P -n -iTCP:"$OMS_PORT" -a -sTCP:LISTEN >>"$OMPP_UI_SH_LOG" 2>&1
if [ $? -eq 0 ] ;
then
echo "FAILED to start oms web-service, port in use: OMS_PORT=$OMS_PORT" | tee -a "$OMPP_UI_SH_LOG"
echo "If port $OMS_PORT used by oms web-service then stop it first" | tee -a "$OMPP_UI_SH_LOG"
echo -n "Press Enter to exit..."
read any
exit 2
fi

# start oms web-service
#
status=0

if [ "${OM_X_TERMINAL}" != "konsole" ] ;
then
echo "${OM_X_TERMINAL} -e ./bin/start_oms.sh" | tee -a "$OMPP_UI_SH_LOG"

${OM_X_TERMINAL} -e ./bin/start_oms.sh
status=$?
else
echo bash -c "konsole -e ./bin/start_oms.sh &" | tee -a "$OMPP_UI_SH_LOG"

bash -c "konsole -e ./bin/start_oms.sh &"
status=$?
fi

if [ $status -ne 0 ] ;
then
echo "FAILED to start oms web-service using ${OM_X_TERMINAL}" | tee -a "$OMPP_UI_SH_LOG"
echo -n "Press Enter to exit..."
read any
exit 1
fi
# known issue: test above does not catch exit code of start_oms.sh

# start browser and open UI
#
OMS_URL="http://localhost:${OMS_PORT}"

echo "Open openM++ UI in browser:" | tee -a "$OMPP_UI_SH_LOG"
echo "xdg-open ${OMS_URL}" | tee -a "$OMPP_UI_SH_LOG"

if ! xdg-open "${OMS_URL}" >> "$OMPP_UI_SH_LOG" 2>&1;
then
echo "FAILED to open browser at ${OMS_URL}" | tee -a "$OMPP_UI_SH_LOG"
echo -n "Press Enter to exit..."
read any
exit 7
fi
# known issue: xdg-open may return 0 when it is not able to start browser

echo "Done." | tee -a "$OMPP_UI_SH_LOG"

echo -n "Press Enter to exit..."
read any
exit 0
50 changes: 50 additions & 0 deletions bin/start_oms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# It does:
# OM_ROOT=${OM_ROOT} bin/oms -oms.Listen http://localhost:${OMS_PORT} -oms.LogRequest
#
# Environment:
# OM_ROOT - openM++ root folder, default: current directory
# OMS_PORT - oms web-service port to listen, default: 4040

# set -e
set -m

# set openM++ root folder
#
self=$(basename $0)

if [ -z "$OM_ROOT" ] ;
then

if [ -x "${self}" ] ;
then
echo "pushd .."
pushd ..
fi

OM_ROOT="$PWD"

fi

[ "$OM_ROOT" != "$PWD" ] && pushd $OM_ROOT

# start oms web-service
#
[ -z "$OMS_PORT" ] && OMS_PORT=4040

echo "OM_ROOT=$OM_ROOT ./bin/oms -l localhost:${OMS_PORT} -oms.LogRequest"

OM_ROOT=$OM_ROOT ./bin/oms -l localhost:${OMS_PORT} -oms.LogRequest
status=$?

if [ $status -ne 0 ] ;
then
[ $status -eq 130 ] && echo " oms web-service terminated by Ctrl+C"
[ $status -ne 130 ] && echo " FAILED to start oms web-service"
fi

echo "."
echo -n "Press Enter to exit..."
read any
exit $status
15 changes: 9 additions & 6 deletions models/modelOne/modelOne.ini
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,16 @@ LogToConsole = true ; log to console
; "stamped" name produced from "last run" name by adding time-stamp and/or pid-stamp, i.e.:
; trace.txt => trace.2012_08_17_16_04_59_148.987654.txt
;
; TraceToConsole = true ; log to console
; TraceToFile = true ; log to file
; TraceToStampedFile = true ; log to "stamped" file
; If trace to file is enabled
; then existing "last run" trace file truncated even model does not write anything into trace output
;
; TraceToConsole = false ; log to console
; TraceToFile = false ; log to file
; TraceToStampedFile = false ; log to "stamped" file
; TraceFilePath = trace.txt ; log file path, default: input_set_name.txt
; TraceUseTimeStamp = true ; use time-stamp in log "stamped" file name
; TraceUsePidStamp = true ; use pid-stamp in log "stamped" file name
; TraceNoMsgTime = false ; if true then do not prefix trace messages with date-time
; TraceUseTimeStamp = false ; use time-stamp in log "stamped" file name
; TraceUsePidStamp = false ; use pid-stamp in log "stamped" file name
; TraceNoMsgTime = true ; if true then do not prefix trace messages with date-time

;============================================================================
;
Expand Down
20 changes: 17 additions & 3 deletions models/modelOne/modelOne.message.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
; modelOne localized messages
;
; message search is done by "normalized" language code:
; if user language is fr_CA.UTF-8 then it is "normalized" into: fr-ca
; and if default model language is EN
; then search is done by following sections: fr-CA -> fr -> EN
; both forms: "fr-CA" and "fr_CA.UTF-8" are "normalized" into "fr-ca" and EN into "en"
;
; section name and language code comparison is not case sensitive, for example:
; [fr-CA] is equal to [fr-ca]
;
; message key comparison IS case sensitive,
; for example: "Completed" is NOT the same as "completed"
; and as result below two messages are different:
; Completed = Terminé
; completed = Terminé

[en_CA]
; Running Simulation = (en_CA) Running Simulation
Running simulation = (en_CA) Running simulation

[EN]
; Running Simulation = (en) Running Simulation
Running simulation = (en) Running simulation

[fr-CA]
; Running Simulation = (fr-CA) Running Simulation
Running simulation = (fr-CA) Running simulation

2 changes: 1 addition & 1 deletion models/start-ompp-ui-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# It does:
# cd $OM_ROOT
# # start oms, listen on free port:
# bin/oms -oms.Listen http://localhost:0 .... &
# bin/oms -oms.Listen localhost:0 .... &
# # use lsof to find oms port:
# lsof -i -a -sTCP:LISTEN -a -p $OMS_PID ....
# # write oms URL into file:
Expand Down
2 changes: 1 addition & 1 deletion models/start-ompp-ui-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# It does:
# cd $OM_ROOT
# # start oms, listen on free port:
# bin/oms -oms.Listen http://localhost:0 .... &
# bin/oms -oms.Listen localhost:0 .... &
# # use lsof to find oms port:
# lsof -i -a -sTCP:LISTEN -a -p $OMS_PID ....
# # write oms URL into file:
Expand Down
9 changes: 7 additions & 2 deletions openm/libopenm/common/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ TraceLog::~TraceLog(void) noexcept
catch (...) { }
}

/** re-initialize log file name(s) and other log settings.
/** re-initialize trace file name(s) and other log settings, it is also create or truncate existing trace file.
*
* @param[in] i_logToConsole if true then log to console
* @param[in] i_basePath path to "last" log file, if NULL or empty "" then no log file
* @param[in] i_basePath path to "last" trace file, if NULL or empty "" then no trace file
* @param[in] i_logToFile if true then enable log to "last" file
* @param[in] i_useTimeStamp if true then use timestamp suffix in "stamped" file name
* @param[in] i_usePidStamp if true then use PID suffix in "stamped" file name
Expand All @@ -488,6 +488,11 @@ void TraceLog::init(
) noexcept
{
LogBase::init(i_logToConsole, i_basePath, i_logToFile, i_useTimeStamp, i_usePidStamp, i_noMsgTime);

// create or truncate trace file
if (isLastEnabled && !isLastCreated) {
isLastEnabled = isLastCreated = logFileCreate(lastPath);
}
}

/** log message */
Expand Down
6 changes: 3 additions & 3 deletions openm/libopenm/common/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ namespace openm

~TraceLog(void) noexcept;

/** re-initialize log file name(s) and other log settings.
/** re-initialize trace file name(s) and other log settings, it is also create or truncate existing trace file.
*
* @param[in] i_logToConsole if true then log to console
* @param[in] i_basePath path to "last" log file, if NULL or empty "" then no log file
* @param[in] i_logToConsole if true then trace to console
* @param[in] i_basePath path to "last" trace file, if NULL or empty "" then no trace file
* @param[in] i_logToFile if true then enable log to "last" file
* @param[in] i_useTimeStamp if true then use timestamp suffix in "stamped" file name
* @param[in] i_usePidStamp if true then use PID suffix in "stamped" file name
Expand Down
Loading

0 comments on commit ba7d5dc

Please sign in to comment.