[SDFAB-933] Integrate atomix-3.1.12 and expose demote API

Additionally, this patch adds unit tests for demote and
updates a bunch of testing tools

Change-Id: I9636078b08486c9167ae253f0251f72239ad2802
diff --git a/tools/build/bazel/generate_workspace.bzl b/tools/build/bazel/generate_workspace.bzl
index 6892ac7..7c80fee 100644
--- a/tools/build/bazel/generate_workspace.bzl
+++ b/tools/build/bazel/generate_workspace.bzl
@@ -145,45 +145,45 @@
     if "atomix" not in native.existing_rules():
         java_import_external(
             name = "atomix",
-            jar_sha256 = "e4700e1acf329747fc41f49279d9066c368877f1381f609fcb4c0ce63824e0c6",
+            jar_sha256 = "d5163b005977b5da5f27835af528fce4a71127a1c795f5350f05a5767324e019",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix/3.1.9/atomix-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix/3.1.12/atomix-3.1.12.jar"],        )
     if "atomix_cluster" not in native.existing_rules():
         java_import_external(
             name = "atomix_cluster",
-            jar_sha256 = "38c3ee00cdc48fa00012c543abbd7cf5975568233ce25dbbb7d4c422b7579b57",
+            jar_sha256 = "4e3cbd01f23414934ffe5ccfafa0b16d4009c3d497390fcf8711236f6055fda2",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-cluster/3.1.9/atomix-cluster-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-cluster/3.1.12/atomix-cluster-3.1.12.jar"],        )
     if "atomix_primary_backup" not in native.existing_rules():
         java_import_external(
             name = "atomix_primary_backup",
-            jar_sha256 = "f87527364ac10e006b714f55ce1a6d92a1f27fa27e8813de82454665876838d6",
+            jar_sha256 = "afa5191c3a1ab79e007c208c9ef44f4b7c6e0904a1d7f576200d3cacd90c3f4b",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-primary-backup/3.1.9/atomix-primary-backup-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-primary-backup/3.1.12/atomix-primary-backup-3.1.12.jar"],        )
     if "atomix_primitive" not in native.existing_rules():
         java_import_external(
             name = "atomix_primitive",
-            jar_sha256 = "12c7ff4e65ad683419906d86d320250ce4ea160fbb394b90a577116563cb81b4",
+            jar_sha256 = "a2a4002824db7b80308f8cedd83a5abe67ebdb9723b6c50fa99ab935c49c2641",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-primitive/3.1.9/atomix-primitive-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-primitive/3.1.12/atomix-primitive-3.1.12.jar"],        )
     if "atomix_raft" not in native.existing_rules():
         java_import_external(
             name = "atomix_raft",
-            jar_sha256 = "69a3188bc34d5f5629b6321be04c10ca3064faecbb6d139015c1fd5bcaac713f",
+            jar_sha256 = "9583123d7cfc60edb786964087b92f568aafdf00be1b52d4e4737a6cf9d4ca31",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-raft/3.1.9/atomix-raft-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-raft/3.1.12/atomix-raft-3.1.12.jar"],        )
     if "atomix_storage" not in native.existing_rules():
         java_import_external(
             name = "atomix_storage",
-            jar_sha256 = "a049ae8a671bcacea4cbc8db31e78aa8c4f0bca4b3871929e06644d70d33e857",
+            jar_sha256 = "d81895846ca70202f38a13c9627b8fc3674e363a3670f7f1221e5444188bbaf3",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-storage/3.1.9/atomix-storage-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-storage/3.1.12/atomix-storage-3.1.12.jar"],        )
     if "atomix_utils" not in native.existing_rules():
         java_import_external(
             name = "atomix_utils",
-            jar_sha256 = "dba1d7b0fa900f39cee3160045e3cd624ffcaf18f9756fdadadb1c876ef331e0",
+            jar_sha256 = "8d8b177488bf7665e008e892b33a5fbde92d6233dc83cf350d51f6bc3f5344d8",
             licenses = ["notice"],
-            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-utils/3.1.9/atomix-utils-3.1.9.jar"],        )
+            jar_urls = ["https://repo1.maven.org/maven2/io/atomix/atomix-utils/3.1.12/atomix-utils-3.1.12.jar"],        )
     if "classgraph" not in native.existing_rules():
         java_import_external(
             name = "classgraph",
@@ -1484,13 +1484,13 @@
 artifact_map["@aopalliance_repackaged//:aopalliance_repackaged"] = "mvn:org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42"
 artifact_map["@amqp_client//:amqp_client"] = "mvn:com.rabbitmq:amqp-client:jar:3.6.1"
 artifact_map["@asm//:asm"] = "mvn:org.ow2.asm:asm:jar:5.2"
-artifact_map["@atomix//:atomix"] = "mvn:io.atomix:atomix:jar:3.1.9"
-artifact_map["@atomix_cluster//:atomix_cluster"] = "mvn:io.atomix:atomix-cluster:jar:3.1.9"
-artifact_map["@atomix_primary_backup//:atomix_primary_backup"] = "mvn:io.atomix:atomix-primary-backup:jar:3.1.9"
-artifact_map["@atomix_primitive//:atomix_primitive"] = "mvn:io.atomix:atomix-primitive:jar:3.1.9"
-artifact_map["@atomix_raft//:atomix_raft"] = "mvn:io.atomix:atomix-raft:jar:3.1.9"
-artifact_map["@atomix_storage//:atomix_storage"] = "mvn:io.atomix:atomix-storage:jar:3.1.9"
-artifact_map["@atomix_utils//:atomix_utils"] = "mvn:io.atomix:atomix-utils:jar:3.1.9"
+artifact_map["@atomix//:atomix"] = "mvn:io.atomix:atomix:jar:3.1.12"
+artifact_map["@atomix_cluster//:atomix_cluster"] = "mvn:io.atomix:atomix-cluster:jar:3.1.12"
+artifact_map["@atomix_primary_backup//:atomix_primary_backup"] = "mvn:io.atomix:atomix-primary-backup:jar:3.1.12"
+artifact_map["@atomix_primitive//:atomix_primitive"] = "mvn:io.atomix:atomix-primitive:jar:3.1.12"
+artifact_map["@atomix_raft//:atomix_raft"] = "mvn:io.atomix:atomix-raft:jar:3.1.12"
+artifact_map["@atomix_storage//:atomix_storage"] = "mvn:io.atomix:atomix-storage:jar:3.1.12"
+artifact_map["@atomix_utils//:atomix_utils"] = "mvn:io.atomix:atomix-utils:jar:3.1.12"
 artifact_map["@classgraph//:classgraph"] = "mvn:io.github.classgraph:classgraph:jar:4.2.3"
 artifact_map["@commons_codec//:commons_codec"] = "mvn:commons-codec:commons-codec:jar:1.10"
 artifact_map["@commons_cli//:commons_cli"] = "mvn:commons-cli:commons-cli:jar:1.3"
diff --git a/tools/dev/docker/Dockerfile-sshd b/tools/dev/docker/Dockerfile-sshd
index 2229787..6f0c00c 100644
--- a/tools/dev/docker/Dockerfile-sshd
+++ b/tools/dev/docker/Dockerfile-sshd
@@ -2,9 +2,9 @@
 LABEL maintainer="Eric Tang <qcorba at gmail.com>"
 
 ARG ATOMIX_VERSION
-ENV ENV_ATOMIX_VERSION=${ATOMIX_VERSION:-3.1.9}
+ENV ENV_ATOMIX_VERSION=${ATOMIX_VERSION:-3.1.12}
 
-RUN apt-get update 
+RUN apt-get update
 RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \
     --no-install-recommends \
     openjdk-11-jre \
@@ -66,7 +66,7 @@
 
 # Install Atomix
 RUN set -eux; \
-#   curl -o /tmp/atomix.tar.gz -XGET https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/3.1.9/atomix-dist-3.1.9.tar.gz; \
+#   curl -o /tmp/atomix.tar.gz -XGET https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/3.1.12/atomix-dist-3.1.12.tar.gz; \
     curl -o /tmp/atomix.tar.gz https://repo1.maven.org/maven2/io/atomix/atomix-dist/$ENV_ATOMIX_VERSION/atomix-dist-$ENV_ATOMIX_VERSION.tar.gz; \
     mkdir /opt/atomix; \
     tar zxmf /tmp/atomix.tar.gz -C /opt/atomix; \
diff --git a/tools/test/bin/atomix-push-bits b/tools/test/bin/atomix-push-bits
index d82321c..5eb9191 100755
--- a/tools/test/bin/atomix-push-bits
+++ b/tools/test/bin/atomix-push-bits
@@ -26,7 +26,7 @@
 
 . $ONOS_ROOT/tools/build/envDefaults
 
-ATOMIX_VERSION=${ATOMIX_VERSION:-3.1.9}
+ATOMIX_VERSION=${ATOMIX_VERSION:-3.1.12}
 ATOMIX_MAVEN=~/.m2/repository/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz
 ATOMIX_LOCAL=/tmp/atomix-$ATOMIX_VERSION.tar.gz
 ATOMIX_REMOTE=https://oss.sonatype.org/content/repositories/releases/io/atomix/atomix-dist/$ATOMIX_VERSION/atomix-dist-$ATOMIX_VERSION.tar.gz
diff --git a/tools/test/bin/atomix-service b/tools/test/bin/atomix-service
index 5910a8c..8eb6a5e 100755
--- a/tools/test/bin/atomix-service
+++ b/tools/test/bin/atomix-service
@@ -40,11 +40,9 @@
 fi
 
 # Define the java options for atomix
-# FIXME atomix-agent already provides a gc algorithm. Once we fix atomix-agent we can allow this
-# JAVA_OPTS="${JAVA_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200}"
+JAVA_OPTS="${JAVA_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200}"
 if [ ! -z "$ONOS_YOURKIT" ]; then
-    #JAVA_OPTS+=" -agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all"
-    JAVA_OPTS="${JAVA_OPTS:--agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all}"
+    JAVA_OPTS+=" -agentpath:$ATOMIX_INSTALL_DIR/libyjpagent.so=listen=all"
 fi
 
 case $2 in
diff --git a/tools/test/scenarios/odtn/createOdtnCell.sh b/tools/test/scenarios/odtn/createOdtnCell.sh
index 8e5f74d..fcb81ba 100755
--- a/tools/test/scenarios/odtn/createOdtnCell.sh
+++ b/tools/test/scenarios/odtn/createOdtnCell.sh
@@ -16,7 +16,7 @@
 echo "The public key in local host is: $SSH_KEY"
 
 # Create Atomix cluster using Atomix docker image
-ATOMIX_IMAGE=atomix/atomix:3.1.9
+ATOMIX_IMAGE=atomix/atomix:3.1.12
 for i in {1..3}; do
     echo "Setting up atomix-$i..."
     docker container run --detach --name atomix-$i --hostname atomix-$i \