#! /bin/bash
. acsstartupAcsPorts
#--------------------------------------
CL_RHOST=

# These options can be recognized (longopts comma-separated. colon means argument is required)
LONGOPTS=help,rhost:
SHORTOPTS=h

# Usage info. Be nice and keep this up-to-date!
function printUsage {
   echo "Runs component performance tests"
   echo ""
	echo "Usage: `basename $0` [OPTIONS] "
	echo "Options: "
	echo "   -rhost remote_host        remote host"
   echo "   -h | -help                     prints this help and exits"
}

# Run getopt (posixly_correct needed). We run twice:
# First run is simply to check the commandline for correctness
# Second run is the real deal which replaces the command line args with getopt's output
export POSIXLY_CORRECT=1

getopt -n `basename $0` -Q -u -a -l $LONGOPTS $SHORTOPTS "$@" || {
   printUsage
	exit 43;
}

set -- `getopt -u -a -l $LONGOPTS $SHORTOPTS "$@"`

# Iterate over getopt's output and set CL_XXX variables accordingly
while : 
do
	case "$1" in
	--rhost)            CL_RHOST=$2 ; shift ;;
	--help)             CL_HELP=true ;; 
	-h)                 CL_HELP=true ;; 
	--) break ;;
	esac
	shift
done
shift

# must be unset! otherwise our custom export() function
# that is defined below doesn't get used by the shell
export POSIXLY_CORRECT=
unset POSIXLY_CORRECT

if [ "$CL_HELP" ] ; then
   printUsage
   exit 0
fi
#--------------------------------------
rm -rf $ACS_TMP
mkdir $ACS_TMP

if [ ! $CL_RHOST ]
then
    export DATABASE=../doc/compMethod.dbm
    export OUT_HTML=../doc/ComponentMethodPerf.html
else
    export DATABASE=../doc/remoteCompMethod.dbm
    export OUT_HTML=../doc/RemoteComponentMethodPerf.html
fi


#Startup services/manager
acsutilTATPrologue

export ACS_INSTANCE=`cat $ACS_TMP/acs_instance` 

#Startup containers
if [ ! $CL_RHOST ]
then
    acsStartContainer -cpp  bilboContainer >& $ACS_TMP/bilboContainer.log&
    sleep 15

    acsStartContainer -java  frodoContainer >& $ACS_TMP/frodoContainer.log&
    sleep 15

    acsStartContainer -py  aragornContainer >& $ACS_TMP/aragornContainer.log&
    sleep 15
else
    export MANAGER_REFERENCE=corbaloc::`getIP`:`getManagerPort`/Manager


    echo "Starting remote containers on '$CL_RHOST'. It may be necessary to enter a password here..."
    (ssh -f $USER@$CL_RHOST acsStartContainer -cpp -m $MANAGER_REFERENCE  bilboContainer) >& $ACS_TMP/bilboContainer.log
    sleep 15

    (ssh -f $USER@$CL_RHOST acsStartContainer -java -m $MANAGER_REFERENCE frodoContainer) >& $ACS_TMP/frodoContainer.log
    sleep 15

    (ssh -f $USER@$CL_RHOST acsStartContainer -py -m $MANAGER_REFERENCE aragornContainer) >& $ACS_TMP/aragornContainer.log
    sleep 15
fi

#-------------------------------------------------------
echo "C++ Generic method invocation from Python"
componentsClientTestPy SBC01 100 method\(\) "Invocation Time of a Simple (C++) Method" >> $ACS_TMP/genCompReport.log
echo "Python Generic method invocation from Python"
componentsClientTestPy SBCPY01 100 method\(\) "Invocation Time of a Simple (Python) Method" >> $ACS_TMP/genCompReport.log
echo "Java Generic method invocation from Python"
componentsClientTestPy SBCJAVA01 100 method\(\) "Invocation Time of a Simple (Java) Method" >> $ACS_TMP/genCompReport.log
echo "C++ Generic method invocation from C++"
componentsClientSimpleTest SBC01 100 "Invocation Time of a Simple (C++) Method" >> $ACS_TMP/genCompReport.log
echo "Python Generic method invocation from C++"
componentsClientSimpleTest SBCPY01 100 "Invocation Time of a Simple (Python) Method" >> $ACS_TMP/genCompReport.log
echo "Java Generic method invocation from C++"
componentsClientSimpleTest SBCJAVA01 100 "Invocation Time of a Simple (Java) Method" >> $ACS_TMP/genCompReport.log
echo "C++ Generic method invocation from Java"
acsStartJava alma.perftest.client.ClientSimpleTest SBC01 100 "Invocation Time of a Simple (C++) Method" >> $ACS_TMP/genCompReport.log
echo "Python Generic method invocation from Java"
acsStartJava alma.perftest.client.ClientSimpleTest SBCPY01 100 "Invocation Time of a Simple (Python) Method" >> $ACS_TMP/genCompReport.log
echo "Java Generic method invocation from Java"
acsStartJava alma.perftest.client.ClientSimpleTest SBCJAVA01 100 "Invocation Time of a Simple (Java) Method" >> $ACS_TMP/genCompReport.log

echo "C++ Method Variable Return Size from C++"
componentsClientMethodTest MTC01 100 1 0 "Invocation Time of (C++) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 5 0 "Invocation Time of (C++) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 10 0 "Invocation Time of (C++) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 20 0 "Invocation Time of (C++) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 100 0 "Invocation Time of (C++) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 1000 0 "Invocation Time of (C++) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 10000 0 "Invocation Time of (C++) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTC01 100 500000 0 "Invocation Time of (C++) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "C++ Method Variable Return Size from Python"
componentsMethodTestPy MTC01 100 1 0 "Invocation Time of (C++) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 5 0 "Invocation Time of (C++) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 10 0 "Invocation Time of (C++) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 20 0 "Invocation Time of (C++) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 100 0 "Invocation Time of (C++) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 1000 0 "Invocation Time of (C++) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 10000 0 "Invocation Time of (C++) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTC01 100 500000 0 "Invocation Time of (C++) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "C++ Method Variable Return Size from Java"
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 1 0 "Invocation Time of (C++) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 5 0 "Invocation Time of (C++) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 10 0 "Invocation Time of (C++) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 20 0 "Invocation Time of (C++) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 100 0 "Invocation Time of (C++) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 1000 0 "Invocation Time of (C++) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 10000 0 "Invocation Time of (C++) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTC01 100 500000 0 "Invocation Time of (C++) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Python Method Variable Return Size from C++"
componentsClientMethodTest MTCPY01 100 1 0 "Invocation Time of (Python) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 5 0 "Invocation Time of (Python) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 10 0 "Invocation Time of (Python) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 20 0 "Invocation Time of (Python) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 100 0 "Invocation Time of (Python) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 1000 0 "Invocation Time of (Python) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 10000 0 "Invocation Time of (Python) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCPY01 100 500000 0 "Invocation Time of (Python) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Python Method Variable Return Size from Python"
componentsMethodTestPy MTCPY01 100 1 0 "Invocation Time of (Python) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 5 0 "Invocation Time of (Python) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 10 0 "Invocation Time of (Python) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 20 0 "Invocation Time of (Python) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 100 0 "Invocation Time of (Python) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 1000 0 "Invocation Time of (Python) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 10000 0 "Invocation Time of (Python) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCPY01 100 500000 0 "Invocation Time of (Python) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Python Method Variable Return Size from Java"
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 1 0 "Invocation Time of (Python) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 5 0 "Invocation Time of (Python) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 10 0 "Invocation Time of (Python) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 20 0 "Invocation Time of (Python) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 100 0 "Invocation Time of (Python) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 1000 0 "Invocation Time of (Python) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 10000 0 "Invocation Time of (Python) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCPY01 100 500000 0 "Invocation Time of (Python) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Java Method Variable Return Size from C++"
componentsClientMethodTest MTCJAVA01 100 1 0 "Invocation Time of (Java) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 5 0 "Invocation Time of (Java) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 10 0 "Invocation Time of (Java) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 20 0 "Invocation Time of (Java) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 100 0 "Invocation Time of (Java) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 1000 0 "Invocation Time of (Java) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 10000 0 "Invocation Time of (Java) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsClientMethodTest MTCJAVA01 100 500000 0 "Invocation Time of (Java) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Java Method Variable Return Size from Python"
componentsMethodTestPy MTCJAVA01 100 1 0 "Invocation Time of (Java) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 5 0 "Invocation Time of (Java) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 10 0 "Invocation Time of (Java) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 20 0 "Invocation Time of (Java) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 100 0 "Invocation Time of (Java) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 1000 0 "Invocation Time of (Java) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 10000 0 "Invocation Time of (Java) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
componentsMethodTestPy MTCJAVA01 100 500000 0 "Invocation Time of (Java) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
echo "Java Method Variable Return Size from Java"
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 1 0 "Invocation Time of (Java) Method Returning 1 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 5 0 "Invocation Time of (Java) Method Returning 5 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 10 0 "Invocation Time of (Java) Method Returning 10 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 20 0 "Invocation Time of (Java) Method Returning 20 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 100 0 "Invocation Time of (Java) Method Returning 100 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 1000 0 "Invocation Time of (Java) Method Returning 1000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 10000 0 "Invocation Time of (Java) Method Returning 10000 Byte(s)" >> $ACS_TMP/genCompReport.log
acsStartJava alma.perftest.client.ClientMethodTest MTCJAVA01 100 500000 0 "Invocation Time of (Java) Method Returning 500000 Byte(s)" >> $ACS_TMP/genCompReport.log
#-------------------------------------------------------
#Stop containers/manager/services
acsStopContainer aragornContainer >& /dev/null
acsStopContainer frodoContainer >& /dev/null
acsStopContainer bilboContainer >& /dev/null
sleep 10
acsutilTATEpilogue

#Give everything time to finish...
sleep 5

#Load the data into the database
ACSPerfAnalyzer $DATABASE $ACS_TMP/bilboContainer.log
ACSPerfAnalyzer $DATABASE $ACS_TMP/frodoContainer.log
ACSPerfAnalyzer $DATABASE $ACS_TMP/aragornContainer.log
ACSPerfAnalyzer $DATABASE $ACS_TMP/genCompReport.log

#Generate HTML report
ACSPerfReportGen $DATABASE > $OUT_HTML
