<commit_before>#!/bin/bash
#set -x

JOYNR_SOURCE_DIR=""
ILT_BUILD_DIR=""
ILT_RESULTS_DIR=""
while getopts "b:s:r:" OPTIONS;
do
	case $OPTIONS in
		b)
			ILT_BUILD_DIR=$OPTARG
			;;
		r)
			ILT_RESULTS_DIR=$OPTARG
			;;
		s)
			JOYNR_SOURCE_DIR=$OPTARG
			if [ ! -d "$JOYNR_SOURCE_DIR" ]
			then
				echo "Directory $JOYNR_SOURCE_DIR does not exist!"
				exit 1
			else
				echo "JOYNR_SOURCE_DIR=$OPTARG"
			fi
			;;
		\?)
			echo "Illegal option found."
			echo "Synopsis: run-inter-language-tests.sh [-b <joynr-build-dir>] [-r <ilt-results-dir>] [-s <joynr-source-dir>]"
			exit 1
			;;
	esac
done

if [ -z "$JOYNR_SOURCE_DIR" ]
then
	# assume this script is started inside a git repo subdirectory,
	JOYNR_SOURCE_DIR=`git rev-parse --show-toplevel`
fi

ILT_DIR=$JOYNR_SOURCE_DIR/tests/inter-language-test

if [ -z "$ILT_BUILD_DIR" ]
then
	ILT_BUILD_DIR=$ILT_DIR/build
fi

# if CI environment, source global settings
if [ -f /data/scripts/global.sh ]
then
	source /data/scripts/global.sh
fi

if [ -z "$ILT_RESULTS_DIR" ]
then
	ILT_RESULTS_DIR=$ILT_DIR/ilt-results-$(date "+%Y-%m-%d-%H:%M:%S")
fi

# process ids for background stuff
JETTY_PID=""
CLUSTER_CONTROLLER_PID=""
PROVIDER_PID=""

# in case of interrupts, forcibly kill background stuff
function stopall {
	stop_provider
	stop_cluster_controller
	stop_services
	exit 1
}

trap stopall INT

#log "ENVIRONMENT"
#env

SUCCESS=0
FAILED_TESTS=0
DOMAIN="joynr-inter-language-test-domain"

function prechecks {
	if [ ! -f "$ILT_BUILD_DIR/bin/cluster-controller" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_BUILD_DIR/bin/ilt-consumer-cc" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_BUILD_DIR/bin/ilt-provider-cc" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/discovery.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/bounceproxy.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/accesscontrol.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi
}

function start_services {
	cd $ILT_DIR
	rm -f joynr.properties
	rm -f joynr_participantIds.properties
	echo '####################################################'
	echo '# starting services'
	echo '####################################################'
	mvn $SPECIAL_MAVEN_OPTIONS jetty:run-war --quiet > $ILT_RESULTS_DIR/jetty-$1.log 2>&1 &
	JETTY_PID=$!
	echo "Starting Jetty with PID $JETTY_PID"
	# wait until server is up and running or 60 seconds (= 30 * 2) timeout is exceeded
	started=
	count=0
	while [ "$started" != "200" -a "$count" -lt "30" ]
	do
		sleep 2
		started=`curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://localhost:8080/bounceproxy/time/`
		let count+=1
	done
	if [ "$started" != "200" ]
	then
		# startup failed
		stopall
	fi
	echo "Jetty successfully started."
	sleep 5
}

function stop_services {
	if [ -n "$JETTY_PID" ]
	then
		cd $ILT_DIR
		echo '####################################################'
		echo '# stopping services'
		echo '####################################################'
		mvn $SPECIAL_MAVEN_OPTIONS jetty:stop --quiet
		wait $JETTY_PID
		echo "Stopped Jetty with PID $JETTY_PID"
		JETTY_PID=""
	fi
}

function start_cluster_controller {<commit_msg>[ILT] report failed jetty startup<commit_after>#!/bin/bash
#set -x

JOYNR_SOURCE_DIR=""
ILT_BUILD_DIR=""
ILT_RESULTS_DIR=""
while getopts "b:s:r:" OPTIONS;
do
	case $OPTIONS in
		b)
			ILT_BUILD_DIR=$OPTARG
			;;
		r)
			ILT_RESULTS_DIR=$OPTARG
			;;
		s)
			JOYNR_SOURCE_DIR=$OPTARG
			if [ ! -d "$JOYNR_SOURCE_DIR" ]
			then
				echo "Directory $JOYNR_SOURCE_DIR does not exist!"
				exit 1
			else
				echo "JOYNR_SOURCE_DIR=$OPTARG"
			fi
			;;
		\?)
			echo "Illegal option found."
			echo "Synopsis: run-inter-language-tests.sh [-b <joynr-build-dir>] [-r <ilt-results-dir>] [-s <joynr-source-dir>]"
			exit 1
			;;
	esac
done

if [ -z "$JOYNR_SOURCE_DIR" ]
then
	# assume this script is started inside a git repo subdirectory,
	JOYNR_SOURCE_DIR=`git rev-parse --show-toplevel`
fi

ILT_DIR=$JOYNR_SOURCE_DIR/tests/inter-language-test

if [ -z "$ILT_BUILD_DIR" ]
then
	ILT_BUILD_DIR=$ILT_DIR/build
fi

# if CI environment, source global settings
if [ -f /data/scripts/global.sh ]
then
	source /data/scripts/global.sh
fi

if [ -z "$ILT_RESULTS_DIR" ]
then
	ILT_RESULTS_DIR=$ILT_DIR/ilt-results-$(date "+%Y-%m-%d-%H:%M:%S")
fi

# process ids for background stuff
JETTY_PID=""
CLUSTER_CONTROLLER_PID=""
PROVIDER_PID=""

# in case of interrupts, forcibly kill background stuff
function stopall {
	stop_provider
	stop_cluster_controller
	stop_services
	exit 1
}

trap stopall INT

#log "ENVIRONMENT"
#env

SUCCESS=0
FAILED_TESTS=0
DOMAIN="joynr-inter-language-test-domain"

function prechecks {
	if [ ! -f "$ILT_BUILD_DIR/bin/cluster-controller" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_BUILD_DIR/bin/ilt-consumer-cc" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_BUILD_DIR/bin/ilt-provider-cc" ]
	then
		echo 'C++ environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/discovery.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/bounceproxy.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi

	if [ ! -f "$ILT_DIR/target/accesscontrol.war" ]
	then
		echo 'Java environment not built'
		exit 1
	fi
}

function start_services {
	cd $ILT_DIR
	rm -f joynr.properties
	rm -f joynr_participantIds.properties
	echo '####################################################'
	echo '# starting services'
	echo '####################################################'
	mvn $SPECIAL_MAVEN_OPTIONS jetty:run-war --quiet > $ILT_RESULTS_DIR/jetty-$1.log 2>&1 &
	JETTY_PID=$!
	echo "Starting Jetty with PID $JETTY_PID"
	# wait until server is up and running or 60 seconds (= 30 * 2) timeout is exceeded
	started=
	count=0
	while [ "$started" != "200" -a "$count" -lt "30" ]
	do
		sleep 2
		started=`curl -o /dev/null --silent --head --write-out '%{http_code}\n' http://localhost:8080/bounceproxy/time/`
		let count+=1
	done
	if [ "$started" != "200" ]
	then
		echo "Starting Jetty FAILED"
		# startup failed
		stopall
	fi
	echo "Jetty successfully started."
	sleep 5
}

function stop_services {
	if [ -n "$JETTY_PID" ]
	then
		cd $ILT_DIR
		echo '####################################################'
		echo '# stopping services'
		echo '####################################################'
		mvn $SPECIAL_MAVEN_OPTIONS jetty:stop --quiet
		wait $JETTY_PID
		echo "Stopped Jetty with PID $JETTY_PID"
		JETTY_PID=""
	fi
}

function start_cluster_controller {
{'fraction_non_alphanumeric': 0.18203628729944518, 'fraction_numerical': 0.01049632628579997, 'mean_word_length': 3.9297856614929785, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5007784', 'n_tokens_mistral': 2787, 'n_tokens_neox': 2499, 'n_words': 634}