This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add server subcommand and gldserver module (#1292)
* (#1277) Added additional check and errors for non-SPCT transformers that are connected to triplex_node objects, or have an "S" phase. (#1281) (#37) Migration of fix from gridlabd issue 1432 Co-authored-by: Frank Tuffner <francis.tuffner@pnnl.gov> * Add server python module * Update Makefile.mk * Fix naming conflict. * Fix resource warning (one of two) * Update server.cpp * Update object.cpp * Update gridlabd-server * Update gldserver.py * Update gldserver.py * Update gridlabd-server * Update Makefile.am * Update gridlabd-server * Update regulator.cpp * Update server.cpp * Update gldserver.py --------- Co-authored-by: Frank Tuffner <francis.tuffner@pnnl.gov>
- Loading branch information
Showing
9 changed files
with
695 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
#!/bin/bash | ||
## GridLAB-D server control | ||
## | ||
## Syntax: gridlabd server COMMAND | ||
## | ||
## Commands: | ||
## | ||
## start [-p|--port PORT] [-d|--detach] OPTIONS | ||
## | ||
## stop|halt|shutdown|kill PORT|all | ||
## | ||
## list [PORT|all] | ||
## | ||
## log PORT | ||
## | ||
## status [-c|--continuous] [PORT|all] | ||
## | ||
## The `gridlabd server` commands controls a server in the background. This is | ||
## contrast to the `gridlabd --server` command which does not detach the | ||
## process from the current process after it is launched. | ||
## | ||
## All servers are identified by their port number. The default port number is | ||
## 6267 and incremented automatically is already in use. The maximum number | ||
## of server that can be started automatically is 10. | ||
## | ||
## The `start` command requires the GridLAB-D command line options to be | ||
## provided. | ||
## | ||
## The `stop`, `halt`, `shutdown`, and `kill` commands correspond to the | ||
## GridLAB-D server control commands. See [[GLM/Server]] for details. | ||
## | ||
## The `list` command outputs a list of active servers. The `status` command | ||
## outputs the status of active servers. | ||
## | ||
## The server status can be one of the following: | ||
## | ||
## INIT initialization in progress | ||
## RUNNING simulation running | ||
## PAUSED simulation paused | ||
## DONE simulation done | ||
## LOCKED simulation locked for concurrency | ||
## NOREPLY simulation server not responding to control commands | ||
## | ||
## See also: | ||
## | ||
## [[GLM/Server]] | ||
## | ||
|
||
E_OK=0 | ||
E_FAILED=1 | ||
E_INVALID=2 | ||
E_MISSING=3 | ||
E_NOTFOUND=4 | ||
E_SYNTAX=9 | ||
|
||
TIMEOUT=10 | ||
MAXPORTS=10 | ||
LOGFILE=/tmp/gridlabd-server | ||
|
||
function error () | ||
{ | ||
RC=$1 | ||
shift 1 | ||
echo "ERROR [gridlabd-server]: $*" > /dev/stderr | ||
exit $RC | ||
} | ||
|
||
function getport () | ||
{ | ||
if [ $# -eq 0 ]; then | ||
PORT=6267 | ||
while [ ! -z "$(curl -s http://localhost:$PORT/raw/mainloop_state 2>/dev/null)" ]; do | ||
PORT=$(($PORT+1)) | ||
done | ||
echo $PORT | ||
else | ||
echo $(($1+6266)) | ||
fi | ||
} | ||
|
||
function getstatus() | ||
{ | ||
for P in $(list $*); do | ||
echo $P $(curl -s http://localhost:$P/raw/mainloop_state 2>/dev/null || echo "NOREPLY") | ||
done | ||
|
||
} | ||
|
||
function waitport () | ||
{ | ||
for P in $(list $*); do | ||
T=0 | ||
while [ ! -z "$(curl -s http://localhost:$P/raw/mainloop_state 2>/dev/null)" ]; do | ||
sleep 1 | ||
T=$(($T+1)) | ||
if [ $T -gt $TIMEOUT ]; then | ||
error E_FAILED "wait on port $P timeout" | ||
fi | ||
done | ||
done | ||
} | ||
|
||
function list () | ||
{ | ||
if [ $# -gt 0 ]; then | ||
for P in $*; do | ||
curl -s http://localhost:$P/raw/mainloop_state >/dev/null && echo $P | ||
done | ||
else | ||
P=0 | ||
while [ $P -lt $MAXPORTS ]; do | ||
PORT=$(($P+6267)) | ||
curl -s http://localhost:$PORT/raw/mainloop_state >/dev/null && echo $PORT | ||
P=$(($P+1)) | ||
done | ||
fi | ||
} | ||
|
||
# catch no args | ||
if [ $# -eq 0 ]; then | ||
grep '^## ' $0 | cut -c4- | grep '^Syntax: ' > /dev/stderr | ||
exit $E_SYNTAX | ||
fi | ||
|
||
# process args | ||
case $1 in | ||
help | --help | -h ) | ||
grep '^## ' $0 | cut -c4- | ||
;; | ||
start ) | ||
shift 1 | ||
while [ -z "$OK" ]; do | ||
case $1 in | ||
-p | --port ) | ||
PORT=$2 | ||
shift 2 | ||
;; | ||
-d | --detach ) | ||
DETACH=yes | ||
shift 1 | ||
;; | ||
-l | --logfile ) | ||
LOG=$2 | ||
shift 2 | ||
;; | ||
* ) | ||
OK=yes | ||
;; | ||
esac | ||
done | ||
if [ -z "$PORT" ]; then | ||
PORT=$(getport) | ||
echo $PORT | ||
fi | ||
if [ -z "$LOG" ]; then | ||
LOG=$LOGFILE-$PORT.log | ||
elif [ "$LOG" = "-" ]; then | ||
LOG=/dev/stderr | ||
fi | ||
rm -f $LOG | ||
gridlabd --server -D server_portnum=$PORT $* 1>$LOG 2>&1 & | ||
sleep 1 | ||
if [ ! -z "$!" ] ; then | ||
if [ ! -z "$DETACH" ]; then | ||
disown %1 | ||
fi | ||
else | ||
error $E_FAILED "unable to start server for port $PORT" | ||
fi | ||
;; | ||
stop | halt | shutdown | kill ) | ||
if [ -z "$2" ]; then | ||
error $E_MISSING "missing port number" | ||
elif [ "$2" = "all" ]; then | ||
PORTLIST=$(list) | ||
else | ||
PORTLIST=$* | ||
fi | ||
for PORT in $PORTLIST; do | ||
curl -s http://localhost:$PORT/control/$1 | ||
done | ||
waitport $PORTLIST | ||
;; | ||
list ) | ||
shift 1 | ||
list $* | ||
;; | ||
log ) | ||
shift 1 | ||
if [ $# -eq 0 ]; then | ||
error $E_MISSING "missing port number" | ||
elif [ ! -f $LOGFILE-$1.log ]; then | ||
error $E_NOTFOUND "no log found for port $1" | ||
fi | ||
echo 'INFO [gridlabd-server]: created '$(stat -f %SB -t "%Y-%m-%d %H:%M:%S %Z" $LOGFILE-$1.log) | ||
cat $LOGFILE-$1.log | ||
if [ -z "$(getstatus $1)" ]; then | ||
echo 'INFO [gridlabd-server]: stopped '$(stat -f %Sm -t "%Y-%m-%d %H:%M:%S %Z" $LOGFILE-$1.log) | ||
else | ||
echo 'INFO [gridlabd-server]: updated '$(stat -f %Sm -t "%Y-%m-%d %H:%M:%S %Z" $LOGFILE-$1.log) | ||
fi | ||
;; | ||
status ) | ||
shift 1 | ||
if [ "$1" = "-c" -o "$1" = "--continuous" ]; then | ||
shift 1 | ||
while [ true ]; do | ||
clear | ||
echo "Server Last update Status Options" | ||
echo "------ ------------------- ---------- --------------------" | ||
for P in $(list $*); do | ||
printf '%6.6s %19.19s %10.10s %s\n' "$P" "$(stat -f %Sm -t "%Y-%m-%d %H:%M:%S" $LOGFILE-$P.log)" "$(curl -s http://localhost:$P/raw/mainloop_state 2>/dev/null || echo 'NOREPLY')" "$(curl -s http://localhost:$P/raw/command_line 2>/dev/null | cut -f5- -d' ')" | ||
done | ||
echo "" | ||
echo "Press Ctrl-C to quit" | ||
sleep 1 | ||
done | ||
else | ||
getstatus $* | ||
fi | ||
;; | ||
* ) | ||
error $E_INVALID "'$1' is an invalid gridlabd-server command" | ||
;; | ||
esac | ||
exit $E_OK | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.