<commit_before>#!/bin/bash

set -o errexit

# Functions

# Iterates over active containers and prints their logs to stdout
function print_docker_logs() {
    echo -e "\n\nSomething went wrong... Printing logs of active containers:\n"
    docker ps | sed -n '1!p' > /tmp/containers.txt
    while read field1 field2 field3; do
      echo -e "\n\nContainer name [$field2] with id [$field1] logs: \n\n"
      docker logs --tail=$NUMBER_OF_LINES_TO_LOG -t $field1
    done < /tmp/containers.txt
    echo -e "\n\nApps logs"
    echo -e "\n\nBrewing"
    tail -n $NUMBER_OF_LINES_TO_LOG build/brewing.log || echo "Failed to open log"
    echo -e "\n\nZuul"
    tail -n $NUMBER_OF_LINES_TO_LOG build/zuul.log || echo "Failed to open log"
    echo -e "\n\Presenting"
    tail -n $NUMBER_OF_LINES_TO_LOG build/presenting.log || echo "Failed to open log"
    echo -e "\n\nConfig Server"
    tail -n $NUMBER_OF_LINES_TO_LOG build/config-server.log || echo "Failed to open log"
    echo -e "\n\nEureka"
    tail -n $NUMBER_OF_LINES_TO_LOG build/eureka.log || echo "Failed to open log"
    echo -e "\n\nZipkin Server"
    tail -n $NUMBER_OF_LINES_TO_LOG build/zipkin-server.log || echo "Failed to open log"
}

# ${RETRIES} number of times will try to netcat to passed port $1 and host $2
function netcat_port() {
    local PASSED_HOST="${2:-$HEALTH_HOST}"
    local READY_FOR_TESTS=1
    for i in $( seq 1 "${RETRIES}" ); do
        sleep "${WAIT_TIME}"
        nc -v -z -w 1 $PASSED_HOST $1 && READY_FOR_TESTS=0 && break
        echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds"
    done
    return $READY_FOR_TESTS
}

# ${RETRIES} number of times will try to curl to /health endpoint to passed port $1 and host $2
function curl_health_endpoint() {
    local PASSED_HOST="${2:-$HEALTH_HOST}"
    local READY_FOR_TESTS=1
    for i in $( seq 1 "${RETRIES}" ); do
        sleep "${WAIT_TIME}"
        curl -m 5 "${PASSED_HOST}:$1/health" && READY_FOR_TESTS=0 && break
        echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds"
    done
    return $READY_FOR_TESTS
}

# ${RETRIES} number of times will try to curl to /health endpoint to passed port $1 and localhost
function curl_local_health_endpoint() {
    curl_health_endpoint $1 "127.0.0.1"
}

# Runs the `java -jar` for given application $1 and system properties $2
function java_jar() {
    local APP_JAVA_PATH=$1/build/libs
    local EXPRESSION="nohup $JAVA_HOME/bin/java $2 $MEM_ARGS -jar $APP_JAVA_PATH/*.jar >$APP_JAVA_PATH/nohup.log &"
    eval $EXPRESSION
    pid=$!
    echo $pid > $APP_JAVA_PATH/app.pid
    echo -e "\nJust started [$EXPRESSION]"
    echo -e "[$1] process pid is [$pid]"
    echo -e "System props are [$2]"
    echo -e "Logs are under [$1.log] or here from nohup $APP_JAVA_PATH/nohup.log\n"
    return 0
}

# Starts the main brewery apps with given system props $1
function start_brewery_apps() {
    local REMOTE_DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address"
    java_jar "presenting" "$1 $REMOTE_DEBUG=8991"
    java_jar "brewing" "$1 $REMOTE_DEBUG=8992"
    java_jar "zuul" "$1 $REMOTE_DEBUG=8993"
    return 0
}

# Kills all started aps
function kill_all_apps() {
    kill -9 `jps | grep "brewing" | cut -d " " -f 1` || echo "Can't find brewing in running processes"
    kill -9 `jps | grep "zuul" | cut -d " " -f 1`  || echo "Can't find zuul in running processes"
    kill -9 `jps | grep "presenting" | cut -d " " -f 1`  || echo "Can't find presenting in running processes"
    kill -9 `jps | grep "config-server" | cut -d " " -f 1` || echo "Can't find config-server in running processes"
    kill -9 `jps | grep "eureka" | cut -d " " -f 1` || echo "Can't find eureka in running processes"
    kill -9 `jps | grep "zipkin-server" | cut -d " " -f 1` || echo "Can't find zipkin-server in running processes"
    docker kill $(docker ps -q) || echo "No running docker containers are left"
    return 0
}

# Kills all started aps if the switch is on
function kill_all_apps_if_switch_on() {
    if [[ $KILL_AT_THE_END ]]; then
        echo -e "\n\nKilling all the apps"
        kill_all_apps
    fi
    return 0
}

# Variables
REPO_URL="${REPO_URL:-https://github.com/spring-cloud-samples/brewery.git}"
REPO_BRANCH="${REPO_BRANCH:-master}"
if [[ -d acceptance-tests ]]; then
  REPO_LOCAL="${REPO_LOCAL:-.}"
else
  REPO_LOCAL="${REPO_LOCAL:-brewery}"
fi
WAIT_TIME="${WAIT_TIME:-5}"
RETRIES="${RETRIES:-70}"<commit_msg>Added one more debug info for Bamboo<commit_after>#!/bin/bash

set -o errexit

# Functions

# Iterates over active containers and prints their logs to stdout
function print_docker_logs() {
    echo -e "\n\nSomething went wrong... Printing logs of active containers:\n"
    docker ps | sed -n '1!p' > /tmp/containers.txt
    while read field1 field2 field3; do
      echo -e "\n\nContainer name [$field2] with id [$field1] logs: \n\n"
      docker logs --tail=$NUMBER_OF_LINES_TO_LOG -t $field1
    done < /tmp/containers.txt
    echo -e "\n\nApps logs"
    echo -e "\n\nBrewing"
    tail -n $NUMBER_OF_LINES_TO_LOG build/brewing.log || echo "Failed to open log"
    echo -e "\n\nZuul"
    tail -n $NUMBER_OF_LINES_TO_LOG build/zuul.log || echo "Failed to open log"
    echo -e "\n\Presenting"
    tail -n $NUMBER_OF_LINES_TO_LOG build/presenting.log || echo "Failed to open log"
    echo -e "\n\nConfig Server"
    tail -n $NUMBER_OF_LINES_TO_LOG build/config-server.log || echo "Failed to open log"
    echo -e "\n\nEureka"
    tail -n $NUMBER_OF_LINES_TO_LOG build/eureka.log || echo "Failed to open log"
    echo -e "\n\nZipkin Server"
    tail -n $NUMBER_OF_LINES_TO_LOG build/zipkin-server.log || echo "Failed to open log"
}

# ${RETRIES} number of times will try to netcat to passed port $1 and host $2
function netcat_port() {
    local PASSED_HOST="${2:-$HEALTH_HOST}"
    local READY_FOR_TESTS=1
    for i in $( seq 1 "${RETRIES}" ); do
        sleep "${WAIT_TIME}"
        nc -v -z -w 1 $PASSED_HOST $1 && READY_FOR_TESTS=0 && break
        echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds"
    done
    return $READY_FOR_TESTS
}

# ${RETRIES} number of times will try to curl to /health endpoint to passed port $1 and host $2
function curl_health_endpoint() {
    local PASSED_HOST="${2:-$HEALTH_HOST}"
    local READY_FOR_TESTS=1
    for i in $( seq 1 "${RETRIES}" ); do
        sleep "${WAIT_TIME}"
        curl -m 5 "${PASSED_HOST}:$1/health" && READY_FOR_TESTS=0 && break
        echo "Fail #$i/${RETRIES}... will try again in [${WAIT_TIME}] seconds"
    done
    return $READY_FOR_TESTS
}

# ${RETRIES} number of times will try to curl to /health endpoint to passed port $1 and localhost
function curl_local_health_endpoint() {
    curl_health_endpoint $1 "127.0.0.1"
}

# Runs the `java -jar` for given application $1 and system properties $2
function java_jar() {
    local APP_JAVA_PATH=$1/build/libs
    local EXPRESSION="nohup $JAVA_HOME/bin/java $2 $MEM_ARGS -jar $APP_JAVA_PATH/*.jar >$APP_JAVA_PATH/nohup.log &"
    eval $EXPRESSION
    pid=$!
    echo $pid > $APP_JAVA_PATH/app.pid
    echo -e "\nJust started [$EXPRESSION]"
    echo -e "[$1] process pid is [$pid]"
    echo -e "System props are [$2]"
    echo -e "Logs are under [$1.log] or here from nohup $APP_JAVA_PATH/nohup.log\n"
    return 0
}

# Starts the main brewery apps with given system props $1
function start_brewery_apps() {
    local REMOTE_DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address"
    java_jar "presenting" "$1 $REMOTE_DEBUG=8991"
    java_jar "brewing" "$1 $REMOTE_DEBUG=8992"
    java_jar "zuul" "$1 $REMOTE_DEBUG=8993"
    return 0
}

# Kills all started aps
function kill_all_apps() {
    kill -9 `jps | grep "brewing" | cut -d " " -f 1` || echo "Can't find brewing in running processes"
    kill -9 `jps | grep "zuul" | cut -d " " -f 1`  || echo "Can't find zuul in running processes"
    kill -9 `jps | grep "presenting" | cut -d " " -f 1`  || echo "Can't find presenting in running processes"
    kill -9 `jps | grep "config-server" | cut -d " " -f 1` || echo "Can't find config-server in running processes"
    kill -9 `jps | grep "eureka" | cut -d " " -f 1` || echo "Can't find eureka in running processes"
    kill -9 `jps | grep "zipkin-server" | cut -d " " -f 1` || echo "Can't find zipkin-server in running processes"
    docker kill $(docker ps -q) || echo "No running docker containers are left"
    return 0
}

# Kills all started aps if the switch is on
function kill_all_apps_if_switch_on() {
    if [[ $KILL_AT_THE_END ]]; then
        echo -e "\n\nKilling all the apps"
        kill_all_apps
    else
        echo -e "\n\nNo switch to kill the apps turned on"
        return 0
    fi
    return 0
}

# Variables
REPO_URL="${REPO_URL:-https://github.com/spring-cloud-samples/brewery.git}"
REPO_BRANCH="${REPO_BRANCH:-master}"
if [[ -d acceptance-tests ]]; then
  REPO_LOCAL="${REPO_LOCAL:-.}"
else
  REPO_LOCAL="${REPO_LOCAL:-brewery}"
fi
WAIT_TIME="${WAIT_TIME:-5}"
RETRIES="${RETRIES:-70}"
{'fraction_non_alphanumeric': 0.13255555555555557, 'fraction_numerical': 0.01633333333333333, 'mean_word_length': 3.2437529467232435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1365696', 'n_tokens_mistral': 3393, 'n_tokens_neox': 3238, 'n_words': 1018}