+# A single entry point script that can be used in Kubernetes based deployments (via OOM) and standalone docker deployments.
+# Please see https://wiki.onap.org/display/DW/startODL.sh+-+Important+Environment+variables+and+their+description for more details
+
+# Functions
+
+# Test if repository exists, like this mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-oran-feature/0.7.2/xml/features
+# $1 repository
+isRepoExisting() {
+ REPO=$(echo "$1" | sed -E "s#mvn:(.*)/xml/features\$#\1#")
+ OIFS="$IFS"
+ IFS='/'
+ set parts $REPO
+ IFS="$OIFS"
+ path="$ODL_HOME/system/$(echo "$2" | tr '.' '/')/$3/$4"
+ [ -d "$path" ]
+}
+
+# Add features repository to karaf featuresRepositories configuration
+# $1 repositories to be added
+addRepository() {
+ CFG=$ODL_FEATURES_BOOT_FILE
+ ORIG=$CFG.orig
+ if isRepoExisting "$1" ; then
+ printf "%s\n" "Add repository: $1"
+ sed -i "\|featuresRepositories|s|$|, $1|" "$CFG"
+ else
+ printf "%s\n" "Repo does not exist: $1"
+ fi
+}
+
+# Append features to karaf boot feature configuration
+# $1 additional feature to be added
+# $2 repositories to be added (optional)
+addToFeatureBoot() {
+ CFG=$ODL_FEATURES_BOOT_FILE
+ ORIG=$CFG.orig
+ if [ -n "$2" ] ; then
+ printf "%s\n" "Add repository: $2"
+ mv "$CFG" "$ORIG"
+ sed -e "\|featuresRepositories|s|$|,$2|" "$ORIG" > "$CFG"
+ fi
+ printf "%s\n" "Add boot feature: $1"
+ mv "$CFG" "$ORIG"
+ sed -e "\|featuresBoot *=|s|$|,$1|" "$ORIG" > "$CFG"
+}
+
+# Append features to karaf boot feature configuration
+# $1 search pattern
+# $2 replacement
+replaceFeatureBoot() {
+ CFG="$ODL_HOME"/etc/org.apache.karaf.features.cfg
+ ORIG=$CFG.orig
+ printf "%s %s\n" "Replace boot feature $1 with: $2"
+ sed -i "/featuresBoot/ s/$1/$2/g" "$CFG"
+}
+
+# Remove all sdnc specific features
+cleanupFeatureBoot() {
+ printf "Remove northbound bootfeatures \n"
+ sed -i "/featuresBoot/ s/,ccsdk-sli-core-all.*$//g" "$ODL_FEATURES_BOOT_FILE"
+}
+
+initialize_sdnr() {
+ printf "SDN-R Database Initialization"
+ INITCMD="$JAVA_HOME/bin/java -jar "
+ INITCMD="${INITCMD} $ODL_HOME/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/$CCSDKFEATUREVERSION/sdnr-dmt.jar "
+ INITCMD="${INITCMD} $SDNRDBCOMMAND"
+ printf "%s\n" "Execute: $INITCMD"
+ n=0
+ until [ $n -ge 5 ] ; do
+ $INITCMD && break
+ n=$((n+1))
+ sleep 15
+ done
+ return $?
+}
+
+install_sdnrwt_features() {
+ # Repository setup provided via sdnc dockerfile
+ if $SDNRWT; then
+ addRepository "$SDNRDM_BASE_REPO"
+
+ if $SDNRONLY; then
+ cleanupFeatureBoot
+ fi
+ if $SDNRDM; then
+ addToFeatureBoot "$SDNRDM_BOOTFEATURES"
+ else
+ addToFeatureBoot "$SDNRWT_BOOTFEATURES"
+ fi
+ fi
+}
+
+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
+}