+install_sdnr_northbound_features() {
+ addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
+}
+
+# Reconfigure ODL from default single node configuration to cluster
+
+enable_odl_cluster() {
+ if [ -z "$SDNC_REPLICAS" ]; then
+ printf "SDNC_REPLICAS is not configured in Env field"
+ exit
+ fi
+
+ # ODL NETCONF setup
+ printf "Installing Opendaylight cluster features for mdsal and netconf\n"
+
+ #Be sure to remove feature odl-netconf-connector-all from list
+ replaceFeatureBoot "odl-netconf-connector-all,"
+
+ printf "Installing Opendaylight cluster features\n"
+ replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
+ replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
+ addToFeatureBoot odl-jolokia
+ #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
+ #${ODL_HOME}/bin/client feature:install odl-jolokia
+
+ # ODL Cluster or Geo cluster configuration
+
+ printf "Update cluster information statically\n"
+ fqdn=$(hostname -f)
+ printf "%s\n" "Get current fqdn ${fqdn}"
+
+ # Extract node index using first digit after "-"
+ # Example 2 from "sdnr-2.logo.ost.das.r32.com"
+ node_index=$(echo "${fqdn}" | sed -r 's/.*-([0-9]).*/\1/g')
+ member_offset=1
+
+ if $GEO_ENABLED; then
+ printf "This is a Geo cluster\n"
+
+ if [ -z "$IS_PRIMARY_CLUSTER" ] || [ -z "$MY_ODL_CLUSTER" ] || [ -z "$PEER_ODL_CLUSTER" ]; then
+ printf "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field\n"
+ return
+ fi
+
+ if $IS_PRIMARY_CLUSTER; then
+ PRIMARY_NODE=${MY_ODL_CLUSTER}
+ SECONDARY_NODE=${PEER_ODL_CLUSTER}
+ else
+ PRIMARY_NODE=${PEER_ODL_CLUSTER}
+ SECONDARY_NODE=${MY_ODL_CLUSTER}
+ member_offset=4
+ fi
+
+ node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
+
+ "${SDNC_BIN}"/configure_geo_cluster.sh $((node_index+member_offset)) "${node_list}"
+ else
+ printf "This is a local cluster\n"
+ i=0
+ node_list=""
+ # SERVICE_NAME and NAMESPACE are used to create cluster node names and are provided via Helm charts in OOM environment
+ if [ ! -z "$SERVICE_NAME" ] && [ ! -z "$NAMESPACE" ]; then
+ # Extract node name minus the index
+ # Example sdnr from "sdnr-2.logo.ost.das.r32.com"
+ node_name=$(echo "${fqdn}" | sed 's/-[0-9].*$//g')
+ while [ $i -lt "$SDNC_REPLICAS" ]; do
+ node_list="${node_list} ${node_name}-$i.${SERVICE_NAME}-cluster.${NAMESPACE}"
+ i=$(($i + 1))
+ done
+ "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
+ elif [ -z "$SERVICE_NAME" ] && [ -z "$NAMESPACE" ]; then
+ # Hostname is used in Standalone environment to create cluster node names
+ while [ $i -lt "$SDNC_REPLICAS" ]; do
+ #assemble node list by replacing node-index in hostname with "i"
+ node_name=$(echo "${fqdn}" | sed -r "s/-[0-9]/-$i/g")
+ node_list="${node_list} ${node_name}"
+ i=$(($i + 1))
+ done
+ "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
+ else
+ printf "Unhandled cluster scenario. Terminating the container\n"
+ printf "Any one of the below 2 conditions should be satisfied for successfully enabling cluster mode : \n"
+ printf "1. OOM Environment - Both SERVICE_NAME and NAMESPACE environment variables have to be set.\n"
+ printf "2. Docker (standalone) Environment - Neither of SERVICE_NAME and NAMESPACE have to be set.\n"
+ printf "Current configuration - SERVICE_NAME = $SERVICE_NAME NAMESPACE = $NAMESPACE\n"
+ exit $NOTOK
+ fi
+ fi