#!/bin/bash -e
#
# Apache v2 license
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

OPTION=${1:-tls_off_1_node_django}
WORKLOAD=${WORKLOAD:-django}
NODES=$(echo ${OPTION%_gated*}|cut -d_ -f3)
ATTEMPT=${ATTEMPT:-1}
SIEGE_WORKER=${SIEGE_WORKER:-}
DURATION=${DURATION:-1}
UWSGI_WORKER=${UWSGI_WORKER:-}
MEMCACHE_THREAD=${MEMCACHE_THREAD:-2}
MEMCACHE_MEMORY=${MEMCACHE_MEMORY:-5120}
CASSANDRA_CR=${CASSANDRA_CR:-128}
CASSANDRA_CW=${CASSANDRA_CW:-64}
CASSANDRA_CCW=${CASSANDRA_CCW:-128}
CASSANDRA_JAVA_XMX=${CASSANDRA_JAVA_XMX:-'16g'}
CASSANDRA_JAVA_XMS=${CASSANDRA_JAVA_XMS:-'16g'}
CASSANDRA_JAVA_XMN=${CASSANDRA_JAVA_XMN:-'14g'}
IMARCH=""
#USE_OPTIMIZED_PARAM=${USE_OPTIMIZED_PARAM:-false}

echo $WORKER
if [ $(echo ${OPTION%_gated*}|cut -d_ -f2) == "off" ]; then
  TLS="0"
else
  TLS="1"
fi

if [[ "$IMAGEARCH" != "linux/amd64" ]]; then
    IMARCH="-${IMAGEARCH/*\//}"
fi

# Logs Setting
DIR="$( cd "$( dirname "$0" )" &> /dev/null && pwd )"
. "$DIR/../../script/overwrite.sh"

# Workload Setting
WORKLOAD_PARAMS=(NODES TLS ATTEMPT SIEGE_WORKER DURATION UWSGI_WORKER MEMCACHE_THREAD MEMCACHE_MEMORY CASSANDRA_CR CASSANDRA_CW CASSANDRA_CCW CASSANDRA_JAVA_XMX CASSANDRA_JAVA_XMS CASSANDRA_JAVA_XMN)

# Docker Setting
DOCKER_IMAGE=""
DOCKER_OPTIONS=""

# Kubernetes Setting
RECONFIG_OPTIONS="-DNODES=$NODES -DTLS=$TLS -DATTEMPT=$ATTEMPT -DSIEGE_WORKER=$SIEGE_WORKER -DIMARCH=$IMARCH -DDURATION=$DURATION -DUWSGI_WORKER=$UWSGI_WORKER -DMEMCACHE_THREAD=$MEMCACHE_THREAD -DMEMCACHE_MEMORY=$MEMCACHE_MEMORY -DCASSANDRA_CR=$CASSANDRA_CR -DCASSANDRA_CW=$CASSANDRA_CW -DCASSANDRA_CCW=$CASSANDRA_CCW"
JOB_FILTER="job-name=benchmark"

. "$DIR/../../script/validate.sh"
