3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2020 Samsung Electronics
7 # Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
8 # Copyright (C) 2020 Highstreet Technologies
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
23 # A single entry point script that can be used in Kubernetes based deployments (via OOM) and standalone docker deployments.
24 # Please see https://wiki.onap.org/display/DW/startODL.sh+-+Important+Environment+variables+and+their+description for more details
28 # Test if repository exists, like this mvn:org.onap.ccsdk.features.sdnr.wt/sdnr-wt-devicemanager-oran-feature/0.7.2/xml/features
31 REPO=$(echo "$1" | sed -E "s#mvn:(.*)/xml/features\$#\1#")
36 path="$ODL_HOME/system/$(echo "$2" | tr '.' '/')/$3/$4"
40 # Add features repository to karaf featuresRepositories configuration
41 # $1 repositories to be added
43 CFG=$ODL_FEATURES_BOOT_FILE
45 if isRepoExisting "$1" ; then
46 printf "%s\n" "Add repository: $1"
47 sed -i "\|featuresRepositories|s|$|, $1|" "$CFG"
49 printf "%s\n" "Repo does not exist: $1"
53 # Append features to karaf boot feature configuration
54 # $1 additional feature to be added
55 # $2 repositories to be added (optional)
57 CFG=$ODL_FEATURES_BOOT_FILE
60 printf "%s\n" "Add repository: $2"
62 sed -e "\|featuresRepositories|s|$|,$2|" "$ORIG" > "$CFG"
64 printf "%s\n" "Add boot feature: $1"
66 sed -e "\|featuresBoot *=|s|$|,$1|" "$ORIG" > "$CFG"
69 # Append features to karaf boot feature configuration
72 replaceFeatureBoot() {
73 CFG="$ODL_HOME"/etc/org.apache.karaf.features.cfg
75 printf "%s %s\n" "Replace boot feature $1 with: $2"
76 sed -i "/featuresBoot/ s/$1/$2/g" "$CFG"
79 # Remove all sdnc specific features
80 cleanupFeatureBoot() {
81 printf "Remove northbound bootfeatures \n"
82 sed -i "/featuresBoot/ s/,ccsdk-sli-core-all.*$//g" "$ODL_FEATURES_BOOT_FILE"
86 printf "SDN-R Database Initialization"
87 INITCMD="$JAVA_HOME/bin/java -jar "
88 INITCMD="${INITCMD} $ODL_HOME/system/org/onap/ccsdk/features/sdnr/wt/sdnr-wt-data-provider-setup/$CCSDKFEATUREVERSION/sdnr-dmt.jar "
89 INITCMD="${INITCMD} $SDNRDBCOMMAND"
90 printf "%s\n" "Execute: $INITCMD"
92 until [ $n -ge 5 ] ; do
100 install_sdnrwt_features() {
101 # Repository setup provided via sdnc dockerfile
107 addToFeatureBoot "$SDNRDM_BOOTFEATURES"
109 addToFeatureBoot "$SDNRODLUX_BOOTFEATURES"
113 install_sdnr_oauth_features() {
114 addToFeatureBoot "$SDNROAUTH_BOOTFEATURES"
116 install_sdnr_northbound_features() {
117 addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
120 # Reconfigure ODL from default single node configuration to cluster
122 enable_odl_cluster() {
123 if [ -z "$SDNC_REPLICAS" ]; then
124 printf "SDNC_REPLICAS is not configured in Env field"
129 printf "Installing Opendaylight cluster features for mdsal and netconf\n"
131 #Be sure to remove feature odl-netconf-connector-all from list
132 replaceFeatureBoot "odl-netconf-connector-all,"
134 printf "Installing Opendaylight cluster features\n"
135 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
136 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
137 addToFeatureBoot odl-jolokia
138 #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
139 #${ODL_HOME}/bin/client feature:install odl-jolokia
141 # ODL Cluster or Geo cluster configuration
143 printf "Update cluster information statically\n"
145 printf "%s\n" "Get current fqdn ${fqdn}"
147 # Extract node index using first digit after "-"
148 # Example 2 from "sdnr-2.logo.ost.das.r32.com"
149 node_index=$(echo "${fqdn}" | sed -r 's/.*-([0-9]).*/\1/g')
152 if $GEO_ENABLED; then
153 printf "This is a Geo cluster\n"
155 if [ -z "$IS_PRIMARY_CLUSTER" ] || [ -z "$MY_ODL_CLUSTER" ] || [ -z "$PEER_ODL_CLUSTER" ]; then
156 printf "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field\n"
160 if $IS_PRIMARY_CLUSTER; then
161 PRIMARY_NODE=${MY_ODL_CLUSTER}
162 SECONDARY_NODE=${PEER_ODL_CLUSTER}
164 PRIMARY_NODE=${PEER_ODL_CLUSTER}
165 SECONDARY_NODE=${MY_ODL_CLUSTER}
169 node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
171 "${SDNC_BIN}"/configure_geo_cluster.sh $((node_index+member_offset)) "${node_list}"
173 printf "This is a local cluster\n"
176 # SERVICE_NAME and NAMESPACE are used to create cluster node names and are provided via Helm charts in OOM environment
177 if [ ! -z "$SERVICE_NAME" ] && [ ! -z "$NAMESPACE" ]; then
178 # Extract node name minus the index
179 # Example sdnr from "sdnr-2.logo.ost.das.r32.com"
180 node_name=$(echo "${fqdn}" | sed 's/-[0-9].*$//g')
181 while [ $i -lt "$SDNC_REPLICAS" ]; do
182 node_list="${node_list} ${node_name}-$i.${SERVICE_NAME}-cluster.${NAMESPACE}"
185 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
186 elif [ -z "$SERVICE_NAME" ] && [ -z "$NAMESPACE" ]; then
187 # Hostname is used in Standalone environment to create cluster node names
188 while [ $i -lt "$SDNC_REPLICAS" ]; do
189 #assemble node list by replacing node-index in hostname with "i"
190 node_name=$(echo "${fqdn}" | sed -r "s/-[0-9]/-$i/g")
191 node_list="${node_list} ${node_name}"
194 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
196 printf "Unhandled cluster scenario. Terminating the container\n"
197 printf "Any one of the below 2 conditions should be satisfied for successfully enabling cluster mode : \n"
198 printf "1. OOM Environment - Both SERVICE_NAME and NAMESPACE environment variables have to be set.\n"
199 printf "2. Docker (standalone) Environment - Neither of SERVICE_NAME and NAMESPACE have to be set.\n"
200 printf "Current configuration - SERVICE_NAME = $SERVICE_NAME NAMESPACE = $NAMESPACE\n"
207 # Install SDN-C platform components if not already installed and start container
209 # -----------------------
210 # Main script starts here
211 printf "Installing SDNC/R from startODL.sh script\n"
212 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
213 ODL_FEATURES_BOOT_FILE=$ODL_HOME/etc/org.apache.karaf.features.cfg
215 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
216 # do not start container if ADMIN_PASSWORD is not set
217 if [ -z "$ODL_ADMIN_PASSWORD" ]; then
218 echo "ODL_ADMIN_PASSWORD is not set"
221 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
222 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
223 # Whether to intialize MYSql DB or not. Default is to initialize
224 SDNC_DB_INIT=${SDNC_DB_INIT:-false}
225 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
226 JDEBUG=${JDEBUG:-false}
227 MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-openECOMP1.0}
228 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
229 ENABLE_OAUTH=${ENABLE_OAUTH:-false}
230 ENABLE_ODLUX_RBAC=${ENABLE_ODLUX_RBAC:-false}
231 GEO_ENABLED=${GEO_ENABLED:-false}
232 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
233 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
234 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
235 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
236 SDNRWT=${SDNRWT:-false}
237 SDNRODLUX_BOOTFEATURES=${SDNRODLUX_BOOTFEATURES:-sdnr-wt-helpserver-feature,sdnr-wt-odlux-core-feature,sdnr-wt-odlux-apps-feature}
238 SDNROAUTH_BOOTFEATURES=${SDNROAUTH_BOOTFEATURES:-sdnr-wt-feature-aggregator-oauth}
239 SDNRDM=${SDNRDM:-false}
240 # Add devicemanager features
241 SDNRDM_SDM_LIST=${SDNRDM_SDM_LIST:-sdnr-wt-feature-aggregator-devicemanager}
242 SDNRDM_BOOTFEATURES=${SDNRDM_BOOTFEATURES:-sdnr-wt-feature-aggregator-devicemanager-base,${SDNRDM_SDM_LIST}}
243 # Whether to Initialize the ElasticSearch DB.
244 SDNRINIT=${SDNRINIT:-false}
245 SDNRONLY=${SDNRONLY:-false}
246 SDNRDBURL=${SDNRDBURL:-http://sdnrdb:9200}
247 SDNRDBCOMMAND=${SDNRDBCOMMAND:--c init -db $SDNRDBURL -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD $SDNRDBPARAMETER}
249 SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
250 SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
252 #export for installCerts.py
253 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
256 printf "Activate remote debugging\n"
257 #JSTADTPOLICYFILE="$ODL_HOME/etc/tools.policy"
258 #echo -e "grant codebase \"file:${JAVA_HOME}/lib/tools.jar\" {\n permission java.security.AllPermission;\n };" > $JSTADTPOLICYFILE
260 #$JAVA_HOME/bin/jstatd -p 1089 -J-Djava.security.policy=$JSTADTPOLICYFILE &
261 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=1090"
262 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.rmi.port=1090"
263 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Djava.rmi.server.hostname=$(hostname) "
264 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.local.only=false"
265 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
266 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
267 export EXTRA_JAVA_OPTS
272 printf "%s\n" " SDNC_BIN=$SDNC_BIN"
273 printf "%s\n" " SDNC_HOME=$SDNC_HOME"
274 printf "%s\n" " SDNC_DB_INIT=$SDNC_DB_INIT"
275 printf "%s\n" " ODL_CERT_DIR=$ODL_CERT_DIR"
276 printf "%s\n" " CCSDKFEATUREVERSION=$CCSDKFEATUREVERSION"
277 printf "%s\n" " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
278 printf "%s\n" " ODL_REMOVEIDMDB=$ODL_REMOVEIDMDB"
279 printf "%s\n" " SDNC_REPLICAS=$SDNC_REPLICAS"
280 printf "%s\n" " ENABLE_OAUTH=$ENABLE_OAUTH"
281 printf "%s\n" " ENABLE_ODLUX_RBAC=$ENABLE_ODLUX_RBAC"
282 printf "%s\n" " SDNRWT=$SDNRWT"
283 printf "%s\n" " SDNRDM=$SDNRDM"
284 printf "%s\n" " SDNRONLY=$SDNRONLY"
285 printf "%s\n" " SDNRINIT=$SDNRINIT"
286 printf "%s\n" " SDNRDBURL=$SDNRDBURL"
287 printf "%s\n" " SDNRDBUSERNAME=$SDNRDBUSERNAME"
288 printf "%s\n" " GEO_ENABLED=$GEO_ENABLED"
289 printf "%s\n" " IS_PRIMARY_CLUSTER=$IS_PRIMARY_CLUSTER"
290 printf "%s\n" " MY_ODL_CLUSTER=$MY_ODL_CLUSTER"
291 printf "%s\n" " PEER_ODL_CLUSTER=$PEER_ODL_CLUSTER"
292 printf "%s\n" " SDNR_NORTHBOUND=$SDNR_NORTHBOUND"
293 printf "%s\n" " AAF_ENABLED=$SDNC_AAF_ENABLED"
294 printf "%s\n" " SERVICE_NAME=$SERVICE_NAME"
295 printf "%s\n" " NAMESPACE=$NAMESPACE"
297 if "$SDNC_AAF_ENABLED"; then
298 export SDNC_AAF_STORE_DIR=/opt/app/osaaf/local
299 export SDNC_AAF_CONFIG_DIR=/opt/app/osaaf/local
300 export SDNC_KEYPASS=$(cat /opt/app/osaaf/local/.pass)
301 export SDNC_KEYSTORE=org.onap.sdnc.p12
302 sed -i '/cadi_prop_files/d' "$ODL_HOME"/etc/system.properties
303 echo "cadi_prop_files=$SDNC_AAF_CONFIG_DIR/org.onap.sdnc.props" >> "$ODL_HOME"/etc/system.properties
305 sed -i '/org.ops4j.pax.web.ssl.keystore/d' "$ODL_HOME"/etc/custom.properties
306 sed -i '/org.ops4j.pax.web.ssl.password/d' "$ODL_HOME"/etc/custom.properties
307 sed -i '/org.ops4j.pax.web.ssl.keypassword/d' "$ODL_HOME"/etc/custom.properties
308 echo "org.ops4j.pax.web.ssl.keystore=$SDNC_AAF_STORE_DIR/$SDNC_KEYSTORE" >> "$ODL_HOME"/etc/custom.properties
309 echo "org.ops4j.pax.web.ssl.password=$SDNC_KEYPASS" >> "$ODL_HOME"/etc/custom.properties
310 echo "org.ops4j.pax.web.ssl.keypassword=$SDNC_KEYPASS" >> "$ODL_HOME"/etc/custom.properties
314 #One time intialization action
317 printf "%s\n" "Result of init script: $init_result"
319 printf "Proceed to initialize sdnr\n"
325 # Check for MySQL DB connectivity only if SDNC_DB_INIT is set to "true"
326 if $SDNC_DB_INIT; then
330 printf "Waiting for mysql"
331 until mysql -h dbhost -u root -p"${MYSQL_ROOT_PASSWORD}" -e "select 1" > /dev/null 2>&1
336 printf "\nmysql ready"
339 if [ ! -d "${INSTALLED_DIR}" ]
341 mkdir -p "${INSTALLED_DIR}"
344 if [ ! -f "${SDNC_HOME}"/.installed ]
346 # for integration testing. In OOM, a separate job takes care of installing it.
347 if $SDNC_DB_INIT; then
348 printf "Installing SDN-C database\n"
349 "${SDNC_HOME}"/bin/installSdncDb.sh
351 printf "Installing SDN-C keyStore\n"
352 "${SDNC_HOME}"/bin/addSdncKeyStore.sh
353 printf "Installing A1-adapter trustStore\n"
354 "${SDNC_HOME}"/bin/addA1TrustStore.sh
356 if [ -x "${SDNC_HOME}"/svclogic/bin/install.sh ]
358 printf "Installing directed graphs\n"
359 "${SDNC_HOME}"/svclogic/bin/install.sh
362 if $SDNRWT ; then install_sdnrwt_features ; fi
363 if $ENABLE_OAUTH ; then install_sdnr_oauth_features ; fi
365 # The enable_odl_cluster call should not be moved above this line as the cleanFeatureBoot will overwrite entries. Ex: odl-jolokia
366 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
368 if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
369 printf "%s" "Installed at $(date)" > "${SDNC_HOME}"/.installed
372 #cp /opt/opendaylight/current/certs/* /tmp
373 #cp /var/custom-certs/* /tmp
375 if [ -n "$OVERRIDE_FEATURES_BOOT" ] ; then
376 printf "%s\n" "Override features boot: $OVERRIDE_FEATURES_BOOT"
377 sed -i "/$FEATURESBOOTMARKER/c\featuresBoot = $OVERRIDE_FEATURES_BOOT" "$ODL_FEATURES_BOOT_FILE"
380 # Odl configuration done
381 ODL_REPOSITORIES_BOOT=$(sed -n "/$REPOSITORIESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
382 ODL_FEATURES_BOOT=$(sed -n "/$FEATURESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
383 export ODL_FEATURES_BOOT
385 # Create ODL data log directory (it nornally is created after karaf
386 # is started, but needs to exist before installCerts.py runs)
387 if [ -z "$ODL_CERT_DIR" ] ; then
388 printf "No certs provided. Skip installation.\n"
390 printf "Start background cert installer\n"
391 mkdir -p /opt/opendaylight/data/log
392 nohup python3 "${SDNC_BIN}"/installCerts.py &
393 printf "Start monitoring certificate installation. \n"
394 nohup sh "${SDNC_BIN}"/monitorCertsInstall.sh &
397 printf "Startup opendaylight\n"
398 printf "%s\n" "$ODL_REPOSITORIES_BOOT"
399 printf "%s\n" "$ODL_FEATURES_BOOT"
400 exec "${ODL_HOME}"/bin/karaf server