Allow usage of MRI distribution in csit
[releng/builder.git] / jjb / integration / common-functions.sh
index 60aeb0e459a81bb3abbc6d020b2535c3332b1d56..cfd8e39da635c8b36adf41b6380c1e3f4f2b3a56 100644 (file)
@@ -10,7 +10,7 @@ export FEATURESCONF=/tmp/${BUNDLEFOLDER}/etc/org.apache.karaf.features.cfg
 export CUSTOMPROP=/tmp/${BUNDLEFOLDER}/etc/custom.properties
 export LOGCONF=/tmp/${BUNDLEFOLDER}/etc/org.ops4j.pax.logging.cfg
 export MEMCONF=/tmp/${BUNDLEFOLDER}/bin/setenv
-export CONTROLLERMEM="2048m"
+export CONTROLLERMEM=${CONTROLLERMAXMEM}
 
 # Cluster specific configuration settings
 export AKKACONF=/tmp/${BUNDLEFOLDER}/configuration/initial/akka.conf
@@ -83,10 +83,8 @@ function configure_karaf_log() {
     echo "Configuring the karaf log... karaf_version: ${karaf_version}, logapi: ${logapi}"
     if [ "${logapi}" == "log4j2" ]; then
         # FIXME: Make log size limit configurable from build parameter.
-        # From Neon the default karaf file size is 64 MB
+        # Increase default log file size to 1GB
         sed -ie 's/log4j2.appender.rolling.policies.size.size = 64MB/log4j2.appender.rolling.policies.size.size = 1GB/g' "${LOGCONF}"
-        # Flourine still uses 16 MB
-        sed -ie 's/log4j2.appender.rolling.policies.size.size = 16MB/log4j2.appender.rolling.policies.size.size = 1GB/g' "${LOGCONF}"
         orgmodule="org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver"
         orgmodule_="${orgmodule//./_}"
         echo "${logapi}.logger.${orgmodule_}.name = WARN" >> "${LOGCONF}"
@@ -223,6 +221,11 @@ function get_test_suites() {
         testplan_filepath="${WORKSPACE}/test/csit/testplans/${TESTPLAN}"
     fi
 
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        add_test="integration/test/csit/suites/integration/Create_JVM_Plots.robot"
+        echo "${add_test}" >> "$testplan_filepath"
+    fi
+
     echo "Changing the testplan path..."
     sed "s:integration:${WORKSPACE}:" "${testplan_filepath}" > testplan.txt
     cat testplan.txt
@@ -282,6 +285,125 @@ function run_plan() {
     printf "Finished running %s plans\\n" "${type}"
 } # function run_plan()
 
+# Run scripts to support JVM monitoring.
+function add_jvm_support()
+{
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        set_elasticsearch_attribute "${ELASTICSEARCHATTRIBUTE}"
+        set_jvm_common_attribute
+    fi
+} # function add_jvm_support()
+
+#Expected input parameter: long/short/a number
+function set_elasticsearch_attribute()
+{
+short=5000
+long=120000
+default=$short
+
+case $1 in
+short)
+  period=$short
+  ;;
+long)
+  period=$long
+  ;;
+*)
+  # shellcheck disable=SC2166
+  if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge $short -a "$1" -le $long ]; then
+      period=$1
+  else
+      period=$default
+  fi
+  ;;
+esac
+
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.scheduler.simple.cfg <<EOF
+period=$period
+
+EOF
+
+echo "Copying config files to ODL Controller folder"
+
+# shellcheck disable=SC2086
+for i in $(seq 1 ${NUM_ODL_SYSTEM})
+do
+        CONTROLLERIP=ODL_SYSTEM_${i}_IP
+        echo "Set Decanter Polling Period to ${!CONTROLLERIP}"
+        # shellcheck disable=SC2029
+        ssh "${!CONTROLLERIP}" "mkdir -p \"/tmp/${BUNDLEFOLDER}/etc/opendaylight/karaf/\""
+        scp "${WORKSPACE}"/org.apache.karaf.decanter.scheduler.simple.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+done
+} #function set_elasticsearch_attribute
+
+function set_jvm_common_attribute()
+{
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg <<EOF
+type=jmx-local
+url=local
+object.name=java.lang:type=*,name=*
+
+EOF
+
+cat > "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg <<EOF
+type=jmx-local
+url=local
+object.name=java.lang:type=*
+
+EOF
+
+# shellcheck disable=SC2086
+for i in $(seq 1 ${NUM_ODL_SYSTEM})
+do
+    CONTROLLERIP=ODL_SYSTEM_${i}_IP
+
+    cat > "${WORKSPACE}"/elasticsearch.yml <<EOF
+    discovery.zen.ping.multicast.enabled: false
+
+EOF
+
+    cat > "${WORKSPACE}"/elasticsearch_startup.sh <<EOF
+    cd /tmp/elasticsearch/elasticsearch-1.7.5
+    ls -al
+
+    if [ -d "data" ]; then
+        echo "data directory exists, deleting...."
+        rm -r data
+    else
+        echo "data directory does not exist"
+    fi
+
+    cd /tmp/elasticsearch
+    ls -al
+
+    echo "Starting Elasticsearch node"
+    sudo /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch > /dev/null 2>&1 &
+    ls -al /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch
+
+EOF
+    echo "Setup ODL_SYSTEM_IP specific config files for ${!CONTROLLERIP} "
+    cat "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg
+    cat "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg
+    cat "${WORKSPACE}"/elasticsearch.yml
+
+
+    echo "Copying config files to ${!CONTROLLERIP}"
+    scp "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-local.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+    scp "${WORKSPACE}"/org.apache.karaf.decanter.collector.jmx-others.cfg "${!CONTROLLERIP}":/tmp/"${BUNDLEFOLDER}"/etc/
+    scp "${WORKSPACE}"/elasticsearch.yml "${!CONTROLLERIP}":/tmp/
+
+    ssh "${!CONTROLLERIP}" "sudo ls -al /tmp/elasticsearch/"
+    ssh "${!CONTROLLERIP}" "sudo mv /tmp/elasticsearch.yml /tmp/elasticsearch/elasticsearch-1.7.5/config/"
+    ssh "${!CONTROLLERIP}" "cat /tmp/elasticsearch/elasticsearch-1.7.5/config/elasticsearch.yml"
+
+    echo "Copying the elasticsearch_startup script to ${!CONTROLLERIP}"
+    cat "${WORKSPACE}"/elasticsearch_startup.sh
+    scp "${WORKSPACE}"/elasticsearch_startup.sh "${!CONTROLLERIP}":/tmp
+    ssh "${!CONTROLLERIP}" 'bash /tmp/elasticsearch_startup.sh'
+    ssh "${!CONTROLLERIP}" 'ps aux | grep elasticsearch'
+done
+} #function set_jvm_common_attribute
+
 # Return elapsed time. Usage:
 # - Call first time with no arguments and a new timer is returned.
 # - Next call with the first argument as the timer and the elapsed time is returned.
@@ -340,6 +462,7 @@ DISTROSTREAM: ${DISTROSTREAM}
 BUNDLE_URL: ${BUNDLE_URL}
 CONTROLLERFEATURES: ${CONTROLLERFEATURES}
 CONTROLLERDEBUGMAP: ${CONTROLLERDEBUGMAP}
+CONTROLLERMAXMEM: ${CONTROLLERMAXMEM}
 SCRIPTPLAN: ${SCRIPTPLAN}
 CONFIGPLAN: ${CONFIGPLAN}
 STREAMTESTPLAN: ${STREAMTESTPLAN}
@@ -372,6 +495,7 @@ CREATE_INITIAL_NETWORKS: ${CREATE_INITIAL_NETWORKS}
 LBAAS_SERVICE_PROVIDER: ${LBAAS_SERVICE_PROVIDER}
 ODL_SFC_DRIVER: ${ODL_SFC_DRIVER}
 ODL_SNAT_MODE: ${ODL_SNAT_MODE}
+GROUP_ADD_MOD_ENABLED: ${GROUP_ADD_MOD_ENABLED}
 
 EOF
 }
@@ -547,7 +671,7 @@ EOF
         echo "collect_logs: for opendaylight controller ip: ${!CONTROLLERIP}"
         NODE_FOLDER="odl_${i}"
         mkdir -p "${NODE_FOLDER}"
-        echo "Lets's take the karaf thread dump again..."
+        echo "Let's take the karaf thread dump again..."
         ssh "${!CONTROLLERIP}" "sudo ps aux" > "${WORKSPACE}"/ps_after.log
         pid=$(grep org.apache.karaf.main.Main "${WORKSPACE}"/ps_after.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
         echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"
@@ -732,12 +856,26 @@ function get_nodes_list() {
 
 function get_features() {
     if [ "${CONTROLLERSCOPE}" == 'all' ]; then
-        ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
-        export CONTROLLERMEM="3072m"
+        if [ "$KARAF_PROJECT" == "integration" ]; then
+            ACTUALFEATURES="odl-integration-compatible-with-all,${CONTROLLERFEATURES}"
+        else
+            ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
+        fi
+        # if CONTROLLERMEM still is the default 2G and was not overridden by a
+        # custom job, then we need to make sure to increase it because "all"
+        # features can be heavy
+        if [ "${CONTROLLERMEM}" == "2048m" ]; then
+            export CONTROLLERMEM="3072m"
+        fi
     else
         ACTUALFEATURES="odl-infrautils-ready,${CONTROLLERFEATURES}"
     fi
 
+    if [ "${ELASTICSEARCHATTRIBUTE}" != "disabled" ]; then
+        # Add decanter features to allow JVM monitoring
+        ACTUALFEATURES="${ACTUALFEATURES},decanter-collector-jmx,decanter-appender-elasticsearch-rest"
+    fi
+
     # Some versions of jenkins job builder result in feature list containing spaces
     # and ending in newline. Remove all that.
     ACTUALFEATURES=$(echo "${ACTUALFEATURES}" | tr -d '\n \r')
@@ -782,9 +920,12 @@ if [[ "$KARAF_VERSION" == "karaf4" ]]; then
     FEATURE_TEST_STRING="features-test"
 fi
 
-sed -ie "s%\\(featuresRepositories=\\|featuresRepositories =\\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.0.0/xml/features,%g" ${FEATURESCONF}
-if [[ ! -z "${REPO_URL}" ]]; then
-   sed -ie "s%featuresRepositories =%featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
+# only manipulate feature repo in integration distro
+if [[ "$KARAF_PROJECT" == "integration" ]]; then
+       sed -ie "s%\\(featuresRepositories=\\|featuresRepositories =\\)%featuresRepositories = mvn:org.opendaylight.integration/\${FEATURE_TEST_STRING}/${BUNDLE_VERSION}/xml/features,mvn:org.apache.karaf.decanter/apache-karaf-decanter/1.2.0/xml/features,%g" ${FEATURESCONF}
+       if [[ ! -z "${REPO_URL}" ]]; then
+          sed -ie "s%featuresRepositories =%featuresRepositories = ${REPO_URL},%g" ${FEATURESCONF}
+       fi
 fi
 cat ${FEATURESCONF}
 
@@ -832,15 +973,26 @@ EOF
 
 function create_post_startup_script() {
     cat > "${WORKSPACE}"/post-startup-script.sh <<EOF
-if [[ "$USEFEATURESBOOT" != "True" ]]; then
+# wait up to 60s for karaf port 8101 to be opened, polling every 5s
+loop_count=0;
+until [[ \$loop_count -ge 12 ]]; do
+    netstat -na | grep ":::8101" && break;
+    loop_count=\$[\$loop_count+1];
+    sleep 5;
+done
 
-    # wait up to 60s for karaf port 8101 to be opened, polling every 5s
-    loop_count=0;
-    until [[ \$loop_count -ge 12 ]]; do
-        netstat -na | grep 8101 && break;
-        loop_count=\$[\$loop_count+1];
-        sleep 5;
-    done
+# This workaround is required for Karaf decanter to work proper
+# The bundle:refresh command does not fail if the decanter bundles are not present
+# There seems to be impact in silicon stream so we better comment the lines below
+#
+#echo "ssh to karaf console to do bundle refresh of decanter jmx collector"
+#sshpass -p karaf ssh -o StrictHostKeyChecking=no \
+#                     -o UserKnownHostsFile=/dev/null \
+#                     -o LogLevel=error \
+#                     -p 8101 karaf@localhost \
+#                     "bundle:refresh org.apache.karaf.decanter.collector.jmx && bundle:refresh org.apache.karaf.decanter.api"
+
+if [[ "$USEFEATURESBOOT" != "True" ]]; then
 
     echo "going to feature:install --no-auto-refresh ${SPACE_SEPARATED_FEATURES} one at a time"
     for feature in ${SPACE_SEPARATED_FEATURES}; do
@@ -871,7 +1023,7 @@ done;
 
 # if we ended up not finding ready status in the above loop, we can output some debugs
 grep 'org.opendaylight.infrautils.*System ready' /tmp/${BUNDLEFOLDER}/data/log/karaf.log
-if [ $? -ne 0 ]; then
+if [ \$? -ne 0 ]; then
     echo "Timeout Controller DOWN"
     echo "Dumping first 500K bytes of karaf log..."
     head --bytes=500K "/tmp/${BUNDLEFOLDER}/data/log/karaf.log"
@@ -941,12 +1093,10 @@ function copy_and_run_post_startup_script() {
     done
 }
 
-function create_controller_variables() {
-    echo "Generating controller variables..."
+function dump_controller_threads() {
     for i in $(seq 1 "${NUM_ODL_SYSTEM}"); do
         CONTROLLERIP="ODL_SYSTEM_${i}_IP"
-        odl_variables=${odl_variables}" -v ${CONTROLLERIP}:${!CONTROLLERIP}"
-        echo "Lets's take the karaf thread dump"
+        echo "Let's take the karaf thread dump"
         ssh "${!CONTROLLERIP}" "sudo ps aux" > "${WORKSPACE}"/ps_before.log
         pid=$(grep org.apache.karaf.main.Main "${WORKSPACE}"/ps_before.log | grep -v grep | tr -s ' ' | cut -f2 -d' ')
         echo "karaf main: org.apache.karaf.main.Main, pid:${pid}"