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 FN=$(find "$ODL_HOME/system" -name "sdnr-wt-data-provider-setup-*.jar")
89 INITCMD="${INITCMD} ${FN} $SDNRDBCOMMAND"
90 printf "%s\n" "Execute: $INITCMD"
92 until [ $n -ge 5 ] ; do
95 if [ $ret -eq 0 ] ; then
104 install_sdnrwt_features() {
105 # Repository setup provided via sdnc dockerfile
110 addToFeatureBoot "$SDNRDM_BOOTFEATURES"
111 if $SDNR_NETCONF_CALLHOME_ENABLED; then
112 addToFeatureBoot "$SDNR_NETCONF_CALLHOME_FEATURE"
116 install_sdnr_oauth_features() {
117 addToFeatureBoot "$SDNROAUTH_BOOTFEATURES"
119 install_sdnr_northbound_features() {
120 addToFeatureBoot "$SDNR_NORTHBOUND_BOOTFEATURES"
122 install_a1_northbound_features() {
123 addToFeatureBoot "$A1_ADAPTER_NORTHBOUND_BOOTFEATURES"
125 # Reconfigure ODL from default single node configuration to cluster
127 enable_odl_cluster() {
128 if [ -z "$SDNC_REPLICAS" ]; then
129 printf "SDNC_REPLICAS is not configured in Env field"
134 printf "Installing Opendaylight cluster features for mdsal and netconf\n"
136 #Be sure to remove feature odl-netconf-connector-all from list
137 replaceFeatureBoot "odl-netconf-connector-all,"
139 printf "Installing Opendaylight cluster features\n"
140 replaceFeatureBoot odl-netconf-topology odl-netconf-clustered-topology
141 replaceFeatureBoot odl-mdsal-all odl-mdsal-all,odl-mdsal-clustering
142 addToFeatureBoot odl-jolokia
143 #${ODL_HOME}/bin/client feature:install odl-mdsal-clustering
144 #${ODL_HOME}/bin/client feature:install odl-jolokia
146 # ODL Cluster or Geo cluster configuration
148 printf "Update cluster information statically\n"
150 printf "%s\n" "Get current fqdn ${fqdn}"
152 # Extract node index using first digit after "-"
153 # Example 2 from "sdnr-2.logo.ost.das.r32.com"
154 node_index=$(echo "${fqdn}" | sed -r 's/.*-([0-9]).*/\1/g')
157 if $GEO_ENABLED; then
158 printf "This is a Geo cluster\n"
160 if [ -z "$IS_PRIMARY_CLUSTER" ] || [ -z "$MY_ODL_CLUSTER" ] || [ -z "$PEER_ODL_CLUSTER" ]; then
161 printf "IS_PRIMARY_CLUSTER, MY_ODL_CLUSTER and PEER_ODL_CLUSTER must all be configured in Env field\n"
165 if $IS_PRIMARY_CLUSTER; then
166 PRIMARY_NODE=${MY_ODL_CLUSTER}
167 SECONDARY_NODE=${PEER_ODL_CLUSTER}
169 PRIMARY_NODE=${PEER_ODL_CLUSTER}
170 SECONDARY_NODE=${MY_ODL_CLUSTER}
174 node_list="${PRIMARY_NODE} ${SECONDARY_NODE}"
176 "${SDNC_BIN}"/configure_geo_cluster.sh $((node_index+member_offset)) "${node_list}"
178 printf "This is a local cluster\n"
181 # SERVICE_NAME and NAMESPACE are used to create cluster node names and are provided via Helm charts in OOM environment
182 if [ ! -z "$SERVICE_NAME" ] && [ ! -z "$NAMESPACE" ]; then
183 # Extract node name minus the index
184 # Example sdnr from "sdnr-2.logo.ost.das.r32.com"
185 node_name=$(echo "${fqdn}" | sed 's/-[0-9].*$//g')
186 while [ $i -lt "$SDNC_REPLICAS" ]; do
187 node_list="${node_list} ${node_name}-$i.${SERVICE_NAME}-cluster.${NAMESPACE}"
190 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
191 elif [ -z "$SERVICE_NAME" ] && [ -z "$NAMESPACE" ]; then
192 # Hostname is used in Standalone environment to create cluster node names
193 while [ $i -lt "$SDNC_REPLICAS" ]; do
194 #assemble node list by replacing node-index in hostname with "i"
195 node_name=$(echo "${fqdn}" | sed -r "s/-[0-9]/-$i/g")
196 node_list="${node_list} ${node_name}"
199 "${ODL_HOME}"/bin/configure_cluster.sh $((node_index+1)) "${node_list}"
201 printf "Unhandled cluster scenario. Terminating the container\n"
202 printf "Any one of the below 2 conditions should be satisfied for successfully enabling cluster mode : \n"
203 printf "1. OOM Environment - Both SERVICE_NAME and NAMESPACE environment variables have to be set.\n"
204 printf "2. Docker (standalone) Environment - Neither of SERVICE_NAME and NAMESPACE have to be set.\n"
205 printf "Current configuration - SERVICE_NAME = $SERVICE_NAME NAMESPACE = $NAMESPACE\n"
212 # Install SDN-C platform components if not already installed and start container
214 # -----------------------
215 # Main script starts here
216 printf "Installing SDNC/R from startODL.sh script\n"
217 ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
218 ODL_FEATURES_BOOT_FILE=$ODL_HOME/etc/org.apache.karaf.features.cfg
219 FEATURESBOOTMARKER="featuresBoot *="
220 REPOSITORIESBOOTMARKER="featuresRepositories *="
222 ODL_ADMIN_USERNAME=${ODL_ADMIN_USERNAME:-admin}
223 ODL_REMOVEIDMDB=${ODL_REMOVEIDMDB:-true}
225 if $ODL_REMOVEIDMDB ; then
226 if [ -f $ODL_HOME/data/idmlight.db.mv.db ]; then
227 rm $ODL_HOME/data/idmlight.db.mv.db
231 CCSDK_HOME=${CCSDK_HOME:-/opt/onap/ccsdk}
232 SDNC_HOME=${SDNC_HOME:-/opt/onap/sdnc}
233 SDNC_BIN=${SDNC_BIN:-/opt/onap/sdnc/bin}
234 JDEBUG=${JDEBUG:-false}
235 SDNC_AAF_ENABLED=${SDNC_AAF_ENABLED:-false}
236 INSTALLED_DIR=${INSTALLED_FILE:-/opt/opendaylight/current/daexim}
238 # Whether to intialize MYSql DB or not. Default is to initialize
239 SDNC_DB_INIT=${SDNC_DB_INIT:-false}
240 MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-openECOMP1.0}
242 IS_PRIMARY_CLUSTER=${IS_PRIMARY_CLUSTER:-false}
243 MY_ODL_CLUSTER=${MY_ODL_CLUSTER:-127.0.0.1}
244 ENABLE_ODL_CLUSTER=${ENABLE_ODL_CLUSTER:-false}
245 ENABLE_OAUTH=${ENABLE_OAUTH:-false}
246 ENABLE_ODLUX_RBAC=${ENABLE_ODLUX_RBAC:-false}
247 GEO_ENABLED=${GEO_ENABLED:-false}
249 SDNRWT=${SDNRWT:-false}
250 SDNRDM=${SDNRDM:-false}
251 SDNROAUTH_BOOTFEATURES=${SDNROAUTH_BOOTFEATURES:-sdnr-wt-feature-aggregator-oauth}
252 SDNR_NETCONF_CALLHOME_ENABLED=${SDNR_NETCONF_CALLHOME_ENABLED:-false}
254 # Add devicemanager features
255 SDNRDM_SDM_LIST=${SDNRDM_SDM_LIST:-sdnr-wt-feature-aggregator-devicemanager}
256 SDNRDM_BOOTFEATURES=${SDNRDM_BOOTFEATURES:-sdnr-wt-feature-aggregator-devicemanager-base,${SDNRDM_SDM_LIST}}
258 # Whether to Initialize the ElasticSearch DB.
259 SDNRINIT=${SDNRINIT:-false}
260 SDNRONLY=${SDNRONLY:-false}
261 SDNRDBTYPE=${SDNRDBTYPE:-ELASTICSEARCH}
262 SDNRDBURL=${SDNRDBURL:-http://sdnrdb:9200}
263 SDNRDBCOMMAND=${SDNRDBCOMMAND:--c init -db $SDNRDBURL -dbt $SDNRDBTYPE -dbu $SDNRDBUSERNAME -dbp $SDNRDBPASSWORD $SDNRDBPARAMETER}
264 SDNR_WEBSOCKET_PORT=${SDNR_WEBSOCKET_PORT:-8182}
266 SDNR_NORTHBOUND=${SDNR_NORTHBOUND:-false}
267 SDNR_NORTHBOUND_BOOTFEATURES=${SDNR_NORTHBOUND_BOOTFEATURES:-sdnr-northbound-all}
268 SDNR_NETCONF_CALLHOME_FEATURE=${SDNR_NETCONF_CALLHOME_FEATURE:-odl-netconf-callhome-ssh}
270 # if only SDNR features then do not start A1 adapter
272 A1_ADAPTER_NORTHBOUND=false
274 A1_ADAPTER_NORTHBOUND=${A1_ADAPTER_NORTHBOUND:-true}
276 A1_ADAPTER_NORTHBOUND_BOOTFEATURES=${A1_ADAPTER_NORTHBOUND_BOOTFEATURES:-a1-adapter-northbound}
279 #export for installCerts.py
280 export ODL_ADMIN_PASSWORD ODL_ADMIN_USERNAME
283 printf "Activate remote debugging\n"
284 #JSTADTPOLICYFILE="$ODL_HOME/etc/tools.policy"
285 #echo -e "grant codebase \"file:${JAVA_HOME}/lib/tools.jar\" {\n permission java.security.AllPermission;\n };" > $JSTADTPOLICYFILE
287 #$JAVA_HOME/bin/jstatd -p 1089 -J-Djava.security.policy=$JSTADTPOLICYFILE &
288 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.port=1090"
289 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.rmi.port=1090"
290 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Djava.rmi.server.hostname=$(hostname) "
291 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.local.only=false"
292 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.ssl=false"
293 EXTRA_JAVA_OPTS="${EXTRA_JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false"
294 export EXTRA_JAVA_OPTS
299 printf "%s\n" " SDNC_BIN=$SDNC_BIN"
300 printf "%s\n" " SDNC_HOME=$SDNC_HOME"
301 printf "%s\n" " SDNC_DB_INIT=$SDNC_DB_INIT"
302 printf "%s\n" " ODL_CERT_DIR=$ODL_CERT_DIR"
303 printf "%s\n" " ENABLE_ODL_CLUSTER=$ENABLE_ODL_CLUSTER"
304 printf "%s\n" " ODL_REMOVEIDMDB=$ODL_REMOVEIDMDB"
305 printf "%s\n" " SDNC_REPLICAS=$SDNC_REPLICAS"
306 printf "%s\n" " ENABLE_OAUTH=$ENABLE_OAUTH"
307 printf "%s\n" " ENABLE_ODLUX_RBAC=$ENABLE_ODLUX_RBAC"
308 printf "%s\n" " SDNRWT=$SDNRWT"
309 printf "%s\n" " SDNRDM=$SDNRDM"
310 printf "%s\n" " SDNRONLY=$SDNRONLY"
311 printf "%s\n" " SDNRINIT=$SDNRINIT"
312 printf "%s\n" " SDNRDBURL=$SDNRDBURL"
313 printf "%s\n" " SDNRDBTYPE=$SDNRDBTYPE"
314 printf "%s\n" " SDNRDBUSERNAME=$SDNRDBUSERNAME"
315 printf "%s\n" " GEO_ENABLED=$GEO_ENABLED"
316 printf "%s\n" " IS_PRIMARY_CLUSTER=$IS_PRIMARY_CLUSTER"
317 printf "%s\n" " MY_ODL_CLUSTER=$MY_ODL_CLUSTER"
318 printf "%s\n" " PEER_ODL_CLUSTER=$PEER_ODL_CLUSTER"
319 printf "%s\n" " SDNR_NORTHBOUND=$SDNR_NORTHBOUND"
320 printf "%s\n" " AAF_ENABLED=$SDNC_AAF_ENABLED"
321 printf "%s\n" " SERVICE_NAME=$SERVICE_NAME"
322 printf "%s\n" " NAMESPACE=$NAMESPACE"
323 printf "%s\n" " SDNR_NETCONF_CALLHOME_ENABLED=$SDNR_NETCONF_CALLHOME_ENABLED"
325 if "$SDNC_AAF_ENABLED"; then
326 export SDNC_AAF_STORE_DIR=/opt/app/osaaf/local
327 export SDNC_AAF_CONFIG_DIR=/opt/app/osaaf/local
328 export SDNC_KEYPASS=$(cat /opt/app/osaaf/local/.pass)
329 export SDNC_KEYSTORE=org.onap.sdnc.p12
330 sed -i '/cadi_prop_files/d' "$ODL_HOME"/etc/system.properties
331 echo "cadi_prop_files=$SDNC_AAF_CONFIG_DIR/org.onap.sdnc.props" >> "$ODL_HOME"/etc/system.properties
333 sed -i '/org.ops4j.pax.web.ssl.keystore/d' "$ODL_HOME"/etc/custom.properties
334 sed -i '/org.ops4j.pax.web.ssl.password/d' "$ODL_HOME"/etc/custom.properties
335 sed -i '/org.ops4j.pax.web.ssl.keypassword/d' "$ODL_HOME"/etc/custom.properties
336 echo "org.ops4j.pax.web.ssl.keystore=$SDNC_AAF_STORE_DIR/$SDNC_KEYSTORE" >> "$ODL_HOME"/etc/custom.properties
337 echo "org.ops4j.pax.web.ssl.password=\"$SDNC_KEYPASS\"" >> "$ODL_HOME"/etc/custom.properties
338 echo "org.ops4j.pax.web.ssl.keypassword=\"$SDNC_KEYPASS\"" >> "$ODL_HOME"/etc/custom.properties
342 #One time intialization action
345 printf "%s\n" "Result of init script: $init_result"
347 if [ $init_result -ne 0 ]; then
348 echo "db not initialized. stopping container"
351 printf "Proceed to initialize sdnr\n"
357 # do not start container if ADMIN_PASSWORD is not set
358 if [ -z "$ODL_ADMIN_PASSWORD" ]; then
359 echo "ODL_ADMIN_PASSWORD is not set"
363 # Check for MySQL DB connectivity only if SDNC_DB_INIT is set to "true"
364 if $SDNC_DB_INIT; then
368 printf "Waiting for mysql"
369 until mysql -h dbhost -u root -p"${MYSQL_ROOT_PASSWORD}" -e "select 1" > /dev/null 2>&1
374 printf "\nmysql ready"
378 if [ ! -d "${INSTALLED_DIR}" ]
380 mkdir -p "${INSTALLED_DIR}"
383 if [ ! -f "${SDNC_HOME}"/.installed ]
385 # for integration testing. In OOM, a separate job takes care of installing it.
386 if $SDNC_DB_INIT; then
387 printf "Installing SDN-C database\n"
388 "${SDNC_HOME}"/bin/installSdncDb.sh
390 printf "Installing SDN-C keyStore\n"
391 "${SDNC_HOME}"/bin/addSdncKeyStore.sh
392 printf "Installing A1-adapter trustStore\n"
393 "${SDNC_HOME}"/bin/addA1TrustStore.sh
395 if [ -x "${SDNC_HOME}"/svclogic/bin/install.sh ]
397 printf "Installing directed graphs\n"
398 "${SDNC_HOME}"/svclogic/bin/install.sh
401 if $SDNRWT ; then install_sdnrwt_features ; fi
402 if $ENABLE_OAUTH ; then
403 cp $SDNC_HOME/data/oauth-aaa-app-config.xml $(find $ODL_HOME/system/org/opendaylight/aaa/ -name *aaa-app-config.xml)
404 echo -e "\norg.ops4j.pax.web.session.cookie.comment = disable" >> $ODL_HOME/etc/org.ops4j.pax.web.cfg
405 install_sdnr_oauth_features
408 # The enable_odl_cluster call should not be moved above this line as the cleanFeatureBoot will overwrite entries. Ex: odl-jolokia
409 if $ENABLE_ODL_CLUSTER ; then enable_odl_cluster ; fi
411 if $SDNR_NORTHBOUND ; then install_sdnr_northbound_features ; fi
412 if $A1_ADAPTER_NORTHBOUND ; then install_a1_northbound_features ; fi
414 printf "%s" "Installed at $(date)" > "${SDNC_HOME}"/.installed
417 #cp /opt/opendaylight/current/certs/* /tmp
418 #cp /var/custom-certs/* /tmp
420 if [ -n "$OVERRIDE_FEATURES_BOOT" ] ; then
421 printf "%s\n" "Override features boot: $OVERRIDE_FEATURES_BOOT"
422 sed -i "/$FEATURESBOOTMARKER/c\featuresBoot = $OVERRIDE_FEATURES_BOOT" "$ODL_FEATURES_BOOT_FILE"
425 # Odl configuration done
426 ODL_REPOSITORIES_BOOT=$(sed -n "/$REPOSITORIESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
427 ODL_FEATURES_BOOT=$(sed -n "/$FEATURESBOOTMARKER/p" "$ODL_FEATURES_BOOT_FILE")
428 export ODL_FEATURES_BOOT
430 # Create ODL data log directory (it nornally is created after karaf
431 # is started, but needs to exist before installCerts.py runs)
432 if [ -z "$ODL_CERT_DIR" ] ; then
433 printf "No certs provided. Skip installation.\n"
435 printf "Start background cert installer\n"
436 mkdir -p /opt/opendaylight/data/log
437 nohup python3 "${SDNC_BIN}"/installCerts.py &
438 printf "Start monitoring certificate installation. \n"
439 nohup sh "${SDNC_BIN}"/monitorCertsInstall.sh &
442 printf "Startup opendaylight\n"
443 printf "%s\n" "$ODL_REPOSITORIES_BOOT"
444 printf "%s\n" "$ODL_FEATURES_BOOT"
446 exec "${ODL_HOME}"/bin/karaf server