+# PA_ADAPTER used for switch between REST and DMAAP
+PA_ADAPTER_TYPE="REST"
+PA_ADAPTER=$PA_PATH
+
+# Make curl retries towards the agent for http response codes set in this env var, space separated list of codes
+AGENT_RETRY_CODES=""
+
+###########################
+### Policy Agents functions
+###########################
+
+# All calls to the agent will be directed to the agent REST interface from now on
+# args: -
+# (Function for test scripts)
+use_agent_rest_http() {
+ echo -e $BOLD"Agent protocol setting"$EBOLD
+ echo -e " Using $BOLD http $EBOLD and $BOLD REST $EBOLD towards the agent"
+ PA_HTTPX="http"
+ PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_PORT
+
+ PA_ADAPTER_TYPE="REST"
+ PA_ADAPTER=$PA_PATH
+ echo ""
+}
+
+# All calls to the agent will be directed to the agent REST interface from now on
+# args: -
+# (Function for test scripts)
+use_agent_rest_https() {
+ echo -e $BOLD"Agent protocol setting"$EBOLD
+ echo -e " Using $BOLD https $EBOLD and $BOLD REST $EBOLD towards the agent"
+ PA_HTTPX="https"
+ PA_PATH=$PA_HTTPX"://"$PA_HOST_NAME":"$POLICY_AGENT_EXTERNAL_SECURE_PORT
+
+ PA_ADAPTER_TYPE="REST"
+ PA_ADAPTER=$PA_PATH
+ echo ""
+}
+
+# All calls to the agent will be directed to the agent dmaap interface over http from now on
+# args: -
+# (Function for test scripts)
+use_agent_dmaap_http() {
+ echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
+ echo -e " Using $BOLD http $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
+ PA_ADAPTER_TYPE="MR-HTTP"
+ echo ""
+}
+
+# All calls to the agent will be directed to the agent dmaap interface over https from now on
+# args: -
+# (Function for test scripts)
+use_agent_dmaap_https() {
+ echo -e $BOLD"Agent dmaap protocol setting"$EBOLD
+ echo -e " Using $BOLD https $EBOLD and $BOLD DMAAP $EBOLD towards the agent"
+ echo -e $YELLOW" Setting http instead of https - MR only uses http"$EYELLOW
+ PA_ADAPTER_TYPE="MR-HTTPS"
+ echo ""
+}
+
+# Start the policy agent
+# args: (docker) PROXY|NOPROXY <config-file>
+# args: (kube) PROXY|NOPROXY <config-file> [ <data-file>]
+# (Function for test scripts)
+start_policy_agent() {
+ echo -e $BOLD"Starting $POLICY_AGENT_DISPLAY_NAME"$EBOLD
+
+ if [ $RUNMODE == "KUBE" ]; then
+
+ # Check if app shall be fully managed by the test script
+ __check_included_image "PA"
+ retcode_i=$?
+
+ # Check if app shall only be used by the testscipt
+ __check_prestarted_image "PA"
+ retcode_p=$?
+
+ if [ $retcode_i -ne 0 ] && [ $retcode_p -ne 0 ]; then
+ echo -e $RED"The $POLICY_AGENT_APP_NAME app is not included as managed nor prestarted in this test script"$ERED
+ echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
+ exit
+ fi
+ if [ $retcode_i -eq 0 ] && [ $retcode_p -eq 0 ]; then
+ echo -e $RED"The $POLICY_AGENT_APP_NAME app is included both as managed and prestarted in this test script"$ERED
+ echo -e $RED"The $POLICY_AGENT_APP_NAME will not be started"$ERED
+ exit
+ fi
+
+ if [ $retcode_p -eq 0 ]; then
+ echo -e " Using existing $POLICY_AGENT_APP_NAME deployment and service"
+ echo " Setting $POLICY_AGENT_APP_NAME replicas=1"
+ __kube_scale deployment $POLICY_AGENT_APP_NAME $KUBE_NONRTRIC_NAMESPACE 1
+ fi
+
+ if [ $retcode_i -eq 0 ]; then
+
+ echo -e " Creating $POLICY_AGENT_APP_NAME app and expose service"
+
+ #Check if nonrtric namespace exists, if not create it
+ __kube_create_namespace $KUBE_NONRTRIC_NAMESPACE
+
+ #Export all vars needed for service and deployment
+ export POLICY_AGENT_APP_NAME
+ export KUBE_NONRTRIC_NAMESPACE
+ export POLICY_AGENT_IMAGE
+ export POLICY_AGENT_INTERNAL_PORT
+ export POLICY_AGENT_INTERNAL_SECURE_PORT
+ export POLICY_AGENT_EXTERNAL_PORT
+ export POLICY_AGENT_EXTERNAL_SECURE_PORT
+ export POLICY_AGENT_CONFIG_MOUNT_PATH
+ export POLICY_AGENT_DATA_MOUNT_PATH
+ export POLICY_AGENT_CONFIG_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-config"
+ export POLICY_AGENT_DATA_CONFIGMAP_NAME=$POLICY_AGENT_APP_NAME"-data"
+ export POLICY_AGENT_PKG_NAME
+ if [ $1 == "PROXY" ]; then
+ AGENT_HTTP_PROXY_CONFIG_PORT=$HTTP_PROXY_CONFIG_PORT #Set if proxy is started
+ AGENT_HTTP_PROXY_CONFIG_HOST_NAME=$HTTP_PROXY_CONFIG_HOST_NAME #Set if proxy is started
+ if [ $AGENT_HTTP_PROXY_CONFIG_PORT -eq 0 ] || [ -z "$AGENT_HTTP_PROXY_CONFIG_HOST_NAME" ]; then
+ echo -e $YELLOW" Warning: HTTP PROXY will not be configured, proxy app not started"$EYELLOW
+ else
+ echo " Configured with http proxy"
+ fi
+ else
+ AGENT_HTTP_PROXY_CONFIG_PORT=0
+ AGENT_HTTP_PROXY_CONFIG_HOST_NAME=""
+ echo " Configured without http proxy"